blob: 7fd1344ff1f9b705410016a42f07fbfa080686fb [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 Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21* QLogic ISP2x00 Hardware Support Function Prototypes.
22*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Andrew Vasquezac280b62009-08-20 11:06:05 -070044/* SRB Extensions ---------------------------------------------------------- */
45
46static void
47qla2x00_ctx_sp_timeout(unsigned long __data)
48{
49 srb_t *sp = (srb_t *)__data;
50 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070051 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070052 fc_port_t *fcport = sp->fcport;
53 struct qla_hw_data *ha = fcport->vha->hw;
54 struct req_que *req;
55 unsigned long flags;
56
57 spin_lock_irqsave(&ha->hardware_lock, flags);
58 req = ha->req_q_map[0];
59 req->outstanding_cmds[sp->handle] = NULL;
60 ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070061 iocb = ctx->u.iocb_cmd;
62 iocb->timeout(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070063 spin_unlock_irqrestore(&ha->hardware_lock, flags);
64
Madhuranath Iyengar49163922010-05-04 15:01:28 -070065 iocb->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070066}
67
Giridhar Malavali9a069e12010-01-12 13:02:47 -080068void
Andrew Vasquezac280b62009-08-20 11:06:05 -070069qla2x00_ctx_sp_free(srb_t *sp)
70{
71 struct srb_ctx *ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070072 struct srb_iocb *iocb = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070073
Madhuranath Iyengar49163922010-05-04 15:01:28 -070074 del_timer_sync(&iocb->timer);
75 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070076 kfree(ctx);
77 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
78}
79
80inline srb_t *
81qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
82 unsigned long tmo)
83{
84 srb_t *sp;
85 struct qla_hw_data *ha = vha->hw;
86 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070087 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070088
89 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
90 if (!sp)
91 goto done;
92 ctx = kzalloc(size, GFP_KERNEL);
93 if (!ctx) {
94 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070095 sp = NULL;
96 goto done;
97 }
98 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
99 if (!iocb) {
100 mempool_free(sp, ha->srb_mempool);
101 sp = NULL;
102 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700103 goto done;
104 }
105
106 memset(sp, 0, sizeof(*sp));
107 sp->fcport = fcport;
108 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700109 ctx->u.iocb_cmd = iocb;
110 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700111
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700112 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700113 if (!tmo)
114 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700115 iocb->timer.expires = jiffies + tmo * HZ;
116 iocb->timer.data = (unsigned long)sp;
117 iocb->timer.function = qla2x00_ctx_sp_timeout;
118 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700119done:
120 return sp;
121}
122
123/* Asynchronous Login/Logout Routines -------------------------------------- */
124
125#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
126
127static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700128qla2x00_async_iocb_timeout(srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700129{
130 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700131 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700132
133 DEBUG2(printk(KERN_WARNING
134 "scsi(%ld:%x): Async-%s timeout.\n",
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700135 fcport->vha->host_no, sp->handle, ctx->name));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700136
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700137 fcport->flags &= ~FCF_ASYNC_SENT;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700138 if (ctx->type == SRB_LOGIN_CMD)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700139 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
140}
141
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700142static void
143qla2x00_async_login_ctx_done(srb_t *sp)
144{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700145 struct srb_ctx *ctx = sp->ctx;
146 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700147
148 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700149 lio->u.logio.data);
150 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700151}
152
Andrew Vasquezac280b62009-08-20 11:06:05 -0700153int
154qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
155 uint16_t *data)
156{
157 struct qla_hw_data *ha = vha->hw;
158 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700159 struct srb_ctx *ctx;
160 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700161 int rval;
162
163 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700164 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165 ELS_TMO_2_RATOV(ha) + 2);
166 if (!sp)
167 goto done;
168
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700169 ctx = sp->ctx;
170 ctx->type = SRB_LOGIN_CMD;
171 ctx->name = "login";
172 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700173 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700174 lio->done = qla2x00_async_login_ctx_done;
175 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700176 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700177 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700178 rval = qla2x00_start_sp(sp);
179 if (rval != QLA_SUCCESS)
180 goto done_free_sp;
181
182 DEBUG2(printk(KERN_DEBUG
183 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
184 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
185 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
186 fcport->login_retry));
187 return rval;
188
189done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700190 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700191done:
192 return rval;
193}
194
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700195static void
196qla2x00_async_logout_ctx_done(srb_t *sp)
197{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700198 struct srb_ctx *ctx = sp->ctx;
199 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700200
201 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700202 lio->u.logio.data);
203 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700204}
205
Andrew Vasquezac280b62009-08-20 11:06:05 -0700206int
207qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
208{
209 struct qla_hw_data *ha = vha->hw;
210 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700211 struct srb_ctx *ctx;
212 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700213 int rval;
214
215 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700216 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700217 ELS_TMO_2_RATOV(ha) + 2);
218 if (!sp)
219 goto done;
220
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700221 ctx = sp->ctx;
222 ctx->type = SRB_LOGOUT_CMD;
223 ctx->name = "logout";
224 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700225 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700226 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700227 rval = qla2x00_start_sp(sp);
228 if (rval != QLA_SUCCESS)
229 goto done_free_sp;
230
231 DEBUG2(printk(KERN_DEBUG
232 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
233 fcport->vha->host_no, sp->handle, fcport->loop_id,
234 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
235 return rval;
236
237done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700238 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700239done:
240 return rval;
241}
242
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700243static void
244qla2x00_async_adisc_ctx_done(srb_t *sp)
245{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700246 struct srb_ctx *ctx = sp->ctx;
247 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700248
249 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700250 lio->u.logio.data);
251 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700252}
253
254int
255qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
256 uint16_t *data)
257{
258 struct qla_hw_data *ha = vha->hw;
259 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700260 struct srb_ctx *ctx;
261 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700262 int rval;
263
264 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700265 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700266 ELS_TMO_2_RATOV(ha) + 2);
267 if (!sp)
268 goto done;
269
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700270 ctx = sp->ctx;
271 ctx->type = SRB_ADISC_CMD;
272 ctx->name = "adisc";
273 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700274 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700275 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700276 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700277 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700278 rval = qla2x00_start_sp(sp);
279 if (rval != QLA_SUCCESS)
280 goto done_free_sp;
281
282 DEBUG2(printk(KERN_DEBUG
283 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
284 fcport->vha->host_no, sp->handle, fcport->loop_id,
285 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
286
287 return rval;
288
289done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700290 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700291done:
292 return rval;
293}
294
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700295static void
296qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
297{
298 struct srb_ctx *ctx = sp->ctx;
299 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
300
301 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
302 iocb->free(sp);
303}
304
305int
306qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
307 uint32_t tag)
308{
309 struct scsi_qla_host *vha = fcport->vha;
310 struct qla_hw_data *ha = vha->hw;
311 srb_t *sp;
312 struct srb_ctx *ctx;
313 struct srb_iocb *tcf;
314 int rval;
315
316 rval = QLA_FUNCTION_FAILED;
317 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
318 ELS_TMO_2_RATOV(ha) + 2);
319 if (!sp)
320 goto done;
321
322 ctx = sp->ctx;
323 ctx->type = SRB_TM_CMD;
324 ctx->name = "tmf";
325 tcf = ctx->u.iocb_cmd;
326 tcf->u.tmf.flags = flags;
327 tcf->u.tmf.lun = lun;
328 tcf->u.tmf.data = tag;
329 tcf->timeout = qla2x00_async_iocb_timeout;
330 tcf->done = qla2x00_async_tm_cmd_ctx_done;
331
332 rval = qla2x00_start_sp(sp);
333 if (rval != QLA_SUCCESS)
334 goto done_free_sp;
335
336 DEBUG2(printk(KERN_DEBUG
337 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
338 fcport->vha->host_no, sp->handle, fcport->loop_id,
339 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
340
341 return rval;
342
343done_free_sp:
344 tcf->free(sp);
345done:
346 return rval;
347}
348
349static void
350qla2x00_async_marker_ctx_done(srb_t *sp)
351{
352 struct srb_ctx *ctx = sp->ctx;
353 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
354
355 qla2x00_async_marker_done(sp->fcport->vha, sp->fcport, iocb);
356 iocb->free(sp);
357}
358
359int
360qla2x00_async_marker(fc_port_t *fcport, uint16_t lun, uint8_t modif)
361{
362 struct scsi_qla_host *vha = fcport->vha;
363 srb_t *sp;
364 struct srb_ctx *ctx;
365 struct srb_iocb *mrk;
366 int rval;
367
368 rval = QLA_FUNCTION_FAILED;
369 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), 0);
370 if (!sp)
371 goto done;
372
373 ctx = sp->ctx;
374 ctx->type = SRB_MARKER_CMD;
375 ctx->name = "marker";
376 mrk = ctx->u.iocb_cmd;
377 mrk->u.marker.lun = lun;
378 mrk->u.marker.modif = modif;
379 mrk->timeout = qla2x00_async_iocb_timeout;
380 mrk->done = qla2x00_async_marker_ctx_done;
381
382 rval = qla2x00_start_sp(sp);
383 if (rval != QLA_SUCCESS)
384 goto done_free_sp;
385
386 DEBUG2(printk(KERN_DEBUG
387 "scsi(%ld:%x): Async-marker - loop-id=%x "
388 "portid=%02x%02x%02x.\n",
389 fcport->vha->host_no, sp->handle, fcport->loop_id,
390 fcport->d_id.b.domain, fcport->d_id.b.area,
391 fcport->d_id.b.al_pa));
392
393 return rval;
394
395done_free_sp:
396 mrk->free(sp);
397done:
398 return rval;
399}
400
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700401void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700402qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
403 uint16_t *data)
404{
405 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700406
407 switch (data[0]) {
408 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700409 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700410 fcport->flags |= FCF_ASYNC_SENT;
411 qla2x00_post_async_adisc_work(vha, fcport, data);
412 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700413 }
414 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700415 break;
416 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700417 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700418 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
419 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
420 else
421 qla2x00_mark_device_lost(vha, fcport, 1, 0);
422 break;
423 case MBS_PORT_ID_USED:
424 fcport->loop_id = data[1];
425 qla2x00_post_async_login_work(vha, fcport, NULL);
426 break;
427 case MBS_LOOP_ID_USED:
428 fcport->loop_id++;
429 rval = qla2x00_find_new_loop_id(vha, fcport);
430 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700431 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700432 qla2x00_mark_device_lost(vha, fcport, 1, 0);
433 break;
434 }
435 qla2x00_post_async_login_work(vha, fcport, NULL);
436 break;
437 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700438 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700439}
440
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700441void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700442qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
443 uint16_t *data)
444{
445 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700446 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700447}
448
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700449void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700450qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
451 uint16_t *data)
452{
453 if (data[0] == MBS_COMMAND_COMPLETE) {
454 qla2x00_update_fcport(vha, fcport);
455
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700456 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700457 }
458
459 /* Retry login. */
460 fcport->flags &= ~FCF_ASYNC_SENT;
461 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
462 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
463 else
464 qla2x00_mark_device_lost(vha, fcport, 1, 0);
465
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700466 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700467}
468
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700469void
470qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
471 struct srb_iocb *iocb)
472{
473 int rval;
474 uint32_t flags;
475 uint16_t lun;
476
477 flags = iocb->u.tmf.flags;
478 lun = (uint16_t)iocb->u.tmf.lun;
479
480 /* Issue Marker IOCB */
481 rval = qla2x00_async_marker(fcport, lun,
482 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
483
484 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
485 DEBUG2_3_11(printk(KERN_WARNING
486 "%s(%ld): TM IOCB failed (%x).\n",
487 __func__, vha->host_no, rval));
488 }
489
490 return;
491}
492
493void
494qla2x00_async_marker_done(struct scsi_qla_host *vha, fc_port_t *fcport,
495 struct srb_iocb *iocb)
496{
497 /*
498 * Currently we dont have any specific post response processing
499 * for this IOCB. We'll just return success or failed
500 * depending on whether the IOCB command succeeded or failed.
501 */
502 if (iocb->u.tmf.data) {
503 DEBUG2_3_11(printk(KERN_WARNING
504 "%s(%ld): Marker IOCB failed (%x).\n",
505 __func__, vha->host_no, iocb->u.tmf.data));
506 }
507
508 return;
509}
510
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511/****************************************************************************/
512/* QLogic ISP2x00 Hardware Support Functions. */
513/****************************************************************************/
514
515/*
516* qla2x00_initialize_adapter
517* Initialize board.
518*
519* Input:
520* ha = adapter block pointer.
521*
522* Returns:
523* 0 = success
524*/
525int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527{
528 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800529 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800530 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800533 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700534 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800535 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800536 ha->flags.pci_channel_io_perm_failure = 0;
537 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800538 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
539 atomic_set(&vha->loop_state, LOOP_DOWN);
540 vha->device_flags = DFLG_NO_CABLE;
541 vha->dpc_flags = 0;
542 vha->flags.management_server_logged_in = 0;
543 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544 ha->isp_abort_cnt = 0;
545 ha->beacon_blink_led = 0;
546
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800547 set_bit(0, ha->req_qid_map);
548 set_bit(0, ha->rsp_qid_map);
549
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700550 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800551 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800553 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 return (rval);
556 }
557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800558 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800560 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700561 if (rval) {
562 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800563 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700564 return (rval);
565 }
566
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800567 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800568
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700570
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800571 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700573 if (ha->flags.disable_serdes) {
574 /* Mask HBA via NVRAM settings? */
575 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
576 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800577 vha->port_name[0], vha->port_name[1],
578 vha->port_name[2], vha->port_name[3],
579 vha->port_name[4], vha->port_name[5],
580 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700581 return QLA_FUNCTION_FAILED;
582 }
583
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
585
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800586 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
587 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800588 if (rval)
589 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800590 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800591 if (rval)
592 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700594
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700595 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700597 if (!ha->cs84xx) {
598 qla_printk(KERN_ERR, ha,
599 "Unable to configure ISP84XX.\n");
600 return QLA_FUNCTION_FAILED;
601 }
602 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800603 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700604 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800606 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700607 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800608 rval = qla84xx_init_chip(vha);
609 if (rval != QLA_SUCCESS) {
610 qla_printk(KERN_ERR, ha,
611 "Unable to initialize ISP84XX.\n");
612 qla84xx_put_chip(vha);
613 }
614 }
615
Sarang Radke09ff7012010-03-19 17:03:59 -0700616 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
617 if (qla24xx_read_fcp_prio_cfg(vha))
618 qla_printk(KERN_ERR, ha,
619 "Unable to read FCP priority data.\n");
620 }
621
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 return (rval);
623}
624
625/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700626 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 * @ha: HA context
628 *
629 * Returns 0 on success.
630 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700631int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800632qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700634 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700635 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800636 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700637 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700640 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700643 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
645
Andrew Vasquez737faec2008-10-24 15:13:45 -0700646 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700648 /* Get PCI bus information. */
649 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700650 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700651 spin_unlock_irqrestore(&ha->hardware_lock, flags);
652
653 return QLA_SUCCESS;
654}
655
656/**
657 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
658 * @ha: HA context
659 *
660 * Returns 0 on success.
661 */
662int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700664{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700665 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700666 unsigned long flags = 0;
667 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800668 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700669 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700670
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700671 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700672 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700673
674 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700675 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700676
677 if (IS_QLA2322(ha) || IS_QLA6322(ha))
678 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700679 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700680
681 /*
682 * If this is a 2300 card and not 2312, reset the
683 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
684 * the 2310 also reports itself as a 2300 so we need to get the
685 * fb revision level -- a 6 indicates it really is a 2300 and
686 * not a 2310.
687 */
688 if (IS_QLA2300(ha)) {
689 spin_lock_irqsave(&ha->hardware_lock, flags);
690
691 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700692 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700693 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700694 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700695 break;
696
697 udelay(10);
698 }
699
700 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700701 WRT_REG_WORD(&reg->ctrl_status, 0x20);
702 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700703
704 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700705 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700706
707 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700708 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700709
710 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700711 WRT_REG_WORD(&reg->ctrl_status, 0x0);
712 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700713
714 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700715 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700716 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700717 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700718 break;
719
720 udelay(10);
721 }
722
723 spin_unlock_irqrestore(&ha->hardware_lock, flags);
724 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700725
726 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
727
Andrew Vasquez737faec2008-10-24 15:13:45 -0700728 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700729
730 /* Get PCI bus information. */
731 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700732 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700733 spin_unlock_irqrestore(&ha->hardware_lock, flags);
734
735 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736}
737
738/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700739 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
740 * @ha: HA context
741 *
742 * Returns 0 on success.
743 */
744int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700746{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700747 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700748 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700750 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700751
752 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700753 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700754
755 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700756 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700757 w &= ~PCI_COMMAND_INTX_DISABLE;
758 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
759
760 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
761
762 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700763 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
764 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700765
766 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700767 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
768 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700769
Andrew Vasquez737faec2008-10-24 15:13:45 -0700770 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700771
Auke Kok44c10132007-06-08 15:46:36 -0700772 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800773
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700774 /* Get PCI bus information. */
775 spin_lock_irqsave(&ha->hardware_lock, flags);
776 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
777 spin_unlock_irqrestore(&ha->hardware_lock, flags);
778
779 return QLA_SUCCESS;
780}
781
782/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700783 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
784 * @ha: HA context
785 *
786 * Returns 0 on success.
787 */
788int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800789qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700790{
791 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700793
794 pci_set_master(ha->pdev);
795 pci_try_set_mwi(ha->pdev);
796
797 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
798 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
799 w &= ~PCI_COMMAND_INTX_DISABLE;
800 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
801
802 /* PCIe -- adjust Maximum Read Request Size (2048). */
803 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
804 pcie_set_readrq(ha->pdev, 2048);
805
Andrew Vasquez737faec2008-10-24 15:13:45 -0700806 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700807
808 ha->chip_revision = ha->pdev->revision;
809
810 return QLA_SUCCESS;
811}
812
813/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 * qla2x00_isp_firmware() - Choose firmware image.
815 * @ha: HA context
816 *
817 * Returns 0 on success.
818 */
819static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821{
822 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700823 uint16_t loop_id, topo, sw_cap;
824 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800825 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700826
827 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700828 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 if (ha->flags.disable_risc_code_load) {
831 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800832 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
834
835 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800836 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700837 if (rval == QLA_SUCCESS) {
838 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800839 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700840 &area, &domain, &topo, &sw_cap);
841 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842 }
843
844 if (rval) {
845 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700847 }
848
849 return (rval);
850}
851
852/**
853 * qla2x00_reset_chip() - Reset ISP chip.
854 * @ha: HA context
855 *
856 * Returns 0 on success.
857 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700858void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800859qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860{
861 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800862 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700863 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 uint16_t cmd;
866
Andrew Vasquez85880802009-12-15 21:29:46 -0800867 if (unlikely(pci_channel_offline(ha->pdev)))
868 return;
869
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700870 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700871
872 spin_lock_irqsave(&ha->hardware_lock, flags);
873
874 /* Turn off master enable */
875 cmd = 0;
876 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
877 cmd &= ~PCI_COMMAND_MASTER;
878 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
879
880 if (!IS_QLA2100(ha)) {
881 /* Pause RISC. */
882 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
883 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
884 for (cnt = 0; cnt < 30000; cnt++) {
885 if ((RD_REG_WORD(&reg->hccr) &
886 HCCR_RISC_PAUSE) != 0)
887 break;
888 udelay(100);
889 }
890 } else {
891 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
892 udelay(10);
893 }
894
895 /* Select FPM registers. */
896 WRT_REG_WORD(&reg->ctrl_status, 0x20);
897 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
898
899 /* FPM Soft Reset. */
900 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
901 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
902
903 /* Toggle Fpm Reset. */
904 if (!IS_QLA2200(ha)) {
905 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
906 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
907 }
908
909 /* Select frame buffer registers. */
910 WRT_REG_WORD(&reg->ctrl_status, 0x10);
911 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
912
913 /* Reset frame buffer FIFOs. */
914 if (IS_QLA2200(ha)) {
915 WRT_FB_CMD_REG(ha, reg, 0xa000);
916 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
917 } else {
918 WRT_FB_CMD_REG(ha, reg, 0x00fc);
919
920 /* Read back fb_cmd until zero or 3 seconds max */
921 for (cnt = 0; cnt < 3000; cnt++) {
922 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
923 break;
924 udelay(100);
925 }
926 }
927
928 /* Select RISC module registers. */
929 WRT_REG_WORD(&reg->ctrl_status, 0);
930 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
931
932 /* Reset RISC processor. */
933 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
934 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
935
936 /* Release RISC processor. */
937 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
938 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
939 }
940
941 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
942 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
943
944 /* Reset ISP chip. */
945 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
946
947 /* Wait for RISC to recover from reset. */
948 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
949 /*
950 * It is necessary to for a delay here since the card doesn't
951 * respond to PCI reads during a reset. On some architectures
952 * this will result in an MCA.
953 */
954 udelay(20);
955 for (cnt = 30000; cnt; cnt--) {
956 if ((RD_REG_WORD(&reg->ctrl_status) &
957 CSR_ISP_SOFT_RESET) == 0)
958 break;
959 udelay(100);
960 }
961 } else
962 udelay(10);
963
964 /* Reset RISC processor. */
965 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
966
967 WRT_REG_WORD(&reg->semaphore, 0);
968
969 /* Release RISC processor. */
970 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
971 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
972
973 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
974 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700975 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
978 udelay(100);
979 }
980 } else
981 udelay(100);
982
983 /* Turn on master enable */
984 cmd |= PCI_COMMAND_MASTER;
985 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
986
987 /* Disable RISC pause on FPM parity error. */
988 if (!IS_QLA2100(ha)) {
989 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
990 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
991 }
992
993 spin_unlock_irqrestore(&ha->hardware_lock, flags);
994}
995
996/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700997 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700998 * @ha: HA context
999 *
1000 * Returns 0 on success.
1001 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001002static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001004{
1005 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001006 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001007 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1008 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001009 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001010
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001011 spin_lock_irqsave(&ha->hardware_lock, flags);
1012
1013 /* Reset RISC. */
1014 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1015 for (cnt = 0; cnt < 30000; cnt++) {
1016 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1017 break;
1018
1019 udelay(10);
1020 }
1021
1022 WRT_REG_DWORD(&reg->ctrl_status,
1023 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001024 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001025
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001026 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001027 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001028 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1029 for (cnt = 10000 ; cnt && d2; cnt--) {
1030 udelay(5);
1031 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1032 barrier();
1033 }
1034
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001035 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001036 d2 = RD_REG_DWORD(&reg->ctrl_status);
1037 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1038 udelay(5);
1039 d2 = RD_REG_DWORD(&reg->ctrl_status);
1040 barrier();
1041 }
1042
1043 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1044 RD_REG_DWORD(&reg->hccr);
1045
1046 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1047 RD_REG_DWORD(&reg->hccr);
1048
1049 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1050 RD_REG_DWORD(&reg->hccr);
1051
1052 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1053 for (cnt = 6000000 ; cnt && d2; cnt--) {
1054 udelay(5);
1055 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1056 barrier();
1057 }
1058
1059 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001060
1061 if (IS_NOPOLLING_TYPE(ha))
1062 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001063}
1064
1065/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001066 * qla24xx_reset_chip() - Reset ISP24xx chip.
1067 * @ha: HA context
1068 *
1069 * Returns 0 on success.
1070 */
1071void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001072qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001073{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001074 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001075
1076 if (pci_channel_offline(ha->pdev) &&
1077 ha->flags.pci_channel_io_perm_failure) {
1078 return;
1079 }
1080
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001081 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001082
1083 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001084 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001085}
1086
1087/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088 * qla2x00_chip_diag() - Test chip for proper operation.
1089 * @ha: HA context
1090 *
1091 * Returns 0 on success.
1092 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001093int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001094qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001095{
1096 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001097 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001098 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 unsigned long flags = 0;
1100 uint16_t data;
1101 uint32_t cnt;
1102 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001103 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104
1105 /* Assume a failed state */
1106 rval = QLA_FUNCTION_FAILED;
1107
1108 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110
1111 spin_lock_irqsave(&ha->hardware_lock, flags);
1112
1113 /* Reset ISP chip. */
1114 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1115
1116 /*
1117 * We need to have a delay here since the card will not respond while
1118 * in reset causing an MCA on some architectures.
1119 */
1120 udelay(20);
1121 data = qla2x00_debounce_register(&reg->ctrl_status);
1122 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1123 udelay(5);
1124 data = RD_REG_WORD(&reg->ctrl_status);
1125 barrier();
1126 }
1127
1128 if (!cnt)
1129 goto chip_diag_failed;
1130
1131 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001132 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 /* Reset RISC processor. */
1135 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1136 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1137
1138 /* Workaround for QLA2312 PCI parity error */
1139 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1140 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1141 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1142 udelay(5);
1143 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001144 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 }
1146 } else
1147 udelay(10);
1148
1149 if (!cnt)
1150 goto chip_diag_failed;
1151
1152 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001153 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001154
1155 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1156 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1157 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1158 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1159 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1160 mb[3] != PROD_ID_3) {
1161 qla_printk(KERN_WARNING, ha,
1162 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1163
1164 goto chip_diag_failed;
1165 }
1166 ha->product_id[0] = mb[1];
1167 ha->product_id[1] = mb[2];
1168 ha->product_id[2] = mb[3];
1169 ha->product_id[3] = mb[4];
1170
1171 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001172 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1174 else
1175 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001176 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 if (IS_QLA2200(ha) &&
1179 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1180 /* Limit firmware transfer size with a 2200A */
1181 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001184 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 ha->fw_transfer_size = 128;
1186 }
1187
1188 /* Wrap Incoming Mailboxes Test. */
1189 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1190
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001191 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1192 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 if (rval) {
1194 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001195 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001196 qla_printk(KERN_WARNING, ha,
1197 "Failed mailbox send register test\n");
1198 }
1199 else {
1200 /* Flag a successful rval */
1201 rval = QLA_SUCCESS;
1202 }
1203 spin_lock_irqsave(&ha->hardware_lock, flags);
1204
1205chip_diag_failed:
1206 if (rval)
1207 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209
1210 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1211
1212 return (rval);
1213}
1214
1215/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001216 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1217 * @ha: HA context
1218 *
1219 * Returns 0 on success.
1220 */
1221int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001222qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001223{
1224 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001225 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001226 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001227
Giridhar Malavalia9083012010-04-12 17:59:55 -07001228 if (IS_QLA82XX(ha))
1229 return QLA_SUCCESS;
1230
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001231 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001232
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001234 if (rval) {
1235 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001236 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001237 qla_printk(KERN_WARNING, ha,
1238 "Failed mailbox send register test\n");
1239 } else {
1240 /* Flag a successful rval */
1241 rval = QLA_SUCCESS;
1242 }
1243
1244 return rval;
1245}
1246
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001247void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001248qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001249{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001250 int rval;
1251 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001252 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001253 dma_addr_t tc_dma;
1254 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001255 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001256 struct req_que *req = ha->req_q_map[0];
1257 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001258
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001259 if (ha->fw_dump) {
1260 qla_printk(KERN_WARNING, ha,
1261 "Firmware dump previously allocated.\n");
1262 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001263 }
1264
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001265 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001266 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001267 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1268 fixed_size = sizeof(struct qla2100_fw_dump);
1269 } else if (IS_QLA23XX(ha)) {
1270 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1271 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1272 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001273 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001274 if (IS_QLA81XX(ha))
1275 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1276 else if (IS_QLA25XX(ha))
1277 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1278 else
1279 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001280 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1281 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001282 if (ha->mqenable)
1283 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001284 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001285 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001286 goto try_eft;
1287
1288 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1289 GFP_KERNEL);
1290 if (!tc) {
1291 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1292 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001293 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001294 }
1295
1296 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001297 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001298 ha->fce_mb, &ha->fce_bufs);
1299 if (rval) {
1300 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1301 "FCE (%d).\n", rval);
1302 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1303 tc_dma);
1304 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001305 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001306 }
1307
1308 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1309 FCE_SIZE / 1024);
1310
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001311 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001312 ha->flags.fce_enabled = 1;
1313 ha->fce_dma = tc_dma;
1314 ha->fce = tc;
1315try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001316 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001317 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001318 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001319 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001320 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1321 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1322 goto cont_alloc;
1323 }
1324
Andrew Vasquezfc447652008-01-17 09:02:18 -08001325 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001327 if (rval) {
1328 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1329 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001330 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1331 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001332 goto cont_alloc;
1333 }
1334
1335 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1336 EFT_SIZE / 1024);
1337
1338 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001339 ha->eft_dma = tc_dma;
1340 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001341 }
1342cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001343 req_q_size = req->length * sizeof(request_t);
1344 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001345
1346 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001347 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001348 ha->chain_offset = dump_size;
1349 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001350
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001351 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001352 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001353 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001354 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001355
1356 if (ha->eft) {
1357 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1358 ha->eft_dma);
1359 ha->eft = NULL;
1360 ha->eft_dma = 0;
1361 }
1362 return;
1363 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001364 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1365 dump_size / 1024);
1366
1367 ha->fw_dump_len = dump_size;
1368 ha->fw_dump->signature[0] = 'Q';
1369 ha->fw_dump->signature[1] = 'L';
1370 ha->fw_dump->signature[2] = 'G';
1371 ha->fw_dump->signature[3] = 'C';
1372 ha->fw_dump->version = __constant_htonl(1);
1373
1374 ha->fw_dump->fixed_size = htonl(fixed_size);
1375 ha->fw_dump->mem_size = htonl(mem_size);
1376 ha->fw_dump->req_q_size = htonl(req_q_size);
1377 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1378
1379 ha->fw_dump->eft_size = htonl(eft_size);
1380 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1381 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1382
1383 ha->fw_dump->header_size =
1384 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001385}
1386
Andrew Vasquez18e75552009-06-03 09:55:30 -07001387static int
1388qla81xx_mpi_sync(scsi_qla_host_t *vha)
1389{
1390#define MPS_MASK 0xe0
1391 int rval;
1392 uint16_t dc;
1393 uint32_t dw;
1394 struct qla_hw_data *ha = vha->hw;
1395
1396 if (!IS_QLA81XX(vha->hw))
1397 return QLA_SUCCESS;
1398
1399 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1400 if (rval != QLA_SUCCESS) {
1401 DEBUG2(qla_printk(KERN_WARNING, ha,
1402 "Sync-MPI: Unable to acquire semaphore.\n"));
1403 goto done;
1404 }
1405
1406 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1407 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1408 if (rval != QLA_SUCCESS) {
1409 DEBUG2(qla_printk(KERN_WARNING, ha,
1410 "Sync-MPI: Unable to read sync.\n"));
1411 goto done_release;
1412 }
1413
1414 dc &= MPS_MASK;
1415 if (dc == (dw & MPS_MASK))
1416 goto done_release;
1417
1418 dw &= ~MPS_MASK;
1419 dw |= dc;
1420 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1421 if (rval != QLA_SUCCESS) {
1422 DEBUG2(qla_printk(KERN_WARNING, ha,
1423 "Sync-MPI: Unable to gain sync.\n"));
1424 }
1425
1426done_release:
1427 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1428 if (rval != QLA_SUCCESS) {
1429 DEBUG2(qla_printk(KERN_WARNING, ha,
1430 "Sync-MPI: Unable to release semaphore.\n"));
1431 }
1432
1433done:
1434 return rval;
1435}
1436
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001437/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 * qla2x00_setup_chip() - Load and start RISC firmware.
1439 * @ha: HA context
1440 *
1441 * Returns 0 on success.
1442 */
1443static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001446 int rval;
1447 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001449 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1450 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001451 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001452
Giridhar Malavalia9083012010-04-12 17:59:55 -07001453 if (IS_QLA82XX(ha)) {
1454 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1455 if (rval == QLA_SUCCESS)
1456 goto enable_82xx_npiv;
1457 }
1458
Andrew Vasquez3db06522008-01-31 12:33:49 -08001459 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1460 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1461 spin_lock_irqsave(&ha->hardware_lock, flags);
1462 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1463 RD_REG_WORD(&reg->hccr);
1464 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1465 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
Andrew Vasquez18e75552009-06-03 09:55:30 -07001467 qla81xx_mpi_sync(vha);
1468
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001470 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001471 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 if (rval == QLA_SUCCESS) {
1477 /* Start firmware execution. */
1478 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001479 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001483 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001484enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001485 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001486 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 &ha->fw_major_version,
1488 &ha->fw_minor_version,
1489 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001490 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001491 ha->mpi_version, &ha->mpi_capabilities,
1492 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001493 if (rval != QLA_SUCCESS)
1494 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001495 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001497 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001498 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001499 if ((!ha->max_npiv_vports) ||
1500 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001501 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001502 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001503 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001504 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001505 qla2x00_get_resource_cnts(vha, NULL,
1506 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001507 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001508
Giridhar Malavalia9083012010-04-12 17:59:55 -07001509 if (!fw_major_version && ql2xallocfwdump) {
1510 if (!IS_QLA82XX(ha))
1511 qla2x00_alloc_fw_dump(vha);
1512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 }
1514 } else {
1515 DEBUG2(printk(KERN_INFO
1516 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001517 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 }
1519 }
1520
Andrew Vasquez3db06522008-01-31 12:33:49 -08001521 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1522 /* Enable proper parity. */
1523 spin_lock_irqsave(&ha->hardware_lock, flags);
1524 if (IS_QLA2300(ha))
1525 /* SRAM parity */
1526 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1527 else
1528 /* SRAM, Instruction RAM and GP RAM parity */
1529 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1530 RD_REG_WORD(&reg->hccr);
1531 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1532 }
1533
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001534 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1535 uint32_t size;
1536
1537 rval = qla81xx_fac_get_sector_size(vha, &size);
1538 if (rval == QLA_SUCCESS) {
1539 ha->flags.fac_supported = 1;
1540 ha->fdt_block_size = size << 2;
1541 } else {
1542 qla_printk(KERN_ERR, ha,
1543 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1544 ha->fw_major_version, ha->fw_minor_version,
1545 ha->fw_subminor_version);
1546 }
1547 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001548failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 if (rval) {
1550 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001551 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 }
1553
1554 return (rval);
1555}
1556
1557/**
1558 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1559 * @ha: HA context
1560 *
1561 * Beginning of request ring has initialization control block already built
1562 * by nvram config routine.
1563 *
1564 * Returns 0 on success.
1565 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001566void
1567qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568{
1569 uint16_t cnt;
1570 response_t *pkt;
1571
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001572 rsp->ring_ptr = rsp->ring;
1573 rsp->ring_index = 0;
1574 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001575 pkt = rsp->ring_ptr;
1576 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 pkt->signature = RESPONSE_PROCESSED;
1578 pkt++;
1579 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580}
1581
1582/**
1583 * qla2x00_update_fw_options() - Read and process firmware options.
1584 * @ha: HA context
1585 *
1586 * Returns 0 on success.
1587 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001588void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001589qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590{
1591 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001592 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001595 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596
1597 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1598 return;
1599
1600 /* Serial Link options. */
1601 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001602 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1604 sizeof(ha->fw_seriallink_options)));
1605
1606 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1607 if (ha->fw_seriallink_options[3] & BIT_2) {
1608 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1609
1610 /* 1G settings */
1611 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1612 emphasis = (ha->fw_seriallink_options[2] &
1613 (BIT_4 | BIT_3)) >> 3;
1614 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001615 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616 rx_sens = (ha->fw_seriallink_options[0] &
1617 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1618 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1619 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1620 if (rx_sens == 0x0)
1621 rx_sens = 0x3;
1622 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1623 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1624 ha->fw_options[10] |= BIT_5 |
1625 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1626 (tx_sens & (BIT_1 | BIT_0));
1627
1628 /* 2G settings */
1629 swing = (ha->fw_seriallink_options[2] &
1630 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1631 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1632 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001633 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 rx_sens = (ha->fw_seriallink_options[1] &
1635 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1636 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1637 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1638 if (rx_sens == 0x0)
1639 rx_sens = 0x3;
1640 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1641 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1642 ha->fw_options[11] |= BIT_5 |
1643 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1644 (tx_sens & (BIT_1 | BIT_0));
1645 }
1646
1647 /* FCP2 options. */
1648 /* Return command IOCBs without waiting for an ABTS to complete. */
1649 ha->fw_options[3] |= BIT_13;
1650
1651 /* LED scheme. */
1652 if (ha->flags.enable_led_scheme)
1653 ha->fw_options[2] |= BIT_12;
1654
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001655 /* Detect ISP6312. */
1656 if (IS_QLA6312(ha))
1657 ha->fw_options[2] |= BIT_13;
1658
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001660 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661}
1662
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001663void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001664qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001665{
1666 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001668
Giridhar Malavalia9083012010-04-12 17:59:55 -07001669 if (IS_QLA82XX(ha))
1670 return;
1671
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001672 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001673 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001674 return;
1675
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001677 le16_to_cpu(ha->fw_seriallink_options24[1]),
1678 le16_to_cpu(ha->fw_seriallink_options24[2]),
1679 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001680 if (rval != QLA_SUCCESS) {
1681 qla_printk(KERN_WARNING, ha,
1682 "Unable to update Serial Link options (%x).\n", rval);
1683 }
1684}
1685
1686void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001687qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001688{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001690 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001691 struct req_que *req = ha->req_q_map[0];
1692 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001693
1694 /* Setup ring parameters in initialization control block. */
1695 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1696 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001697 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1698 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1699 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1700 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1701 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1702 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001703
1704 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1705 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1706 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1707 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1708 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1709}
1710
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001711void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001712qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001713{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001714 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001715 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1716 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1717 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001718 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001719 uint16_t rid = 0;
1720 struct req_que *req = ha->req_q_map[0];
1721 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001722
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001723/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001724 icb = (struct init_cb_24xx *)ha->init_cb;
1725 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1726 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001727 icb->request_q_length = cpu_to_le16(req->length);
1728 icb->response_q_length = cpu_to_le16(rsp->length);
1729 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1730 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1731 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1732 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001733
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001734 if (ha->mqenable) {
1735 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1736 icb->rid = __constant_cpu_to_le16(rid);
1737 if (ha->flags.msix_enabled) {
1738 msix = &ha->msix_entries[1];
1739 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001740 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001741 icb->msix = cpu_to_le16(msix->entry);
1742 }
1743 /* Use alternate PCI bus number */
1744 if (MSB(rid))
1745 icb->firmware_options_2 |=
1746 __constant_cpu_to_le32(BIT_19);
1747 /* Use alternate PCI devfn */
1748 if (LSB(rid))
1749 icb->firmware_options_2 |=
1750 __constant_cpu_to_le32(BIT_18);
1751
Anirban Chakraborty31557542009-12-02 10:36:55 -08001752 /* Use Disable MSIX Handshake mode for capable adapters */
1753 if (IS_MSIX_NACK_CAPABLE(ha)) {
1754 icb->firmware_options_2 &=
1755 __constant_cpu_to_le32(~BIT_22);
1756 ha->flags.disable_msix_handshake = 1;
1757 qla_printk(KERN_INFO, ha,
1758 "MSIX Handshake Disable Mode turned on\n");
1759 } else {
1760 icb->firmware_options_2 |=
1761 __constant_cpu_to_le32(BIT_22);
1762 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001763 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001764
1765 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1766 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1767 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1768 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1769 } else {
1770 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1771 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1772 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1773 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1774 }
1775 /* PCI posting */
1776 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001777}
1778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779/**
1780 * qla2x00_init_rings() - Initializes firmware.
1781 * @ha: HA context
1782 *
1783 * Beginning of request ring has initialization control block already built
1784 * by nvram config routine.
1785 *
1786 * Returns 0 on success.
1787 */
1788static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001789qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790{
1791 int rval;
1792 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001793 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001794 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001795 struct req_que *req;
1796 struct rsp_que *rsp;
1797 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001798 struct mid_init_cb_24xx *mid_init_cb =
1799 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800
1801 spin_lock_irqsave(&ha->hardware_lock, flags);
1802
1803 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001804 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001805 req = ha->req_q_map[que];
1806 if (!req)
1807 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001808 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001809 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001811 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001812
1813 /* Initialize firmware. */
1814 req->ring_ptr = req->ring;
1815 req->ring_index = 0;
1816 req->cnt = req->length;
1817 }
1818
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001819 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001820 rsp = ha->rsp_q_map[que];
1821 if (!rsp)
1822 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001823 /* Initialize response queue entries */
1824 qla2x00_init_response_q_entries(rsp);
1825 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826
1827 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001828 list_for_each_entry(vp, &ha->vp_list, list) {
1829 vp->rscn_in_ptr = 0;
1830 vp->rscn_out_ptr = 0;
1831 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001832 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833
1834 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1835
1836 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001837 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001839 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001840
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001841 if (ha->flags.npiv_supported) {
1842 if (ha->operating_mode == LOOP)
1843 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001844 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001845 }
1846
Andrew Vasquez24a08132009-03-24 09:08:16 -07001847 if (IS_FWI2_CAPABLE(ha)) {
1848 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1849 mid_init_cb->init_cb.execution_throttle =
1850 cpu_to_le16(ha->fw_xcb_count);
1851 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001852
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001853 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001854 if (rval) {
1855 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001856 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 } else {
1858 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001859 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 }
1861
1862 return (rval);
1863}
1864
1865/**
1866 * qla2x00_fw_ready() - Waits for firmware ready.
1867 * @ha: HA context
1868 *
1869 * Returns 0 on success.
1870 */
1871static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001872qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
1874 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001875 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 uint16_t min_wait; /* Minimum wait time if loop is down */
1877 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001878 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001879 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880
1881 rval = QLA_SUCCESS;
1882
1883 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001884 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885
1886 /*
1887 * Firmware should take at most one RATOV to login, plus 5 seconds for
1888 * our own processing.
1889 */
1890 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1891 wait_time = min_wait;
1892 }
1893
1894 /* Min wait time if loop down */
1895 mtime = jiffies + (min_wait * HZ);
1896
1897 /* wait time before firmware ready */
1898 wtime = jiffies + (wait_time * HZ);
1899
1900 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001901 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1903
1904 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001905 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906
1907 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001908 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001910 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001913 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1914 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001916 state[2]));
1917 if ((state[2] & FSTATE_LOGGED_IN) &&
1918 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1919 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001920 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001921
1922 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001924 if (rval != QLA_SUCCESS)
1925 break;
1926
1927 /* Add time taken to initialize. */
1928 cs84xx_time = jiffies - cs84xx_time;
1929 wtime += cs84xx_time;
1930 mtime += cs84xx_time;
1931 DEBUG16(printk("scsi(%ld): Increasing "
1932 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001933 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001934 }
1935 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001939 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940 &ha->login_timeout, &ha->r_a_tov);
1941
1942 rval = QLA_SUCCESS;
1943 break;
1944 }
1945
1946 rval = QLA_FUNCTION_FAILED;
1947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001948 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001949 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001951 * other than Wait for Login.
1952 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 if (time_after_eq(jiffies, mtime)) {
1954 qla_printk(KERN_INFO, ha,
1955 "Cable is unplugged...\n");
1956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001957 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 break;
1959 }
1960 }
1961 } else {
1962 /* Mailbox cmd failed. Timeout on min_wait. */
1963 if (time_after_eq(jiffies, mtime))
1964 break;
1965 }
1966
1967 if (time_after_eq(jiffies, wtime))
1968 break;
1969
1970 /* Delay for a while */
1971 msleep(500);
1972
1973 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975 } while (1);
1976
Andrew Vasquez656e8912009-06-03 09:55:29 -07001977 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1978 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1979 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 if (rval) {
1982 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 }
1985
1986 return (rval);
1987}
1988
1989/*
1990* qla2x00_configure_hba
1991* Setup adapter context.
1992*
1993* Input:
1994* ha = adapter state pointer.
1995*
1996* Returns:
1997* 0 = success
1998*
1999* Context:
2000* Kernel context.
2001*/
2002static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004{
2005 int rval;
2006 uint16_t loop_id;
2007 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002008 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 uint8_t al_pa;
2010 uint8_t area;
2011 uint8_t domain;
2012 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002013 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
2015 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002017 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002020 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2021 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002022 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002023 } else {
2024 qla_printk(KERN_WARNING, ha,
2025 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002027 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 return (rval);
2029 }
2030
2031 if (topo == 4) {
2032 qla_printk(KERN_INFO, ha,
2033 "Cannot get topology - retrying.\n");
2034 return (QLA_FUNCTION_FAILED);
2035 }
2036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038
2039 /* initialize */
2040 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2041 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002042 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043
2044 switch (topo) {
2045 case 0:
2046 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 ha->current_topology = ISP_CFG_NL;
2049 strcpy(connect_type, "(Loop)");
2050 break;
2051
2052 case 1:
2053 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002054 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002055 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 ha->current_topology = ISP_CFG_FL;
2057 strcpy(connect_type, "(FL_Port)");
2058 break;
2059
2060 case 2:
2061 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 ha->operating_mode = P2P;
2064 ha->current_topology = ISP_CFG_N;
2065 strcpy(connect_type, "(N_Port-to-N_Port)");
2066 break;
2067
2068 case 3:
2069 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002070 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002071 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 ha->operating_mode = P2P;
2073 ha->current_topology = ISP_CFG_F;
2074 strcpy(connect_type, "(F_Port)");
2075 break;
2076
2077 default:
2078 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2079 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002080 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081 ha->current_topology = ISP_CFG_NL;
2082 strcpy(connect_type, "(Loop)");
2083 break;
2084 }
2085
2086 /* Save Host port and loop ID. */
2087 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002088 vha->d_id.b.domain = domain;
2089 vha->d_id.b.area = area;
2090 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002092 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 qla_printk(KERN_INFO, ha,
2094 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002095 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
2097 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 }
2102
2103 return(rval);
2104}
2105
Giridhar Malavalia9083012010-04-12 17:59:55 -07002106inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002107qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2108 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002109{
2110 char *st, *en;
2111 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002112 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002113 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002114 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002115
2116 if (memcmp(model, BINZERO, len) != 0) {
2117 strncpy(ha->model_number, model, len);
2118 st = en = ha->model_number;
2119 en += len - 1;
2120 while (en > st) {
2121 if (*en != 0x20 && *en != 0x00)
2122 break;
2123 *en-- = '\0';
2124 }
2125
2126 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002127 if (use_tbl &&
2128 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002129 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002130 strncpy(ha->model_desc,
2131 qla2x00_model_name[index * 2 + 1],
2132 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002133 } else {
2134 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002135 if (use_tbl &&
2136 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002137 index < QLA_MODEL_NAMES) {
2138 strcpy(ha->model_number,
2139 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002140 strncpy(ha->model_desc,
2141 qla2x00_model_name[index * 2 + 1],
2142 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002143 } else {
2144 strcpy(ha->model_number, def);
2145 }
2146 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002147 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002148 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002149 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002150}
2151
David Miller4e08df32007-04-16 12:37:43 -07002152/* On sparc systems, obtain port and node WWN from firmware
2153 * properties.
2154 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002156{
2157#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002159 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002160 struct device_node *dp = pci_device_to_OF_node(pdev);
2161 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002162 int len;
2163
2164 val = of_get_property(dp, "port-wwn", &len);
2165 if (val && len >= WWN_SIZE)
2166 memcpy(nv->port_name, val, WWN_SIZE);
2167
2168 val = of_get_property(dp, "node-wwn", &len);
2169 if (val && len >= WWN_SIZE)
2170 memcpy(nv->node_name, val, WWN_SIZE);
2171#endif
2172}
2173
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174/*
2175* NVRAM configuration for ISP 2xxx
2176*
2177* Input:
2178* ha = adapter block pointer.
2179*
2180* Output:
2181* initialization control block in response_ring
2182* host adapters parameters in host adapter block
2183*
2184* Returns:
2185* 0 = success.
2186*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002187int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002188qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189{
David Miller4e08df32007-04-16 12:37:43 -07002190 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002191 uint8_t chksum = 0;
2192 uint16_t cnt;
2193 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002195 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002196 nvram_t *nv = ha->nvram;
2197 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002198 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199
David Miller4e08df32007-04-16 12:37:43 -07002200 rval = QLA_SUCCESS;
2201
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002203 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 ha->nvram_base = 0;
2205 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2206 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2207 ha->nvram_base = 0x80;
2208
2209 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002210 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002211 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2212 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002215 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 /* Bad NVRAM data, set defaults parameters. */
2218 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2219 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2220 /* Reset NVRAM data. */
2221 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2222 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2223 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002224 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2225 "invalid -- WWPN) defaults.\n");
2226
2227 /*
2228 * Set default initialization control block.
2229 */
2230 memset(nv, 0, ha->nvram_size);
2231 nv->parameter_block_version = ICB_VERSION;
2232
2233 if (IS_QLA23XX(ha)) {
2234 nv->firmware_options[0] = BIT_2 | BIT_1;
2235 nv->firmware_options[1] = BIT_7 | BIT_5;
2236 nv->add_firmware_options[0] = BIT_5;
2237 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2238 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2239 nv->special_options[1] = BIT_7;
2240 } else if (IS_QLA2200(ha)) {
2241 nv->firmware_options[0] = BIT_2 | BIT_1;
2242 nv->firmware_options[1] = BIT_7 | BIT_5;
2243 nv->add_firmware_options[0] = BIT_5;
2244 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2245 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2246 } else if (IS_QLA2100(ha)) {
2247 nv->firmware_options[0] = BIT_3 | BIT_1;
2248 nv->firmware_options[1] = BIT_5;
2249 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2250 }
2251
2252 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2253 nv->execution_throttle = __constant_cpu_to_le16(16);
2254 nv->retry_count = 8;
2255 nv->retry_delay = 1;
2256
2257 nv->port_name[0] = 33;
2258 nv->port_name[3] = 224;
2259 nv->port_name[4] = 139;
2260
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002261 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002262
2263 nv->login_timeout = 4;
2264
2265 /*
2266 * Set default host adapter parameters
2267 */
2268 nv->host_p[1] = BIT_2;
2269 nv->reset_delay = 5;
2270 nv->port_down_retry_count = 8;
2271 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2272 nv->link_down_timeout = 60;
2273
2274 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275 }
2276
2277#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2278 /*
2279 * The SN2 does not provide BIOS emulation which means you can't change
2280 * potentially bogus BIOS settings. Force the use of default settings
2281 * for link rate and frame size. Hope that the rest of the settings
2282 * are valid.
2283 */
2284 if (ia64_platform_is("sn2")) {
2285 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2286 if (IS_QLA23XX(ha))
2287 nv->special_options[1] = BIT_7;
2288 }
2289#endif
2290
2291 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002292 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293
2294 /*
2295 * Setup driver NVRAM options.
2296 */
2297 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2298 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2299 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2300 nv->firmware_options[1] &= ~BIT_4;
2301
2302 if (IS_QLA23XX(ha)) {
2303 nv->firmware_options[0] |= BIT_2;
2304 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002305 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002306 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307
2308 if (IS_QLA2300(ha)) {
2309 if (ha->fb_rev == FPM_2310) {
2310 strcpy(ha->model_number, "QLA2310");
2311 } else {
2312 strcpy(ha->model_number, "QLA2300");
2313 }
2314 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002316 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317 }
2318 } else if (IS_QLA2200(ha)) {
2319 nv->firmware_options[0] |= BIT_2;
2320 /*
2321 * 'Point-to-point preferred, else loop' is not a safe
2322 * connection mode setting.
2323 */
2324 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2325 (BIT_5 | BIT_4)) {
2326 /* Force 'loop preferred, else point-to-point'. */
2327 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2328 nv->add_firmware_options[0] |= BIT_5;
2329 }
2330 strcpy(ha->model_number, "QLA22xx");
2331 } else /*if (IS_QLA2100(ha))*/ {
2332 strcpy(ha->model_number, "QLA2100");
2333 }
2334
2335 /*
2336 * Copy over NVRAM RISC parameter block to initialization control block.
2337 */
2338 dptr1 = (uint8_t *)icb;
2339 dptr2 = (uint8_t *)&nv->parameter_block_version;
2340 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2341 while (cnt--)
2342 *dptr1++ = *dptr2++;
2343
2344 /* Copy 2nd half. */
2345 dptr1 = (uint8_t *)icb->add_firmware_options;
2346 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2347 while (cnt--)
2348 *dptr1++ = *dptr2++;
2349
Andrew Vasquez5341e862006-05-17 15:09:16 -07002350 /* Use alternate WWN? */
2351 if (nv->host_p[1] & BIT_7) {
2352 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2353 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2354 }
2355
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 /* Prepare nodename */
2357 if ((icb->firmware_options[1] & BIT_6) == 0) {
2358 /*
2359 * Firmware will apply the following mask if the nodename was
2360 * not provided.
2361 */
2362 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2363 icb->node_name[0] &= 0xF0;
2364 }
2365
2366 /*
2367 * Set host adapter parameters.
2368 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002369 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002370 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2372 /* Always load RISC code on non ISP2[12]00 chips. */
2373 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2374 ha->flags.disable_risc_code_load = 0;
2375 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2376 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2377 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002378 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002379 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380
2381 ha->operating_mode =
2382 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2383
2384 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2385 sizeof(ha->fw_seriallink_options));
2386
2387 /* save HBA serial number */
2388 ha->serial0 = icb->port_name[5];
2389 ha->serial1 = icb->port_name[6];
2390 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002391 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2392 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393
2394 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2395
2396 ha->retry_count = nv->retry_count;
2397
2398 /* Set minimum login_timeout to 4 seconds. */
2399 if (nv->login_timeout < ql2xlogintimeout)
2400 nv->login_timeout = ql2xlogintimeout;
2401 if (nv->login_timeout < 4)
2402 nv->login_timeout = 4;
2403 ha->login_timeout = nv->login_timeout;
2404 icb->login_timeout = nv->login_timeout;
2405
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002406 /* Set minimum RATOV to 100 tenths of a second. */
2407 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 ha->loop_reset_delay = nv->reset_delay;
2410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 /* Link Down Timeout = 0:
2412 *
2413 * When Port Down timer expires we will start returning
2414 * I/O's to OS with "DID_NO_CONNECT".
2415 *
2416 * Link Down Timeout != 0:
2417 *
2418 * The driver waits for the link to come up after link down
2419 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002420 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 if (nv->link_down_timeout == 0) {
2422 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002423 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 } else {
2425 ha->link_down_timeout = nv->link_down_timeout;
2426 ha->loop_down_abort_time =
2427 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 /*
2431 * Need enough time to try and get the port back.
2432 */
2433 ha->port_down_retry_count = nv->port_down_retry_count;
2434 if (qlport_down_retry)
2435 ha->port_down_retry_count = qlport_down_retry;
2436 /* Set login_retry_count */
2437 ha->login_retry_count = nv->retry_count;
2438 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2439 ha->port_down_retry_count > 3)
2440 ha->login_retry_count = ha->port_down_retry_count;
2441 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2442 ha->login_retry_count = ha->port_down_retry_count;
2443 if (ql2xloginretrycount)
2444 ha->login_retry_count = ql2xloginretrycount;
2445
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 icb->lun_enables = __constant_cpu_to_le16(0);
2447 icb->command_resource_count = 0;
2448 icb->immediate_notify_resource_count = 0;
2449 icb->timeout = __constant_cpu_to_le16(0);
2450
2451 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2452 /* Enable RIO */
2453 icb->firmware_options[0] &= ~BIT_3;
2454 icb->add_firmware_options[0] &=
2455 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2456 icb->add_firmware_options[0] |= BIT_2;
2457 icb->response_accumulation_timer = 3;
2458 icb->interrupt_delay_timer = 5;
2459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002460 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002462 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002463 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002464 ha->zio_mode = icb->add_firmware_options[0] &
2465 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2466 ha->zio_timer = icb->interrupt_delay_timer ?
2467 icb->interrupt_delay_timer: 2;
2468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 icb->add_firmware_options[0] &=
2470 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002471 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002472 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002473 ha->zio_mode = QLA_ZIO_MODE_6;
2474
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002475 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002477 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002479 "ZIO mode %d enabled; timer delay (%d us).\n",
2480 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002482 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2483 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 }
2486 }
2487
David Miller4e08df32007-04-16 12:37:43 -07002488 if (rval) {
2489 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002490 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002491 }
2492 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493}
2494
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002495static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002496qla2x00_rport_del(void *data)
2497{
2498 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002499 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002500
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002501 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002502 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002503 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002505 if (rport)
2506 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002507}
2508
Linus Torvalds1da177e2005-04-16 15:20:36 -07002509/**
2510 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2511 * @ha: HA context
2512 * @flags: allocation flags
2513 *
2514 * Returns a pointer to the allocated fcport, or NULL, if none available.
2515 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002516fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518{
2519 fc_port_t *fcport;
2520
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002521 fcport = kzalloc(sizeof(fc_port_t), flags);
2522 if (!fcport)
2523 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524
2525 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 fcport->vha = vha;
2527 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 fcport->port_type = FCT_UNKNOWN;
2529 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002531 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002533 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534}
2535
2536/*
2537 * qla2x00_configure_loop
2538 * Updates Fibre Channel Device Database with what is actually on loop.
2539 *
2540 * Input:
2541 * ha = adapter block pointer.
2542 *
2543 * Returns:
2544 * 0 = success.
2545 * 1 = error.
2546 * 2 = database was full and device was not configured.
2547 */
2548static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002549qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550{
2551 int rval;
2552 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002553 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 rval = QLA_SUCCESS;
2555
2556 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2558 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 if (rval != QLA_SUCCESS) {
2560 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002561 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562 return (rval);
2563 }
2564 }
2565
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002566 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569
2570 /*
2571 * If we have both an RSCN and PORT UPDATE pending then handle them
2572 * both at the same time.
2573 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2575 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576
Michael Hernandez3064ff32009-12-15 21:29:44 -08002577 qla2x00_get_data_rate(vha);
2578
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 /* Determine what we need to do */
2580 if (ha->current_topology == ISP_CFG_FL &&
2581 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2582
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 set_bit(RSCN_UPDATE, &flags);
2585
2586 } else if (ha->current_topology == ISP_CFG_F &&
2587 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2588
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002589 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002590 set_bit(RSCN_UPDATE, &flags);
2591 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2592
Andrew Vasquez21333b42006-05-17 15:09:56 -07002593 } else if (ha->current_topology == ISP_CFG_N) {
2594 clear_bit(RSCN_UPDATE, &flags);
2595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2598
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 set_bit(RSCN_UPDATE, &flags);
2601 set_bit(LOCAL_LOOP_UPDATE, &flags);
2602 }
2603
2604 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002607 else
2608 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 }
2610
2611 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 else
2615 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 }
2617
2618 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 if (atomic_read(&vha->loop_down_timer) ||
2620 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 rval = QLA_FUNCTION_FAILED;
2622 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002623 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002625 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626 }
2627 }
2628
2629 if (rval) {
2630 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002631 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 } else {
2633 DEBUG3(printk("%s: exiting normally\n", __func__));
2634 }
2635
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002636 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002639 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002640 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002642 vha->flags.rscn_queue_overflow = 1;
2643 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 }
2645
2646 return (rval);
2647}
2648
2649
2650
2651/*
2652 * qla2x00_configure_local_loop
2653 * Updates Fibre Channel Device Database with local loop devices.
2654 *
2655 * Input:
2656 * ha = adapter block pointer.
2657 *
2658 * Returns:
2659 * 0 = success.
2660 */
2661static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002662qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663{
2664 int rval, rval2;
2665 int found_devs;
2666 int found;
2667 fc_port_t *fcport, *new_fcport;
2668
2669 uint16_t index;
2670 uint16_t entries;
2671 char *id_iter;
2672 uint16_t loop_id;
2673 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
2676 found_devs = 0;
2677 new_fcport = NULL;
2678 entries = MAX_FIBRE_DEVICES;
2679
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2681 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682
2683 /* Get list of logged in devices. */
2684 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 &entries);
2687 if (rval != QLA_SUCCESS)
2688 goto cleanup_allocation;
2689
2690 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002691 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2693 entries * sizeof(struct gid_list_info)));
2694
2695 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 if (new_fcport == NULL) {
2698 rval = QLA_MEMORY_ALLOC_FAILED;
2699 goto cleanup_allocation;
2700 }
2701 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2702
2703 /*
2704 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2705 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2708 fcport->port_type != FCT_BROADCAST &&
2709 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2710
2711 DEBUG(printk("scsi(%ld): Marking port lost, "
2712 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 }
2717 }
2718
2719 /* Add devices to port list. */
2720 id_iter = (char *)ha->gid_list;
2721 for (index = 0; index < entries; index++) {
2722 domain = ((struct gid_list_info *)id_iter)->domain;
2723 area = ((struct gid_list_info *)id_iter)->area;
2724 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002725 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 loop_id = (uint16_t)
2727 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002728 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 loop_id = le16_to_cpu(
2730 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002731 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732
2733 /* Bypass reserved domain fields. */
2734 if ((domain & 0xf0) == 0xf0)
2735 continue;
2736
2737 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002738 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 continue;
2741
2742 /* Bypass invalid local loop ID. */
2743 if (loop_id > LAST_LOCAL_LOOP_ID)
2744 continue;
2745
2746 /* Fill in member data. */
2747 new_fcport->d_id.b.domain = domain;
2748 new_fcport->d_id.b.area = area;
2749 new_fcport->d_id.b.al_pa = al_pa;
2750 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 new_fcport->vp_idx = vha->vp_idx;
2752 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 if (rval2 != QLA_SUCCESS) {
2754 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2755 "information -- get_port_database=%x, "
2756 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002758 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 vha->host_no));
2760 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 continue;
2762 }
2763
2764 /* Check for matching device in port list. */
2765 found = 0;
2766 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 if (memcmp(new_fcport->port_name, fcport->port_name,
2769 WWN_SIZE))
2770 continue;
2771
Shyam Sundarddb9b122009-03-24 09:08:10 -07002772 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 fcport->loop_id = new_fcport->loop_id;
2774 fcport->port_type = new_fcport->port_type;
2775 fcport->d_id.b24 = new_fcport->d_id.b24;
2776 memcpy(fcport->node_name, new_fcport->node_name,
2777 WWN_SIZE);
2778
2779 found++;
2780 break;
2781 }
2782
2783 if (!found) {
2784 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002785 if (vha->vp_idx) {
2786 new_fcport->vha = vha;
2787 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002788 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002789 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
2791 /* Allocate a new replacement fcport. */
2792 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794 if (new_fcport == NULL) {
2795 rval = QLA_MEMORY_ALLOC_FAILED;
2796 goto cleanup_allocation;
2797 }
2798 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2799 }
2800
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002801 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002802 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002804 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806 found_devs++;
2807 }
2808
2809cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002810 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811
2812 if (rval != QLA_SUCCESS) {
2813 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 }
2816
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 return (rval);
2818}
2819
2820static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002822{
2823#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002824 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2825 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002826 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002827 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002829
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002830 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002831 return;
2832
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002833 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2834 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002835 return;
2836
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002838 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002839 if (rval != QLA_SUCCESS) {
2840 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2841 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002842 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002843 fcport->port_name[2], fcport->port_name[3],
2844 fcport->port_name[4], fcport->port_name[5],
2845 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002846 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002847 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002848 link_speed = link_speeds[LS_UNKNOWN];
2849 if (fcport->fp_speed < 5)
2850 link_speed = link_speeds[fcport->fp_speed];
2851 else if (fcport->fp_speed == 0x13)
2852 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002853 DEBUG2(qla_printk(KERN_INFO, ha,
2854 "iIDMA adjusted to %s GB/s on "
2855 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002856 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002857 fcport->port_name[1], fcport->port_name[2],
2858 fcport->port_name[3], fcport->port_name[4],
2859 fcport->port_name[5], fcport->port_name[6],
2860 fcport->port_name[7]));
2861 }
2862}
2863
Adrian Bunk23be3312006-11-24 02:46:01 +01002864static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002865qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002866{
2867 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002868 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002870
Andrew Vasquezac280b62009-08-20 11:06:05 -07002871 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002872
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002873 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2874 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002875 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2876 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2877 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002879 if (!rport) {
2880 qla_printk(KERN_WARNING, ha,
2881 "Unable to allocate fc remote port!\n");
2882 return;
2883 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002884 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002885 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002887
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002888 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002889
2890 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002891 if (fcport->port_type == FCT_INITIATOR)
2892 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2893 if (fcport->port_type == FCT_TARGET)
2894 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002895 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002896}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897
2898/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002899 * qla2x00_update_fcport
2900 * Updates device on list.
2901 *
2902 * Input:
2903 * ha = adapter block pointer.
2904 * fcport = port structure pointer.
2905 *
2906 * Return:
2907 * 0 - Success
2908 * BIT_0 - error
2909 *
2910 * Context:
2911 * Kernel context.
2912 */
2913void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002914qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002915{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002919 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002921 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002922 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002923 PORT_RETRY_TIME);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002924 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002925
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002927
2928 atomic_set(&fcport->state, FCS_ONLINE);
2929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002931}
2932
2933/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002934 * qla2x00_configure_fabric
2935 * Setup SNS devices with loop ID's.
2936 *
2937 * Input:
2938 * ha = adapter block pointer.
2939 *
2940 * Returns:
2941 * 0 = success.
2942 * BIT_0 = error
2943 */
2944static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002945qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946{
2947 int rval, rval2;
2948 fc_port_t *fcport, *fcptemp;
2949 uint16_t next_loopid;
2950 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002951 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 struct qla_hw_data *ha = vha->hw;
2954 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955
2956 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002957 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002958 loop_id = NPH_F_PORT;
2959 else
2960 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 if (rval != QLA_SUCCESS) {
2963 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 return (QLA_SUCCESS);
2968 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002969 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970
2971 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 if (rval2 == QLA_RSCNS_HANDLED) {
2974 /* No point doing the scan, just continue. */
2975 return (QLA_SUCCESS);
2976 }
2977 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002978 /* FDMI support. */
2979 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2981 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002982
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002984 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002985 loop_id = NPH_SNS;
2986 else
2987 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002988 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002989 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 if (mb[0] != MBS_COMMAND_COMPLETE) {
2991 DEBUG2(qla_printk(KERN_INFO, ha,
2992 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002993 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 mb[0], mb[1], mb[2], mb[6], mb[7]));
2995 return (QLA_SUCCESS);
2996 }
2997
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2999 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 /* EMPTY */
3001 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 /* EMPTY */
3006 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 /* EMPTY */
3011 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003012 "failed.\n", vha->host_no));
3013 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 /* EMPTY */
3015 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 }
3018 }
3019
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 if (rval != QLA_SUCCESS)
3022 break;
3023
3024 /*
3025 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003026 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3029 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 break;
3031
3032 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3033 continue;
3034
3035 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003037 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003039 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 fcport->port_type != FCT_INITIATOR &&
3041 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003043 fcport->loop_id,
3044 fcport->d_id.b.domain,
3045 fcport->d_id.b.area,
3046 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 fcport->loop_id = FC_NO_LOOP_ID;
3048 }
3049 }
3050 }
3051
3052 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054
3055 /*
3056 * Scan through our port list and login entries that need to be
3057 * logged in.
3058 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3060 if (atomic_read(&vha->loop_down_timer) ||
3061 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003062 break;
3063
3064 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3065 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3066 continue;
3067
3068 if (fcport->loop_id == FC_NO_LOOP_ID) {
3069 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003070 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003071 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 if (rval != QLA_SUCCESS) {
3073 /* Ran out of IDs to use */
3074 break;
3075 }
3076 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003077 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003078 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 }
3080
3081 /* Exit if out of loop IDs. */
3082 if (rval != QLA_SUCCESS) {
3083 break;
3084 }
3085
3086 /*
3087 * Login and add the new devices to our port list.
3088 */
3089 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003090 if (atomic_read(&vha->loop_down_timer) ||
3091 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 break;
3093
3094 /* Find a new loop ID to use. */
3095 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 if (rval != QLA_SUCCESS) {
3098 /* Ran out of IDs to use */
3099 break;
3100 }
3101
bdf79622005-04-17 15:06:53 -05003102 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003103 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003104
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003105 if (vha->vp_idx) {
3106 fcport->vha = vha;
3107 fcport->vp_idx = vha->vp_idx;
3108 }
3109 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 }
3111 } while (0);
3112
3113 /* Free all new device structures not processed. */
3114 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3115 list_del(&fcport->list);
3116 kfree(fcport);
3117 }
3118
3119 if (rval) {
3120 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003121 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003122 }
3123
3124 return (rval);
3125}
3126
3127
3128/*
3129 * qla2x00_find_all_fabric_devs
3130 *
3131 * Input:
3132 * ha = adapter block pointer.
3133 * dev = database device entry pointer.
3134 *
3135 * Returns:
3136 * 0 = success.
3137 *
3138 * Context:
3139 * Kernel context.
3140 */
3141static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003142qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3143 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144{
3145 int rval;
3146 uint16_t loop_id;
3147 fc_port_t *fcport, *new_fcport, *fcptemp;
3148 int found;
3149
3150 sw_info_t *swl;
3151 int swl_idx;
3152 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003153 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003154 struct qla_hw_data *ha = vha->hw;
3155 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003156 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157
3158 rval = QLA_SUCCESS;
3159
3160 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003161 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003162 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163 /*EMPTY*/
3164 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003165 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003167 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 kfree(swl);
3169 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171 kfree(swl);
3172 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 kfree(swl);
3175 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003176 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003177 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3178 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 }
3180 }
3181 swl_idx = 0;
3182
3183 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003186 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 return (QLA_MEMORY_ALLOC_FAILED);
3188 }
3189 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190 /* Set start port ID scan at adapter ID. */
3191 first_dev = 1;
3192 last_dev = 0;
3193
3194 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003195 loop_id = ha->min_external_loopid;
3196 for (; loop_id <= ha->max_loop_id; loop_id++) {
3197 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 continue;
3199
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003200 if (atomic_read(&vha->loop_down_timer) ||
3201 LOOP_TRANSITION(vha)) {
3202 atomic_set(&vha->loop_down_timer, 0);
3203 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3204 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
3208 if (swl != NULL) {
3209 if (last_dev) {
3210 wrap.b24 = new_fcport->d_id.b24;
3211 } else {
3212 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3213 memcpy(new_fcport->node_name,
3214 swl[swl_idx].node_name, WWN_SIZE);
3215 memcpy(new_fcport->port_name,
3216 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003217 memcpy(new_fcport->fabric_port_name,
3218 swl[swl_idx].fabric_port_name, WWN_SIZE);
3219 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003220
3221 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3222 last_dev = 1;
3223 }
3224 swl_idx++;
3225 }
3226 } else {
3227 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 if (rval != QLA_SUCCESS) {
3230 qla_printk(KERN_WARNING, ha,
3231 "SNS scan failed -- assuming zero-entry "
3232 "result...\n");
3233 list_for_each_entry_safe(fcport, fcptemp,
3234 new_fcports, list) {
3235 list_del(&fcport->list);
3236 kfree(fcport);
3237 }
3238 rval = QLA_SUCCESS;
3239 break;
3240 }
3241 }
3242
3243 /* If wrap on switch device list, exit. */
3244 if (first_dev) {
3245 wrap.b24 = new_fcport->d_id.b24;
3246 first_dev = 0;
3247 } else if (new_fcport->d_id.b24 == wrap.b24) {
3248 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3251 break;
3252 }
3253
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003254 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 continue;
3257
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003258 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 found = 0;
3260 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003261 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003262 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3263 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003264 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003265 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003266 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003268 continue;
3269 }
3270
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003271 /* Bypass if same domain and area of adapter. */
3272 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003274 ISP_CFG_FL)
3275 continue;
3276
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 /* Bypass reserved domain fields. */
3278 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3279 continue;
3280
3281 /* Locate matching device in database. */
3282 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003283 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 if (memcmp(new_fcport->port_name, fcport->port_name,
3285 WWN_SIZE))
3286 continue;
3287
3288 found++;
3289
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003290 /* Update port state. */
3291 memcpy(fcport->fabric_port_name,
3292 new_fcport->fabric_port_name, WWN_SIZE);
3293 fcport->fp_speed = new_fcport->fp_speed;
3294
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 /*
3296 * If address the same and state FCS_ONLINE, nothing
3297 * changed.
3298 */
3299 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3300 atomic_read(&fcport->state) == FCS_ONLINE) {
3301 break;
3302 }
3303
3304 /*
3305 * If device was not a fabric device before.
3306 */
3307 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3308 fcport->d_id.b24 = new_fcport->d_id.b24;
3309 fcport->loop_id = FC_NO_LOOP_ID;
3310 fcport->flags |= (FCF_FABRIC_DEVICE |
3311 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 break;
3313 }
3314
3315 /*
3316 * Port ID changed or device was marked to be updated;
3317 * Log it out if still logged in and mark it for
3318 * relogin later.
3319 */
3320 fcport->d_id.b24 = new_fcport->d_id.b24;
3321 fcport->flags |= FCF_LOGIN_NEEDED;
3322 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003323 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 fcport->port_type != FCT_INITIATOR &&
3325 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003326 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003327 fcport->d_id.b.domain, fcport->d_id.b.area,
3328 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 fcport->loop_id = FC_NO_LOOP_ID;
3330 }
3331
3332 break;
3333 }
3334
3335 if (found)
3336 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 /* If device was not in our fcports list, then add it. */
3338 list_add_tail(&new_fcport->list, new_fcports);
3339
3340 /* Allocate a new replacement fcport. */
3341 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003344 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 return (QLA_MEMORY_ALLOC_FAILED);
3346 }
3347 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3348 new_fcport->d_id.b24 = nxt_d_id.b24;
3349 }
3350
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003351 kfree(swl);
3352 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 return (rval);
3355}
3356
3357/*
3358 * qla2x00_find_new_loop_id
3359 * Scan through our port list and find a new usable loop ID.
3360 *
3361 * Input:
3362 * ha: adapter state pointer.
3363 * dev: port structure pointer.
3364 *
3365 * Returns:
3366 * qla2x00 local function return status code.
3367 *
3368 * Context:
3369 * Kernel context.
3370 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003371static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373{
3374 int rval;
3375 int found;
3376 fc_port_t *fcport;
3377 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 struct qla_hw_data *ha = vha->hw;
3379 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003380 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381
3382 rval = QLA_SUCCESS;
3383
3384 /* Save starting loop ID. */
3385 first_loop_id = dev->loop_id;
3386
3387 for (;;) {
3388 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
3392 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003393 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 /* first loop ID. */
3399 dev->loop_id = ha->min_external_loopid;
3400 }
3401
3402 /* Check for loop ID being already in use. */
3403 found = 0;
3404 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003405 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003406 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3407 if (fcport->loop_id == dev->loop_id &&
3408 fcport != dev) {
3409 /* ID possibly in use */
3410 found++;
3411 break;
3412 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 if (found)
3415 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 }
3417
3418 /* If not in use then it is free to use. */
3419 if (!found) {
3420 break;
3421 }
3422
3423 /* ID in use. Try next value. */
3424 dev->loop_id++;
3425
3426 /* If wrap around. No free ID to use. */
3427 if (dev->loop_id == first_loop_id) {
3428 dev->loop_id = FC_NO_LOOP_ID;
3429 rval = QLA_FUNCTION_FAILED;
3430 break;
3431 }
3432 }
3433
3434 return (rval);
3435}
3436
3437/*
3438 * qla2x00_device_resync
3439 * Marks devices in the database that needs resynchronization.
3440 *
3441 * Input:
3442 * ha = adapter block pointer.
3443 *
3444 * Context:
3445 * Kernel context.
3446 */
3447static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449{
3450 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 uint32_t mask;
3452 fc_port_t *fcport;
3453 uint32_t rscn_entry;
3454 uint8_t rscn_out_iter;
3455 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003456 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457
3458 rval = QLA_RSCNS_HANDLED;
3459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3461 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003463 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 format = MSB(MSW(rscn_entry));
3465 d_id.b.domain = LSB(MSW(rscn_entry));
3466 d_id.b.area = MSB(LSW(rscn_entry));
3467 d_id.b.al_pa = LSB(LSW(rscn_entry));
3468
3469 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3470 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003471 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003472 d_id.b.area, d_id.b.al_pa));
3473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003474 vha->rscn_out_ptr++;
3475 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3476 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
3478 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003479 for (rscn_out_iter = vha->rscn_out_ptr;
3480 !vha->flags.rscn_queue_overflow &&
3481 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 rscn_out_iter = (rscn_out_iter ==
3483 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 break;
3487
3488 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490 rscn_out_iter));
3491
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003492 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493 }
3494
3495 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003496 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499
3500 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003501 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003502 }
3503
3504 switch (format) {
3505 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506 mask = 0xffffff;
3507 break;
3508 case 1:
3509 mask = 0xffff00;
3510 break;
3511 case 2:
3512 mask = 0xff0000;
3513 break;
3514 default:
3515 mask = 0x0;
3516 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 break;
3519 }
3520
3521 rval = QLA_SUCCESS;
3522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003523 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3525 (fcport->d_id.b24 & mask) != d_id.b24 ||
3526 fcport->port_type == FCT_BROADCAST)
3527 continue;
3528
3529 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3530 if (format != 3 ||
3531 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003533 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 }
3535 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 }
3537 }
3538 return (rval);
3539}
3540
3541/*
3542 * qla2x00_fabric_dev_login
3543 * Login fabric target device and update FC port database.
3544 *
3545 * Input:
3546 * ha: adapter state pointer.
3547 * fcport: port structure list pointer.
3548 * next_loopid: contains value of a new loop ID that can be used
3549 * by the next login attempt.
3550 *
3551 * Returns:
3552 * qla2x00 local function return status code.
3553 *
3554 * Context:
3555 * Kernel context.
3556 */
3557static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559 uint16_t *next_loopid)
3560{
3561 int rval;
3562 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003563 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003564 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003565
3566 rval = QLA_SUCCESS;
3567 retry = 0;
3568
Andrew Vasquezac280b62009-08-20 11:06:05 -07003569 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003570 if (fcport->flags & FCF_ASYNC_SENT)
3571 return rval;
3572 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003573 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3574 if (!rval)
3575 return rval;
3576 }
3577
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003578 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003581 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003582 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003583 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003584 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003585 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003586 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003588 fcport->d_id.b.domain, fcport->d_id.b.area,
3589 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003590 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003591 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003592 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 }
3594 }
3595
3596 return (rval);
3597}
3598
3599/*
3600 * qla2x00_fabric_login
3601 * Issue fabric login command.
3602 *
3603 * Input:
3604 * ha = adapter block pointer.
3605 * device = pointer to FC device type structure.
3606 *
3607 * Returns:
3608 * 0 - Login successfully
3609 * 1 - Login failed
3610 * 2 - Initiator device
3611 * 3 - Fatal error
3612 */
3613int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003614qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 uint16_t *next_loopid)
3616{
3617 int rval;
3618 int retry;
3619 uint16_t tmp_loopid;
3620 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003621 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003622
3623 retry = 0;
3624 tmp_loopid = 0;
3625
3626 for (;;) {
3627 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3628 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003629 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3631
3632 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003633 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634 fcport->d_id.b.domain, fcport->d_id.b.area,
3635 fcport->d_id.b.al_pa, mb, BIT_0);
3636 if (mb[0] == MBS_PORT_ID_USED) {
3637 /*
3638 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003639 * recommends the driver perform an implicit login with
3640 * the specified ID again. The ID we just used is save
3641 * here so we return with an ID that can be tried by
3642 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 */
3644 retry++;
3645 tmp_loopid = fcport->loop_id;
3646 fcport->loop_id = mb[1];
3647
3648 DEBUG(printk("Fabric Login: port in use - next "
3649 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3650 fcport->loop_id, fcport->d_id.b.domain,
3651 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3652
3653 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3654 /*
3655 * Login succeeded.
3656 */
3657 if (retry) {
3658 /* A retry occurred before. */
3659 *next_loopid = tmp_loopid;
3660 } else {
3661 /*
3662 * No retry occurred before. Just increment the
3663 * ID value for next login.
3664 */
3665 *next_loopid = (fcport->loop_id + 1);
3666 }
3667
3668 if (mb[1] & BIT_0) {
3669 fcport->port_type = FCT_INITIATOR;
3670 } else {
3671 fcport->port_type = FCT_TARGET;
3672 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003673 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003674 }
3675 }
3676
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003677 if (mb[10] & BIT_0)
3678 fcport->supported_classes |= FC_COS_CLASS2;
3679 if (mb[10] & BIT_1)
3680 fcport->supported_classes |= FC_COS_CLASS3;
3681
Linus Torvalds1da177e2005-04-16 15:20:36 -07003682 rval = QLA_SUCCESS;
3683 break;
3684 } else if (mb[0] == MBS_LOOP_ID_USED) {
3685 /*
3686 * Loop ID already used, try next loop ID.
3687 */
3688 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003689 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003690 if (rval != QLA_SUCCESS) {
3691 /* Ran out of loop IDs to use */
3692 break;
3693 }
3694 } else if (mb[0] == MBS_COMMAND_ERROR) {
3695 /*
3696 * Firmware possibly timed out during login. If NO
3697 * retries are left to do then the device is declared
3698 * dead.
3699 */
3700 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003701 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003702 fcport->d_id.b.domain, fcport->d_id.b.area,
3703 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003704 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003705
3706 rval = 1;
3707 break;
3708 } else {
3709 /*
3710 * unrecoverable / not handled error
3711 */
3712 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003713 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003714 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003715 fcport->d_id.b.domain, fcport->d_id.b.area,
3716 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3717
3718 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003719 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003720 fcport->d_id.b.domain, fcport->d_id.b.area,
3721 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003723 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724
3725 rval = 3;
3726 break;
3727 }
3728 }
3729
3730 return (rval);
3731}
3732
3733/*
3734 * qla2x00_local_device_login
3735 * Issue local device login command.
3736 *
3737 * Input:
3738 * ha = adapter block pointer.
3739 * loop_id = loop id of device to login to.
3740 *
3741 * Returns (Where's the #define!!!!):
3742 * 0 - Login successfully
3743 * 1 - Login failed
3744 * 3 - Fatal error
3745 */
3746int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003747qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748{
3749 int rval;
3750 uint16_t mb[MAILBOX_REGISTER_COUNT];
3751
3752 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003753 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 if (rval == QLA_SUCCESS) {
3755 /* Interrogate mailbox registers for any errors */
3756 if (mb[0] == MBS_COMMAND_ERROR)
3757 rval = 1;
3758 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3759 /* device not in PCB table */
3760 rval = 3;
3761 }
3762
3763 return (rval);
3764}
3765
3766/*
3767 * qla2x00_loop_resync
3768 * Resync with fibre channel devices.
3769 *
3770 * Input:
3771 * ha = adapter block pointer.
3772 *
3773 * Returns:
3774 * 0 = success
3775 */
3776int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003779 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003781 struct req_que *req;
3782 struct rsp_que *rsp;
3783
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003784 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003785 req = vha->hw->req_q_map[0];
3786 else
3787 req = vha->req;
3788 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003789
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003790 atomic_set(&vha->loop_state, LOOP_UPDATE);
3791 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3792 if (vha->flags.online) {
3793 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3795 wait_time = 256;
3796 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003797 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003799 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003800 qla2x00_marker(vha, req, rsp, 0, 0,
3801 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003802 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803
3804 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003805 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003807 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 } while (!atomic_read(&vha->loop_down_timer) &&
3810 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3811 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3812 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003813 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003814 }
3815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003818
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003821
3822 return (rval);
3823}
3824
Linus Torvalds1da177e2005-04-16 15:20:36 -07003825void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003826qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003827{
3828 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003829 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003830
3831 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003832 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3833 list_for_each_entry(fcport, &vha->vp_fcports, list)
3834 if (fcport && fcport->drport &&
3835 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3836 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003837}
3838
Giridhar Malavalia9083012010-04-12 17:59:55 -07003839void
3840qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3841{
3842 struct qla_hw_data *ha = vha->hw;
3843 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3844 struct scsi_qla_host *tvp;
3845
3846 vha->flags.online = 0;
3847 ha->flags.chip_reset_done = 0;
3848 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3849 ha->qla_stats.total_isp_aborts++;
3850
3851 qla_printk(KERN_INFO, ha,
3852 "Performing ISP error recovery - ha= %p.\n", ha);
3853
3854 /* Chip reset does not apply to 82XX */
3855 if (!IS_QLA82XX(ha))
3856 ha->isp_ops->reset_chip(vha);
3857
3858 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3859 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3860 atomic_set(&vha->loop_state, LOOP_DOWN);
3861 qla2x00_mark_all_devices_lost(vha, 0);
3862 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3863 qla2x00_mark_all_devices_lost(vp, 0);
3864 } else {
3865 if (!atomic_read(&vha->loop_down_timer))
3866 atomic_set(&vha->loop_down_timer,
3867 LOOP_DOWN_TIME);
3868 }
3869
3870 /* Make sure for ISP 82XX IO DMA is complete */
3871 if (IS_QLA82XX(ha))
3872 qla82xx_wait_for_pending_commands(vha);
3873
3874 /* Requeue all commands in outstanding command list. */
3875 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3876}
3877
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878/*
3879* qla2x00_abort_isp
3880* Resets ISP and aborts all outstanding commands.
3881*
3882* Input:
3883* ha = adapter block pointer.
3884*
3885* Returns:
3886* 0 = success
3887*/
3888int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003889qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003890{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003891 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003893 struct qla_hw_data *ha = vha->hw;
3894 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003895 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003896 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003898 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003899 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003900
Andrew Vasquez85880802009-12-15 21:29:46 -08003901 if (unlikely(pci_channel_offline(ha->pdev) &&
3902 ha->flags.pci_channel_io_perm_failure)) {
3903 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3904 status = 0;
3905 return status;
3906 }
3907
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003908 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003909
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003910 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 if (!qla2x00_restart_isp(vha)) {
3913 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916 /*
3917 * Issue marker command only when we are going
3918 * to start the I/O .
3919 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003920 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003921 }
3922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003923 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003924
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003925 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003927 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003928 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003929
Lalit Chandivade29c53972009-10-13 15:16:47 -07003930 if (IS_QLA81XX(ha))
3931 qla2x00_get_fw_version(vha,
3932 &ha->fw_major_version,
3933 &ha->fw_minor_version,
3934 &ha->fw_subminor_version,
3935 &ha->fw_attributes, &ha->fw_memory_size,
3936 ha->mpi_version, &ha->mpi_capabilities,
3937 ha->phy_version);
3938
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003939 if (ha->fce) {
3940 ha->flags.fce_enabled = 1;
3941 memset(ha->fce, 0,
3942 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003943 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003944 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3945 &ha->fce_bufs);
3946 if (rval) {
3947 qla_printk(KERN_WARNING, ha,
3948 "Unable to reinitialize FCE "
3949 "(%d).\n", rval);
3950 ha->flags.fce_enabled = 0;
3951 }
3952 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003953
3954 if (ha->eft) {
3955 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003957 ha->eft_dma, EFT_NUM_BUFFERS);
3958 if (rval) {
3959 qla_printk(KERN_WARNING, ha,
3960 "Unable to reinitialize EFT "
3961 "(%d).\n", rval);
3962 }
3963 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003964 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003965 vha->flags.online = 1;
3966 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967 if (ha->isp_abort_cnt == 0) {
3968 qla_printk(KERN_WARNING, ha,
3969 "ISP error recovery failed - "
3970 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003971 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 * The next call disables the board
3973 * completely.
3974 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003975 ha->isp_ops->reset_adapter(vha);
3976 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003978 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 status = 0;
3980 } else { /* schedule another ISP abort */
3981 ha->isp_abort_cnt--;
3982 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003983 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003984 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003985 status = 1;
3986 }
3987 } else {
3988 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3989 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3990 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003991 vha->host_no, ha->isp_abort_cnt));
3992 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 status = 1;
3994 }
3995 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003996
Linus Torvalds1da177e2005-04-16 15:20:36 -07003997 }
3998
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003999 if (!status) {
4000 DEBUG(printk(KERN_INFO
4001 "qla2x00_abort_isp(%ld): succeeded.\n",
4002 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08004003 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 if (vp->vp_idx)
4005 qla2x00_vp_abort_isp(vp);
4006 }
4007 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 qla_printk(KERN_INFO, ha,
4009 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 }
4011
4012 return(status);
4013}
4014
4015/*
4016* qla2x00_restart_isp
4017* restarts the ISP after a reset
4018*
4019* Input:
4020* ha = adapter block pointer.
4021*
4022* Returns:
4023* 0 = success
4024*/
4025static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004028 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004030 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004031 struct req_que *req = ha->req_q_map[0];
4032 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004033
4034 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 if (qla2x00_isp_firmware(vha)) {
4036 vha->flags.online = 0;
4037 status = ha->isp_ops->chip_diag(vha);
4038 if (!status)
4039 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004040 }
4041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004042 if (!status && !(status = qla2x00_init_rings(vha))) {
4043 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004044 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004045 /* Initialize the queues in use */
4046 qla25xx_init_queues(ha);
4047
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004048 status = qla2x00_fw_ready(vha);
4049 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004050 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004051 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004052
4053 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004054 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4058 wait_time = 256;
4059 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004060 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4061 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004062 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004063 } while (!atomic_read(&vha->loop_down_timer) &&
4064 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4065 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4066 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004067 }
4068
4069 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004070 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 status = 0;
4072
4073 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4074 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004075 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 }
4077 return (status);
4078}
4079
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004080static int
4081qla25xx_init_queues(struct qla_hw_data *ha)
4082{
4083 struct rsp_que *rsp = NULL;
4084 struct req_que *req = NULL;
4085 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4086 int ret = -1;
4087 int i;
4088
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004089 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004090 rsp = ha->rsp_q_map[i];
4091 if (rsp) {
4092 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004093 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004094 if (ret != QLA_SUCCESS)
4095 DEBUG2_17(printk(KERN_WARNING
4096 "%s Rsp que:%d init failed\n", __func__,
4097 rsp->id));
4098 else
4099 DEBUG2_17(printk(KERN_INFO
4100 "%s Rsp que:%d inited\n", __func__,
4101 rsp->id));
4102 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004103 }
4104 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004105 req = ha->req_q_map[i];
4106 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004107 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004108 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004109 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004110 if (ret != QLA_SUCCESS)
4111 DEBUG2_17(printk(KERN_WARNING
4112 "%s Req que:%d init failed\n", __func__,
4113 req->id));
4114 else
4115 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004116 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004117 req->id));
4118 }
4119 }
4120 return ret;
4121}
4122
Linus Torvalds1da177e2005-04-16 15:20:36 -07004123/*
4124* qla2x00_reset_adapter
4125* Reset adapter.
4126*
4127* Input:
4128* ha = adapter block pointer.
4129*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004130void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004131qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132{
4133 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004134 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004135 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004136
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004138 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004139
Linus Torvalds1da177e2005-04-16 15:20:36 -07004140 spin_lock_irqsave(&ha->hardware_lock, flags);
4141 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4142 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4143 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4144 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4145 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4146}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004147
4148void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004149qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004150{
4151 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004152 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004153 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4154
Giridhar Malavalia9083012010-04-12 17:59:55 -07004155 if (IS_QLA82XX(ha))
4156 return;
4157
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004159 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004160
4161 spin_lock_irqsave(&ha->hardware_lock, flags);
4162 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4163 RD_REG_DWORD(&reg->hccr);
4164 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4165 RD_REG_DWORD(&reg->hccr);
4166 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004167
4168 if (IS_NOPOLLING_TYPE(ha))
4169 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004170}
4171
David Miller4e08df32007-04-16 12:37:43 -07004172/* On sparc systems, obtain port and node WWN from firmware
4173 * properties.
4174 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004175static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4176 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004177{
4178#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004179 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004180 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004181 struct device_node *dp = pci_device_to_OF_node(pdev);
4182 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004183 int len;
4184
4185 val = of_get_property(dp, "port-wwn", &len);
4186 if (val && len >= WWN_SIZE)
4187 memcpy(nv->port_name, val, WWN_SIZE);
4188
4189 val = of_get_property(dp, "node-wwn", &len);
4190 if (val && len >= WWN_SIZE)
4191 memcpy(nv->node_name, val, WWN_SIZE);
4192#endif
4193}
4194
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004195int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004196qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004197{
David Miller4e08df32007-04-16 12:37:43 -07004198 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004199 struct init_cb_24xx *icb;
4200 struct nvram_24xx *nv;
4201 uint32_t *dptr;
4202 uint8_t *dptr1, *dptr2;
4203 uint32_t chksum;
4204 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004205 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004206
David Miller4e08df32007-04-16 12:37:43 -07004207 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004208 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004209 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004210
4211 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004212 if (ha->flags.port0) {
4213 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4214 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4215 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004216 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004217 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4218 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004219 ha->nvram_size = sizeof(struct nvram_24xx);
4220 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004221 if (IS_QLA82XX(ha))
4222 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004223
Seokmann Ju281afe12007-07-26 13:43:34 -07004224 /* Get VPD data into cache */
4225 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004226 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004227 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4228
4229 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004230 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004231 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004232 ha->nvram_size);
4233 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4234 chksum += le32_to_cpu(*dptr++);
4235
Andrew Vasquez76403352009-04-06 22:33:39 -07004236 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004237 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004238
4239 /* Bad NVRAM data, set defaults parameters. */
4240 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4241 || nv->id[3] != ' ' ||
4242 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4243 /* Reset NVRAM data. */
4244 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4245 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4246 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004247 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4248 "invalid -- WWPN) defaults.\n");
4249
4250 /*
4251 * Set default initialization control block.
4252 */
4253 memset(nv, 0, ha->nvram_size);
4254 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4255 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4256 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4257 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4258 nv->exchange_count = __constant_cpu_to_le16(0);
4259 nv->hard_address = __constant_cpu_to_le16(124);
4260 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004261 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004262 nv->port_name[2] = 0x00;
4263 nv->port_name[3] = 0xe0;
4264 nv->port_name[4] = 0x8b;
4265 nv->port_name[5] = 0x1c;
4266 nv->port_name[6] = 0x55;
4267 nv->port_name[7] = 0x86;
4268 nv->node_name[0] = 0x20;
4269 nv->node_name[1] = 0x00;
4270 nv->node_name[2] = 0x00;
4271 nv->node_name[3] = 0xe0;
4272 nv->node_name[4] = 0x8b;
4273 nv->node_name[5] = 0x1c;
4274 nv->node_name[6] = 0x55;
4275 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004276 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004277 nv->login_retry_count = __constant_cpu_to_le16(8);
4278 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4279 nv->login_timeout = __constant_cpu_to_le16(0);
4280 nv->firmware_options_1 =
4281 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4282 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4283 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4284 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4285 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4286 nv->efi_parameters = __constant_cpu_to_le32(0);
4287 nv->reset_delay = 5;
4288 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4289 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4290 nv->link_down_timeout = __constant_cpu_to_le16(30);
4291
4292 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004293 }
4294
4295 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004296 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004297
4298 /* Copy 1st segment. */
4299 dptr1 = (uint8_t *)icb;
4300 dptr2 = (uint8_t *)&nv->version;
4301 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4302 while (cnt--)
4303 *dptr1++ = *dptr2++;
4304
4305 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004306 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004307
4308 /* Copy 2nd segment. */
4309 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4310 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4311 cnt = (uint8_t *)&icb->reserved_3 -
4312 (uint8_t *)&icb->interrupt_delay_timer;
4313 while (cnt--)
4314 *dptr1++ = *dptr2++;
4315
4316 /*
4317 * Setup driver NVRAM options.
4318 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004319 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004320 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004321
Andrew Vasquez5341e862006-05-17 15:09:16 -07004322 /* Use alternate WWN? */
4323 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4324 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4325 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4326 }
4327
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004328 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004329 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004330 /*
4331 * Firmware will apply the following mask if the nodename was
4332 * not provided.
4333 */
4334 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4335 icb->node_name[0] &= 0xF0;
4336 }
4337
4338 /* Set host adapter parameters. */
4339 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004340 ha->flags.enable_lip_reset = 0;
4341 ha->flags.enable_lip_full_login =
4342 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4343 ha->flags.enable_target_reset =
4344 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004345 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004346 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004347
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004348 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4349 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004350
4351 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4352 sizeof(ha->fw_seriallink_options24));
4353
4354 /* save HBA serial number */
4355 ha->serial0 = icb->port_name[5];
4356 ha->serial1 = icb->port_name[6];
4357 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004358 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4359 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004360
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004361 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4362
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004363 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4364
4365 /* Set minimum login_timeout to 4 seconds. */
4366 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4367 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4368 if (le16_to_cpu(nv->login_timeout) < 4)
4369 nv->login_timeout = __constant_cpu_to_le16(4);
4370 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004371 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004372
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004373 /* Set minimum RATOV to 100 tenths of a second. */
4374 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004375
4376 ha->loop_reset_delay = nv->reset_delay;
4377
4378 /* Link Down Timeout = 0:
4379 *
4380 * When Port Down timer expires we will start returning
4381 * I/O's to OS with "DID_NO_CONNECT".
4382 *
4383 * Link Down Timeout != 0:
4384 *
4385 * The driver waits for the link to come up after link down
4386 * before returning I/Os to OS with "DID_NO_CONNECT".
4387 */
4388 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4389 ha->loop_down_abort_time =
4390 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4391 } else {
4392 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4393 ha->loop_down_abort_time =
4394 (LOOP_DOWN_TIME - ha->link_down_timeout);
4395 }
4396
4397 /* Need enough time to try and get the port back. */
4398 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4399 if (qlport_down_retry)
4400 ha->port_down_retry_count = qlport_down_retry;
4401
4402 /* Set login_retry_count */
4403 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4404 if (ha->port_down_retry_count ==
4405 le16_to_cpu(nv->port_down_retry_count) &&
4406 ha->port_down_retry_count > 3)
4407 ha->login_retry_count = ha->port_down_retry_count;
4408 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4409 ha->login_retry_count = ha->port_down_retry_count;
4410 if (ql2xloginretrycount)
4411 ha->login_retry_count = ql2xloginretrycount;
4412
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004413 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004414 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004415 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4416 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4417 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4418 le16_to_cpu(icb->interrupt_delay_timer): 2;
4419 }
4420 icb->firmware_options_2 &= __constant_cpu_to_le32(
4421 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004422 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004423 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004424 ha->zio_mode = QLA_ZIO_MODE_6;
4425
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004426 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004427 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004428 ha->zio_timer * 100));
4429 qla_printk(KERN_INFO, ha,
4430 "ZIO mode %d enabled; timer delay (%d us).\n",
4431 ha->zio_mode, ha->zio_timer * 100);
4432
4433 icb->firmware_options_2 |= cpu_to_le32(
4434 (uint32_t)ha->zio_mode);
4435 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004436 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004437 }
4438
David Miller4e08df32007-04-16 12:37:43 -07004439 if (rval) {
4440 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004441 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004442 }
4443 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004444}
4445
Adrian Bunk413975a2006-06-30 02:33:06 -07004446static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004447qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4448 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004449{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004450 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004451 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004452 uint32_t *dcode, dlen;
4453 uint32_t risc_addr;
4454 uint32_t risc_size;
4455 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004456 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004457 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004458
4459 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004460 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004461
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004462 rval = QLA_SUCCESS;
4463
4464 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004465 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004466 *srisc_addr = 0;
4467
4468 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004469 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004470 for (i = 0; i < 4; i++)
4471 dcode[i] = be32_to_cpu(dcode[i]);
4472 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4473 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4474 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4475 dcode[3] == 0)) {
4476 qla_printk(KERN_WARNING, ha,
4477 "Unable to verify integrity of flash firmware image!\n");
4478 qla_printk(KERN_WARNING, ha,
4479 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4480 dcode[1], dcode[2], dcode[3]);
4481
4482 return QLA_FUNCTION_FAILED;
4483 }
4484
4485 while (segments && rval == QLA_SUCCESS) {
4486 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004487 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004488
4489 risc_addr = be32_to_cpu(dcode[2]);
4490 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4491 risc_size = be32_to_cpu(dcode[3]);
4492
4493 fragment = 0;
4494 while (risc_size > 0 && rval == QLA_SUCCESS) {
4495 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4496 if (dlen > risc_size)
4497 dlen = risc_size;
4498
4499 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4500 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004501 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004502
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004504 for (i = 0; i < dlen; i++)
4505 dcode[i] = swab32(dcode[i]);
4506
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004507 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004508 dlen);
4509 if (rval) {
4510 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004511 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004512 fragment));
4513 qla_printk(KERN_WARNING, ha,
4514 "[ERROR] Failed to load segment %d of "
4515 "firmware\n", fragment);
4516 break;
4517 }
4518
4519 faddr += dlen;
4520 risc_addr += dlen;
4521 risc_size -= dlen;
4522 fragment++;
4523 }
4524
4525 /* Next segment. */
4526 segments--;
4527 }
4528
4529 return rval;
4530}
4531
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004532#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4533
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004534int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004535qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004536{
4537 int rval;
4538 int i, fragment;
4539 uint16_t *wcode, *fwcode;
4540 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4541 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004542 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004543 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004544
4545 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004546 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004547 if (!blob) {
4548 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004549 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4550 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004551 return QLA_FUNCTION_FAILED;
4552 }
4553
4554 rval = QLA_SUCCESS;
4555
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004556 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004557 *srisc_addr = 0;
4558 fwcode = (uint16_t *)blob->fw->data;
4559 fwclen = 0;
4560
4561 /* Validate firmware image by checking version. */
4562 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4563 qla_printk(KERN_WARNING, ha,
4564 "Unable to verify integrity of firmware image (%Zd)!\n",
4565 blob->fw->size);
4566 goto fail_fw_integrity;
4567 }
4568 for (i = 0; i < 4; i++)
4569 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4570 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4571 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4572 wcode[2] == 0 && wcode[3] == 0)) {
4573 qla_printk(KERN_WARNING, ha,
4574 "Unable to verify integrity of firmware image!\n");
4575 qla_printk(KERN_WARNING, ha,
4576 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4577 wcode[1], wcode[2], wcode[3]);
4578 goto fail_fw_integrity;
4579 }
4580
4581 seg = blob->segs;
4582 while (*seg && rval == QLA_SUCCESS) {
4583 risc_addr = *seg;
4584 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4585 risc_size = be16_to_cpu(fwcode[3]);
4586
4587 /* Validate firmware image size. */
4588 fwclen += risc_size * sizeof(uint16_t);
4589 if (blob->fw->size < fwclen) {
4590 qla_printk(KERN_WARNING, ha,
4591 "Unable to verify integrity of firmware image "
4592 "(%Zd)!\n", blob->fw->size);
4593 goto fail_fw_integrity;
4594 }
4595
4596 fragment = 0;
4597 while (risc_size > 0 && rval == QLA_SUCCESS) {
4598 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4599 if (wlen > risc_size)
4600 wlen = risc_size;
4601
4602 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004603 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004604 risc_addr, wlen));
4605
4606 for (i = 0; i < wlen; i++)
4607 wcode[i] = swab16(fwcode[i]);
4608
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004609 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004610 wlen);
4611 if (rval) {
4612 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004613 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004614 fragment));
4615 qla_printk(KERN_WARNING, ha,
4616 "[ERROR] Failed to load segment %d of "
4617 "firmware\n", fragment);
4618 break;
4619 }
4620
4621 fwcode += wlen;
4622 risc_addr += wlen;
4623 risc_size -= wlen;
4624 fragment++;
4625 }
4626
4627 /* Next segment. */
4628 seg++;
4629 }
4630 return rval;
4631
4632fail_fw_integrity:
4633 return QLA_FUNCTION_FAILED;
4634}
4635
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004636static int
4637qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004638{
4639 int rval;
4640 int segments, fragment;
4641 uint32_t *dcode, dlen;
4642 uint32_t risc_addr;
4643 uint32_t risc_size;
4644 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004645 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004646 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004647 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004648 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004649
Andrew Vasquez54333832005-11-09 15:49:04 -08004650 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004651 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004652 if (!blob) {
4653 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004654 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4655 "from: " QLA_FW_URL ".\n");
4656
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004657 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004658 }
4659
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004660 qla_printk(KERN_INFO, ha,
4661 "FW: Loading via request-firmware...\n");
4662
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004663 rval = QLA_SUCCESS;
4664
4665 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004666 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004667 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004668 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004669 fwclen = 0;
4670
4671 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004672 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004673 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004674 "Unable to verify integrity of firmware image (%Zd)!\n",
4675 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004676 goto fail_fw_integrity;
4677 }
4678 for (i = 0; i < 4; i++)
4679 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4680 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4681 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4682 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4683 dcode[3] == 0)) {
4684 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004685 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004686 qla_printk(KERN_WARNING, ha,
4687 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4688 dcode[1], dcode[2], dcode[3]);
4689 goto fail_fw_integrity;
4690 }
4691
4692 while (segments && rval == QLA_SUCCESS) {
4693 risc_addr = be32_to_cpu(fwcode[2]);
4694 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4695 risc_size = be32_to_cpu(fwcode[3]);
4696
4697 /* Validate firmware image size. */
4698 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004699 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004700 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004701 "Unable to verify integrity of firmware image "
4702 "(%Zd)!\n", blob->fw->size);
4703
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004704 goto fail_fw_integrity;
4705 }
4706
4707 fragment = 0;
4708 while (risc_size > 0 && rval == QLA_SUCCESS) {
4709 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4710 if (dlen > risc_size)
4711 dlen = risc_size;
4712
4713 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004714 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004715 risc_addr, dlen));
4716
4717 for (i = 0; i < dlen; i++)
4718 dcode[i] = swab32(fwcode[i]);
4719
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004720 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004721 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004722 if (rval) {
4723 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004724 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004725 fragment));
4726 qla_printk(KERN_WARNING, ha,
4727 "[ERROR] Failed to load segment %d of "
4728 "firmware\n", fragment);
4729 break;
4730 }
4731
4732 fwcode += dlen;
4733 risc_addr += dlen;
4734 risc_size -= dlen;
4735 fragment++;
4736 }
4737
4738 /* Next segment. */
4739 segments--;
4740 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004741 return rval;
4742
4743fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004744 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004745}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004746
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004747int
4748qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4749{
4750 int rval;
4751
Andrew Vasqueze337d902009-04-06 22:33:49 -07004752 if (ql2xfwloadbin == 1)
4753 return qla81xx_load_risc(vha, srisc_addr);
4754
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004755 /*
4756 * FW Load priority:
4757 * 1) Firmware via request-firmware interface (.bin file).
4758 * 2) Firmware residing in flash.
4759 */
4760 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4761 if (rval == QLA_SUCCESS)
4762 return rval;
4763
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004764 return qla24xx_load_risc_flash(vha, srisc_addr,
4765 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004766}
4767
4768int
4769qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4770{
4771 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004772 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004773
Andrew Vasqueze337d902009-04-06 22:33:49 -07004774 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004775 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004776
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004777 /*
4778 * FW Load priority:
4779 * 1) Firmware residing in flash.
4780 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004781 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004782 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004783 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004784 if (rval == QLA_SUCCESS)
4785 return rval;
4786
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004787try_blob_fw:
4788 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4789 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4790 return rval;
4791
4792 qla_printk(KERN_ERR, ha,
4793 "FW: Attempting to fallback to golden firmware...\n");
4794 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4795 if (rval != QLA_SUCCESS)
4796 return rval;
4797
4798 qla_printk(KERN_ERR, ha,
4799 "FW: Please update operational firmware...\n");
4800 ha->flags.running_gold_fw = 1;
4801
4802 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004803}
4804
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004805void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004806qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004807{
4808 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004809 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004810
Andrew Vasquez85880802009-12-15 21:29:46 -08004811 if (ha->flags.pci_channel_io_perm_failure)
4812 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004813 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004814 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004815 if (!ha->fw_major_version)
4816 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004818 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004819 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004820 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004821 ha->isp_ops->reset_chip(vha);
4822 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004823 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004824 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004825 continue;
4826 qla_printk(KERN_INFO, ha,
4827 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004828 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004829 }
4830}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004831
4832int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004833qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004834{
4835 int rval = QLA_SUCCESS;
4836 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004837 struct qla_hw_data *ha = vha->hw;
4838 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004839 struct req_que *req;
4840 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004841
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004842 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004843 return -EINVAL;
4844
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004845 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004846 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004847 req = ha->req_q_map[0];
4848 else
4849 req = vha->req;
4850 rsp = req->rsp;
4851
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004852 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004853 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004854 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004855 }
4856
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004857 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004858
4859 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004860 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004861 if (mb[0] != MBS_COMMAND_COMPLETE) {
4862 DEBUG15(qla_printk(KERN_INFO, ha,
4863 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4864 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4865 mb[0], mb[1], mb[2], mb[6], mb[7]));
4866 return (QLA_FUNCTION_FAILED);
4867 }
4868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004869 atomic_set(&vha->loop_down_timer, 0);
4870 atomic_set(&vha->loop_state, LOOP_UP);
4871 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4872 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4873 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004874
4875 return rval;
4876}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004877
4878/* 84XX Support **************************************************************/
4879
4880static LIST_HEAD(qla_cs84xx_list);
4881static DEFINE_MUTEX(qla_cs84xx_mutex);
4882
4883static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004884qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004885{
4886 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004887 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004888
4889 mutex_lock(&qla_cs84xx_mutex);
4890
4891 /* Find any shared 84xx chip. */
4892 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4893 if (cs84xx->bus == ha->pdev->bus) {
4894 kref_get(&cs84xx->kref);
4895 goto done;
4896 }
4897 }
4898
4899 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4900 if (!cs84xx)
4901 goto done;
4902
4903 kref_init(&cs84xx->kref);
4904 spin_lock_init(&cs84xx->access_lock);
4905 mutex_init(&cs84xx->fw_update_mutex);
4906 cs84xx->bus = ha->pdev->bus;
4907
4908 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4909done:
4910 mutex_unlock(&qla_cs84xx_mutex);
4911 return cs84xx;
4912}
4913
4914static void
4915__qla84xx_chip_release(struct kref *kref)
4916{
4917 struct qla_chip_state_84xx *cs84xx =
4918 container_of(kref, struct qla_chip_state_84xx, kref);
4919
4920 mutex_lock(&qla_cs84xx_mutex);
4921 list_del(&cs84xx->list);
4922 mutex_unlock(&qla_cs84xx_mutex);
4923 kfree(cs84xx);
4924}
4925
4926void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004927qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004928{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004929 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004930 if (ha->cs84xx)
4931 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4932}
4933
4934static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004935qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004936{
4937 int rval;
4938 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004939 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004940
4941 mutex_lock(&ha->cs84xx->fw_update_mutex);
4942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004943 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004944
4945 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4946
4947 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4948 QLA_SUCCESS;
4949}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004950
4951/* 81XX Support **************************************************************/
4952
4953int
4954qla81xx_nvram_config(scsi_qla_host_t *vha)
4955{
4956 int rval;
4957 struct init_cb_81xx *icb;
4958 struct nvram_81xx *nv;
4959 uint32_t *dptr;
4960 uint8_t *dptr1, *dptr2;
4961 uint32_t chksum;
4962 uint16_t cnt;
4963 struct qla_hw_data *ha = vha->hw;
4964
4965 rval = QLA_SUCCESS;
4966 icb = (struct init_cb_81xx *)ha->init_cb;
4967 nv = ha->nvram;
4968
4969 /* Determine NVRAM starting address. */
4970 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004971 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004972
4973 /* Get VPD data into cache */
4974 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004975 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4976 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004977
4978 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004979 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004980 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004981 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004982 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4983 chksum += le32_to_cpu(*dptr++);
4984
Andrew Vasquez76403352009-04-06 22:33:39 -07004985 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004986 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4987
4988 /* Bad NVRAM data, set defaults parameters. */
4989 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4990 || nv->id[3] != ' ' ||
4991 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4992 /* Reset NVRAM data. */
4993 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4994 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4995 le16_to_cpu(nv->nvram_version));
4996 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4997 "invalid -- WWPN) defaults.\n");
4998
4999 /*
5000 * Set default initialization control block.
5001 */
5002 memset(nv, 0, ha->nvram_size);
5003 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5004 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5005 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5006 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5007 nv->exchange_count = __constant_cpu_to_le16(0);
5008 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005009 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005010 nv->port_name[2] = 0x00;
5011 nv->port_name[3] = 0xe0;
5012 nv->port_name[4] = 0x8b;
5013 nv->port_name[5] = 0x1c;
5014 nv->port_name[6] = 0x55;
5015 nv->port_name[7] = 0x86;
5016 nv->node_name[0] = 0x20;
5017 nv->node_name[1] = 0x00;
5018 nv->node_name[2] = 0x00;
5019 nv->node_name[3] = 0xe0;
5020 nv->node_name[4] = 0x8b;
5021 nv->node_name[5] = 0x1c;
5022 nv->node_name[6] = 0x55;
5023 nv->node_name[7] = 0x86;
5024 nv->login_retry_count = __constant_cpu_to_le16(8);
5025 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5026 nv->login_timeout = __constant_cpu_to_le16(0);
5027 nv->firmware_options_1 =
5028 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5029 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5030 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5031 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5032 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5033 nv->efi_parameters = __constant_cpu_to_le32(0);
5034 nv->reset_delay = 5;
5035 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5036 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5037 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005038 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005039 nv->enode_mac[1] = 0x02;
5040 nv->enode_mac[2] = 0x03;
5041 nv->enode_mac[3] = 0x04;
5042 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005043 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005044
5045 rval = 1;
5046 }
5047
5048 /* Reset Initialization control block */
5049 memset(icb, 0, sizeof(struct init_cb_81xx));
5050
5051 /* Copy 1st segment. */
5052 dptr1 = (uint8_t *)icb;
5053 dptr2 = (uint8_t *)&nv->version;
5054 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5055 while (cnt--)
5056 *dptr1++ = *dptr2++;
5057
5058 icb->login_retry_count = nv->login_retry_count;
5059
5060 /* Copy 2nd segment. */
5061 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5062 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5063 cnt = (uint8_t *)&icb->reserved_5 -
5064 (uint8_t *)&icb->interrupt_delay_timer;
5065 while (cnt--)
5066 *dptr1++ = *dptr2++;
5067
5068 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5069 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5070 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5071 icb->enode_mac[0] = 0x01;
5072 icb->enode_mac[1] = 0x02;
5073 icb->enode_mac[2] = 0x03;
5074 icb->enode_mac[3] = 0x04;
5075 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005076 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005077 }
5078
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005079 /* Use extended-initialization control block. */
5080 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5081
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005082 /*
5083 * Setup driver NVRAM options.
5084 */
5085 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005086 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005087
5088 /* Use alternate WWN? */
5089 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5090 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5091 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5092 }
5093
5094 /* Prepare nodename */
5095 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5096 /*
5097 * Firmware will apply the following mask if the nodename was
5098 * not provided.
5099 */
5100 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5101 icb->node_name[0] &= 0xF0;
5102 }
5103
5104 /* Set host adapter parameters. */
5105 ha->flags.disable_risc_code_load = 0;
5106 ha->flags.enable_lip_reset = 0;
5107 ha->flags.enable_lip_full_login =
5108 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5109 ha->flags.enable_target_reset =
5110 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5111 ha->flags.enable_led_scheme = 0;
5112 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5113
5114 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5115 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5116
5117 /* save HBA serial number */
5118 ha->serial0 = icb->port_name[5];
5119 ha->serial1 = icb->port_name[6];
5120 ha->serial2 = icb->port_name[7];
5121 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5122 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5123
5124 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5125
5126 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5127
5128 /* Set minimum login_timeout to 4 seconds. */
5129 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5130 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5131 if (le16_to_cpu(nv->login_timeout) < 4)
5132 nv->login_timeout = __constant_cpu_to_le16(4);
5133 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5134 icb->login_timeout = nv->login_timeout;
5135
5136 /* Set minimum RATOV to 100 tenths of a second. */
5137 ha->r_a_tov = 100;
5138
5139 ha->loop_reset_delay = nv->reset_delay;
5140
5141 /* Link Down Timeout = 0:
5142 *
5143 * When Port Down timer expires we will start returning
5144 * I/O's to OS with "DID_NO_CONNECT".
5145 *
5146 * Link Down Timeout != 0:
5147 *
5148 * The driver waits for the link to come up after link down
5149 * before returning I/Os to OS with "DID_NO_CONNECT".
5150 */
5151 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5152 ha->loop_down_abort_time =
5153 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5154 } else {
5155 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5156 ha->loop_down_abort_time =
5157 (LOOP_DOWN_TIME - ha->link_down_timeout);
5158 }
5159
5160 /* Need enough time to try and get the port back. */
5161 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5162 if (qlport_down_retry)
5163 ha->port_down_retry_count = qlport_down_retry;
5164
5165 /* Set login_retry_count */
5166 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5167 if (ha->port_down_retry_count ==
5168 le16_to_cpu(nv->port_down_retry_count) &&
5169 ha->port_down_retry_count > 3)
5170 ha->login_retry_count = ha->port_down_retry_count;
5171 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5172 ha->login_retry_count = ha->port_down_retry_count;
5173 if (ql2xloginretrycount)
5174 ha->login_retry_count = ql2xloginretrycount;
5175
5176 /* Enable ZIO. */
5177 if (!vha->flags.init_done) {
5178 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5179 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5180 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5181 le16_to_cpu(icb->interrupt_delay_timer): 2;
5182 }
5183 icb->firmware_options_2 &= __constant_cpu_to_le32(
5184 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5185 vha->flags.process_response_queue = 0;
5186 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5187 ha->zio_mode = QLA_ZIO_MODE_6;
5188
5189 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5190 "(%d us).\n", vha->host_no, ha->zio_mode,
5191 ha->zio_timer * 100));
5192 qla_printk(KERN_INFO, ha,
5193 "ZIO mode %d enabled; timer delay (%d us).\n",
5194 ha->zio_mode, ha->zio_timer * 100);
5195
5196 icb->firmware_options_2 |= cpu_to_le32(
5197 (uint32_t)ha->zio_mode);
5198 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5199 vha->flags.process_response_queue = 1;
5200 }
5201
5202 if (rval) {
5203 DEBUG2_3(printk(KERN_WARNING
5204 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5205 }
5206 return (rval);
5207}
5208
Giridhar Malavalia9083012010-04-12 17:59:55 -07005209int
5210qla82xx_restart_isp(scsi_qla_host_t *vha)
5211{
5212 int status, rval;
5213 uint32_t wait_time;
5214 struct qla_hw_data *ha = vha->hw;
5215 struct req_que *req = ha->req_q_map[0];
5216 struct rsp_que *rsp = ha->rsp_q_map[0];
5217 struct scsi_qla_host *vp;
5218 struct scsi_qla_host *tvp;
5219
5220 status = qla2x00_init_rings(vha);
5221 if (!status) {
5222 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5223 ha->flags.chip_reset_done = 1;
5224
5225 status = qla2x00_fw_ready(vha);
5226 if (!status) {
5227 qla_printk(KERN_INFO, ha,
5228 "%s(): Start configure loop, "
5229 "status = %d\n", __func__, status);
5230
5231 /* Issue a marker after FW becomes ready. */
5232 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5233
5234 vha->flags.online = 1;
5235 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5236 wait_time = 256;
5237 do {
5238 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5239 qla2x00_configure_loop(vha);
5240 wait_time--;
5241 } while (!atomic_read(&vha->loop_down_timer) &&
5242 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5243 wait_time &&
5244 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5245 }
5246
5247 /* if no cable then assume it's good */
5248 if ((vha->device_flags & DFLG_NO_CABLE))
5249 status = 0;
5250
5251 qla_printk(KERN_INFO, ha,
5252 "%s(): Configure loop done, status = 0x%x\n",
5253 __func__, status);
5254 }
5255
5256 if (!status) {
5257 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5258
5259 if (!atomic_read(&vha->loop_down_timer)) {
5260 /*
5261 * Issue marker command only when we are going
5262 * to start the I/O .
5263 */
5264 vha->marker_needed = 1;
5265 }
5266
5267 vha->flags.online = 1;
5268
5269 ha->isp_ops->enable_intrs(ha);
5270
5271 ha->isp_abort_cnt = 0;
5272 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5273
5274 if (ha->fce) {
5275 ha->flags.fce_enabled = 1;
5276 memset(ha->fce, 0,
5277 fce_calc_size(ha->fce_bufs));
5278 rval = qla2x00_enable_fce_trace(vha,
5279 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5280 &ha->fce_bufs);
5281 if (rval) {
5282 qla_printk(KERN_WARNING, ha,
5283 "Unable to reinitialize FCE "
5284 "(%d).\n", rval);
5285 ha->flags.fce_enabled = 0;
5286 }
5287 }
5288
5289 if (ha->eft) {
5290 memset(ha->eft, 0, EFT_SIZE);
5291 rval = qla2x00_enable_eft_trace(vha,
5292 ha->eft_dma, EFT_NUM_BUFFERS);
5293 if (rval) {
5294 qla_printk(KERN_WARNING, ha,
5295 "Unable to reinitialize EFT "
5296 "(%d).\n", rval);
5297 }
5298 }
5299 } else { /* failed the ISP abort */
5300 vha->flags.online = 1;
5301 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
5302 if (ha->isp_abort_cnt == 0) {
5303 qla_printk(KERN_WARNING, ha,
5304 "ISP error recovery failed - "
5305 "board disabled\n");
5306 /*
5307 * The next call disables the board
5308 * completely.
5309 */
5310 ha->isp_ops->reset_adapter(vha);
5311 vha->flags.online = 0;
5312 clear_bit(ISP_ABORT_RETRY,
5313 &vha->dpc_flags);
5314 status = 0;
5315 } else { /* schedule another ISP abort */
5316 ha->isp_abort_cnt--;
5317 qla_printk(KERN_INFO, ha,
5318 "qla%ld: ISP abort - "
5319 "retry remaining %d\n",
5320 vha->host_no, ha->isp_abort_cnt);
5321 status = 1;
5322 }
5323 } else {
5324 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
5325 qla_printk(KERN_INFO, ha,
5326 "(%ld): ISP error recovery "
5327 "- retrying (%d) more times\n",
5328 vha->host_no, ha->isp_abort_cnt);
5329 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5330 status = 1;
5331 }
5332 }
5333
5334 if (!status) {
5335 DEBUG(printk(KERN_INFO
5336 "qla82xx_restart_isp(%ld): succeeded.\n",
5337 vha->host_no));
5338 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5339 if (vp->vp_idx)
5340 qla2x00_vp_abort_isp(vp);
5341 }
5342 } else {
5343 qla_printk(KERN_INFO, ha,
5344 "qla82xx_restart_isp: **** FAILED ****\n");
5345 }
5346
5347 return status;
5348}
5349
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005350void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005351qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005352{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005353 struct qla_hw_data *ha = vha->hw;
5354
5355 if (!ql2xetsenable)
5356 return;
5357
5358 /* Enable ETS Burst. */
5359 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5360 ha->fw_options[2] |= BIT_9;
5361 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005362}
Sarang Radke09ff7012010-03-19 17:03:59 -07005363
5364/*
5365 * qla24xx_get_fcp_prio
5366 * Gets the fcp cmd priority value for the logged in port.
5367 * Looks for a match of the port descriptors within
5368 * each of the fcp prio config entries. If a match is found,
5369 * the tag (priority) value is returned.
5370 *
5371 * Input:
5372 * ha = adapter block po
5373 * fcport = port structure pointer.
5374 *
5375 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005376 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005377 * 0 (if not found)
5378 *
5379 * Context:
5380 * Kernel context
5381 */
5382uint8_t
5383qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5384{
5385 int i, entries;
5386 uint8_t pid_match, wwn_match;
5387 uint8_t priority;
5388 uint32_t pid1, pid2;
5389 uint64_t wwn1, wwn2;
5390 struct qla_fcp_prio_entry *pri_entry;
5391 struct qla_hw_data *ha = vha->hw;
5392
5393 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5394 return 0;
5395
5396 priority = 0;
5397 entries = ha->fcp_prio_cfg->num_entries;
5398 pri_entry = &ha->fcp_prio_cfg->entry[0];
5399
5400 for (i = 0; i < entries; i++) {
5401 pid_match = wwn_match = 0;
5402
5403 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5404 pri_entry++;
5405 continue;
5406 }
5407
5408 /* check source pid for a match */
5409 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5410 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5411 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5412 if (pid1 == INVALID_PORT_ID)
5413 pid_match++;
5414 else if (pid1 == pid2)
5415 pid_match++;
5416 }
5417
5418 /* check destination pid for a match */
5419 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5420 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5421 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5422 if (pid1 == INVALID_PORT_ID)
5423 pid_match++;
5424 else if (pid1 == pid2)
5425 pid_match++;
5426 }
5427
5428 /* check source WWN for a match */
5429 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5430 wwn1 = wwn_to_u64(vha->port_name);
5431 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5432 if (wwn2 == (uint64_t)-1)
5433 wwn_match++;
5434 else if (wwn1 == wwn2)
5435 wwn_match++;
5436 }
5437
5438 /* check destination WWN for a match */
5439 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5440 wwn1 = wwn_to_u64(fcport->port_name);
5441 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5442 if (wwn2 == (uint64_t)-1)
5443 wwn_match++;
5444 else if (wwn1 == wwn2)
5445 wwn_match++;
5446 }
5447
5448 if (pid_match == 2 || wwn_match == 2) {
5449 /* Found a matching entry */
5450 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5451 priority = pri_entry->tag;
5452 break;
5453 }
5454
5455 pri_entry++;
5456 }
5457
5458 return priority;
5459}
5460
5461/*
5462 * qla24xx_update_fcport_fcp_prio
5463 * Activates fcp priority for the logged in fc port
5464 *
5465 * Input:
5466 * ha = adapter block pointer.
5467 * fcp = port structure pointer.
5468 *
5469 * Return:
5470 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5471 *
5472 * Context:
5473 * Kernel context.
5474 */
5475int
5476qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5477{
5478 int ret;
5479 uint8_t priority;
5480 uint16_t mb[5];
5481
5482 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5483 fcport->port_type != FCT_TARGET ||
5484 fcport->loop_id == FC_NO_LOOP_ID)
5485 return QLA_FUNCTION_FAILED;
5486
5487 priority = qla24xx_get_fcp_prio(ha, fcport);
5488 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5489 if (ret == QLA_SUCCESS)
5490 fcport->fcp_prio = priority;
5491 else
5492 DEBUG2(printk(KERN_WARNING
5493 "scsi(%ld): Unable to activate fcp priority, "
5494 " ret=0x%x\n", ha->host_no, ret));
5495
5496 return ret;
5497}
5498
5499/*
5500 * qla24xx_update_all_fcp_prio
5501 * Activates fcp priority for all the logged in ports
5502 *
5503 * Input:
5504 * ha = adapter block pointer.
5505 *
5506 * Return:
5507 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5508 *
5509 * Context:
5510 * Kernel context.
5511 */
5512int
5513qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5514{
5515 int ret;
5516 fc_port_t *fcport;
5517
5518 ret = QLA_FUNCTION_FAILED;
5519 /* We need to set priority for all logged in ports */
5520 list_for_each_entry(fcport, &vha->vp_fcports, list)
5521 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5522
5523 return ret;
5524}