blob: f1db11a0d699b05fd0de6401ceeda018fcc52cac [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;
Giridhar Malavalib9637522010-05-28 15:08:15 -07001457 else
1458 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001459 }
1460
Andrew Vasquez3db06522008-01-31 12:33:49 -08001461 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1462 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1463 spin_lock_irqsave(&ha->hardware_lock, flags);
1464 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1465 RD_REG_WORD(&reg->hccr);
1466 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1467 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Andrew Vasquez18e75552009-06-03 09:55:30 -07001469 qla81xx_mpi_sync(vha);
1470
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001473 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001477 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 if (rval == QLA_SUCCESS) {
1479 /* Start firmware execution. */
1480 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001485 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001486enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001487 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001488 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 &ha->fw_major_version,
1490 &ha->fw_minor_version,
1491 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001492 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001493 ha->mpi_version, &ha->mpi_capabilities,
1494 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001495 if (rval != QLA_SUCCESS)
1496 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001497 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001499 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001500 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001501 if ((!ha->max_npiv_vports) ||
1502 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001503 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001504 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001505 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001506 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001507 qla2x00_get_resource_cnts(vha, NULL,
1508 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001509 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001510
Giridhar Malavalia9083012010-04-12 17:59:55 -07001511 if (!fw_major_version && ql2xallocfwdump) {
1512 if (!IS_QLA82XX(ha))
1513 qla2x00_alloc_fw_dump(vha);
1514 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515 }
1516 } else {
1517 DEBUG2(printk(KERN_INFO
1518 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520 }
1521 }
1522
Andrew Vasquez3db06522008-01-31 12:33:49 -08001523 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1524 /* Enable proper parity. */
1525 spin_lock_irqsave(&ha->hardware_lock, flags);
1526 if (IS_QLA2300(ha))
1527 /* SRAM parity */
1528 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1529 else
1530 /* SRAM, Instruction RAM and GP RAM parity */
1531 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1532 RD_REG_WORD(&reg->hccr);
1533 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1534 }
1535
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001536 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1537 uint32_t size;
1538
1539 rval = qla81xx_fac_get_sector_size(vha, &size);
1540 if (rval == QLA_SUCCESS) {
1541 ha->flags.fac_supported = 1;
1542 ha->fdt_block_size = size << 2;
1543 } else {
1544 qla_printk(KERN_ERR, ha,
1545 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1546 ha->fw_major_version, ha->fw_minor_version,
1547 ha->fw_subminor_version);
1548 }
1549 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001550failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551 if (rval) {
1552 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554 }
1555
1556 return (rval);
1557}
1558
1559/**
1560 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1561 * @ha: HA context
1562 *
1563 * Beginning of request ring has initialization control block already built
1564 * by nvram config routine.
1565 *
1566 * Returns 0 on success.
1567 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001568void
1569qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570{
1571 uint16_t cnt;
1572 response_t *pkt;
1573
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001574 rsp->ring_ptr = rsp->ring;
1575 rsp->ring_index = 0;
1576 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001577 pkt = rsp->ring_ptr;
1578 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 pkt->signature = RESPONSE_PROCESSED;
1580 pkt++;
1581 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001582}
1583
1584/**
1585 * qla2x00_update_fw_options() - Read and process firmware options.
1586 * @ha: HA context
1587 *
1588 * Returns 0 on success.
1589 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001590void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001591qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592{
1593 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595
1596 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
1599 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1600 return;
1601
1602 /* Serial Link options. */
1603 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1606 sizeof(ha->fw_seriallink_options)));
1607
1608 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1609 if (ha->fw_seriallink_options[3] & BIT_2) {
1610 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1611
1612 /* 1G settings */
1613 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1614 emphasis = (ha->fw_seriallink_options[2] &
1615 (BIT_4 | BIT_3)) >> 3;
1616 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001617 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618 rx_sens = (ha->fw_seriallink_options[0] &
1619 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1620 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1621 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1622 if (rx_sens == 0x0)
1623 rx_sens = 0x3;
1624 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1625 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1626 ha->fw_options[10] |= BIT_5 |
1627 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1628 (tx_sens & (BIT_1 | BIT_0));
1629
1630 /* 2G settings */
1631 swing = (ha->fw_seriallink_options[2] &
1632 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1633 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1634 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001635 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 rx_sens = (ha->fw_seriallink_options[1] &
1637 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1638 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1639 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1640 if (rx_sens == 0x0)
1641 rx_sens = 0x3;
1642 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1643 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1644 ha->fw_options[11] |= BIT_5 |
1645 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1646 (tx_sens & (BIT_1 | BIT_0));
1647 }
1648
1649 /* FCP2 options. */
1650 /* Return command IOCBs without waiting for an ABTS to complete. */
1651 ha->fw_options[3] |= BIT_13;
1652
1653 /* LED scheme. */
1654 if (ha->flags.enable_led_scheme)
1655 ha->fw_options[2] |= BIT_12;
1656
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001657 /* Detect ISP6312. */
1658 if (IS_QLA6312(ha))
1659 ha->fw_options[2] |= BIT_13;
1660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001662 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663}
1664
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001665void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001666qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001667{
1668 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001669 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001670
Giridhar Malavalia9083012010-04-12 17:59:55 -07001671 if (IS_QLA82XX(ha))
1672 return;
1673
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001674 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001675 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001676 return;
1677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001678 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001679 le16_to_cpu(ha->fw_seriallink_options24[1]),
1680 le16_to_cpu(ha->fw_seriallink_options24[2]),
1681 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001682 if (rval != QLA_SUCCESS) {
1683 qla_printk(KERN_WARNING, ha,
1684 "Unable to update Serial Link options (%x).\n", rval);
1685 }
1686}
1687
1688void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001690{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001691 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001692 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001693 struct req_que *req = ha->req_q_map[0];
1694 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001695
1696 /* Setup ring parameters in initialization control block. */
1697 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1698 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001699 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1700 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1701 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1702 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1703 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1704 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001705
1706 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1707 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1708 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1709 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1710 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1711}
1712
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001713void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001714qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001715{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001716 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001717 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1718 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1719 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001720 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001721 uint16_t rid = 0;
1722 struct req_que *req = ha->req_q_map[0];
1723 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001724
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001725/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001726 icb = (struct init_cb_24xx *)ha->init_cb;
1727 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1728 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001729 icb->request_q_length = cpu_to_le16(req->length);
1730 icb->response_q_length = cpu_to_le16(rsp->length);
1731 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1732 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1733 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1734 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001735
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001736 if (ha->mqenable) {
1737 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1738 icb->rid = __constant_cpu_to_le16(rid);
1739 if (ha->flags.msix_enabled) {
1740 msix = &ha->msix_entries[1];
1741 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001742 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001743 icb->msix = cpu_to_le16(msix->entry);
1744 }
1745 /* Use alternate PCI bus number */
1746 if (MSB(rid))
1747 icb->firmware_options_2 |=
1748 __constant_cpu_to_le32(BIT_19);
1749 /* Use alternate PCI devfn */
1750 if (LSB(rid))
1751 icb->firmware_options_2 |=
1752 __constant_cpu_to_le32(BIT_18);
1753
Anirban Chakraborty31557542009-12-02 10:36:55 -08001754 /* Use Disable MSIX Handshake mode for capable adapters */
1755 if (IS_MSIX_NACK_CAPABLE(ha)) {
1756 icb->firmware_options_2 &=
1757 __constant_cpu_to_le32(~BIT_22);
1758 ha->flags.disable_msix_handshake = 1;
1759 qla_printk(KERN_INFO, ha,
1760 "MSIX Handshake Disable Mode turned on\n");
1761 } else {
1762 icb->firmware_options_2 |=
1763 __constant_cpu_to_le32(BIT_22);
1764 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001765 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001766
1767 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1768 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1769 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1770 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1771 } else {
1772 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1773 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1774 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1775 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1776 }
1777 /* PCI posting */
1778 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001779}
1780
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781/**
1782 * qla2x00_init_rings() - Initializes firmware.
1783 * @ha: HA context
1784 *
1785 * Beginning of request ring has initialization control block already built
1786 * by nvram config routine.
1787 *
1788 * Returns 0 on success.
1789 */
1790static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
1793 int rval;
1794 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001795 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001796 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001797 struct req_que *req;
1798 struct rsp_que *rsp;
1799 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001800 struct mid_init_cb_24xx *mid_init_cb =
1801 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
1803 spin_lock_irqsave(&ha->hardware_lock, flags);
1804
1805 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001806 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001807 req = ha->req_q_map[que];
1808 if (!req)
1809 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001810 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001811 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001813 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001814
1815 /* Initialize firmware. */
1816 req->ring_ptr = req->ring;
1817 req->ring_index = 0;
1818 req->cnt = req->length;
1819 }
1820
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001821 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001822 rsp = ha->rsp_q_map[que];
1823 if (!rsp)
1824 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001825 /* Initialize response queue entries */
1826 qla2x00_init_response_q_entries(rsp);
1827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828
1829 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001830 list_for_each_entry(vp, &ha->vp_list, list) {
1831 vp->rscn_in_ptr = 0;
1832 vp->rscn_out_ptr = 0;
1833 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001834 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
1836 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1837
1838 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001839 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001842
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001843 if (ha->flags.npiv_supported) {
1844 if (ha->operating_mode == LOOP)
1845 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001846 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001847 }
1848
Andrew Vasquez24a08132009-03-24 09:08:16 -07001849 if (IS_FWI2_CAPABLE(ha)) {
1850 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1851 mid_init_cb->init_cb.execution_throttle =
1852 cpu_to_le16(ha->fw_xcb_count);
1853 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001854
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001855 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856 if (rval) {
1857 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001858 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 } else {
1860 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001861 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 }
1863
1864 return (rval);
1865}
1866
1867/**
1868 * qla2x00_fw_ready() - Waits for firmware ready.
1869 * @ha: HA context
1870 *
1871 * Returns 0 on success.
1872 */
1873static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875{
1876 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001877 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 uint16_t min_wait; /* Minimum wait time if loop is down */
1879 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001880 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001881 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
1883 rval = QLA_SUCCESS;
1884
1885 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001886 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
1888 /*
1889 * Firmware should take at most one RATOV to login, plus 5 seconds for
1890 * our own processing.
1891 */
1892 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1893 wait_time = min_wait;
1894 }
1895
1896 /* Min wait time if loop down */
1897 mtime = jiffies + (min_wait * HZ);
1898
1899 /* wait time before firmware ready */
1900 wtime = jiffies + (wait_time * HZ);
1901
1902 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1905
1906 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
1909 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001910 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001912 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001915 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1916 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001918 state[2]));
1919 if ((state[2] & FSTATE_LOGGED_IN) &&
1920 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1921 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001922 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001923
1924 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001926 if (rval != QLA_SUCCESS)
1927 break;
1928
1929 /* Add time taken to initialize. */
1930 cs84xx_time = jiffies - cs84xx_time;
1931 wtime += cs84xx_time;
1932 mtime += cs84xx_time;
1933 DEBUG16(printk("scsi(%ld): Increasing "
1934 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001935 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001936 }
1937 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001939 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001940
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001941 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 &ha->login_timeout, &ha->r_a_tov);
1943
1944 rval = QLA_SUCCESS;
1945 break;
1946 }
1947
1948 rval = QLA_FUNCTION_FAILED;
1949
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001951 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001953 * other than Wait for Login.
1954 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 if (time_after_eq(jiffies, mtime)) {
1956 qla_printk(KERN_INFO, ha,
1957 "Cable is unplugged...\n");
1958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001959 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 break;
1961 }
1962 }
1963 } else {
1964 /* Mailbox cmd failed. Timeout on min_wait. */
1965 if (time_after_eq(jiffies, mtime))
1966 break;
1967 }
1968
1969 if (time_after_eq(jiffies, wtime))
1970 break;
1971
1972 /* Delay for a while */
1973 msleep(500);
1974
1975 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001976 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 } while (1);
1978
Andrew Vasquez656e8912009-06-03 09:55:29 -07001979 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1980 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1981 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
1983 if (rval) {
1984 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001985 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 }
1987
1988 return (rval);
1989}
1990
1991/*
1992* qla2x00_configure_hba
1993* Setup adapter context.
1994*
1995* Input:
1996* ha = adapter state pointer.
1997*
1998* Returns:
1999* 0 = success
2000*
2001* Context:
2002* Kernel context.
2003*/
2004static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002005qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006{
2007 int rval;
2008 uint16_t loop_id;
2009 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002010 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 uint8_t al_pa;
2012 uint8_t area;
2013 uint8_t domain;
2014 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
2017 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002018 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002019 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002022 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2023 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002024 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002025 } else {
2026 qla_printk(KERN_WARNING, ha,
2027 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002028 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 return (rval);
2031 }
2032
2033 if (topo == 4) {
2034 qla_printk(KERN_INFO, ha,
2035 "Cannot get topology - retrying.\n");
2036 return (QLA_FUNCTION_FAILED);
2037 }
2038
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040
2041 /* initialize */
2042 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2043 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002044 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
2046 switch (topo) {
2047 case 0:
2048 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 ha->current_topology = ISP_CFG_NL;
2051 strcpy(connect_type, "(Loop)");
2052 break;
2053
2054 case 1:
2055 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002056 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002057 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 ha->current_topology = ISP_CFG_FL;
2059 strcpy(connect_type, "(FL_Port)");
2060 break;
2061
2062 case 2:
2063 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 ha->operating_mode = P2P;
2066 ha->current_topology = ISP_CFG_N;
2067 strcpy(connect_type, "(N_Port-to-N_Port)");
2068 break;
2069
2070 case 3:
2071 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002072 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002073 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002074 ha->operating_mode = P2P;
2075 ha->current_topology = ISP_CFG_F;
2076 strcpy(connect_type, "(F_Port)");
2077 break;
2078
2079 default:
2080 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2081 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 ha->current_topology = ISP_CFG_NL;
2084 strcpy(connect_type, "(Loop)");
2085 break;
2086 }
2087
2088 /* Save Host port and loop ID. */
2089 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002090 vha->d_id.b.domain = domain;
2091 vha->d_id.b.area = area;
2092 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 qla_printk(KERN_INFO, ha,
2096 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002097 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098
2099 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 }
2104
2105 return(rval);
2106}
2107
Giridhar Malavalia9083012010-04-12 17:59:55 -07002108inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002109qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2110 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002111{
2112 char *st, *en;
2113 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002114 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002115 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002116 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002117
2118 if (memcmp(model, BINZERO, len) != 0) {
2119 strncpy(ha->model_number, model, len);
2120 st = en = ha->model_number;
2121 en += len - 1;
2122 while (en > st) {
2123 if (*en != 0x20 && *en != 0x00)
2124 break;
2125 *en-- = '\0';
2126 }
2127
2128 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002129 if (use_tbl &&
2130 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002131 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002132 strncpy(ha->model_desc,
2133 qla2x00_model_name[index * 2 + 1],
2134 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002135 } else {
2136 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002137 if (use_tbl &&
2138 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002139 index < QLA_MODEL_NAMES) {
2140 strcpy(ha->model_number,
2141 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002142 strncpy(ha->model_desc,
2143 qla2x00_model_name[index * 2 + 1],
2144 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002145 } else {
2146 strcpy(ha->model_number, def);
2147 }
2148 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002149 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002150 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002151 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002152}
2153
David Miller4e08df32007-04-16 12:37:43 -07002154/* On sparc systems, obtain port and node WWN from firmware
2155 * properties.
2156 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002158{
2159#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002161 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002162 struct device_node *dp = pci_device_to_OF_node(pdev);
2163 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002164 int len;
2165
2166 val = of_get_property(dp, "port-wwn", &len);
2167 if (val && len >= WWN_SIZE)
2168 memcpy(nv->port_name, val, WWN_SIZE);
2169
2170 val = of_get_property(dp, "node-wwn", &len);
2171 if (val && len >= WWN_SIZE)
2172 memcpy(nv->node_name, val, WWN_SIZE);
2173#endif
2174}
2175
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176/*
2177* NVRAM configuration for ISP 2xxx
2178*
2179* Input:
2180* ha = adapter block pointer.
2181*
2182* Output:
2183* initialization control block in response_ring
2184* host adapters parameters in host adapter block
2185*
2186* Returns:
2187* 0 = success.
2188*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002189int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191{
David Miller4e08df32007-04-16 12:37:43 -07002192 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002193 uint8_t chksum = 0;
2194 uint16_t cnt;
2195 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002196 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002197 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002198 nvram_t *nv = ha->nvram;
2199 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002200 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
David Miller4e08df32007-04-16 12:37:43 -07002202 rval = QLA_SUCCESS;
2203
Linus Torvalds1da177e2005-04-16 15:20:36 -07002204 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002205 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 ha->nvram_base = 0;
2207 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2208 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2209 ha->nvram_base = 0x80;
2210
2211 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002213 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2214 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002216 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002217 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002218
2219 /* Bad NVRAM data, set defaults parameters. */
2220 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2221 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2222 /* Reset NVRAM data. */
2223 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2224 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2225 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002226 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2227 "invalid -- WWPN) defaults.\n");
2228
2229 /*
2230 * Set default initialization control block.
2231 */
2232 memset(nv, 0, ha->nvram_size);
2233 nv->parameter_block_version = ICB_VERSION;
2234
2235 if (IS_QLA23XX(ha)) {
2236 nv->firmware_options[0] = BIT_2 | BIT_1;
2237 nv->firmware_options[1] = BIT_7 | BIT_5;
2238 nv->add_firmware_options[0] = BIT_5;
2239 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2240 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2241 nv->special_options[1] = BIT_7;
2242 } else if (IS_QLA2200(ha)) {
2243 nv->firmware_options[0] = BIT_2 | BIT_1;
2244 nv->firmware_options[1] = BIT_7 | BIT_5;
2245 nv->add_firmware_options[0] = BIT_5;
2246 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2247 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2248 } else if (IS_QLA2100(ha)) {
2249 nv->firmware_options[0] = BIT_3 | BIT_1;
2250 nv->firmware_options[1] = BIT_5;
2251 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2252 }
2253
2254 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2255 nv->execution_throttle = __constant_cpu_to_le16(16);
2256 nv->retry_count = 8;
2257 nv->retry_delay = 1;
2258
2259 nv->port_name[0] = 33;
2260 nv->port_name[3] = 224;
2261 nv->port_name[4] = 139;
2262
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002264
2265 nv->login_timeout = 4;
2266
2267 /*
2268 * Set default host adapter parameters
2269 */
2270 nv->host_p[1] = BIT_2;
2271 nv->reset_delay = 5;
2272 nv->port_down_retry_count = 8;
2273 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2274 nv->link_down_timeout = 60;
2275
2276 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 }
2278
2279#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2280 /*
2281 * The SN2 does not provide BIOS emulation which means you can't change
2282 * potentially bogus BIOS settings. Force the use of default settings
2283 * for link rate and frame size. Hope that the rest of the settings
2284 * are valid.
2285 */
2286 if (ia64_platform_is("sn2")) {
2287 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2288 if (IS_QLA23XX(ha))
2289 nv->special_options[1] = BIT_7;
2290 }
2291#endif
2292
2293 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002294 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295
2296 /*
2297 * Setup driver NVRAM options.
2298 */
2299 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2300 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2301 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2302 nv->firmware_options[1] &= ~BIT_4;
2303
2304 if (IS_QLA23XX(ha)) {
2305 nv->firmware_options[0] |= BIT_2;
2306 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002307 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002308 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309
2310 if (IS_QLA2300(ha)) {
2311 if (ha->fb_rev == FPM_2310) {
2312 strcpy(ha->model_number, "QLA2310");
2313 } else {
2314 strcpy(ha->model_number, "QLA2300");
2315 }
2316 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002317 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002318 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 }
2320 } else if (IS_QLA2200(ha)) {
2321 nv->firmware_options[0] |= BIT_2;
2322 /*
2323 * 'Point-to-point preferred, else loop' is not a safe
2324 * connection mode setting.
2325 */
2326 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2327 (BIT_5 | BIT_4)) {
2328 /* Force 'loop preferred, else point-to-point'. */
2329 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2330 nv->add_firmware_options[0] |= BIT_5;
2331 }
2332 strcpy(ha->model_number, "QLA22xx");
2333 } else /*if (IS_QLA2100(ha))*/ {
2334 strcpy(ha->model_number, "QLA2100");
2335 }
2336
2337 /*
2338 * Copy over NVRAM RISC parameter block to initialization control block.
2339 */
2340 dptr1 = (uint8_t *)icb;
2341 dptr2 = (uint8_t *)&nv->parameter_block_version;
2342 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2343 while (cnt--)
2344 *dptr1++ = *dptr2++;
2345
2346 /* Copy 2nd half. */
2347 dptr1 = (uint8_t *)icb->add_firmware_options;
2348 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2349 while (cnt--)
2350 *dptr1++ = *dptr2++;
2351
Andrew Vasquez5341e862006-05-17 15:09:16 -07002352 /* Use alternate WWN? */
2353 if (nv->host_p[1] & BIT_7) {
2354 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2355 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2356 }
2357
Linus Torvalds1da177e2005-04-16 15:20:36 -07002358 /* Prepare nodename */
2359 if ((icb->firmware_options[1] & BIT_6) == 0) {
2360 /*
2361 * Firmware will apply the following mask if the nodename was
2362 * not provided.
2363 */
2364 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2365 icb->node_name[0] &= 0xF0;
2366 }
2367
2368 /*
2369 * Set host adapter parameters.
2370 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002371 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002372 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2374 /* Always load RISC code on non ISP2[12]00 chips. */
2375 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2376 ha->flags.disable_risc_code_load = 0;
2377 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2378 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2379 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002380 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002381 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382
2383 ha->operating_mode =
2384 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2385
2386 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2387 sizeof(ha->fw_seriallink_options));
2388
2389 /* save HBA serial number */
2390 ha->serial0 = icb->port_name[5];
2391 ha->serial1 = icb->port_name[6];
2392 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2394 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
2396 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2397
2398 ha->retry_count = nv->retry_count;
2399
2400 /* Set minimum login_timeout to 4 seconds. */
2401 if (nv->login_timeout < ql2xlogintimeout)
2402 nv->login_timeout = ql2xlogintimeout;
2403 if (nv->login_timeout < 4)
2404 nv->login_timeout = 4;
2405 ha->login_timeout = nv->login_timeout;
2406 icb->login_timeout = nv->login_timeout;
2407
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002408 /* Set minimum RATOV to 100 tenths of a second. */
2409 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 ha->loop_reset_delay = nv->reset_delay;
2412
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 /* Link Down Timeout = 0:
2414 *
2415 * When Port Down timer expires we will start returning
2416 * I/O's to OS with "DID_NO_CONNECT".
2417 *
2418 * Link Down Timeout != 0:
2419 *
2420 * The driver waits for the link to come up after link down
2421 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002422 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 if (nv->link_down_timeout == 0) {
2424 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002425 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 } else {
2427 ha->link_down_timeout = nv->link_down_timeout;
2428 ha->loop_down_abort_time =
2429 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002430 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431
Linus Torvalds1da177e2005-04-16 15:20:36 -07002432 /*
2433 * Need enough time to try and get the port back.
2434 */
2435 ha->port_down_retry_count = nv->port_down_retry_count;
2436 if (qlport_down_retry)
2437 ha->port_down_retry_count = qlport_down_retry;
2438 /* Set login_retry_count */
2439 ha->login_retry_count = nv->retry_count;
2440 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2441 ha->port_down_retry_count > 3)
2442 ha->login_retry_count = ha->port_down_retry_count;
2443 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2444 ha->login_retry_count = ha->port_down_retry_count;
2445 if (ql2xloginretrycount)
2446 ha->login_retry_count = ql2xloginretrycount;
2447
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 icb->lun_enables = __constant_cpu_to_le16(0);
2449 icb->command_resource_count = 0;
2450 icb->immediate_notify_resource_count = 0;
2451 icb->timeout = __constant_cpu_to_le16(0);
2452
2453 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2454 /* Enable RIO */
2455 icb->firmware_options[0] &= ~BIT_3;
2456 icb->add_firmware_options[0] &=
2457 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2458 icb->add_firmware_options[0] |= BIT_2;
2459 icb->response_accumulation_timer = 3;
2460 icb->interrupt_delay_timer = 5;
2461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002464 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002466 ha->zio_mode = icb->add_firmware_options[0] &
2467 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2468 ha->zio_timer = icb->interrupt_delay_timer ?
2469 icb->interrupt_delay_timer: 2;
2470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 icb->add_firmware_options[0] &=
2472 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002474 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002475 ha->zio_mode = QLA_ZIO_MODE_6;
2476
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002477 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002478 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002479 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002481 "ZIO mode %d enabled; timer delay (%d us).\n",
2482 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002484 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2485 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002486 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 }
2488 }
2489
David Miller4e08df32007-04-16 12:37:43 -07002490 if (rval) {
2491 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002493 }
2494 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495}
2496
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002497static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002498qla2x00_rport_del(void *data)
2499{
2500 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002501 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002502
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002503 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002504 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002505 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002506 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002507 if (rport)
2508 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002509}
2510
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511/**
2512 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2513 * @ha: HA context
2514 * @flags: allocation flags
2515 *
2516 * Returns a pointer to the allocated fcport, or NULL, if none available.
2517 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002518fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002519qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520{
2521 fc_port_t *fcport;
2522
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002523 fcport = kzalloc(sizeof(fc_port_t), flags);
2524 if (!fcport)
2525 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526
2527 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002528 fcport->vha = vha;
2529 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 fcport->port_type = FCT_UNKNOWN;
2531 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002533 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002535 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536}
2537
2538/*
2539 * qla2x00_configure_loop
2540 * Updates Fibre Channel Device Database with what is actually on loop.
2541 *
2542 * Input:
2543 * ha = adapter block pointer.
2544 *
2545 * Returns:
2546 * 0 = success.
2547 * 1 = error.
2548 * 2 = database was full and device was not configured.
2549 */
2550static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002551qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002552{
2553 int rval;
2554 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 rval = QLA_SUCCESS;
2557
2558 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2560 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 if (rval != QLA_SUCCESS) {
2562 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564 return (rval);
2565 }
2566 }
2567
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
2572 /*
2573 * If we have both an RSCN and PORT UPDATE pending then handle them
2574 * both at the same time.
2575 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002576 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2577 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
Michael Hernandez3064ff32009-12-15 21:29:44 -08002579 qla2x00_get_data_rate(vha);
2580
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 /* Determine what we need to do */
2582 if (ha->current_topology == ISP_CFG_FL &&
2583 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2584
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002585 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 set_bit(RSCN_UPDATE, &flags);
2587
2588 } else if (ha->current_topology == ISP_CFG_F &&
2589 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2590
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 set_bit(RSCN_UPDATE, &flags);
2593 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2594
Andrew Vasquez21333b42006-05-17 15:09:56 -07002595 } else if (ha->current_topology == ISP_CFG_N) {
2596 clear_bit(RSCN_UPDATE, &flags);
2597
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2600
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 set_bit(RSCN_UPDATE, &flags);
2603 set_bit(LOCAL_LOOP_UPDATE, &flags);
2604 }
2605
2606 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002607 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 else
2610 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 }
2612
2613 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616 else
2617 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 }
2619
2620 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621 if (atomic_read(&vha->loop_down_timer) ||
2622 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 rval = QLA_FUNCTION_FAILED;
2624 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002625 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 }
2629 }
2630
2631 if (rval) {
2632 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002634 } else {
2635 DEBUG3(printk("%s: exiting normally\n", __func__));
2636 }
2637
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002638 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002639 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002642 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002643 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002644 vha->flags.rscn_queue_overflow = 1;
2645 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 }
2647
2648 return (rval);
2649}
2650
2651
2652
2653/*
2654 * qla2x00_configure_local_loop
2655 * Updates Fibre Channel Device Database with local loop devices.
2656 *
2657 * Input:
2658 * ha = adapter block pointer.
2659 *
2660 * Returns:
2661 * 0 = success.
2662 */
2663static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665{
2666 int rval, rval2;
2667 int found_devs;
2668 int found;
2669 fc_port_t *fcport, *new_fcport;
2670
2671 uint16_t index;
2672 uint16_t entries;
2673 char *id_iter;
2674 uint16_t loop_id;
2675 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
2678 found_devs = 0;
2679 new_fcport = NULL;
2680 entries = MAX_FIBRE_DEVICES;
2681
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2683 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684
2685 /* Get list of logged in devices. */
2686 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 &entries);
2689 if (rval != QLA_SUCCESS)
2690 goto cleanup_allocation;
2691
2692 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002693 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2695 entries * sizeof(struct gid_list_info)));
2696
2697 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 if (new_fcport == NULL) {
2700 rval = QLA_MEMORY_ALLOC_FAILED;
2701 goto cleanup_allocation;
2702 }
2703 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2704
2705 /*
2706 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2707 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2710 fcport->port_type != FCT_BROADCAST &&
2711 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2712
2713 DEBUG(printk("scsi(%ld): Marking port lost, "
2714 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716
2717 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 }
2719 }
2720
2721 /* Add devices to port list. */
2722 id_iter = (char *)ha->gid_list;
2723 for (index = 0; index < entries; index++) {
2724 domain = ((struct gid_list_info *)id_iter)->domain;
2725 area = ((struct gid_list_info *)id_iter)->area;
2726 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002727 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 loop_id = (uint16_t)
2729 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002730 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002731 loop_id = le16_to_cpu(
2732 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002733 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
2735 /* Bypass reserved domain fields. */
2736 if ((domain & 0xf0) == 0xf0)
2737 continue;
2738
2739 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002740 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002741 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 continue;
2743
2744 /* Bypass invalid local loop ID. */
2745 if (loop_id > LAST_LOCAL_LOOP_ID)
2746 continue;
2747
2748 /* Fill in member data. */
2749 new_fcport->d_id.b.domain = domain;
2750 new_fcport->d_id.b.area = area;
2751 new_fcport->d_id.b.al_pa = al_pa;
2752 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002753 new_fcport->vp_idx = vha->vp_idx;
2754 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002755 if (rval2 != QLA_SUCCESS) {
2756 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2757 "information -- get_port_database=%x, "
2758 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002760 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 vha->host_no));
2762 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 continue;
2764 }
2765
2766 /* Check for matching device in port list. */
2767 found = 0;
2768 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002769 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770 if (memcmp(new_fcport->port_name, fcport->port_name,
2771 WWN_SIZE))
2772 continue;
2773
Shyam Sundarddb9b122009-03-24 09:08:10 -07002774 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 fcport->loop_id = new_fcport->loop_id;
2776 fcport->port_type = new_fcport->port_type;
2777 fcport->d_id.b24 = new_fcport->d_id.b24;
2778 memcpy(fcport->node_name, new_fcport->node_name,
2779 WWN_SIZE);
2780
2781 found++;
2782 break;
2783 }
2784
2785 if (!found) {
2786 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 if (vha->vp_idx) {
2788 new_fcport->vha = vha;
2789 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002790 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
2793 /* Allocate a new replacement fcport. */
2794 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 if (new_fcport == NULL) {
2797 rval = QLA_MEMORY_ALLOC_FAILED;
2798 goto cleanup_allocation;
2799 }
2800 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2801 }
2802
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002803 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002804 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002805
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002806 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 found_devs++;
2809 }
2810
2811cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002812 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 if (rval != QLA_SUCCESS) {
2815 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 }
2818
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 return (rval);
2820}
2821
2822static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002824{
2825#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002826 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2827 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002828 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002829 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002831
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002832 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002833 return;
2834
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002835 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2836 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002837 return;
2838
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002839 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002840 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002841 if (rval != QLA_SUCCESS) {
2842 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2843 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002845 fcport->port_name[2], fcport->port_name[3],
2846 fcport->port_name[4], fcport->port_name[5],
2847 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002848 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002849 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002850 link_speed = link_speeds[LS_UNKNOWN];
2851 if (fcport->fp_speed < 5)
2852 link_speed = link_speeds[fcport->fp_speed];
2853 else if (fcport->fp_speed == 0x13)
2854 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002855 DEBUG2(qla_printk(KERN_INFO, ha,
2856 "iIDMA adjusted to %s GB/s on "
2857 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002858 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002859 fcport->port_name[1], fcport->port_name[2],
2860 fcport->port_name[3], fcport->port_name[4],
2861 fcport->port_name[5], fcport->port_name[6],
2862 fcport->port_name[7]));
2863 }
2864}
2865
Adrian Bunk23be3312006-11-24 02:46:01 +01002866static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002868{
2869 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002870 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002871 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002872
Andrew Vasquezac280b62009-08-20 11:06:05 -07002873 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002874
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002875 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2876 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002877 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2878 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2879 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002881 if (!rport) {
2882 qla_printk(KERN_WARNING, ha,
2883 "Unable to allocate fc remote port!\n");
2884 return;
2885 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002887 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002888 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002889
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002890 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002891
2892 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002893 if (fcport->port_type == FCT_INITIATOR)
2894 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2895 if (fcport->port_type == FCT_TARGET)
2896 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002897 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002898}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899
2900/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002901 * qla2x00_update_fcport
2902 * Updates device on list.
2903 *
2904 * Input:
2905 * ha = adapter block pointer.
2906 * fcport = port structure pointer.
2907 *
2908 * Return:
2909 * 0 - Success
2910 * BIT_0 - error
2911 *
2912 * Context:
2913 * Kernel context.
2914 */
2915void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002916qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002917{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002919
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002920 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002921 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002922 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002923 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002925 PORT_RETRY_TIME);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002926 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002928 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002929
2930 atomic_set(&fcport->state, FCS_ONLINE);
2931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002933}
2934
2935/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 * qla2x00_configure_fabric
2937 * Setup SNS devices with loop ID's.
2938 *
2939 * Input:
2940 * ha = adapter block pointer.
2941 *
2942 * Returns:
2943 * 0 = success.
2944 * BIT_0 = error
2945 */
2946static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948{
2949 int rval, rval2;
2950 fc_port_t *fcport, *fcptemp;
2951 uint16_t next_loopid;
2952 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002953 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 struct qla_hw_data *ha = vha->hw;
2956 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957
2958 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002959 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002960 loop_id = NPH_F_PORT;
2961 else
2962 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002963 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 if (rval != QLA_SUCCESS) {
2965 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 return (QLA_SUCCESS);
2970 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002971 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972
2973 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002974 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 if (rval2 == QLA_RSCNS_HANDLED) {
2976 /* No point doing the scan, just continue. */
2977 return (QLA_SUCCESS);
2978 }
2979 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002980 /* FDMI support. */
2981 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002982 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2983 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002984
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002986 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002987 loop_id = NPH_SNS;
2988 else
2989 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002990 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002991 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 if (mb[0] != MBS_COMMAND_COMPLETE) {
2993 DEBUG2(qla_printk(KERN_INFO, ha,
2994 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002995 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 mb[0], mb[1], mb[2], mb[6], mb[7]));
2997 return (QLA_SUCCESS);
2998 }
2999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003000 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3001 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 /* EMPTY */
3003 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 /* EMPTY */
3008 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 /* EMPTY */
3013 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014 "failed.\n", vha->host_no));
3015 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 /* EMPTY */
3017 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 }
3020 }
3021
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 if (rval != QLA_SUCCESS)
3024 break;
3025
3026 /*
3027 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003028 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003030 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3031 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 break;
3033
3034 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3035 continue;
3036
3037 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003039 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003041 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 fcport->port_type != FCT_INITIATOR &&
3043 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003045 fcport->loop_id,
3046 fcport->d_id.b.domain,
3047 fcport->d_id.b.area,
3048 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 fcport->loop_id = FC_NO_LOOP_ID;
3050 }
3051 }
3052 }
3053
3054 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056
3057 /*
3058 * Scan through our port list and login entries that need to be
3059 * logged in.
3060 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003061 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3062 if (atomic_read(&vha->loop_down_timer) ||
3063 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 break;
3065
3066 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3067 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3068 continue;
3069
3070 if (fcport->loop_id == FC_NO_LOOP_ID) {
3071 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003072 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003073 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 if (rval != QLA_SUCCESS) {
3075 /* Ran out of IDs to use */
3076 break;
3077 }
3078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 }
3082
3083 /* Exit if out of loop IDs. */
3084 if (rval != QLA_SUCCESS) {
3085 break;
3086 }
3087
3088 /*
3089 * Login and add the new devices to our port list.
3090 */
3091 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003092 if (atomic_read(&vha->loop_down_timer) ||
3093 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003094 break;
3095
3096 /* Find a new loop ID to use. */
3097 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003098 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003099 if (rval != QLA_SUCCESS) {
3100 /* Ran out of IDs to use */
3101 break;
3102 }
3103
bdf79622005-04-17 15:06:53 -05003104 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003105 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003106
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003107 if (vha->vp_idx) {
3108 fcport->vha = vha;
3109 fcport->vp_idx = vha->vp_idx;
3110 }
3111 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 }
3113 } while (0);
3114
3115 /* Free all new device structures not processed. */
3116 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3117 list_del(&fcport->list);
3118 kfree(fcport);
3119 }
3120
3121 if (rval) {
3122 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003123 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124 }
3125
3126 return (rval);
3127}
3128
3129
3130/*
3131 * qla2x00_find_all_fabric_devs
3132 *
3133 * Input:
3134 * ha = adapter block pointer.
3135 * dev = database device entry pointer.
3136 *
3137 * Returns:
3138 * 0 = success.
3139 *
3140 * Context:
3141 * Kernel context.
3142 */
3143static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003144qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3145 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146{
3147 int rval;
3148 uint16_t loop_id;
3149 fc_port_t *fcport, *new_fcport, *fcptemp;
3150 int found;
3151
3152 sw_info_t *swl;
3153 int swl_idx;
3154 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003155 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003156 struct qla_hw_data *ha = vha->hw;
3157 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003158 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
3160 rval = QLA_SUCCESS;
3161
3162 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003163 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003164 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 /*EMPTY*/
3166 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003167 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003169 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170 kfree(swl);
3171 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003172 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 kfree(swl);
3174 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003175 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 kfree(swl);
3177 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003178 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003179 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3180 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 }
3182 }
3183 swl_idx = 0;
3184
3185 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003188 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 return (QLA_MEMORY_ALLOC_FAILED);
3190 }
3191 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 /* Set start port ID scan at adapter ID. */
3193 first_dev = 1;
3194 last_dev = 0;
3195
3196 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003197 loop_id = ha->min_external_loopid;
3198 for (; loop_id <= ha->max_loop_id; loop_id++) {
3199 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 continue;
3201
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003202 if (atomic_read(&vha->loop_down_timer) ||
3203 LOOP_TRANSITION(vha)) {
3204 atomic_set(&vha->loop_down_timer, 0);
3205 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3206 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003208 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
3210 if (swl != NULL) {
3211 if (last_dev) {
3212 wrap.b24 = new_fcport->d_id.b24;
3213 } else {
3214 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3215 memcpy(new_fcport->node_name,
3216 swl[swl_idx].node_name, WWN_SIZE);
3217 memcpy(new_fcport->port_name,
3218 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003219 memcpy(new_fcport->fabric_port_name,
3220 swl[swl_idx].fabric_port_name, WWN_SIZE);
3221 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
3223 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3224 last_dev = 1;
3225 }
3226 swl_idx++;
3227 }
3228 } else {
3229 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 if (rval != QLA_SUCCESS) {
3232 qla_printk(KERN_WARNING, ha,
3233 "SNS scan failed -- assuming zero-entry "
3234 "result...\n");
3235 list_for_each_entry_safe(fcport, fcptemp,
3236 new_fcports, list) {
3237 list_del(&fcport->list);
3238 kfree(fcport);
3239 }
3240 rval = QLA_SUCCESS;
3241 break;
3242 }
3243 }
3244
3245 /* If wrap on switch device list, exit. */
3246 if (first_dev) {
3247 wrap.b24 = new_fcport->d_id.b24;
3248 first_dev = 0;
3249 } else if (new_fcport->d_id.b24 == wrap.b24) {
3250 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3253 break;
3254 }
3255
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003256 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 continue;
3259
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003260 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003261 found = 0;
3262 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003263 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3265 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003266 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003268 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003269 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003270 continue;
3271 }
3272
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003273 /* Bypass if same domain and area of adapter. */
3274 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003276 ISP_CFG_FL)
3277 continue;
3278
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 /* Bypass reserved domain fields. */
3280 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3281 continue;
3282
3283 /* Locate matching device in database. */
3284 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 if (memcmp(new_fcport->port_name, fcport->port_name,
3287 WWN_SIZE))
3288 continue;
3289
3290 found++;
3291
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003292 /* Update port state. */
3293 memcpy(fcport->fabric_port_name,
3294 new_fcport->fabric_port_name, WWN_SIZE);
3295 fcport->fp_speed = new_fcport->fp_speed;
3296
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 /*
3298 * If address the same and state FCS_ONLINE, nothing
3299 * changed.
3300 */
3301 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3302 atomic_read(&fcport->state) == FCS_ONLINE) {
3303 break;
3304 }
3305
3306 /*
3307 * If device was not a fabric device before.
3308 */
3309 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3310 fcport->d_id.b24 = new_fcport->d_id.b24;
3311 fcport->loop_id = FC_NO_LOOP_ID;
3312 fcport->flags |= (FCF_FABRIC_DEVICE |
3313 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 break;
3315 }
3316
3317 /*
3318 * Port ID changed or device was marked to be updated;
3319 * Log it out if still logged in and mark it for
3320 * relogin later.
3321 */
3322 fcport->d_id.b24 = new_fcport->d_id.b24;
3323 fcport->flags |= FCF_LOGIN_NEEDED;
3324 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003325 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 fcport->port_type != FCT_INITIATOR &&
3327 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003329 fcport->d_id.b.domain, fcport->d_id.b.area,
3330 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003331 fcport->loop_id = FC_NO_LOOP_ID;
3332 }
3333
3334 break;
3335 }
3336
3337 if (found)
3338 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 /* If device was not in our fcports list, then add it. */
3340 list_add_tail(&new_fcport->list, new_fcports);
3341
3342 /* Allocate a new replacement fcport. */
3343 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003344 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003346 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003347 return (QLA_MEMORY_ALLOC_FAILED);
3348 }
3349 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3350 new_fcport->d_id.b24 = nxt_d_id.b24;
3351 }
3352
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003353 kfree(swl);
3354 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 return (rval);
3357}
3358
3359/*
3360 * qla2x00_find_new_loop_id
3361 * Scan through our port list and find a new usable loop ID.
3362 *
3363 * Input:
3364 * ha: adapter state pointer.
3365 * dev: port structure pointer.
3366 *
3367 * Returns:
3368 * qla2x00 local function return status code.
3369 *
3370 * Context:
3371 * Kernel context.
3372 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003373static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375{
3376 int rval;
3377 int found;
3378 fc_port_t *fcport;
3379 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003380 struct qla_hw_data *ha = vha->hw;
3381 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003382 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383
3384 rval = QLA_SUCCESS;
3385
3386 /* Save starting loop ID. */
3387 first_loop_id = dev->loop_id;
3388
3389 for (;;) {
3390 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003391 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393
3394 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397
3398 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003399 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 /* first loop ID. */
3401 dev->loop_id = ha->min_external_loopid;
3402 }
3403
3404 /* Check for loop ID being already in use. */
3405 found = 0;
3406 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003407 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3409 if (fcport->loop_id == dev->loop_id &&
3410 fcport != dev) {
3411 /* ID possibly in use */
3412 found++;
3413 break;
3414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416 if (found)
3417 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 }
3419
3420 /* If not in use then it is free to use. */
3421 if (!found) {
3422 break;
3423 }
3424
3425 /* ID in use. Try next value. */
3426 dev->loop_id++;
3427
3428 /* If wrap around. No free ID to use. */
3429 if (dev->loop_id == first_loop_id) {
3430 dev->loop_id = FC_NO_LOOP_ID;
3431 rval = QLA_FUNCTION_FAILED;
3432 break;
3433 }
3434 }
3435
3436 return (rval);
3437}
3438
3439/*
3440 * qla2x00_device_resync
3441 * Marks devices in the database that needs resynchronization.
3442 *
3443 * Input:
3444 * ha = adapter block pointer.
3445 *
3446 * Context:
3447 * Kernel context.
3448 */
3449static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451{
3452 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 uint32_t mask;
3454 fc_port_t *fcport;
3455 uint32_t rscn_entry;
3456 uint8_t rscn_out_iter;
3457 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003458 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459
3460 rval = QLA_RSCNS_HANDLED;
3461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3463 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003465 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 format = MSB(MSW(rscn_entry));
3467 d_id.b.domain = LSB(MSW(rscn_entry));
3468 d_id.b.area = MSB(LSW(rscn_entry));
3469 d_id.b.al_pa = LSB(LSW(rscn_entry));
3470
3471 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3472 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 d_id.b.area, d_id.b.al_pa));
3475
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003476 vha->rscn_out_ptr++;
3477 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3478 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
3480 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 for (rscn_out_iter = vha->rscn_out_ptr;
3482 !vha->flags.rscn_queue_overflow &&
3483 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 rscn_out_iter = (rscn_out_iter ==
3485 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003487 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 break;
3489
3490 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 rscn_out_iter));
3493
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003494 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 }
3496
3497 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003500 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501
3502 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003503 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 }
3505
3506 switch (format) {
3507 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508 mask = 0xffffff;
3509 break;
3510 case 1:
3511 mask = 0xffff00;
3512 break;
3513 case 2:
3514 mask = 0xff0000;
3515 break;
3516 default:
3517 mask = 0x0;
3518 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003519 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 break;
3521 }
3522
3523 rval = QLA_SUCCESS;
3524
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3527 (fcport->d_id.b24 & mask) != d_id.b24 ||
3528 fcport->port_type == FCT_BROADCAST)
3529 continue;
3530
3531 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3532 if (format != 3 ||
3533 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003534 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003535 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536 }
3537 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 }
3539 }
3540 return (rval);
3541}
3542
3543/*
3544 * qla2x00_fabric_dev_login
3545 * Login fabric target device and update FC port database.
3546 *
3547 * Input:
3548 * ha: adapter state pointer.
3549 * fcport: port structure list pointer.
3550 * next_loopid: contains value of a new loop ID that can be used
3551 * by the next login attempt.
3552 *
3553 * Returns:
3554 * qla2x00 local function return status code.
3555 *
3556 * Context:
3557 * Kernel context.
3558 */
3559static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 uint16_t *next_loopid)
3562{
3563 int rval;
3564 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003565 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003566 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567
3568 rval = QLA_SUCCESS;
3569 retry = 0;
3570
Andrew Vasquezac280b62009-08-20 11:06:05 -07003571 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003572 if (fcport->flags & FCF_ASYNC_SENT)
3573 return rval;
3574 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003575 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3576 if (!rval)
3577 return rval;
3578 }
3579
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003580 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003581 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003582 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003583 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003584 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003585 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003586 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003587 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003588 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003589 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003590 fcport->d_id.b.domain, fcport->d_id.b.area,
3591 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003592 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003593 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003594 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 }
3596 }
3597
3598 return (rval);
3599}
3600
3601/*
3602 * qla2x00_fabric_login
3603 * Issue fabric login command.
3604 *
3605 * Input:
3606 * ha = adapter block pointer.
3607 * device = pointer to FC device type structure.
3608 *
3609 * Returns:
3610 * 0 - Login successfully
3611 * 1 - Login failed
3612 * 2 - Initiator device
3613 * 3 - Fatal error
3614 */
3615int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003616qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003617 uint16_t *next_loopid)
3618{
3619 int rval;
3620 int retry;
3621 uint16_t tmp_loopid;
3622 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003623 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003624
3625 retry = 0;
3626 tmp_loopid = 0;
3627
3628 for (;;) {
3629 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3630 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003631 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3633
3634 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003635 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636 fcport->d_id.b.domain, fcport->d_id.b.area,
3637 fcport->d_id.b.al_pa, mb, BIT_0);
3638 if (mb[0] == MBS_PORT_ID_USED) {
3639 /*
3640 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003641 * recommends the driver perform an implicit login with
3642 * the specified ID again. The ID we just used is save
3643 * here so we return with an ID that can be tried by
3644 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 */
3646 retry++;
3647 tmp_loopid = fcport->loop_id;
3648 fcport->loop_id = mb[1];
3649
3650 DEBUG(printk("Fabric Login: port in use - next "
3651 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3652 fcport->loop_id, fcport->d_id.b.domain,
3653 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3654
3655 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3656 /*
3657 * Login succeeded.
3658 */
3659 if (retry) {
3660 /* A retry occurred before. */
3661 *next_loopid = tmp_loopid;
3662 } else {
3663 /*
3664 * No retry occurred before. Just increment the
3665 * ID value for next login.
3666 */
3667 *next_loopid = (fcport->loop_id + 1);
3668 }
3669
3670 if (mb[1] & BIT_0) {
3671 fcport->port_type = FCT_INITIATOR;
3672 } else {
3673 fcport->port_type = FCT_TARGET;
3674 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003675 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 }
3677 }
3678
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003679 if (mb[10] & BIT_0)
3680 fcport->supported_classes |= FC_COS_CLASS2;
3681 if (mb[10] & BIT_1)
3682 fcport->supported_classes |= FC_COS_CLASS3;
3683
Linus Torvalds1da177e2005-04-16 15:20:36 -07003684 rval = QLA_SUCCESS;
3685 break;
3686 } else if (mb[0] == MBS_LOOP_ID_USED) {
3687 /*
3688 * Loop ID already used, try next loop ID.
3689 */
3690 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003691 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003692 if (rval != QLA_SUCCESS) {
3693 /* Ran out of loop IDs to use */
3694 break;
3695 }
3696 } else if (mb[0] == MBS_COMMAND_ERROR) {
3697 /*
3698 * Firmware possibly timed out during login. If NO
3699 * retries are left to do then the device is declared
3700 * dead.
3701 */
3702 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003703 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003704 fcport->d_id.b.domain, fcport->d_id.b.area,
3705 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003706 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707
3708 rval = 1;
3709 break;
3710 } else {
3711 /*
3712 * unrecoverable / not handled error
3713 */
3714 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003715 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 fcport->d_id.b.domain, fcport->d_id.b.area,
3718 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3719
3720 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003721 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003722 fcport->d_id.b.domain, fcport->d_id.b.area,
3723 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003724 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003725 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003726
3727 rval = 3;
3728 break;
3729 }
3730 }
3731
3732 return (rval);
3733}
3734
3735/*
3736 * qla2x00_local_device_login
3737 * Issue local device login command.
3738 *
3739 * Input:
3740 * ha = adapter block pointer.
3741 * loop_id = loop id of device to login to.
3742 *
3743 * Returns (Where's the #define!!!!):
3744 * 0 - Login successfully
3745 * 1 - Login failed
3746 * 3 - Fatal error
3747 */
3748int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003749qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003750{
3751 int rval;
3752 uint16_t mb[MAILBOX_REGISTER_COUNT];
3753
3754 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003755 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003756 if (rval == QLA_SUCCESS) {
3757 /* Interrogate mailbox registers for any errors */
3758 if (mb[0] == MBS_COMMAND_ERROR)
3759 rval = 1;
3760 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3761 /* device not in PCB table */
3762 rval = 3;
3763 }
3764
3765 return (rval);
3766}
3767
3768/*
3769 * qla2x00_loop_resync
3770 * Resync with fibre channel devices.
3771 *
3772 * Input:
3773 * ha = adapter block pointer.
3774 *
3775 * Returns:
3776 * 0 = success
3777 */
3778int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003779qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003780{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003781 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003783 struct req_que *req;
3784 struct rsp_que *rsp;
3785
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003786 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003787 req = vha->hw->req_q_map[0];
3788 else
3789 req = vha->req;
3790 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003791
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003792 atomic_set(&vha->loop_state, LOOP_UPDATE);
3793 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3794 if (vha->flags.online) {
3795 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003796 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3797 wait_time = 256;
3798 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003799 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003800
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003801 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003802 qla2x00_marker(vha, req, rsp, 0, 0,
3803 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003804 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805
3806 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003807 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003811 } while (!atomic_read(&vha->loop_down_timer) &&
3812 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3813 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3814 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 }
3817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003823
3824 return (rval);
3825}
3826
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003828qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003829{
3830 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003831 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003832
3833 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003834 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3835 list_for_each_entry(fcport, &vha->vp_fcports, list)
3836 if (fcport && fcport->drport &&
3837 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3838 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003839}
3840
Giridhar Malavalia9083012010-04-12 17:59:55 -07003841void
3842qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3843{
3844 struct qla_hw_data *ha = vha->hw;
3845 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3846 struct scsi_qla_host *tvp;
3847
3848 vha->flags.online = 0;
3849 ha->flags.chip_reset_done = 0;
3850 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3851 ha->qla_stats.total_isp_aborts++;
3852
3853 qla_printk(KERN_INFO, ha,
3854 "Performing ISP error recovery - ha= %p.\n", ha);
3855
3856 /* Chip reset does not apply to 82XX */
3857 if (!IS_QLA82XX(ha))
3858 ha->isp_ops->reset_chip(vha);
3859
3860 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3861 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3862 atomic_set(&vha->loop_state, LOOP_DOWN);
3863 qla2x00_mark_all_devices_lost(vha, 0);
3864 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3865 qla2x00_mark_all_devices_lost(vp, 0);
3866 } else {
3867 if (!atomic_read(&vha->loop_down_timer))
3868 atomic_set(&vha->loop_down_timer,
3869 LOOP_DOWN_TIME);
3870 }
3871
3872 /* Make sure for ISP 82XX IO DMA is complete */
3873 if (IS_QLA82XX(ha))
3874 qla82xx_wait_for_pending_commands(vha);
3875
3876 /* Requeue all commands in outstanding command list. */
3877 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3878}
3879
Linus Torvalds1da177e2005-04-16 15:20:36 -07003880/*
3881* qla2x00_abort_isp
3882* Resets ISP and aborts all outstanding commands.
3883*
3884* Input:
3885* ha = adapter block pointer.
3886*
3887* Returns:
3888* 0 = success
3889*/
3890int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003891qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003893 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003895 struct qla_hw_data *ha = vha->hw;
3896 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003897 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003898 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003900 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003901 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902
Andrew Vasquez85880802009-12-15 21:29:46 -08003903 if (unlikely(pci_channel_offline(ha->pdev) &&
3904 ha->flags.pci_channel_io_perm_failure)) {
3905 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3906 status = 0;
3907 return status;
3908 }
3909
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003910 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003913
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003914 if (!qla2x00_restart_isp(vha)) {
3915 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003918 /*
3919 * Issue marker command only when we are going
3920 * to start the I/O .
3921 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 }
3924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003925 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003926
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003927 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003929 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003930 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003931
Lalit Chandivade29c53972009-10-13 15:16:47 -07003932 if (IS_QLA81XX(ha))
3933 qla2x00_get_fw_version(vha,
3934 &ha->fw_major_version,
3935 &ha->fw_minor_version,
3936 &ha->fw_subminor_version,
3937 &ha->fw_attributes, &ha->fw_memory_size,
3938 ha->mpi_version, &ha->mpi_capabilities,
3939 ha->phy_version);
3940
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003941 if (ha->fce) {
3942 ha->flags.fce_enabled = 1;
3943 memset(ha->fce, 0,
3944 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003945 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003946 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3947 &ha->fce_bufs);
3948 if (rval) {
3949 qla_printk(KERN_WARNING, ha,
3950 "Unable to reinitialize FCE "
3951 "(%d).\n", rval);
3952 ha->flags.fce_enabled = 0;
3953 }
3954 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003955
3956 if (ha->eft) {
3957 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003958 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003959 ha->eft_dma, EFT_NUM_BUFFERS);
3960 if (rval) {
3961 qla_printk(KERN_WARNING, ha,
3962 "Unable to reinitialize EFT "
3963 "(%d).\n", rval);
3964 }
3965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003966 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003967 vha->flags.online = 1;
3968 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003969 if (ha->isp_abort_cnt == 0) {
3970 qla_printk(KERN_WARNING, ha,
3971 "ISP error recovery failed - "
3972 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003973 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974 * The next call disables the board
3975 * completely.
3976 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003977 ha->isp_ops->reset_adapter(vha);
3978 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003979 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003980 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 status = 0;
3982 } else { /* schedule another ISP abort */
3983 ha->isp_abort_cnt--;
3984 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003985 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003986 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003987 status = 1;
3988 }
3989 } else {
3990 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3991 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3992 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003993 vha->host_no, ha->isp_abort_cnt));
3994 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003995 status = 1;
3996 }
3997 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003998
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 }
4000
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001 if (!status) {
4002 DEBUG(printk(KERN_INFO
4003 "qla2x00_abort_isp(%ld): succeeded.\n",
4004 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08004005 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004006 if (vp->vp_idx)
4007 qla2x00_vp_abort_isp(vp);
4008 }
4009 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004010 qla_printk(KERN_INFO, ha,
4011 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004012 }
4013
4014 return(status);
4015}
4016
4017/*
4018* qla2x00_restart_isp
4019* restarts the ISP after a reset
4020*
4021* Input:
4022* ha = adapter block pointer.
4023*
4024* Returns:
4025* 0 = success
4026*/
4027static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004028qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004029{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004030 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004032 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004033 struct req_que *req = ha->req_q_map[0];
4034 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004035
4036 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004037 if (qla2x00_isp_firmware(vha)) {
4038 vha->flags.online = 0;
4039 status = ha->isp_ops->chip_diag(vha);
4040 if (!status)
4041 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004042 }
4043
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004044 if (!status && !(status = qla2x00_init_rings(vha))) {
4045 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004046 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004047 /* Initialize the queues in use */
4048 qla25xx_init_queues(ha);
4049
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004050 status = qla2x00_fw_ready(vha);
4051 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004053 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004054
4055 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004056 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004057
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004058 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004059 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4060 wait_time = 256;
4061 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4063 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004065 } while (!atomic_read(&vha->loop_down_timer) &&
4066 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4067 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4068 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004069 }
4070
4071 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004072 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 status = 0;
4074
4075 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4076 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004077 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004078 }
4079 return (status);
4080}
4081
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004082static int
4083qla25xx_init_queues(struct qla_hw_data *ha)
4084{
4085 struct rsp_que *rsp = NULL;
4086 struct req_que *req = NULL;
4087 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4088 int ret = -1;
4089 int i;
4090
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004091 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004092 rsp = ha->rsp_q_map[i];
4093 if (rsp) {
4094 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004095 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004096 if (ret != QLA_SUCCESS)
4097 DEBUG2_17(printk(KERN_WARNING
4098 "%s Rsp que:%d init failed\n", __func__,
4099 rsp->id));
4100 else
4101 DEBUG2_17(printk(KERN_INFO
4102 "%s Rsp que:%d inited\n", __func__,
4103 rsp->id));
4104 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004105 }
4106 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004107 req = ha->req_q_map[i];
4108 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004109 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004110 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004111 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004112 if (ret != QLA_SUCCESS)
4113 DEBUG2_17(printk(KERN_WARNING
4114 "%s Req que:%d init failed\n", __func__,
4115 req->id));
4116 else
4117 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004118 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004119 req->id));
4120 }
4121 }
4122 return ret;
4123}
4124
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125/*
4126* qla2x00_reset_adapter
4127* Reset adapter.
4128*
4129* Input:
4130* ha = adapter block pointer.
4131*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004132void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004133qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134{
4135 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004136 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004137 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004140 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141
Linus Torvalds1da177e2005-04-16 15:20:36 -07004142 spin_lock_irqsave(&ha->hardware_lock, flags);
4143 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4144 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4145 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4146 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4147 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4148}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004149
4150void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004152{
4153 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004154 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004155 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4156
Giridhar Malavalia9083012010-04-12 17:59:55 -07004157 if (IS_QLA82XX(ha))
4158 return;
4159
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004161 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004162
4163 spin_lock_irqsave(&ha->hardware_lock, flags);
4164 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4165 RD_REG_DWORD(&reg->hccr);
4166 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4167 RD_REG_DWORD(&reg->hccr);
4168 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004169
4170 if (IS_NOPOLLING_TYPE(ha))
4171 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004172}
4173
David Miller4e08df32007-04-16 12:37:43 -07004174/* On sparc systems, obtain port and node WWN from firmware
4175 * properties.
4176 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004177static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4178 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004179{
4180#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004181 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004182 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004183 struct device_node *dp = pci_device_to_OF_node(pdev);
4184 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004185 int len;
4186
4187 val = of_get_property(dp, "port-wwn", &len);
4188 if (val && len >= WWN_SIZE)
4189 memcpy(nv->port_name, val, WWN_SIZE);
4190
4191 val = of_get_property(dp, "node-wwn", &len);
4192 if (val && len >= WWN_SIZE)
4193 memcpy(nv->node_name, val, WWN_SIZE);
4194#endif
4195}
4196
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004197int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004198qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004199{
David Miller4e08df32007-04-16 12:37:43 -07004200 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004201 struct init_cb_24xx *icb;
4202 struct nvram_24xx *nv;
4203 uint32_t *dptr;
4204 uint8_t *dptr1, *dptr2;
4205 uint32_t chksum;
4206 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004207 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004208
David Miller4e08df32007-04-16 12:37:43 -07004209 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004210 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004211 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004212
4213 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004214 if (ha->flags.port0) {
4215 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4216 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4217 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004218 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004219 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4220 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004221 ha->nvram_size = sizeof(struct nvram_24xx);
4222 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004223 if (IS_QLA82XX(ha))
4224 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004225
Seokmann Ju281afe12007-07-26 13:43:34 -07004226 /* Get VPD data into cache */
4227 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004228 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004229 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4230
4231 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004232 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004233 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004234 ha->nvram_size);
4235 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4236 chksum += le32_to_cpu(*dptr++);
4237
Andrew Vasquez76403352009-04-06 22:33:39 -07004238 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004239 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004240
4241 /* Bad NVRAM data, set defaults parameters. */
4242 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4243 || nv->id[3] != ' ' ||
4244 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4245 /* Reset NVRAM data. */
4246 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4247 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4248 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004249 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4250 "invalid -- WWPN) defaults.\n");
4251
4252 /*
4253 * Set default initialization control block.
4254 */
4255 memset(nv, 0, ha->nvram_size);
4256 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4257 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4258 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4259 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4260 nv->exchange_count = __constant_cpu_to_le16(0);
4261 nv->hard_address = __constant_cpu_to_le16(124);
4262 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004263 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004264 nv->port_name[2] = 0x00;
4265 nv->port_name[3] = 0xe0;
4266 nv->port_name[4] = 0x8b;
4267 nv->port_name[5] = 0x1c;
4268 nv->port_name[6] = 0x55;
4269 nv->port_name[7] = 0x86;
4270 nv->node_name[0] = 0x20;
4271 nv->node_name[1] = 0x00;
4272 nv->node_name[2] = 0x00;
4273 nv->node_name[3] = 0xe0;
4274 nv->node_name[4] = 0x8b;
4275 nv->node_name[5] = 0x1c;
4276 nv->node_name[6] = 0x55;
4277 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004278 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004279 nv->login_retry_count = __constant_cpu_to_le16(8);
4280 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4281 nv->login_timeout = __constant_cpu_to_le16(0);
4282 nv->firmware_options_1 =
4283 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4284 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4285 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4286 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4287 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4288 nv->efi_parameters = __constant_cpu_to_le32(0);
4289 nv->reset_delay = 5;
4290 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4291 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4292 nv->link_down_timeout = __constant_cpu_to_le16(30);
4293
4294 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004295 }
4296
4297 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004298 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004299
4300 /* Copy 1st segment. */
4301 dptr1 = (uint8_t *)icb;
4302 dptr2 = (uint8_t *)&nv->version;
4303 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4304 while (cnt--)
4305 *dptr1++ = *dptr2++;
4306
4307 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004308 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004309
4310 /* Copy 2nd segment. */
4311 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4312 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4313 cnt = (uint8_t *)&icb->reserved_3 -
4314 (uint8_t *)&icb->interrupt_delay_timer;
4315 while (cnt--)
4316 *dptr1++ = *dptr2++;
4317
4318 /*
4319 * Setup driver NVRAM options.
4320 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004321 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004322 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004323
Andrew Vasquez5341e862006-05-17 15:09:16 -07004324 /* Use alternate WWN? */
4325 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4326 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4327 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4328 }
4329
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004330 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004331 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004332 /*
4333 * Firmware will apply the following mask if the nodename was
4334 * not provided.
4335 */
4336 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4337 icb->node_name[0] &= 0xF0;
4338 }
4339
4340 /* Set host adapter parameters. */
4341 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004342 ha->flags.enable_lip_reset = 0;
4343 ha->flags.enable_lip_full_login =
4344 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4345 ha->flags.enable_target_reset =
4346 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004347 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004348 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004349
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004350 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4351 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004352
4353 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4354 sizeof(ha->fw_seriallink_options24));
4355
4356 /* save HBA serial number */
4357 ha->serial0 = icb->port_name[5];
4358 ha->serial1 = icb->port_name[6];
4359 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004360 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4361 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004362
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004363 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4364
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004365 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4366
4367 /* Set minimum login_timeout to 4 seconds. */
4368 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4369 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4370 if (le16_to_cpu(nv->login_timeout) < 4)
4371 nv->login_timeout = __constant_cpu_to_le16(4);
4372 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004373 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004374
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004375 /* Set minimum RATOV to 100 tenths of a second. */
4376 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004377
4378 ha->loop_reset_delay = nv->reset_delay;
4379
4380 /* Link Down Timeout = 0:
4381 *
4382 * When Port Down timer expires we will start returning
4383 * I/O's to OS with "DID_NO_CONNECT".
4384 *
4385 * Link Down Timeout != 0:
4386 *
4387 * The driver waits for the link to come up after link down
4388 * before returning I/Os to OS with "DID_NO_CONNECT".
4389 */
4390 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4391 ha->loop_down_abort_time =
4392 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4393 } else {
4394 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4395 ha->loop_down_abort_time =
4396 (LOOP_DOWN_TIME - ha->link_down_timeout);
4397 }
4398
4399 /* Need enough time to try and get the port back. */
4400 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4401 if (qlport_down_retry)
4402 ha->port_down_retry_count = qlport_down_retry;
4403
4404 /* Set login_retry_count */
4405 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4406 if (ha->port_down_retry_count ==
4407 le16_to_cpu(nv->port_down_retry_count) &&
4408 ha->port_down_retry_count > 3)
4409 ha->login_retry_count = ha->port_down_retry_count;
4410 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4411 ha->login_retry_count = ha->port_down_retry_count;
4412 if (ql2xloginretrycount)
4413 ha->login_retry_count = ql2xloginretrycount;
4414
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004415 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004416 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004417 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4418 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4419 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4420 le16_to_cpu(icb->interrupt_delay_timer): 2;
4421 }
4422 icb->firmware_options_2 &= __constant_cpu_to_le32(
4423 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004424 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004425 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004426 ha->zio_mode = QLA_ZIO_MODE_6;
4427
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004428 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004429 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004430 ha->zio_timer * 100));
4431 qla_printk(KERN_INFO, ha,
4432 "ZIO mode %d enabled; timer delay (%d us).\n",
4433 ha->zio_mode, ha->zio_timer * 100);
4434
4435 icb->firmware_options_2 |= cpu_to_le32(
4436 (uint32_t)ha->zio_mode);
4437 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004438 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004439 }
4440
David Miller4e08df32007-04-16 12:37:43 -07004441 if (rval) {
4442 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004443 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004444 }
4445 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004446}
4447
Adrian Bunk413975a2006-06-30 02:33:06 -07004448static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004449qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4450 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004451{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004452 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004453 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004454 uint32_t *dcode, dlen;
4455 uint32_t risc_addr;
4456 uint32_t risc_size;
4457 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004458 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004459 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004460
4461 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004462 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004463
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004464 rval = QLA_SUCCESS;
4465
4466 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004467 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004468 *srisc_addr = 0;
4469
4470 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004471 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004472 for (i = 0; i < 4; i++)
4473 dcode[i] = be32_to_cpu(dcode[i]);
4474 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4475 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4476 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4477 dcode[3] == 0)) {
4478 qla_printk(KERN_WARNING, ha,
4479 "Unable to verify integrity of flash firmware image!\n");
4480 qla_printk(KERN_WARNING, ha,
4481 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4482 dcode[1], dcode[2], dcode[3]);
4483
4484 return QLA_FUNCTION_FAILED;
4485 }
4486
4487 while (segments && rval == QLA_SUCCESS) {
4488 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004489 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004490
4491 risc_addr = be32_to_cpu(dcode[2]);
4492 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4493 risc_size = be32_to_cpu(dcode[3]);
4494
4495 fragment = 0;
4496 while (risc_size > 0 && rval == QLA_SUCCESS) {
4497 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4498 if (dlen > risc_size)
4499 dlen = risc_size;
4500
4501 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4502 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004504
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004505 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004506 for (i = 0; i < dlen; i++)
4507 dcode[i] = swab32(dcode[i]);
4508
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004509 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004510 dlen);
4511 if (rval) {
4512 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004513 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004514 fragment));
4515 qla_printk(KERN_WARNING, ha,
4516 "[ERROR] Failed to load segment %d of "
4517 "firmware\n", fragment);
4518 break;
4519 }
4520
4521 faddr += dlen;
4522 risc_addr += dlen;
4523 risc_size -= dlen;
4524 fragment++;
4525 }
4526
4527 /* Next segment. */
4528 segments--;
4529 }
4530
4531 return rval;
4532}
4533
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004534#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4535
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004536int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004537qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004538{
4539 int rval;
4540 int i, fragment;
4541 uint16_t *wcode, *fwcode;
4542 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4543 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004544 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004545 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004546
4547 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004548 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004549 if (!blob) {
4550 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004551 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4552 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004553 return QLA_FUNCTION_FAILED;
4554 }
4555
4556 rval = QLA_SUCCESS;
4557
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004558 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004559 *srisc_addr = 0;
4560 fwcode = (uint16_t *)blob->fw->data;
4561 fwclen = 0;
4562
4563 /* Validate firmware image by checking version. */
4564 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4565 qla_printk(KERN_WARNING, ha,
4566 "Unable to verify integrity of firmware image (%Zd)!\n",
4567 blob->fw->size);
4568 goto fail_fw_integrity;
4569 }
4570 for (i = 0; i < 4; i++)
4571 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4572 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4573 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4574 wcode[2] == 0 && wcode[3] == 0)) {
4575 qla_printk(KERN_WARNING, ha,
4576 "Unable to verify integrity of firmware image!\n");
4577 qla_printk(KERN_WARNING, ha,
4578 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4579 wcode[1], wcode[2], wcode[3]);
4580 goto fail_fw_integrity;
4581 }
4582
4583 seg = blob->segs;
4584 while (*seg && rval == QLA_SUCCESS) {
4585 risc_addr = *seg;
4586 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4587 risc_size = be16_to_cpu(fwcode[3]);
4588
4589 /* Validate firmware image size. */
4590 fwclen += risc_size * sizeof(uint16_t);
4591 if (blob->fw->size < fwclen) {
4592 qla_printk(KERN_WARNING, ha,
4593 "Unable to verify integrity of firmware image "
4594 "(%Zd)!\n", blob->fw->size);
4595 goto fail_fw_integrity;
4596 }
4597
4598 fragment = 0;
4599 while (risc_size > 0 && rval == QLA_SUCCESS) {
4600 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4601 if (wlen > risc_size)
4602 wlen = risc_size;
4603
4604 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004605 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004606 risc_addr, wlen));
4607
4608 for (i = 0; i < wlen; i++)
4609 wcode[i] = swab16(fwcode[i]);
4610
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004611 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004612 wlen);
4613 if (rval) {
4614 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004615 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004616 fragment));
4617 qla_printk(KERN_WARNING, ha,
4618 "[ERROR] Failed to load segment %d of "
4619 "firmware\n", fragment);
4620 break;
4621 }
4622
4623 fwcode += wlen;
4624 risc_addr += wlen;
4625 risc_size -= wlen;
4626 fragment++;
4627 }
4628
4629 /* Next segment. */
4630 seg++;
4631 }
4632 return rval;
4633
4634fail_fw_integrity:
4635 return QLA_FUNCTION_FAILED;
4636}
4637
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004638static int
4639qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004640{
4641 int rval;
4642 int segments, fragment;
4643 uint32_t *dcode, dlen;
4644 uint32_t risc_addr;
4645 uint32_t risc_size;
4646 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004647 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004648 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004649 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004650 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004651
Andrew Vasquez54333832005-11-09 15:49:04 -08004652 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004653 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004654 if (!blob) {
4655 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004656 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4657 "from: " QLA_FW_URL ".\n");
4658
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004659 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004660 }
4661
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004662 qla_printk(KERN_INFO, ha,
4663 "FW: Loading via request-firmware...\n");
4664
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004665 rval = QLA_SUCCESS;
4666
4667 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004668 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004669 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004670 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004671 fwclen = 0;
4672
4673 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004674 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004675 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004676 "Unable to verify integrity of firmware image (%Zd)!\n",
4677 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004678 goto fail_fw_integrity;
4679 }
4680 for (i = 0; i < 4; i++)
4681 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4682 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4683 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4684 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4685 dcode[3] == 0)) {
4686 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004687 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004688 qla_printk(KERN_WARNING, ha,
4689 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4690 dcode[1], dcode[2], dcode[3]);
4691 goto fail_fw_integrity;
4692 }
4693
4694 while (segments && rval == QLA_SUCCESS) {
4695 risc_addr = be32_to_cpu(fwcode[2]);
4696 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4697 risc_size = be32_to_cpu(fwcode[3]);
4698
4699 /* Validate firmware image size. */
4700 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004701 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004702 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004703 "Unable to verify integrity of firmware image "
4704 "(%Zd)!\n", blob->fw->size);
4705
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004706 goto fail_fw_integrity;
4707 }
4708
4709 fragment = 0;
4710 while (risc_size > 0 && rval == QLA_SUCCESS) {
4711 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4712 if (dlen > risc_size)
4713 dlen = risc_size;
4714
4715 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004716 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004717 risc_addr, dlen));
4718
4719 for (i = 0; i < dlen; i++)
4720 dcode[i] = swab32(fwcode[i]);
4721
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004722 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004723 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004724 if (rval) {
4725 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004726 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004727 fragment));
4728 qla_printk(KERN_WARNING, ha,
4729 "[ERROR] Failed to load segment %d of "
4730 "firmware\n", fragment);
4731 break;
4732 }
4733
4734 fwcode += dlen;
4735 risc_addr += dlen;
4736 risc_size -= dlen;
4737 fragment++;
4738 }
4739
4740 /* Next segment. */
4741 segments--;
4742 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004743 return rval;
4744
4745fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004746 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004747}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004748
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004749int
4750qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4751{
4752 int rval;
4753
Andrew Vasqueze337d902009-04-06 22:33:49 -07004754 if (ql2xfwloadbin == 1)
4755 return qla81xx_load_risc(vha, srisc_addr);
4756
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004757 /*
4758 * FW Load priority:
4759 * 1) Firmware via request-firmware interface (.bin file).
4760 * 2) Firmware residing in flash.
4761 */
4762 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4763 if (rval == QLA_SUCCESS)
4764 return rval;
4765
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004766 return qla24xx_load_risc_flash(vha, srisc_addr,
4767 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004768}
4769
4770int
4771qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4772{
4773 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004774 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004775
Andrew Vasqueze337d902009-04-06 22:33:49 -07004776 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004777 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004778
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004779 /*
4780 * FW Load priority:
4781 * 1) Firmware residing in flash.
4782 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004783 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004784 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004785 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004786 if (rval == QLA_SUCCESS)
4787 return rval;
4788
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004789try_blob_fw:
4790 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4791 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4792 return rval;
4793
4794 qla_printk(KERN_ERR, ha,
4795 "FW: Attempting to fallback to golden firmware...\n");
4796 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4797 if (rval != QLA_SUCCESS)
4798 return rval;
4799
4800 qla_printk(KERN_ERR, ha,
4801 "FW: Please update operational firmware...\n");
4802 ha->flags.running_gold_fw = 1;
4803
4804 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004805}
4806
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004807void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004808qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004809{
4810 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004811 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004812
Andrew Vasquez85880802009-12-15 21:29:46 -08004813 if (ha->flags.pci_channel_io_perm_failure)
4814 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004815 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004816 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004817 if (!ha->fw_major_version)
4818 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004819
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004820 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004821 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004822 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004823 ha->isp_ops->reset_chip(vha);
4824 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004825 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004826 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004827 continue;
4828 qla_printk(KERN_INFO, ha,
4829 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004830 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004831 }
4832}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004833
4834int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004835qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004836{
4837 int rval = QLA_SUCCESS;
4838 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004839 struct qla_hw_data *ha = vha->hw;
4840 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004841 struct req_que *req;
4842 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004843
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004844 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004845 return -EINVAL;
4846
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004847 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004848 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004849 req = ha->req_q_map[0];
4850 else
4851 req = vha->req;
4852 rsp = req->rsp;
4853
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004854 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004855 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004856 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004857 }
4858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004859 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004860
4861 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004862 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004863 if (mb[0] != MBS_COMMAND_COMPLETE) {
4864 DEBUG15(qla_printk(KERN_INFO, ha,
4865 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4866 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4867 mb[0], mb[1], mb[2], mb[6], mb[7]));
4868 return (QLA_FUNCTION_FAILED);
4869 }
4870
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004871 atomic_set(&vha->loop_down_timer, 0);
4872 atomic_set(&vha->loop_state, LOOP_UP);
4873 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4874 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4875 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004876
4877 return rval;
4878}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004879
4880/* 84XX Support **************************************************************/
4881
4882static LIST_HEAD(qla_cs84xx_list);
4883static DEFINE_MUTEX(qla_cs84xx_mutex);
4884
4885static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004886qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004887{
4888 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004889 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004890
4891 mutex_lock(&qla_cs84xx_mutex);
4892
4893 /* Find any shared 84xx chip. */
4894 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4895 if (cs84xx->bus == ha->pdev->bus) {
4896 kref_get(&cs84xx->kref);
4897 goto done;
4898 }
4899 }
4900
4901 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4902 if (!cs84xx)
4903 goto done;
4904
4905 kref_init(&cs84xx->kref);
4906 spin_lock_init(&cs84xx->access_lock);
4907 mutex_init(&cs84xx->fw_update_mutex);
4908 cs84xx->bus = ha->pdev->bus;
4909
4910 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4911done:
4912 mutex_unlock(&qla_cs84xx_mutex);
4913 return cs84xx;
4914}
4915
4916static void
4917__qla84xx_chip_release(struct kref *kref)
4918{
4919 struct qla_chip_state_84xx *cs84xx =
4920 container_of(kref, struct qla_chip_state_84xx, kref);
4921
4922 mutex_lock(&qla_cs84xx_mutex);
4923 list_del(&cs84xx->list);
4924 mutex_unlock(&qla_cs84xx_mutex);
4925 kfree(cs84xx);
4926}
4927
4928void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004929qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004930{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004931 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004932 if (ha->cs84xx)
4933 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4934}
4935
4936static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004937qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004938{
4939 int rval;
4940 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004941 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004942
4943 mutex_lock(&ha->cs84xx->fw_update_mutex);
4944
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004945 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004946
4947 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4948
4949 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4950 QLA_SUCCESS;
4951}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004952
4953/* 81XX Support **************************************************************/
4954
4955int
4956qla81xx_nvram_config(scsi_qla_host_t *vha)
4957{
4958 int rval;
4959 struct init_cb_81xx *icb;
4960 struct nvram_81xx *nv;
4961 uint32_t *dptr;
4962 uint8_t *dptr1, *dptr2;
4963 uint32_t chksum;
4964 uint16_t cnt;
4965 struct qla_hw_data *ha = vha->hw;
4966
4967 rval = QLA_SUCCESS;
4968 icb = (struct init_cb_81xx *)ha->init_cb;
4969 nv = ha->nvram;
4970
4971 /* Determine NVRAM starting address. */
4972 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004973 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004974
4975 /* Get VPD data into cache */
4976 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004977 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4978 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004979
4980 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004981 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004982 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004983 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004984 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4985 chksum += le32_to_cpu(*dptr++);
4986
Andrew Vasquez76403352009-04-06 22:33:39 -07004987 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004988 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4989
4990 /* Bad NVRAM data, set defaults parameters. */
4991 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4992 || nv->id[3] != ' ' ||
4993 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4994 /* Reset NVRAM data. */
4995 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4996 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4997 le16_to_cpu(nv->nvram_version));
4998 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4999 "invalid -- WWPN) defaults.\n");
5000
5001 /*
5002 * Set default initialization control block.
5003 */
5004 memset(nv, 0, ha->nvram_size);
5005 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5006 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5007 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5008 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5009 nv->exchange_count = __constant_cpu_to_le16(0);
5010 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005011 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005012 nv->port_name[2] = 0x00;
5013 nv->port_name[3] = 0xe0;
5014 nv->port_name[4] = 0x8b;
5015 nv->port_name[5] = 0x1c;
5016 nv->port_name[6] = 0x55;
5017 nv->port_name[7] = 0x86;
5018 nv->node_name[0] = 0x20;
5019 nv->node_name[1] = 0x00;
5020 nv->node_name[2] = 0x00;
5021 nv->node_name[3] = 0xe0;
5022 nv->node_name[4] = 0x8b;
5023 nv->node_name[5] = 0x1c;
5024 nv->node_name[6] = 0x55;
5025 nv->node_name[7] = 0x86;
5026 nv->login_retry_count = __constant_cpu_to_le16(8);
5027 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5028 nv->login_timeout = __constant_cpu_to_le16(0);
5029 nv->firmware_options_1 =
5030 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5031 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5032 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5033 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5034 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5035 nv->efi_parameters = __constant_cpu_to_le32(0);
5036 nv->reset_delay = 5;
5037 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5038 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5039 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005040 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005041 nv->enode_mac[1] = 0x02;
5042 nv->enode_mac[2] = 0x03;
5043 nv->enode_mac[3] = 0x04;
5044 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005045 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005046
5047 rval = 1;
5048 }
5049
5050 /* Reset Initialization control block */
5051 memset(icb, 0, sizeof(struct init_cb_81xx));
5052
5053 /* Copy 1st segment. */
5054 dptr1 = (uint8_t *)icb;
5055 dptr2 = (uint8_t *)&nv->version;
5056 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5057 while (cnt--)
5058 *dptr1++ = *dptr2++;
5059
5060 icb->login_retry_count = nv->login_retry_count;
5061
5062 /* Copy 2nd segment. */
5063 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5064 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5065 cnt = (uint8_t *)&icb->reserved_5 -
5066 (uint8_t *)&icb->interrupt_delay_timer;
5067 while (cnt--)
5068 *dptr1++ = *dptr2++;
5069
5070 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5071 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5072 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5073 icb->enode_mac[0] = 0x01;
5074 icb->enode_mac[1] = 0x02;
5075 icb->enode_mac[2] = 0x03;
5076 icb->enode_mac[3] = 0x04;
5077 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005078 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005079 }
5080
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005081 /* Use extended-initialization control block. */
5082 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5083
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005084 /*
5085 * Setup driver NVRAM options.
5086 */
5087 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005088 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005089
5090 /* Use alternate WWN? */
5091 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5092 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5093 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5094 }
5095
5096 /* Prepare nodename */
5097 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5098 /*
5099 * Firmware will apply the following mask if the nodename was
5100 * not provided.
5101 */
5102 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5103 icb->node_name[0] &= 0xF0;
5104 }
5105
5106 /* Set host adapter parameters. */
5107 ha->flags.disable_risc_code_load = 0;
5108 ha->flags.enable_lip_reset = 0;
5109 ha->flags.enable_lip_full_login =
5110 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5111 ha->flags.enable_target_reset =
5112 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5113 ha->flags.enable_led_scheme = 0;
5114 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5115
5116 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5117 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5118
5119 /* save HBA serial number */
5120 ha->serial0 = icb->port_name[5];
5121 ha->serial1 = icb->port_name[6];
5122 ha->serial2 = icb->port_name[7];
5123 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5124 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5125
5126 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5127
5128 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5129
5130 /* Set minimum login_timeout to 4 seconds. */
5131 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5132 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5133 if (le16_to_cpu(nv->login_timeout) < 4)
5134 nv->login_timeout = __constant_cpu_to_le16(4);
5135 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5136 icb->login_timeout = nv->login_timeout;
5137
5138 /* Set minimum RATOV to 100 tenths of a second. */
5139 ha->r_a_tov = 100;
5140
5141 ha->loop_reset_delay = nv->reset_delay;
5142
5143 /* Link Down Timeout = 0:
5144 *
5145 * When Port Down timer expires we will start returning
5146 * I/O's to OS with "DID_NO_CONNECT".
5147 *
5148 * Link Down Timeout != 0:
5149 *
5150 * The driver waits for the link to come up after link down
5151 * before returning I/Os to OS with "DID_NO_CONNECT".
5152 */
5153 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5154 ha->loop_down_abort_time =
5155 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5156 } else {
5157 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5158 ha->loop_down_abort_time =
5159 (LOOP_DOWN_TIME - ha->link_down_timeout);
5160 }
5161
5162 /* Need enough time to try and get the port back. */
5163 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5164 if (qlport_down_retry)
5165 ha->port_down_retry_count = qlport_down_retry;
5166
5167 /* Set login_retry_count */
5168 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5169 if (ha->port_down_retry_count ==
5170 le16_to_cpu(nv->port_down_retry_count) &&
5171 ha->port_down_retry_count > 3)
5172 ha->login_retry_count = ha->port_down_retry_count;
5173 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5174 ha->login_retry_count = ha->port_down_retry_count;
5175 if (ql2xloginretrycount)
5176 ha->login_retry_count = ql2xloginretrycount;
5177
5178 /* Enable ZIO. */
5179 if (!vha->flags.init_done) {
5180 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5181 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5182 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5183 le16_to_cpu(icb->interrupt_delay_timer): 2;
5184 }
5185 icb->firmware_options_2 &= __constant_cpu_to_le32(
5186 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5187 vha->flags.process_response_queue = 0;
5188 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5189 ha->zio_mode = QLA_ZIO_MODE_6;
5190
5191 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5192 "(%d us).\n", vha->host_no, ha->zio_mode,
5193 ha->zio_timer * 100));
5194 qla_printk(KERN_INFO, ha,
5195 "ZIO mode %d enabled; timer delay (%d us).\n",
5196 ha->zio_mode, ha->zio_timer * 100);
5197
5198 icb->firmware_options_2 |= cpu_to_le32(
5199 (uint32_t)ha->zio_mode);
5200 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5201 vha->flags.process_response_queue = 1;
5202 }
5203
5204 if (rval) {
5205 DEBUG2_3(printk(KERN_WARNING
5206 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5207 }
5208 return (rval);
5209}
5210
Giridhar Malavalia9083012010-04-12 17:59:55 -07005211int
5212qla82xx_restart_isp(scsi_qla_host_t *vha)
5213{
5214 int status, rval;
5215 uint32_t wait_time;
5216 struct qla_hw_data *ha = vha->hw;
5217 struct req_que *req = ha->req_q_map[0];
5218 struct rsp_que *rsp = ha->rsp_q_map[0];
5219 struct scsi_qla_host *vp;
5220 struct scsi_qla_host *tvp;
5221
5222 status = qla2x00_init_rings(vha);
5223 if (!status) {
5224 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5225 ha->flags.chip_reset_done = 1;
5226
5227 status = qla2x00_fw_ready(vha);
5228 if (!status) {
5229 qla_printk(KERN_INFO, ha,
5230 "%s(): Start configure loop, "
5231 "status = %d\n", __func__, status);
5232
5233 /* Issue a marker after FW becomes ready. */
5234 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5235
5236 vha->flags.online = 1;
5237 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5238 wait_time = 256;
5239 do {
5240 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5241 qla2x00_configure_loop(vha);
5242 wait_time--;
5243 } while (!atomic_read(&vha->loop_down_timer) &&
5244 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5245 wait_time &&
5246 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5247 }
5248
5249 /* if no cable then assume it's good */
5250 if ((vha->device_flags & DFLG_NO_CABLE))
5251 status = 0;
5252
5253 qla_printk(KERN_INFO, ha,
5254 "%s(): Configure loop done, status = 0x%x\n",
5255 __func__, status);
5256 }
5257
5258 if (!status) {
5259 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5260
5261 if (!atomic_read(&vha->loop_down_timer)) {
5262 /*
5263 * Issue marker command only when we are going
5264 * to start the I/O .
5265 */
5266 vha->marker_needed = 1;
5267 }
5268
5269 vha->flags.online = 1;
5270
5271 ha->isp_ops->enable_intrs(ha);
5272
5273 ha->isp_abort_cnt = 0;
5274 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5275
5276 if (ha->fce) {
5277 ha->flags.fce_enabled = 1;
5278 memset(ha->fce, 0,
5279 fce_calc_size(ha->fce_bufs));
5280 rval = qla2x00_enable_fce_trace(vha,
5281 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5282 &ha->fce_bufs);
5283 if (rval) {
5284 qla_printk(KERN_WARNING, ha,
5285 "Unable to reinitialize FCE "
5286 "(%d).\n", rval);
5287 ha->flags.fce_enabled = 0;
5288 }
5289 }
5290
5291 if (ha->eft) {
5292 memset(ha->eft, 0, EFT_SIZE);
5293 rval = qla2x00_enable_eft_trace(vha,
5294 ha->eft_dma, EFT_NUM_BUFFERS);
5295 if (rval) {
5296 qla_printk(KERN_WARNING, ha,
5297 "Unable to reinitialize EFT "
5298 "(%d).\n", rval);
5299 }
5300 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005301 }
5302
5303 if (!status) {
5304 DEBUG(printk(KERN_INFO
5305 "qla82xx_restart_isp(%ld): succeeded.\n",
5306 vha->host_no));
5307 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5308 if (vp->vp_idx)
5309 qla2x00_vp_abort_isp(vp);
5310 }
5311 } else {
5312 qla_printk(KERN_INFO, ha,
5313 "qla82xx_restart_isp: **** FAILED ****\n");
5314 }
5315
5316 return status;
5317}
5318
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005319void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005320qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005321{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005322 struct qla_hw_data *ha = vha->hw;
5323
5324 if (!ql2xetsenable)
5325 return;
5326
5327 /* Enable ETS Burst. */
5328 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5329 ha->fw_options[2] |= BIT_9;
5330 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005331}
Sarang Radke09ff7012010-03-19 17:03:59 -07005332
5333/*
5334 * qla24xx_get_fcp_prio
5335 * Gets the fcp cmd priority value for the logged in port.
5336 * Looks for a match of the port descriptors within
5337 * each of the fcp prio config entries. If a match is found,
5338 * the tag (priority) value is returned.
5339 *
5340 * Input:
5341 * ha = adapter block po
5342 * fcport = port structure pointer.
5343 *
5344 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005345 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005346 * 0 (if not found)
5347 *
5348 * Context:
5349 * Kernel context
5350 */
5351uint8_t
5352qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5353{
5354 int i, entries;
5355 uint8_t pid_match, wwn_match;
5356 uint8_t priority;
5357 uint32_t pid1, pid2;
5358 uint64_t wwn1, wwn2;
5359 struct qla_fcp_prio_entry *pri_entry;
5360 struct qla_hw_data *ha = vha->hw;
5361
5362 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5363 return 0;
5364
5365 priority = 0;
5366 entries = ha->fcp_prio_cfg->num_entries;
5367 pri_entry = &ha->fcp_prio_cfg->entry[0];
5368
5369 for (i = 0; i < entries; i++) {
5370 pid_match = wwn_match = 0;
5371
5372 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5373 pri_entry++;
5374 continue;
5375 }
5376
5377 /* check source pid for a match */
5378 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5379 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5380 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5381 if (pid1 == INVALID_PORT_ID)
5382 pid_match++;
5383 else if (pid1 == pid2)
5384 pid_match++;
5385 }
5386
5387 /* check destination pid for a match */
5388 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5389 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5390 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5391 if (pid1 == INVALID_PORT_ID)
5392 pid_match++;
5393 else if (pid1 == pid2)
5394 pid_match++;
5395 }
5396
5397 /* check source WWN for a match */
5398 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5399 wwn1 = wwn_to_u64(vha->port_name);
5400 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5401 if (wwn2 == (uint64_t)-1)
5402 wwn_match++;
5403 else if (wwn1 == wwn2)
5404 wwn_match++;
5405 }
5406
5407 /* check destination WWN for a match */
5408 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5409 wwn1 = wwn_to_u64(fcport->port_name);
5410 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5411 if (wwn2 == (uint64_t)-1)
5412 wwn_match++;
5413 else if (wwn1 == wwn2)
5414 wwn_match++;
5415 }
5416
5417 if (pid_match == 2 || wwn_match == 2) {
5418 /* Found a matching entry */
5419 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5420 priority = pri_entry->tag;
5421 break;
5422 }
5423
5424 pri_entry++;
5425 }
5426
5427 return priority;
5428}
5429
5430/*
5431 * qla24xx_update_fcport_fcp_prio
5432 * Activates fcp priority for the logged in fc port
5433 *
5434 * Input:
5435 * ha = adapter block pointer.
5436 * fcp = port structure pointer.
5437 *
5438 * Return:
5439 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5440 *
5441 * Context:
5442 * Kernel context.
5443 */
5444int
5445qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5446{
5447 int ret;
5448 uint8_t priority;
5449 uint16_t mb[5];
5450
5451 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5452 fcport->port_type != FCT_TARGET ||
5453 fcport->loop_id == FC_NO_LOOP_ID)
5454 return QLA_FUNCTION_FAILED;
5455
5456 priority = qla24xx_get_fcp_prio(ha, fcport);
5457 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5458 if (ret == QLA_SUCCESS)
5459 fcport->fcp_prio = priority;
5460 else
5461 DEBUG2(printk(KERN_WARNING
5462 "scsi(%ld): Unable to activate fcp priority, "
5463 " ret=0x%x\n", ha->host_no, ret));
5464
5465 return ret;
5466}
5467
5468/*
5469 * qla24xx_update_all_fcp_prio
5470 * Activates fcp priority for all the logged in ports
5471 *
5472 * Input:
5473 * ha = adapter block pointer.
5474 *
5475 * Return:
5476 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5477 *
5478 * Context:
5479 * Kernel context.
5480 */
5481int
5482qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5483{
5484 int ret;
5485 fc_port_t *fcport;
5486
5487 ret = QLA_FUNCTION_FAILED;
5488 /* We need to set priority for all logged in ports */
5489 list_for_each_entry(fcport, &vha->vp_fcports, list)
5490 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5491
5492 return ret;
5493}