blob: 3d0384506929727328449ba5d28889563277db2a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez07e264b2011-03-30 11:46:23 -07003 * Copyright (c) 2003-2011 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21* QLogic ISP2x00 Hardware Support Function Prototypes.
22*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Harihara Kadayam4d4df192008-04-03 13:13:26 -070038static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
39static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080040static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070041
Andrew Vasquezac280b62009-08-20 11:06:05 -070042/* SRB Extensions ---------------------------------------------------------- */
43
44static void
45qla2x00_ctx_sp_timeout(unsigned long __data)
46{
47 srb_t *sp = (srb_t *)__data;
48 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070049 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070050 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
52 struct req_que *req;
53 unsigned long flags;
54
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
58 ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070059 iocb = ctx->u.iocb_cmd;
60 iocb->timeout(sp);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070061 iocb->free(sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070062 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070063}
64
Andrew Vasquez3dbe7562010-07-23 15:28:37 +050065static void
Andrew Vasquezac280b62009-08-20 11:06:05 -070066qla2x00_ctx_sp_free(srb_t *sp)
67{
68 struct srb_ctx *ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070069 struct srb_iocb *iocb = ctx->u.iocb_cmd;
Arun Easifeafb7b2010-09-03 14:57:00 -070070 struct scsi_qla_host *vha = sp->fcport->vha;
Andrew Vasquezac280b62009-08-20 11:06:05 -070071
Chad Dupuis4d97cc52010-10-15 11:27:41 -070072 del_timer(&iocb->timer);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070073 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070074 kfree(ctx);
75 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
Arun Easifeafb7b2010-09-03 14:57:00 -070076
77 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -070078}
79
80inline srb_t *
81qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
82 unsigned long tmo)
83{
Arun Easifeafb7b2010-09-03 14:57:00 -070084 srb_t *sp = NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -070085 struct qla_hw_data *ha = vha->hw;
86 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070087 struct srb_iocb *iocb;
Arun Easifeafb7b2010-09-03 14:57:00 -070088 uint8_t bail;
89
90 QLA_VHA_MARK_BUSY(vha, bail);
91 if (bail)
92 return NULL;
Andrew Vasquezac280b62009-08-20 11:06:05 -070093
94 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
95 if (!sp)
96 goto done;
97 ctx = kzalloc(size, GFP_KERNEL);
98 if (!ctx) {
99 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700100 sp = NULL;
101 goto done;
102 }
103 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
104 if (!iocb) {
105 mempool_free(sp, ha->srb_mempool);
106 sp = NULL;
107 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700108 goto done;
109 }
110
111 memset(sp, 0, sizeof(*sp));
112 sp->fcport = fcport;
113 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700114 ctx->u.iocb_cmd = iocb;
115 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700116
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700117 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118 if (!tmo)
119 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700120 iocb->timer.expires = jiffies + tmo * HZ;
121 iocb->timer.data = (unsigned long)sp;
122 iocb->timer.function = qla2x00_ctx_sp_timeout;
123 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700124done:
Arun Easifeafb7b2010-09-03 14:57:00 -0700125 if (!sp)
126 QLA_VHA_MARK_NOT_BUSY(vha);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700127 return sp;
128}
129
130/* Asynchronous Login/Logout Routines -------------------------------------- */
131
Andrew Vasquez5b914902010-05-28 15:08:30 -0700132static inline unsigned long
133qla2x00_get_async_timeout(struct scsi_qla_host *vha)
134{
135 unsigned long tmo;
136 struct qla_hw_data *ha = vha->hw;
137
138 /* Firmware should use switch negotiated r_a_tov for timeout. */
139 tmo = ha->r_a_tov / 10 * 2;
140 if (!IS_FWI2_CAPABLE(ha)) {
141 /*
142 * Except for earlier ISPs where the timeout is seeded from the
143 * initialization control block.
144 */
145 tmo = ha->login_timeout;
146 }
147 return tmo;
148}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700149
150static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700151qla2x00_async_iocb_timeout(srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700152{
153 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700154 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700155
156 DEBUG2(printk(KERN_WARNING
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700157 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
158 fcport->vha->host_no, sp->handle,
159 ctx->name, fcport->d_id.b.domain,
160 fcport->d_id.b.area, fcport->d_id.b.al_pa));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700161
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700162 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700163 if (ctx->type == SRB_LOGIN_CMD) {
164 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700166 /* Retry as needed. */
167 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
168 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
169 QLA_LOGIO_LOGIN_RETRIED : 0;
170 qla2x00_post_async_login_done_work(fcport->vha, fcport,
171 lio->u.logio.data);
172 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700173}
174
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700175static void
176qla2x00_async_login_ctx_done(srb_t *sp)
177{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700178 struct srb_ctx *ctx = sp->ctx;
179 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700180
181 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700182 lio->u.logio.data);
183 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700184}
185
Andrew Vasquezac280b62009-08-20 11:06:05 -0700186int
187qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
188 uint16_t *data)
189{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700190 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700191 struct srb_ctx *ctx;
192 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700193 int rval;
194
195 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700196 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700197 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700198 if (!sp)
199 goto done;
200
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700201 ctx = sp->ctx;
202 ctx->type = SRB_LOGIN_CMD;
203 ctx->name = "login";
204 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700205 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700206 lio->done = qla2x00_async_login_ctx_done;
207 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700208 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700209 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700210 rval = qla2x00_start_sp(sp);
211 if (rval != QLA_SUCCESS)
212 goto done_free_sp;
213
214 DEBUG2(printk(KERN_DEBUG
215 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
216 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
217 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
218 fcport->login_retry));
219 return rval;
220
221done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700222 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700223done:
224 return rval;
225}
226
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700227static void
228qla2x00_async_logout_ctx_done(srb_t *sp)
229{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700230 struct srb_ctx *ctx = sp->ctx;
231 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700232
233 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700234 lio->u.logio.data);
235 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700236}
237
Andrew Vasquezac280b62009-08-20 11:06:05 -0700238int
239qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
240{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700241 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700242 struct srb_ctx *ctx;
243 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700244 int rval;
245
246 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700247 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700248 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700249 if (!sp)
250 goto done;
251
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700252 ctx = sp->ctx;
253 ctx->type = SRB_LOGOUT_CMD;
254 ctx->name = "logout";
255 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700256 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700257 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700258 rval = qla2x00_start_sp(sp);
259 if (rval != QLA_SUCCESS)
260 goto done_free_sp;
261
262 DEBUG2(printk(KERN_DEBUG
263 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
264 fcport->vha->host_no, sp->handle, fcport->loop_id,
265 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
266 return rval;
267
268done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700269 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700270done:
271 return rval;
272}
273
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700274static void
275qla2x00_async_adisc_ctx_done(srb_t *sp)
276{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700277 struct srb_ctx *ctx = sp->ctx;
278 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700279
280 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700281 lio->u.logio.data);
282 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700283}
284
285int
286qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
287 uint16_t *data)
288{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700289 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700290 struct srb_ctx *ctx;
291 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700292 int rval;
293
294 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700295 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700296 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700297 if (!sp)
298 goto done;
299
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700300 ctx = sp->ctx;
301 ctx->type = SRB_ADISC_CMD;
302 ctx->name = "adisc";
303 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700304 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700305 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700306 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700307 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700308 rval = qla2x00_start_sp(sp);
309 if (rval != QLA_SUCCESS)
310 goto done_free_sp;
311
312 DEBUG2(printk(KERN_DEBUG
313 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
314 fcport->vha->host_no, sp->handle, fcport->loop_id,
315 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
316
317 return rval;
318
319done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700320 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700321done:
322 return rval;
323}
324
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700325static void
326qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
327{
328 struct srb_ctx *ctx = sp->ctx;
329 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
330
331 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
332 iocb->free(sp);
333}
334
335int
336qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
337 uint32_t tag)
338{
339 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700340 srb_t *sp;
341 struct srb_ctx *ctx;
342 struct srb_iocb *tcf;
343 int rval;
344
345 rval = QLA_FUNCTION_FAILED;
346 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700347 qla2x00_get_async_timeout(vha) + 2);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700348 if (!sp)
349 goto done;
350
351 ctx = sp->ctx;
352 ctx->type = SRB_TM_CMD;
353 ctx->name = "tmf";
354 tcf = ctx->u.iocb_cmd;
355 tcf->u.tmf.flags = flags;
356 tcf->u.tmf.lun = lun;
357 tcf->u.tmf.data = tag;
358 tcf->timeout = qla2x00_async_iocb_timeout;
359 tcf->done = qla2x00_async_tm_cmd_ctx_done;
360
361 rval = qla2x00_start_sp(sp);
362 if (rval != QLA_SUCCESS)
363 goto done_free_sp;
364
365 DEBUG2(printk(KERN_DEBUG
366 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
367 fcport->vha->host_no, sp->handle, fcport->loop_id,
368 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
369
370 return rval;
371
372done_free_sp:
373 tcf->free(sp);
374done:
375 return rval;
376}
377
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700378void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700379qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
380 uint16_t *data)
381{
382 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700383
384 switch (data[0]) {
385 case MBS_COMMAND_COMPLETE:
Andrew Vasqueza4f92a32011-03-30 11:46:31 -0700386 /*
387 * Driver must validate login state - If PRLI not complete,
388 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
389 * requests.
390 */
391 rval = qla2x00_get_port_database(vha, fcport, 0);
392 if (rval != QLA_SUCCESS) {
393 qla2x00_post_async_logout_work(vha, fcport, NULL);
394 qla2x00_post_async_login_work(vha, fcport, NULL);
395 break;
396 }
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700397 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700398 qla2x00_post_async_adisc_work(vha, fcport, data);
399 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700400 }
401 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700402 break;
403 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700404 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700405 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
406 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
407 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700408 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700409 break;
410 case MBS_PORT_ID_USED:
411 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700412 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700413 qla2x00_post_async_login_work(vha, fcport, NULL);
414 break;
415 case MBS_LOOP_ID_USED:
416 fcport->loop_id++;
417 rval = qla2x00_find_new_loop_id(vha, fcport);
418 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700419 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700420 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700421 break;
422 }
423 qla2x00_post_async_login_work(vha, fcport, NULL);
424 break;
425 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700426 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700427}
428
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700429void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700430qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
431 uint16_t *data)
432{
433 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700434 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700435}
436
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700437void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700438qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
439 uint16_t *data)
440{
441 if (data[0] == MBS_COMMAND_COMPLETE) {
442 qla2x00_update_fcport(vha, fcport);
443
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700444 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700445 }
446
447 /* Retry login. */
448 fcport->flags &= ~FCF_ASYNC_SENT;
449 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
450 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
451 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700452 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700453
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700454 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700455}
456
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700457void
458qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
459 struct srb_iocb *iocb)
460{
461 int rval;
462 uint32_t flags;
463 uint16_t lun;
464
465 flags = iocb->u.tmf.flags;
466 lun = (uint16_t)iocb->u.tmf.lun;
467
468 /* Issue Marker IOCB */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500469 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
470 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700471 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
472
473 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
474 DEBUG2_3_11(printk(KERN_WARNING
475 "%s(%ld): TM IOCB failed (%x).\n",
476 __func__, vha->host_no, rval));
477 }
478
479 return;
480}
481
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482/****************************************************************************/
483/* QLogic ISP2x00 Hardware Support Functions. */
484/****************************************************************************/
485
486/*
487* qla2x00_initialize_adapter
488* Initialize board.
489*
490* Input:
491* ha = adapter block pointer.
492*
493* Returns:
494* 0 = success
495*/
496int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800497qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498{
499 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800500 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800501 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700502
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700505 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800506 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800507 ha->flags.pci_channel_io_perm_failure = 0;
508 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800509 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800510 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
511 atomic_set(&vha->loop_state, LOOP_DOWN);
512 vha->device_flags = DFLG_NO_CABLE;
513 vha->dpc_flags = 0;
514 vha->flags.management_server_logged_in = 0;
515 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 ha->isp_abort_cnt = 0;
517 ha->beacon_blink_led = 0;
518
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800519 set_bit(0, ha->req_qid_map);
520 set_bit(0, ha->rsp_qid_map);
521
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700522 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700524 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800525 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 return (rval);
528 }
529
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800532 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700533 if (rval) {
534 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800535 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700536 return (rval);
537 }
538
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800539 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800540
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700542
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800543 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700545 if (ha->flags.disable_serdes) {
546 /* Mask HBA via NVRAM settings? */
547 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
548 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 vha->port_name[0], vha->port_name[1],
550 vha->port_name[2], vha->port_name[3],
551 vha->port_name[4], vha->port_name[5],
552 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700553 return QLA_FUNCTION_FAILED;
554 }
555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
559 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800560 if (rval)
561 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800562 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800563 if (rval)
564 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700566
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700567 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800568 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700569 if (!ha->cs84xx) {
570 qla_printk(KERN_ERR, ha,
571 "Unable to configure ISP84XX.\n");
572 return QLA_FUNCTION_FAILED;
573 }
574 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800575 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700576 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800578 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700579 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800580 rval = qla84xx_init_chip(vha);
581 if (rval != QLA_SUCCESS) {
582 qla_printk(KERN_ERR, ha,
583 "Unable to initialize ISP84XX.\n");
584 qla84xx_put_chip(vha);
585 }
586 }
587
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500588 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
589 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700590
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 return (rval);
592}
593
594/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700595 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596 * @ha: HA context
597 *
598 * Returns 0 on success.
599 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700600int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700603 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700604 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800605 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700606 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700609 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700612 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
614
Andrew Vasquez737faec2008-10-24 15:13:45 -0700615 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700617 /* Get PCI bus information. */
618 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700619 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700620 spin_unlock_irqrestore(&ha->hardware_lock, flags);
621
622 return QLA_SUCCESS;
623}
624
625/**
626 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
627 * @ha: HA context
628 *
629 * Returns 0 on success.
630 */
631int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800632qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700634 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700635 unsigned long flags = 0;
636 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800637 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700638 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700639
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700640 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700641 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700642
643 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700644 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700645
646 if (IS_QLA2322(ha) || IS_QLA6322(ha))
647 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700648 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700649
650 /*
651 * If this is a 2300 card and not 2312, reset the
652 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
653 * the 2310 also reports itself as a 2300 so we need to get the
654 * fb revision level -- a 6 indicates it really is a 2300 and
655 * not a 2310.
656 */
657 if (IS_QLA2300(ha)) {
658 spin_lock_irqsave(&ha->hardware_lock, flags);
659
660 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700661 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700662 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700663 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700664 break;
665
666 udelay(10);
667 }
668
669 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700670 WRT_REG_WORD(&reg->ctrl_status, 0x20);
671 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700672
673 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700674 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700675
676 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700677 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700678
679 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700680 WRT_REG_WORD(&reg->ctrl_status, 0x0);
681 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700682
683 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700684 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700685 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700686 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700687 break;
688
689 udelay(10);
690 }
691
692 spin_unlock_irqrestore(&ha->hardware_lock, flags);
693 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700694
695 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
696
Andrew Vasquez737faec2008-10-24 15:13:45 -0700697 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700698
699 /* Get PCI bus information. */
700 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700701 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700702 spin_unlock_irqrestore(&ha->hardware_lock, flags);
703
704 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705}
706
707/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700708 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
709 * @ha: HA context
710 *
711 * Returns 0 on success.
712 */
713int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800714qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700715{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700716 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700717 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800718 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700719 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700720
721 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700722 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700723
724 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700725 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700726 w &= ~PCI_COMMAND_INTX_DISABLE;
727 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
728
729 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
730
731 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700732 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
733 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700734
735 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700736 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
737 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700738
Andrew Vasquez737faec2008-10-24 15:13:45 -0700739 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700740
Auke Kok44c10132007-06-08 15:46:36 -0700741 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800742
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700743 /* Get PCI bus information. */
744 spin_lock_irqsave(&ha->hardware_lock, flags);
745 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
746 spin_unlock_irqrestore(&ha->hardware_lock, flags);
747
748 return QLA_SUCCESS;
749}
750
751/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700752 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
753 * @ha: HA context
754 *
755 * Returns 0 on success.
756 */
757int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800758qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700759{
760 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800761 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700762
763 pci_set_master(ha->pdev);
764 pci_try_set_mwi(ha->pdev);
765
766 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
767 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
768 w &= ~PCI_COMMAND_INTX_DISABLE;
769 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
770
771 /* PCIe -- adjust Maximum Read Request Size (2048). */
772 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
773 pcie_set_readrq(ha->pdev, 2048);
774
Andrew Vasquez737faec2008-10-24 15:13:45 -0700775 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700776
777 ha->chip_revision = ha->pdev->revision;
778
779 return QLA_SUCCESS;
780}
781
782/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 * qla2x00_isp_firmware() - Choose firmware image.
784 * @ha: HA context
785 *
786 * Returns 0 on success.
787 */
788static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800789qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790{
791 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700792 uint16_t loop_id, topo, sw_cap;
793 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795
796 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700797 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798
799 if (ha->flags.disable_risc_code_load) {
800 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800801 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
803
804 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800805 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700806 if (rval == QLA_SUCCESS) {
807 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800808 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700809 &area, &domain, &topo, &sw_cap);
810 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811 }
812
813 if (rval) {
814 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800815 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
817
818 return (rval);
819}
820
821/**
822 * qla2x00_reset_chip() - Reset ISP chip.
823 * @ha: HA context
824 *
825 * Returns 0 on success.
826 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700827void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800828qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829{
830 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700832 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 uint16_t cmd;
835
Andrew Vasquez85880802009-12-15 21:29:46 -0800836 if (unlikely(pci_channel_offline(ha->pdev)))
837 return;
838
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700839 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700840
841 spin_lock_irqsave(&ha->hardware_lock, flags);
842
843 /* Turn off master enable */
844 cmd = 0;
845 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
846 cmd &= ~PCI_COMMAND_MASTER;
847 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
848
849 if (!IS_QLA2100(ha)) {
850 /* Pause RISC. */
851 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
852 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
853 for (cnt = 0; cnt < 30000; cnt++) {
854 if ((RD_REG_WORD(&reg->hccr) &
855 HCCR_RISC_PAUSE) != 0)
856 break;
857 udelay(100);
858 }
859 } else {
860 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
861 udelay(10);
862 }
863
864 /* Select FPM registers. */
865 WRT_REG_WORD(&reg->ctrl_status, 0x20);
866 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
867
868 /* FPM Soft Reset. */
869 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
870 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
871
872 /* Toggle Fpm Reset. */
873 if (!IS_QLA2200(ha)) {
874 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
875 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
876 }
877
878 /* Select frame buffer registers. */
879 WRT_REG_WORD(&reg->ctrl_status, 0x10);
880 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
881
882 /* Reset frame buffer FIFOs. */
883 if (IS_QLA2200(ha)) {
884 WRT_FB_CMD_REG(ha, reg, 0xa000);
885 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
886 } else {
887 WRT_FB_CMD_REG(ha, reg, 0x00fc);
888
889 /* Read back fb_cmd until zero or 3 seconds max */
890 for (cnt = 0; cnt < 3000; cnt++) {
891 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
892 break;
893 udelay(100);
894 }
895 }
896
897 /* Select RISC module registers. */
898 WRT_REG_WORD(&reg->ctrl_status, 0);
899 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
900
901 /* Reset RISC processor. */
902 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
903 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
904
905 /* Release RISC processor. */
906 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
907 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
908 }
909
910 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
911 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
912
913 /* Reset ISP chip. */
914 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
915
916 /* Wait for RISC to recover from reset. */
917 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
918 /*
919 * It is necessary to for a delay here since the card doesn't
920 * respond to PCI reads during a reset. On some architectures
921 * this will result in an MCA.
922 */
923 udelay(20);
924 for (cnt = 30000; cnt; cnt--) {
925 if ((RD_REG_WORD(&reg->ctrl_status) &
926 CSR_ISP_SOFT_RESET) == 0)
927 break;
928 udelay(100);
929 }
930 } else
931 udelay(10);
932
933 /* Reset RISC processor. */
934 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
935
936 WRT_REG_WORD(&reg->semaphore, 0);
937
938 /* Release RISC processor. */
939 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
940 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
941
942 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
943 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700944 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946
947 udelay(100);
948 }
949 } else
950 udelay(100);
951
952 /* Turn on master enable */
953 cmd |= PCI_COMMAND_MASTER;
954 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
955
956 /* Disable RISC pause on FPM parity error. */
957 if (!IS_QLA2100(ha)) {
958 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
959 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
960 }
961
962 spin_unlock_irqrestore(&ha->hardware_lock, flags);
963}
964
965/**
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700966 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
967 *
968 * Returns 0 on success.
969 */
970int
971qla81xx_reset_mpi(scsi_qla_host_t *vha)
972{
973 uint16_t mb[4] = {0x1010, 0, 1, 0};
974
975 return qla81xx_write_mpi_register(vha, mb);
976}
977
978/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700979 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700980 * @ha: HA context
981 *
982 * Returns 0 on success.
983 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700984static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700986{
987 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700989 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
990 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800991 uint16_t wd;
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -0700992 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700993
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700994 spin_lock_irqsave(&ha->hardware_lock, flags);
995
996 /* Reset RISC. */
997 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
998 for (cnt = 0; cnt < 30000; cnt++) {
999 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1000 break;
1001
1002 udelay(10);
1003 }
1004
1005 WRT_REG_DWORD(&reg->ctrl_status,
1006 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001007 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001008
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001009 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001010 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001011 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1012 for (cnt = 10000 ; cnt && d2; cnt--) {
1013 udelay(5);
1014 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1015 barrier();
1016 }
1017
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001018 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001019 d2 = RD_REG_DWORD(&reg->ctrl_status);
1020 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1021 udelay(5);
1022 d2 = RD_REG_DWORD(&reg->ctrl_status);
1023 barrier();
1024 }
1025
Madhuranath Iyengarb1d46982010-09-03 15:20:54 -07001026 /* If required, do an MPI FW reset now */
1027 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1028 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1029 if (++abts_cnt < 5) {
1030 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1031 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1032 } else {
1033 /*
1034 * We exhausted the ISP abort retries. We have to
1035 * set the board offline.
1036 */
1037 abts_cnt = 0;
1038 vha->flags.online = 0;
1039 }
1040 }
1041 }
1042
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001043 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1044 RD_REG_DWORD(&reg->hccr);
1045
1046 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1047 RD_REG_DWORD(&reg->hccr);
1048
1049 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1050 RD_REG_DWORD(&reg->hccr);
1051
1052 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1053 for (cnt = 6000000 ; cnt && d2; cnt--) {
1054 udelay(5);
1055 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1056 barrier();
1057 }
1058
1059 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001060
1061 if (IS_NOPOLLING_TYPE(ha))
1062 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001063}
1064
1065/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001066 * qla24xx_reset_chip() - Reset ISP24xx chip.
1067 * @ha: HA context
1068 *
1069 * Returns 0 on success.
1070 */
1071void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001072qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001073{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001074 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001075
1076 if (pci_channel_offline(ha->pdev) &&
1077 ha->flags.pci_channel_io_perm_failure) {
1078 return;
1079 }
1080
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001081 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001082
1083 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001084 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001085}
1086
1087/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 * qla2x00_chip_diag() - Test chip for proper operation.
1089 * @ha: HA context
1090 *
1091 * Returns 0 on success.
1092 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001093int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001094qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
1096 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001097 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001098 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 unsigned long flags = 0;
1100 uint16_t data;
1101 uint32_t cnt;
1102 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001103 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 /* Assume a failed state */
1106 rval = QLA_FUNCTION_FAILED;
1107
1108 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 spin_lock_irqsave(&ha->hardware_lock, flags);
1112
1113 /* Reset ISP chip. */
1114 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1115
1116 /*
1117 * We need to have a delay here since the card will not respond while
1118 * in reset causing an MCA on some architectures.
1119 */
1120 udelay(20);
1121 data = qla2x00_debounce_register(&reg->ctrl_status);
1122 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1123 udelay(5);
1124 data = RD_REG_WORD(&reg->ctrl_status);
1125 barrier();
1126 }
1127
1128 if (!cnt)
1129 goto chip_diag_failed;
1130
1131 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001132 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 /* Reset RISC processor. */
1135 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1136 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1137
1138 /* Workaround for QLA2312 PCI parity error */
1139 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1140 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1141 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1142 udelay(5);
1143 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001144 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
1146 } else
1147 udelay(10);
1148
1149 if (!cnt)
1150 goto chip_diag_failed;
1151
1152 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001153 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
1155 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1156 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1157 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1158 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1159 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1160 mb[3] != PROD_ID_3) {
1161 qla_printk(KERN_WARNING, ha,
1162 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1163
1164 goto chip_diag_failed;
1165 }
1166 ha->product_id[0] = mb[1];
1167 ha->product_id[1] = mb[2];
1168 ha->product_id[2] = mb[3];
1169 ha->product_id[3] = mb[4];
1170
1171 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001172 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1174 else
1175 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001176 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 if (IS_QLA2200(ha) &&
1179 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1180 /* Limit firmware transfer size with a 2200A */
1181 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001184 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 ha->fw_transfer_size = 128;
1186 }
1187
1188 /* Wrap Incoming Mailboxes Test. */
1189 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1190
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001191 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1192 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (rval) {
1194 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001195 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 qla_printk(KERN_WARNING, ha,
1197 "Failed mailbox send register test\n");
1198 }
1199 else {
1200 /* Flag a successful rval */
1201 rval = QLA_SUCCESS;
1202 }
1203 spin_lock_irqsave(&ha->hardware_lock, flags);
1204
1205chip_diag_failed:
1206 if (rval)
1207 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1211
1212 return (rval);
1213}
1214
1215/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001216 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1217 * @ha: HA context
1218 *
1219 * Returns 0 on success.
1220 */
1221int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001222qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001223{
1224 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001225 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001226 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001227
Giridhar Malavalia9083012010-04-12 17:59:55 -07001228 if (IS_QLA82XX(ha))
1229 return QLA_SUCCESS;
1230
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001231 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001232
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001234 if (rval) {
1235 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001237 qla_printk(KERN_WARNING, ha,
1238 "Failed mailbox send register test\n");
1239 } else {
1240 /* Flag a successful rval */
1241 rval = QLA_SUCCESS;
1242 }
1243
1244 return rval;
1245}
1246
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001247void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001248qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001249{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001250 int rval;
1251 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001252 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001253 dma_addr_t tc_dma;
1254 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001255 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001256 struct req_que *req = ha->req_q_map[0];
1257 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001258
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001259 if (ha->fw_dump) {
1260 qla_printk(KERN_WARNING, ha,
1261 "Firmware dump previously allocated.\n");
1262 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001263 }
1264
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001265 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001266 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001267 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1268 fixed_size = sizeof(struct qla2100_fw_dump);
1269 } else if (IS_QLA23XX(ha)) {
1270 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1271 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1272 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001273 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001274 if (IS_QLA81XX(ha))
1275 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1276 else if (IS_QLA25XX(ha))
1277 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1278 else
1279 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001280 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1281 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001282 if (ha->mqenable)
1283 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001284 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001285 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001286 goto try_eft;
1287
1288 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1289 GFP_KERNEL);
1290 if (!tc) {
1291 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1292 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001293 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001294 }
1295
1296 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001297 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001298 ha->fce_mb, &ha->fce_bufs);
1299 if (rval) {
1300 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1301 "FCE (%d).\n", rval);
1302 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1303 tc_dma);
1304 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001305 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001306 }
1307
1308 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1309 FCE_SIZE / 1024);
1310
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001311 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001312 ha->flags.fce_enabled = 1;
1313 ha->fce_dma = tc_dma;
1314 ha->fce = tc;
1315try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001316 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001317 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001318 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001319 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001320 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1321 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1322 goto cont_alloc;
1323 }
1324
Andrew Vasquezfc447652008-01-17 09:02:18 -08001325 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001327 if (rval) {
1328 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1329 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001330 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1331 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001332 goto cont_alloc;
1333 }
1334
1335 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1336 EFT_SIZE / 1024);
1337
1338 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001339 ha->eft_dma = tc_dma;
1340 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001341 }
1342cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001343 req_q_size = req->length * sizeof(request_t);
1344 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001345
1346 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001347 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001348 ha->chain_offset = dump_size;
1349 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001350
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001351 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001352 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001353 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001354 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001355
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001356 if (ha->fce) {
1357 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1358 ha->fce_dma);
1359 ha->fce = NULL;
1360 ha->fce_dma = 0;
1361 }
1362
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001363 if (ha->eft) {
1364 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1365 ha->eft_dma);
1366 ha->eft = NULL;
1367 ha->eft_dma = 0;
1368 }
1369 return;
1370 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001371 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1372 dump_size / 1024);
1373
1374 ha->fw_dump_len = dump_size;
1375 ha->fw_dump->signature[0] = 'Q';
1376 ha->fw_dump->signature[1] = 'L';
1377 ha->fw_dump->signature[2] = 'G';
1378 ha->fw_dump->signature[3] = 'C';
1379 ha->fw_dump->version = __constant_htonl(1);
1380
1381 ha->fw_dump->fixed_size = htonl(fixed_size);
1382 ha->fw_dump->mem_size = htonl(mem_size);
1383 ha->fw_dump->req_q_size = htonl(req_q_size);
1384 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1385
1386 ha->fw_dump->eft_size = htonl(eft_size);
1387 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1388 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1389
1390 ha->fw_dump->header_size =
1391 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001392}
1393
Andrew Vasquez18e75552009-06-03 09:55:30 -07001394static int
1395qla81xx_mpi_sync(scsi_qla_host_t *vha)
1396{
1397#define MPS_MASK 0xe0
1398 int rval;
1399 uint16_t dc;
1400 uint32_t dw;
1401 struct qla_hw_data *ha = vha->hw;
1402
1403 if (!IS_QLA81XX(vha->hw))
1404 return QLA_SUCCESS;
1405
1406 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1407 if (rval != QLA_SUCCESS) {
1408 DEBUG2(qla_printk(KERN_WARNING, ha,
1409 "Sync-MPI: Unable to acquire semaphore.\n"));
1410 goto done;
1411 }
1412
1413 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1414 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1415 if (rval != QLA_SUCCESS) {
1416 DEBUG2(qla_printk(KERN_WARNING, ha,
1417 "Sync-MPI: Unable to read sync.\n"));
1418 goto done_release;
1419 }
1420
1421 dc &= MPS_MASK;
1422 if (dc == (dw & MPS_MASK))
1423 goto done_release;
1424
1425 dw &= ~MPS_MASK;
1426 dw |= dc;
1427 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1428 if (rval != QLA_SUCCESS) {
1429 DEBUG2(qla_printk(KERN_WARNING, ha,
1430 "Sync-MPI: Unable to gain sync.\n"));
1431 }
1432
1433done_release:
1434 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1435 if (rval != QLA_SUCCESS) {
1436 DEBUG2(qla_printk(KERN_WARNING, ha,
1437 "Sync-MPI: Unable to release semaphore.\n"));
1438 }
1439
1440done:
1441 return rval;
1442}
1443
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001444/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 * qla2x00_setup_chip() - Load and start RISC firmware.
1446 * @ha: HA context
1447 *
1448 * Returns 0 on success.
1449 */
1450static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001451qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001453 int rval;
1454 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001455 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001456 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1457 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001458 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001459
Giridhar Malavalia9083012010-04-12 17:59:55 -07001460 if (IS_QLA82XX(ha)) {
1461 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001462 if (rval == QLA_SUCCESS) {
1463 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001464 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001465 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001466 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001467 }
1468
Andrew Vasquez3db06522008-01-31 12:33:49 -08001469 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1470 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1471 spin_lock_irqsave(&ha->hardware_lock, flags);
1472 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1473 RD_REG_WORD(&reg->hccr);
1474 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1475 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Andrew Vasquez18e75552009-06-03 09:55:30 -07001477 qla81xx_mpi_sync(vha);
1478
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001481 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 if (rval == QLA_SUCCESS) {
1487 /* Start firmware execution. */
1488 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001489 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001493 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001494enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001495 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001496 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 &ha->fw_major_version,
1498 &ha->fw_minor_version,
1499 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001500 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001501 ha->mpi_version, &ha->mpi_capabilities,
1502 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001503 if (rval != QLA_SUCCESS)
1504 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001505 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001506 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001507 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001508 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001509 if ((!ha->max_npiv_vports) ||
1510 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001511 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001512 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001513 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001514 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001515 qla2x00_get_resource_cnts(vha, NULL,
1516 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001517 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001518
Giridhar Malavalia9083012010-04-12 17:59:55 -07001519 if (!fw_major_version && ql2xallocfwdump) {
1520 if (!IS_QLA82XX(ha))
1521 qla2x00_alloc_fw_dump(vha);
1522 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 }
1524 } else {
1525 DEBUG2(printk(KERN_INFO
1526 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001527 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 }
1529 }
1530
Andrew Vasquez3db06522008-01-31 12:33:49 -08001531 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1532 /* Enable proper parity. */
1533 spin_lock_irqsave(&ha->hardware_lock, flags);
1534 if (IS_QLA2300(ha))
1535 /* SRAM parity */
1536 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1537 else
1538 /* SRAM, Instruction RAM and GP RAM parity */
1539 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1540 RD_REG_WORD(&reg->hccr);
1541 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1542 }
1543
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001544 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1545 uint32_t size;
1546
1547 rval = qla81xx_fac_get_sector_size(vha, &size);
1548 if (rval == QLA_SUCCESS) {
1549 ha->flags.fac_supported = 1;
1550 ha->fdt_block_size = size << 2;
1551 } else {
1552 qla_printk(KERN_ERR, ha,
1553 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1554 ha->fw_major_version, ha->fw_minor_version,
1555 ha->fw_subminor_version);
1556 }
1557 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001558failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559 if (rval) {
1560 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001561 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 }
1563
1564 return (rval);
1565}
1566
1567/**
1568 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1569 * @ha: HA context
1570 *
1571 * Beginning of request ring has initialization control block already built
1572 * by nvram config routine.
1573 *
1574 * Returns 0 on success.
1575 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001576void
1577qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578{
1579 uint16_t cnt;
1580 response_t *pkt;
1581
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001582 rsp->ring_ptr = rsp->ring;
1583 rsp->ring_index = 0;
1584 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585 pkt = rsp->ring_ptr;
1586 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587 pkt->signature = RESPONSE_PROCESSED;
1588 pkt++;
1589 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590}
1591
1592/**
1593 * qla2x00_update_fw_options() - Read and process firmware options.
1594 * @ha: HA context
1595 *
1596 * Returns 0 on success.
1597 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001598void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001599qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
1601 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001602 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
1604 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001605 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606
1607 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1608 return;
1609
1610 /* Serial Link options. */
1611 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1614 sizeof(ha->fw_seriallink_options)));
1615
1616 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1617 if (ha->fw_seriallink_options[3] & BIT_2) {
1618 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1619
1620 /* 1G settings */
1621 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1622 emphasis = (ha->fw_seriallink_options[2] &
1623 (BIT_4 | BIT_3)) >> 3;
1624 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001625 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 rx_sens = (ha->fw_seriallink_options[0] &
1627 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1628 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1629 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1630 if (rx_sens == 0x0)
1631 rx_sens = 0x3;
1632 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1633 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1634 ha->fw_options[10] |= BIT_5 |
1635 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1636 (tx_sens & (BIT_1 | BIT_0));
1637
1638 /* 2G settings */
1639 swing = (ha->fw_seriallink_options[2] &
1640 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1641 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1642 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001643 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 rx_sens = (ha->fw_seriallink_options[1] &
1645 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1646 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1647 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1648 if (rx_sens == 0x0)
1649 rx_sens = 0x3;
1650 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1651 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1652 ha->fw_options[11] |= BIT_5 |
1653 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1654 (tx_sens & (BIT_1 | BIT_0));
1655 }
1656
1657 /* FCP2 options. */
1658 /* Return command IOCBs without waiting for an ABTS to complete. */
1659 ha->fw_options[3] |= BIT_13;
1660
1661 /* LED scheme. */
1662 if (ha->flags.enable_led_scheme)
1663 ha->fw_options[2] |= BIT_12;
1664
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001665 /* Detect ISP6312. */
1666 if (IS_QLA6312(ha))
1667 ha->fw_options[2] |= BIT_13;
1668
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671}
1672
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001673void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001674qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001675{
1676 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001677 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001678
Giridhar Malavalia9083012010-04-12 17:59:55 -07001679 if (IS_QLA82XX(ha))
1680 return;
1681
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001682 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001683 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001684 return;
1685
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001686 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001687 le16_to_cpu(ha->fw_seriallink_options24[1]),
1688 le16_to_cpu(ha->fw_seriallink_options24[2]),
1689 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001690 if (rval != QLA_SUCCESS) {
1691 qla_printk(KERN_WARNING, ha,
1692 "Unable to update Serial Link options (%x).\n", rval);
1693 }
1694}
1695
1696void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001697qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001698{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001699 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001700 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001701 struct req_que *req = ha->req_q_map[0];
1702 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001703
1704 /* Setup ring parameters in initialization control block. */
1705 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1706 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001707 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1708 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1709 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1710 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1711 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1712 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001713
1714 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1715 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1716 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1717 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1718 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1719}
1720
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001721void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001722qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001723{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001724 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001725 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1726 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1727 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001728 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001729 uint16_t rid = 0;
1730 struct req_que *req = ha->req_q_map[0];
1731 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001732
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001733/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001734 icb = (struct init_cb_24xx *)ha->init_cb;
1735 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1736 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001737 icb->request_q_length = cpu_to_le16(req->length);
1738 icb->response_q_length = cpu_to_le16(rsp->length);
1739 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1740 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1741 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1742 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001743
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001744 if (ha->mqenable) {
1745 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1746 icb->rid = __constant_cpu_to_le16(rid);
1747 if (ha->flags.msix_enabled) {
1748 msix = &ha->msix_entries[1];
1749 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001750 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001751 icb->msix = cpu_to_le16(msix->entry);
1752 }
1753 /* Use alternate PCI bus number */
1754 if (MSB(rid))
1755 icb->firmware_options_2 |=
1756 __constant_cpu_to_le32(BIT_19);
1757 /* Use alternate PCI devfn */
1758 if (LSB(rid))
1759 icb->firmware_options_2 |=
1760 __constant_cpu_to_le32(BIT_18);
1761
Anirban Chakraborty31557542009-12-02 10:36:55 -08001762 /* Use Disable MSIX Handshake mode for capable adapters */
1763 if (IS_MSIX_NACK_CAPABLE(ha)) {
1764 icb->firmware_options_2 &=
1765 __constant_cpu_to_le32(~BIT_22);
1766 ha->flags.disable_msix_handshake = 1;
1767 qla_printk(KERN_INFO, ha,
1768 "MSIX Handshake Disable Mode turned on\n");
1769 } else {
1770 icb->firmware_options_2 |=
1771 __constant_cpu_to_le32(BIT_22);
1772 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001773 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001774
1775 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1776 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1777 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1778 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1779 } else {
1780 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1781 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1782 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1783 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1784 }
1785 /* PCI posting */
1786 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001787}
1788
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789/**
1790 * qla2x00_init_rings() - Initializes firmware.
1791 * @ha: HA context
1792 *
1793 * Beginning of request ring has initialization control block already built
1794 * by nvram config routine.
1795 *
1796 * Returns 0 on success.
1797 */
1798static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001799qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800{
1801 int rval;
1802 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001803 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001804 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001805 struct req_que *req;
1806 struct rsp_que *rsp;
1807 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001808 struct mid_init_cb_24xx *mid_init_cb =
1809 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
1811 spin_lock_irqsave(&ha->hardware_lock, flags);
1812
1813 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001814 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001815 req = ha->req_q_map[que];
1816 if (!req)
1817 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001818 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001819 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001821 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001822
1823 /* Initialize firmware. */
1824 req->ring_ptr = req->ring;
1825 req->ring_index = 0;
1826 req->cnt = req->length;
1827 }
1828
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001829 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001830 rsp = ha->rsp_q_map[que];
1831 if (!rsp)
1832 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001833 /* Initialize response queue entries */
1834 qla2x00_init_response_q_entries(rsp);
1835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
Dan Carpenter542bce12010-10-15 11:27:38 -07001837 spin_lock(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001839 list_for_each_entry(vp, &ha->vp_list, list) {
1840 vp->rscn_in_ptr = 0;
1841 vp->rscn_out_ptr = 0;
1842 }
Arun Easifeafb7b2010-09-03 14:57:00 -07001843
Dan Carpenter542bce12010-10-15 11:27:38 -07001844 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001845
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001846 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847
1848 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1849
1850 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001851 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001853 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001854
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001855 if (ha->flags.npiv_supported) {
1856 if (ha->operating_mode == LOOP)
1857 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001858 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001859 }
1860
Andrew Vasquez24a08132009-03-24 09:08:16 -07001861 if (IS_FWI2_CAPABLE(ha)) {
1862 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1863 mid_init_cb->init_cb.execution_throttle =
1864 cpu_to_le16(ha->fw_xcb_count);
1865 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001866
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001867 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 if (rval) {
1869 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001870 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 } else {
1872 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001873 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 }
1875
1876 return (rval);
1877}
1878
1879/**
1880 * qla2x00_fw_ready() - Waits for firmware ready.
1881 * @ha: HA context
1882 *
1883 * Returns 0 on success.
1884 */
1885static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001886qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887{
1888 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001889 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890 uint16_t min_wait; /* Minimum wait time if loop is down */
1891 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001892 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001893 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894
1895 rval = QLA_SUCCESS;
1896
1897 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001898 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
1900 /*
1901 * Firmware should take at most one RATOV to login, plus 5 seconds for
1902 * our own processing.
1903 */
1904 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1905 wait_time = min_wait;
1906 }
1907
1908 /* Min wait time if loop down */
1909 mtime = jiffies + (min_wait * HZ);
1910
1911 /* wait time before firmware ready */
1912 wtime = jiffies + (wait_time * HZ);
1913
1914 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1917
1918 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920
1921 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001922 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001923 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001924 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001927 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1928 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001930 state[2]));
1931 if ((state[2] & FSTATE_LOGGED_IN) &&
1932 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1933 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001934 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001935
1936 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001938 if (rval != QLA_SUCCESS)
1939 break;
1940
1941 /* Add time taken to initialize. */
1942 cs84xx_time = jiffies - cs84xx_time;
1943 wtime += cs84xx_time;
1944 mtime += cs84xx_time;
1945 DEBUG16(printk("scsi(%ld): Increasing "
1946 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001947 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001948 }
1949 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001951 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954 &ha->login_timeout, &ha->r_a_tov);
1955
1956 rval = QLA_SUCCESS;
1957 break;
1958 }
1959
1960 rval = QLA_FUNCTION_FAILED;
1961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001963 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001965 * other than Wait for Login.
1966 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967 if (time_after_eq(jiffies, mtime)) {
1968 qla_printk(KERN_INFO, ha,
1969 "Cable is unplugged...\n");
1970
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001971 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001972 break;
1973 }
1974 }
1975 } else {
1976 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001977 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08001978 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 break;
1980 }
1981
1982 if (time_after_eq(jiffies, wtime))
1983 break;
1984
1985 /* Delay for a while */
1986 msleep(500);
1987
1988 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 } while (1);
1991
Andrew Vasquez656e8912009-06-03 09:55:29 -07001992 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1993 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1994 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
1996 if (rval) {
1997 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 }
2000
2001 return (rval);
2002}
2003
2004/*
2005* qla2x00_configure_hba
2006* Setup adapter context.
2007*
2008* Input:
2009* ha = adapter state pointer.
2010*
2011* Returns:
2012* 0 = success
2013*
2014* Context:
2015* Kernel context.
2016*/
2017static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002018qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019{
2020 int rval;
2021 uint16_t loop_id;
2022 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002023 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 uint8_t al_pa;
2025 uint8_t area;
2026 uint8_t domain;
2027 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002028 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029
2030 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002032 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Andrew Vasquez7a44b862010-12-21 16:00:23 -08002035 IS_QLA8XXX_TYPE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002036 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2037 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002039 } else {
2040 qla_printk(KERN_WARNING, ha,
2041 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002042 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002043 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 return (rval);
2045 }
2046
2047 if (topo == 4) {
2048 qla_printk(KERN_INFO, ha,
2049 "Cannot get topology - retrying.\n");
2050 return (QLA_FUNCTION_FAILED);
2051 }
2052
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
2055 /* initialize */
2056 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2057 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002058 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
2060 switch (topo) {
2061 case 0:
2062 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 ha->current_topology = ISP_CFG_NL;
2065 strcpy(connect_type, "(Loop)");
2066 break;
2067
2068 case 1:
2069 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002070 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002071 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 ha->current_topology = ISP_CFG_FL;
2073 strcpy(connect_type, "(FL_Port)");
2074 break;
2075
2076 case 2:
2077 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002078 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 ha->operating_mode = P2P;
2080 ha->current_topology = ISP_CFG_N;
2081 strcpy(connect_type, "(N_Port-to-N_Port)");
2082 break;
2083
2084 case 3:
2085 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002086 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002087 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 ha->operating_mode = P2P;
2089 ha->current_topology = ISP_CFG_F;
2090 strcpy(connect_type, "(F_Port)");
2091 break;
2092
2093 default:
2094 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2095 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 ha->current_topology = ISP_CFG_NL;
2098 strcpy(connect_type, "(Loop)");
2099 break;
2100 }
2101
2102 /* Save Host port and loop ID. */
2103 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 vha->d_id.b.domain = domain;
2105 vha->d_id.b.area = area;
2106 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002108 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 qla_printk(KERN_INFO, ha,
2110 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002111 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
2113 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002114 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002116 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 }
2118
2119 return(rval);
2120}
2121
Giridhar Malavalia9083012010-04-12 17:59:55 -07002122inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002123qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2124 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002125{
2126 char *st, *en;
2127 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002128 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002129 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002130 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002131
2132 if (memcmp(model, BINZERO, len) != 0) {
2133 strncpy(ha->model_number, model, len);
2134 st = en = ha->model_number;
2135 en += len - 1;
2136 while (en > st) {
2137 if (*en != 0x20 && *en != 0x00)
2138 break;
2139 *en-- = '\0';
2140 }
2141
2142 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002143 if (use_tbl &&
2144 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002145 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002146 strncpy(ha->model_desc,
2147 qla2x00_model_name[index * 2 + 1],
2148 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002149 } else {
2150 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002151 if (use_tbl &&
2152 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002153 index < QLA_MODEL_NAMES) {
2154 strcpy(ha->model_number,
2155 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002156 strncpy(ha->model_desc,
2157 qla2x00_model_name[index * 2 + 1],
2158 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002159 } else {
2160 strcpy(ha->model_number, def);
2161 }
2162 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002163 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002165 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002166}
2167
David Miller4e08df32007-04-16 12:37:43 -07002168/* On sparc systems, obtain port and node WWN from firmware
2169 * properties.
2170 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002171static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002172{
2173#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002174 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002175 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002176 struct device_node *dp = pci_device_to_OF_node(pdev);
2177 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002178 int len;
2179
2180 val = of_get_property(dp, "port-wwn", &len);
2181 if (val && len >= WWN_SIZE)
2182 memcpy(nv->port_name, val, WWN_SIZE);
2183
2184 val = of_get_property(dp, "node-wwn", &len);
2185 if (val && len >= WWN_SIZE)
2186 memcpy(nv->node_name, val, WWN_SIZE);
2187#endif
2188}
2189
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190/*
2191* NVRAM configuration for ISP 2xxx
2192*
2193* Input:
2194* ha = adapter block pointer.
2195*
2196* Output:
2197* initialization control block in response_ring
2198* host adapters parameters in host adapter block
2199*
2200* Returns:
2201* 0 = success.
2202*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002203int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002204qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205{
David Miller4e08df32007-04-16 12:37:43 -07002206 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002207 uint8_t chksum = 0;
2208 uint16_t cnt;
2209 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002210 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002211 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002212 nvram_t *nv = ha->nvram;
2213 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002214 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
David Miller4e08df32007-04-16 12:37:43 -07002216 rval = QLA_SUCCESS;
2217
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002219 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 ha->nvram_base = 0;
2221 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2222 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2223 ha->nvram_base = 0x80;
2224
2225 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002226 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002227 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2228 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002229
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002230 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002231 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 /* Bad NVRAM data, set defaults parameters. */
2234 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2235 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2236 /* Reset NVRAM data. */
2237 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2238 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2239 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002240 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2241 "invalid -- WWPN) defaults.\n");
2242
2243 /*
2244 * Set default initialization control block.
2245 */
2246 memset(nv, 0, ha->nvram_size);
2247 nv->parameter_block_version = ICB_VERSION;
2248
2249 if (IS_QLA23XX(ha)) {
2250 nv->firmware_options[0] = BIT_2 | BIT_1;
2251 nv->firmware_options[1] = BIT_7 | BIT_5;
2252 nv->add_firmware_options[0] = BIT_5;
2253 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2254 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2255 nv->special_options[1] = BIT_7;
2256 } else if (IS_QLA2200(ha)) {
2257 nv->firmware_options[0] = BIT_2 | BIT_1;
2258 nv->firmware_options[1] = BIT_7 | BIT_5;
2259 nv->add_firmware_options[0] = BIT_5;
2260 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2261 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2262 } else if (IS_QLA2100(ha)) {
2263 nv->firmware_options[0] = BIT_3 | BIT_1;
2264 nv->firmware_options[1] = BIT_5;
2265 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2266 }
2267
2268 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2269 nv->execution_throttle = __constant_cpu_to_le16(16);
2270 nv->retry_count = 8;
2271 nv->retry_delay = 1;
2272
2273 nv->port_name[0] = 33;
2274 nv->port_name[3] = 224;
2275 nv->port_name[4] = 139;
2276
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002278
2279 nv->login_timeout = 4;
2280
2281 /*
2282 * Set default host adapter parameters
2283 */
2284 nv->host_p[1] = BIT_2;
2285 nv->reset_delay = 5;
2286 nv->port_down_retry_count = 8;
2287 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2288 nv->link_down_timeout = 60;
2289
2290 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291 }
2292
2293#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2294 /*
2295 * The SN2 does not provide BIOS emulation which means you can't change
2296 * potentially bogus BIOS settings. Force the use of default settings
2297 * for link rate and frame size. Hope that the rest of the settings
2298 * are valid.
2299 */
2300 if (ia64_platform_is("sn2")) {
2301 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2302 if (IS_QLA23XX(ha))
2303 nv->special_options[1] = BIT_7;
2304 }
2305#endif
2306
2307 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002308 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
2310 /*
2311 * Setup driver NVRAM options.
2312 */
2313 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2314 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2315 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2316 nv->firmware_options[1] &= ~BIT_4;
2317
2318 if (IS_QLA23XX(ha)) {
2319 nv->firmware_options[0] |= BIT_2;
2320 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002321 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002322 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
2324 if (IS_QLA2300(ha)) {
2325 if (ha->fb_rev == FPM_2310) {
2326 strcpy(ha->model_number, "QLA2310");
2327 } else {
2328 strcpy(ha->model_number, "QLA2300");
2329 }
2330 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002332 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333 }
2334 } else if (IS_QLA2200(ha)) {
2335 nv->firmware_options[0] |= BIT_2;
2336 /*
2337 * 'Point-to-point preferred, else loop' is not a safe
2338 * connection mode setting.
2339 */
2340 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2341 (BIT_5 | BIT_4)) {
2342 /* Force 'loop preferred, else point-to-point'. */
2343 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2344 nv->add_firmware_options[0] |= BIT_5;
2345 }
2346 strcpy(ha->model_number, "QLA22xx");
2347 } else /*if (IS_QLA2100(ha))*/ {
2348 strcpy(ha->model_number, "QLA2100");
2349 }
2350
2351 /*
2352 * Copy over NVRAM RISC parameter block to initialization control block.
2353 */
2354 dptr1 = (uint8_t *)icb;
2355 dptr2 = (uint8_t *)&nv->parameter_block_version;
2356 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2357 while (cnt--)
2358 *dptr1++ = *dptr2++;
2359
2360 /* Copy 2nd half. */
2361 dptr1 = (uint8_t *)icb->add_firmware_options;
2362 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2363 while (cnt--)
2364 *dptr1++ = *dptr2++;
2365
Andrew Vasquez5341e862006-05-17 15:09:16 -07002366 /* Use alternate WWN? */
2367 if (nv->host_p[1] & BIT_7) {
2368 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2369 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2370 }
2371
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 /* Prepare nodename */
2373 if ((icb->firmware_options[1] & BIT_6) == 0) {
2374 /*
2375 * Firmware will apply the following mask if the nodename was
2376 * not provided.
2377 */
2378 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2379 icb->node_name[0] &= 0xF0;
2380 }
2381
2382 /*
2383 * Set host adapter parameters.
2384 */
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002385
2386 /*
2387 * BIT_7 in the host-parameters section allows for modification to
2388 * internal driver logging.
2389 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002390 if (nv->host_p[0] & BIT_7)
Saurav Kashyap3ce88662011-07-14 12:00:12 -07002391 ql2xextended_error_logging = 0x7fffffff;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2393 /* Always load RISC code on non ISP2[12]00 chips. */
2394 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2395 ha->flags.disable_risc_code_load = 0;
2396 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2397 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2398 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002399 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002400 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
2402 ha->operating_mode =
2403 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2404
2405 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2406 sizeof(ha->fw_seriallink_options));
2407
2408 /* save HBA serial number */
2409 ha->serial0 = icb->port_name[5];
2410 ha->serial1 = icb->port_name[6];
2411 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2413 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414
2415 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2416
2417 ha->retry_count = nv->retry_count;
2418
2419 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002420 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 nv->login_timeout = ql2xlogintimeout;
2422 if (nv->login_timeout < 4)
2423 nv->login_timeout = 4;
2424 ha->login_timeout = nv->login_timeout;
2425 icb->login_timeout = nv->login_timeout;
2426
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002427 /* Set minimum RATOV to 100 tenths of a second. */
2428 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 ha->loop_reset_delay = nv->reset_delay;
2431
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 /* Link Down Timeout = 0:
2433 *
2434 * When Port Down timer expires we will start returning
2435 * I/O's to OS with "DID_NO_CONNECT".
2436 *
2437 * Link Down Timeout != 0:
2438 *
2439 * The driver waits for the link to come up after link down
2440 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002441 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 if (nv->link_down_timeout == 0) {
2443 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002444 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 } else {
2446 ha->link_down_timeout = nv->link_down_timeout;
2447 ha->loop_down_abort_time =
2448 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 /*
2452 * Need enough time to try and get the port back.
2453 */
2454 ha->port_down_retry_count = nv->port_down_retry_count;
2455 if (qlport_down_retry)
2456 ha->port_down_retry_count = qlport_down_retry;
2457 /* Set login_retry_count */
2458 ha->login_retry_count = nv->retry_count;
2459 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2460 ha->port_down_retry_count > 3)
2461 ha->login_retry_count = ha->port_down_retry_count;
2462 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2463 ha->login_retry_count = ha->port_down_retry_count;
2464 if (ql2xloginretrycount)
2465 ha->login_retry_count = ql2xloginretrycount;
2466
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 icb->lun_enables = __constant_cpu_to_le16(0);
2468 icb->command_resource_count = 0;
2469 icb->immediate_notify_resource_count = 0;
2470 icb->timeout = __constant_cpu_to_le16(0);
2471
2472 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2473 /* Enable RIO */
2474 icb->firmware_options[0] &= ~BIT_3;
2475 icb->add_firmware_options[0] &=
2476 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2477 icb->add_firmware_options[0] |= BIT_2;
2478 icb->response_accumulation_timer = 3;
2479 icb->interrupt_delay_timer = 5;
2480
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002483 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002485 ha->zio_mode = icb->add_firmware_options[0] &
2486 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2487 ha->zio_timer = icb->interrupt_delay_timer ?
2488 icb->interrupt_delay_timer: 2;
2489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 icb->add_firmware_options[0] &=
2491 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002493 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002494 ha->zio_mode = QLA_ZIO_MODE_6;
2495
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002496 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002498 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002500 "ZIO mode %d enabled; timer delay (%d us).\n",
2501 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002503 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2504 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 }
2507 }
2508
David Miller4e08df32007-04-16 12:37:43 -07002509 if (rval) {
2510 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002511 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002512 }
2513 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002514}
2515
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002516static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002517qla2x00_rport_del(void *data)
2518{
2519 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002520 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002521 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002522
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002523 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002524 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002525 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002526 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002527 if (rport)
2528 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002529}
2530
Linus Torvalds1da177e2005-04-16 15:20:36 -07002531/**
2532 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2533 * @ha: HA context
2534 * @flags: allocation flags
2535 *
2536 * Returns a pointer to the allocated fcport, or NULL, if none available.
2537 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002538fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540{
2541 fc_port_t *fcport;
2542
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002543 fcport = kzalloc(sizeof(fc_port_t), flags);
2544 if (!fcport)
2545 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546
2547 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 fcport->vha = vha;
2549 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 fcport->port_type = FCT_UNKNOWN;
2551 fcport->loop_id = FC_NO_LOOP_ID;
Chad Dupuisec426e12011-03-30 11:46:32 -07002552 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002553 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002555 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556}
2557
2558/*
2559 * qla2x00_configure_loop
2560 * Updates Fibre Channel Device Database with what is actually on loop.
2561 *
2562 * Input:
2563 * ha = adapter block pointer.
2564 *
2565 * Returns:
2566 * 0 = success.
2567 * 1 = error.
2568 * 2 = database was full and device was not configured.
2569 */
2570static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002571qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572{
2573 int rval;
2574 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002575 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 rval = QLA_SUCCESS;
2577
2578 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2580 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 if (rval != QLA_SUCCESS) {
2582 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 return (rval);
2585 }
2586 }
2587
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002588 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591
2592 /*
2593 * If we have both an RSCN and PORT UPDATE pending then handle them
2594 * both at the same time.
2595 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2597 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598
Michael Hernandez3064ff32009-12-15 21:29:44 -08002599 qla2x00_get_data_rate(vha);
2600
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 /* Determine what we need to do */
2602 if (ha->current_topology == ISP_CFG_FL &&
2603 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2604
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 set_bit(RSCN_UPDATE, &flags);
2607
2608 } else if (ha->current_topology == ISP_CFG_F &&
2609 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2610
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 set_bit(RSCN_UPDATE, &flags);
2613 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2614
Andrew Vasquez21333b42006-05-17 15:09:56 -07002615 } else if (ha->current_topology == ISP_CFG_N) {
2616 clear_bit(RSCN_UPDATE, &flags);
2617
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2620
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 set_bit(RSCN_UPDATE, &flags);
2623 set_bit(LOCAL_LOOP_UPDATE, &flags);
2624 }
2625
2626 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 else
2630 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 }
2632
2633 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002636 else
2637 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 }
2639
2640 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 if (atomic_read(&vha->loop_down_timer) ||
2642 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 rval = QLA_FUNCTION_FAILED;
2644 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 }
2649 }
2650
2651 if (rval) {
2652 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 } else {
2655 DEBUG3(printk("%s: exiting normally\n", __func__));
2656 }
2657
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002658 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002659 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002660 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002662 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002663 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002664 if (!IS_ALOGIO_CAPABLE(ha))
2665 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002666 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 }
2668
2669 return (rval);
2670}
2671
2672
2673
2674/*
2675 * qla2x00_configure_local_loop
2676 * Updates Fibre Channel Device Database with local loop devices.
2677 *
2678 * Input:
2679 * ha = adapter block pointer.
2680 *
2681 * Returns:
2682 * 0 = success.
2683 */
2684static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686{
2687 int rval, rval2;
2688 int found_devs;
2689 int found;
2690 fc_port_t *fcport, *new_fcport;
2691
2692 uint16_t index;
2693 uint16_t entries;
2694 char *id_iter;
2695 uint16_t loop_id;
2696 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698
2699 found_devs = 0;
2700 new_fcport = NULL;
2701 entries = MAX_FIBRE_DEVICES;
2702
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002703 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2704 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
2706 /* Get list of logged in devices. */
2707 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 &entries);
2710 if (rval != QLA_SUCCESS)
2711 goto cleanup_allocation;
2712
2713 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002714 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2716 entries * sizeof(struct gid_list_info)));
2717
2718 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 if (new_fcport == NULL) {
2721 rval = QLA_MEMORY_ALLOC_FAILED;
2722 goto cleanup_allocation;
2723 }
2724 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2725
2726 /*
2727 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2728 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002729 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2731 fcport->port_type != FCT_BROADCAST &&
2732 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2733
2734 DEBUG(printk("scsi(%ld): Marking port lost, "
2735 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737
Chad Dupuisec426e12011-03-30 11:46:32 -07002738 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 }
2740 }
2741
2742 /* Add devices to port list. */
2743 id_iter = (char *)ha->gid_list;
2744 for (index = 0; index < entries; index++) {
2745 domain = ((struct gid_list_info *)id_iter)->domain;
2746 area = ((struct gid_list_info *)id_iter)->area;
2747 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002748 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 loop_id = (uint16_t)
2750 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002751 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 loop_id = le16_to_cpu(
2753 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002754 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755
2756 /* Bypass reserved domain fields. */
2757 if ((domain & 0xf0) == 0xf0)
2758 continue;
2759
2760 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002761 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002762 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 continue;
2764
2765 /* Bypass invalid local loop ID. */
2766 if (loop_id > LAST_LOCAL_LOOP_ID)
2767 continue;
2768
2769 /* Fill in member data. */
2770 new_fcport->d_id.b.domain = domain;
2771 new_fcport->d_id.b.area = area;
2772 new_fcport->d_id.b.al_pa = al_pa;
2773 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002774 new_fcport->vp_idx = vha->vp_idx;
2775 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 if (rval2 != QLA_SUCCESS) {
2777 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2778 "information -- get_port_database=%x, "
2779 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002780 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002781 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002782 vha->host_no));
2783 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784 continue;
2785 }
2786
2787 /* Check for matching device in port list. */
2788 found = 0;
2789 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002790 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 if (memcmp(new_fcport->port_name, fcport->port_name,
2792 WWN_SIZE))
2793 continue;
2794
Shyam Sundarddb9b122009-03-24 09:08:10 -07002795 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 fcport->loop_id = new_fcport->loop_id;
2797 fcport->port_type = new_fcport->port_type;
2798 fcport->d_id.b24 = new_fcport->d_id.b24;
2799 memcpy(fcport->node_name, new_fcport->node_name,
2800 WWN_SIZE);
2801
2802 found++;
2803 break;
2804 }
2805
2806 if (!found) {
2807 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002808 if (vha->vp_idx) {
2809 new_fcport->vha = vha;
2810 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002811 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 /* Allocate a new replacement fcport. */
2815 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 if (new_fcport == NULL) {
2818 rval = QLA_MEMORY_ALLOC_FAILED;
2819 goto cleanup_allocation;
2820 }
2821 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2822 }
2823
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002824 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002825 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002826
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
2829 found_devs++;
2830 }
2831
2832cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002833 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834
2835 if (rval != QLA_SUCCESS) {
2836 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 }
2839
Linus Torvalds1da177e2005-04-16 15:20:36 -07002840 return (rval);
2841}
2842
2843static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002845{
2846#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002847 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2848 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002849 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002850 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002852
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002853 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002854 return;
2855
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002856 if (atomic_read(&fcport->state) != FCS_ONLINE)
2857 return;
2858
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002859 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2860 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002861 return;
2862
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002864 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002865 if (rval != QLA_SUCCESS) {
2866 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2867 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002869 fcport->port_name[2], fcport->port_name[3],
2870 fcport->port_name[4], fcport->port_name[5],
2871 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002872 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002873 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002874 link_speed = link_speeds[LS_UNKNOWN];
2875 if (fcport->fp_speed < 5)
2876 link_speed = link_speeds[fcport->fp_speed];
2877 else if (fcport->fp_speed == 0x13)
2878 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002879 DEBUG2(qla_printk(KERN_INFO, ha,
2880 "iIDMA adjusted to %s GB/s on "
2881 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002882 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002883 fcport->port_name[1], fcport->port_name[2],
2884 fcport->port_name[3], fcport->port_name[4],
2885 fcport->port_name[5], fcport->port_name[6],
2886 fcport->port_name[7]));
2887 }
2888}
2889
Adrian Bunk23be3312006-11-24 02:46:01 +01002890static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002892{
2893 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002894 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895 struct qla_hw_data *ha = vha->hw;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002896 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002897
Andrew Vasquezac280b62009-08-20 11:06:05 -07002898 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002899
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002900 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2901 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002902 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2903 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2904 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002906 if (!rport) {
2907 qla_printk(KERN_WARNING, ha,
2908 "Unable to allocate fc remote port!\n");
2909 return;
2910 }
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002911 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002912 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002913 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002914
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002915 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002916
2917 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002918 if (fcport->port_type == FCT_INITIATOR)
2919 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2920 if (fcport->port_type == FCT_TARGET)
2921 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002922 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002923}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924
2925/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002926 * qla2x00_update_fcport
2927 * Updates device on list.
2928 *
2929 * Input:
2930 * ha = adapter block pointer.
2931 * fcport = port structure pointer.
2932 *
2933 * Return:
2934 * 0 - Success
2935 * BIT_0 - error
2936 *
2937 * Context:
2938 * Kernel context.
2939 */
2940void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002941qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002942{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002944 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002945 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002948 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949 qla2x00_reg_remote_port(vha, fcport);
Chad Dupuisec426e12011-03-30 11:46:32 -07002950 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002951}
2952
2953/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 * qla2x00_configure_fabric
2955 * Setup SNS devices with loop ID's.
2956 *
2957 * Input:
2958 * ha = adapter block pointer.
2959 *
2960 * Returns:
2961 * 0 = success.
2962 * BIT_0 = error
2963 */
2964static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966{
2967 int rval, rval2;
2968 fc_port_t *fcport, *fcptemp;
2969 uint16_t next_loopid;
2970 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002971 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 struct qla_hw_data *ha = vha->hw;
2974 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975
2976 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002977 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002978 loop_id = NPH_F_PORT;
2979 else
2980 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002981 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002982 if (rval != QLA_SUCCESS) {
2983 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002986 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 return (QLA_SUCCESS);
2988 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990
2991 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 if (rval2 == QLA_RSCNS_HANDLED) {
2994 /* No point doing the scan, just continue. */
2995 return (QLA_SUCCESS);
2996 }
2997 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002998 /* FDMI support. */
2999 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003000 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
3001 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07003002
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07003004 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003005 loop_id = NPH_SNS;
3006 else
3007 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003009 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 if (mb[0] != MBS_COMMAND_COMPLETE) {
3011 DEBUG2(qla_printk(KERN_INFO, ha,
3012 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003013 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 mb[0], mb[1], mb[2], mb[6], mb[7]));
3015 return (QLA_SUCCESS);
3016 }
3017
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3019 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 /* EMPTY */
3021 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 /* EMPTY */
3026 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003027 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 /* EMPTY */
3031 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 "failed.\n", vha->host_no));
3033 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 /* EMPTY */
3035 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 }
3038 }
3039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 if (rval != QLA_SUCCESS)
3042 break;
3043
3044 /*
3045 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003046 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3049 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 break;
3051
3052 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3053 continue;
3054
3055 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003056 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003057 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003059 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 fcport->port_type != FCT_INITIATOR &&
3061 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003063 fcport->loop_id,
3064 fcport->d_id.b.domain,
3065 fcport->d_id.b.area,
3066 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 fcport->loop_id = FC_NO_LOOP_ID;
3068 }
3069 }
3070 }
3071
3072 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003073 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074
3075 /*
3076 * Scan through our port list and login entries that need to be
3077 * logged in.
3078 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3080 if (atomic_read(&vha->loop_down_timer) ||
3081 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003082 break;
3083
3084 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3085 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3086 continue;
3087
3088 if (fcport->loop_id == FC_NO_LOOP_ID) {
3089 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07003090 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 if (rval != QLA_SUCCESS) {
3093 /* Ran out of IDs to use */
3094 break;
3095 }
3096 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003098 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 }
3100
3101 /* Exit if out of loop IDs. */
3102 if (rval != QLA_SUCCESS) {
3103 break;
3104 }
3105
3106 /*
3107 * Login and add the new devices to our port list.
3108 */
3109 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003110 if (atomic_read(&vha->loop_down_timer) ||
3111 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 break;
3113
3114 /* Find a new loop ID to use. */
3115 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003116 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117 if (rval != QLA_SUCCESS) {
3118 /* Ran out of IDs to use */
3119 break;
3120 }
3121
bdf79622005-04-17 15:06:53 -05003122 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003123 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003124
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 if (vha->vp_idx) {
3126 fcport->vha = vha;
3127 fcport->vp_idx = vha->vp_idx;
3128 }
3129 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003130 }
3131 } while (0);
3132
3133 /* Free all new device structures not processed. */
3134 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3135 list_del(&fcport->list);
3136 kfree(fcport);
3137 }
3138
3139 if (rval) {
3140 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 }
3143
3144 return (rval);
3145}
3146
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147/*
3148 * qla2x00_find_all_fabric_devs
3149 *
3150 * Input:
3151 * ha = adapter block pointer.
3152 * dev = database device entry pointer.
3153 *
3154 * Returns:
3155 * 0 = success.
3156 *
3157 * Context:
3158 * Kernel context.
3159 */
3160static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003161qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3162 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163{
3164 int rval;
3165 uint16_t loop_id;
3166 fc_port_t *fcport, *new_fcport, *fcptemp;
3167 int found;
3168
3169 sw_info_t *swl;
3170 int swl_idx;
3171 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003172 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 struct qla_hw_data *ha = vha->hw;
3174 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003175 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176
3177 rval = QLA_SUCCESS;
3178
3179 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003180 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003181 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 /*EMPTY*/
3183 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 kfree(swl);
3188 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003189 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 kfree(swl);
3191 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 kfree(swl);
3194 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003195 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003196 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3197 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003199
3200 /* If other queries succeeded probe for FC-4 type */
3201 if (swl)
3202 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 }
3204 swl_idx = 0;
3205
3206 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003209 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 return (QLA_MEMORY_ALLOC_FAILED);
3211 }
3212 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 /* Set start port ID scan at adapter ID. */
3214 first_dev = 1;
3215 last_dev = 0;
3216
3217 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003218 loop_id = ha->min_external_loopid;
3219 for (; loop_id <= ha->max_loop_id; loop_id++) {
3220 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 continue;
3222
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003223 if (ha->current_topology == ISP_CFG_FL &&
3224 (atomic_read(&vha->loop_down_timer) ||
3225 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003226 atomic_set(&vha->loop_down_timer, 0);
3227 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3228 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003230 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231
3232 if (swl != NULL) {
3233 if (last_dev) {
3234 wrap.b24 = new_fcport->d_id.b24;
3235 } else {
3236 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3237 memcpy(new_fcport->node_name,
3238 swl[swl_idx].node_name, WWN_SIZE);
3239 memcpy(new_fcport->port_name,
3240 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003241 memcpy(new_fcport->fabric_port_name,
3242 swl[swl_idx].fabric_port_name, WWN_SIZE);
3243 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003244 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
3246 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3247 last_dev = 1;
3248 }
3249 swl_idx++;
3250 }
3251 } else {
3252 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 if (rval != QLA_SUCCESS) {
3255 qla_printk(KERN_WARNING, ha,
3256 "SNS scan failed -- assuming zero-entry "
3257 "result...\n");
3258 list_for_each_entry_safe(fcport, fcptemp,
3259 new_fcports, list) {
3260 list_del(&fcport->list);
3261 kfree(fcport);
3262 }
3263 rval = QLA_SUCCESS;
3264 break;
3265 }
3266 }
3267
3268 /* If wrap on switch device list, exit. */
3269 if (first_dev) {
3270 wrap.b24 = new_fcport->d_id.b24;
3271 first_dev = 0;
3272 } else if (new_fcport->d_id.b24 == wrap.b24) {
3273 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003274 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3276 break;
3277 }
3278
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003279 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281 continue;
3282
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003283 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003284 found = 0;
3285 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003286 unsigned long flags;
3287
3288 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003289 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003290 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3291 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003292 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003294 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003295 spin_unlock_irqrestore(&ha->vport_slock, flags);
3296
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003298 continue;
3299 }
3300
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003301 /* Bypass if same domain and area of adapter. */
3302 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003304 ISP_CFG_FL)
3305 continue;
3306
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 /* Bypass reserved domain fields. */
3308 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3309 continue;
3310
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003311 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003312 if (ql2xgffidenable &&
3313 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3314 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003315 continue;
3316
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 /* Locate matching device in database. */
3318 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 if (memcmp(new_fcport->port_name, fcport->port_name,
3321 WWN_SIZE))
3322 continue;
3323
3324 found++;
3325
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003326 /* Update port state. */
3327 memcpy(fcport->fabric_port_name,
3328 new_fcport->fabric_port_name, WWN_SIZE);
3329 fcport->fp_speed = new_fcport->fp_speed;
3330
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 /*
3332 * If address the same and state FCS_ONLINE, nothing
3333 * changed.
3334 */
3335 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3336 atomic_read(&fcport->state) == FCS_ONLINE) {
3337 break;
3338 }
3339
3340 /*
3341 * If device was not a fabric device before.
3342 */
3343 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3344 fcport->d_id.b24 = new_fcport->d_id.b24;
3345 fcport->loop_id = FC_NO_LOOP_ID;
3346 fcport->flags |= (FCF_FABRIC_DEVICE |
3347 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 break;
3349 }
3350
3351 /*
3352 * Port ID changed or device was marked to be updated;
3353 * Log it out if still logged in and mark it for
3354 * relogin later.
3355 */
3356 fcport->d_id.b24 = new_fcport->d_id.b24;
3357 fcport->flags |= FCF_LOGIN_NEEDED;
3358 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003359 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 fcport->port_type != FCT_INITIATOR &&
3361 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003362 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003363 fcport->d_id.b.domain, fcport->d_id.b.area,
3364 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 fcport->loop_id = FC_NO_LOOP_ID;
3366 }
3367
3368 break;
3369 }
3370
3371 if (found)
3372 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 /* If device was not in our fcports list, then add it. */
3374 list_add_tail(&new_fcport->list, new_fcports);
3375
3376 /* Allocate a new replacement fcport. */
3377 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003380 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 return (QLA_MEMORY_ALLOC_FAILED);
3382 }
3383 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3384 new_fcport->d_id.b24 = nxt_d_id.b24;
3385 }
3386
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003387 kfree(swl);
3388 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 return (rval);
3391}
3392
3393/*
3394 * qla2x00_find_new_loop_id
3395 * Scan through our port list and find a new usable loop ID.
3396 *
3397 * Input:
3398 * ha: adapter state pointer.
3399 * dev: port structure pointer.
3400 *
3401 * Returns:
3402 * qla2x00 local function return status code.
3403 *
3404 * Context:
3405 * Kernel context.
3406 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003407int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409{
3410 int rval;
3411 int found;
3412 fc_port_t *fcport;
3413 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 struct qla_hw_data *ha = vha->hw;
3415 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003416 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003417 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418
3419 rval = QLA_SUCCESS;
3420
3421 /* Save starting loop ID. */
3422 first_loop_id = dev->loop_id;
3423
3424 for (;;) {
3425 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003426 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428
3429 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432
3433 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003434 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435 /* first loop ID. */
3436 dev->loop_id = ha->min_external_loopid;
3437 }
3438
3439 /* Check for loop ID being already in use. */
3440 found = 0;
3441 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003442
3443 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003444 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003445 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3446 if (fcport->loop_id == dev->loop_id &&
3447 fcport != dev) {
3448 /* ID possibly in use */
3449 found++;
3450 break;
3451 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003453 if (found)
3454 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003456 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
3458 /* If not in use then it is free to use. */
3459 if (!found) {
3460 break;
3461 }
3462
3463 /* ID in use. Try next value. */
3464 dev->loop_id++;
3465
3466 /* If wrap around. No free ID to use. */
3467 if (dev->loop_id == first_loop_id) {
3468 dev->loop_id = FC_NO_LOOP_ID;
3469 rval = QLA_FUNCTION_FAILED;
3470 break;
3471 }
3472 }
3473
3474 return (rval);
3475}
3476
3477/*
3478 * qla2x00_device_resync
3479 * Marks devices in the database that needs resynchronization.
3480 *
3481 * Input:
3482 * ha = adapter block pointer.
3483 *
3484 * Context:
3485 * Kernel context.
3486 */
3487static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003488qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489{
3490 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 uint32_t mask;
3492 fc_port_t *fcport;
3493 uint32_t rscn_entry;
3494 uint8_t rscn_out_iter;
3495 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003496 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497
3498 rval = QLA_RSCNS_HANDLED;
3499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3501 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003503 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 format = MSB(MSW(rscn_entry));
3505 d_id.b.domain = LSB(MSW(rscn_entry));
3506 d_id.b.area = MSB(LSW(rscn_entry));
3507 d_id.b.al_pa = LSB(LSW(rscn_entry));
3508
3509 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3510 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003511 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512 d_id.b.area, d_id.b.al_pa));
3513
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514 vha->rscn_out_ptr++;
3515 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3516 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517
3518 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003519 for (rscn_out_iter = vha->rscn_out_ptr;
3520 !vha->flags.rscn_queue_overflow &&
3521 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 rscn_out_iter = (rscn_out_iter ==
3523 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3524
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 break;
3527
3528 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003529 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 rscn_out_iter));
3531
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533 }
3534
3535 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003536 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539
3540 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 }
3543
3544 switch (format) {
3545 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 mask = 0xffffff;
3547 break;
3548 case 1:
3549 mask = 0xffff00;
3550 break;
3551 case 2:
3552 mask = 0xff0000;
3553 break;
3554 default:
3555 mask = 0x0;
3556 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 break;
3559 }
3560
3561 rval = QLA_SUCCESS;
3562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003563 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003564 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3565 (fcport->d_id.b24 & mask) != d_id.b24 ||
3566 fcport->port_type == FCT_BROADCAST)
3567 continue;
3568
3569 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3570 if (format != 3 ||
3571 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003573 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 }
3575 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 }
3577 }
3578 return (rval);
3579}
3580
3581/*
3582 * qla2x00_fabric_dev_login
3583 * Login fabric target device and update FC port database.
3584 *
3585 * Input:
3586 * ha: adapter state pointer.
3587 * fcport: port structure list pointer.
3588 * next_loopid: contains value of a new loop ID that can be used
3589 * by the next login attempt.
3590 *
3591 * Returns:
3592 * qla2x00 local function return status code.
3593 *
3594 * Context:
3595 * Kernel context.
3596 */
3597static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003598qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 uint16_t *next_loopid)
3600{
3601 int rval;
3602 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003603 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003604 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605
3606 rval = QLA_SUCCESS;
3607 retry = 0;
3608
Andrew Vasquezac280b62009-08-20 11:06:05 -07003609 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003610 if (fcport->flags & FCF_ASYNC_SENT)
3611 return rval;
3612 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003613 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3614 if (!rval)
3615 return rval;
3616 }
3617
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003618 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003619 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003621 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003622 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003623 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003624 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003625 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003626 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003627 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003628 fcport->d_id.b.domain, fcport->d_id.b.area,
3629 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003630 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003632 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 }
3634 }
3635
3636 return (rval);
3637}
3638
3639/*
3640 * qla2x00_fabric_login
3641 * Issue fabric login command.
3642 *
3643 * Input:
3644 * ha = adapter block pointer.
3645 * device = pointer to FC device type structure.
3646 *
3647 * Returns:
3648 * 0 - Login successfully
3649 * 1 - Login failed
3650 * 2 - Initiator device
3651 * 3 - Fatal error
3652 */
3653int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003654qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655 uint16_t *next_loopid)
3656{
3657 int rval;
3658 int retry;
3659 uint16_t tmp_loopid;
3660 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003661 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003662
3663 retry = 0;
3664 tmp_loopid = 0;
3665
3666 for (;;) {
3667 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3668 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003669 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3671
3672 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003673 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 fcport->d_id.b.domain, fcport->d_id.b.area,
3675 fcport->d_id.b.al_pa, mb, BIT_0);
3676 if (mb[0] == MBS_PORT_ID_USED) {
3677 /*
3678 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003679 * recommends the driver perform an implicit login with
3680 * the specified ID again. The ID we just used is save
3681 * here so we return with an ID that can be tried by
3682 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003683 */
3684 retry++;
3685 tmp_loopid = fcport->loop_id;
3686 fcport->loop_id = mb[1];
3687
3688 DEBUG(printk("Fabric Login: port in use - next "
3689 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3690 fcport->loop_id, fcport->d_id.b.domain,
3691 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3692
3693 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3694 /*
3695 * Login succeeded.
3696 */
3697 if (retry) {
3698 /* A retry occurred before. */
3699 *next_loopid = tmp_loopid;
3700 } else {
3701 /*
3702 * No retry occurred before. Just increment the
3703 * ID value for next login.
3704 */
3705 *next_loopid = (fcport->loop_id + 1);
3706 }
3707
3708 if (mb[1] & BIT_0) {
3709 fcport->port_type = FCT_INITIATOR;
3710 } else {
3711 fcport->port_type = FCT_TARGET;
3712 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003713 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 }
3715 }
3716
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003717 if (mb[10] & BIT_0)
3718 fcport->supported_classes |= FC_COS_CLASS2;
3719 if (mb[10] & BIT_1)
3720 fcport->supported_classes |= FC_COS_CLASS3;
3721
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 rval = QLA_SUCCESS;
3723 break;
3724 } else if (mb[0] == MBS_LOOP_ID_USED) {
3725 /*
3726 * Loop ID already used, try next loop ID.
3727 */
3728 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003729 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730 if (rval != QLA_SUCCESS) {
3731 /* Ran out of loop IDs to use */
3732 break;
3733 }
3734 } else if (mb[0] == MBS_COMMAND_ERROR) {
3735 /*
3736 * Firmware possibly timed out during login. If NO
3737 * retries are left to do then the device is declared
3738 * dead.
3739 */
3740 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003741 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003742 fcport->d_id.b.domain, fcport->d_id.b.area,
3743 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003744 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745
3746 rval = 1;
3747 break;
3748 } else {
3749 /*
3750 * unrecoverable / not handled error
3751 */
3752 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003753 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003754 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755 fcport->d_id.b.domain, fcport->d_id.b.area,
3756 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3757
3758 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003759 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003760 fcport->d_id.b.domain, fcport->d_id.b.area,
3761 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003763 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764
3765 rval = 3;
3766 break;
3767 }
3768 }
3769
3770 return (rval);
3771}
3772
3773/*
3774 * qla2x00_local_device_login
3775 * Issue local device login command.
3776 *
3777 * Input:
3778 * ha = adapter block pointer.
3779 * loop_id = loop id of device to login to.
3780 *
3781 * Returns (Where's the #define!!!!):
3782 * 0 - Login successfully
3783 * 1 - Login failed
3784 * 3 - Fatal error
3785 */
3786int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003787qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788{
3789 int rval;
3790 uint16_t mb[MAILBOX_REGISTER_COUNT];
3791
3792 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003793 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 if (rval == QLA_SUCCESS) {
3795 /* Interrogate mailbox registers for any errors */
3796 if (mb[0] == MBS_COMMAND_ERROR)
3797 rval = 1;
3798 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3799 /* device not in PCB table */
3800 rval = 3;
3801 }
3802
3803 return (rval);
3804}
3805
3806/*
3807 * qla2x00_loop_resync
3808 * Resync with fibre channel devices.
3809 *
3810 * Input:
3811 * ha = adapter block pointer.
3812 *
3813 * Returns:
3814 * 0 = success
3815 */
3816int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003819 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003821 struct req_que *req;
3822 struct rsp_que *rsp;
3823
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003824 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003825 req = vha->hw->req_q_map[0];
3826 else
3827 req = vha->req;
3828 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 atomic_set(&vha->loop_state, LOOP_UPDATE);
3831 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3832 if (vha->flags.online) {
3833 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3835 wait_time = 256;
3836 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003837 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003839 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003840 qla2x00_marker(vha, req, rsp, 0, 0,
3841 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003842 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003843
3844 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003845 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003846
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003847 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003849 } while (!atomic_read(&vha->loop_down_timer) &&
3850 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3851 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3852 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003853 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003854 }
3855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003857 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003859 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003861
3862 return (rval);
3863}
3864
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003865/*
3866* qla2x00_perform_loop_resync
3867* Description: This function will set the appropriate flags and call
3868* qla2x00_loop_resync. If successful loop will be resynced
3869* Arguments : scsi_qla_host_t pointer
3870* returm : Success or Failure
3871*/
3872
3873int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3874{
3875 int32_t rval = 0;
3876
3877 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3878 /*Configure the flags so that resync happens properly*/
3879 atomic_set(&ha->loop_down_timer, 0);
3880 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3881 atomic_set(&ha->loop_state, LOOP_UP);
3882 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3883 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3884 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3885
3886 rval = qla2x00_loop_resync(ha);
3887 } else
3888 atomic_set(&ha->loop_state, LOOP_DEAD);
3889
3890 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3891 }
3892
3893 return rval;
3894}
3895
Linus Torvalds1da177e2005-04-16 15:20:36 -07003896void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003897qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003898{
3899 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003900 struct scsi_qla_host *vha;
3901 struct qla_hw_data *ha = base_vha->hw;
3902 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003903
Arun Easifeafb7b2010-09-03 14:57:00 -07003904 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003905 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003906 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3907 atomic_inc(&vha->vref_count);
3908 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003909 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003910 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3911 spin_unlock_irqrestore(&ha->vport_slock, flags);
3912
Andrew Vasquez67becc02009-08-25 11:36:20 -07003913 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003914
3915 spin_lock_irqsave(&ha->vport_slock, flags);
3916 }
3917 }
3918 atomic_dec(&vha->vref_count);
3919 }
3920 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003921}
3922
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003923/*
3924* qla82xx_quiescent_state_cleanup
3925* Description: This function will block the new I/Os
3926* Its not aborting any I/Os as context
3927* is not destroyed during quiescence
3928* Arguments: scsi_qla_host_t
3929* return : void
3930*/
3931void
3932qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3933{
3934 struct qla_hw_data *ha = vha->hw;
3935 struct scsi_qla_host *vp;
3936
3937 qla_printk(KERN_INFO, ha,
3938 "Performing ISP error recovery - ha= %p.\n", ha);
3939
3940 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3941 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3942 atomic_set(&vha->loop_state, LOOP_DOWN);
3943 qla2x00_mark_all_devices_lost(vha, 0);
3944 list_for_each_entry(vp, &ha->vp_list, list)
3945 qla2x00_mark_all_devices_lost(vha, 0);
3946 } else {
3947 if (!atomic_read(&vha->loop_down_timer))
3948 atomic_set(&vha->loop_down_timer,
3949 LOOP_DOWN_TIME);
3950 }
3951 /* Wait for pending cmds to complete */
3952 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3953}
3954
Giridhar Malavalia9083012010-04-12 17:59:55 -07003955void
3956qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3957{
3958 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003959 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003960 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003961 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003962
Saurav Kashyape46ef002011-02-23 15:27:16 -08003963 /* For ISP82XX, driver waits for completion of the commands.
3964 * online flag should be set.
3965 */
3966 if (!IS_QLA82XX(ha))
3967 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003968 ha->flags.chip_reset_done = 0;
3969 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3970 ha->qla_stats.total_isp_aborts++;
3971
3972 qla_printk(KERN_INFO, ha,
3973 "Performing ISP error recovery - ha= %p.\n", ha);
3974
Saurav Kashyape46ef002011-02-23 15:27:16 -08003975 /* For ISP82XX, reset_chip is just disabling interrupts.
3976 * Driver waits for the completion of the commands.
3977 * the interrupts need to be enabled.
3978 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003979 if (!IS_QLA82XX(ha))
3980 ha->isp_ops->reset_chip(vha);
3981
3982 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3983 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3984 atomic_set(&vha->loop_state, LOOP_DOWN);
3985 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003986
3987 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003988 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003989 atomic_inc(&vp->vref_count);
3990 spin_unlock_irqrestore(&ha->vport_slock, flags);
3991
Giridhar Malavalia9083012010-04-12 17:59:55 -07003992 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003993
3994 spin_lock_irqsave(&ha->vport_slock, flags);
3995 atomic_dec(&vp->vref_count);
3996 }
3997 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003998 } else {
3999 if (!atomic_read(&vha->loop_down_timer))
4000 atomic_set(&vha->loop_down_timer,
4001 LOOP_DOWN_TIME);
4002 }
4003
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08004004 /* Clear all async request states across all VPs. */
4005 list_for_each_entry(fcport, &vha->vp_fcports, list)
4006 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4007 spin_lock_irqsave(&ha->vport_slock, flags);
4008 list_for_each_entry(vp, &ha->vp_list, list) {
4009 atomic_inc(&vp->vref_count);
4010 spin_unlock_irqrestore(&ha->vport_slock, flags);
4011
4012 list_for_each_entry(fcport, &vp->vp_fcports, list)
4013 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
4014
4015 spin_lock_irqsave(&ha->vport_slock, flags);
4016 atomic_dec(&vp->vref_count);
4017 }
4018 spin_unlock_irqrestore(&ha->vport_slock, flags);
4019
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004020 if (!ha->flags.eeh_busy) {
4021 /* Make sure for ISP 82XX IO DMA is complete */
4022 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004023 qla82xx_chip_reset_cleanup(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004024
Saurav Kashyape46ef002011-02-23 15:27:16 -08004025 /* Done waiting for pending commands.
4026 * Reset the online flag.
4027 */
4028 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004030
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004031 /* Requeue all commands in outstanding command list. */
4032 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034}
4035
4036/*
4037* qla2x00_abort_isp
4038* Resets ISP and aborts all outstanding commands.
4039*
4040* Input:
4041* ha = adapter block pointer.
4042*
4043* Returns:
4044* 0 = success
4045*/
4046int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004047qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004048{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004049 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051 struct qla_hw_data *ha = vha->hw;
4052 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004053 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004054 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004057 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058
Andrew Vasquez85880802009-12-15 21:29:46 -08004059 if (unlikely(pci_channel_offline(ha->pdev) &&
4060 ha->flags.pci_channel_io_perm_failure)) {
4061 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4062 status = 0;
4063 return status;
4064 }
4065
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004066 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004067
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004068 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004070 if (!qla2x00_restart_isp(vha)) {
4071 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004073 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 /*
4075 * Issue marker command only when we are going
4076 * to start the I/O .
4077 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004078 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004079 }
4080
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004081 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004082
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004083 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004084
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004085 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004086 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004087
Lalit Chandivade29c53972009-10-13 15:16:47 -07004088 if (IS_QLA81XX(ha))
4089 qla2x00_get_fw_version(vha,
4090 &ha->fw_major_version,
4091 &ha->fw_minor_version,
4092 &ha->fw_subminor_version,
4093 &ha->fw_attributes, &ha->fw_memory_size,
4094 ha->mpi_version, &ha->mpi_capabilities,
4095 ha->phy_version);
4096
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004097 if (ha->fce) {
4098 ha->flags.fce_enabled = 1;
4099 memset(ha->fce, 0,
4100 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004101 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004102 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4103 &ha->fce_bufs);
4104 if (rval) {
4105 qla_printk(KERN_WARNING, ha,
4106 "Unable to reinitialize FCE "
4107 "(%d).\n", rval);
4108 ha->flags.fce_enabled = 0;
4109 }
4110 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004111
4112 if (ha->eft) {
4113 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004114 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004115 ha->eft_dma, EFT_NUM_BUFFERS);
4116 if (rval) {
4117 qla_printk(KERN_WARNING, ha,
4118 "Unable to reinitialize EFT "
4119 "(%d).\n", rval);
4120 }
4121 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004122 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004123 vha->flags.online = 1;
4124 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 if (ha->isp_abort_cnt == 0) {
4126 qla_printk(KERN_WARNING, ha,
4127 "ISP error recovery failed - "
4128 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004129 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 * The next call disables the board
4131 * completely.
4132 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133 ha->isp_ops->reset_adapter(vha);
4134 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004136 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137 status = 0;
4138 } else { /* schedule another ISP abort */
4139 ha->isp_abort_cnt--;
4140 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004141 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 status = 1;
4144 }
4145 } else {
4146 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4147 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4148 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004149 vha->host_no, ha->isp_abort_cnt));
4150 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004151 status = 1;
4152 }
4153 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004154
Linus Torvalds1da177e2005-04-16 15:20:36 -07004155 }
4156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004157 if (!status) {
4158 DEBUG(printk(KERN_INFO
4159 "qla2x00_abort_isp(%ld): succeeded.\n",
4160 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07004161
4162 spin_lock_irqsave(&ha->vport_slock, flags);
4163 list_for_each_entry(vp, &ha->vp_list, list) {
4164 if (vp->vp_idx) {
4165 atomic_inc(&vp->vref_count);
4166 spin_unlock_irqrestore(&ha->vport_slock, flags);
4167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004168 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004169
4170 spin_lock_irqsave(&ha->vport_slock, flags);
4171 atomic_dec(&vp->vref_count);
4172 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004174 spin_unlock_irqrestore(&ha->vport_slock, flags);
4175
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 qla_printk(KERN_INFO, ha,
4178 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 }
4180
4181 return(status);
4182}
4183
4184/*
4185* qla2x00_restart_isp
4186* restarts the ISP after a reset
4187*
4188* Input:
4189* ha = adapter block pointer.
4190*
4191* Returns:
4192* 0 = success
4193*/
4194static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004195qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004197 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004198 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004199 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004200 struct req_que *req = ha->req_q_map[0];
4201 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202
4203 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004204 if (qla2x00_isp_firmware(vha)) {
4205 vha->flags.online = 0;
4206 status = ha->isp_ops->chip_diag(vha);
4207 if (!status)
4208 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004209 }
4210
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004211 if (!status && !(status = qla2x00_init_rings(vha))) {
4212 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004213 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004214 /* Initialize the queues in use */
4215 qla25xx_init_queues(ha);
4216
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004217 status = qla2x00_fw_ready(vha);
4218 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004219 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004220 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004221
4222 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004223 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004224
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004225 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4227 wait_time = 256;
4228 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004229 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4230 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004231 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 } while (!atomic_read(&vha->loop_down_timer) &&
4233 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4234 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4235 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004236 }
4237
4238 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004239 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004240 status = 0;
4241
4242 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4243 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004244 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 }
4246 return (status);
4247}
4248
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004249static int
4250qla25xx_init_queues(struct qla_hw_data *ha)
4251{
4252 struct rsp_que *rsp = NULL;
4253 struct req_que *req = NULL;
4254 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4255 int ret = -1;
4256 int i;
4257
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004258 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004259 rsp = ha->rsp_q_map[i];
4260 if (rsp) {
4261 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004262 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004263 if (ret != QLA_SUCCESS)
4264 DEBUG2_17(printk(KERN_WARNING
4265 "%s Rsp que:%d init failed\n", __func__,
4266 rsp->id));
4267 else
4268 DEBUG2_17(printk(KERN_INFO
4269 "%s Rsp que:%d inited\n", __func__,
4270 rsp->id));
4271 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004272 }
4273 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004274 req = ha->req_q_map[i];
4275 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004276 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004277 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004278 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004279 if (ret != QLA_SUCCESS)
4280 DEBUG2_17(printk(KERN_WARNING
4281 "%s Req que:%d init failed\n", __func__,
4282 req->id));
4283 else
4284 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004285 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004286 req->id));
4287 }
4288 }
4289 return ret;
4290}
4291
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292/*
4293* qla2x00_reset_adapter
4294* Reset adapter.
4295*
4296* Input:
4297* ha = adapter block pointer.
4298*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004299void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004300qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004301{
4302 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004303 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004304 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004306 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004307 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004308
Linus Torvalds1da177e2005-04-16 15:20:36 -07004309 spin_lock_irqsave(&ha->hardware_lock, flags);
4310 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4311 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4312 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4313 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4314 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4315}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004316
4317void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004318qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004319{
4320 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004321 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004322 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4323
Giridhar Malavalia9083012010-04-12 17:59:55 -07004324 if (IS_QLA82XX(ha))
4325 return;
4326
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004327 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004328 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004329
4330 spin_lock_irqsave(&ha->hardware_lock, flags);
4331 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4332 RD_REG_DWORD(&reg->hccr);
4333 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4334 RD_REG_DWORD(&reg->hccr);
4335 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004336
4337 if (IS_NOPOLLING_TYPE(ha))
4338 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004339}
4340
David Miller4e08df32007-04-16 12:37:43 -07004341/* On sparc systems, obtain port and node WWN from firmware
4342 * properties.
4343 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004344static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4345 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004346{
4347#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004348 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004349 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004350 struct device_node *dp = pci_device_to_OF_node(pdev);
4351 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004352 int len;
4353
4354 val = of_get_property(dp, "port-wwn", &len);
4355 if (val && len >= WWN_SIZE)
4356 memcpy(nv->port_name, val, WWN_SIZE);
4357
4358 val = of_get_property(dp, "node-wwn", &len);
4359 if (val && len >= WWN_SIZE)
4360 memcpy(nv->node_name, val, WWN_SIZE);
4361#endif
4362}
4363
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004364int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004365qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004366{
David Miller4e08df32007-04-16 12:37:43 -07004367 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004368 struct init_cb_24xx *icb;
4369 struct nvram_24xx *nv;
4370 uint32_t *dptr;
4371 uint8_t *dptr1, *dptr2;
4372 uint32_t chksum;
4373 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004374 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004375
David Miller4e08df32007-04-16 12:37:43 -07004376 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004377 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004378 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004379
4380 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004381 if (ha->flags.port0) {
4382 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4383 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4384 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004385 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004386 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4387 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004388 ha->nvram_size = sizeof(struct nvram_24xx);
4389 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004390 if (IS_QLA82XX(ha))
4391 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004392
Seokmann Ju281afe12007-07-26 13:43:34 -07004393 /* Get VPD data into cache */
4394 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004395 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004396 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4397
4398 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004399 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004400 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004401 ha->nvram_size);
4402 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4403 chksum += le32_to_cpu(*dptr++);
4404
Andrew Vasquez76403352009-04-06 22:33:39 -07004405 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004406 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004407
4408 /* Bad NVRAM data, set defaults parameters. */
4409 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4410 || nv->id[3] != ' ' ||
4411 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4412 /* Reset NVRAM data. */
4413 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4414 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4415 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004416 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4417 "invalid -- WWPN) defaults.\n");
4418
4419 /*
4420 * Set default initialization control block.
4421 */
4422 memset(nv, 0, ha->nvram_size);
4423 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4424 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4425 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4426 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4427 nv->exchange_count = __constant_cpu_to_le16(0);
4428 nv->hard_address = __constant_cpu_to_le16(124);
4429 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004430 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004431 nv->port_name[2] = 0x00;
4432 nv->port_name[3] = 0xe0;
4433 nv->port_name[4] = 0x8b;
4434 nv->port_name[5] = 0x1c;
4435 nv->port_name[6] = 0x55;
4436 nv->port_name[7] = 0x86;
4437 nv->node_name[0] = 0x20;
4438 nv->node_name[1] = 0x00;
4439 nv->node_name[2] = 0x00;
4440 nv->node_name[3] = 0xe0;
4441 nv->node_name[4] = 0x8b;
4442 nv->node_name[5] = 0x1c;
4443 nv->node_name[6] = 0x55;
4444 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004445 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004446 nv->login_retry_count = __constant_cpu_to_le16(8);
4447 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4448 nv->login_timeout = __constant_cpu_to_le16(0);
4449 nv->firmware_options_1 =
4450 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4451 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4452 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4453 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4454 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4455 nv->efi_parameters = __constant_cpu_to_le32(0);
4456 nv->reset_delay = 5;
4457 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4458 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4459 nv->link_down_timeout = __constant_cpu_to_le16(30);
4460
4461 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004462 }
4463
4464 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004465 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004466
4467 /* Copy 1st segment. */
4468 dptr1 = (uint8_t *)icb;
4469 dptr2 = (uint8_t *)&nv->version;
4470 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4471 while (cnt--)
4472 *dptr1++ = *dptr2++;
4473
4474 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004475 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004476
4477 /* Copy 2nd segment. */
4478 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4479 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4480 cnt = (uint8_t *)&icb->reserved_3 -
4481 (uint8_t *)&icb->interrupt_delay_timer;
4482 while (cnt--)
4483 *dptr1++ = *dptr2++;
4484
4485 /*
4486 * Setup driver NVRAM options.
4487 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004488 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004489 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004490
Andrew Vasquez5341e862006-05-17 15:09:16 -07004491 /* Use alternate WWN? */
4492 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4493 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4494 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4495 }
4496
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004497 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004498 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004499 /*
4500 * Firmware will apply the following mask if the nodename was
4501 * not provided.
4502 */
4503 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4504 icb->node_name[0] &= 0xF0;
4505 }
4506
4507 /* Set host adapter parameters. */
4508 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004509 ha->flags.enable_lip_reset = 0;
4510 ha->flags.enable_lip_full_login =
4511 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4512 ha->flags.enable_target_reset =
4513 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004514 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004515 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004516
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004517 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4518 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004519
4520 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4521 sizeof(ha->fw_seriallink_options24));
4522
4523 /* save HBA serial number */
4524 ha->serial0 = icb->port_name[5];
4525 ha->serial1 = icb->port_name[6];
4526 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004527 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4528 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004529
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004530 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4531
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004532 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4533
4534 /* Set minimum login_timeout to 4 seconds. */
4535 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4536 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4537 if (le16_to_cpu(nv->login_timeout) < 4)
4538 nv->login_timeout = __constant_cpu_to_le16(4);
4539 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004540 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004541
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004542 /* Set minimum RATOV to 100 tenths of a second. */
4543 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004544
4545 ha->loop_reset_delay = nv->reset_delay;
4546
4547 /* Link Down Timeout = 0:
4548 *
4549 * When Port Down timer expires we will start returning
4550 * I/O's to OS with "DID_NO_CONNECT".
4551 *
4552 * Link Down Timeout != 0:
4553 *
4554 * The driver waits for the link to come up after link down
4555 * before returning I/Os to OS with "DID_NO_CONNECT".
4556 */
4557 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4558 ha->loop_down_abort_time =
4559 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4560 } else {
4561 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4562 ha->loop_down_abort_time =
4563 (LOOP_DOWN_TIME - ha->link_down_timeout);
4564 }
4565
4566 /* Need enough time to try and get the port back. */
4567 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4568 if (qlport_down_retry)
4569 ha->port_down_retry_count = qlport_down_retry;
4570
4571 /* Set login_retry_count */
4572 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4573 if (ha->port_down_retry_count ==
4574 le16_to_cpu(nv->port_down_retry_count) &&
4575 ha->port_down_retry_count > 3)
4576 ha->login_retry_count = ha->port_down_retry_count;
4577 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4578 ha->login_retry_count = ha->port_down_retry_count;
4579 if (ql2xloginretrycount)
4580 ha->login_retry_count = ql2xloginretrycount;
4581
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004582 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004583 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004584 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4585 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4586 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4587 le16_to_cpu(icb->interrupt_delay_timer): 2;
4588 }
4589 icb->firmware_options_2 &= __constant_cpu_to_le32(
4590 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004591 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004592 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004593 ha->zio_mode = QLA_ZIO_MODE_6;
4594
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004595 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004596 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004597 ha->zio_timer * 100));
4598 qla_printk(KERN_INFO, ha,
4599 "ZIO mode %d enabled; timer delay (%d us).\n",
4600 ha->zio_mode, ha->zio_timer * 100);
4601
4602 icb->firmware_options_2 |= cpu_to_le32(
4603 (uint32_t)ha->zio_mode);
4604 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004605 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004606 }
4607
David Miller4e08df32007-04-16 12:37:43 -07004608 if (rval) {
4609 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004610 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004611 }
4612 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004613}
4614
Adrian Bunk413975a2006-06-30 02:33:06 -07004615static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004616qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4617 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004618{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004619 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004620 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004621 uint32_t *dcode, dlen;
4622 uint32_t risc_addr;
4623 uint32_t risc_size;
4624 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004625 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004626 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004627
4628 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004629 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004630
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004631 rval = QLA_SUCCESS;
4632
4633 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004634 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004635 *srisc_addr = 0;
4636
4637 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004638 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004639 for (i = 0; i < 4; i++)
4640 dcode[i] = be32_to_cpu(dcode[i]);
4641 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4642 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4643 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4644 dcode[3] == 0)) {
4645 qla_printk(KERN_WARNING, ha,
4646 "Unable to verify integrity of flash firmware image!\n");
4647 qla_printk(KERN_WARNING, ha,
4648 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4649 dcode[1], dcode[2], dcode[3]);
4650
4651 return QLA_FUNCTION_FAILED;
4652 }
4653
4654 while (segments && rval == QLA_SUCCESS) {
4655 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004656 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004657
4658 risc_addr = be32_to_cpu(dcode[2]);
4659 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4660 risc_size = be32_to_cpu(dcode[3]);
4661
4662 fragment = 0;
4663 while (risc_size > 0 && rval == QLA_SUCCESS) {
4664 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4665 if (dlen > risc_size)
4666 dlen = risc_size;
4667
4668 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4669 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004670 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004672 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004673 for (i = 0; i < dlen; i++)
4674 dcode[i] = swab32(dcode[i]);
4675
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004676 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004677 dlen);
4678 if (rval) {
4679 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004680 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004681 fragment));
4682 qla_printk(KERN_WARNING, ha,
4683 "[ERROR] Failed to load segment %d of "
4684 "firmware\n", fragment);
4685 break;
4686 }
4687
4688 faddr += dlen;
4689 risc_addr += dlen;
4690 risc_size -= dlen;
4691 fragment++;
4692 }
4693
4694 /* Next segment. */
4695 segments--;
4696 }
4697
4698 return rval;
4699}
4700
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004701#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4702
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004703int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004704qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004705{
4706 int rval;
4707 int i, fragment;
4708 uint16_t *wcode, *fwcode;
4709 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4710 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004711 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004712 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004713
4714 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004715 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004716 if (!blob) {
4717 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004718 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4719 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004720 return QLA_FUNCTION_FAILED;
4721 }
4722
4723 rval = QLA_SUCCESS;
4724
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004725 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004726 *srisc_addr = 0;
4727 fwcode = (uint16_t *)blob->fw->data;
4728 fwclen = 0;
4729
4730 /* Validate firmware image by checking version. */
4731 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4732 qla_printk(KERN_WARNING, ha,
4733 "Unable to verify integrity of firmware image (%Zd)!\n",
4734 blob->fw->size);
4735 goto fail_fw_integrity;
4736 }
4737 for (i = 0; i < 4; i++)
4738 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4739 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4740 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4741 wcode[2] == 0 && wcode[3] == 0)) {
4742 qla_printk(KERN_WARNING, ha,
4743 "Unable to verify integrity of firmware image!\n");
4744 qla_printk(KERN_WARNING, ha,
4745 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4746 wcode[1], wcode[2], wcode[3]);
4747 goto fail_fw_integrity;
4748 }
4749
4750 seg = blob->segs;
4751 while (*seg && rval == QLA_SUCCESS) {
4752 risc_addr = *seg;
4753 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4754 risc_size = be16_to_cpu(fwcode[3]);
4755
4756 /* Validate firmware image size. */
4757 fwclen += risc_size * sizeof(uint16_t);
4758 if (blob->fw->size < fwclen) {
4759 qla_printk(KERN_WARNING, ha,
4760 "Unable to verify integrity of firmware image "
4761 "(%Zd)!\n", blob->fw->size);
4762 goto fail_fw_integrity;
4763 }
4764
4765 fragment = 0;
4766 while (risc_size > 0 && rval == QLA_SUCCESS) {
4767 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4768 if (wlen > risc_size)
4769 wlen = risc_size;
4770
4771 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004772 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004773 risc_addr, wlen));
4774
4775 for (i = 0; i < wlen; i++)
4776 wcode[i] = swab16(fwcode[i]);
4777
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004778 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004779 wlen);
4780 if (rval) {
4781 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004782 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004783 fragment));
4784 qla_printk(KERN_WARNING, ha,
4785 "[ERROR] Failed to load segment %d of "
4786 "firmware\n", fragment);
4787 break;
4788 }
4789
4790 fwcode += wlen;
4791 risc_addr += wlen;
4792 risc_size -= wlen;
4793 fragment++;
4794 }
4795
4796 /* Next segment. */
4797 seg++;
4798 }
4799 return rval;
4800
4801fail_fw_integrity:
4802 return QLA_FUNCTION_FAILED;
4803}
4804
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004805static int
4806qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004807{
4808 int rval;
4809 int segments, fragment;
4810 uint32_t *dcode, dlen;
4811 uint32_t risc_addr;
4812 uint32_t risc_size;
4813 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004814 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004815 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004816 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004817 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004818
Andrew Vasquez54333832005-11-09 15:49:04 -08004819 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004820 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004821 if (!blob) {
4822 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004823 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4824 "from: " QLA_FW_URL ".\n");
4825
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004826 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004827 }
4828
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004829 qla_printk(KERN_INFO, ha,
4830 "FW: Loading via request-firmware...\n");
4831
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004832 rval = QLA_SUCCESS;
4833
4834 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004835 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004836 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004837 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004838 fwclen = 0;
4839
4840 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004841 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004842 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004843 "Unable to verify integrity of firmware image (%Zd)!\n",
4844 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004845 goto fail_fw_integrity;
4846 }
4847 for (i = 0; i < 4; i++)
4848 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4849 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4850 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4851 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4852 dcode[3] == 0)) {
4853 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004854 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004855 qla_printk(KERN_WARNING, ha,
4856 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4857 dcode[1], dcode[2], dcode[3]);
4858 goto fail_fw_integrity;
4859 }
4860
4861 while (segments && rval == QLA_SUCCESS) {
4862 risc_addr = be32_to_cpu(fwcode[2]);
4863 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4864 risc_size = be32_to_cpu(fwcode[3]);
4865
4866 /* Validate firmware image size. */
4867 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004868 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004869 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004870 "Unable to verify integrity of firmware image "
4871 "(%Zd)!\n", blob->fw->size);
4872
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004873 goto fail_fw_integrity;
4874 }
4875
4876 fragment = 0;
4877 while (risc_size > 0 && rval == QLA_SUCCESS) {
4878 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4879 if (dlen > risc_size)
4880 dlen = risc_size;
4881
4882 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004883 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004884 risc_addr, dlen));
4885
4886 for (i = 0; i < dlen; i++)
4887 dcode[i] = swab32(fwcode[i]);
4888
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004889 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004890 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004891 if (rval) {
4892 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004893 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004894 fragment));
4895 qla_printk(KERN_WARNING, ha,
4896 "[ERROR] Failed to load segment %d of "
4897 "firmware\n", fragment);
4898 break;
4899 }
4900
4901 fwcode += dlen;
4902 risc_addr += dlen;
4903 risc_size -= dlen;
4904 fragment++;
4905 }
4906
4907 /* Next segment. */
4908 segments--;
4909 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004910 return rval;
4911
4912fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004913 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004914}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004915
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004916int
4917qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4918{
4919 int rval;
4920
Andrew Vasqueze337d902009-04-06 22:33:49 -07004921 if (ql2xfwloadbin == 1)
4922 return qla81xx_load_risc(vha, srisc_addr);
4923
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004924 /*
4925 * FW Load priority:
4926 * 1) Firmware via request-firmware interface (.bin file).
4927 * 2) Firmware residing in flash.
4928 */
4929 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4930 if (rval == QLA_SUCCESS)
4931 return rval;
4932
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004933 return qla24xx_load_risc_flash(vha, srisc_addr,
4934 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004935}
4936
4937int
4938qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4939{
4940 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004941 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004942
Andrew Vasqueze337d902009-04-06 22:33:49 -07004943 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004944 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004945
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004946 /*
4947 * FW Load priority:
4948 * 1) Firmware residing in flash.
4949 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004950 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004951 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004952 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004953 if (rval == QLA_SUCCESS)
4954 return rval;
4955
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004956try_blob_fw:
4957 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4958 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4959 return rval;
4960
4961 qla_printk(KERN_ERR, ha,
4962 "FW: Attempting to fallback to golden firmware...\n");
4963 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4964 if (rval != QLA_SUCCESS)
4965 return rval;
4966
4967 qla_printk(KERN_ERR, ha,
4968 "FW: Please update operational firmware...\n");
4969 ha->flags.running_gold_fw = 1;
4970
4971 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004972}
4973
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004974void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004975qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004976{
4977 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004978 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004979
Andrew Vasquez85880802009-12-15 21:29:46 -08004980 if (ha->flags.pci_channel_io_perm_failure)
4981 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004982 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004983 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004984 if (!ha->fw_major_version)
4985 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004987 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004988 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004989 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004990 ha->isp_ops->reset_chip(vha);
4991 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004992 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004993 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004994 continue;
4995 qla_printk(KERN_INFO, ha,
4996 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004997 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004998 }
4999}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005000
5001int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005002qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005003{
5004 int rval = QLA_SUCCESS;
5005 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005006 struct qla_hw_data *ha = vha->hw;
5007 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005008 struct req_que *req;
5009 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005010
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005011 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005012 return -EINVAL;
5013
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005014 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07005015 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005016 req = ha->req_q_map[0];
5017 else
5018 req = vha->req;
5019 rsp = req->rsp;
5020
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005021 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005022 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005023 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005024 }
5025
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005026 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005027
5028 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005029 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005030 if (mb[0] != MBS_COMMAND_COMPLETE) {
5031 DEBUG15(qla_printk(KERN_INFO, ha,
5032 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5033 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
5034 mb[0], mb[1], mb[2], mb[6], mb[7]));
5035 return (QLA_FUNCTION_FAILED);
5036 }
5037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005038 atomic_set(&vha->loop_down_timer, 0);
5039 atomic_set(&vha->loop_state, LOOP_UP);
5040 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5041 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5042 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005043
5044 return rval;
5045}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005046
5047/* 84XX Support **************************************************************/
5048
5049static LIST_HEAD(qla_cs84xx_list);
5050static DEFINE_MUTEX(qla_cs84xx_mutex);
5051
5052static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005053qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005054{
5055 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005056 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005057
5058 mutex_lock(&qla_cs84xx_mutex);
5059
5060 /* Find any shared 84xx chip. */
5061 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5062 if (cs84xx->bus == ha->pdev->bus) {
5063 kref_get(&cs84xx->kref);
5064 goto done;
5065 }
5066 }
5067
5068 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5069 if (!cs84xx)
5070 goto done;
5071
5072 kref_init(&cs84xx->kref);
5073 spin_lock_init(&cs84xx->access_lock);
5074 mutex_init(&cs84xx->fw_update_mutex);
5075 cs84xx->bus = ha->pdev->bus;
5076
5077 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5078done:
5079 mutex_unlock(&qla_cs84xx_mutex);
5080 return cs84xx;
5081}
5082
5083static void
5084__qla84xx_chip_release(struct kref *kref)
5085{
5086 struct qla_chip_state_84xx *cs84xx =
5087 container_of(kref, struct qla_chip_state_84xx, kref);
5088
5089 mutex_lock(&qla_cs84xx_mutex);
5090 list_del(&cs84xx->list);
5091 mutex_unlock(&qla_cs84xx_mutex);
5092 kfree(cs84xx);
5093}
5094
5095void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005096qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005097{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005098 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005099 if (ha->cs84xx)
5100 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5101}
5102
5103static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005104qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005105{
5106 int rval;
5107 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005108 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005109
5110 mutex_lock(&ha->cs84xx->fw_update_mutex);
5111
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005112 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005113
5114 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5115
5116 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5117 QLA_SUCCESS;
5118}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005119
5120/* 81XX Support **************************************************************/
5121
5122int
5123qla81xx_nvram_config(scsi_qla_host_t *vha)
5124{
5125 int rval;
5126 struct init_cb_81xx *icb;
5127 struct nvram_81xx *nv;
5128 uint32_t *dptr;
5129 uint8_t *dptr1, *dptr2;
5130 uint32_t chksum;
5131 uint16_t cnt;
5132 struct qla_hw_data *ha = vha->hw;
5133
5134 rval = QLA_SUCCESS;
5135 icb = (struct init_cb_81xx *)ha->init_cb;
5136 nv = ha->nvram;
5137
5138 /* Determine NVRAM starting address. */
5139 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005140 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005141
5142 /* Get VPD data into cache */
5143 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005144 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5145 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005146
5147 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005148 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005149 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005150 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005151 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5152 chksum += le32_to_cpu(*dptr++);
5153
Andrew Vasquez76403352009-04-06 22:33:39 -07005154 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005155 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
5156
5157 /* Bad NVRAM data, set defaults parameters. */
5158 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5159 || nv->id[3] != ' ' ||
5160 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5161 /* Reset NVRAM data. */
5162 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5163 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5164 le16_to_cpu(nv->nvram_version));
5165 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5166 "invalid -- WWPN) defaults.\n");
5167
5168 /*
5169 * Set default initialization control block.
5170 */
5171 memset(nv, 0, ha->nvram_size);
5172 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5173 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5174 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5175 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5176 nv->exchange_count = __constant_cpu_to_le16(0);
5177 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005178 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005179 nv->port_name[2] = 0x00;
5180 nv->port_name[3] = 0xe0;
5181 nv->port_name[4] = 0x8b;
5182 nv->port_name[5] = 0x1c;
5183 nv->port_name[6] = 0x55;
5184 nv->port_name[7] = 0x86;
5185 nv->node_name[0] = 0x20;
5186 nv->node_name[1] = 0x00;
5187 nv->node_name[2] = 0x00;
5188 nv->node_name[3] = 0xe0;
5189 nv->node_name[4] = 0x8b;
5190 nv->node_name[5] = 0x1c;
5191 nv->node_name[6] = 0x55;
5192 nv->node_name[7] = 0x86;
5193 nv->login_retry_count = __constant_cpu_to_le16(8);
5194 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5195 nv->login_timeout = __constant_cpu_to_le16(0);
5196 nv->firmware_options_1 =
5197 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5198 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5199 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5200 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5201 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5202 nv->efi_parameters = __constant_cpu_to_le32(0);
5203 nv->reset_delay = 5;
5204 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5205 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5206 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005207 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005208 nv->enode_mac[1] = 0x02;
5209 nv->enode_mac[2] = 0x03;
5210 nv->enode_mac[3] = 0x04;
5211 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005212 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005213
5214 rval = 1;
5215 }
5216
5217 /* Reset Initialization control block */
Andrew Vasquez773120e2011-05-10 11:30:14 -07005218 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005219
5220 /* Copy 1st segment. */
5221 dptr1 = (uint8_t *)icb;
5222 dptr2 = (uint8_t *)&nv->version;
5223 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5224 while (cnt--)
5225 *dptr1++ = *dptr2++;
5226
5227 icb->login_retry_count = nv->login_retry_count;
5228
5229 /* Copy 2nd segment. */
5230 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5231 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5232 cnt = (uint8_t *)&icb->reserved_5 -
5233 (uint8_t *)&icb->interrupt_delay_timer;
5234 while (cnt--)
5235 *dptr1++ = *dptr2++;
5236
5237 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5238 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5239 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5240 icb->enode_mac[0] = 0x01;
5241 icb->enode_mac[1] = 0x02;
5242 icb->enode_mac[2] = 0x03;
5243 icb->enode_mac[3] = 0x04;
5244 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005245 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005246 }
5247
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005248 /* Use extended-initialization control block. */
5249 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5250
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005251 /*
5252 * Setup driver NVRAM options.
5253 */
5254 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005255 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005256
5257 /* Use alternate WWN? */
5258 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5259 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5260 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5261 }
5262
5263 /* Prepare nodename */
5264 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5265 /*
5266 * Firmware will apply the following mask if the nodename was
5267 * not provided.
5268 */
5269 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5270 icb->node_name[0] &= 0xF0;
5271 }
5272
5273 /* Set host adapter parameters. */
5274 ha->flags.disable_risc_code_load = 0;
5275 ha->flags.enable_lip_reset = 0;
5276 ha->flags.enable_lip_full_login =
5277 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5278 ha->flags.enable_target_reset =
5279 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5280 ha->flags.enable_led_scheme = 0;
5281 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5282
5283 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5284 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5285
5286 /* save HBA serial number */
5287 ha->serial0 = icb->port_name[5];
5288 ha->serial1 = icb->port_name[6];
5289 ha->serial2 = icb->port_name[7];
5290 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5291 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5292
5293 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5294
5295 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5296
5297 /* Set minimum login_timeout to 4 seconds. */
5298 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5299 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5300 if (le16_to_cpu(nv->login_timeout) < 4)
5301 nv->login_timeout = __constant_cpu_to_le16(4);
5302 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5303 icb->login_timeout = nv->login_timeout;
5304
5305 /* Set minimum RATOV to 100 tenths of a second. */
5306 ha->r_a_tov = 100;
5307
5308 ha->loop_reset_delay = nv->reset_delay;
5309
5310 /* Link Down Timeout = 0:
5311 *
5312 * When Port Down timer expires we will start returning
5313 * I/O's to OS with "DID_NO_CONNECT".
5314 *
5315 * Link Down Timeout != 0:
5316 *
5317 * The driver waits for the link to come up after link down
5318 * before returning I/Os to OS with "DID_NO_CONNECT".
5319 */
5320 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5321 ha->loop_down_abort_time =
5322 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5323 } else {
5324 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5325 ha->loop_down_abort_time =
5326 (LOOP_DOWN_TIME - ha->link_down_timeout);
5327 }
5328
5329 /* Need enough time to try and get the port back. */
5330 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5331 if (qlport_down_retry)
5332 ha->port_down_retry_count = qlport_down_retry;
5333
5334 /* Set login_retry_count */
5335 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5336 if (ha->port_down_retry_count ==
5337 le16_to_cpu(nv->port_down_retry_count) &&
5338 ha->port_down_retry_count > 3)
5339 ha->login_retry_count = ha->port_down_retry_count;
5340 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5341 ha->login_retry_count = ha->port_down_retry_count;
5342 if (ql2xloginretrycount)
5343 ha->login_retry_count = ql2xloginretrycount;
5344
5345 /* Enable ZIO. */
5346 if (!vha->flags.init_done) {
5347 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5348 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5349 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5350 le16_to_cpu(icb->interrupt_delay_timer): 2;
5351 }
5352 icb->firmware_options_2 &= __constant_cpu_to_le32(
5353 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5354 vha->flags.process_response_queue = 0;
5355 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5356 ha->zio_mode = QLA_ZIO_MODE_6;
5357
5358 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5359 "(%d us).\n", vha->host_no, ha->zio_mode,
5360 ha->zio_timer * 100));
5361 qla_printk(KERN_INFO, ha,
5362 "ZIO mode %d enabled; timer delay (%d us).\n",
5363 ha->zio_mode, ha->zio_timer * 100);
5364
5365 icb->firmware_options_2 |= cpu_to_le32(
5366 (uint32_t)ha->zio_mode);
5367 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5368 vha->flags.process_response_queue = 1;
5369 }
5370
5371 if (rval) {
5372 DEBUG2_3(printk(KERN_WARNING
5373 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5374 }
5375 return (rval);
5376}
5377
Giridhar Malavalia9083012010-04-12 17:59:55 -07005378int
5379qla82xx_restart_isp(scsi_qla_host_t *vha)
5380{
5381 int status, rval;
5382 uint32_t wait_time;
5383 struct qla_hw_data *ha = vha->hw;
5384 struct req_que *req = ha->req_q_map[0];
5385 struct rsp_que *rsp = ha->rsp_q_map[0];
5386 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005387 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005388
5389 status = qla2x00_init_rings(vha);
5390 if (!status) {
5391 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5392 ha->flags.chip_reset_done = 1;
5393
5394 status = qla2x00_fw_ready(vha);
5395 if (!status) {
5396 qla_printk(KERN_INFO, ha,
5397 "%s(): Start configure loop, "
5398 "status = %d\n", __func__, status);
5399
5400 /* Issue a marker after FW becomes ready. */
5401 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5402
5403 vha->flags.online = 1;
5404 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5405 wait_time = 256;
5406 do {
5407 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5408 qla2x00_configure_loop(vha);
5409 wait_time--;
5410 } while (!atomic_read(&vha->loop_down_timer) &&
5411 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5412 wait_time &&
5413 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5414 }
5415
5416 /* if no cable then assume it's good */
5417 if ((vha->device_flags & DFLG_NO_CABLE))
5418 status = 0;
5419
5420 qla_printk(KERN_INFO, ha,
5421 "%s(): Configure loop done, status = 0x%x\n",
5422 __func__, status);
5423 }
5424
5425 if (!status) {
5426 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5427
5428 if (!atomic_read(&vha->loop_down_timer)) {
5429 /*
5430 * Issue marker command only when we are going
5431 * to start the I/O .
5432 */
5433 vha->marker_needed = 1;
5434 }
5435
5436 vha->flags.online = 1;
5437
5438 ha->isp_ops->enable_intrs(ha);
5439
5440 ha->isp_abort_cnt = 0;
5441 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5442
Saurav Kashyap53296782011-05-10 11:30:06 -07005443 /* Update the firmware version */
5444 qla2x00_get_fw_version(vha, &ha->fw_major_version,
5445 &ha->fw_minor_version, &ha->fw_subminor_version,
5446 &ha->fw_attributes, &ha->fw_memory_size,
5447 ha->mpi_version, &ha->mpi_capabilities,
5448 ha->phy_version);
5449
Giridhar Malavalia9083012010-04-12 17:59:55 -07005450 if (ha->fce) {
5451 ha->flags.fce_enabled = 1;
5452 memset(ha->fce, 0,
5453 fce_calc_size(ha->fce_bufs));
5454 rval = qla2x00_enable_fce_trace(vha,
5455 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5456 &ha->fce_bufs);
5457 if (rval) {
5458 qla_printk(KERN_WARNING, ha,
5459 "Unable to reinitialize FCE "
5460 "(%d).\n", rval);
5461 ha->flags.fce_enabled = 0;
5462 }
5463 }
5464
5465 if (ha->eft) {
5466 memset(ha->eft, 0, EFT_SIZE);
5467 rval = qla2x00_enable_eft_trace(vha,
5468 ha->eft_dma, EFT_NUM_BUFFERS);
5469 if (rval) {
5470 qla_printk(KERN_WARNING, ha,
5471 "Unable to reinitialize EFT "
5472 "(%d).\n", rval);
5473 }
5474 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005475 }
5476
5477 if (!status) {
5478 DEBUG(printk(KERN_INFO
5479 "qla82xx_restart_isp(%ld): succeeded.\n",
5480 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07005481
5482 spin_lock_irqsave(&ha->vport_slock, flags);
5483 list_for_each_entry(vp, &ha->vp_list, list) {
5484 if (vp->vp_idx) {
5485 atomic_inc(&vp->vref_count);
5486 spin_unlock_irqrestore(&ha->vport_slock, flags);
5487
Giridhar Malavalia9083012010-04-12 17:59:55 -07005488 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005489
5490 spin_lock_irqsave(&ha->vport_slock, flags);
5491 atomic_dec(&vp->vref_count);
5492 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005493 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005494 spin_unlock_irqrestore(&ha->vport_slock, flags);
5495
Giridhar Malavalia9083012010-04-12 17:59:55 -07005496 } else {
5497 qla_printk(KERN_INFO, ha,
5498 "qla82xx_restart_isp: **** FAILED ****\n");
5499 }
5500
5501 return status;
5502}
5503
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005504void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005505qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005506{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005507 struct qla_hw_data *ha = vha->hw;
5508
5509 if (!ql2xetsenable)
5510 return;
5511
5512 /* Enable ETS Burst. */
5513 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5514 ha->fw_options[2] |= BIT_9;
5515 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005516}
Sarang Radke09ff7012010-03-19 17:03:59 -07005517
5518/*
5519 * qla24xx_get_fcp_prio
5520 * Gets the fcp cmd priority value for the logged in port.
5521 * Looks for a match of the port descriptors within
5522 * each of the fcp prio config entries. If a match is found,
5523 * the tag (priority) value is returned.
5524 *
5525 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005526 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005527 * fcport = port structure pointer.
5528 *
5529 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005530 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005531 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005532 *
5533 * Context:
5534 * Kernel context
5535 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005536static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005537qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5538{
5539 int i, entries;
5540 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005541 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005542 uint32_t pid1, pid2;
5543 uint64_t wwn1, wwn2;
5544 struct qla_fcp_prio_entry *pri_entry;
5545 struct qla_hw_data *ha = vha->hw;
5546
5547 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005548 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005549
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005550 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005551 entries = ha->fcp_prio_cfg->num_entries;
5552 pri_entry = &ha->fcp_prio_cfg->entry[0];
5553
5554 for (i = 0; i < entries; i++) {
5555 pid_match = wwn_match = 0;
5556
5557 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5558 pri_entry++;
5559 continue;
5560 }
5561
5562 /* check source pid for a match */
5563 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5564 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5565 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5566 if (pid1 == INVALID_PORT_ID)
5567 pid_match++;
5568 else if (pid1 == pid2)
5569 pid_match++;
5570 }
5571
5572 /* check destination pid for a match */
5573 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5574 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5575 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5576 if (pid1 == INVALID_PORT_ID)
5577 pid_match++;
5578 else if (pid1 == pid2)
5579 pid_match++;
5580 }
5581
5582 /* check source WWN for a match */
5583 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5584 wwn1 = wwn_to_u64(vha->port_name);
5585 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5586 if (wwn2 == (uint64_t)-1)
5587 wwn_match++;
5588 else if (wwn1 == wwn2)
5589 wwn_match++;
5590 }
5591
5592 /* check destination WWN for a match */
5593 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5594 wwn1 = wwn_to_u64(fcport->port_name);
5595 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5596 if (wwn2 == (uint64_t)-1)
5597 wwn_match++;
5598 else if (wwn1 == wwn2)
5599 wwn_match++;
5600 }
5601
5602 if (pid_match == 2 || wwn_match == 2) {
5603 /* Found a matching entry */
5604 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5605 priority = pri_entry->tag;
5606 break;
5607 }
5608
5609 pri_entry++;
5610 }
5611
5612 return priority;
5613}
5614
5615/*
5616 * qla24xx_update_fcport_fcp_prio
5617 * Activates fcp priority for the logged in fc port
5618 *
5619 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005620 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005621 * fcp = port structure pointer.
5622 *
5623 * Return:
5624 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5625 *
5626 * Context:
5627 * Kernel context.
5628 */
5629int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005630qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005631{
5632 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005633 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005634 uint16_t mb[5];
5635
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005636 if (fcport->port_type != FCT_TARGET ||
5637 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005638 return QLA_FUNCTION_FAILED;
5639
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005640 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005641 if (priority < 0)
5642 return QLA_FUNCTION_FAILED;
5643
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005644 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Sarang Radke09ff7012010-03-19 17:03:59 -07005645 if (ret == QLA_SUCCESS)
5646 fcport->fcp_prio = priority;
5647 else
5648 DEBUG2(printk(KERN_WARNING
5649 "scsi(%ld): Unable to activate fcp priority, "
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005650 " ret=0x%x\n", vha->host_no, ret));
Sarang Radke09ff7012010-03-19 17:03:59 -07005651
5652 return ret;
5653}
5654
5655/*
5656 * qla24xx_update_all_fcp_prio
5657 * Activates fcp priority for all the logged in ports
5658 *
5659 * Input:
5660 * ha = adapter block pointer.
5661 *
5662 * Return:
5663 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5664 *
5665 * Context:
5666 * Kernel context.
5667 */
5668int
5669qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5670{
5671 int ret;
5672 fc_port_t *fcport;
5673
5674 ret = QLA_FUNCTION_FAILED;
5675 /* We need to set priority for all logged in ports */
5676 list_for_each_entry(fcport, &vha->vp_fcports, list)
5677 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5678
5679 return ret;
5680}