blob: 234c1c28bf4430c62d64dbd8ac227345a9c17441 [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 Vasquez99b0bec2010-05-04 15:01:25 -0700386 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700387 qla2x00_post_async_adisc_work(vha, fcport, data);
388 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700389 }
390 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700391 break;
392 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700393 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700394 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
395 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
396 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700397 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700398 break;
399 case MBS_PORT_ID_USED:
400 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700401 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700402 qla2x00_post_async_login_work(vha, fcport, NULL);
403 break;
404 case MBS_LOOP_ID_USED:
405 fcport->loop_id++;
406 rval = qla2x00_find_new_loop_id(vha, fcport);
407 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700408 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez80d79442011-03-30 11:46:17 -0700409 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700410 break;
411 }
412 qla2x00_post_async_login_work(vha, fcport, NULL);
413 break;
414 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700415 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700416}
417
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700418void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700419qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
420 uint16_t *data)
421{
422 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700423 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700424}
425
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700426void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700427qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
428 uint16_t *data)
429{
430 if (data[0] == MBS_COMMAND_COMPLETE) {
431 qla2x00_update_fcport(vha, fcport);
432
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700433 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700434 }
435
436 /* Retry login. */
437 fcport->flags &= ~FCF_ASYNC_SENT;
438 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
439 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
440 else
Andrew Vasquez80d79442011-03-30 11:46:17 -0700441 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700442
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700443 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700444}
445
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700446void
447qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
448 struct srb_iocb *iocb)
449{
450 int rval;
451 uint32_t flags;
452 uint16_t lun;
453
454 flags = iocb->u.tmf.flags;
455 lun = (uint16_t)iocb->u.tmf.lun;
456
457 /* Issue Marker IOCB */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500458 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
459 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700460 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
461
462 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
463 DEBUG2_3_11(printk(KERN_WARNING
464 "%s(%ld): TM IOCB failed (%x).\n",
465 __func__, vha->host_no, rval));
466 }
467
468 return;
469}
470
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471/****************************************************************************/
472/* QLogic ISP2x00 Hardware Support Functions. */
473/****************************************************************************/
474
475/*
476* qla2x00_initialize_adapter
477* Initialize board.
478*
479* Input:
480* ha = adapter block pointer.
481*
482* Returns:
483* 0 = success
484*/
485int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487{
488 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800489 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800490 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700491
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800493 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700494 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800495 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800496 ha->flags.pci_channel_io_perm_failure = 0;
497 ha->flags.eeh_busy = 0;
Andrew Vasquez794a5692010-12-21 16:00:21 -0800498 ha->flags.thermal_supported = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
500 atomic_set(&vha->loop_state, LOOP_DOWN);
501 vha->device_flags = DFLG_NO_CABLE;
502 vha->dpc_flags = 0;
503 vha->flags.management_server_logged_in = 0;
504 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 ha->isp_abort_cnt = 0;
506 ha->beacon_blink_led = 0;
507
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800508 set_bit(0, ha->req_qid_map);
509 set_bit(0, ha->rsp_qid_map);
510
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700511 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800512 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800514 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 return (rval);
517 }
518
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800519 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800521 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700522 if (rval) {
523 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700525 return (rval);
526 }
527
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800528 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800529
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700531
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800532 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700533
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700534 if (ha->flags.disable_serdes) {
535 /* Mask HBA via NVRAM settings? */
536 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
537 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800538 vha->port_name[0], vha->port_name[1],
539 vha->port_name[2], vha->port_name[3],
540 vha->port_name[4], vha->port_name[5],
541 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700542 return QLA_FUNCTION_FAILED;
543 }
544
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800547 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
548 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800549 if (rval)
550 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800551 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800552 if (rval)
553 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700555
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700556 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800557 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700558 if (!ha->cs84xx) {
559 qla_printk(KERN_ERR, ha,
560 "Unable to configure ISP84XX.\n");
561 return QLA_FUNCTION_FAILED;
562 }
563 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800564 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700565 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800567 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700568 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800569 rval = qla84xx_init_chip(vha);
570 if (rval != QLA_SUCCESS) {
571 qla_printk(KERN_ERR, ha,
572 "Unable to initialize ISP84XX.\n");
573 qla84xx_put_chip(vha);
574 }
575 }
576
Madhuranath Iyengar2f0f3f42010-07-23 15:28:24 +0500577 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
578 qla24xx_read_fcp_prio_cfg(vha);
Sarang Radke09ff7012010-03-19 17:03:59 -0700579
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 return (rval);
581}
582
583/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700584 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 * @ha: HA context
586 *
587 * Returns 0 on success.
588 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700589int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800590qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700592 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700593 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800594 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700595 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700598 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700601 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
603
Andrew Vasquez737faec2008-10-24 15:13:45 -0700604 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700606 /* Get PCI bus information. */
607 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700608 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700609 spin_unlock_irqrestore(&ha->hardware_lock, flags);
610
611 return QLA_SUCCESS;
612}
613
614/**
615 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
616 * @ha: HA context
617 *
618 * Returns 0 on success.
619 */
620int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800621qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700622{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700623 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700624 unsigned long flags = 0;
625 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800626 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700627 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700628
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700629 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700630 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631
632 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700633 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700634
635 if (IS_QLA2322(ha) || IS_QLA6322(ha))
636 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700637 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700638
639 /*
640 * If this is a 2300 card and not 2312, reset the
641 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
642 * the 2310 also reports itself as a 2300 so we need to get the
643 * fb revision level -- a 6 indicates it really is a 2300 and
644 * not a 2310.
645 */
646 if (IS_QLA2300(ha)) {
647 spin_lock_irqsave(&ha->hardware_lock, flags);
648
649 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700650 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700651 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700652 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700653 break;
654
655 udelay(10);
656 }
657
658 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700659 WRT_REG_WORD(&reg->ctrl_status, 0x20);
660 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700661
662 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700663 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700664
665 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700666 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700667
668 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700669 WRT_REG_WORD(&reg->ctrl_status, 0x0);
670 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700671
672 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700673 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700674 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700675 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700676 break;
677
678 udelay(10);
679 }
680
681 spin_unlock_irqrestore(&ha->hardware_lock, flags);
682 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700683
684 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
685
Andrew Vasquez737faec2008-10-24 15:13:45 -0700686 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700687
688 /* Get PCI bus information. */
689 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700690 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700691 spin_unlock_irqrestore(&ha->hardware_lock, flags);
692
693 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694}
695
696/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700697 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
698 * @ha: HA context
699 *
700 * Returns 0 on success.
701 */
702int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800703qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700704{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700705 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700706 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800707 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700708 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700709
710 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700711 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700712
713 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700714 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700715 w &= ~PCI_COMMAND_INTX_DISABLE;
716 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
717
718 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
719
720 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700721 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
722 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700723
724 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700725 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
726 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700727
Andrew Vasquez737faec2008-10-24 15:13:45 -0700728 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700729
Auke Kok44c10132007-06-08 15:46:36 -0700730 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800731
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700732 /* Get PCI bus information. */
733 spin_lock_irqsave(&ha->hardware_lock, flags);
734 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
735 spin_unlock_irqrestore(&ha->hardware_lock, flags);
736
737 return QLA_SUCCESS;
738}
739
740/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700741 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
742 * @ha: HA context
743 *
744 * Returns 0 on success.
745 */
746int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800747qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700748{
749 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800750 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700751
752 pci_set_master(ha->pdev);
753 pci_try_set_mwi(ha->pdev);
754
755 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
756 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
757 w &= ~PCI_COMMAND_INTX_DISABLE;
758 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
759
760 /* PCIe -- adjust Maximum Read Request Size (2048). */
761 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
762 pcie_set_readrq(ha->pdev, 2048);
763
Andrew Vasquez737faec2008-10-24 15:13:45 -0700764 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700765
766 ha->chip_revision = ha->pdev->revision;
767
768 return QLA_SUCCESS;
769}
770
771/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 * qla2x00_isp_firmware() - Choose firmware image.
773 * @ha: HA context
774 *
775 * Returns 0 on success.
776 */
777static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800778qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779{
780 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700781 uint16_t loop_id, topo, sw_cap;
782 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800783 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700786 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700787
788 if (ha->flags.disable_risc_code_load) {
789 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800790 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
792
793 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800794 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700795 if (rval == QLA_SUCCESS) {
796 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800797 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700798 &area, &domain, &topo, &sw_cap);
799 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
801
802 if (rval) {
803 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800804 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
806
807 return (rval);
808}
809
810/**
811 * qla2x00_reset_chip() - Reset ISP chip.
812 * @ha: HA context
813 *
814 * Returns 0 on success.
815 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700816void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800817qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818{
819 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700821 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700822 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823 uint16_t cmd;
824
Andrew Vasquez85880802009-12-15 21:29:46 -0800825 if (unlikely(pci_channel_offline(ha->pdev)))
826 return;
827
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700828 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 spin_lock_irqsave(&ha->hardware_lock, flags);
831
832 /* Turn off master enable */
833 cmd = 0;
834 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
835 cmd &= ~PCI_COMMAND_MASTER;
836 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
837
838 if (!IS_QLA2100(ha)) {
839 /* Pause RISC. */
840 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
841 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
842 for (cnt = 0; cnt < 30000; cnt++) {
843 if ((RD_REG_WORD(&reg->hccr) &
844 HCCR_RISC_PAUSE) != 0)
845 break;
846 udelay(100);
847 }
848 } else {
849 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
850 udelay(10);
851 }
852
853 /* Select FPM registers. */
854 WRT_REG_WORD(&reg->ctrl_status, 0x20);
855 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
856
857 /* FPM Soft Reset. */
858 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
859 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
860
861 /* Toggle Fpm Reset. */
862 if (!IS_QLA2200(ha)) {
863 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
864 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
865 }
866
867 /* Select frame buffer registers. */
868 WRT_REG_WORD(&reg->ctrl_status, 0x10);
869 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
870
871 /* Reset frame buffer FIFOs. */
872 if (IS_QLA2200(ha)) {
873 WRT_FB_CMD_REG(ha, reg, 0xa000);
874 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
875 } else {
876 WRT_FB_CMD_REG(ha, reg, 0x00fc);
877
878 /* Read back fb_cmd until zero or 3 seconds max */
879 for (cnt = 0; cnt < 3000; cnt++) {
880 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
881 break;
882 udelay(100);
883 }
884 }
885
886 /* Select RISC module registers. */
887 WRT_REG_WORD(&reg->ctrl_status, 0);
888 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
889
890 /* Reset RISC processor. */
891 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
892 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
893
894 /* Release RISC processor. */
895 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
896 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
897 }
898
899 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
900 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
901
902 /* Reset ISP chip. */
903 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
904
905 /* Wait for RISC to recover from reset. */
906 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
907 /*
908 * It is necessary to for a delay here since the card doesn't
909 * respond to PCI reads during a reset. On some architectures
910 * this will result in an MCA.
911 */
912 udelay(20);
913 for (cnt = 30000; cnt; cnt--) {
914 if ((RD_REG_WORD(&reg->ctrl_status) &
915 CSR_ISP_SOFT_RESET) == 0)
916 break;
917 udelay(100);
918 }
919 } else
920 udelay(10);
921
922 /* Reset RISC processor. */
923 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
924
925 WRT_REG_WORD(&reg->semaphore, 0);
926
927 /* Release RISC processor. */
928 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
929 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
930
931 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
932 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700933 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 udelay(100);
937 }
938 } else
939 udelay(100);
940
941 /* Turn on master enable */
942 cmd |= PCI_COMMAND_MASTER;
943 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
944
945 /* Disable RISC pause on FPM parity error. */
946 if (!IS_QLA2100(ha)) {
947 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
948 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
949 }
950
951 spin_unlock_irqrestore(&ha->hardware_lock, flags);
952}
953
954/**
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700955 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
956 *
957 * Returns 0 on success.
958 */
959int
960qla81xx_reset_mpi(scsi_qla_host_t *vha)
961{
962 uint16_t mb[4] = {0x1010, 0, 1, 0};
963
964 return qla81xx_write_mpi_register(vha, mb);
965}
966
967/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700968 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700969 * @ha: HA context
970 *
971 * Returns 0 on success.
972 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700973static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800974qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700975{
976 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800977 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700978 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
979 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800980 uint16_t wd;
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -0700981 static int abts_cnt; /* ISP abort retry counts */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700982
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700983 spin_lock_irqsave(&ha->hardware_lock, flags);
984
985 /* Reset RISC. */
986 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
987 for (cnt = 0; cnt < 30000; cnt++) {
988 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
989 break;
990
991 udelay(10);
992 }
993
994 WRT_REG_DWORD(&reg->ctrl_status,
995 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800996 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700997
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800998 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700999 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001000 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1001 for (cnt = 10000 ; cnt && d2; cnt--) {
1002 udelay(5);
1003 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1004 barrier();
1005 }
1006
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001007 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001008 d2 = RD_REG_DWORD(&reg->ctrl_status);
1009 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1010 udelay(5);
1011 d2 = RD_REG_DWORD(&reg->ctrl_status);
1012 barrier();
1013 }
1014
Madhuranath Iyengarb1d469892010-09-03 15:20:54 -07001015 /* If required, do an MPI FW reset now */
1016 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
1017 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
1018 if (++abts_cnt < 5) {
1019 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
1020 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
1021 } else {
1022 /*
1023 * We exhausted the ISP abort retries. We have to
1024 * set the board offline.
1025 */
1026 abts_cnt = 0;
1027 vha->flags.online = 0;
1028 }
1029 }
1030 }
1031
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001032 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1033 RD_REG_DWORD(&reg->hccr);
1034
1035 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1036 RD_REG_DWORD(&reg->hccr);
1037
1038 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1039 RD_REG_DWORD(&reg->hccr);
1040
1041 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1042 for (cnt = 6000000 ; cnt && d2; cnt--) {
1043 udelay(5);
1044 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1045 barrier();
1046 }
1047
1048 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001049
1050 if (IS_NOPOLLING_TYPE(ha))
1051 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001052}
1053
1054/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001055 * qla24xx_reset_chip() - Reset ISP24xx chip.
1056 * @ha: HA context
1057 *
1058 * Returns 0 on success.
1059 */
1060void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001061qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001062{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001064
1065 if (pci_channel_offline(ha->pdev) &&
1066 ha->flags.pci_channel_io_perm_failure) {
1067 return;
1068 }
1069
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001070 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001071
1072 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001074}
1075
1076/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001077 * qla2x00_chip_diag() - Test chip for proper operation.
1078 * @ha: HA context
1079 *
1080 * Returns 0 on success.
1081 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001082int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001083qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084{
1085 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001086 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001087 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 unsigned long flags = 0;
1089 uint16_t data;
1090 uint32_t cnt;
1091 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001092 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001093
1094 /* Assume a failed state */
1095 rval = QLA_FUNCTION_FAILED;
1096
1097 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001098 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099
1100 spin_lock_irqsave(&ha->hardware_lock, flags);
1101
1102 /* Reset ISP chip. */
1103 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1104
1105 /*
1106 * We need to have a delay here since the card will not respond while
1107 * in reset causing an MCA on some architectures.
1108 */
1109 udelay(20);
1110 data = qla2x00_debounce_register(&reg->ctrl_status);
1111 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1112 udelay(5);
1113 data = RD_REG_WORD(&reg->ctrl_status);
1114 barrier();
1115 }
1116
1117 if (!cnt)
1118 goto chip_diag_failed;
1119
1120 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001121 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001122
1123 /* Reset RISC processor. */
1124 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1125 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1126
1127 /* Workaround for QLA2312 PCI parity error */
1128 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1129 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1130 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1131 udelay(5);
1132 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001133 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134 }
1135 } else
1136 udelay(10);
1137
1138 if (!cnt)
1139 goto chip_diag_failed;
1140
1141 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001142 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1145 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1146 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1147 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1148 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1149 mb[3] != PROD_ID_3) {
1150 qla_printk(KERN_WARNING, ha,
1151 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1152
1153 goto chip_diag_failed;
1154 }
1155 ha->product_id[0] = mb[1];
1156 ha->product_id[1] = mb[2];
1157 ha->product_id[2] = mb[3];
1158 ha->product_id[3] = mb[4];
1159
1160 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001161 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1163 else
1164 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001165 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
1167 if (IS_QLA2200(ha) &&
1168 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1169 /* Limit firmware transfer size with a 2200A */
1170 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001171 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001173 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 ha->fw_transfer_size = 128;
1175 }
1176
1177 /* Wrap Incoming Mailboxes Test. */
1178 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1181 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 if (rval) {
1183 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001184 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 qla_printk(KERN_WARNING, ha,
1186 "Failed mailbox send register test\n");
1187 }
1188 else {
1189 /* Flag a successful rval */
1190 rval = QLA_SUCCESS;
1191 }
1192 spin_lock_irqsave(&ha->hardware_lock, flags);
1193
1194chip_diag_failed:
1195 if (rval)
1196 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001197 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1200
1201 return (rval);
1202}
1203
1204/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001205 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1206 * @ha: HA context
1207 *
1208 * Returns 0 on success.
1209 */
1210int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001211qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001212{
1213 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001214 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001215 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001216
Giridhar Malavalia9083012010-04-12 17:59:55 -07001217 if (IS_QLA82XX(ha))
1218 return QLA_SUCCESS;
1219
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001220 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001222 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001223 if (rval) {
1224 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001225 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001226 qla_printk(KERN_WARNING, ha,
1227 "Failed mailbox send register test\n");
1228 } else {
1229 /* Flag a successful rval */
1230 rval = QLA_SUCCESS;
1231 }
1232
1233 return rval;
1234}
1235
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001236void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001237qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001238{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001239 int rval;
1240 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001241 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001242 dma_addr_t tc_dma;
1243 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001244 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001245 struct req_que *req = ha->req_q_map[0];
1246 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001247
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001248 if (ha->fw_dump) {
1249 qla_printk(KERN_WARNING, ha,
1250 "Firmware dump previously allocated.\n");
1251 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001252 }
1253
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001254 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001255 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001256 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1257 fixed_size = sizeof(struct qla2100_fw_dump);
1258 } else if (IS_QLA23XX(ha)) {
1259 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1260 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1261 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001262 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001263 if (IS_QLA81XX(ha))
1264 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1265 else if (IS_QLA25XX(ha))
1266 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1267 else
1268 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001269 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1270 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001271 if (ha->mqenable)
1272 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001273 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001274 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001275 goto try_eft;
1276
1277 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1278 GFP_KERNEL);
1279 if (!tc) {
1280 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1281 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001282 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001283 }
1284
1285 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001286 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001287 ha->fce_mb, &ha->fce_bufs);
1288 if (rval) {
1289 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1290 "FCE (%d).\n", rval);
1291 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1292 tc_dma);
1293 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001294 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001295 }
1296
1297 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1298 FCE_SIZE / 1024);
1299
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001300 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001301 ha->flags.fce_enabled = 1;
1302 ha->fce_dma = tc_dma;
1303 ha->fce = tc;
1304try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001305 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001306 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001307 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001308 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001309 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1310 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1311 goto cont_alloc;
1312 }
1313
Andrew Vasquezfc447652008-01-17 09:02:18 -08001314 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001315 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001316 if (rval) {
1317 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1318 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001319 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1320 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001321 goto cont_alloc;
1322 }
1323
1324 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1325 EFT_SIZE / 1024);
1326
1327 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001328 ha->eft_dma = tc_dma;
1329 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001330 }
1331cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001332 req_q_size = req->length * sizeof(request_t);
1333 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001334
1335 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001336 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001337 ha->chain_offset = dump_size;
1338 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001339
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001340 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001341 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001342 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001343 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001344
Madhuranath Iyengare30d1752010-10-15 11:27:46 -07001345 if (ha->fce) {
1346 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
1347 ha->fce_dma);
1348 ha->fce = NULL;
1349 ha->fce_dma = 0;
1350 }
1351
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001352 if (ha->eft) {
1353 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1354 ha->eft_dma);
1355 ha->eft = NULL;
1356 ha->eft_dma = 0;
1357 }
1358 return;
1359 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001360 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1361 dump_size / 1024);
1362
1363 ha->fw_dump_len = dump_size;
1364 ha->fw_dump->signature[0] = 'Q';
1365 ha->fw_dump->signature[1] = 'L';
1366 ha->fw_dump->signature[2] = 'G';
1367 ha->fw_dump->signature[3] = 'C';
1368 ha->fw_dump->version = __constant_htonl(1);
1369
1370 ha->fw_dump->fixed_size = htonl(fixed_size);
1371 ha->fw_dump->mem_size = htonl(mem_size);
1372 ha->fw_dump->req_q_size = htonl(req_q_size);
1373 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1374
1375 ha->fw_dump->eft_size = htonl(eft_size);
1376 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1377 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1378
1379 ha->fw_dump->header_size =
1380 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001381}
1382
Andrew Vasquez18e75552009-06-03 09:55:30 -07001383static int
1384qla81xx_mpi_sync(scsi_qla_host_t *vha)
1385{
1386#define MPS_MASK 0xe0
1387 int rval;
1388 uint16_t dc;
1389 uint32_t dw;
1390 struct qla_hw_data *ha = vha->hw;
1391
1392 if (!IS_QLA81XX(vha->hw))
1393 return QLA_SUCCESS;
1394
1395 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1396 if (rval != QLA_SUCCESS) {
1397 DEBUG2(qla_printk(KERN_WARNING, ha,
1398 "Sync-MPI: Unable to acquire semaphore.\n"));
1399 goto done;
1400 }
1401
1402 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1403 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1404 if (rval != QLA_SUCCESS) {
1405 DEBUG2(qla_printk(KERN_WARNING, ha,
1406 "Sync-MPI: Unable to read sync.\n"));
1407 goto done_release;
1408 }
1409
1410 dc &= MPS_MASK;
1411 if (dc == (dw & MPS_MASK))
1412 goto done_release;
1413
1414 dw &= ~MPS_MASK;
1415 dw |= dc;
1416 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1417 if (rval != QLA_SUCCESS) {
1418 DEBUG2(qla_printk(KERN_WARNING, ha,
1419 "Sync-MPI: Unable to gain sync.\n"));
1420 }
1421
1422done_release:
1423 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1424 if (rval != QLA_SUCCESS) {
1425 DEBUG2(qla_printk(KERN_WARNING, ha,
1426 "Sync-MPI: Unable to release semaphore.\n"));
1427 }
1428
1429done:
1430 return rval;
1431}
1432
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001433/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 * qla2x00_setup_chip() - Load and start RISC firmware.
1435 * @ha: HA context
1436 *
1437 * Returns 0 on success.
1438 */
1439static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001440qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001441{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001442 int rval;
1443 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001445 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1446 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001447 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001448
Giridhar Malavalia9083012010-04-12 17:59:55 -07001449 if (IS_QLA82XX(ha)) {
1450 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001451 if (rval == QLA_SUCCESS) {
1452 qla2x00_stop_firmware(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07001453 goto enable_82xx_npiv;
Andrew Vasquez14e303d2010-07-23 15:28:29 +05001454 } else
Giridhar Malavalib9637522010-05-28 15:08:15 -07001455 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001456 }
1457
Andrew Vasquez3db06522008-01-31 12:33:49 -08001458 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1459 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1460 spin_lock_irqsave(&ha->hardware_lock, flags);
1461 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1462 RD_REG_WORD(&reg->hccr);
1463 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1464 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465
Andrew Vasquez18e75552009-06-03 09:55:30 -07001466 qla81xx_mpi_sync(vha);
1467
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001469 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001470 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001474 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475 if (rval == QLA_SUCCESS) {
1476 /* Start firmware execution. */
1477 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001480 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001482 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001483enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001484 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001485 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 &ha->fw_major_version,
1487 &ha->fw_minor_version,
1488 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001489 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001490 ha->mpi_version, &ha->mpi_capabilities,
1491 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001492 if (rval != QLA_SUCCESS)
1493 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001494 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001495 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001496 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001497 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001498 if ((!ha->max_npiv_vports) ||
1499 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001500 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001501 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001502 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001503 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001504 qla2x00_get_resource_cnts(vha, NULL,
1505 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001506 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001507
Giridhar Malavalia9083012010-04-12 17:59:55 -07001508 if (!fw_major_version && ql2xallocfwdump) {
1509 if (!IS_QLA82XX(ha))
1510 qla2x00_alloc_fw_dump(vha);
1511 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512 }
1513 } else {
1514 DEBUG2(printk(KERN_INFO
1515 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 }
1518 }
1519
Andrew Vasquez3db06522008-01-31 12:33:49 -08001520 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1521 /* Enable proper parity. */
1522 spin_lock_irqsave(&ha->hardware_lock, flags);
1523 if (IS_QLA2300(ha))
1524 /* SRAM parity */
1525 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1526 else
1527 /* SRAM, Instruction RAM and GP RAM parity */
1528 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1529 RD_REG_WORD(&reg->hccr);
1530 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1531 }
1532
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001533 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1534 uint32_t size;
1535
1536 rval = qla81xx_fac_get_sector_size(vha, &size);
1537 if (rval == QLA_SUCCESS) {
1538 ha->flags.fac_supported = 1;
1539 ha->fdt_block_size = size << 2;
1540 } else {
1541 qla_printk(KERN_ERR, ha,
1542 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1543 ha->fw_major_version, ha->fw_minor_version,
1544 ha->fw_subminor_version);
1545 }
1546 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001547failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 if (rval) {
1549 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 }
1552
1553 return (rval);
1554}
1555
1556/**
1557 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1558 * @ha: HA context
1559 *
1560 * Beginning of request ring has initialization control block already built
1561 * by nvram config routine.
1562 *
1563 * Returns 0 on success.
1564 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001565void
1566qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567{
1568 uint16_t cnt;
1569 response_t *pkt;
1570
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001571 rsp->ring_ptr = rsp->ring;
1572 rsp->ring_index = 0;
1573 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001574 pkt = rsp->ring_ptr;
1575 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 pkt->signature = RESPONSE_PROCESSED;
1577 pkt++;
1578 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579}
1580
1581/**
1582 * qla2x00_update_fw_options() - Read and process firmware options.
1583 * @ha: HA context
1584 *
1585 * Returns 0 on success.
1586 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001587void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589{
1590 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001591 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
1593 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1597 return;
1598
1599 /* Serial Link options. */
1600 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001601 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1603 sizeof(ha->fw_seriallink_options)));
1604
1605 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1606 if (ha->fw_seriallink_options[3] & BIT_2) {
1607 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1608
1609 /* 1G settings */
1610 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1611 emphasis = (ha->fw_seriallink_options[2] &
1612 (BIT_4 | BIT_3)) >> 3;
1613 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001614 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 rx_sens = (ha->fw_seriallink_options[0] &
1616 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1617 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1618 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1619 if (rx_sens == 0x0)
1620 rx_sens = 0x3;
1621 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1622 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1623 ha->fw_options[10] |= BIT_5 |
1624 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1625 (tx_sens & (BIT_1 | BIT_0));
1626
1627 /* 2G settings */
1628 swing = (ha->fw_seriallink_options[2] &
1629 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1630 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1631 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001632 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 rx_sens = (ha->fw_seriallink_options[1] &
1634 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1635 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1636 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1637 if (rx_sens == 0x0)
1638 rx_sens = 0x3;
1639 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1640 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1641 ha->fw_options[11] |= BIT_5 |
1642 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1643 (tx_sens & (BIT_1 | BIT_0));
1644 }
1645
1646 /* FCP2 options. */
1647 /* Return command IOCBs without waiting for an ABTS to complete. */
1648 ha->fw_options[3] |= BIT_13;
1649
1650 /* LED scheme. */
1651 if (ha->flags.enable_led_scheme)
1652 ha->fw_options[2] |= BIT_12;
1653
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001654 /* Detect ISP6312. */
1655 if (IS_QLA6312(ha))
1656 ha->fw_options[2] |= BIT_13;
1657
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001659 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660}
1661
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001662void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001664{
1665 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001666 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001667
Giridhar Malavalia9083012010-04-12 17:59:55 -07001668 if (IS_QLA82XX(ha))
1669 return;
1670
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001671 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001672 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001673 return;
1674
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001675 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001676 le16_to_cpu(ha->fw_seriallink_options24[1]),
1677 le16_to_cpu(ha->fw_seriallink_options24[2]),
1678 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001679 if (rval != QLA_SUCCESS) {
1680 qla_printk(KERN_WARNING, ha,
1681 "Unable to update Serial Link options (%x).\n", rval);
1682 }
1683}
1684
1685void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001686qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001687{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001689 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001690 struct req_que *req = ha->req_q_map[0];
1691 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001692
1693 /* Setup ring parameters in initialization control block. */
1694 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1695 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001696 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1697 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1698 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1699 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1700 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1701 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001702
1703 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1704 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1705 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1706 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1707 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1708}
1709
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001710void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001711qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001712{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001713 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001714 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1715 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1716 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001717 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001718 uint16_t rid = 0;
1719 struct req_que *req = ha->req_q_map[0];
1720 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001721
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001722/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001723 icb = (struct init_cb_24xx *)ha->init_cb;
1724 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1725 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001726 icb->request_q_length = cpu_to_le16(req->length);
1727 icb->response_q_length = cpu_to_le16(rsp->length);
1728 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1729 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1730 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1731 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001732
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001733 if (ha->mqenable) {
1734 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1735 icb->rid = __constant_cpu_to_le16(rid);
1736 if (ha->flags.msix_enabled) {
1737 msix = &ha->msix_entries[1];
1738 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001739 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001740 icb->msix = cpu_to_le16(msix->entry);
1741 }
1742 /* Use alternate PCI bus number */
1743 if (MSB(rid))
1744 icb->firmware_options_2 |=
1745 __constant_cpu_to_le32(BIT_19);
1746 /* Use alternate PCI devfn */
1747 if (LSB(rid))
1748 icb->firmware_options_2 |=
1749 __constant_cpu_to_le32(BIT_18);
1750
Anirban Chakraborty31557542009-12-02 10:36:55 -08001751 /* Use Disable MSIX Handshake mode for capable adapters */
1752 if (IS_MSIX_NACK_CAPABLE(ha)) {
1753 icb->firmware_options_2 &=
1754 __constant_cpu_to_le32(~BIT_22);
1755 ha->flags.disable_msix_handshake = 1;
1756 qla_printk(KERN_INFO, ha,
1757 "MSIX Handshake Disable Mode turned on\n");
1758 } else {
1759 icb->firmware_options_2 |=
1760 __constant_cpu_to_le32(BIT_22);
1761 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001762 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001763
1764 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1765 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1766 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1767 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1768 } else {
1769 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1770 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1771 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1772 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1773 }
1774 /* PCI posting */
1775 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001776}
1777
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778/**
1779 * qla2x00_init_rings() - Initializes firmware.
1780 * @ha: HA context
1781 *
1782 * Beginning of request ring has initialization control block already built
1783 * by nvram config routine.
1784 *
1785 * Returns 0 on success.
1786 */
1787static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789{
1790 int rval;
1791 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001792 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001793 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001794 struct req_que *req;
1795 struct rsp_que *rsp;
1796 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001797 struct mid_init_cb_24xx *mid_init_cb =
1798 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
1800 spin_lock_irqsave(&ha->hardware_lock, flags);
1801
1802 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001803 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001804 req = ha->req_q_map[que];
1805 if (!req)
1806 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001807 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001808 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001810 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001811
1812 /* Initialize firmware. */
1813 req->ring_ptr = req->ring;
1814 req->ring_index = 0;
1815 req->cnt = req->length;
1816 }
1817
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001818 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001819 rsp = ha->rsp_q_map[que];
1820 if (!rsp)
1821 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001822 /* Initialize response queue entries */
1823 qla2x00_init_response_q_entries(rsp);
1824 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001825
Dan Carpenter542bce12010-10-15 11:27:38 -07001826 spin_lock(&ha->vport_slock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001828 list_for_each_entry(vp, &ha->vp_list, list) {
1829 vp->rscn_in_ptr = 0;
1830 vp->rscn_out_ptr = 0;
1831 }
Arun Easifeafb7b2010-09-03 14:57:00 -07001832
Dan Carpenter542bce12010-10-15 11:27:38 -07001833 spin_unlock(&ha->vport_slock);
Arun Easifeafb7b2010-09-03 14:57:00 -07001834
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836
1837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1838
1839 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001842 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001843
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001844 if (ha->flags.npiv_supported) {
1845 if (ha->operating_mode == LOOP)
1846 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001847 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001848 }
1849
Andrew Vasquez24a08132009-03-24 09:08:16 -07001850 if (IS_FWI2_CAPABLE(ha)) {
1851 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1852 mid_init_cb->init_cb.execution_throttle =
1853 cpu_to_le16(ha->fw_xcb_count);
1854 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001856 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 if (rval) {
1858 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001859 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 } else {
1861 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001862 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001863 }
1864
1865 return (rval);
1866}
1867
1868/**
1869 * qla2x00_fw_ready() - Waits for firmware ready.
1870 * @ha: HA context
1871 *
1872 * Returns 0 on success.
1873 */
1874static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001875qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876{
1877 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001878 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 uint16_t min_wait; /* Minimum wait time if loop is down */
1880 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001881 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001882 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
1884 rval = QLA_SUCCESS;
1885
1886 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001887 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
1889 /*
1890 * Firmware should take at most one RATOV to login, plus 5 seconds for
1891 * our own processing.
1892 */
1893 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1894 wait_time = min_wait;
1895 }
1896
1897 /* Min wait time if loop down */
1898 mtime = jiffies + (min_wait * HZ);
1899
1900 /* wait time before firmware ready */
1901 wtime = jiffies + (wait_time * HZ);
1902
1903 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001904 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1906
1907 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001908 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909
1910 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001913 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001914 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001916 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1917 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001918 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001919 state[2]));
1920 if ((state[2] & FSTATE_LOGGED_IN) &&
1921 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1922 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001924
1925 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001927 if (rval != QLA_SUCCESS)
1928 break;
1929
1930 /* Add time taken to initialize. */
1931 cs84xx_time = jiffies - cs84xx_time;
1932 wtime += cs84xx_time;
1933 mtime += cs84xx_time;
1934 DEBUG16(printk("scsi(%ld): Increasing "
1935 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001936 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001937 }
1938 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 &ha->login_timeout, &ha->r_a_tov);
1944
1945 rval = QLA_SUCCESS;
1946 break;
1947 }
1948
1949 rval = QLA_FUNCTION_FAILED;
1950
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001951 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001952 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001954 * other than Wait for Login.
1955 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956 if (time_after_eq(jiffies, mtime)) {
1957 qla_printk(KERN_INFO, ha,
1958 "Cable is unplugged...\n");
1959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961 break;
1962 }
1963 }
1964 } else {
1965 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a4f2010-05-28 15:08:25 -07001966 if (time_after_eq(jiffies, mtime) ||
Giridhar Malavali71905752011-02-23 15:27:10 -08001967 ha->flags.isp82xx_fw_hung)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 break;
1969 }
1970
1971 if (time_after_eq(jiffies, wtime))
1972 break;
1973
1974 /* Delay for a while */
1975 msleep(500);
1976
1977 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001978 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 } while (1);
1980
Andrew Vasquez656e8912009-06-03 09:55:29 -07001981 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1982 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1983 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
1985 if (rval) {
1986 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001987 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 }
1989
1990 return (rval);
1991}
1992
1993/*
1994* qla2x00_configure_hba
1995* Setup adapter context.
1996*
1997* Input:
1998* ha = adapter state pointer.
1999*
2000* Returns:
2001* 0 = success
2002*
2003* Context:
2004* Kernel context.
2005*/
2006static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
2009 int rval;
2010 uint16_t loop_id;
2011 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002012 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 uint8_t al_pa;
2014 uint8_t area;
2015 uint8_t domain;
2016 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002017 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002021 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Andrew Vasquez7a44b862010-12-21 16:00:23 -08002024 IS_QLA8XXX_TYPE(ha) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002025 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2026 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002028 } else {
2029 qla_printk(KERN_WARNING, ha,
2030 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002032 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 return (rval);
2034 }
2035
2036 if (topo == 4) {
2037 qla_printk(KERN_INFO, ha,
2038 "Cannot get topology - retrying.\n");
2039 return (QLA_FUNCTION_FAILED);
2040 }
2041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002042 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
2044 /* initialize */
2045 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2046 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002047 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048
2049 switch (topo) {
2050 case 0:
2051 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 ha->current_topology = ISP_CFG_NL;
2054 strcpy(connect_type, "(Loop)");
2055 break;
2056
2057 case 1:
2058 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002060 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 ha->current_topology = ISP_CFG_FL;
2062 strcpy(connect_type, "(FL_Port)");
2063 break;
2064
2065 case 2:
2066 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002067 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 ha->operating_mode = P2P;
2069 ha->current_topology = ISP_CFG_N;
2070 strcpy(connect_type, "(N_Port-to-N_Port)");
2071 break;
2072
2073 case 3:
2074 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002076 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 ha->operating_mode = P2P;
2078 ha->current_topology = ISP_CFG_F;
2079 strcpy(connect_type, "(F_Port)");
2080 break;
2081
2082 default:
2083 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2084 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002085 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002086 ha->current_topology = ISP_CFG_NL;
2087 strcpy(connect_type, "(Loop)");
2088 break;
2089 }
2090
2091 /* Save Host port and loop ID. */
2092 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002093 vha->d_id.b.domain = domain;
2094 vha->d_id.b.area = area;
2095 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002097 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 qla_printk(KERN_INFO, ha,
2099 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
2102 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002103 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002105 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
2107
2108 return(rval);
2109}
2110
Giridhar Malavalia9083012010-04-12 17:59:55 -07002111inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002112qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2113 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002114{
2115 char *st, *en;
2116 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002117 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002118 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002119 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002120
2121 if (memcmp(model, BINZERO, len) != 0) {
2122 strncpy(ha->model_number, model, len);
2123 st = en = ha->model_number;
2124 en += len - 1;
2125 while (en > st) {
2126 if (*en != 0x20 && *en != 0x00)
2127 break;
2128 *en-- = '\0';
2129 }
2130
2131 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002132 if (use_tbl &&
2133 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002134 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002135 strncpy(ha->model_desc,
2136 qla2x00_model_name[index * 2 + 1],
2137 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002138 } else {
2139 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002140 if (use_tbl &&
2141 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002142 index < QLA_MODEL_NAMES) {
2143 strcpy(ha->model_number,
2144 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002145 strncpy(ha->model_desc,
2146 qla2x00_model_name[index * 2 + 1],
2147 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002148 } else {
2149 strcpy(ha->model_number, def);
2150 }
2151 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002152 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002153 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002154 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002155}
2156
David Miller4e08df32007-04-16 12:37:43 -07002157/* On sparc systems, obtain port and node WWN from firmware
2158 * properties.
2159 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002161{
2162#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002163 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002164 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002165 struct device_node *dp = pci_device_to_OF_node(pdev);
2166 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002167 int len;
2168
2169 val = of_get_property(dp, "port-wwn", &len);
2170 if (val && len >= WWN_SIZE)
2171 memcpy(nv->port_name, val, WWN_SIZE);
2172
2173 val = of_get_property(dp, "node-wwn", &len);
2174 if (val && len >= WWN_SIZE)
2175 memcpy(nv->node_name, val, WWN_SIZE);
2176#endif
2177}
2178
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179/*
2180* NVRAM configuration for ISP 2xxx
2181*
2182* Input:
2183* ha = adapter block pointer.
2184*
2185* Output:
2186* initialization control block in response_ring
2187* host adapters parameters in host adapter block
2188*
2189* Returns:
2190* 0 = success.
2191*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002192int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194{
David Miller4e08df32007-04-16 12:37:43 -07002195 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002196 uint8_t chksum = 0;
2197 uint16_t cnt;
2198 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002200 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002201 nvram_t *nv = ha->nvram;
2202 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002203 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204
David Miller4e08df32007-04-16 12:37:43 -07002205 rval = QLA_SUCCESS;
2206
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002208 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 ha->nvram_base = 0;
2210 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2211 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2212 ha->nvram_base = 0x80;
2213
2214 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002215 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002216 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2217 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002219 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002220 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002221
2222 /* Bad NVRAM data, set defaults parameters. */
2223 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2224 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2225 /* Reset NVRAM data. */
2226 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2227 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2228 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002229 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2230 "invalid -- WWPN) defaults.\n");
2231
2232 /*
2233 * Set default initialization control block.
2234 */
2235 memset(nv, 0, ha->nvram_size);
2236 nv->parameter_block_version = ICB_VERSION;
2237
2238 if (IS_QLA23XX(ha)) {
2239 nv->firmware_options[0] = BIT_2 | BIT_1;
2240 nv->firmware_options[1] = BIT_7 | BIT_5;
2241 nv->add_firmware_options[0] = BIT_5;
2242 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2243 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2244 nv->special_options[1] = BIT_7;
2245 } else if (IS_QLA2200(ha)) {
2246 nv->firmware_options[0] = BIT_2 | BIT_1;
2247 nv->firmware_options[1] = BIT_7 | BIT_5;
2248 nv->add_firmware_options[0] = BIT_5;
2249 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2250 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2251 } else if (IS_QLA2100(ha)) {
2252 nv->firmware_options[0] = BIT_3 | BIT_1;
2253 nv->firmware_options[1] = BIT_5;
2254 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2255 }
2256
2257 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2258 nv->execution_throttle = __constant_cpu_to_le16(16);
2259 nv->retry_count = 8;
2260 nv->retry_delay = 1;
2261
2262 nv->port_name[0] = 33;
2263 nv->port_name[3] = 224;
2264 nv->port_name[4] = 139;
2265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002266 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002267
2268 nv->login_timeout = 4;
2269
2270 /*
2271 * Set default host adapter parameters
2272 */
2273 nv->host_p[1] = BIT_2;
2274 nv->reset_delay = 5;
2275 nv->port_down_retry_count = 8;
2276 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2277 nv->link_down_timeout = 60;
2278
2279 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 }
2281
2282#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2283 /*
2284 * The SN2 does not provide BIOS emulation which means you can't change
2285 * potentially bogus BIOS settings. Force the use of default settings
2286 * for link rate and frame size. Hope that the rest of the settings
2287 * are valid.
2288 */
2289 if (ia64_platform_is("sn2")) {
2290 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2291 if (IS_QLA23XX(ha))
2292 nv->special_options[1] = BIT_7;
2293 }
2294#endif
2295
2296 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002297 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298
2299 /*
2300 * Setup driver NVRAM options.
2301 */
2302 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2303 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2304 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2305 nv->firmware_options[1] &= ~BIT_4;
2306
2307 if (IS_QLA23XX(ha)) {
2308 nv->firmware_options[0] |= BIT_2;
2309 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002310 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002311 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
2313 if (IS_QLA2300(ha)) {
2314 if (ha->fb_rev == FPM_2310) {
2315 strcpy(ha->model_number, "QLA2310");
2316 } else {
2317 strcpy(ha->model_number, "QLA2300");
2318 }
2319 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002320 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002321 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002322 }
2323 } else if (IS_QLA2200(ha)) {
2324 nv->firmware_options[0] |= BIT_2;
2325 /*
2326 * 'Point-to-point preferred, else loop' is not a safe
2327 * connection mode setting.
2328 */
2329 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2330 (BIT_5 | BIT_4)) {
2331 /* Force 'loop preferred, else point-to-point'. */
2332 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2333 nv->add_firmware_options[0] |= BIT_5;
2334 }
2335 strcpy(ha->model_number, "QLA22xx");
2336 } else /*if (IS_QLA2100(ha))*/ {
2337 strcpy(ha->model_number, "QLA2100");
2338 }
2339
2340 /*
2341 * Copy over NVRAM RISC parameter block to initialization control block.
2342 */
2343 dptr1 = (uint8_t *)icb;
2344 dptr2 = (uint8_t *)&nv->parameter_block_version;
2345 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2346 while (cnt--)
2347 *dptr1++ = *dptr2++;
2348
2349 /* Copy 2nd half. */
2350 dptr1 = (uint8_t *)icb->add_firmware_options;
2351 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2352 while (cnt--)
2353 *dptr1++ = *dptr2++;
2354
Andrew Vasquez5341e862006-05-17 15:09:16 -07002355 /* Use alternate WWN? */
2356 if (nv->host_p[1] & BIT_7) {
2357 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2358 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2359 }
2360
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 /* Prepare nodename */
2362 if ((icb->firmware_options[1] & BIT_6) == 0) {
2363 /*
2364 * Firmware will apply the following mask if the nodename was
2365 * not provided.
2366 */
2367 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2368 icb->node_name[0] &= 0xF0;
2369 }
2370
2371 /*
2372 * Set host adapter parameters.
2373 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002374 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002375 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2377 /* Always load RISC code on non ISP2[12]00 chips. */
2378 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2379 ha->flags.disable_risc_code_load = 0;
2380 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2381 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2382 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002383 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002384 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
2386 ha->operating_mode =
2387 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2388
2389 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2390 sizeof(ha->fw_seriallink_options));
2391
2392 /* save HBA serial number */
2393 ha->serial0 = icb->port_name[5];
2394 ha->serial1 = icb->port_name[6];
2395 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002396 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2397 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
2399 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2400
2401 ha->retry_count = nv->retry_count;
2402
2403 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002404 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 nv->login_timeout = ql2xlogintimeout;
2406 if (nv->login_timeout < 4)
2407 nv->login_timeout = 4;
2408 ha->login_timeout = nv->login_timeout;
2409 icb->login_timeout = nv->login_timeout;
2410
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002411 /* Set minimum RATOV to 100 tenths of a second. */
2412 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 ha->loop_reset_delay = nv->reset_delay;
2415
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 /* Link Down Timeout = 0:
2417 *
2418 * When Port Down timer expires we will start returning
2419 * I/O's to OS with "DID_NO_CONNECT".
2420 *
2421 * Link Down Timeout != 0:
2422 *
2423 * The driver waits for the link to come up after link down
2424 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002425 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 if (nv->link_down_timeout == 0) {
2427 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002428 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 } else {
2430 ha->link_down_timeout = nv->link_down_timeout;
2431 ha->loop_down_abort_time =
2432 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002433 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 /*
2436 * Need enough time to try and get the port back.
2437 */
2438 ha->port_down_retry_count = nv->port_down_retry_count;
2439 if (qlport_down_retry)
2440 ha->port_down_retry_count = qlport_down_retry;
2441 /* Set login_retry_count */
2442 ha->login_retry_count = nv->retry_count;
2443 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2444 ha->port_down_retry_count > 3)
2445 ha->login_retry_count = ha->port_down_retry_count;
2446 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2447 ha->login_retry_count = ha->port_down_retry_count;
2448 if (ql2xloginretrycount)
2449 ha->login_retry_count = ql2xloginretrycount;
2450
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 icb->lun_enables = __constant_cpu_to_le16(0);
2452 icb->command_resource_count = 0;
2453 icb->immediate_notify_resource_count = 0;
2454 icb->timeout = __constant_cpu_to_le16(0);
2455
2456 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2457 /* Enable RIO */
2458 icb->firmware_options[0] &= ~BIT_3;
2459 icb->add_firmware_options[0] &=
2460 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2461 icb->add_firmware_options[0] |= BIT_2;
2462 icb->response_accumulation_timer = 3;
2463 icb->interrupt_delay_timer = 5;
2464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002467 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002469 ha->zio_mode = icb->add_firmware_options[0] &
2470 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2471 ha->zio_timer = icb->interrupt_delay_timer ?
2472 icb->interrupt_delay_timer: 2;
2473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 icb->add_firmware_options[0] &=
2475 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002477 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002478 ha->zio_mode = QLA_ZIO_MODE_6;
2479
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002480 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002481 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002482 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002484 "ZIO mode %d enabled; timer delay (%d us).\n",
2485 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002487 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2488 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 }
2491 }
2492
David Miller4e08df32007-04-16 12:37:43 -07002493 if (rval) {
2494 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002496 }
2497 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498}
2499
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002500static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002501qla2x00_rport_del(void *data)
2502{
2503 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002504 struct fc_rport *rport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002505 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002506
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002507 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002508 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002509 fcport->drport = NULL;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002510 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002511 if (rport)
2512 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002513}
2514
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515/**
2516 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2517 * @ha: HA context
2518 * @flags: allocation flags
2519 *
2520 * Returns a pointer to the allocated fcport, or NULL, if none available.
2521 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002522fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524{
2525 fc_port_t *fcport;
2526
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002527 fcport = kzalloc(sizeof(fc_port_t), flags);
2528 if (!fcport)
2529 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002532 fcport->vha = vha;
2533 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 fcport->port_type = FCT_UNKNOWN;
2535 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002537 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002539 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540}
2541
2542/*
2543 * qla2x00_configure_loop
2544 * Updates Fibre Channel Device Database with what is actually on loop.
2545 *
2546 * Input:
2547 * ha = adapter block pointer.
2548 *
2549 * Returns:
2550 * 0 = success.
2551 * 1 = error.
2552 * 2 = database was full and device was not configured.
2553 */
2554static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556{
2557 int rval;
2558 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 rval = QLA_SUCCESS;
2561
2562 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2564 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 if (rval != QLA_SUCCESS) {
2566 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 return (rval);
2569 }
2570 }
2571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002572 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575
2576 /*
2577 * If we have both an RSCN and PORT UPDATE pending then handle them
2578 * both at the same time.
2579 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2581 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582
Michael Hernandez3064ff32009-12-15 21:29:44 -08002583 qla2x00_get_data_rate(vha);
2584
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 /* Determine what we need to do */
2586 if (ha->current_topology == ISP_CFG_FL &&
2587 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2588
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002589 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 set_bit(RSCN_UPDATE, &flags);
2591
2592 } else if (ha->current_topology == ISP_CFG_F &&
2593 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2594
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 set_bit(RSCN_UPDATE, &flags);
2597 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2598
Andrew Vasquez21333b42006-05-17 15:09:56 -07002599 } else if (ha->current_topology == ISP_CFG_N) {
2600 clear_bit(RSCN_UPDATE, &flags);
2601
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002602 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 (test_bit(ABORT_ISP_ACTIVE, &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 set_bit(LOCAL_LOOP_UPDATE, &flags);
2608 }
2609
2610 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 else
2614 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 }
2616
2617 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 else
2621 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 }
2623
2624 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002625 if (atomic_read(&vha->loop_down_timer) ||
2626 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 rval = QLA_FUNCTION_FAILED;
2628 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002631 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 }
2633 }
2634
2635 if (rval) {
2636 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 } else {
2639 DEBUG3(printk("%s: exiting normally\n", __func__));
2640 }
2641
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002642 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002643 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002646 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002648 if (!IS_ALOGIO_CAPABLE(ha))
2649 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002650 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 }
2652
2653 return (rval);
2654}
2655
2656
2657
2658/*
2659 * qla2x00_configure_local_loop
2660 * Updates Fibre Channel Device Database with local loop devices.
2661 *
2662 * Input:
2663 * ha = adapter block pointer.
2664 *
2665 * Returns:
2666 * 0 = success.
2667 */
2668static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002669qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670{
2671 int rval, rval2;
2672 int found_devs;
2673 int found;
2674 fc_port_t *fcport, *new_fcport;
2675
2676 uint16_t index;
2677 uint16_t entries;
2678 char *id_iter;
2679 uint16_t loop_id;
2680 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002681 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
2683 found_devs = 0;
2684 new_fcport = NULL;
2685 entries = MAX_FIBRE_DEVICES;
2686
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2688 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
2690 /* Get list of logged in devices. */
2691 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 &entries);
2694 if (rval != QLA_SUCCESS)
2695 goto cleanup_allocation;
2696
2697 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002698 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2700 entries * sizeof(struct gid_list_info)));
2701
2702 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002703 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 if (new_fcport == NULL) {
2705 rval = QLA_MEMORY_ALLOC_FAILED;
2706 goto cleanup_allocation;
2707 }
2708 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2709
2710 /*
2711 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2712 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2715 fcport->port_type != FCT_BROADCAST &&
2716 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2717
2718 DEBUG(printk("scsi(%ld): Marking port lost, "
2719 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
2722 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 }
2724 }
2725
2726 /* Add devices to port list. */
2727 id_iter = (char *)ha->gid_list;
2728 for (index = 0; index < entries; index++) {
2729 domain = ((struct gid_list_info *)id_iter)->domain;
2730 area = ((struct gid_list_info *)id_iter)->area;
2731 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002732 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 loop_id = (uint16_t)
2734 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002735 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 loop_id = le16_to_cpu(
2737 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002738 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
2740 /* Bypass reserved domain fields. */
2741 if ((domain & 0xf0) == 0xf0)
2742 continue;
2743
2744 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002745 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002746 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 continue;
2748
2749 /* Bypass invalid local loop ID. */
2750 if (loop_id > LAST_LOCAL_LOOP_ID)
2751 continue;
2752
2753 /* Fill in member data. */
2754 new_fcport->d_id.b.domain = domain;
2755 new_fcport->d_id.b.area = area;
2756 new_fcport->d_id.b.al_pa = al_pa;
2757 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002758 new_fcport->vp_idx = vha->vp_idx;
2759 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 if (rval2 != QLA_SUCCESS) {
2761 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2762 "information -- get_port_database=%x, "
2763 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002765 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766 vha->host_no));
2767 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 continue;
2769 }
2770
2771 /* Check for matching device in port list. */
2772 found = 0;
2773 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002774 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 if (memcmp(new_fcport->port_name, fcport->port_name,
2776 WWN_SIZE))
2777 continue;
2778
Shyam Sundarddb9b122009-03-24 09:08:10 -07002779 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 fcport->loop_id = new_fcport->loop_id;
2781 fcport->port_type = new_fcport->port_type;
2782 fcport->d_id.b24 = new_fcport->d_id.b24;
2783 memcpy(fcport->node_name, new_fcport->node_name,
2784 WWN_SIZE);
2785
2786 found++;
2787 break;
2788 }
2789
2790 if (!found) {
2791 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002792 if (vha->vp_idx) {
2793 new_fcport->vha = vha;
2794 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002795 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002796 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798 /* Allocate a new replacement fcport. */
2799 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002800 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801 if (new_fcport == NULL) {
2802 rval = QLA_MEMORY_ALLOC_FAILED;
2803 goto cleanup_allocation;
2804 }
2805 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2806 }
2807
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002808 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002809 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
2813 found_devs++;
2814 }
2815
2816cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002817 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
2819 if (rval != QLA_SUCCESS) {
2820 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 }
2823
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824 return (rval);
2825}
2826
2827static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002829{
2830#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002831 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2832 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002833 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002834 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002836
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002837 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002838 return;
2839
Giridhar Malavalic9afb9a2010-09-03 15:20:48 -07002840 if (atomic_read(&fcport->state) != FCS_ONLINE)
2841 return;
2842
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002843 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2844 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002845 return;
2846
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002848 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002849 if (rval != QLA_SUCCESS) {
2850 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2851 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002853 fcport->port_name[2], fcport->port_name[3],
2854 fcport->port_name[4], fcport->port_name[5],
2855 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002856 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002857 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002858 link_speed = link_speeds[LS_UNKNOWN];
2859 if (fcport->fp_speed < 5)
2860 link_speed = link_speeds[fcport->fp_speed];
2861 else if (fcport->fp_speed == 0x13)
2862 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002863 DEBUG2(qla_printk(KERN_INFO, ha,
2864 "iIDMA adjusted to %s GB/s on "
2865 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002866 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002867 fcport->port_name[1], fcport->port_name[2],
2868 fcport->port_name[3], fcport->port_name[4],
2869 fcport->port_name[5], fcport->port_name[6],
2870 fcport->port_name[7]));
2871 }
2872}
2873
Adrian Bunk23be3312006-11-24 02:46:01 +01002874static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002876{
2877 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002878 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 struct qla_hw_data *ha = vha->hw;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002880 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002881
Andrew Vasquezac280b62009-08-20 11:06:05 -07002882 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002883
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002884 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2885 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002886 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2887 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2888 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002889 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002890 if (!rport) {
2891 qla_printk(KERN_WARNING, ha,
2892 "Unable to allocate fc remote port!\n");
2893 return;
2894 }
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002895 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002896 *((fc_port_t **)rport->dd_data) = fcport;
Madhuranath Iyengar044d78e2011-01-28 15:17:56 -08002897 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002898
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002899 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002900
2901 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002902 if (fcport->port_type == FCT_INITIATOR)
2903 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2904 if (fcport->port_type == FCT_TARGET)
2905 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002906 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002907}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
2909/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002910 * qla2x00_update_fcport
2911 * Updates device on list.
2912 *
2913 * Input:
2914 * ha = adapter block pointer.
2915 * fcport = port structure pointer.
2916 *
2917 * Return:
2918 * 0 - Success
2919 * BIT_0 - error
2920 *
2921 * Context:
2922 * Kernel context.
2923 */
2924void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002926{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002928 fcport->login_retry = 0;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002929 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931 qla2x00_iidma_fcport(vha, fcport);
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08002932 qla24xx_update_fcport_fcp_prio(vha, fcport);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933 qla2x00_reg_remote_port(vha, fcport);
Giridhar Malavali38170fa2010-10-15 11:27:49 -07002934 atomic_set(&fcport->state, FCS_ONLINE);
Adrian Bunk23be3312006-11-24 02:46:01 +01002935}
2936
2937/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 * qla2x00_configure_fabric
2939 * Setup SNS devices with loop ID's.
2940 *
2941 * Input:
2942 * ha = adapter block pointer.
2943 *
2944 * Returns:
2945 * 0 = success.
2946 * BIT_0 = error
2947 */
2948static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002950{
2951 int rval, rval2;
2952 fc_port_t *fcport, *fcptemp;
2953 uint16_t next_loopid;
2954 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002955 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 struct qla_hw_data *ha = vha->hw;
2958 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959
2960 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002961 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002962 loop_id = NPH_F_PORT;
2963 else
2964 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 if (rval != QLA_SUCCESS) {
2967 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 return (QLA_SUCCESS);
2972 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002976 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002977 if (rval2 == QLA_RSCNS_HANDLED) {
2978 /* No point doing the scan, just continue. */
2979 return (QLA_SUCCESS);
2980 }
2981 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002982 /* FDMI support. */
2983 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2985 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002986
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002988 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002989 loop_id = NPH_SNS;
2990 else
2991 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002993 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 if (mb[0] != MBS_COMMAND_COMPLETE) {
2995 DEBUG2(qla_printk(KERN_INFO, ha,
2996 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002997 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 mb[0], mb[1], mb[2], mb[6], mb[7]));
2999 return (QLA_SUCCESS);
3000 }
3001
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3003 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 /* EMPTY */
3005 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 /* EMPTY */
3010 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 /* EMPTY */
3015 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 "failed.\n", vha->host_no));
3017 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 /* EMPTY */
3019 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 }
3022 }
3023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 if (rval != QLA_SUCCESS)
3026 break;
3027
3028 /*
3029 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003030 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3033 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 break;
3035
3036 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3037 continue;
3038
3039 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003041 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003043 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 fcport->port_type != FCT_INITIATOR &&
3045 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003046 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003047 fcport->loop_id,
3048 fcport->d_id.b.domain,
3049 fcport->d_id.b.area,
3050 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 fcport->loop_id = FC_NO_LOOP_ID;
3052 }
3053 }
3054 }
3055
3056 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003057 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
3059 /*
3060 * Scan through our port list and login entries that need to be
3061 * logged in.
3062 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003063 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3064 if (atomic_read(&vha->loop_down_timer) ||
3065 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 break;
3067
3068 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3069 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3070 continue;
3071
3072 if (fcport->loop_id == FC_NO_LOOP_ID) {
3073 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003074 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003075 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 if (rval != QLA_SUCCESS) {
3077 /* Ran out of IDs to use */
3078 break;
3079 }
3080 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 }
3084
3085 /* Exit if out of loop IDs. */
3086 if (rval != QLA_SUCCESS) {
3087 break;
3088 }
3089
3090 /*
3091 * Login and add the new devices to our port list.
3092 */
3093 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003094 if (atomic_read(&vha->loop_down_timer) ||
3095 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 break;
3097
3098 /* Find a new loop ID to use. */
3099 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003100 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 if (rval != QLA_SUCCESS) {
3102 /* Ran out of IDs to use */
3103 break;
3104 }
3105
bdf79622005-04-17 15:06:53 -05003106 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003107 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003108
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003109 if (vha->vp_idx) {
3110 fcport->vha = vha;
3111 fcport->vp_idx = vha->vp_idx;
3112 }
3113 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 }
3115 } while (0);
3116
3117 /* Free all new device structures not processed. */
3118 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3119 list_del(&fcport->list);
3120 kfree(fcport);
3121 }
3122
3123 if (rval) {
3124 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 }
3127
3128 return (rval);
3129}
3130
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131/*
3132 * qla2x00_find_all_fabric_devs
3133 *
3134 * Input:
3135 * ha = adapter block pointer.
3136 * dev = database device entry pointer.
3137 *
3138 * Returns:
3139 * 0 = success.
3140 *
3141 * Context:
3142 * Kernel context.
3143 */
3144static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003145qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3146 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147{
3148 int rval;
3149 uint16_t loop_id;
3150 fc_port_t *fcport, *new_fcport, *fcptemp;
3151 int found;
3152
3153 sw_info_t *swl;
3154 int swl_idx;
3155 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003156 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 struct qla_hw_data *ha = vha->hw;
3158 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003159 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160
3161 rval = QLA_SUCCESS;
3162
3163 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003164 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003165 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 /*EMPTY*/
3167 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 kfree(swl);
3172 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 kfree(swl);
3175 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 kfree(swl);
3178 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003179 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3181 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 }
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003183
3184 /* If other queries succeeded probe for FC-4 type */
3185 if (swl)
3186 qla2x00_gff_id(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 }
3188 swl_idx = 0;
3189
3190 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003191 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003193 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 return (QLA_MEMORY_ALLOC_FAILED);
3195 }
3196 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 /* Set start port ID scan at adapter ID. */
3198 first_dev = 1;
3199 last_dev = 0;
3200
3201 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202 loop_id = ha->min_external_loopid;
3203 for (; loop_id <= ha->max_loop_id; loop_id++) {
3204 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 continue;
3206
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003207 if (ha->current_topology == ISP_CFG_FL &&
3208 (atomic_read(&vha->loop_down_timer) ||
3209 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003210 atomic_set(&vha->loop_down_timer, 0);
3211 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3212 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003214 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215
3216 if (swl != NULL) {
3217 if (last_dev) {
3218 wrap.b24 = new_fcport->d_id.b24;
3219 } else {
3220 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3221 memcpy(new_fcport->node_name,
3222 swl[swl_idx].node_name, WWN_SIZE);
3223 memcpy(new_fcport->port_name,
3224 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003225 memcpy(new_fcport->fabric_port_name,
3226 swl[swl_idx].fabric_port_name, WWN_SIZE);
3227 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003228 new_fcport->fc4_type = swl[swl_idx].fc4_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
3230 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3231 last_dev = 1;
3232 }
3233 swl_idx++;
3234 }
3235 } else {
3236 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 if (rval != QLA_SUCCESS) {
3239 qla_printk(KERN_WARNING, ha,
3240 "SNS scan failed -- assuming zero-entry "
3241 "result...\n");
3242 list_for_each_entry_safe(fcport, fcptemp,
3243 new_fcports, list) {
3244 list_del(&fcport->list);
3245 kfree(fcport);
3246 }
3247 rval = QLA_SUCCESS;
3248 break;
3249 }
3250 }
3251
3252 /* If wrap on switch device list, exit. */
3253 if (first_dev) {
3254 wrap.b24 = new_fcport->d_id.b24;
3255 first_dev = 0;
3256 } else if (new_fcport->d_id.b24 == wrap.b24) {
3257 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003258 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3260 break;
3261 }
3262
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003263 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 continue;
3266
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003267 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 found = 0;
3269 if (ha->num_vhosts) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003270 unsigned long flags;
3271
3272 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003273 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003274 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3275 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003276 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003278 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003279 spin_unlock_irqrestore(&ha->vport_slock, flags);
3280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003281 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003282 continue;
3283 }
3284
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003285 /* Bypass if same domain and area of adapter. */
3286 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003288 ISP_CFG_FL)
3289 continue;
3290
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 /* Bypass reserved domain fields. */
3292 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3293 continue;
3294
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003295 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
Chad Dupuis4da26e12010-10-15 11:27:40 -07003296 if (ql2xgffidenable &&
3297 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
3298 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
Chad Dupuise8c72ba2010-07-23 15:28:25 +05003299 continue;
3300
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 /* Locate matching device in database. */
3302 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 if (memcmp(new_fcport->port_name, fcport->port_name,
3305 WWN_SIZE))
3306 continue;
3307
3308 found++;
3309
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003310 /* Update port state. */
3311 memcpy(fcport->fabric_port_name,
3312 new_fcport->fabric_port_name, WWN_SIZE);
3313 fcport->fp_speed = new_fcport->fp_speed;
3314
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 /*
3316 * If address the same and state FCS_ONLINE, nothing
3317 * changed.
3318 */
3319 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3320 atomic_read(&fcport->state) == FCS_ONLINE) {
3321 break;
3322 }
3323
3324 /*
3325 * If device was not a fabric device before.
3326 */
3327 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3328 fcport->d_id.b24 = new_fcport->d_id.b24;
3329 fcport->loop_id = FC_NO_LOOP_ID;
3330 fcport->flags |= (FCF_FABRIC_DEVICE |
3331 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003332 break;
3333 }
3334
3335 /*
3336 * Port ID changed or device was marked to be updated;
3337 * Log it out if still logged in and mark it for
3338 * relogin later.
3339 */
3340 fcport->d_id.b24 = new_fcport->d_id.b24;
3341 fcport->flags |= FCF_LOGIN_NEEDED;
3342 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003343 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003344 fcport->port_type != FCT_INITIATOR &&
3345 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003347 fcport->d_id.b.domain, fcport->d_id.b.area,
3348 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 fcport->loop_id = FC_NO_LOOP_ID;
3350 }
3351
3352 break;
3353 }
3354
3355 if (found)
3356 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 /* If device was not in our fcports list, then add it. */
3358 list_add_tail(&new_fcport->list, new_fcports);
3359
3360 /* Allocate a new replacement fcport. */
3361 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003362 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003363 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003364 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 return (QLA_MEMORY_ALLOC_FAILED);
3366 }
3367 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3368 new_fcport->d_id.b24 = nxt_d_id.b24;
3369 }
3370
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003371 kfree(swl);
3372 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 return (rval);
3375}
3376
3377/*
3378 * qla2x00_find_new_loop_id
3379 * Scan through our port list and find a new usable loop ID.
3380 *
3381 * Input:
3382 * ha: adapter state pointer.
3383 * dev: port structure pointer.
3384 *
3385 * Returns:
3386 * qla2x00 local function return status code.
3387 *
3388 * Context:
3389 * Kernel context.
3390 */
Joe Carnuccio03bcfb52011-03-30 11:46:27 -07003391int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393{
3394 int rval;
3395 int found;
3396 fc_port_t *fcport;
3397 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398 struct qla_hw_data *ha = vha->hw;
3399 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003400 struct scsi_qla_host *tvp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003401 unsigned long flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003402
3403 rval = QLA_SUCCESS;
3404
3405 /* Save starting loop ID. */
3406 first_loop_id = dev->loop_id;
3407
3408 for (;;) {
3409 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412
3413 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416
3417 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 /* first loop ID. */
3420 dev->loop_id = ha->min_external_loopid;
3421 }
3422
3423 /* Check for loop ID being already in use. */
3424 found = 0;
3425 fcport = NULL;
Arun Easifeafb7b2010-09-03 14:57:00 -07003426
3427 spin_lock_irqsave(&ha->vport_slock, flags);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003428 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3430 if (fcport->loop_id == dev->loop_id &&
3431 fcport != dev) {
3432 /* ID possibly in use */
3433 found++;
3434 break;
3435 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003437 if (found)
3438 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 }
Arun Easifeafb7b2010-09-03 14:57:00 -07003440 spin_unlock_irqrestore(&ha->vport_slock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003441
3442 /* If not in use then it is free to use. */
3443 if (!found) {
3444 break;
3445 }
3446
3447 /* ID in use. Try next value. */
3448 dev->loop_id++;
3449
3450 /* If wrap around. No free ID to use. */
3451 if (dev->loop_id == first_loop_id) {
3452 dev->loop_id = FC_NO_LOOP_ID;
3453 rval = QLA_FUNCTION_FAILED;
3454 break;
3455 }
3456 }
3457
3458 return (rval);
3459}
3460
3461/*
3462 * qla2x00_device_resync
3463 * Marks devices in the database that needs resynchronization.
3464 *
3465 * Input:
3466 * ha = adapter block pointer.
3467 *
3468 * Context:
3469 * Kernel context.
3470 */
3471static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473{
3474 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475 uint32_t mask;
3476 fc_port_t *fcport;
3477 uint32_t rscn_entry;
3478 uint8_t rscn_out_iter;
3479 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003480 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481
3482 rval = QLA_RSCNS_HANDLED;
3483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003484 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3485 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003487 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 format = MSB(MSW(rscn_entry));
3489 d_id.b.domain = LSB(MSW(rscn_entry));
3490 d_id.b.area = MSB(LSW(rscn_entry));
3491 d_id.b.al_pa = LSB(LSW(rscn_entry));
3492
3493 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3494 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 d_id.b.area, d_id.b.al_pa));
3497
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 vha->rscn_out_ptr++;
3499 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3500 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
3502 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003503 for (rscn_out_iter = vha->rscn_out_ptr;
3504 !vha->flags.rscn_queue_overflow &&
3505 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 rscn_out_iter = (rscn_out_iter ==
3507 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3508
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003509 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510 break;
3511
3512 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514 rscn_out_iter));
3515
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 }
3518
3519 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003520 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
3524 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 }
3527
3528 switch (format) {
3529 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 mask = 0xffffff;
3531 break;
3532 case 1:
3533 mask = 0xffff00;
3534 break;
3535 case 2:
3536 mask = 0xff0000;
3537 break;
3538 default:
3539 mask = 0x0;
3540 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 break;
3543 }
3544
3545 rval = QLA_SUCCESS;
3546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3549 (fcport->d_id.b24 & mask) != d_id.b24 ||
3550 fcport->port_type == FCT_BROADCAST)
3551 continue;
3552
3553 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3554 if (format != 3 ||
3555 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003557 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558 }
3559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560 }
3561 }
3562 return (rval);
3563}
3564
3565/*
3566 * qla2x00_fabric_dev_login
3567 * Login fabric target device and update FC port database.
3568 *
3569 * Input:
3570 * ha: adapter state pointer.
3571 * fcport: port structure list pointer.
3572 * next_loopid: contains value of a new loop ID that can be used
3573 * by the next login attempt.
3574 *
3575 * Returns:
3576 * qla2x00 local function return status code.
3577 *
3578 * Context:
3579 * Kernel context.
3580 */
3581static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003583 uint16_t *next_loopid)
3584{
3585 int rval;
3586 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003587 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003588 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003589
3590 rval = QLA_SUCCESS;
3591 retry = 0;
3592
Andrew Vasquezac280b62009-08-20 11:06:05 -07003593 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003594 if (fcport->flags & FCF_ASYNC_SENT)
3595 return rval;
3596 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003597 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3598 if (!rval)
3599 return rval;
3600 }
3601
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003602 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003604 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003605 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003606 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003607 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003608 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003609 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003612 fcport->d_id.b.domain, fcport->d_id.b.area,
3613 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003614 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 }
3618 }
3619
3620 return (rval);
3621}
3622
3623/*
3624 * qla2x00_fabric_login
3625 * Issue fabric login command.
3626 *
3627 * Input:
3628 * ha = adapter block pointer.
3629 * device = pointer to FC device type structure.
3630 *
3631 * Returns:
3632 * 0 - Login successfully
3633 * 1 - Login failed
3634 * 2 - Initiator device
3635 * 3 - Fatal error
3636 */
3637int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003638qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 uint16_t *next_loopid)
3640{
3641 int rval;
3642 int retry;
3643 uint16_t tmp_loopid;
3644 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003645 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646
3647 retry = 0;
3648 tmp_loopid = 0;
3649
3650 for (;;) {
3651 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3652 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3655
3656 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003657 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658 fcport->d_id.b.domain, fcport->d_id.b.area,
3659 fcport->d_id.b.al_pa, mb, BIT_0);
3660 if (mb[0] == MBS_PORT_ID_USED) {
3661 /*
3662 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003663 * recommends the driver perform an implicit login with
3664 * the specified ID again. The ID we just used is save
3665 * here so we return with an ID that can be tried by
3666 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003667 */
3668 retry++;
3669 tmp_loopid = fcport->loop_id;
3670 fcport->loop_id = mb[1];
3671
3672 DEBUG(printk("Fabric Login: port in use - next "
3673 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3674 fcport->loop_id, fcport->d_id.b.domain,
3675 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3676
3677 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3678 /*
3679 * Login succeeded.
3680 */
3681 if (retry) {
3682 /* A retry occurred before. */
3683 *next_loopid = tmp_loopid;
3684 } else {
3685 /*
3686 * No retry occurred before. Just increment the
3687 * ID value for next login.
3688 */
3689 *next_loopid = (fcport->loop_id + 1);
3690 }
3691
3692 if (mb[1] & BIT_0) {
3693 fcport->port_type = FCT_INITIATOR;
3694 } else {
3695 fcport->port_type = FCT_TARGET;
3696 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003697 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 }
3699 }
3700
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003701 if (mb[10] & BIT_0)
3702 fcport->supported_classes |= FC_COS_CLASS2;
3703 if (mb[10] & BIT_1)
3704 fcport->supported_classes |= FC_COS_CLASS3;
3705
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706 rval = QLA_SUCCESS;
3707 break;
3708 } else if (mb[0] == MBS_LOOP_ID_USED) {
3709 /*
3710 * Loop ID already used, try next loop ID.
3711 */
3712 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003714 if (rval != QLA_SUCCESS) {
3715 /* Ran out of loop IDs to use */
3716 break;
3717 }
3718 } else if (mb[0] == MBS_COMMAND_ERROR) {
3719 /*
3720 * Firmware possibly timed out during login. If NO
3721 * retries are left to do then the device is declared
3722 * dead.
3723 */
3724 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003725 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003726 fcport->d_id.b.domain, fcport->d_id.b.area,
3727 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003728 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729
3730 rval = 1;
3731 break;
3732 } else {
3733 /*
3734 * unrecoverable / not handled error
3735 */
3736 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003737 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003738 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003739 fcport->d_id.b.domain, fcport->d_id.b.area,
3740 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3741
3742 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003743 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003744 fcport->d_id.b.domain, fcport->d_id.b.area,
3745 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003747 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748
3749 rval = 3;
3750 break;
3751 }
3752 }
3753
3754 return (rval);
3755}
3756
3757/*
3758 * qla2x00_local_device_login
3759 * Issue local device login command.
3760 *
3761 * Input:
3762 * ha = adapter block pointer.
3763 * loop_id = loop id of device to login to.
3764 *
3765 * Returns (Where's the #define!!!!):
3766 * 0 - Login successfully
3767 * 1 - Login failed
3768 * 3 - Fatal error
3769 */
3770int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003771qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772{
3773 int rval;
3774 uint16_t mb[MAILBOX_REGISTER_COUNT];
3775
3776 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 if (rval == QLA_SUCCESS) {
3779 /* Interrogate mailbox registers for any errors */
3780 if (mb[0] == MBS_COMMAND_ERROR)
3781 rval = 1;
3782 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3783 /* device not in PCB table */
3784 rval = 3;
3785 }
3786
3787 return (rval);
3788}
3789
3790/*
3791 * qla2x00_loop_resync
3792 * Resync with fibre channel devices.
3793 *
3794 * Input:
3795 * ha = adapter block pointer.
3796 *
3797 * Returns:
3798 * 0 = success
3799 */
3800int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003802{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003803 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003804 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003805 struct req_que *req;
3806 struct rsp_que *rsp;
3807
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003808 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003809 req = vha->hw->req_q_map[0];
3810 else
3811 req = vha->req;
3812 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 atomic_set(&vha->loop_state, LOOP_UPDATE);
3815 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3816 if (vha->flags.online) {
3817 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3819 wait_time = 256;
3820 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003823 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003824 qla2x00_marker(vha, req, rsp, 0, 0,
3825 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003826 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827
3828 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003830
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003831 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833 } while (!atomic_read(&vha->loop_down_timer) &&
3834 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3835 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3836 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003838 }
3839
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003842
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003843 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003844 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845
3846 return (rval);
3847}
3848
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003849/*
3850* qla2x00_perform_loop_resync
3851* Description: This function will set the appropriate flags and call
3852* qla2x00_loop_resync. If successful loop will be resynced
3853* Arguments : scsi_qla_host_t pointer
3854* returm : Success or Failure
3855*/
3856
3857int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
3858{
3859 int32_t rval = 0;
3860
3861 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
3862 /*Configure the flags so that resync happens properly*/
3863 atomic_set(&ha->loop_down_timer, 0);
3864 if (!(ha->device_flags & DFLG_NO_CABLE)) {
3865 atomic_set(&ha->loop_state, LOOP_UP);
3866 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
3867 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
3868 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3869
3870 rval = qla2x00_loop_resync(ha);
3871 } else
3872 atomic_set(&ha->loop_state, LOOP_DEAD);
3873
3874 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
3875 }
3876
3877 return rval;
3878}
3879
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003881qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003882{
3883 fc_port_t *fcport;
Arun Easifeafb7b2010-09-03 14:57:00 -07003884 struct scsi_qla_host *vha;
3885 struct qla_hw_data *ha = base_vha->hw;
3886 unsigned long flags;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003887
Arun Easifeafb7b2010-09-03 14:57:00 -07003888 spin_lock_irqsave(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003889 /* Go with deferred removal of rport references. */
Arun Easifeafb7b2010-09-03 14:57:00 -07003890 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
3891 atomic_inc(&vha->vref_count);
3892 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Dan Carpenter8ae598d2010-12-21 16:00:15 -08003893 if (fcport->drport &&
Arun Easifeafb7b2010-09-03 14:57:00 -07003894 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
3895 spin_unlock_irqrestore(&ha->vport_slock, flags);
3896
Andrew Vasquez67becc02009-08-25 11:36:20 -07003897 qla2x00_rport_del(fcport);
Arun Easifeafb7b2010-09-03 14:57:00 -07003898
3899 spin_lock_irqsave(&ha->vport_slock, flags);
3900 }
3901 }
3902 atomic_dec(&vha->vref_count);
3903 }
3904 spin_unlock_irqrestore(&ha->vport_slock, flags);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003905}
3906
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003907/*
3908* qla82xx_quiescent_state_cleanup
3909* Description: This function will block the new I/Os
3910* Its not aborting any I/Os as context
3911* is not destroyed during quiescence
3912* Arguments: scsi_qla_host_t
3913* return : void
3914*/
3915void
3916qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha)
3917{
3918 struct qla_hw_data *ha = vha->hw;
3919 struct scsi_qla_host *vp;
3920
3921 qla_printk(KERN_INFO, ha,
3922 "Performing ISP error recovery - ha= %p.\n", ha);
3923
3924 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3925 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3926 atomic_set(&vha->loop_state, LOOP_DOWN);
3927 qla2x00_mark_all_devices_lost(vha, 0);
3928 list_for_each_entry(vp, &ha->vp_list, list)
3929 qla2x00_mark_all_devices_lost(vha, 0);
3930 } else {
3931 if (!atomic_read(&vha->loop_down_timer))
3932 atomic_set(&vha->loop_down_timer,
3933 LOOP_DOWN_TIME);
3934 }
3935 /* Wait for pending cmds to complete */
3936 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
3937}
3938
Giridhar Malavalia9083012010-04-12 17:59:55 -07003939void
3940qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3941{
3942 struct qla_hw_data *ha = vha->hw;
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003943 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07003944 unsigned long flags;
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003945 fc_port_t *fcport;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003946
Saurav Kashyape46ef002011-02-23 15:27:16 -08003947 /* For ISP82XX, driver waits for completion of the commands.
3948 * online flag should be set.
3949 */
3950 if (!IS_QLA82XX(ha))
3951 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003952 ha->flags.chip_reset_done = 0;
3953 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3954 ha->qla_stats.total_isp_aborts++;
3955
3956 qla_printk(KERN_INFO, ha,
3957 "Performing ISP error recovery - ha= %p.\n", ha);
3958
Saurav Kashyape46ef002011-02-23 15:27:16 -08003959 /* For ISP82XX, reset_chip is just disabling interrupts.
3960 * Driver waits for the completion of the commands.
3961 * the interrupts need to be enabled.
3962 */
Giridhar Malavalia9083012010-04-12 17:59:55 -07003963 if (!IS_QLA82XX(ha))
3964 ha->isp_ops->reset_chip(vha);
3965
3966 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3967 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3968 atomic_set(&vha->loop_state, LOOP_DOWN);
3969 qla2x00_mark_all_devices_lost(vha, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003970
3971 spin_lock_irqsave(&ha->vport_slock, flags);
Saurav Kashyap579d12b2010-12-21 16:00:14 -08003972 list_for_each_entry(vp, &ha->vp_list, list) {
Arun Easifeafb7b2010-09-03 14:57:00 -07003973 atomic_inc(&vp->vref_count);
3974 spin_unlock_irqrestore(&ha->vport_slock, flags);
3975
Giridhar Malavalia9083012010-04-12 17:59:55 -07003976 qla2x00_mark_all_devices_lost(vp, 0);
Arun Easifeafb7b2010-09-03 14:57:00 -07003977
3978 spin_lock_irqsave(&ha->vport_slock, flags);
3979 atomic_dec(&vp->vref_count);
3980 }
3981 spin_unlock_irqrestore(&ha->vport_slock, flags);
Giridhar Malavalia9083012010-04-12 17:59:55 -07003982 } else {
3983 if (!atomic_read(&vha->loop_down_timer))
3984 atomic_set(&vha->loop_down_timer,
3985 LOOP_DOWN_TIME);
3986 }
3987
Andrew Vasquez6aef87b2011-02-23 15:27:13 -08003988 /* Clear all async request states across all VPs. */
3989 list_for_each_entry(fcport, &vha->vp_fcports, list)
3990 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3991 spin_lock_irqsave(&ha->vport_slock, flags);
3992 list_for_each_entry(vp, &ha->vp_list, list) {
3993 atomic_inc(&vp->vref_count);
3994 spin_unlock_irqrestore(&ha->vport_slock, flags);
3995
3996 list_for_each_entry(fcport, &vp->vp_fcports, list)
3997 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
3998
3999 spin_lock_irqsave(&ha->vport_slock, flags);
4000 atomic_dec(&vp->vref_count);
4001 }
4002 spin_unlock_irqrestore(&ha->vport_slock, flags);
4003
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004004 if (!ha->flags.eeh_busy) {
4005 /* Make sure for ISP 82XX IO DMA is complete */
4006 if (IS_QLA82XX(ha)) {
Giridhar Malavali71905752011-02-23 15:27:10 -08004007 qla82xx_chip_reset_cleanup(vha);
Giridhar Malavalia9083012010-04-12 17:59:55 -07004008
Saurav Kashyape46ef002011-02-23 15:27:16 -08004009 /* Done waiting for pending commands.
4010 * Reset the online flag.
4011 */
4012 vha->flags.online = 0;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004013 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004014
Lalit Chandivadebddd2d62010-09-03 15:20:53 -07004015 /* Requeue all commands in outstanding command list. */
4016 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4017 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004018}
4019
4020/*
4021* qla2x00_abort_isp
4022* Resets ISP and aborts all outstanding commands.
4023*
4024* Input:
4025* ha = adapter block pointer.
4026*
4027* Returns:
4028* 0 = success
4029*/
4030int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004031qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004032{
Andrew Vasquez476e8972006-08-23 14:54:55 -07004033 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 struct qla_hw_data *ha = vha->hw;
4036 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004037 struct req_que *req = ha->req_q_map[0];
Arun Easifeafb7b2010-09-03 14:57:00 -07004038 unsigned long flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07004041 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042
Andrew Vasquez85880802009-12-15 21:29:46 -08004043 if (unlikely(pci_channel_offline(ha->pdev) &&
4044 ha->flags.pci_channel_io_perm_failure)) {
4045 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
4046 status = 0;
4047 return status;
4048 }
4049
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004050 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08004051
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004052 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004054 if (!qla2x00_restart_isp(vha)) {
4055 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004058 /*
4059 * Issue marker command only when we are going
4060 * to start the I/O .
4061 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 }
4064
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004065 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004067 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004068
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004069 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004070 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07004071
Lalit Chandivade29c53972009-10-13 15:16:47 -07004072 if (IS_QLA81XX(ha))
4073 qla2x00_get_fw_version(vha,
4074 &ha->fw_major_version,
4075 &ha->fw_minor_version,
4076 &ha->fw_subminor_version,
4077 &ha->fw_attributes, &ha->fw_memory_size,
4078 ha->mpi_version, &ha->mpi_capabilities,
4079 ha->phy_version);
4080
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004081 if (ha->fce) {
4082 ha->flags.fce_enabled = 1;
4083 memset(ha->fce, 0,
4084 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004085 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08004086 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
4087 &ha->fce_bufs);
4088 if (rval) {
4089 qla_printk(KERN_WARNING, ha,
4090 "Unable to reinitialize FCE "
4091 "(%d).\n", rval);
4092 ha->flags.fce_enabled = 0;
4093 }
4094 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004095
4096 if (ha->eft) {
4097 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004098 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07004099 ha->eft_dma, EFT_NUM_BUFFERS);
4100 if (rval) {
4101 qla_printk(KERN_WARNING, ha,
4102 "Unable to reinitialize EFT "
4103 "(%d).\n", rval);
4104 }
4105 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004106 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004107 vha->flags.online = 1;
4108 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004109 if (ha->isp_abort_cnt == 0) {
4110 qla_printk(KERN_WARNING, ha,
4111 "ISP error recovery failed - "
4112 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004113 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004114 * The next call disables the board
4115 * completely.
4116 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004117 ha->isp_ops->reset_adapter(vha);
4118 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004119 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004120 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004121 status = 0;
4122 } else { /* schedule another ISP abort */
4123 ha->isp_abort_cnt--;
4124 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004125 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004126 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004127 status = 1;
4128 }
4129 } else {
4130 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4131 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4132 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133 vha->host_no, ha->isp_abort_cnt));
4134 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135 status = 1;
4136 }
4137 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004138
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139 }
4140
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004141 if (!status) {
4142 DEBUG(printk(KERN_INFO
4143 "qla2x00_abort_isp(%ld): succeeded.\n",
4144 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07004145
4146 spin_lock_irqsave(&ha->vport_slock, flags);
4147 list_for_each_entry(vp, &ha->vp_list, list) {
4148 if (vp->vp_idx) {
4149 atomic_inc(&vp->vref_count);
4150 spin_unlock_irqrestore(&ha->vport_slock, flags);
4151
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004152 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07004153
4154 spin_lock_irqsave(&ha->vport_slock, flags);
4155 atomic_dec(&vp->vref_count);
4156 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004157 }
Arun Easifeafb7b2010-09-03 14:57:00 -07004158 spin_unlock_irqrestore(&ha->vport_slock, flags);
4159
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 qla_printk(KERN_INFO, ha,
4162 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 }
4164
4165 return(status);
4166}
4167
4168/*
4169* qla2x00_restart_isp
4170* restarts the ISP after a reset
4171*
4172* Input:
4173* ha = adapter block pointer.
4174*
4175* Returns:
4176* 0 = success
4177*/
4178static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004179qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004180{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004181 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004182 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004183 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004184 struct req_que *req = ha->req_q_map[0];
4185 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004186
4187 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004188 if (qla2x00_isp_firmware(vha)) {
4189 vha->flags.online = 0;
4190 status = ha->isp_ops->chip_diag(vha);
4191 if (!status)
4192 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 }
4194
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004195 if (!status && !(status = qla2x00_init_rings(vha))) {
4196 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004197 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004198 /* Initialize the queues in use */
4199 qla25xx_init_queues(ha);
4200
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004201 status = qla2x00_fw_ready(vha);
4202 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004203 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004204 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004205
4206 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004207 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004209 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004210 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4211 wait_time = 256;
4212 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004213 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4214 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004216 } while (!atomic_read(&vha->loop_down_timer) &&
4217 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4218 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4219 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 }
4221
4222 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 status = 0;
4225
4226 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4227 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004228 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004229 }
4230 return (status);
4231}
4232
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004233static int
4234qla25xx_init_queues(struct qla_hw_data *ha)
4235{
4236 struct rsp_que *rsp = NULL;
4237 struct req_que *req = NULL;
4238 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4239 int ret = -1;
4240 int i;
4241
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004242 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004243 rsp = ha->rsp_q_map[i];
4244 if (rsp) {
4245 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004246 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004247 if (ret != QLA_SUCCESS)
4248 DEBUG2_17(printk(KERN_WARNING
4249 "%s Rsp que:%d init failed\n", __func__,
4250 rsp->id));
4251 else
4252 DEBUG2_17(printk(KERN_INFO
4253 "%s Rsp que:%d inited\n", __func__,
4254 rsp->id));
4255 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004256 }
4257 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004258 req = ha->req_q_map[i];
4259 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004260 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004261 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004262 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004263 if (ret != QLA_SUCCESS)
4264 DEBUG2_17(printk(KERN_WARNING
4265 "%s Req que:%d init failed\n", __func__,
4266 req->id));
4267 else
4268 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004269 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004270 req->id));
4271 }
4272 }
4273 return ret;
4274}
4275
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276/*
4277* qla2x00_reset_adapter
4278* Reset adapter.
4279*
4280* Input:
4281* ha = adapter block pointer.
4282*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004283void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004284qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285{
4286 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004287 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004288 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004289
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004290 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004291 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004292
Linus Torvalds1da177e2005-04-16 15:20:36 -07004293 spin_lock_irqsave(&ha->hardware_lock, flags);
4294 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4295 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4296 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4297 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4298 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4299}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004300
4301void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004302qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004303{
4304 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004305 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004306 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4307
Giridhar Malavalia9083012010-04-12 17:59:55 -07004308 if (IS_QLA82XX(ha))
4309 return;
4310
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004311 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004312 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004313
4314 spin_lock_irqsave(&ha->hardware_lock, flags);
4315 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4316 RD_REG_DWORD(&reg->hccr);
4317 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4318 RD_REG_DWORD(&reg->hccr);
4319 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004320
4321 if (IS_NOPOLLING_TYPE(ha))
4322 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004323}
4324
David Miller4e08df32007-04-16 12:37:43 -07004325/* On sparc systems, obtain port and node WWN from firmware
4326 * properties.
4327 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004328static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4329 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004330{
4331#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004332 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004333 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004334 struct device_node *dp = pci_device_to_OF_node(pdev);
4335 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004336 int len;
4337
4338 val = of_get_property(dp, "port-wwn", &len);
4339 if (val && len >= WWN_SIZE)
4340 memcpy(nv->port_name, val, WWN_SIZE);
4341
4342 val = of_get_property(dp, "node-wwn", &len);
4343 if (val && len >= WWN_SIZE)
4344 memcpy(nv->node_name, val, WWN_SIZE);
4345#endif
4346}
4347
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004348int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004349qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004350{
David Miller4e08df32007-04-16 12:37:43 -07004351 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004352 struct init_cb_24xx *icb;
4353 struct nvram_24xx *nv;
4354 uint32_t *dptr;
4355 uint8_t *dptr1, *dptr2;
4356 uint32_t chksum;
4357 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004358 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004359
David Miller4e08df32007-04-16 12:37:43 -07004360 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004361 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004362 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004363
4364 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004365 if (ha->flags.port0) {
4366 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4367 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4368 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004369 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004370 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4371 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004372 ha->nvram_size = sizeof(struct nvram_24xx);
4373 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004374 if (IS_QLA82XX(ha))
4375 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004376
Seokmann Ju281afe12007-07-26 13:43:34 -07004377 /* Get VPD data into cache */
4378 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004379 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004380 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4381
4382 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004383 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004384 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004385 ha->nvram_size);
4386 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4387 chksum += le32_to_cpu(*dptr++);
4388
Andrew Vasquez76403352009-04-06 22:33:39 -07004389 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004390 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004391
4392 /* Bad NVRAM data, set defaults parameters. */
4393 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4394 || nv->id[3] != ' ' ||
4395 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4396 /* Reset NVRAM data. */
4397 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4398 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4399 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004400 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4401 "invalid -- WWPN) defaults.\n");
4402
4403 /*
4404 * Set default initialization control block.
4405 */
4406 memset(nv, 0, ha->nvram_size);
4407 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4408 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4409 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4410 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4411 nv->exchange_count = __constant_cpu_to_le16(0);
4412 nv->hard_address = __constant_cpu_to_le16(124);
4413 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004414 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004415 nv->port_name[2] = 0x00;
4416 nv->port_name[3] = 0xe0;
4417 nv->port_name[4] = 0x8b;
4418 nv->port_name[5] = 0x1c;
4419 nv->port_name[6] = 0x55;
4420 nv->port_name[7] = 0x86;
4421 nv->node_name[0] = 0x20;
4422 nv->node_name[1] = 0x00;
4423 nv->node_name[2] = 0x00;
4424 nv->node_name[3] = 0xe0;
4425 nv->node_name[4] = 0x8b;
4426 nv->node_name[5] = 0x1c;
4427 nv->node_name[6] = 0x55;
4428 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004429 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004430 nv->login_retry_count = __constant_cpu_to_le16(8);
4431 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4432 nv->login_timeout = __constant_cpu_to_le16(0);
4433 nv->firmware_options_1 =
4434 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4435 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4436 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4437 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4438 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4439 nv->efi_parameters = __constant_cpu_to_le32(0);
4440 nv->reset_delay = 5;
4441 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4442 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4443 nv->link_down_timeout = __constant_cpu_to_le16(30);
4444
4445 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004446 }
4447
4448 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004449 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004450
4451 /* Copy 1st segment. */
4452 dptr1 = (uint8_t *)icb;
4453 dptr2 = (uint8_t *)&nv->version;
4454 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4455 while (cnt--)
4456 *dptr1++ = *dptr2++;
4457
4458 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004459 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004460
4461 /* Copy 2nd segment. */
4462 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4463 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4464 cnt = (uint8_t *)&icb->reserved_3 -
4465 (uint8_t *)&icb->interrupt_delay_timer;
4466 while (cnt--)
4467 *dptr1++ = *dptr2++;
4468
4469 /*
4470 * Setup driver NVRAM options.
4471 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004472 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004473 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004474
Andrew Vasquez5341e862006-05-17 15:09:16 -07004475 /* Use alternate WWN? */
4476 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4477 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4478 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4479 }
4480
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004481 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004482 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004483 /*
4484 * Firmware will apply the following mask if the nodename was
4485 * not provided.
4486 */
4487 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4488 icb->node_name[0] &= 0xF0;
4489 }
4490
4491 /* Set host adapter parameters. */
4492 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004493 ha->flags.enable_lip_reset = 0;
4494 ha->flags.enable_lip_full_login =
4495 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4496 ha->flags.enable_target_reset =
4497 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004498 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004499 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004500
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004501 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4502 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004503
4504 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4505 sizeof(ha->fw_seriallink_options24));
4506
4507 /* save HBA serial number */
4508 ha->serial0 = icb->port_name[5];
4509 ha->serial1 = icb->port_name[6];
4510 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004511 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4512 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004513
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004514 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4515
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004516 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4517
4518 /* Set minimum login_timeout to 4 seconds. */
4519 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4520 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4521 if (le16_to_cpu(nv->login_timeout) < 4)
4522 nv->login_timeout = __constant_cpu_to_le16(4);
4523 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004524 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004525
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004526 /* Set minimum RATOV to 100 tenths of a second. */
4527 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004528
4529 ha->loop_reset_delay = nv->reset_delay;
4530
4531 /* Link Down Timeout = 0:
4532 *
4533 * When Port Down timer expires we will start returning
4534 * I/O's to OS with "DID_NO_CONNECT".
4535 *
4536 * Link Down Timeout != 0:
4537 *
4538 * The driver waits for the link to come up after link down
4539 * before returning I/Os to OS with "DID_NO_CONNECT".
4540 */
4541 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4542 ha->loop_down_abort_time =
4543 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4544 } else {
4545 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4546 ha->loop_down_abort_time =
4547 (LOOP_DOWN_TIME - ha->link_down_timeout);
4548 }
4549
4550 /* Need enough time to try and get the port back. */
4551 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4552 if (qlport_down_retry)
4553 ha->port_down_retry_count = qlport_down_retry;
4554
4555 /* Set login_retry_count */
4556 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4557 if (ha->port_down_retry_count ==
4558 le16_to_cpu(nv->port_down_retry_count) &&
4559 ha->port_down_retry_count > 3)
4560 ha->login_retry_count = ha->port_down_retry_count;
4561 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4562 ha->login_retry_count = ha->port_down_retry_count;
4563 if (ql2xloginretrycount)
4564 ha->login_retry_count = ql2xloginretrycount;
4565
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004566 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004567 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004568 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4569 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4570 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4571 le16_to_cpu(icb->interrupt_delay_timer): 2;
4572 }
4573 icb->firmware_options_2 &= __constant_cpu_to_le32(
4574 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004575 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004576 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004577 ha->zio_mode = QLA_ZIO_MODE_6;
4578
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004579 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004580 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004581 ha->zio_timer * 100));
4582 qla_printk(KERN_INFO, ha,
4583 "ZIO mode %d enabled; timer delay (%d us).\n",
4584 ha->zio_mode, ha->zio_timer * 100);
4585
4586 icb->firmware_options_2 |= cpu_to_le32(
4587 (uint32_t)ha->zio_mode);
4588 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004589 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004590 }
4591
David Miller4e08df32007-04-16 12:37:43 -07004592 if (rval) {
4593 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004594 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004595 }
4596 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004597}
4598
Adrian Bunk413975a2006-06-30 02:33:06 -07004599static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004600qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4601 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004602{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004603 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004604 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004605 uint32_t *dcode, dlen;
4606 uint32_t risc_addr;
4607 uint32_t risc_size;
4608 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004609 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004610 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004611
4612 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004613 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004614
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004615 rval = QLA_SUCCESS;
4616
4617 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004618 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004619 *srisc_addr = 0;
4620
4621 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004622 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004623 for (i = 0; i < 4; i++)
4624 dcode[i] = be32_to_cpu(dcode[i]);
4625 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4626 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4627 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4628 dcode[3] == 0)) {
4629 qla_printk(KERN_WARNING, ha,
4630 "Unable to verify integrity of flash firmware image!\n");
4631 qla_printk(KERN_WARNING, ha,
4632 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4633 dcode[1], dcode[2], dcode[3]);
4634
4635 return QLA_FUNCTION_FAILED;
4636 }
4637
4638 while (segments && rval == QLA_SUCCESS) {
4639 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004640 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004641
4642 risc_addr = be32_to_cpu(dcode[2]);
4643 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4644 risc_size = be32_to_cpu(dcode[3]);
4645
4646 fragment = 0;
4647 while (risc_size > 0 && rval == QLA_SUCCESS) {
4648 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4649 if (dlen > risc_size)
4650 dlen = risc_size;
4651
4652 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4653 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004654 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004656 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004657 for (i = 0; i < dlen; i++)
4658 dcode[i] = swab32(dcode[i]);
4659
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004660 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004661 dlen);
4662 if (rval) {
4663 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004664 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004665 fragment));
4666 qla_printk(KERN_WARNING, ha,
4667 "[ERROR] Failed to load segment %d of "
4668 "firmware\n", fragment);
4669 break;
4670 }
4671
4672 faddr += dlen;
4673 risc_addr += dlen;
4674 risc_size -= dlen;
4675 fragment++;
4676 }
4677
4678 /* Next segment. */
4679 segments--;
4680 }
4681
4682 return rval;
4683}
4684
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004685#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4686
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004687int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004688qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004689{
4690 int rval;
4691 int i, fragment;
4692 uint16_t *wcode, *fwcode;
4693 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4694 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004695 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004696 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004697
4698 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004699 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004700 if (!blob) {
4701 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004702 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4703 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004704 return QLA_FUNCTION_FAILED;
4705 }
4706
4707 rval = QLA_SUCCESS;
4708
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004709 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004710 *srisc_addr = 0;
4711 fwcode = (uint16_t *)blob->fw->data;
4712 fwclen = 0;
4713
4714 /* Validate firmware image by checking version. */
4715 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4716 qla_printk(KERN_WARNING, ha,
4717 "Unable to verify integrity of firmware image (%Zd)!\n",
4718 blob->fw->size);
4719 goto fail_fw_integrity;
4720 }
4721 for (i = 0; i < 4; i++)
4722 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4723 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4724 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4725 wcode[2] == 0 && wcode[3] == 0)) {
4726 qla_printk(KERN_WARNING, ha,
4727 "Unable to verify integrity of firmware image!\n");
4728 qla_printk(KERN_WARNING, ha,
4729 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4730 wcode[1], wcode[2], wcode[3]);
4731 goto fail_fw_integrity;
4732 }
4733
4734 seg = blob->segs;
4735 while (*seg && rval == QLA_SUCCESS) {
4736 risc_addr = *seg;
4737 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4738 risc_size = be16_to_cpu(fwcode[3]);
4739
4740 /* Validate firmware image size. */
4741 fwclen += risc_size * sizeof(uint16_t);
4742 if (blob->fw->size < fwclen) {
4743 qla_printk(KERN_WARNING, ha,
4744 "Unable to verify integrity of firmware image "
4745 "(%Zd)!\n", blob->fw->size);
4746 goto fail_fw_integrity;
4747 }
4748
4749 fragment = 0;
4750 while (risc_size > 0 && rval == QLA_SUCCESS) {
4751 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4752 if (wlen > risc_size)
4753 wlen = risc_size;
4754
4755 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004756 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004757 risc_addr, wlen));
4758
4759 for (i = 0; i < wlen; i++)
4760 wcode[i] = swab16(fwcode[i]);
4761
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004762 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004763 wlen);
4764 if (rval) {
4765 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004766 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004767 fragment));
4768 qla_printk(KERN_WARNING, ha,
4769 "[ERROR] Failed to load segment %d of "
4770 "firmware\n", fragment);
4771 break;
4772 }
4773
4774 fwcode += wlen;
4775 risc_addr += wlen;
4776 risc_size -= wlen;
4777 fragment++;
4778 }
4779
4780 /* Next segment. */
4781 seg++;
4782 }
4783 return rval;
4784
4785fail_fw_integrity:
4786 return QLA_FUNCTION_FAILED;
4787}
4788
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004789static int
4790qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004791{
4792 int rval;
4793 int segments, fragment;
4794 uint32_t *dcode, dlen;
4795 uint32_t risc_addr;
4796 uint32_t risc_size;
4797 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004798 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004799 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004800 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004801 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004802
Andrew Vasquez54333832005-11-09 15:49:04 -08004803 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004804 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004805 if (!blob) {
4806 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004807 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4808 "from: " QLA_FW_URL ".\n");
4809
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004810 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004811 }
4812
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004813 qla_printk(KERN_INFO, ha,
4814 "FW: Loading via request-firmware...\n");
4815
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004816 rval = QLA_SUCCESS;
4817
4818 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004819 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004820 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004821 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004822 fwclen = 0;
4823
4824 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004825 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004826 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004827 "Unable to verify integrity of firmware image (%Zd)!\n",
4828 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004829 goto fail_fw_integrity;
4830 }
4831 for (i = 0; i < 4; i++)
4832 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4833 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4834 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4835 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4836 dcode[3] == 0)) {
4837 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004838 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004839 qla_printk(KERN_WARNING, ha,
4840 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4841 dcode[1], dcode[2], dcode[3]);
4842 goto fail_fw_integrity;
4843 }
4844
4845 while (segments && rval == QLA_SUCCESS) {
4846 risc_addr = be32_to_cpu(fwcode[2]);
4847 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4848 risc_size = be32_to_cpu(fwcode[3]);
4849
4850 /* Validate firmware image size. */
4851 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004852 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004853 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004854 "Unable to verify integrity of firmware image "
4855 "(%Zd)!\n", blob->fw->size);
4856
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004857 goto fail_fw_integrity;
4858 }
4859
4860 fragment = 0;
4861 while (risc_size > 0 && rval == QLA_SUCCESS) {
4862 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4863 if (dlen > risc_size)
4864 dlen = risc_size;
4865
4866 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004867 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004868 risc_addr, dlen));
4869
4870 for (i = 0; i < dlen; i++)
4871 dcode[i] = swab32(fwcode[i]);
4872
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004873 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004874 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004875 if (rval) {
4876 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004877 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004878 fragment));
4879 qla_printk(KERN_WARNING, ha,
4880 "[ERROR] Failed to load segment %d of "
4881 "firmware\n", fragment);
4882 break;
4883 }
4884
4885 fwcode += dlen;
4886 risc_addr += dlen;
4887 risc_size -= dlen;
4888 fragment++;
4889 }
4890
4891 /* Next segment. */
4892 segments--;
4893 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004894 return rval;
4895
4896fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004897 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004898}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004899
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004900int
4901qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4902{
4903 int rval;
4904
Andrew Vasqueze337d902009-04-06 22:33:49 -07004905 if (ql2xfwloadbin == 1)
4906 return qla81xx_load_risc(vha, srisc_addr);
4907
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004908 /*
4909 * FW Load priority:
4910 * 1) Firmware via request-firmware interface (.bin file).
4911 * 2) Firmware residing in flash.
4912 */
4913 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4914 if (rval == QLA_SUCCESS)
4915 return rval;
4916
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004917 return qla24xx_load_risc_flash(vha, srisc_addr,
4918 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004919}
4920
4921int
4922qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4923{
4924 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004925 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004926
Andrew Vasqueze337d902009-04-06 22:33:49 -07004927 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004928 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004929
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004930 /*
4931 * FW Load priority:
4932 * 1) Firmware residing in flash.
4933 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004934 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004935 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004936 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004937 if (rval == QLA_SUCCESS)
4938 return rval;
4939
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004940try_blob_fw:
4941 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4942 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4943 return rval;
4944
4945 qla_printk(KERN_ERR, ha,
4946 "FW: Attempting to fallback to golden firmware...\n");
4947 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4948 if (rval != QLA_SUCCESS)
4949 return rval;
4950
4951 qla_printk(KERN_ERR, ha,
4952 "FW: Please update operational firmware...\n");
4953 ha->flags.running_gold_fw = 1;
4954
4955 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004956}
4957
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004958void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004959qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004960{
4961 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004962 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004963
Andrew Vasquez85880802009-12-15 21:29:46 -08004964 if (ha->flags.pci_channel_io_perm_failure)
4965 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004966 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004967 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004968 if (!ha->fw_major_version)
4969 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004970
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004971 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004972 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004973 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004974 ha->isp_ops->reset_chip(vha);
4975 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004976 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004977 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004978 continue;
4979 qla_printk(KERN_INFO, ha,
4980 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004981 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004982 }
4983}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004984
4985int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004986qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004987{
4988 int rval = QLA_SUCCESS;
4989 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004990 struct qla_hw_data *ha = vha->hw;
4991 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004992 struct req_que *req;
4993 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004994
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004995 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004996 return -EINVAL;
4997
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004998 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004999 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07005000 req = ha->req_q_map[0];
5001 else
5002 req = vha->req;
5003 rsp = req->rsp;
5004
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005005 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005006 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08005007 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005008 }
5009
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005010 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005011
5012 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005013 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005014 if (mb[0] != MBS_COMMAND_COMPLETE) {
5015 DEBUG15(qla_printk(KERN_INFO, ha,
5016 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5017 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
5018 mb[0], mb[1], mb[2], mb[6], mb[7]));
5019 return (QLA_FUNCTION_FAILED);
5020 }
5021
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005022 atomic_set(&vha->loop_down_timer, 0);
5023 atomic_set(&vha->loop_state, LOOP_UP);
5024 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5025 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5026 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07005027
5028 return rval;
5029}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005030
5031/* 84XX Support **************************************************************/
5032
5033static LIST_HEAD(qla_cs84xx_list);
5034static DEFINE_MUTEX(qla_cs84xx_mutex);
5035
5036static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005037qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005038{
5039 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005040 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005041
5042 mutex_lock(&qla_cs84xx_mutex);
5043
5044 /* Find any shared 84xx chip. */
5045 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
5046 if (cs84xx->bus == ha->pdev->bus) {
5047 kref_get(&cs84xx->kref);
5048 goto done;
5049 }
5050 }
5051
5052 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
5053 if (!cs84xx)
5054 goto done;
5055
5056 kref_init(&cs84xx->kref);
5057 spin_lock_init(&cs84xx->access_lock);
5058 mutex_init(&cs84xx->fw_update_mutex);
5059 cs84xx->bus = ha->pdev->bus;
5060
5061 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
5062done:
5063 mutex_unlock(&qla_cs84xx_mutex);
5064 return cs84xx;
5065}
5066
5067static void
5068__qla84xx_chip_release(struct kref *kref)
5069{
5070 struct qla_chip_state_84xx *cs84xx =
5071 container_of(kref, struct qla_chip_state_84xx, kref);
5072
5073 mutex_lock(&qla_cs84xx_mutex);
5074 list_del(&cs84xx->list);
5075 mutex_unlock(&qla_cs84xx_mutex);
5076 kfree(cs84xx);
5077}
5078
5079void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005080qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005081{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005082 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005083 if (ha->cs84xx)
5084 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
5085}
5086
5087static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005088qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005089{
5090 int rval;
5091 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005092 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005093
5094 mutex_lock(&ha->cs84xx->fw_update_mutex);
5095
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08005096 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07005097
5098 mutex_unlock(&ha->cs84xx->fw_update_mutex);
5099
5100 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
5101 QLA_SUCCESS;
5102}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005103
5104/* 81XX Support **************************************************************/
5105
5106int
5107qla81xx_nvram_config(scsi_qla_host_t *vha)
5108{
5109 int rval;
5110 struct init_cb_81xx *icb;
5111 struct nvram_81xx *nv;
5112 uint32_t *dptr;
5113 uint8_t *dptr1, *dptr2;
5114 uint32_t chksum;
5115 uint16_t cnt;
5116 struct qla_hw_data *ha = vha->hw;
5117
5118 rval = QLA_SUCCESS;
5119 icb = (struct init_cb_81xx *)ha->init_cb;
5120 nv = ha->nvram;
5121
5122 /* Determine NVRAM starting address. */
5123 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005124 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005125
5126 /* Get VPD data into cache */
5127 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005128 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
5129 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005130
5131 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005132 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005133 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07005134 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005135 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
5136 chksum += le32_to_cpu(*dptr++);
5137
Andrew Vasquez76403352009-04-06 22:33:39 -07005138 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005139 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
5140
5141 /* Bad NVRAM data, set defaults parameters. */
5142 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5143 || nv->id[3] != ' ' ||
5144 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5145 /* Reset NVRAM data. */
5146 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5147 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5148 le16_to_cpu(nv->nvram_version));
5149 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5150 "invalid -- WWPN) defaults.\n");
5151
5152 /*
5153 * Set default initialization control block.
5154 */
5155 memset(nv, 0, ha->nvram_size);
5156 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5157 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5158 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5159 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5160 nv->exchange_count = __constant_cpu_to_le16(0);
5161 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005162 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005163 nv->port_name[2] = 0x00;
5164 nv->port_name[3] = 0xe0;
5165 nv->port_name[4] = 0x8b;
5166 nv->port_name[5] = 0x1c;
5167 nv->port_name[6] = 0x55;
5168 nv->port_name[7] = 0x86;
5169 nv->node_name[0] = 0x20;
5170 nv->node_name[1] = 0x00;
5171 nv->node_name[2] = 0x00;
5172 nv->node_name[3] = 0xe0;
5173 nv->node_name[4] = 0x8b;
5174 nv->node_name[5] = 0x1c;
5175 nv->node_name[6] = 0x55;
5176 nv->node_name[7] = 0x86;
5177 nv->login_retry_count = __constant_cpu_to_le16(8);
5178 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5179 nv->login_timeout = __constant_cpu_to_le16(0);
5180 nv->firmware_options_1 =
5181 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5182 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5183 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5184 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5185 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5186 nv->efi_parameters = __constant_cpu_to_le32(0);
5187 nv->reset_delay = 5;
5188 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5189 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5190 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005191 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005192 nv->enode_mac[1] = 0x02;
5193 nv->enode_mac[2] = 0x03;
5194 nv->enode_mac[3] = 0x04;
5195 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005196 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005197
5198 rval = 1;
5199 }
5200
5201 /* Reset Initialization control block */
5202 memset(icb, 0, sizeof(struct init_cb_81xx));
5203
5204 /* Copy 1st segment. */
5205 dptr1 = (uint8_t *)icb;
5206 dptr2 = (uint8_t *)&nv->version;
5207 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5208 while (cnt--)
5209 *dptr1++ = *dptr2++;
5210
5211 icb->login_retry_count = nv->login_retry_count;
5212
5213 /* Copy 2nd segment. */
5214 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5215 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5216 cnt = (uint8_t *)&icb->reserved_5 -
5217 (uint8_t *)&icb->interrupt_delay_timer;
5218 while (cnt--)
5219 *dptr1++ = *dptr2++;
5220
5221 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5222 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5223 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5224 icb->enode_mac[0] = 0x01;
5225 icb->enode_mac[1] = 0x02;
5226 icb->enode_mac[2] = 0x03;
5227 icb->enode_mac[3] = 0x04;
5228 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005229 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005230 }
5231
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005232 /* Use extended-initialization control block. */
5233 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5234
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005235 /*
5236 * Setup driver NVRAM options.
5237 */
5238 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005239 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005240
5241 /* Use alternate WWN? */
5242 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5243 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5244 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5245 }
5246
5247 /* Prepare nodename */
5248 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5249 /*
5250 * Firmware will apply the following mask if the nodename was
5251 * not provided.
5252 */
5253 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5254 icb->node_name[0] &= 0xF0;
5255 }
5256
5257 /* Set host adapter parameters. */
5258 ha->flags.disable_risc_code_load = 0;
5259 ha->flags.enable_lip_reset = 0;
5260 ha->flags.enable_lip_full_login =
5261 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5262 ha->flags.enable_target_reset =
5263 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5264 ha->flags.enable_led_scheme = 0;
5265 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5266
5267 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5268 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5269
5270 /* save HBA serial number */
5271 ha->serial0 = icb->port_name[5];
5272 ha->serial1 = icb->port_name[6];
5273 ha->serial2 = icb->port_name[7];
5274 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5275 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5276
5277 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5278
5279 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5280
5281 /* Set minimum login_timeout to 4 seconds. */
5282 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5283 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5284 if (le16_to_cpu(nv->login_timeout) < 4)
5285 nv->login_timeout = __constant_cpu_to_le16(4);
5286 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5287 icb->login_timeout = nv->login_timeout;
5288
5289 /* Set minimum RATOV to 100 tenths of a second. */
5290 ha->r_a_tov = 100;
5291
5292 ha->loop_reset_delay = nv->reset_delay;
5293
5294 /* Link Down Timeout = 0:
5295 *
5296 * When Port Down timer expires we will start returning
5297 * I/O's to OS with "DID_NO_CONNECT".
5298 *
5299 * Link Down Timeout != 0:
5300 *
5301 * The driver waits for the link to come up after link down
5302 * before returning I/Os to OS with "DID_NO_CONNECT".
5303 */
5304 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5305 ha->loop_down_abort_time =
5306 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5307 } else {
5308 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5309 ha->loop_down_abort_time =
5310 (LOOP_DOWN_TIME - ha->link_down_timeout);
5311 }
5312
5313 /* Need enough time to try and get the port back. */
5314 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5315 if (qlport_down_retry)
5316 ha->port_down_retry_count = qlport_down_retry;
5317
5318 /* Set login_retry_count */
5319 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5320 if (ha->port_down_retry_count ==
5321 le16_to_cpu(nv->port_down_retry_count) &&
5322 ha->port_down_retry_count > 3)
5323 ha->login_retry_count = ha->port_down_retry_count;
5324 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5325 ha->login_retry_count = ha->port_down_retry_count;
5326 if (ql2xloginretrycount)
5327 ha->login_retry_count = ql2xloginretrycount;
5328
5329 /* Enable ZIO. */
5330 if (!vha->flags.init_done) {
5331 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5332 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5333 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5334 le16_to_cpu(icb->interrupt_delay_timer): 2;
5335 }
5336 icb->firmware_options_2 &= __constant_cpu_to_le32(
5337 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5338 vha->flags.process_response_queue = 0;
5339 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5340 ha->zio_mode = QLA_ZIO_MODE_6;
5341
5342 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5343 "(%d us).\n", vha->host_no, ha->zio_mode,
5344 ha->zio_timer * 100));
5345 qla_printk(KERN_INFO, ha,
5346 "ZIO mode %d enabled; timer delay (%d us).\n",
5347 ha->zio_mode, ha->zio_timer * 100);
5348
5349 icb->firmware_options_2 |= cpu_to_le32(
5350 (uint32_t)ha->zio_mode);
5351 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5352 vha->flags.process_response_queue = 1;
5353 }
5354
5355 if (rval) {
5356 DEBUG2_3(printk(KERN_WARNING
5357 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5358 }
5359 return (rval);
5360}
5361
Giridhar Malavalia9083012010-04-12 17:59:55 -07005362int
5363qla82xx_restart_isp(scsi_qla_host_t *vha)
5364{
5365 int status, rval;
5366 uint32_t wait_time;
5367 struct qla_hw_data *ha = vha->hw;
5368 struct req_que *req = ha->req_q_map[0];
5369 struct rsp_que *rsp = ha->rsp_q_map[0];
5370 struct scsi_qla_host *vp;
Arun Easifeafb7b2010-09-03 14:57:00 -07005371 unsigned long flags;
Giridhar Malavalia9083012010-04-12 17:59:55 -07005372
5373 status = qla2x00_init_rings(vha);
5374 if (!status) {
5375 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5376 ha->flags.chip_reset_done = 1;
5377
5378 status = qla2x00_fw_ready(vha);
5379 if (!status) {
5380 qla_printk(KERN_INFO, ha,
5381 "%s(): Start configure loop, "
5382 "status = %d\n", __func__, status);
5383
5384 /* Issue a marker after FW becomes ready. */
5385 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5386
5387 vha->flags.online = 1;
5388 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5389 wait_time = 256;
5390 do {
5391 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5392 qla2x00_configure_loop(vha);
5393 wait_time--;
5394 } while (!atomic_read(&vha->loop_down_timer) &&
5395 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5396 wait_time &&
5397 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5398 }
5399
5400 /* if no cable then assume it's good */
5401 if ((vha->device_flags & DFLG_NO_CABLE))
5402 status = 0;
5403
5404 qla_printk(KERN_INFO, ha,
5405 "%s(): Configure loop done, status = 0x%x\n",
5406 __func__, status);
5407 }
5408
5409 if (!status) {
5410 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5411
5412 if (!atomic_read(&vha->loop_down_timer)) {
5413 /*
5414 * Issue marker command only when we are going
5415 * to start the I/O .
5416 */
5417 vha->marker_needed = 1;
5418 }
5419
5420 vha->flags.online = 1;
5421
5422 ha->isp_ops->enable_intrs(ha);
5423
5424 ha->isp_abort_cnt = 0;
5425 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5426
5427 if (ha->fce) {
5428 ha->flags.fce_enabled = 1;
5429 memset(ha->fce, 0,
5430 fce_calc_size(ha->fce_bufs));
5431 rval = qla2x00_enable_fce_trace(vha,
5432 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5433 &ha->fce_bufs);
5434 if (rval) {
5435 qla_printk(KERN_WARNING, ha,
5436 "Unable to reinitialize FCE "
5437 "(%d).\n", rval);
5438 ha->flags.fce_enabled = 0;
5439 }
5440 }
5441
5442 if (ha->eft) {
5443 memset(ha->eft, 0, EFT_SIZE);
5444 rval = qla2x00_enable_eft_trace(vha,
5445 ha->eft_dma, EFT_NUM_BUFFERS);
5446 if (rval) {
5447 qla_printk(KERN_WARNING, ha,
5448 "Unable to reinitialize EFT "
5449 "(%d).\n", rval);
5450 }
5451 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005452 }
5453
5454 if (!status) {
5455 DEBUG(printk(KERN_INFO
5456 "qla82xx_restart_isp(%ld): succeeded.\n",
5457 vha->host_no));
Arun Easifeafb7b2010-09-03 14:57:00 -07005458
5459 spin_lock_irqsave(&ha->vport_slock, flags);
5460 list_for_each_entry(vp, &ha->vp_list, list) {
5461 if (vp->vp_idx) {
5462 atomic_inc(&vp->vref_count);
5463 spin_unlock_irqrestore(&ha->vport_slock, flags);
5464
Giridhar Malavalia9083012010-04-12 17:59:55 -07005465 qla2x00_vp_abort_isp(vp);
Arun Easifeafb7b2010-09-03 14:57:00 -07005466
5467 spin_lock_irqsave(&ha->vport_slock, flags);
5468 atomic_dec(&vp->vref_count);
5469 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005470 }
Arun Easifeafb7b2010-09-03 14:57:00 -07005471 spin_unlock_irqrestore(&ha->vport_slock, flags);
5472
Giridhar Malavalia9083012010-04-12 17:59:55 -07005473 } else {
5474 qla_printk(KERN_INFO, ha,
5475 "qla82xx_restart_isp: **** FAILED ****\n");
5476 }
5477
5478 return status;
5479}
5480
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005481void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005482qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005483{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005484 struct qla_hw_data *ha = vha->hw;
5485
5486 if (!ql2xetsenable)
5487 return;
5488
5489 /* Enable ETS Burst. */
5490 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5491 ha->fw_options[2] |= BIT_9;
5492 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005493}
Sarang Radke09ff7012010-03-19 17:03:59 -07005494
5495/*
5496 * qla24xx_get_fcp_prio
5497 * Gets the fcp cmd priority value for the logged in port.
5498 * Looks for a match of the port descriptors within
5499 * each of the fcp prio config entries. If a match is found,
5500 * the tag (priority) value is returned.
5501 *
5502 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005503 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005504 * fcport = port structure pointer.
5505 *
5506 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005507 * non-zero (if found)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005508 * -1 (if not found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005509 *
5510 * Context:
5511 * Kernel context
5512 */
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005513static int
Sarang Radke09ff7012010-03-19 17:03:59 -07005514qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5515{
5516 int i, entries;
5517 uint8_t pid_match, wwn_match;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005518 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005519 uint32_t pid1, pid2;
5520 uint64_t wwn1, wwn2;
5521 struct qla_fcp_prio_entry *pri_entry;
5522 struct qla_hw_data *ha = vha->hw;
5523
5524 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005525 return -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005526
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005527 priority = -1;
Sarang Radke09ff7012010-03-19 17:03:59 -07005528 entries = ha->fcp_prio_cfg->num_entries;
5529 pri_entry = &ha->fcp_prio_cfg->entry[0];
5530
5531 for (i = 0; i < entries; i++) {
5532 pid_match = wwn_match = 0;
5533
5534 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5535 pri_entry++;
5536 continue;
5537 }
5538
5539 /* check source pid for a match */
5540 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5541 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5542 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5543 if (pid1 == INVALID_PORT_ID)
5544 pid_match++;
5545 else if (pid1 == pid2)
5546 pid_match++;
5547 }
5548
5549 /* check destination pid for a match */
5550 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5551 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5552 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5553 if (pid1 == INVALID_PORT_ID)
5554 pid_match++;
5555 else if (pid1 == pid2)
5556 pid_match++;
5557 }
5558
5559 /* check source WWN for a match */
5560 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5561 wwn1 = wwn_to_u64(vha->port_name);
5562 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5563 if (wwn2 == (uint64_t)-1)
5564 wwn_match++;
5565 else if (wwn1 == wwn2)
5566 wwn_match++;
5567 }
5568
5569 /* check destination WWN for a match */
5570 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5571 wwn1 = wwn_to_u64(fcport->port_name);
5572 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5573 if (wwn2 == (uint64_t)-1)
5574 wwn_match++;
5575 else if (wwn1 == wwn2)
5576 wwn_match++;
5577 }
5578
5579 if (pid_match == 2 || wwn_match == 2) {
5580 /* Found a matching entry */
5581 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5582 priority = pri_entry->tag;
5583 break;
5584 }
5585
5586 pri_entry++;
5587 }
5588
5589 return priority;
5590}
5591
5592/*
5593 * qla24xx_update_fcport_fcp_prio
5594 * Activates fcp priority for the logged in fc port
5595 *
5596 * Input:
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005597 * vha = scsi host structure pointer.
Sarang Radke09ff7012010-03-19 17:03:59 -07005598 * fcp = port structure pointer.
5599 *
5600 * Return:
5601 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5602 *
5603 * Context:
5604 * Kernel context.
5605 */
5606int
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005607qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
Sarang Radke09ff7012010-03-19 17:03:59 -07005608{
5609 int ret;
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005610 int priority;
Sarang Radke09ff7012010-03-19 17:03:59 -07005611 uint16_t mb[5];
5612
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005613 if (fcport->port_type != FCT_TARGET ||
5614 fcport->loop_id == FC_NO_LOOP_ID)
Sarang Radke09ff7012010-03-19 17:03:59 -07005615 return QLA_FUNCTION_FAILED;
5616
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005617 priority = qla24xx_get_fcp_prio(vha, fcport);
Andrew Vasquezf28a0a92011-03-30 11:46:18 -07005618 if (priority < 0)
5619 return QLA_FUNCTION_FAILED;
5620
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005621 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
Sarang Radke09ff7012010-03-19 17:03:59 -07005622 if (ret == QLA_SUCCESS)
5623 fcport->fcp_prio = priority;
5624 else
5625 DEBUG2(printk(KERN_WARNING
5626 "scsi(%ld): Unable to activate fcp priority, "
Madhuranath Iyengar21090cb2010-12-21 16:00:18 -08005627 " ret=0x%x\n", vha->host_no, ret));
Sarang Radke09ff7012010-03-19 17:03:59 -07005628
5629 return ret;
5630}
5631
5632/*
5633 * qla24xx_update_all_fcp_prio
5634 * Activates fcp priority for all the logged in ports
5635 *
5636 * Input:
5637 * ha = adapter block pointer.
5638 *
5639 * Return:
5640 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5641 *
5642 * Context:
5643 * Kernel context.
5644 */
5645int
5646qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5647{
5648 int ret;
5649 fc_port_t *fcport;
5650
5651 ret = QLA_FUNCTION_FAILED;
5652 /* We need to set priority for all logged in ports */
5653 list_for_each_entry(fcport, &vha->vp_fcports, list)
5654 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5655
5656 return ret;
5657}