blob: 5bc3170703712da6561647dcefcc315c38ce1932 [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 Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 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 Vasquez01071092005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21* QLogic ISP2x00 Hardware Support Function Prototypes.
22*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Andrew Vasquezac280b62009-08-20 11:06:05 -070044/* SRB Extensions ---------------------------------------------------------- */
45
46static void
47qla2x00_ctx_sp_timeout(unsigned long __data)
48{
49 srb_t *sp = (srb_t *)__data;
50 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070051 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070052 fc_port_t *fcport = sp->fcport;
53 struct qla_hw_data *ha = fcport->vha->hw;
54 struct req_que *req;
55 unsigned long flags;
56
57 spin_lock_irqsave(&ha->hardware_lock, flags);
58 req = ha->req_q_map[0];
59 req->outstanding_cmds[sp->handle] = NULL;
60 ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070061 iocb = ctx->u.iocb_cmd;
62 iocb->timeout(sp);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070063 iocb->free(sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070064 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070065}
66
Giridhar Malavali9a069e12010-01-12 13:02:47 -080067void
Andrew Vasquezac280b62009-08-20 11:06:05 -070068qla2x00_ctx_sp_free(srb_t *sp)
69{
70 struct srb_ctx *ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070071 struct srb_iocb *iocb = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070072
Madhuranath Iyengar49163922010-05-04 15:01:28 -070073 del_timer_sync(&iocb->timer);
74 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070075 kfree(ctx);
76 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
77}
78
79inline srb_t *
80qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
81 unsigned long tmo)
82{
83 srb_t *sp;
84 struct qla_hw_data *ha = vha->hw;
85 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070086 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070087
88 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
89 if (!sp)
90 goto done;
91 ctx = kzalloc(size, GFP_KERNEL);
92 if (!ctx) {
93 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070094 sp = NULL;
95 goto done;
96 }
97 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
98 if (!iocb) {
99 mempool_free(sp, ha->srb_mempool);
100 sp = NULL;
101 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102 goto done;
103 }
104
105 memset(sp, 0, sizeof(*sp));
106 sp->fcport = fcport;
107 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700108 ctx->u.iocb_cmd = iocb;
109 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700110
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700111 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700112 if (!tmo)
113 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700114 iocb->timer.expires = jiffies + tmo * HZ;
115 iocb->timer.data = (unsigned long)sp;
116 iocb->timer.function = qla2x00_ctx_sp_timeout;
117 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118done:
119 return sp;
120}
121
122/* Asynchronous Login/Logout Routines -------------------------------------- */
123
Andrew Vasquez5b914902010-05-28 15:08:30 -0700124static inline unsigned long
125qla2x00_get_async_timeout(struct scsi_qla_host *vha)
126{
127 unsigned long tmo;
128 struct qla_hw_data *ha = vha->hw;
129
130 /* Firmware should use switch negotiated r_a_tov for timeout. */
131 tmo = ha->r_a_tov / 10 * 2;
132 if (!IS_FWI2_CAPABLE(ha)) {
133 /*
134 * Except for earlier ISPs where the timeout is seeded from the
135 * initialization control block.
136 */
137 tmo = ha->login_timeout;
138 }
139 return tmo;
140}
Andrew Vasquezac280b62009-08-20 11:06:05 -0700141
142static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700143qla2x00_async_iocb_timeout(srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700144{
145 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700146 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700147
148 DEBUG2(printk(KERN_WARNING
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700149 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
150 fcport->vha->host_no, sp->handle,
151 ctx->name, fcport->d_id.b.domain,
152 fcport->d_id.b.area, fcport->d_id.b.al_pa));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700153
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700154 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700155 if (ctx->type == SRB_LOGIN_CMD) {
156 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700158 /* Retry as needed. */
159 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
160 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
161 QLA_LOGIO_LOGIN_RETRIED : 0;
162 qla2x00_post_async_login_done_work(fcport->vha, fcport,
163 lio->u.logio.data);
164 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165}
166
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700167static void
168qla2x00_async_login_ctx_done(srb_t *sp)
169{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700170 struct srb_ctx *ctx = sp->ctx;
171 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700172
173 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700174 lio->u.logio.data);
175 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700176}
177
Andrew Vasquezac280b62009-08-20 11:06:05 -0700178int
179qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
180 uint16_t *data)
181{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700182 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700183 struct srb_ctx *ctx;
184 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700185 int rval;
186
187 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700188 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700189 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700190 if (!sp)
191 goto done;
192
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700193 ctx = sp->ctx;
194 ctx->type = SRB_LOGIN_CMD;
195 ctx->name = "login";
196 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700197 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700198 lio->done = qla2x00_async_login_ctx_done;
199 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700200 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700201 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700202 rval = qla2x00_start_sp(sp);
203 if (rval != QLA_SUCCESS)
204 goto done_free_sp;
205
206 DEBUG2(printk(KERN_DEBUG
207 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
208 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
209 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
210 fcport->login_retry));
211 return rval;
212
213done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700214 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700215done:
216 return rval;
217}
218
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700219static void
220qla2x00_async_logout_ctx_done(srb_t *sp)
221{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700222 struct srb_ctx *ctx = sp->ctx;
223 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700224
225 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700226 lio->u.logio.data);
227 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700228}
229
Andrew Vasquezac280b62009-08-20 11:06:05 -0700230int
231qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
232{
Andrew Vasquezac280b62009-08-20 11:06:05 -0700233 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700234 struct srb_ctx *ctx;
235 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700236 int rval;
237
238 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700239 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700240 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700241 if (!sp)
242 goto done;
243
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700244 ctx = sp->ctx;
245 ctx->type = SRB_LOGOUT_CMD;
246 ctx->name = "logout";
247 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700248 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700249 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700250 rval = qla2x00_start_sp(sp);
251 if (rval != QLA_SUCCESS)
252 goto done_free_sp;
253
254 DEBUG2(printk(KERN_DEBUG
255 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
256 fcport->vha->host_no, sp->handle, fcport->loop_id,
257 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
258 return rval;
259
260done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700261 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700262done:
263 return rval;
264}
265
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700266static void
267qla2x00_async_adisc_ctx_done(srb_t *sp)
268{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700269 struct srb_ctx *ctx = sp->ctx;
270 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700271
272 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700273 lio->u.logio.data);
274 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700275}
276
277int
278qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
279 uint16_t *data)
280{
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700281 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700282 struct srb_ctx *ctx;
283 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700284 int rval;
285
286 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700287 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700288 qla2x00_get_async_timeout(vha) + 2);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700289 if (!sp)
290 goto done;
291
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700292 ctx = sp->ctx;
293 ctx->type = SRB_ADISC_CMD;
294 ctx->name = "adisc";
295 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700296 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700297 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700298 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700299 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700300 rval = qla2x00_start_sp(sp);
301 if (rval != QLA_SUCCESS)
302 goto done_free_sp;
303
304 DEBUG2(printk(KERN_DEBUG
305 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
306 fcport->vha->host_no, sp->handle, fcport->loop_id,
307 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
308
309 return rval;
310
311done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700312 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700313done:
314 return rval;
315}
316
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700317static void
318qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
319{
320 struct srb_ctx *ctx = sp->ctx;
321 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
322
323 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
324 iocb->free(sp);
325}
326
327int
328qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
329 uint32_t tag)
330{
331 struct scsi_qla_host *vha = fcport->vha;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700332 srb_t *sp;
333 struct srb_ctx *ctx;
334 struct srb_iocb *tcf;
335 int rval;
336
337 rval = QLA_FUNCTION_FAILED;
338 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5b914902010-05-28 15:08:30 -0700339 qla2x00_get_async_timeout(vha) + 2);
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700340 if (!sp)
341 goto done;
342
343 ctx = sp->ctx;
344 ctx->type = SRB_TM_CMD;
345 ctx->name = "tmf";
346 tcf = ctx->u.iocb_cmd;
347 tcf->u.tmf.flags = flags;
348 tcf->u.tmf.lun = lun;
349 tcf->u.tmf.data = tag;
350 tcf->timeout = qla2x00_async_iocb_timeout;
351 tcf->done = qla2x00_async_tm_cmd_ctx_done;
352
353 rval = qla2x00_start_sp(sp);
354 if (rval != QLA_SUCCESS)
355 goto done_free_sp;
356
357 DEBUG2(printk(KERN_DEBUG
358 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
359 fcport->vha->host_no, sp->handle, fcport->loop_id,
360 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
361
362 return rval;
363
364done_free_sp:
365 tcf->free(sp);
366done:
367 return rval;
368}
369
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700370void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700371qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
372 uint16_t *data)
373{
374 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700375
376 switch (data[0]) {
377 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700378 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700379 fcport->flags |= FCF_ASYNC_SENT;
380 qla2x00_post_async_adisc_work(vha, fcport, data);
381 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700382 }
383 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700384 break;
385 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700386 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700387 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
388 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
389 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700390 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700391 break;
392 case MBS_PORT_ID_USED:
393 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700394 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700395 qla2x00_post_async_login_work(vha, fcport, NULL);
396 break;
397 case MBS_LOOP_ID_USED:
398 fcport->loop_id++;
399 rval = qla2x00_find_new_loop_id(vha, fcport);
400 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700401 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700402 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700403 break;
404 }
405 qla2x00_post_async_login_work(vha, fcport, NULL);
406 break;
407 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700408 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700409}
410
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700411void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700412qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
413 uint16_t *data)
414{
415 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700416 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700417}
418
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700419void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700420qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
421 uint16_t *data)
422{
423 if (data[0] == MBS_COMMAND_COMPLETE) {
424 qla2x00_update_fcport(vha, fcport);
425
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700426 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700427 }
428
429 /* Retry login. */
430 fcport->flags &= ~FCF_ASYNC_SENT;
431 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
432 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
433 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700434 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700435
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700436 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700437}
438
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700439void
440qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
441 struct srb_iocb *iocb)
442{
443 int rval;
444 uint32_t flags;
445 uint16_t lun;
446
447 flags = iocb->u.tmf.flags;
448 lun = (uint16_t)iocb->u.tmf.lun;
449
450 /* Issue Marker IOCB */
Giridhar Malavalid94d10e2010-07-23 15:28:23 +0500451 rval = qla2x00_marker(vha, vha->hw->req_q_map[0],
452 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700453 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
454
455 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
456 DEBUG2_3_11(printk(KERN_WARNING
457 "%s(%ld): TM IOCB failed (%x).\n",
458 __func__, vha->host_no, rval));
459 }
460
461 return;
462}
463
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464/****************************************************************************/
465/* QLogic ISP2x00 Hardware Support Functions. */
466/****************************************************************************/
467
468/*
469* qla2x00_initialize_adapter
470* Initialize board.
471*
472* Input:
473* ha = adapter block pointer.
474*
475* Returns:
476* 0 = success
477*/
478int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800479qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
481 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800482 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800483 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800486 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700487 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800489 ha->flags.pci_channel_io_perm_failure = 0;
490 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800491 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
492 atomic_set(&vha->loop_state, LOOP_DOWN);
493 vha->device_flags = DFLG_NO_CABLE;
494 vha->dpc_flags = 0;
495 vha->flags.management_server_logged_in = 0;
496 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 ha->isp_abort_cnt = 0;
498 ha->beacon_blink_led = 0;
499
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800500 set_bit(0, ha->req_qid_map);
501 set_bit(0, ha->rsp_qid_map);
502
Andrew Vasquez01071092005-07-06 10:31:37 -0700503 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800504 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800506 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508 return (rval);
509 }
510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800511 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700514 if (rval) {
515 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800516 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700517 return (rval);
518 }
519
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800520 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800521
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez01071092005-07-06 10:31:37 -0700523
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800524 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700526 if (ha->flags.disable_serdes) {
527 /* Mask HBA via NVRAM settings? */
528 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
529 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 vha->port_name[0], vha->port_name[1],
531 vha->port_name[2], vha->port_name[3],
532 vha->port_name[4], vha->port_name[5],
533 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700534 return QLA_FUNCTION_FAILED;
535 }
536
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800539 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
540 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800541 if (rval)
542 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800543 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800544 if (rval)
545 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700547
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700548 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700550 if (!ha->cs84xx) {
551 qla_printk(KERN_ERR, ha,
552 "Unable to configure ISP84XX.\n");
553 return QLA_FUNCTION_FAILED;
554 }
555 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800556 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700557 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800559 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700560 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800561 rval = qla84xx_init_chip(vha);
562 if (rval != QLA_SUCCESS) {
563 qla_printk(KERN_ERR, ha,
564 "Unable to initialize ISP84XX.\n");
565 qla84xx_put_chip(vha);
566 }
567 }
568
Sarang Radke09ff7012010-03-19 17:03:59 -0700569 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
570 if (qla24xx_read_fcp_prio_cfg(vha))
571 qla_printk(KERN_ERR, ha,
572 "Unable to read FCP priority data.\n");
573 }
574
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 return (rval);
576}
577
578/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700579 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580 * @ha: HA context
581 *
582 * Returns 0 on success.
583 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700584int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700587 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700588 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700590 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700593 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700596 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700597 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
598
Andrew Vasquez737faec2008-10-24 15:13:45 -0700599 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700601 /* Get PCI bus information. */
602 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700603 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700604 spin_unlock_irqrestore(&ha->hardware_lock, flags);
605
606 return QLA_SUCCESS;
607}
608
609/**
610 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
611 * @ha: HA context
612 *
613 * Returns 0 on success.
614 */
615int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800616qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700617{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700618 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700619 unsigned long flags = 0;
620 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800621 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700622 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700623
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700624 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700625 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700626
627 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700628 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700629
630 if (IS_QLA2322(ha) || IS_QLA6322(ha))
631 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700632 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700633
634 /*
635 * If this is a 2300 card and not 2312, reset the
636 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
637 * the 2310 also reports itself as a 2300 so we need to get the
638 * fb revision level -- a 6 indicates it really is a 2300 and
639 * not a 2310.
640 */
641 if (IS_QLA2300(ha)) {
642 spin_lock_irqsave(&ha->hardware_lock, flags);
643
644 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700645 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700646 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700647 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700648 break;
649
650 udelay(10);
651 }
652
653 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700654 WRT_REG_WORD(&reg->ctrl_status, 0x20);
655 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700656
657 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700658 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700659
660 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700661 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700662
663 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700664 WRT_REG_WORD(&reg->ctrl_status, 0x0);
665 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666
667 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700668 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700669 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700670 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700671 break;
672
673 udelay(10);
674 }
675
676 spin_unlock_irqrestore(&ha->hardware_lock, flags);
677 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700678
679 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
680
Andrew Vasquez737faec2008-10-24 15:13:45 -0700681 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700682
683 /* Get PCI bus information. */
684 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700685 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700686 spin_unlock_irqrestore(&ha->hardware_lock, flags);
687
688 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689}
690
691/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700692 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
693 * @ha: HA context
694 *
695 * Returns 0 on success.
696 */
697int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700699{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700700 uint16_t w;
Andrew Vasquez01071092005-07-06 10:31:37 -0700701 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800702 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700703 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez01071092005-07-06 10:31:37 -0700704
705 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700706 pci_try_set_mwi(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700707
708 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700709 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez01071092005-07-06 10:31:37 -0700710 w &= ~PCI_COMMAND_INTX_DISABLE;
711 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
712
713 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
714
715 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700716 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
717 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700718
719 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700720 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
721 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700722
Andrew Vasquez737faec2008-10-24 15:13:45 -0700723 pci_disable_rom(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700724
Auke Kok44c10132007-06-08 15:46:36 -0700725 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800726
Andrew Vasquez01071092005-07-06 10:31:37 -0700727 /* Get PCI bus information. */
728 spin_lock_irqsave(&ha->hardware_lock, flags);
729 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
730 spin_unlock_irqrestore(&ha->hardware_lock, flags);
731
732 return QLA_SUCCESS;
733}
734
735/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700736 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
737 * @ha: HA context
738 *
739 * Returns 0 on success.
740 */
741int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800742qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700743{
744 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700746
747 pci_set_master(ha->pdev);
748 pci_try_set_mwi(ha->pdev);
749
750 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
751 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
752 w &= ~PCI_COMMAND_INTX_DISABLE;
753 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
754
755 /* PCIe -- adjust Maximum Read Request Size (2048). */
756 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
757 pcie_set_readrq(ha->pdev, 2048);
758
Andrew Vasquez737faec2008-10-24 15:13:45 -0700759 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700760
761 ha->chip_revision = ha->pdev->revision;
762
763 return QLA_SUCCESS;
764}
765
766/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767 * qla2x00_isp_firmware() - Choose firmware image.
768 * @ha: HA context
769 *
770 * Returns 0 on success.
771 */
772static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800773qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774{
775 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700776 uint16_t loop_id, topo, sw_cap;
777 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800778 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779
780 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700781 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782
783 if (ha->flags.disable_risc_code_load) {
784 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800785 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700786 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
787
788 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800789 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700790 if (rval == QLA_SUCCESS) {
791 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700793 &area, &domain, &topo, &sw_cap);
794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 }
796
797 if (rval) {
798 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 }
801
802 return (rval);
803}
804
805/**
806 * qla2x00_reset_chip() - Reset ISP chip.
807 * @ha: HA context
808 *
809 * Returns 0 on success.
810 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700811void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800812qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813{
814 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800815 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700816 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 uint16_t cmd;
819
Andrew Vasquez85880802009-12-15 21:29:46 -0800820 if (unlikely(pci_channel_offline(ha->pdev)))
821 return;
822
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700823 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
825 spin_lock_irqsave(&ha->hardware_lock, flags);
826
827 /* Turn off master enable */
828 cmd = 0;
829 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
830 cmd &= ~PCI_COMMAND_MASTER;
831 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
832
833 if (!IS_QLA2100(ha)) {
834 /* Pause RISC. */
835 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
836 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
837 for (cnt = 0; cnt < 30000; cnt++) {
838 if ((RD_REG_WORD(&reg->hccr) &
839 HCCR_RISC_PAUSE) != 0)
840 break;
841 udelay(100);
842 }
843 } else {
844 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
845 udelay(10);
846 }
847
848 /* Select FPM registers. */
849 WRT_REG_WORD(&reg->ctrl_status, 0x20);
850 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
851
852 /* FPM Soft Reset. */
853 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
854 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
855
856 /* Toggle Fpm Reset. */
857 if (!IS_QLA2200(ha)) {
858 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
859 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
860 }
861
862 /* Select frame buffer registers. */
863 WRT_REG_WORD(&reg->ctrl_status, 0x10);
864 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
865
866 /* Reset frame buffer FIFOs. */
867 if (IS_QLA2200(ha)) {
868 WRT_FB_CMD_REG(ha, reg, 0xa000);
869 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
870 } else {
871 WRT_FB_CMD_REG(ha, reg, 0x00fc);
872
873 /* Read back fb_cmd until zero or 3 seconds max */
874 for (cnt = 0; cnt < 3000; cnt++) {
875 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
876 break;
877 udelay(100);
878 }
879 }
880
881 /* Select RISC module registers. */
882 WRT_REG_WORD(&reg->ctrl_status, 0);
883 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
884
885 /* Reset RISC processor. */
886 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
887 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
888
889 /* Release RISC processor. */
890 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
891 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
892 }
893
894 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
895 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
896
897 /* Reset ISP chip. */
898 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
899
900 /* Wait for RISC to recover from reset. */
901 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
902 /*
903 * It is necessary to for a delay here since the card doesn't
904 * respond to PCI reads during a reset. On some architectures
905 * this will result in an MCA.
906 */
907 udelay(20);
908 for (cnt = 30000; cnt; cnt--) {
909 if ((RD_REG_WORD(&reg->ctrl_status) &
910 CSR_ISP_SOFT_RESET) == 0)
911 break;
912 udelay(100);
913 }
914 } else
915 udelay(10);
916
917 /* Reset RISC processor. */
918 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
919
920 WRT_REG_WORD(&reg->semaphore, 0);
921
922 /* Release RISC processor. */
923 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
924 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
925
926 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
927 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700928 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930
931 udelay(100);
932 }
933 } else
934 udelay(100);
935
936 /* Turn on master enable */
937 cmd |= PCI_COMMAND_MASTER;
938 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
939
940 /* Disable RISC pause on FPM parity error. */
941 if (!IS_QLA2100(ha)) {
942 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
943 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
944 }
945
946 spin_unlock_irqrestore(&ha->hardware_lock, flags);
947}
948
949/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700950 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez01071092005-07-06 10:31:37 -0700951 * @ha: HA context
952 *
953 * Returns 0 on success.
954 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700955static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800956qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700957{
958 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800959 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700960 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
961 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800962 uint16_t wd;
Andrew Vasquez01071092005-07-06 10:31:37 -0700963
Andrew Vasquez01071092005-07-06 10:31:37 -0700964 spin_lock_irqsave(&ha->hardware_lock, flags);
965
966 /* Reset RISC. */
967 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
968 for (cnt = 0; cnt < 30000; cnt++) {
969 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
970 break;
971
972 udelay(10);
973 }
974
975 WRT_REG_DWORD(&reg->ctrl_status,
976 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800977 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700978
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800979 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700980 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700981 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
982 for (cnt = 10000 ; cnt && d2; cnt--) {
983 udelay(5);
984 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
985 barrier();
986 }
987
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800988 /* Wait for soft-reset to complete. */
Andrew Vasquez01071092005-07-06 10:31:37 -0700989 d2 = RD_REG_DWORD(&reg->ctrl_status);
990 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
991 udelay(5);
992 d2 = RD_REG_DWORD(&reg->ctrl_status);
993 barrier();
994 }
995
996 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
997 RD_REG_DWORD(&reg->hccr);
998
999 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1000 RD_REG_DWORD(&reg->hccr);
1001
1002 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1003 RD_REG_DWORD(&reg->hccr);
1004
1005 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1006 for (cnt = 6000000 ; cnt && d2; cnt--) {
1007 udelay(5);
1008 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1009 barrier();
1010 }
1011
1012 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001013
1014 if (IS_NOPOLLING_TYPE(ha))
1015 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07001016}
1017
1018/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001019 * qla24xx_reset_chip() - Reset ISP24xx chip.
1020 * @ha: HA context
1021 *
1022 * Returns 0 on success.
1023 */
1024void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001025qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001026{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001027 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001028
1029 if (pci_channel_offline(ha->pdev) &&
1030 ha->flags.pci_channel_io_perm_failure) {
1031 return;
1032 }
1033
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001034 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001035
1036 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001038}
1039
1040/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041 * qla2x00_chip_diag() - Test chip for proper operation.
1042 * @ha: HA context
1043 *
1044 * Returns 0 on success.
1045 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001046int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001047qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
1049 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001050 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001051 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 unsigned long flags = 0;
1053 uint16_t data;
1054 uint32_t cnt;
1055 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001056 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001057
1058 /* Assume a failed state */
1059 rval = QLA_FUNCTION_FAILED;
1060
1061 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001062 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001063
1064 spin_lock_irqsave(&ha->hardware_lock, flags);
1065
1066 /* Reset ISP chip. */
1067 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1068
1069 /*
1070 * We need to have a delay here since the card will not respond while
1071 * in reset causing an MCA on some architectures.
1072 */
1073 udelay(20);
1074 data = qla2x00_debounce_register(&reg->ctrl_status);
1075 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1076 udelay(5);
1077 data = RD_REG_WORD(&reg->ctrl_status);
1078 barrier();
1079 }
1080
1081 if (!cnt)
1082 goto chip_diag_failed;
1083
1084 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001085 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086
1087 /* Reset RISC processor. */
1088 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1089 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1090
1091 /* Workaround for QLA2312 PCI parity error */
1092 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1093 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1094 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1095 udelay(5);
1096 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001097 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 }
1099 } else
1100 udelay(10);
1101
1102 if (!cnt)
1103 goto chip_diag_failed;
1104
1105 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001106 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107
1108 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1109 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1110 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1111 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1112 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1113 mb[3] != PROD_ID_3) {
1114 qla_printk(KERN_WARNING, ha,
1115 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1116
1117 goto chip_diag_failed;
1118 }
1119 ha->product_id[0] = mb[1];
1120 ha->product_id[1] = mb[2];
1121 ha->product_id[2] = mb[3];
1122 ha->product_id[3] = mb[4];
1123
1124 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001125 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001126 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1127 else
1128 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001129 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130
1131 if (IS_QLA2200(ha) &&
1132 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1133 /* Limit firmware transfer size with a 2200A */
1134 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001135 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001136
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001137 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138 ha->fw_transfer_size = 128;
1139 }
1140
1141 /* Wrap Incoming Mailboxes Test. */
1142 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1143
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1145 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001146 if (rval) {
1147 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001148 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149 qla_printk(KERN_WARNING, ha,
1150 "Failed mailbox send register test\n");
1151 }
1152 else {
1153 /* Flag a successful rval */
1154 rval = QLA_SUCCESS;
1155 }
1156 spin_lock_irqsave(&ha->hardware_lock, flags);
1157
1158chip_diag_failed:
1159 if (rval)
1160 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001161 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1164
1165 return (rval);
1166}
1167
1168/**
Andrew Vasquez01071092005-07-06 10:31:37 -07001169 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1170 * @ha: HA context
1171 *
1172 * Returns 0 on success.
1173 */
1174int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001176{
1177 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001178 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001179 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07001180
Giridhar Malavalia9083012010-04-12 17:59:55 -07001181 if (IS_QLA82XX(ha))
1182 return QLA_SUCCESS;
1183
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001184 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez01071092005-07-06 10:31:37 -07001185
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001186 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -07001187 if (rval) {
1188 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001189 vha->host_no));
Andrew Vasquez01071092005-07-06 10:31:37 -07001190 qla_printk(KERN_WARNING, ha,
1191 "Failed mailbox send register test\n");
1192 } else {
1193 /* Flag a successful rval */
1194 rval = QLA_SUCCESS;
1195 }
1196
1197 return rval;
1198}
1199
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001200void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001201qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001202{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001203 int rval;
1204 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001205 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001206 dma_addr_t tc_dma;
1207 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001209 struct req_que *req = ha->req_q_map[0];
1210 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001211
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001212 if (ha->fw_dump) {
1213 qla_printk(KERN_WARNING, ha,
1214 "Firmware dump previously allocated.\n");
1215 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001216 }
1217
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001218 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001219 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001220 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1221 fixed_size = sizeof(struct qla2100_fw_dump);
1222 } else if (IS_QLA23XX(ha)) {
1223 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1224 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1225 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001226 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001227 if (IS_QLA81XX(ha))
1228 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1229 else if (IS_QLA25XX(ha))
1230 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1231 else
1232 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001233 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1234 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001235 if (ha->mqenable)
1236 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001237 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001238 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001239 goto try_eft;
1240
1241 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1242 GFP_KERNEL);
1243 if (!tc) {
1244 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1245 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001246 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001247 }
1248
1249 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001250 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001251 ha->fce_mb, &ha->fce_bufs);
1252 if (rval) {
1253 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1254 "FCE (%d).\n", rval);
1255 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1256 tc_dma);
1257 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001258 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001259 }
1260
1261 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1262 FCE_SIZE / 1024);
1263
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001264 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001265 ha->flags.fce_enabled = 1;
1266 ha->fce_dma = tc_dma;
1267 ha->fce = tc;
1268try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001269 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001270 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001271 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001272 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001273 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1274 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1275 goto cont_alloc;
1276 }
1277
Andrew Vasquezfc447652008-01-17 09:02:18 -08001278 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001280 if (rval) {
1281 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1282 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001283 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1284 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001285 goto cont_alloc;
1286 }
1287
1288 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1289 EFT_SIZE / 1024);
1290
1291 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001292 ha->eft_dma = tc_dma;
1293 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001294 }
1295cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001296 req_q_size = req->length * sizeof(request_t);
1297 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001298
1299 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001300 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001301 ha->chain_offset = dump_size;
1302 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001303
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001304 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001305 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -07001306 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001307 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001308
1309 if (ha->eft) {
1310 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1311 ha->eft_dma);
1312 ha->eft = NULL;
1313 ha->eft_dma = 0;
1314 }
1315 return;
1316 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001317 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1318 dump_size / 1024);
1319
1320 ha->fw_dump_len = dump_size;
1321 ha->fw_dump->signature[0] = 'Q';
1322 ha->fw_dump->signature[1] = 'L';
1323 ha->fw_dump->signature[2] = 'G';
1324 ha->fw_dump->signature[3] = 'C';
1325 ha->fw_dump->version = __constant_htonl(1);
1326
1327 ha->fw_dump->fixed_size = htonl(fixed_size);
1328 ha->fw_dump->mem_size = htonl(mem_size);
1329 ha->fw_dump->req_q_size = htonl(req_q_size);
1330 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1331
1332 ha->fw_dump->eft_size = htonl(eft_size);
1333 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1334 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1335
1336 ha->fw_dump->header_size =
1337 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -07001338}
1339
Andrew Vasquez18e75552009-06-03 09:55:30 -07001340static int
1341qla81xx_mpi_sync(scsi_qla_host_t *vha)
1342{
1343#define MPS_MASK 0xe0
1344 int rval;
1345 uint16_t dc;
1346 uint32_t dw;
1347 struct qla_hw_data *ha = vha->hw;
1348
1349 if (!IS_QLA81XX(vha->hw))
1350 return QLA_SUCCESS;
1351
1352 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1353 if (rval != QLA_SUCCESS) {
1354 DEBUG2(qla_printk(KERN_WARNING, ha,
1355 "Sync-MPI: Unable to acquire semaphore.\n"));
1356 goto done;
1357 }
1358
1359 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1360 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1361 if (rval != QLA_SUCCESS) {
1362 DEBUG2(qla_printk(KERN_WARNING, ha,
1363 "Sync-MPI: Unable to read sync.\n"));
1364 goto done_release;
1365 }
1366
1367 dc &= MPS_MASK;
1368 if (dc == (dw & MPS_MASK))
1369 goto done_release;
1370
1371 dw &= ~MPS_MASK;
1372 dw |= dc;
1373 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1374 if (rval != QLA_SUCCESS) {
1375 DEBUG2(qla_printk(KERN_WARNING, ha,
1376 "Sync-MPI: Unable to gain sync.\n"));
1377 }
1378
1379done_release:
1380 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1381 if (rval != QLA_SUCCESS) {
1382 DEBUG2(qla_printk(KERN_WARNING, ha,
1383 "Sync-MPI: Unable to release semaphore.\n"));
1384 }
1385
1386done:
1387 return rval;
1388}
1389
Andrew Vasquez01071092005-07-06 10:31:37 -07001390/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391 * qla2x00_setup_chip() - Load and start RISC firmware.
1392 * @ha: HA context
1393 *
1394 * Returns 0 on success.
1395 */
1396static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001397qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398{
Andrew Vasquez01071092005-07-06 10:31:37 -07001399 int rval;
1400 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001402 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1403 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001404 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001405
Giridhar Malavalia9083012010-04-12 17:59:55 -07001406 if (IS_QLA82XX(ha)) {
1407 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1408 if (rval == QLA_SUCCESS)
1409 goto enable_82xx_npiv;
Giridhar Malavalib9637522010-05-28 15:08:15 -07001410 else
1411 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001412 }
1413
Andrew Vasquez3db06522008-01-31 12:33:49 -08001414 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1415 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1416 spin_lock_irqsave(&ha->hardware_lock, flags);
1417 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1418 RD_REG_WORD(&reg->hccr);
1419 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1420 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
Andrew Vasquez18e75552009-06-03 09:55:30 -07001422 qla81xx_mpi_sync(vha);
1423
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001425 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -07001426 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001428 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001430 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001431 if (rval == QLA_SUCCESS) {
1432 /* Start firmware execution. */
1433 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001434 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001436 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001438 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001439enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001440 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001441 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442 &ha->fw_major_version,
1443 &ha->fw_minor_version,
1444 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001445 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001446 ha->mpi_version, &ha->mpi_capabilities,
1447 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001448 if (rval != QLA_SUCCESS)
1449 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001450 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001451 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001452 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001453 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001454 if ((!ha->max_npiv_vports) ||
1455 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001456 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001457 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001458 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001459 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001460 qla2x00_get_resource_cnts(vha, NULL,
1461 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001462 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001463
Giridhar Malavalia9083012010-04-12 17:59:55 -07001464 if (!fw_major_version && ql2xallocfwdump) {
1465 if (!IS_QLA82XX(ha))
1466 qla2x00_alloc_fw_dump(vha);
1467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 }
1469 } else {
1470 DEBUG2(printk(KERN_INFO
1471 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473 }
1474 }
1475
Andrew Vasquez3db06522008-01-31 12:33:49 -08001476 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1477 /* Enable proper parity. */
1478 spin_lock_irqsave(&ha->hardware_lock, flags);
1479 if (IS_QLA2300(ha))
1480 /* SRAM parity */
1481 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1482 else
1483 /* SRAM, Instruction RAM and GP RAM parity */
1484 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1485 RD_REG_WORD(&reg->hccr);
1486 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1487 }
1488
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001489 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1490 uint32_t size;
1491
1492 rval = qla81xx_fac_get_sector_size(vha, &size);
1493 if (rval == QLA_SUCCESS) {
1494 ha->flags.fac_supported = 1;
1495 ha->fdt_block_size = size << 2;
1496 } else {
1497 qla_printk(KERN_ERR, ha,
1498 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1499 ha->fw_major_version, ha->fw_minor_version,
1500 ha->fw_subminor_version);
1501 }
1502 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001503failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 if (rval) {
1505 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001506 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507 }
1508
1509 return (rval);
1510}
1511
1512/**
1513 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1514 * @ha: HA context
1515 *
1516 * Beginning of request ring has initialization control block already built
1517 * by nvram config routine.
1518 *
1519 * Returns 0 on success.
1520 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001521void
1522qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523{
1524 uint16_t cnt;
1525 response_t *pkt;
1526
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001527 rsp->ring_ptr = rsp->ring;
1528 rsp->ring_index = 0;
1529 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001530 pkt = rsp->ring_ptr;
1531 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 pkt->signature = RESPONSE_PROCESSED;
1533 pkt++;
1534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535}
1536
1537/**
1538 * qla2x00_update_fw_options() - Read and process firmware options.
1539 * @ha: HA context
1540 *
1541 * Returns 0 on success.
1542 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001543void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545{
1546 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001547 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548
1549 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
1552 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1553 return;
1554
1555 /* Serial Link options. */
1556 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001557 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1559 sizeof(ha->fw_seriallink_options)));
1560
1561 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1562 if (ha->fw_seriallink_options[3] & BIT_2) {
1563 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1564
1565 /* 1G settings */
1566 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1567 emphasis = (ha->fw_seriallink_options[2] &
1568 (BIT_4 | BIT_3)) >> 3;
1569 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001570 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571 rx_sens = (ha->fw_seriallink_options[0] &
1572 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1573 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1574 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1575 if (rx_sens == 0x0)
1576 rx_sens = 0x3;
1577 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1578 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1579 ha->fw_options[10] |= BIT_5 |
1580 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1581 (tx_sens & (BIT_1 | BIT_0));
1582
1583 /* 2G settings */
1584 swing = (ha->fw_seriallink_options[2] &
1585 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1586 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1587 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001588 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 rx_sens = (ha->fw_seriallink_options[1] &
1590 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1591 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1592 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1593 if (rx_sens == 0x0)
1594 rx_sens = 0x3;
1595 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1596 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1597 ha->fw_options[11] |= BIT_5 |
1598 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1599 (tx_sens & (BIT_1 | BIT_0));
1600 }
1601
1602 /* FCP2 options. */
1603 /* Return command IOCBs without waiting for an ABTS to complete. */
1604 ha->fw_options[3] |= BIT_13;
1605
1606 /* LED scheme. */
1607 if (ha->flags.enable_led_scheme)
1608 ha->fw_options[2] |= BIT_12;
1609
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001610 /* Detect ISP6312. */
1611 if (IS_QLA6312(ha))
1612 ha->fw_options[2] |= BIT_13;
1613
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001615 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616}
1617
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001618void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001619qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001620{
1621 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001622 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001623
Giridhar Malavalia9083012010-04-12 17:59:55 -07001624 if (IS_QLA82XX(ha))
1625 return;
1626
Andrew Vasquez01071092005-07-06 10:31:37 -07001627 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001628 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez01071092005-07-06 10:31:37 -07001629 return;
1630
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001631 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001632 le16_to_cpu(ha->fw_seriallink_options24[1]),
1633 le16_to_cpu(ha->fw_seriallink_options24[2]),
1634 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez01071092005-07-06 10:31:37 -07001635 if (rval != QLA_SUCCESS) {
1636 qla_printk(KERN_WARNING, ha,
1637 "Unable to update Serial Link options (%x).\n", rval);
1638 }
1639}
1640
1641void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001643{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001644 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001645 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001646 struct req_que *req = ha->req_q_map[0];
1647 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001648
1649 /* Setup ring parameters in initialization control block. */
1650 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1651 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1653 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1654 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1655 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1656 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1657 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001658
1659 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1660 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1661 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1662 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1663 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1664}
1665
Andrew Vasquez01071092005-07-06 10:31:37 -07001666void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001668{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001669 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001670 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1671 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1672 struct qla_msix_entry *msix;
Andrew Vasquez01071092005-07-06 10:31:37 -07001673 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001674 uint16_t rid = 0;
1675 struct req_que *req = ha->req_q_map[0];
1676 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07001677
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001678/* Setup ring parameters in initialization control block. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001679 icb = (struct init_cb_24xx *)ha->init_cb;
1680 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1681 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001682 icb->request_q_length = cpu_to_le16(req->length);
1683 icb->response_q_length = cpu_to_le16(rsp->length);
1684 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1685 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1686 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1687 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez01071092005-07-06 10:31:37 -07001688
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001689 if (ha->mqenable) {
1690 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1691 icb->rid = __constant_cpu_to_le16(rid);
1692 if (ha->flags.msix_enabled) {
1693 msix = &ha->msix_entries[1];
1694 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001695 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001696 icb->msix = cpu_to_le16(msix->entry);
1697 }
1698 /* Use alternate PCI bus number */
1699 if (MSB(rid))
1700 icb->firmware_options_2 |=
1701 __constant_cpu_to_le32(BIT_19);
1702 /* Use alternate PCI devfn */
1703 if (LSB(rid))
1704 icb->firmware_options_2 |=
1705 __constant_cpu_to_le32(BIT_18);
1706
Anirban Chakraborty31557542009-12-02 10:36:55 -08001707 /* Use Disable MSIX Handshake mode for capable adapters */
1708 if (IS_MSIX_NACK_CAPABLE(ha)) {
1709 icb->firmware_options_2 &=
1710 __constant_cpu_to_le32(~BIT_22);
1711 ha->flags.disable_msix_handshake = 1;
1712 qla_printk(KERN_INFO, ha,
1713 "MSIX Handshake Disable Mode turned on\n");
1714 } else {
1715 icb->firmware_options_2 |=
1716 __constant_cpu_to_le32(BIT_22);
1717 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001718 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001719
1720 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1721 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1722 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1723 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1724 } else {
1725 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1726 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1727 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1728 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1729 }
1730 /* PCI posting */
1731 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez01071092005-07-06 10:31:37 -07001732}
1733
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734/**
1735 * qla2x00_init_rings() - Initializes firmware.
1736 * @ha: HA context
1737 *
1738 * Beginning of request ring has initialization control block already built
1739 * by nvram config routine.
1740 *
1741 * Returns 0 on success.
1742 */
1743static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001744qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745{
1746 int rval;
1747 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001748 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001749 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001750 struct req_que *req;
1751 struct rsp_que *rsp;
1752 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001753 struct mid_init_cb_24xx *mid_init_cb =
1754 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
1756 spin_lock_irqsave(&ha->hardware_lock, flags);
1757
1758 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001759 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001760 req = ha->req_q_map[que];
1761 if (!req)
1762 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001763 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001764 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001766 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001767
1768 /* Initialize firmware. */
1769 req->ring_ptr = req->ring;
1770 req->ring_index = 0;
1771 req->cnt = req->length;
1772 }
1773
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001774 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001775 rsp = ha->rsp_q_map[que];
1776 if (!rsp)
1777 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001778 /* Initialize response queue entries */
1779 qla2x00_init_response_q_entries(rsp);
1780 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
1782 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001783 list_for_each_entry(vp, &ha->vp_list, list) {
1784 vp->rscn_in_ptr = 0;
1785 vp->rscn_out_ptr = 0;
1786 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001787 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788
1789 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1790
1791 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001792 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001794 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001795
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001796 if (ha->flags.npiv_supported) {
1797 if (ha->operating_mode == LOOP)
1798 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001799 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001800 }
1801
Andrew Vasquez24a08132009-03-24 09:08:16 -07001802 if (IS_FWI2_CAPABLE(ha)) {
1803 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1804 mid_init_cb->init_cb.execution_throttle =
1805 cpu_to_le16(ha->fw_xcb_count);
1806 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001807
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001808 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809 if (rval) {
1810 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001811 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 } else {
1813 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001814 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 }
1816
1817 return (rval);
1818}
1819
1820/**
1821 * qla2x00_fw_ready() - Waits for firmware ready.
1822 * @ha: HA context
1823 *
1824 * Returns 0 on success.
1825 */
1826static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001827qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828{
1829 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001830 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831 uint16_t min_wait; /* Minimum wait time if loop is down */
1832 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001833 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001834 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 rval = QLA_SUCCESS;
1837
1838 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001839 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
1841 /*
1842 * Firmware should take at most one RATOV to login, plus 5 seconds for
1843 * our own processing.
1844 */
1845 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1846 wait_time = min_wait;
1847 }
1848
1849 /* Min wait time if loop down */
1850 mtime = jiffies + (min_wait * HZ);
1851
1852 /* wait time before firmware ready */
1853 wtime = jiffies + (wait_time * HZ);
1854
1855 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001856 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1858
1859 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001860 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861
1862 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001863 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001865 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001866 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001868 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1869 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001870 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001871 state[2]));
1872 if ((state[2] & FSTATE_LOGGED_IN) &&
1873 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1874 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001875 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001876
1877 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001879 if (rval != QLA_SUCCESS)
1880 break;
1881
1882 /* Add time taken to initialize. */
1883 cs84xx_time = jiffies - cs84xx_time;
1884 wtime += cs84xx_time;
1885 mtime += cs84xx_time;
1886 DEBUG16(printk("scsi(%ld): Increasing "
1887 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001888 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001889 }
1890 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001891 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001892 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001894 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895 &ha->login_timeout, &ha->r_a_tov);
1896
1897 rval = QLA_SUCCESS;
1898 break;
1899 }
1900
1901 rval = QLA_FUNCTION_FAILED;
1902
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001904 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001906 * other than Wait for Login.
1907 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 if (time_after_eq(jiffies, mtime)) {
1909 qla_printk(KERN_INFO, ha,
1910 "Cable is unplugged...\n");
1911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001912 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913 break;
1914 }
1915 }
1916 } else {
1917 /* Mailbox cmd failed. Timeout on min_wait. */
Santosh Vernekarcdbb0a42010-05-28 15:08:25 -07001918 if (time_after_eq(jiffies, mtime) ||
1919 (IS_QLA82XX(ha) && ha->flags.fw_hung))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 break;
1921 }
1922
1923 if (time_after_eq(jiffies, wtime))
1924 break;
1925
1926 /* Delay for a while */
1927 msleep(500);
1928
1929 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001930 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 } while (1);
1932
Andrew Vasquez656e8912009-06-03 09:55:29 -07001933 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1934 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1935 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
1937 if (rval) {
1938 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001939 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 }
1941
1942 return (rval);
1943}
1944
1945/*
1946* qla2x00_configure_hba
1947* Setup adapter context.
1948*
1949* Input:
1950* ha = adapter state pointer.
1951*
1952* Returns:
1953* 0 = success
1954*
1955* Context:
1956* Kernel context.
1957*/
1958static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001959qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960{
1961 int rval;
1962 uint16_t loop_id;
1963 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001964 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 uint8_t al_pa;
1966 uint8_t area;
1967 uint8_t domain;
1968 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970
1971 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001972 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001973 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001976 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1977 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001978 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001979 } else {
1980 qla_printk(KERN_WARNING, ha,
1981 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001982 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001983 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 return (rval);
1985 }
1986
1987 if (topo == 4) {
1988 qla_printk(KERN_INFO, ha,
1989 "Cannot get topology - retrying.\n");
1990 return (QLA_FUNCTION_FAILED);
1991 }
1992
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994
1995 /* initialize */
1996 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1997 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001998 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 switch (topo) {
2001 case 0:
2002 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 ha->current_topology = ISP_CFG_NL;
2005 strcpy(connect_type, "(Loop)");
2006 break;
2007
2008 case 1:
2009 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002011 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 ha->current_topology = ISP_CFG_FL;
2013 strcpy(connect_type, "(FL_Port)");
2014 break;
2015
2016 case 2:
2017 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002018 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 ha->operating_mode = P2P;
2020 ha->current_topology = ISP_CFG_N;
2021 strcpy(connect_type, "(N_Port-to-N_Port)");
2022 break;
2023
2024 case 3:
2025 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002027 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 ha->operating_mode = P2P;
2029 ha->current_topology = ISP_CFG_F;
2030 strcpy(connect_type, "(F_Port)");
2031 break;
2032
2033 default:
2034 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2035 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 ha->current_topology = ISP_CFG_NL;
2038 strcpy(connect_type, "(Loop)");
2039 break;
2040 }
2041
2042 /* Save Host port and loop ID. */
2043 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 vha->d_id.b.domain = domain;
2045 vha->d_id.b.area = area;
2046 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 qla_printk(KERN_INFO, ha,
2050 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002051 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
2053 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002054 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002056 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 }
2058
2059 return(rval);
2060}
2061
Giridhar Malavalia9083012010-04-12 17:59:55 -07002062inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2064 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002065{
2066 char *st, *en;
2067 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002068 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002069 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002070 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002071
2072 if (memcmp(model, BINZERO, len) != 0) {
2073 strncpy(ha->model_number, model, len);
2074 st = en = ha->model_number;
2075 en += len - 1;
2076 while (en > st) {
2077 if (*en != 0x20 && *en != 0x00)
2078 break;
2079 *en-- = '\0';
2080 }
2081
2082 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002083 if (use_tbl &&
2084 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002085 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002086 strncpy(ha->model_desc,
2087 qla2x00_model_name[index * 2 + 1],
2088 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002089 } else {
2090 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002091 if (use_tbl &&
2092 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002093 index < QLA_MODEL_NAMES) {
2094 strcpy(ha->model_number,
2095 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002096 strncpy(ha->model_desc,
2097 qla2x00_model_name[index * 2 + 1],
2098 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002099 } else {
2100 strcpy(ha->model_number, def);
2101 }
2102 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002103 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002105 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002106}
2107
David Miller4e08df32007-04-16 12:37:43 -07002108/* On sparc systems, obtain port and node WWN from firmware
2109 * properties.
2110 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002111static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002112{
2113#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002114 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002115 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002116 struct device_node *dp = pci_device_to_OF_node(pdev);
2117 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002118 int len;
2119
2120 val = of_get_property(dp, "port-wwn", &len);
2121 if (val && len >= WWN_SIZE)
2122 memcpy(nv->port_name, val, WWN_SIZE);
2123
2124 val = of_get_property(dp, "node-wwn", &len);
2125 if (val && len >= WWN_SIZE)
2126 memcpy(nv->node_name, val, WWN_SIZE);
2127#endif
2128}
2129
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130/*
2131* NVRAM configuration for ISP 2xxx
2132*
2133* Input:
2134* ha = adapter block pointer.
2135*
2136* Output:
2137* initialization control block in response_ring
2138* host adapters parameters in host adapter block
2139*
2140* Returns:
2141* 0 = success.
2142*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002143int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002144qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145{
David Miller4e08df32007-04-16 12:37:43 -07002146 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07002147 uint8_t chksum = 0;
2148 uint16_t cnt;
2149 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002150 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07002151 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002152 nvram_t *nv = ha->nvram;
2153 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002154 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002155
David Miller4e08df32007-04-16 12:37:43 -07002156 rval = QLA_SUCCESS;
2157
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07002159 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 ha->nvram_base = 0;
2161 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2162 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2163 ha->nvram_base = 0x80;
2164
2165 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07002167 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2168 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002171 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
2173 /* Bad NVRAM data, set defaults parameters. */
2174 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2175 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2176 /* Reset NVRAM data. */
2177 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2178 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2179 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002180 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2181 "invalid -- WWPN) defaults.\n");
2182
2183 /*
2184 * Set default initialization control block.
2185 */
2186 memset(nv, 0, ha->nvram_size);
2187 nv->parameter_block_version = ICB_VERSION;
2188
2189 if (IS_QLA23XX(ha)) {
2190 nv->firmware_options[0] = BIT_2 | BIT_1;
2191 nv->firmware_options[1] = BIT_7 | BIT_5;
2192 nv->add_firmware_options[0] = BIT_5;
2193 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2194 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2195 nv->special_options[1] = BIT_7;
2196 } else if (IS_QLA2200(ha)) {
2197 nv->firmware_options[0] = BIT_2 | BIT_1;
2198 nv->firmware_options[1] = BIT_7 | BIT_5;
2199 nv->add_firmware_options[0] = BIT_5;
2200 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2201 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2202 } else if (IS_QLA2100(ha)) {
2203 nv->firmware_options[0] = BIT_3 | BIT_1;
2204 nv->firmware_options[1] = BIT_5;
2205 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2206 }
2207
2208 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2209 nv->execution_throttle = __constant_cpu_to_le16(16);
2210 nv->retry_count = 8;
2211 nv->retry_delay = 1;
2212
2213 nv->port_name[0] = 33;
2214 nv->port_name[3] = 224;
2215 nv->port_name[4] = 139;
2216
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002217 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002218
2219 nv->login_timeout = 4;
2220
2221 /*
2222 * Set default host adapter parameters
2223 */
2224 nv->host_p[1] = BIT_2;
2225 nv->reset_delay = 5;
2226 nv->port_down_retry_count = 8;
2227 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2228 nv->link_down_timeout = 60;
2229
2230 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231 }
2232
2233#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2234 /*
2235 * The SN2 does not provide BIOS emulation which means you can't change
2236 * potentially bogus BIOS settings. Force the use of default settings
2237 * for link rate and frame size. Hope that the rest of the settings
2238 * are valid.
2239 */
2240 if (ia64_platform_is("sn2")) {
2241 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2242 if (IS_QLA23XX(ha))
2243 nv->special_options[1] = BIT_7;
2244 }
2245#endif
2246
2247 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07002248 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249
2250 /*
2251 * Setup driver NVRAM options.
2252 */
2253 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2254 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2255 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2256 nv->firmware_options[1] &= ~BIT_4;
2257
2258 if (IS_QLA23XX(ha)) {
2259 nv->firmware_options[0] |= BIT_2;
2260 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002261 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez01071092005-07-06 10:31:37 -07002262 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
2264 if (IS_QLA2300(ha)) {
2265 if (ha->fb_rev == FPM_2310) {
2266 strcpy(ha->model_number, "QLA2310");
2267 } else {
2268 strcpy(ha->model_number, "QLA2300");
2269 }
2270 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002271 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002272 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 }
2274 } else if (IS_QLA2200(ha)) {
2275 nv->firmware_options[0] |= BIT_2;
2276 /*
2277 * 'Point-to-point preferred, else loop' is not a safe
2278 * connection mode setting.
2279 */
2280 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2281 (BIT_5 | BIT_4)) {
2282 /* Force 'loop preferred, else point-to-point'. */
2283 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2284 nv->add_firmware_options[0] |= BIT_5;
2285 }
2286 strcpy(ha->model_number, "QLA22xx");
2287 } else /*if (IS_QLA2100(ha))*/ {
2288 strcpy(ha->model_number, "QLA2100");
2289 }
2290
2291 /*
2292 * Copy over NVRAM RISC parameter block to initialization control block.
2293 */
2294 dptr1 = (uint8_t *)icb;
2295 dptr2 = (uint8_t *)&nv->parameter_block_version;
2296 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2297 while (cnt--)
2298 *dptr1++ = *dptr2++;
2299
2300 /* Copy 2nd half. */
2301 dptr1 = (uint8_t *)icb->add_firmware_options;
2302 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2303 while (cnt--)
2304 *dptr1++ = *dptr2++;
2305
Andrew Vasquez5341e862006-05-17 15:09:16 -07002306 /* Use alternate WWN? */
2307 if (nv->host_p[1] & BIT_7) {
2308 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2309 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2310 }
2311
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 /* Prepare nodename */
2313 if ((icb->firmware_options[1] & BIT_6) == 0) {
2314 /*
2315 * Firmware will apply the following mask if the nodename was
2316 * not provided.
2317 */
2318 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2319 icb->node_name[0] &= 0xF0;
2320 }
2321
2322 /*
2323 * Set host adapter parameters.
2324 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002325 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002326 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002327 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2328 /* Always load RISC code on non ISP2[12]00 chips. */
2329 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2330 ha->flags.disable_risc_code_load = 0;
2331 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2332 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2333 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002334 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002335 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
2337 ha->operating_mode =
2338 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2339
2340 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2341 sizeof(ha->fw_seriallink_options));
2342
2343 /* save HBA serial number */
2344 ha->serial0 = icb->port_name[5];
2345 ha->serial1 = icb->port_name[6];
2346 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002347 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2348 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349
2350 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2351
2352 ha->retry_count = nv->retry_count;
2353
2354 /* Set minimum login_timeout to 4 seconds. */
Andrew Vasquez5b914902010-05-28 15:08:30 -07002355 if (nv->login_timeout != ql2xlogintimeout)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 nv->login_timeout = ql2xlogintimeout;
2357 if (nv->login_timeout < 4)
2358 nv->login_timeout = 4;
2359 ha->login_timeout = nv->login_timeout;
2360 icb->login_timeout = nv->login_timeout;
2361
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002362 /* Set minimum RATOV to 100 tenths of a second. */
2363 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002364
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 ha->loop_reset_delay = nv->reset_delay;
2366
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 /* Link Down Timeout = 0:
2368 *
2369 * When Port Down timer expires we will start returning
2370 * I/O's to OS with "DID_NO_CONNECT".
2371 *
2372 * Link Down Timeout != 0:
2373 *
2374 * The driver waits for the link to come up after link down
2375 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002376 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 if (nv->link_down_timeout == 0) {
2378 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002379 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 } else {
2381 ha->link_down_timeout = nv->link_down_timeout;
2382 ha->loop_down_abort_time =
2383 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002384 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 /*
2387 * Need enough time to try and get the port back.
2388 */
2389 ha->port_down_retry_count = nv->port_down_retry_count;
2390 if (qlport_down_retry)
2391 ha->port_down_retry_count = qlport_down_retry;
2392 /* Set login_retry_count */
2393 ha->login_retry_count = nv->retry_count;
2394 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2395 ha->port_down_retry_count > 3)
2396 ha->login_retry_count = ha->port_down_retry_count;
2397 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2398 ha->login_retry_count = ha->port_down_retry_count;
2399 if (ql2xloginretrycount)
2400 ha->login_retry_count = ql2xloginretrycount;
2401
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402 icb->lun_enables = __constant_cpu_to_le16(0);
2403 icb->command_resource_count = 0;
2404 icb->immediate_notify_resource_count = 0;
2405 icb->timeout = __constant_cpu_to_le16(0);
2406
2407 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2408 /* Enable RIO */
2409 icb->firmware_options[0] &= ~BIT_3;
2410 icb->add_firmware_options[0] &=
2411 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2412 icb->add_firmware_options[0] |= BIT_2;
2413 icb->response_accumulation_timer = 3;
2414 icb->interrupt_delay_timer = 5;
2415
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002418 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002419 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002420 ha->zio_mode = icb->add_firmware_options[0] &
2421 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2422 ha->zio_timer = icb->interrupt_delay_timer ?
2423 icb->interrupt_delay_timer: 2;
2424 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 icb->add_firmware_options[0] &=
2426 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002428 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002429 ha->zio_mode = QLA_ZIO_MODE_6;
2430
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002431 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002433 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002435 "ZIO mode %d enabled; timer delay (%d us).\n",
2436 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002438 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2439 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 }
2442 }
2443
David Miller4e08df32007-04-16 12:37:43 -07002444 if (rval) {
2445 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002447 }
2448 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449}
2450
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002451static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002452qla2x00_rport_del(void *data)
2453{
2454 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002455 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002458 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002459 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002460 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002461 if (rport)
2462 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002463}
2464
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465/**
2466 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2467 * @ha: HA context
2468 * @flags: allocation flags
2469 *
2470 * Returns a pointer to the allocated fcport, or NULL, if none available.
2471 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002472fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474{
2475 fc_port_t *fcport;
2476
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002477 fcport = kzalloc(sizeof(fc_port_t), flags);
2478 if (!fcport)
2479 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
2481 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002482 fcport->vha = vha;
2483 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 fcport->port_type = FCT_UNKNOWN;
2485 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002487 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002489 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490}
2491
2492/*
2493 * qla2x00_configure_loop
2494 * Updates Fibre Channel Device Database with what is actually on loop.
2495 *
2496 * Input:
2497 * ha = adapter block pointer.
2498 *
2499 * Returns:
2500 * 0 = success.
2501 * 1 = error.
2502 * 2 = database was full and device was not configured.
2503 */
2504static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506{
2507 int rval;
2508 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002509 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 rval = QLA_SUCCESS;
2511
2512 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2514 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 if (rval != QLA_SUCCESS) {
2516 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 return (rval);
2519 }
2520 }
2521
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002522 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002524 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002525
2526 /*
2527 * If we have both an RSCN and PORT UPDATE pending then handle them
2528 * both at the same time.
2529 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002530 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2531 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Michael Hernandez3064ff32009-12-15 21:29:44 -08002533 qla2x00_get_data_rate(vha);
2534
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 /* Determine what we need to do */
2536 if (ha->current_topology == ISP_CFG_FL &&
2537 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2538
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 set_bit(RSCN_UPDATE, &flags);
2541
2542 } else if (ha->current_topology == ISP_CFG_F &&
2543 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2544
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 set_bit(RSCN_UPDATE, &flags);
2547 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2548
Andrew Vasquez21333b42006-05-17 15:09:56 -07002549 } else if (ha->current_topology == ISP_CFG_N) {
2550 clear_bit(RSCN_UPDATE, &flags);
2551
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 set_bit(RSCN_UPDATE, &flags);
2557 set_bit(LOCAL_LOOP_UPDATE, &flags);
2558 }
2559
2560 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002561 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 else
2564 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 }
2566
2567 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 else
2571 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 }
2573
2574 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002575 if (atomic_read(&vha->loop_down_timer) ||
2576 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 rval = QLA_FUNCTION_FAILED;
2578 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 }
2583 }
2584
2585 if (rval) {
2586 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 } else {
2589 DEBUG3(printk("%s: exiting normally\n", __func__));
2590 }
2591
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002592 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002596 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002598 if (!IS_ALOGIO_CAPABLE(ha))
2599 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002600 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 }
2602
2603 return (rval);
2604}
2605
2606
2607
2608/*
2609 * qla2x00_configure_local_loop
2610 * Updates Fibre Channel Device Database with local loop devices.
2611 *
2612 * Input:
2613 * ha = adapter block pointer.
2614 *
2615 * Returns:
2616 * 0 = success.
2617 */
2618static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620{
2621 int rval, rval2;
2622 int found_devs;
2623 int found;
2624 fc_port_t *fcport, *new_fcport;
2625
2626 uint16_t index;
2627 uint16_t entries;
2628 char *id_iter;
2629 uint16_t loop_id;
2630 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002631 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
2633 found_devs = 0;
2634 new_fcport = NULL;
2635 entries = MAX_FIBRE_DEVICES;
2636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2638 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002639
2640 /* Get list of logged in devices. */
2641 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 &entries);
2644 if (rval != QLA_SUCCESS)
2645 goto cleanup_allocation;
2646
2647 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002648 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2650 entries * sizeof(struct gid_list_info)));
2651
2652 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 if (new_fcport == NULL) {
2655 rval = QLA_MEMORY_ALLOC_FAILED;
2656 goto cleanup_allocation;
2657 }
2658 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2659
2660 /*
2661 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2662 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002663 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2665 fcport->port_type != FCT_BROADCAST &&
2666 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2667
2668 DEBUG(printk("scsi(%ld): Marking port lost, "
2669 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002670 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
2672 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673 }
2674 }
2675
2676 /* Add devices to port list. */
2677 id_iter = (char *)ha->gid_list;
2678 for (index = 0; index < entries; index++) {
2679 domain = ((struct gid_list_info *)id_iter)->domain;
2680 area = ((struct gid_list_info *)id_iter)->area;
2681 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002682 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 loop_id = (uint16_t)
2684 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002685 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 loop_id = le16_to_cpu(
2687 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002688 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689
2690 /* Bypass reserved domain fields. */
2691 if ((domain & 0xf0) == 0xf0)
2692 continue;
2693
2694 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002695 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 continue;
2698
2699 /* Bypass invalid local loop ID. */
2700 if (loop_id > LAST_LOCAL_LOOP_ID)
2701 continue;
2702
2703 /* Fill in member data. */
2704 new_fcport->d_id.b.domain = domain;
2705 new_fcport->d_id.b.area = area;
2706 new_fcport->d_id.b.al_pa = al_pa;
2707 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 new_fcport->vp_idx = vha->vp_idx;
2709 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 if (rval2 != QLA_SUCCESS) {
2711 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2712 "information -- get_port_database=%x, "
2713 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002715 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 vha->host_no));
2717 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 continue;
2719 }
2720
2721 /* Check for matching device in port list. */
2722 found = 0;
2723 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 if (memcmp(new_fcport->port_name, fcport->port_name,
2726 WWN_SIZE))
2727 continue;
2728
Shyam Sundarddb9b122009-03-24 09:08:10 -07002729 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 fcport->loop_id = new_fcport->loop_id;
2731 fcport->port_type = new_fcport->port_type;
2732 fcport->d_id.b24 = new_fcport->d_id.b24;
2733 memcpy(fcport->node_name, new_fcport->node_name,
2734 WWN_SIZE);
2735
2736 found++;
2737 break;
2738 }
2739
2740 if (!found) {
2741 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002742 if (vha->vp_idx) {
2743 new_fcport->vha = vha;
2744 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002745 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002746 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747
2748 /* Allocate a new replacement fcport. */
2749 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002750 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002751 if (new_fcport == NULL) {
2752 rval = QLA_MEMORY_ALLOC_FAILED;
2753 goto cleanup_allocation;
2754 }
2755 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2756 }
2757
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002758 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002759 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002760
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
2763 found_devs++;
2764 }
2765
2766cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002767 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768
2769 if (rval != QLA_SUCCESS) {
2770 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 }
2773
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 return (rval);
2775}
2776
2777static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002779{
2780#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002781 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2782 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002783 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002784 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002785 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002786
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002787 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002788 return;
2789
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002790 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2791 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002792 return;
2793
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002794 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002795 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002796 if (rval != QLA_SUCCESS) {
2797 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2798 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002800 fcport->port_name[2], fcport->port_name[3],
2801 fcport->port_name[4], fcport->port_name[5],
2802 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002803 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002804 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002805 link_speed = link_speeds[LS_UNKNOWN];
2806 if (fcport->fp_speed < 5)
2807 link_speed = link_speeds[fcport->fp_speed];
2808 else if (fcport->fp_speed == 0x13)
2809 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002810 DEBUG2(qla_printk(KERN_INFO, ha,
2811 "iIDMA adjusted to %s GB/s on "
2812 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002813 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002814 fcport->port_name[1], fcport->port_name[2],
2815 fcport->port_name[3], fcport->port_name[4],
2816 fcport->port_name[5], fcport->port_name[6],
2817 fcport->port_name[7]));
2818 }
2819}
2820
Adrian Bunk23be3312006-11-24 02:46:01 +01002821static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e112005-04-17 15:04:54 -05002823{
2824 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002825 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05002827
Andrew Vasquezac280b62009-08-20 11:06:05 -07002828 qla2x00_rport_del(fcport);
8482e112005-04-17 15:04:54 -05002829
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002830 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2831 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002832 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2833 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2834 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002836 if (!rport) {
2837 qla_printk(KERN_WARNING, ha,
2838 "Unable to allocate fc remote port!\n");
2839 return;
2840 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002842 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002844
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002845 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002846
2847 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002848 if (fcport->port_type == FCT_INITIATOR)
2849 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2850 if (fcport->port_type == FCT_TARGET)
2851 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002852 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e112005-04-17 15:04:54 -05002853}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
2855/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002856 * qla2x00_update_fcport
2857 * Updates device on list.
2858 *
2859 * Input:
2860 * ha = adapter block pointer.
2861 * fcport = port structure pointer.
2862 *
2863 * Return:
2864 * 0 - Success
2865 * BIT_0 - error
2866 *
2867 * Context:
2868 * Kernel context.
2869 */
2870void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002871qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002872{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002873 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002876 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002877 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002878 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002880 PORT_RETRY_TIME);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002881 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002882
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002883 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002884
2885 atomic_set(&fcport->state, FCS_ONLINE);
2886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002887 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002888}
2889
2890/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 * qla2x00_configure_fabric
2892 * Setup SNS devices with loop ID's.
2893 *
2894 * Input:
2895 * ha = adapter block pointer.
2896 *
2897 * Returns:
2898 * 0 = success.
2899 * BIT_0 = error
2900 */
2901static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903{
2904 int rval, rval2;
2905 fc_port_t *fcport, *fcptemp;
2906 uint16_t next_loopid;
2907 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002908 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002909 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 struct qla_hw_data *ha = vha->hw;
2911 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912
2913 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002914 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002915 loop_id = NPH_F_PORT;
2916 else
2917 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 if (rval != QLA_SUCCESS) {
2920 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 return (QLA_SUCCESS);
2925 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927
2928 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 if (rval2 == QLA_RSCNS_HANDLED) {
2931 /* No point doing the scan, just continue. */
2932 return (QLA_SUCCESS);
2933 }
2934 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002935 /* FDMI support. */
2936 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2938 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002939
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002941 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002942 loop_id = NPH_SNS;
2943 else
2944 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002945 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002946 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 if (mb[0] != MBS_COMMAND_COMPLETE) {
2948 DEBUG2(qla_printk(KERN_INFO, ha,
2949 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002950 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 mb[0], mb[1], mb[2], mb[6], mb[7]));
2952 return (QLA_SUCCESS);
2953 }
2954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2956 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 /* EMPTY */
2958 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 /* EMPTY */
2963 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 /* EMPTY */
2968 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002969 "failed.\n", vha->host_no));
2970 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 /* EMPTY */
2972 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 }
2975 }
2976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 if (rval != QLA_SUCCESS)
2979 break;
2980
2981 /*
2982 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002983 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2986 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 break;
2988
2989 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2990 continue;
2991
2992 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002993 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002994 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002995 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002996 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 fcport->port_type != FCT_INITIATOR &&
2998 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002999 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003000 fcport->loop_id,
3001 fcport->d_id.b.domain,
3002 fcport->d_id.b.area,
3003 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 fcport->loop_id = FC_NO_LOOP_ID;
3005 }
3006 }
3007 }
3008
3009 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003011
3012 /*
3013 * Scan through our port list and login entries that need to be
3014 * logged in.
3015 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3017 if (atomic_read(&vha->loop_down_timer) ||
3018 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 break;
3020
3021 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3022 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3023 continue;
3024
3025 if (fcport->loop_id == FC_NO_LOOP_ID) {
3026 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07003027 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 if (rval != QLA_SUCCESS) {
3030 /* Ran out of IDs to use */
3031 break;
3032 }
3033 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003035 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 }
3037
3038 /* Exit if out of loop IDs. */
3039 if (rval != QLA_SUCCESS) {
3040 break;
3041 }
3042
3043 /*
3044 * Login and add the new devices to our port list.
3045 */
3046 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 if (atomic_read(&vha->loop_down_timer) ||
3048 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 break;
3050
3051 /* Find a new loop ID to use. */
3052 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 if (rval != QLA_SUCCESS) {
3055 /* Ran out of IDs to use */
3056 break;
3057 }
3058
bdf79622005-04-17 15:06:53 -05003059 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003061
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 if (vha->vp_idx) {
3063 fcport->vha = vha;
3064 fcport->vp_idx = vha->vp_idx;
3065 }
3066 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 }
3068 } while (0);
3069
3070 /* Free all new device structures not processed. */
3071 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3072 list_del(&fcport->list);
3073 kfree(fcport);
3074 }
3075
3076 if (rval) {
3077 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003078 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
3080
3081 return (rval);
3082}
3083
3084
3085/*
3086 * qla2x00_find_all_fabric_devs
3087 *
3088 * Input:
3089 * ha = adapter block pointer.
3090 * dev = database device entry pointer.
3091 *
3092 * Returns:
3093 * 0 = success.
3094 *
3095 * Context:
3096 * Kernel context.
3097 */
3098static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003099qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3100 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101{
3102 int rval;
3103 uint16_t loop_id;
3104 fc_port_t *fcport, *new_fcport, *fcptemp;
3105 int found;
3106
3107 sw_info_t *swl;
3108 int swl_idx;
3109 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003110 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003111 struct qla_hw_data *ha = vha->hw;
3112 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003113 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115 rval = QLA_SUCCESS;
3116
3117 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003118 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003119 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120 /*EMPTY*/
3121 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003122 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003124 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 kfree(swl);
3126 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003127 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 kfree(swl);
3129 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003130 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131 kfree(swl);
3132 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003133 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3135 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 }
3137 }
3138 swl_idx = 0;
3139
3140 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003141 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003142 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003143 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 return (QLA_MEMORY_ALLOC_FAILED);
3145 }
3146 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 /* Set start port ID scan at adapter ID. */
3148 first_dev = 1;
3149 last_dev = 0;
3150
3151 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 loop_id = ha->min_external_loopid;
3153 for (; loop_id <= ha->max_loop_id; loop_id++) {
3154 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 continue;
3156
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003157 if (ha->current_topology == ISP_CFG_FL &&
3158 (atomic_read(&vha->loop_down_timer) ||
3159 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003160 atomic_set(&vha->loop_down_timer, 0);
3161 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3162 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003164 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165
3166 if (swl != NULL) {
3167 if (last_dev) {
3168 wrap.b24 = new_fcport->d_id.b24;
3169 } else {
3170 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3171 memcpy(new_fcport->node_name,
3172 swl[swl_idx].node_name, WWN_SIZE);
3173 memcpy(new_fcport->port_name,
3174 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003175 memcpy(new_fcport->fabric_port_name,
3176 swl[swl_idx].fabric_port_name, WWN_SIZE);
3177 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
3179 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3180 last_dev = 1;
3181 }
3182 swl_idx++;
3183 }
3184 } else {
3185 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 if (rval != QLA_SUCCESS) {
3188 qla_printk(KERN_WARNING, ha,
3189 "SNS scan failed -- assuming zero-entry "
3190 "result...\n");
3191 list_for_each_entry_safe(fcport, fcptemp,
3192 new_fcports, list) {
3193 list_del(&fcport->list);
3194 kfree(fcport);
3195 }
3196 rval = QLA_SUCCESS;
3197 break;
3198 }
3199 }
3200
3201 /* If wrap on switch device list, exit. */
3202 if (first_dev) {
3203 wrap.b24 = new_fcport->d_id.b24;
3204 first_dev = 0;
3205 } else if (new_fcport->d_id.b24 == wrap.b24) {
3206 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3209 break;
3210 }
3211
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003212 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003213 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 continue;
3215
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003216 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003217 found = 0;
3218 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003219 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003220 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3221 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003222 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003223 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003224 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003225 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003226 continue;
3227 }
3228
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003229 /* Bypass if same domain and area of adapter. */
3230 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003232 ISP_CFG_FL)
3233 continue;
3234
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 /* Bypass reserved domain fields. */
3236 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3237 continue;
3238
3239 /* Locate matching device in database. */
3240 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003241 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 if (memcmp(new_fcport->port_name, fcport->port_name,
3243 WWN_SIZE))
3244 continue;
3245
3246 found++;
3247
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003248 /* Update port state. */
3249 memcpy(fcport->fabric_port_name,
3250 new_fcport->fabric_port_name, WWN_SIZE);
3251 fcport->fp_speed = new_fcport->fp_speed;
3252
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 /*
3254 * If address the same and state FCS_ONLINE, nothing
3255 * changed.
3256 */
3257 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3258 atomic_read(&fcport->state) == FCS_ONLINE) {
3259 break;
3260 }
3261
3262 /*
3263 * If device was not a fabric device before.
3264 */
3265 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3266 fcport->d_id.b24 = new_fcport->d_id.b24;
3267 fcport->loop_id = FC_NO_LOOP_ID;
3268 fcport->flags |= (FCF_FABRIC_DEVICE |
3269 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 break;
3271 }
3272
3273 /*
3274 * Port ID changed or device was marked to be updated;
3275 * Log it out if still logged in and mark it for
3276 * relogin later.
3277 */
3278 fcport->d_id.b24 = new_fcport->d_id.b24;
3279 fcport->flags |= FCF_LOGIN_NEEDED;
3280 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003281 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 fcport->port_type != FCT_INITIATOR &&
3283 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003284 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003285 fcport->d_id.b.domain, fcport->d_id.b.area,
3286 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 fcport->loop_id = FC_NO_LOOP_ID;
3288 }
3289
3290 break;
3291 }
3292
3293 if (found)
3294 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 /* If device was not in our fcports list, then add it. */
3296 list_add_tail(&new_fcport->list, new_fcports);
3297
3298 /* Allocate a new replacement fcport. */
3299 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003302 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 return (QLA_MEMORY_ALLOC_FAILED);
3304 }
3305 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3306 new_fcport->d_id.b24 = nxt_d_id.b24;
3307 }
3308
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003309 kfree(swl);
3310 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 return (rval);
3313}
3314
3315/*
3316 * qla2x00_find_new_loop_id
3317 * Scan through our port list and find a new usable loop ID.
3318 *
3319 * Input:
3320 * ha: adapter state pointer.
3321 * dev: port structure pointer.
3322 *
3323 * Returns:
3324 * qla2x00 local function return status code.
3325 *
3326 * Context:
3327 * Kernel context.
3328 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003329static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331{
3332 int rval;
3333 int found;
3334 fc_port_t *fcport;
3335 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336 struct qla_hw_data *ha = vha->hw;
3337 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003338 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
3340 rval = QLA_SUCCESS;
3341
3342 /* Save starting loop ID. */
3343 first_loop_id = dev->loop_id;
3344
3345 for (;;) {
3346 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349
3350 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
3354 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003355 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 /* first loop ID. */
3357 dev->loop_id = ha->min_external_loopid;
3358 }
3359
3360 /* Check for loop ID being already in use. */
3361 found = 0;
3362 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003363 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003364 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3365 if (fcport->loop_id == dev->loop_id &&
3366 fcport != dev) {
3367 /* ID possibly in use */
3368 found++;
3369 break;
3370 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372 if (found)
3373 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 }
3375
3376 /* If not in use then it is free to use. */
3377 if (!found) {
3378 break;
3379 }
3380
3381 /* ID in use. Try next value. */
3382 dev->loop_id++;
3383
3384 /* If wrap around. No free ID to use. */
3385 if (dev->loop_id == first_loop_id) {
3386 dev->loop_id = FC_NO_LOOP_ID;
3387 rval = QLA_FUNCTION_FAILED;
3388 break;
3389 }
3390 }
3391
3392 return (rval);
3393}
3394
3395/*
3396 * qla2x00_device_resync
3397 * Marks devices in the database that needs resynchronization.
3398 *
3399 * Input:
3400 * ha = adapter block pointer.
3401 *
3402 * Context:
3403 * Kernel context.
3404 */
3405static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003406qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407{
3408 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 uint32_t mask;
3410 fc_port_t *fcport;
3411 uint32_t rscn_entry;
3412 uint8_t rscn_out_iter;
3413 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003414 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
3416 rval = QLA_RSCNS_HANDLED;
3417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3419 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 format = MSB(MSW(rscn_entry));
3423 d_id.b.domain = LSB(MSW(rscn_entry));
3424 d_id.b.area = MSB(LSW(rscn_entry));
3425 d_id.b.al_pa = LSB(LSW(rscn_entry));
3426
3427 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3428 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 d_id.b.area, d_id.b.al_pa));
3431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 vha->rscn_out_ptr++;
3433 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3434 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435
3436 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003437 for (rscn_out_iter = vha->rscn_out_ptr;
3438 !vha->flags.rscn_queue_overflow &&
3439 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440 rscn_out_iter = (rscn_out_iter ==
3441 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 break;
3445
3446 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003447 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 rscn_out_iter));
3449
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 }
3452
3453 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003454 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003455 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003456 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
3458 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 }
3461
3462 switch (format) {
3463 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 mask = 0xffffff;
3465 break;
3466 case 1:
3467 mask = 0xffff00;
3468 break;
3469 case 2:
3470 mask = 0xff0000;
3471 break;
3472 default:
3473 mask = 0x0;
3474 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476 break;
3477 }
3478
3479 rval = QLA_SUCCESS;
3480
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3483 (fcport->d_id.b24 & mask) != d_id.b24 ||
3484 fcport->port_type == FCT_BROADCAST)
3485 continue;
3486
3487 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3488 if (format != 3 ||
3489 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003490 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003491 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 }
3493 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494 }
3495 }
3496 return (rval);
3497}
3498
3499/*
3500 * qla2x00_fabric_dev_login
3501 * Login fabric target device and update FC port database.
3502 *
3503 * Input:
3504 * ha: adapter state pointer.
3505 * fcport: port structure list pointer.
3506 * next_loopid: contains value of a new loop ID that can be used
3507 * by the next login attempt.
3508 *
3509 * Returns:
3510 * qla2x00 local function return status code.
3511 *
3512 * Context:
3513 * Kernel context.
3514 */
3515static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517 uint16_t *next_loopid)
3518{
3519 int rval;
3520 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07003521 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523
3524 rval = QLA_SUCCESS;
3525 retry = 0;
3526
Andrew Vasquezac280b62009-08-20 11:06:05 -07003527 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003528 if (fcport->flags & FCF_ASYNC_SENT)
3529 return rval;
3530 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003531 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3532 if (!rval)
3533 return rval;
3534 }
3535
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003536 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003537 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003539 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez01071092005-07-06 10:31:37 -07003540 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003541 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez01071092005-07-06 10:31:37 -07003542 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003546 fcport->d_id.b.domain, fcport->d_id.b.area,
3547 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 }
3552 }
3553
3554 return (rval);
3555}
3556
3557/*
3558 * qla2x00_fabric_login
3559 * Issue fabric login command.
3560 *
3561 * Input:
3562 * ha = adapter block pointer.
3563 * device = pointer to FC device type structure.
3564 *
3565 * Returns:
3566 * 0 - Login successfully
3567 * 1 - Login failed
3568 * 2 - Initiator device
3569 * 3 - Fatal error
3570 */
3571int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 uint16_t *next_loopid)
3574{
3575 int rval;
3576 int retry;
3577 uint16_t tmp_loopid;
3578 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580
3581 retry = 0;
3582 tmp_loopid = 0;
3583
3584 for (;;) {
3585 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3586 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3589
3590 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003592 fcport->d_id.b.domain, fcport->d_id.b.area,
3593 fcport->d_id.b.al_pa, mb, BIT_0);
3594 if (mb[0] == MBS_PORT_ID_USED) {
3595 /*
3596 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07003597 * recommends the driver perform an implicit login with
3598 * the specified ID again. The ID we just used is save
3599 * here so we return with an ID that can be tried by
3600 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 */
3602 retry++;
3603 tmp_loopid = fcport->loop_id;
3604 fcport->loop_id = mb[1];
3605
3606 DEBUG(printk("Fabric Login: port in use - next "
3607 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3608 fcport->loop_id, fcport->d_id.b.domain,
3609 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3610
3611 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3612 /*
3613 * Login succeeded.
3614 */
3615 if (retry) {
3616 /* A retry occurred before. */
3617 *next_loopid = tmp_loopid;
3618 } else {
3619 /*
3620 * No retry occurred before. Just increment the
3621 * ID value for next login.
3622 */
3623 *next_loopid = (fcport->loop_id + 1);
3624 }
3625
3626 if (mb[1] & BIT_0) {
3627 fcport->port_type = FCT_INITIATOR;
3628 } else {
3629 fcport->port_type = FCT_TARGET;
3630 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003631 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 }
3633 }
3634
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003635 if (mb[10] & BIT_0)
3636 fcport->supported_classes |= FC_COS_CLASS2;
3637 if (mb[10] & BIT_1)
3638 fcport->supported_classes |= FC_COS_CLASS3;
3639
Linus Torvalds1da177e2005-04-16 15:20:36 -07003640 rval = QLA_SUCCESS;
3641 break;
3642 } else if (mb[0] == MBS_LOOP_ID_USED) {
3643 /*
3644 * Loop ID already used, try next loop ID.
3645 */
3646 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003647 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 if (rval != QLA_SUCCESS) {
3649 /* Ran out of loop IDs to use */
3650 break;
3651 }
3652 } else if (mb[0] == MBS_COMMAND_ERROR) {
3653 /*
3654 * Firmware possibly timed out during login. If NO
3655 * retries are left to do then the device is declared
3656 * dead.
3657 */
3658 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003659 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003660 fcport->d_id.b.domain, fcport->d_id.b.area,
3661 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663
3664 rval = 1;
3665 break;
3666 } else {
3667 /*
3668 * unrecoverable / not handled error
3669 */
3670 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003671 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003672 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673 fcport->d_id.b.domain, fcport->d_id.b.area,
3674 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3675
3676 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003677 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003678 fcport->d_id.b.domain, fcport->d_id.b.area,
3679 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003680 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003681 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682
3683 rval = 3;
3684 break;
3685 }
3686 }
3687
3688 return (rval);
3689}
3690
3691/*
3692 * qla2x00_local_device_login
3693 * Issue local device login command.
3694 *
3695 * Input:
3696 * ha = adapter block pointer.
3697 * loop_id = loop id of device to login to.
3698 *
3699 * Returns (Where's the #define!!!!):
3700 * 0 - Login successfully
3701 * 1 - Login failed
3702 * 3 - Fatal error
3703 */
3704int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003705qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003706{
3707 int rval;
3708 uint16_t mb[MAILBOX_REGISTER_COUNT];
3709
3710 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003711 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 if (rval == QLA_SUCCESS) {
3713 /* Interrogate mailbox registers for any errors */
3714 if (mb[0] == MBS_COMMAND_ERROR)
3715 rval = 1;
3716 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3717 /* device not in PCB table */
3718 rval = 3;
3719 }
3720
3721 return (rval);
3722}
3723
3724/*
3725 * qla2x00_loop_resync
3726 * Resync with fibre channel devices.
3727 *
3728 * Input:
3729 * ha = adapter block pointer.
3730 *
3731 * Returns:
3732 * 0 = success
3733 */
3734int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003735qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003737 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003739 struct req_que *req;
3740 struct rsp_que *rsp;
3741
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003742 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003743 req = vha->hw->req_q_map[0];
3744 else
3745 req = vha->req;
3746 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003748 atomic_set(&vha->loop_state, LOOP_UPDATE);
3749 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3750 if (vha->flags.online) {
3751 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3753 wait_time = 256;
3754 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003755 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756
Andrew Vasquez01071092005-07-06 10:31:37 -07003757 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003758 qla2x00_marker(vha, req, rsp, 0, 0,
3759 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003760 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003761
3762 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003763 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003764
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003765 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003767 } while (!atomic_read(&vha->loop_down_timer) &&
3768 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3769 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3770 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772 }
3773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003774 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779
3780 return (rval);
3781}
3782
Linus Torvalds1da177e2005-04-16 15:20:36 -07003783void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003784qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003785{
3786 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003787 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003788
3789 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003790 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3791 list_for_each_entry(fcport, &vha->vp_fcports, list)
3792 if (fcport && fcport->drport &&
3793 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3794 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003795}
3796
Giridhar Malavalia9083012010-04-12 17:59:55 -07003797void
3798qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3799{
3800 struct qla_hw_data *ha = vha->hw;
3801 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3802 struct scsi_qla_host *tvp;
3803
3804 vha->flags.online = 0;
3805 ha->flags.chip_reset_done = 0;
3806 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3807 ha->qla_stats.total_isp_aborts++;
3808
3809 qla_printk(KERN_INFO, ha,
3810 "Performing ISP error recovery - ha= %p.\n", ha);
3811
3812 /* Chip reset does not apply to 82XX */
3813 if (!IS_QLA82XX(ha))
3814 ha->isp_ops->reset_chip(vha);
3815
3816 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3817 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3818 atomic_set(&vha->loop_state, LOOP_DOWN);
3819 qla2x00_mark_all_devices_lost(vha, 0);
3820 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3821 qla2x00_mark_all_devices_lost(vp, 0);
3822 } else {
3823 if (!atomic_read(&vha->loop_down_timer))
3824 atomic_set(&vha->loop_down_timer,
3825 LOOP_DOWN_TIME);
3826 }
3827
3828 /* Make sure for ISP 82XX IO DMA is complete */
3829 if (IS_QLA82XX(ha))
3830 qla82xx_wait_for_pending_commands(vha);
3831
3832 /* Requeue all commands in outstanding command list. */
3833 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3834}
3835
Linus Torvalds1da177e2005-04-16 15:20:36 -07003836/*
3837* qla2x00_abort_isp
3838* Resets ISP and aborts all outstanding commands.
3839*
3840* Input:
3841* ha = adapter block pointer.
3842*
3843* Returns:
3844* 0 = success
3845*/
3846int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003847qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003848{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003849 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003850 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003851 struct qla_hw_data *ha = vha->hw;
3852 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003853 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003854 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003857 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858
Andrew Vasquez85880802009-12-15 21:29:46 -08003859 if (unlikely(pci_channel_offline(ha->pdev) &&
3860 ha->flags.pci_channel_io_perm_failure)) {
3861 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3862 status = 0;
3863 return status;
3864 }
3865
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003866 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003867
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003868 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003869
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003870 if (!qla2x00_restart_isp(vha)) {
3871 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003872
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003873 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003874 /*
3875 * Issue marker command only when we are going
3876 * to start the I/O .
3877 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003878 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879 }
3880
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003881 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003882
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003883 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003884
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003885 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003887
Lalit Chandivade29c53972009-10-13 15:16:47 -07003888 if (IS_QLA81XX(ha))
3889 qla2x00_get_fw_version(vha,
3890 &ha->fw_major_version,
3891 &ha->fw_minor_version,
3892 &ha->fw_subminor_version,
3893 &ha->fw_attributes, &ha->fw_memory_size,
3894 ha->mpi_version, &ha->mpi_capabilities,
3895 ha->phy_version);
3896
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003897 if (ha->fce) {
3898 ha->flags.fce_enabled = 1;
3899 memset(ha->fce, 0,
3900 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003901 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003902 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3903 &ha->fce_bufs);
3904 if (rval) {
3905 qla_printk(KERN_WARNING, ha,
3906 "Unable to reinitialize FCE "
3907 "(%d).\n", rval);
3908 ha->flags.fce_enabled = 0;
3909 }
3910 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003911
3912 if (ha->eft) {
3913 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003914 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003915 ha->eft_dma, EFT_NUM_BUFFERS);
3916 if (rval) {
3917 qla_printk(KERN_WARNING, ha,
3918 "Unable to reinitialize EFT "
3919 "(%d).\n", rval);
3920 }
3921 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003922 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003923 vha->flags.online = 1;
3924 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925 if (ha->isp_abort_cnt == 0) {
3926 qla_printk(KERN_WARNING, ha,
3927 "ISP error recovery failed - "
3928 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003929 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 * The next call disables the board
3931 * completely.
3932 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003933 ha->isp_ops->reset_adapter(vha);
3934 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003936 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003937 status = 0;
3938 } else { /* schedule another ISP abort */
3939 ha->isp_abort_cnt--;
3940 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003941 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003942 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003943 status = 1;
3944 }
3945 } else {
3946 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3947 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3948 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003949 vha->host_no, ha->isp_abort_cnt));
3950 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003951 status = 1;
3952 }
3953 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003954
Linus Torvalds1da177e2005-04-16 15:20:36 -07003955 }
3956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003957 if (!status) {
3958 DEBUG(printk(KERN_INFO
3959 "qla2x00_abort_isp(%ld): succeeded.\n",
3960 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003961 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003962 if (vp->vp_idx)
3963 qla2x00_vp_abort_isp(vp);
3964 }
3965 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 qla_printk(KERN_INFO, ha,
3967 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968 }
3969
3970 return(status);
3971}
3972
3973/*
3974* qla2x00_restart_isp
3975* restarts the ISP after a reset
3976*
3977* Input:
3978* ha = adapter block pointer.
3979*
3980* Returns:
3981* 0 = success
3982*/
3983static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003984qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003986 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003988 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003989 struct req_que *req = ha->req_q_map[0];
3990 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991
3992 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003993 if (qla2x00_isp_firmware(vha)) {
3994 vha->flags.online = 0;
3995 status = ha->isp_ops->chip_diag(vha);
3996 if (!status)
3997 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003998 }
3999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004000 if (!status && !(status = qla2x00_init_rings(vha))) {
4001 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004002 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004003 /* Initialize the queues in use */
4004 qla25xx_init_queues(ha);
4005
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004006 status = qla2x00_fw_ready(vha);
4007 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004009 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07004010
4011 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004012 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez01071092005-07-06 10:31:37 -07004013
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004014 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004015 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4016 wait_time = 256;
4017 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004018 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4019 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004020 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004021 } while (!atomic_read(&vha->loop_down_timer) &&
4022 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4023 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4024 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004025 }
4026
4027 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004028 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 status = 0;
4030
4031 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4032 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004033 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004034 }
4035 return (status);
4036}
4037
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004038static int
4039qla25xx_init_queues(struct qla_hw_data *ha)
4040{
4041 struct rsp_que *rsp = NULL;
4042 struct req_que *req = NULL;
4043 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4044 int ret = -1;
4045 int i;
4046
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004047 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004048 rsp = ha->rsp_q_map[i];
4049 if (rsp) {
4050 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004051 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004052 if (ret != QLA_SUCCESS)
4053 DEBUG2_17(printk(KERN_WARNING
4054 "%s Rsp que:%d init failed\n", __func__,
4055 rsp->id));
4056 else
4057 DEBUG2_17(printk(KERN_INFO
4058 "%s Rsp que:%d inited\n", __func__,
4059 rsp->id));
4060 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004061 }
4062 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004063 req = ha->req_q_map[i];
4064 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004065 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004066 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004067 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004068 if (ret != QLA_SUCCESS)
4069 DEBUG2_17(printk(KERN_WARNING
4070 "%s Req que:%d init failed\n", __func__,
4071 req->id));
4072 else
4073 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004074 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004075 req->id));
4076 }
4077 }
4078 return ret;
4079}
4080
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081/*
4082* qla2x00_reset_adapter
4083* Reset adapter.
4084*
4085* Input:
4086* ha = adapter block pointer.
4087*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004088void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004089qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090{
4091 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004092 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004093 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004094
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004095 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004096 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004097
Linus Torvalds1da177e2005-04-16 15:20:36 -07004098 spin_lock_irqsave(&ha->hardware_lock, flags);
4099 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4100 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4101 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4102 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4103 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4104}
Andrew Vasquez01071092005-07-06 10:31:37 -07004105
4106void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004107qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07004108{
4109 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004110 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07004111 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4112
Giridhar Malavalia9083012010-04-12 17:59:55 -07004113 if (IS_QLA82XX(ha))
4114 return;
4115
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004116 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004117 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07004118
4119 spin_lock_irqsave(&ha->hardware_lock, flags);
4120 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4121 RD_REG_DWORD(&reg->hccr);
4122 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4123 RD_REG_DWORD(&reg->hccr);
4124 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004125
4126 if (IS_NOPOLLING_TYPE(ha))
4127 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07004128}
4129
David Miller4e08df32007-04-16 12:37:43 -07004130/* On sparc systems, obtain port and node WWN from firmware
4131 * properties.
4132 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4134 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004135{
4136#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004138 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004139 struct device_node *dp = pci_device_to_OF_node(pdev);
4140 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004141 int len;
4142
4143 val = of_get_property(dp, "port-wwn", &len);
4144 if (val && len >= WWN_SIZE)
4145 memcpy(nv->port_name, val, WWN_SIZE);
4146
4147 val = of_get_property(dp, "node-wwn", &len);
4148 if (val && len >= WWN_SIZE)
4149 memcpy(nv->node_name, val, WWN_SIZE);
4150#endif
4151}
4152
Andrew Vasquez01071092005-07-06 10:31:37 -07004153int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07004155{
David Miller4e08df32007-04-16 12:37:43 -07004156 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07004157 struct init_cb_24xx *icb;
4158 struct nvram_24xx *nv;
4159 uint32_t *dptr;
4160 uint8_t *dptr1, *dptr2;
4161 uint32_t chksum;
4162 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07004164
David Miller4e08df32007-04-16 12:37:43 -07004165 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07004166 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004167 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07004168
4169 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004170 if (ha->flags.port0) {
4171 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4172 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4173 } else {
Andrew Vasquez01071092005-07-06 10:31:37 -07004174 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004175 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4176 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004177 ha->nvram_size = sizeof(struct nvram_24xx);
4178 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004179 if (IS_QLA82XX(ha))
4180 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez01071092005-07-06 10:31:37 -07004181
Seokmann Ju281afe12007-07-26 13:43:34 -07004182 /* Get VPD data into cache */
4183 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004184 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004185 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4186
4187 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07004188 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004189 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07004190 ha->nvram_size);
4191 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4192 chksum += le32_to_cpu(*dptr++);
4193
Andrew Vasquez76403352009-04-06 22:33:39 -07004194 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004195 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07004196
4197 /* Bad NVRAM data, set defaults parameters. */
4198 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4199 || nv->id[3] != ' ' ||
4200 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4201 /* Reset NVRAM data. */
4202 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4203 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4204 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004205 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4206 "invalid -- WWPN) defaults.\n");
4207
4208 /*
4209 * Set default initialization control block.
4210 */
4211 memset(nv, 0, ha->nvram_size);
4212 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4213 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4214 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4215 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4216 nv->exchange_count = __constant_cpu_to_le16(0);
4217 nv->hard_address = __constant_cpu_to_le16(124);
4218 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004219 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004220 nv->port_name[2] = 0x00;
4221 nv->port_name[3] = 0xe0;
4222 nv->port_name[4] = 0x8b;
4223 nv->port_name[5] = 0x1c;
4224 nv->port_name[6] = 0x55;
4225 nv->port_name[7] = 0x86;
4226 nv->node_name[0] = 0x20;
4227 nv->node_name[1] = 0x00;
4228 nv->node_name[2] = 0x00;
4229 nv->node_name[3] = 0xe0;
4230 nv->node_name[4] = 0x8b;
4231 nv->node_name[5] = 0x1c;
4232 nv->node_name[6] = 0x55;
4233 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004234 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004235 nv->login_retry_count = __constant_cpu_to_le16(8);
4236 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4237 nv->login_timeout = __constant_cpu_to_le16(0);
4238 nv->firmware_options_1 =
4239 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4240 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4241 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4242 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4243 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4244 nv->efi_parameters = __constant_cpu_to_le32(0);
4245 nv->reset_delay = 5;
4246 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4247 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4248 nv->link_down_timeout = __constant_cpu_to_le16(30);
4249
4250 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07004251 }
4252
4253 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004254 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07004255
4256 /* Copy 1st segment. */
4257 dptr1 = (uint8_t *)icb;
4258 dptr2 = (uint8_t *)&nv->version;
4259 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4260 while (cnt--)
4261 *dptr1++ = *dptr2++;
4262
4263 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004264 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07004265
4266 /* Copy 2nd segment. */
4267 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4268 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4269 cnt = (uint8_t *)&icb->reserved_3 -
4270 (uint8_t *)&icb->interrupt_delay_timer;
4271 while (cnt--)
4272 *dptr1++ = *dptr2++;
4273
4274 /*
4275 * Setup driver NVRAM options.
4276 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004277 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004278 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07004279
Andrew Vasquez5341e862006-05-17 15:09:16 -07004280 /* Use alternate WWN? */
4281 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4282 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4283 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4284 }
4285
Andrew Vasquez01071092005-07-06 10:31:37 -07004286 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004287 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004288 /*
4289 * Firmware will apply the following mask if the nodename was
4290 * not provided.
4291 */
4292 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4293 icb->node_name[0] &= 0xF0;
4294 }
4295
4296 /* Set host adapter parameters. */
4297 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004298 ha->flags.enable_lip_reset = 0;
4299 ha->flags.enable_lip_full_login =
4300 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4301 ha->flags.enable_target_reset =
4302 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07004303 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004304 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07004305
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004306 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4307 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07004308
4309 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4310 sizeof(ha->fw_seriallink_options24));
4311
4312 /* save HBA serial number */
4313 ha->serial0 = icb->port_name[5];
4314 ha->serial1 = icb->port_name[6];
4315 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004316 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4317 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez01071092005-07-06 10:31:37 -07004318
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004319 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4320
Andrew Vasquez01071092005-07-06 10:31:37 -07004321 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4322
4323 /* Set minimum login_timeout to 4 seconds. */
4324 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4325 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4326 if (le16_to_cpu(nv->login_timeout) < 4)
4327 nv->login_timeout = __constant_cpu_to_le16(4);
4328 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004329 icb->login_timeout = nv->login_timeout;
Andrew Vasquez01071092005-07-06 10:31:37 -07004330
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004331 /* Set minimum RATOV to 100 tenths of a second. */
4332 ha->r_a_tov = 100;
Andrew Vasquez01071092005-07-06 10:31:37 -07004333
4334 ha->loop_reset_delay = nv->reset_delay;
4335
4336 /* Link Down Timeout = 0:
4337 *
4338 * When Port Down timer expires we will start returning
4339 * I/O's to OS with "DID_NO_CONNECT".
4340 *
4341 * Link Down Timeout != 0:
4342 *
4343 * The driver waits for the link to come up after link down
4344 * before returning I/Os to OS with "DID_NO_CONNECT".
4345 */
4346 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4347 ha->loop_down_abort_time =
4348 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4349 } else {
4350 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4351 ha->loop_down_abort_time =
4352 (LOOP_DOWN_TIME - ha->link_down_timeout);
4353 }
4354
4355 /* Need enough time to try and get the port back. */
4356 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4357 if (qlport_down_retry)
4358 ha->port_down_retry_count = qlport_down_retry;
4359
4360 /* Set login_retry_count */
4361 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4362 if (ha->port_down_retry_count ==
4363 le16_to_cpu(nv->port_down_retry_count) &&
4364 ha->port_down_retry_count > 3)
4365 ha->login_retry_count = ha->port_down_retry_count;
4366 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4367 ha->login_retry_count = ha->port_down_retry_count;
4368 if (ql2xloginretrycount)
4369 ha->login_retry_count = ql2xloginretrycount;
4370
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004371 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004372 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004373 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4374 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4375 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4376 le16_to_cpu(icb->interrupt_delay_timer): 2;
4377 }
4378 icb->firmware_options_2 &= __constant_cpu_to_le32(
4379 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004380 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004381 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004382 ha->zio_mode = QLA_ZIO_MODE_6;
4383
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004384 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004385 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004386 ha->zio_timer * 100));
4387 qla_printk(KERN_INFO, ha,
4388 "ZIO mode %d enabled; timer delay (%d us).\n",
4389 ha->zio_mode, ha->zio_timer * 100);
4390
4391 icb->firmware_options_2 |= cpu_to_le32(
4392 (uint32_t)ha->zio_mode);
4393 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004394 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004395 }
4396
David Miller4e08df32007-04-16 12:37:43 -07004397 if (rval) {
4398 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004399 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004400 }
4401 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07004402}
4403
Adrian Bunk413975a2006-06-30 02:33:06 -07004404static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004405qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4406 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004407{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004408 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004409 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004410 uint32_t *dcode, dlen;
4411 uint32_t risc_addr;
4412 uint32_t risc_size;
4413 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004414 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004415 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004416
4417 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004418 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004419
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004420 rval = QLA_SUCCESS;
4421
4422 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004423 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004424 *srisc_addr = 0;
4425
4426 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004427 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004428 for (i = 0; i < 4; i++)
4429 dcode[i] = be32_to_cpu(dcode[i]);
4430 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4431 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4432 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4433 dcode[3] == 0)) {
4434 qla_printk(KERN_WARNING, ha,
4435 "Unable to verify integrity of flash firmware image!\n");
4436 qla_printk(KERN_WARNING, ha,
4437 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4438 dcode[1], dcode[2], dcode[3]);
4439
4440 return QLA_FUNCTION_FAILED;
4441 }
4442
4443 while (segments && rval == QLA_SUCCESS) {
4444 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004445 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004446
4447 risc_addr = be32_to_cpu(dcode[2]);
4448 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4449 risc_size = be32_to_cpu(dcode[3]);
4450
4451 fragment = 0;
4452 while (risc_size > 0 && rval == QLA_SUCCESS) {
4453 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4454 if (dlen > risc_size)
4455 dlen = risc_size;
4456
4457 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4458 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004459 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004461 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004462 for (i = 0; i < dlen; i++)
4463 dcode[i] = swab32(dcode[i]);
4464
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004465 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004466 dlen);
4467 if (rval) {
4468 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004469 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004470 fragment));
4471 qla_printk(KERN_WARNING, ha,
4472 "[ERROR] Failed to load segment %d of "
4473 "firmware\n", fragment);
4474 break;
4475 }
4476
4477 faddr += dlen;
4478 risc_addr += dlen;
4479 risc_size -= dlen;
4480 fragment++;
4481 }
4482
4483 /* Next segment. */
4484 segments--;
4485 }
4486
4487 return rval;
4488}
4489
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004490#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4491
Andrew Vasquez01071092005-07-06 10:31:37 -07004492int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004493qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004494{
4495 int rval;
4496 int i, fragment;
4497 uint16_t *wcode, *fwcode;
4498 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4499 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004500 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004501 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004502
4503 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004504 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004505 if (!blob) {
4506 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004507 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4508 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004509 return QLA_FUNCTION_FAILED;
4510 }
4511
4512 rval = QLA_SUCCESS;
4513
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004514 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004515 *srisc_addr = 0;
4516 fwcode = (uint16_t *)blob->fw->data;
4517 fwclen = 0;
4518
4519 /* Validate firmware image by checking version. */
4520 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4521 qla_printk(KERN_WARNING, ha,
4522 "Unable to verify integrity of firmware image (%Zd)!\n",
4523 blob->fw->size);
4524 goto fail_fw_integrity;
4525 }
4526 for (i = 0; i < 4; i++)
4527 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4528 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4529 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4530 wcode[2] == 0 && wcode[3] == 0)) {
4531 qla_printk(KERN_WARNING, ha,
4532 "Unable to verify integrity of firmware image!\n");
4533 qla_printk(KERN_WARNING, ha,
4534 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4535 wcode[1], wcode[2], wcode[3]);
4536 goto fail_fw_integrity;
4537 }
4538
4539 seg = blob->segs;
4540 while (*seg && rval == QLA_SUCCESS) {
4541 risc_addr = *seg;
4542 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4543 risc_size = be16_to_cpu(fwcode[3]);
4544
4545 /* Validate firmware image size. */
4546 fwclen += risc_size * sizeof(uint16_t);
4547 if (blob->fw->size < fwclen) {
4548 qla_printk(KERN_WARNING, ha,
4549 "Unable to verify integrity of firmware image "
4550 "(%Zd)!\n", blob->fw->size);
4551 goto fail_fw_integrity;
4552 }
4553
4554 fragment = 0;
4555 while (risc_size > 0 && rval == QLA_SUCCESS) {
4556 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4557 if (wlen > risc_size)
4558 wlen = risc_size;
4559
4560 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004561 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004562 risc_addr, wlen));
4563
4564 for (i = 0; i < wlen; i++)
4565 wcode[i] = swab16(fwcode[i]);
4566
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004567 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004568 wlen);
4569 if (rval) {
4570 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004571 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004572 fragment));
4573 qla_printk(KERN_WARNING, ha,
4574 "[ERROR] Failed to load segment %d of "
4575 "firmware\n", fragment);
4576 break;
4577 }
4578
4579 fwcode += wlen;
4580 risc_addr += wlen;
4581 risc_size -= wlen;
4582 fragment++;
4583 }
4584
4585 /* Next segment. */
4586 seg++;
4587 }
4588 return rval;
4589
4590fail_fw_integrity:
4591 return QLA_FUNCTION_FAILED;
4592}
4593
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004594static int
4595qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez01071092005-07-06 10:31:37 -07004596{
4597 int rval;
4598 int segments, fragment;
4599 uint32_t *dcode, dlen;
4600 uint32_t risc_addr;
4601 uint32_t risc_size;
4602 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004603 struct fw_blob *blob;
Andrew Vasquez01071092005-07-06 10:31:37 -07004604 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004605 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004606 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07004607
Andrew Vasquez54333832005-11-09 15:49:04 -08004608 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004609 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004610 if (!blob) {
4611 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004612 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4613 "from: " QLA_FW_URL ".\n");
4614
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004615 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004616 }
4617
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004618 qla_printk(KERN_INFO, ha,
4619 "FW: Loading via request-firmware...\n");
4620
Andrew Vasquez01071092005-07-06 10:31:37 -07004621 rval = QLA_SUCCESS;
4622
4623 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004624 dcode = (uint32_t *)req->ring;
Andrew Vasquez01071092005-07-06 10:31:37 -07004625 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004626 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez01071092005-07-06 10:31:37 -07004627 fwclen = 0;
4628
4629 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004630 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004631 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004632 "Unable to verify integrity of firmware image (%Zd)!\n",
4633 blob->fw->size);
Andrew Vasquez01071092005-07-06 10:31:37 -07004634 goto fail_fw_integrity;
4635 }
4636 for (i = 0; i < 4; i++)
4637 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4638 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4639 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4640 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4641 dcode[3] == 0)) {
4642 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004643 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez01071092005-07-06 10:31:37 -07004644 qla_printk(KERN_WARNING, ha,
4645 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4646 dcode[1], dcode[2], dcode[3]);
4647 goto fail_fw_integrity;
4648 }
4649
4650 while (segments && rval == QLA_SUCCESS) {
4651 risc_addr = be32_to_cpu(fwcode[2]);
4652 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4653 risc_size = be32_to_cpu(fwcode[3]);
4654
4655 /* Validate firmware image size. */
4656 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004657 if (blob->fw->size < fwclen) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004658 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004659 "Unable to verify integrity of firmware image "
4660 "(%Zd)!\n", blob->fw->size);
4661
Andrew Vasquez01071092005-07-06 10:31:37 -07004662 goto fail_fw_integrity;
4663 }
4664
4665 fragment = 0;
4666 while (risc_size > 0 && rval == QLA_SUCCESS) {
4667 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4668 if (dlen > risc_size)
4669 dlen = risc_size;
4670
4671 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004672 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004673 risc_addr, dlen));
4674
4675 for (i = 0; i < dlen; i++)
4676 dcode[i] = swab32(fwcode[i]);
4677
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004678 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004679 dlen);
Andrew Vasquez01071092005-07-06 10:31:37 -07004680 if (rval) {
4681 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004682 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004683 fragment));
4684 qla_printk(KERN_WARNING, ha,
4685 "[ERROR] Failed to load segment %d of "
4686 "firmware\n", fragment);
4687 break;
4688 }
4689
4690 fwcode += dlen;
4691 risc_addr += dlen;
4692 risc_size -= dlen;
4693 fragment++;
4694 }
4695
4696 /* Next segment. */
4697 segments--;
4698 }
Andrew Vasquez01071092005-07-06 10:31:37 -07004699 return rval;
4700
4701fail_fw_integrity:
Andrew Vasquez01071092005-07-06 10:31:37 -07004702 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004703}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004704
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004705int
4706qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4707{
4708 int rval;
4709
Andrew Vasqueze337d902009-04-06 22:33:49 -07004710 if (ql2xfwloadbin == 1)
4711 return qla81xx_load_risc(vha, srisc_addr);
4712
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004713 /*
4714 * FW Load priority:
4715 * 1) Firmware via request-firmware interface (.bin file).
4716 * 2) Firmware residing in flash.
4717 */
4718 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4719 if (rval == QLA_SUCCESS)
4720 return rval;
4721
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004722 return qla24xx_load_risc_flash(vha, srisc_addr,
4723 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004724}
4725
4726int
4727qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4728{
4729 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004730 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004731
Andrew Vasqueze337d902009-04-06 22:33:49 -07004732 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004733 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004734
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004735 /*
4736 * FW Load priority:
4737 * 1) Firmware residing in flash.
4738 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004739 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004740 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004741 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004742 if (rval == QLA_SUCCESS)
4743 return rval;
4744
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004745try_blob_fw:
4746 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4747 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4748 return rval;
4749
4750 qla_printk(KERN_ERR, ha,
4751 "FW: Attempting to fallback to golden firmware...\n");
4752 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4753 if (rval != QLA_SUCCESS)
4754 return rval;
4755
4756 qla_printk(KERN_ERR, ha,
4757 "FW: Please update operational firmware...\n");
4758 ha->flags.running_gold_fw = 1;
4759
4760 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004761}
4762
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004763void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004764qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004765{
4766 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004767 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004768
Andrew Vasquez85880802009-12-15 21:29:46 -08004769 if (ha->flags.pci_channel_io_perm_failure)
4770 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004771 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004772 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004773 if (!ha->fw_major_version)
4774 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004775
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004776 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004777 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004778 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004779 ha->isp_ops->reset_chip(vha);
4780 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004781 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004782 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004783 continue;
4784 qla_printk(KERN_INFO, ha,
4785 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004786 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004787 }
4788}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004789
4790int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004791qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004792{
4793 int rval = QLA_SUCCESS;
4794 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004795 struct qla_hw_data *ha = vha->hw;
4796 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004797 struct req_que *req;
4798 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004800 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004801 return -EINVAL;
4802
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004803 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004804 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004805 req = ha->req_q_map[0];
4806 else
4807 req = vha->req;
4808 rsp = req->rsp;
4809
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004810 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004811 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004812 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004813 }
4814
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004815 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004816
4817 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004818 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004819 if (mb[0] != MBS_COMMAND_COMPLETE) {
4820 DEBUG15(qla_printk(KERN_INFO, ha,
4821 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4822 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4823 mb[0], mb[1], mb[2], mb[6], mb[7]));
4824 return (QLA_FUNCTION_FAILED);
4825 }
4826
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004827 atomic_set(&vha->loop_down_timer, 0);
4828 atomic_set(&vha->loop_state, LOOP_UP);
4829 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4830 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4831 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004832
4833 return rval;
4834}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004835
4836/* 84XX Support **************************************************************/
4837
4838static LIST_HEAD(qla_cs84xx_list);
4839static DEFINE_MUTEX(qla_cs84xx_mutex);
4840
4841static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004842qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004843{
4844 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004845 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004846
4847 mutex_lock(&qla_cs84xx_mutex);
4848
4849 /* Find any shared 84xx chip. */
4850 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4851 if (cs84xx->bus == ha->pdev->bus) {
4852 kref_get(&cs84xx->kref);
4853 goto done;
4854 }
4855 }
4856
4857 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4858 if (!cs84xx)
4859 goto done;
4860
4861 kref_init(&cs84xx->kref);
4862 spin_lock_init(&cs84xx->access_lock);
4863 mutex_init(&cs84xx->fw_update_mutex);
4864 cs84xx->bus = ha->pdev->bus;
4865
4866 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4867done:
4868 mutex_unlock(&qla_cs84xx_mutex);
4869 return cs84xx;
4870}
4871
4872static void
4873__qla84xx_chip_release(struct kref *kref)
4874{
4875 struct qla_chip_state_84xx *cs84xx =
4876 container_of(kref, struct qla_chip_state_84xx, kref);
4877
4878 mutex_lock(&qla_cs84xx_mutex);
4879 list_del(&cs84xx->list);
4880 mutex_unlock(&qla_cs84xx_mutex);
4881 kfree(cs84xx);
4882}
4883
4884void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004885qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004886{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004887 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004888 if (ha->cs84xx)
4889 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4890}
4891
4892static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004893qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004894{
4895 int rval;
4896 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004897 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004898
4899 mutex_lock(&ha->cs84xx->fw_update_mutex);
4900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004901 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004902
4903 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4904
4905 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4906 QLA_SUCCESS;
4907}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004908
4909/* 81XX Support **************************************************************/
4910
4911int
4912qla81xx_nvram_config(scsi_qla_host_t *vha)
4913{
4914 int rval;
4915 struct init_cb_81xx *icb;
4916 struct nvram_81xx *nv;
4917 uint32_t *dptr;
4918 uint8_t *dptr1, *dptr2;
4919 uint32_t chksum;
4920 uint16_t cnt;
4921 struct qla_hw_data *ha = vha->hw;
4922
4923 rval = QLA_SUCCESS;
4924 icb = (struct init_cb_81xx *)ha->init_cb;
4925 nv = ha->nvram;
4926
4927 /* Determine NVRAM starting address. */
4928 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004929 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004930
4931 /* Get VPD data into cache */
4932 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d790382009-03-24 09:08:14 -07004933 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4934 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004935
4936 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d790382009-03-24 09:08:14 -07004937 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004938 ha->nvram_size);
Andrew Vasquez3d790382009-03-24 09:08:14 -07004939 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004940 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4941 chksum += le32_to_cpu(*dptr++);
4942
Andrew Vasquez76403352009-04-06 22:33:39 -07004943 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004944 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4945
4946 /* Bad NVRAM data, set defaults parameters. */
4947 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4948 || nv->id[3] != ' ' ||
4949 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4950 /* Reset NVRAM data. */
4951 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4952 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4953 le16_to_cpu(nv->nvram_version));
4954 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4955 "invalid -- WWPN) defaults.\n");
4956
4957 /*
4958 * Set default initialization control block.
4959 */
4960 memset(nv, 0, ha->nvram_size);
4961 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4962 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4963 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4964 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4965 nv->exchange_count = __constant_cpu_to_le16(0);
4966 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004967 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004968 nv->port_name[2] = 0x00;
4969 nv->port_name[3] = 0xe0;
4970 nv->port_name[4] = 0x8b;
4971 nv->port_name[5] = 0x1c;
4972 nv->port_name[6] = 0x55;
4973 nv->port_name[7] = 0x86;
4974 nv->node_name[0] = 0x20;
4975 nv->node_name[1] = 0x00;
4976 nv->node_name[2] = 0x00;
4977 nv->node_name[3] = 0xe0;
4978 nv->node_name[4] = 0x8b;
4979 nv->node_name[5] = 0x1c;
4980 nv->node_name[6] = 0x55;
4981 nv->node_name[7] = 0x86;
4982 nv->login_retry_count = __constant_cpu_to_le16(8);
4983 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4984 nv->login_timeout = __constant_cpu_to_le16(0);
4985 nv->firmware_options_1 =
4986 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4987 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4988 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4989 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4990 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4991 nv->efi_parameters = __constant_cpu_to_le32(0);
4992 nv->reset_delay = 5;
4993 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4994 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4995 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004996 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004997 nv->enode_mac[1] = 0x02;
4998 nv->enode_mac[2] = 0x03;
4999 nv->enode_mac[3] = 0x04;
5000 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005001 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005002
5003 rval = 1;
5004 }
5005
5006 /* Reset Initialization control block */
5007 memset(icb, 0, sizeof(struct init_cb_81xx));
5008
5009 /* Copy 1st segment. */
5010 dptr1 = (uint8_t *)icb;
5011 dptr2 = (uint8_t *)&nv->version;
5012 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5013 while (cnt--)
5014 *dptr1++ = *dptr2++;
5015
5016 icb->login_retry_count = nv->login_retry_count;
5017
5018 /* Copy 2nd segment. */
5019 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5020 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5021 cnt = (uint8_t *)&icb->reserved_5 -
5022 (uint8_t *)&icb->interrupt_delay_timer;
5023 while (cnt--)
5024 *dptr1++ = *dptr2++;
5025
5026 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5027 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5028 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5029 icb->enode_mac[0] = 0x01;
5030 icb->enode_mac[1] = 0x02;
5031 icb->enode_mac[2] = 0x03;
5032 icb->enode_mac[3] = 0x04;
5033 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005034 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005035 }
5036
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005037 /* Use extended-initialization control block. */
5038 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5039
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005040 /*
5041 * Setup driver NVRAM options.
5042 */
5043 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005044 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005045
5046 /* Use alternate WWN? */
5047 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5048 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5049 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5050 }
5051
5052 /* Prepare nodename */
5053 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5054 /*
5055 * Firmware will apply the following mask if the nodename was
5056 * not provided.
5057 */
5058 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5059 icb->node_name[0] &= 0xF0;
5060 }
5061
5062 /* Set host adapter parameters. */
5063 ha->flags.disable_risc_code_load = 0;
5064 ha->flags.enable_lip_reset = 0;
5065 ha->flags.enable_lip_full_login =
5066 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5067 ha->flags.enable_target_reset =
5068 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5069 ha->flags.enable_led_scheme = 0;
5070 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5071
5072 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5073 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5074
5075 /* save HBA serial number */
5076 ha->serial0 = icb->port_name[5];
5077 ha->serial1 = icb->port_name[6];
5078 ha->serial2 = icb->port_name[7];
5079 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5080 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5081
5082 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5083
5084 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5085
5086 /* Set minimum login_timeout to 4 seconds. */
5087 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5088 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5089 if (le16_to_cpu(nv->login_timeout) < 4)
5090 nv->login_timeout = __constant_cpu_to_le16(4);
5091 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5092 icb->login_timeout = nv->login_timeout;
5093
5094 /* Set minimum RATOV to 100 tenths of a second. */
5095 ha->r_a_tov = 100;
5096
5097 ha->loop_reset_delay = nv->reset_delay;
5098
5099 /* Link Down Timeout = 0:
5100 *
5101 * When Port Down timer expires we will start returning
5102 * I/O's to OS with "DID_NO_CONNECT".
5103 *
5104 * Link Down Timeout != 0:
5105 *
5106 * The driver waits for the link to come up after link down
5107 * before returning I/Os to OS with "DID_NO_CONNECT".
5108 */
5109 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5110 ha->loop_down_abort_time =
5111 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5112 } else {
5113 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5114 ha->loop_down_abort_time =
5115 (LOOP_DOWN_TIME - ha->link_down_timeout);
5116 }
5117
5118 /* Need enough time to try and get the port back. */
5119 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5120 if (qlport_down_retry)
5121 ha->port_down_retry_count = qlport_down_retry;
5122
5123 /* Set login_retry_count */
5124 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5125 if (ha->port_down_retry_count ==
5126 le16_to_cpu(nv->port_down_retry_count) &&
5127 ha->port_down_retry_count > 3)
5128 ha->login_retry_count = ha->port_down_retry_count;
5129 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5130 ha->login_retry_count = ha->port_down_retry_count;
5131 if (ql2xloginretrycount)
5132 ha->login_retry_count = ql2xloginretrycount;
5133
5134 /* Enable ZIO. */
5135 if (!vha->flags.init_done) {
5136 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5137 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5138 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5139 le16_to_cpu(icb->interrupt_delay_timer): 2;
5140 }
5141 icb->firmware_options_2 &= __constant_cpu_to_le32(
5142 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5143 vha->flags.process_response_queue = 0;
5144 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5145 ha->zio_mode = QLA_ZIO_MODE_6;
5146
5147 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5148 "(%d us).\n", vha->host_no, ha->zio_mode,
5149 ha->zio_timer * 100));
5150 qla_printk(KERN_INFO, ha,
5151 "ZIO mode %d enabled; timer delay (%d us).\n",
5152 ha->zio_mode, ha->zio_timer * 100);
5153
5154 icb->firmware_options_2 |= cpu_to_le32(
5155 (uint32_t)ha->zio_mode);
5156 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5157 vha->flags.process_response_queue = 1;
5158 }
5159
5160 if (rval) {
5161 DEBUG2_3(printk(KERN_WARNING
5162 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5163 }
5164 return (rval);
5165}
5166
Giridhar Malavalia9083012010-04-12 17:59:55 -07005167int
5168qla82xx_restart_isp(scsi_qla_host_t *vha)
5169{
5170 int status, rval;
5171 uint32_t wait_time;
5172 struct qla_hw_data *ha = vha->hw;
5173 struct req_que *req = ha->req_q_map[0];
5174 struct rsp_que *rsp = ha->rsp_q_map[0];
5175 struct scsi_qla_host *vp;
5176 struct scsi_qla_host *tvp;
5177
5178 status = qla2x00_init_rings(vha);
5179 if (!status) {
5180 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5181 ha->flags.chip_reset_done = 1;
5182
5183 status = qla2x00_fw_ready(vha);
5184 if (!status) {
5185 qla_printk(KERN_INFO, ha,
5186 "%s(): Start configure loop, "
5187 "status = %d\n", __func__, status);
5188
5189 /* Issue a marker after FW becomes ready. */
5190 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5191
5192 vha->flags.online = 1;
5193 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5194 wait_time = 256;
5195 do {
5196 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5197 qla2x00_configure_loop(vha);
5198 wait_time--;
5199 } while (!atomic_read(&vha->loop_down_timer) &&
5200 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5201 wait_time &&
5202 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5203 }
5204
5205 /* if no cable then assume it's good */
5206 if ((vha->device_flags & DFLG_NO_CABLE))
5207 status = 0;
5208
5209 qla_printk(KERN_INFO, ha,
5210 "%s(): Configure loop done, status = 0x%x\n",
5211 __func__, status);
5212 }
5213
5214 if (!status) {
5215 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5216
5217 if (!atomic_read(&vha->loop_down_timer)) {
5218 /*
5219 * Issue marker command only when we are going
5220 * to start the I/O .
5221 */
5222 vha->marker_needed = 1;
5223 }
5224
5225 vha->flags.online = 1;
5226
5227 ha->isp_ops->enable_intrs(ha);
5228
5229 ha->isp_abort_cnt = 0;
5230 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5231
5232 if (ha->fce) {
5233 ha->flags.fce_enabled = 1;
5234 memset(ha->fce, 0,
5235 fce_calc_size(ha->fce_bufs));
5236 rval = qla2x00_enable_fce_trace(vha,
5237 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5238 &ha->fce_bufs);
5239 if (rval) {
5240 qla_printk(KERN_WARNING, ha,
5241 "Unable to reinitialize FCE "
5242 "(%d).\n", rval);
5243 ha->flags.fce_enabled = 0;
5244 }
5245 }
5246
5247 if (ha->eft) {
5248 memset(ha->eft, 0, EFT_SIZE);
5249 rval = qla2x00_enable_eft_trace(vha,
5250 ha->eft_dma, EFT_NUM_BUFFERS);
5251 if (rval) {
5252 qla_printk(KERN_WARNING, ha,
5253 "Unable to reinitialize EFT "
5254 "(%d).\n", rval);
5255 }
5256 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005257 }
5258
5259 if (!status) {
5260 DEBUG(printk(KERN_INFO
5261 "qla82xx_restart_isp(%ld): succeeded.\n",
5262 vha->host_no));
5263 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5264 if (vp->vp_idx)
5265 qla2x00_vp_abort_isp(vp);
5266 }
5267 } else {
5268 qla_printk(KERN_INFO, ha,
5269 "qla82xx_restart_isp: **** FAILED ****\n");
5270 }
5271
5272 return status;
5273}
5274
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005275void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005276qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005277{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005278 struct qla_hw_data *ha = vha->hw;
5279
5280 if (!ql2xetsenable)
5281 return;
5282
5283 /* Enable ETS Burst. */
5284 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5285 ha->fw_options[2] |= BIT_9;
5286 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005287}
Sarang Radke09ff7012010-03-19 17:03:59 -07005288
5289/*
5290 * qla24xx_get_fcp_prio
5291 * Gets the fcp cmd priority value for the logged in port.
5292 * Looks for a match of the port descriptors within
5293 * each of the fcp prio config entries. If a match is found,
5294 * the tag (priority) value is returned.
5295 *
5296 * Input:
5297 * ha = adapter block po
5298 * fcport = port structure pointer.
5299 *
5300 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005301 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005302 * 0 (if not found)
5303 *
5304 * Context:
5305 * Kernel context
5306 */
5307uint8_t
5308qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5309{
5310 int i, entries;
5311 uint8_t pid_match, wwn_match;
5312 uint8_t priority;
5313 uint32_t pid1, pid2;
5314 uint64_t wwn1, wwn2;
5315 struct qla_fcp_prio_entry *pri_entry;
5316 struct qla_hw_data *ha = vha->hw;
5317
5318 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5319 return 0;
5320
5321 priority = 0;
5322 entries = ha->fcp_prio_cfg->num_entries;
5323 pri_entry = &ha->fcp_prio_cfg->entry[0];
5324
5325 for (i = 0; i < entries; i++) {
5326 pid_match = wwn_match = 0;
5327
5328 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5329 pri_entry++;
5330 continue;
5331 }
5332
5333 /* check source pid for a match */
5334 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5335 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5336 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5337 if (pid1 == INVALID_PORT_ID)
5338 pid_match++;
5339 else if (pid1 == pid2)
5340 pid_match++;
5341 }
5342
5343 /* check destination pid for a match */
5344 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5345 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5346 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5347 if (pid1 == INVALID_PORT_ID)
5348 pid_match++;
5349 else if (pid1 == pid2)
5350 pid_match++;
5351 }
5352
5353 /* check source WWN for a match */
5354 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5355 wwn1 = wwn_to_u64(vha->port_name);
5356 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5357 if (wwn2 == (uint64_t)-1)
5358 wwn_match++;
5359 else if (wwn1 == wwn2)
5360 wwn_match++;
5361 }
5362
5363 /* check destination WWN for a match */
5364 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5365 wwn1 = wwn_to_u64(fcport->port_name);
5366 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5367 if (wwn2 == (uint64_t)-1)
5368 wwn_match++;
5369 else if (wwn1 == wwn2)
5370 wwn_match++;
5371 }
5372
5373 if (pid_match == 2 || wwn_match == 2) {
5374 /* Found a matching entry */
5375 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5376 priority = pri_entry->tag;
5377 break;
5378 }
5379
5380 pri_entry++;
5381 }
5382
5383 return priority;
5384}
5385
5386/*
5387 * qla24xx_update_fcport_fcp_prio
5388 * Activates fcp priority for the logged in fc port
5389 *
5390 * Input:
5391 * ha = adapter block pointer.
5392 * fcp = port structure pointer.
5393 *
5394 * Return:
5395 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5396 *
5397 * Context:
5398 * Kernel context.
5399 */
5400int
5401qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5402{
5403 int ret;
5404 uint8_t priority;
5405 uint16_t mb[5];
5406
5407 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5408 fcport->port_type != FCT_TARGET ||
5409 fcport->loop_id == FC_NO_LOOP_ID)
5410 return QLA_FUNCTION_FAILED;
5411
5412 priority = qla24xx_get_fcp_prio(ha, fcport);
5413 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5414 if (ret == QLA_SUCCESS)
5415 fcport->fcp_prio = priority;
5416 else
5417 DEBUG2(printk(KERN_WARNING
5418 "scsi(%ld): Unable to activate fcp priority, "
5419 " ret=0x%x\n", ha->host_no, ret));
5420
5421 return ret;
5422}
5423
5424/*
5425 * qla24xx_update_all_fcp_prio
5426 * Activates fcp priority for all the logged in ports
5427 *
5428 * Input:
5429 * ha = adapter block pointer.
5430 *
5431 * Return:
5432 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5433 *
5434 * Context:
5435 * Kernel context.
5436 */
5437int
5438qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5439{
5440 int ret;
5441 fc_port_t *fcport;
5442
5443 ret = QLA_FUNCTION_FAILED;
5444 /* We need to set priority for all logged in ports */
5445 list_for_each_entry(fcport, &vha->vp_fcports, list)
5446 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5447
5448 return ret;
5449}