blob: 9d969b596b1442f1079c86ded8b104c99a895822 [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);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070063 iocb->free(sp);
Andrew Vasquez6ac52602010-05-28 15:08:19 -070064 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezac280b62009-08-20 11:06:05 -070065}
66
Giridhar Malavali9a069e12010-01-12 13:02:47 -080067void
Andrew Vasquezac280b62009-08-20 11:06:05 -070068qla2x00_ctx_sp_free(srb_t *sp)
69{
70 struct srb_ctx *ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070071 struct srb_iocb *iocb = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070072
Madhuranath Iyengar49163922010-05-04 15:01:28 -070073 del_timer_sync(&iocb->timer);
74 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070075 kfree(ctx);
76 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
77}
78
79inline srb_t *
80qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
81 unsigned long tmo)
82{
83 srb_t *sp;
84 struct qla_hw_data *ha = vha->hw;
85 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070086 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070087
88 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
89 if (!sp)
90 goto done;
91 ctx = kzalloc(size, GFP_KERNEL);
92 if (!ctx) {
93 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070094 sp = NULL;
95 goto done;
96 }
97 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
98 if (!iocb) {
99 mempool_free(sp, ha->srb_mempool);
100 sp = NULL;
101 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700102 goto done;
103 }
104
105 memset(sp, 0, sizeof(*sp));
106 sp->fcport = fcport;
107 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700108 ctx->u.iocb_cmd = iocb;
109 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700110
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700111 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700112 if (!tmo)
113 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700114 iocb->timer.expires = jiffies + tmo * HZ;
115 iocb->timer.data = (unsigned long)sp;
116 iocb->timer.function = qla2x00_ctx_sp_timeout;
117 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700118done:
119 return sp;
120}
121
122/* Asynchronous Login/Logout Routines -------------------------------------- */
123
124#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
125
126static void
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700127qla2x00_async_iocb_timeout(srb_t *sp)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700128{
129 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700130 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700131
132 DEBUG2(printk(KERN_WARNING
Andrew Vasquezd3fa9e72010-05-28 15:08:16 -0700133 "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n",
134 fcport->vha->host_no, sp->handle,
135 ctx->name, fcport->d_id.b.domain,
136 fcport->d_id.b.area, fcport->d_id.b.al_pa));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700137
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700138 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700139 if (ctx->type == SRB_LOGIN_CMD) {
140 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700141 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700142 /* Retry as needed. */
143 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
144 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
145 QLA_LOGIO_LOGIN_RETRIED : 0;
146 qla2x00_post_async_login_done_work(fcport->vha, fcport,
147 lio->u.logio.data);
148 }
Andrew Vasquezac280b62009-08-20 11:06:05 -0700149}
150
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700151static void
152qla2x00_async_login_ctx_done(srb_t *sp)
153{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700154 struct srb_ctx *ctx = sp->ctx;
155 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700156
157 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700158 lio->u.logio.data);
159 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700160}
161
Andrew Vasquezac280b62009-08-20 11:06:05 -0700162int
163qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
164 uint16_t *data)
165{
166 struct qla_hw_data *ha = vha->hw;
167 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700168 struct srb_ctx *ctx;
169 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700170 int rval;
171
172 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700173 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700174 ELS_TMO_2_RATOV(ha) + 2);
175 if (!sp)
176 goto done;
177
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700178 ctx = sp->ctx;
179 ctx->type = SRB_LOGIN_CMD;
180 ctx->name = "login";
181 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700182 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700183 lio->done = qla2x00_async_login_ctx_done;
184 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700185 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700186 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700187 rval = qla2x00_start_sp(sp);
188 if (rval != QLA_SUCCESS)
189 goto done_free_sp;
190
191 DEBUG2(printk(KERN_DEBUG
192 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
193 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
194 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
195 fcport->login_retry));
196 return rval;
197
198done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700199 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700200done:
201 return rval;
202}
203
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700204static void
205qla2x00_async_logout_ctx_done(srb_t *sp)
206{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700207 struct srb_ctx *ctx = sp->ctx;
208 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700209
210 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700211 lio->u.logio.data);
212 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700213}
214
Andrew Vasquezac280b62009-08-20 11:06:05 -0700215int
216qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
217{
218 struct qla_hw_data *ha = vha->hw;
219 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700220 struct srb_ctx *ctx;
221 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700222 int rval;
223
224 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700225 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700226 ELS_TMO_2_RATOV(ha) + 2);
227 if (!sp)
228 goto done;
229
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700230 ctx = sp->ctx;
231 ctx->type = SRB_LOGOUT_CMD;
232 ctx->name = "logout";
233 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700234 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700235 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700236 rval = qla2x00_start_sp(sp);
237 if (rval != QLA_SUCCESS)
238 goto done_free_sp;
239
240 DEBUG2(printk(KERN_DEBUG
241 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
242 fcport->vha->host_no, sp->handle, fcport->loop_id,
243 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
244 return rval;
245
246done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700247 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700248done:
249 return rval;
250}
251
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700252static void
253qla2x00_async_adisc_ctx_done(srb_t *sp)
254{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700255 struct srb_ctx *ctx = sp->ctx;
256 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700257
258 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700259 lio->u.logio.data);
260 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700261}
262
263int
264qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
265 uint16_t *data)
266{
267 struct qla_hw_data *ha = vha->hw;
268 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700269 struct srb_ctx *ctx;
270 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700271 int rval;
272
273 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700274 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700275 ELS_TMO_2_RATOV(ha) + 2);
276 if (!sp)
277 goto done;
278
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700279 ctx = sp->ctx;
280 ctx->type = SRB_ADISC_CMD;
281 ctx->name = "adisc";
282 lio = ctx->u.iocb_cmd;
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700283 lio->timeout = qla2x00_async_iocb_timeout;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700284 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700285 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700286 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700287 rval = qla2x00_start_sp(sp);
288 if (rval != QLA_SUCCESS)
289 goto done_free_sp;
290
291 DEBUG2(printk(KERN_DEBUG
292 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
293 fcport->vha->host_no, sp->handle, fcport->loop_id,
294 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
295
296 return rval;
297
298done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700299 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700300done:
301 return rval;
302}
303
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700304static void
305qla2x00_async_tm_cmd_ctx_done(srb_t *sp)
306{
307 struct srb_ctx *ctx = sp->ctx;
308 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
309
310 qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb);
311 iocb->free(sp);
312}
313
314int
315qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
316 uint32_t tag)
317{
318 struct scsi_qla_host *vha = fcport->vha;
319 struct qla_hw_data *ha = vha->hw;
320 srb_t *sp;
321 struct srb_ctx *ctx;
322 struct srb_iocb *tcf;
323 int rval;
324
325 rval = QLA_FUNCTION_FAILED;
326 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
327 ELS_TMO_2_RATOV(ha) + 2);
328 if (!sp)
329 goto done;
330
331 ctx = sp->ctx;
332 ctx->type = SRB_TM_CMD;
333 ctx->name = "tmf";
334 tcf = ctx->u.iocb_cmd;
335 tcf->u.tmf.flags = flags;
336 tcf->u.tmf.lun = lun;
337 tcf->u.tmf.data = tag;
338 tcf->timeout = qla2x00_async_iocb_timeout;
339 tcf->done = qla2x00_async_tm_cmd_ctx_done;
340
341 rval = qla2x00_start_sp(sp);
342 if (rval != QLA_SUCCESS)
343 goto done_free_sp;
344
345 DEBUG2(printk(KERN_DEBUG
346 "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n",
347 fcport->vha->host_no, sp->handle, fcport->loop_id,
348 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
349
350 return rval;
351
352done_free_sp:
353 tcf->free(sp);
354done:
355 return rval;
356}
357
358static void
359qla2x00_async_marker_ctx_done(srb_t *sp)
360{
361 struct srb_ctx *ctx = sp->ctx;
362 struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd;
363
364 qla2x00_async_marker_done(sp->fcport->vha, sp->fcport, iocb);
365 iocb->free(sp);
366}
367
368int
369qla2x00_async_marker(fc_port_t *fcport, uint16_t lun, uint8_t modif)
370{
371 struct scsi_qla_host *vha = fcport->vha;
372 srb_t *sp;
373 struct srb_ctx *ctx;
374 struct srb_iocb *mrk;
375 int rval;
376
377 rval = QLA_FUNCTION_FAILED;
378 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), 0);
379 if (!sp)
380 goto done;
381
382 ctx = sp->ctx;
383 ctx->type = SRB_MARKER_CMD;
384 ctx->name = "marker";
385 mrk = ctx->u.iocb_cmd;
386 mrk->u.marker.lun = lun;
387 mrk->u.marker.modif = modif;
388 mrk->timeout = qla2x00_async_iocb_timeout;
389 mrk->done = qla2x00_async_marker_ctx_done;
390
391 rval = qla2x00_start_sp(sp);
392 if (rval != QLA_SUCCESS)
393 goto done_free_sp;
394
395 DEBUG2(printk(KERN_DEBUG
396 "scsi(%ld:%x): Async-marker - loop-id=%x "
397 "portid=%02x%02x%02x.\n",
398 fcport->vha->host_no, sp->handle, fcport->loop_id,
399 fcport->d_id.b.domain, fcport->d_id.b.area,
400 fcport->d_id.b.al_pa));
401
402 return rval;
403
404done_free_sp:
405 mrk->free(sp);
406done:
407 return rval;
408}
409
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700410void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700411qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
412 uint16_t *data)
413{
414 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700415
416 switch (data[0]) {
417 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700418 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700419 fcport->flags |= FCF_ASYNC_SENT;
420 qla2x00_post_async_adisc_work(vha, fcport, data);
421 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700422 }
423 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700424 break;
425 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700426 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700427 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
428 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
429 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700430 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700431 break;
432 case MBS_PORT_ID_USED:
433 fcport->loop_id = data[1];
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700434 qla2x00_post_async_logout_work(vha, fcport, NULL);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700435 qla2x00_post_async_login_work(vha, fcport, NULL);
436 break;
437 case MBS_LOOP_ID_USED:
438 fcport->loop_id++;
439 rval = qla2x00_find_new_loop_id(vha, fcport);
440 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700441 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700442 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700443 break;
444 }
445 qla2x00_post_async_login_work(vha, fcport, NULL);
446 break;
447 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700448 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700449}
450
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700451void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700452qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
453 uint16_t *data)
454{
455 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700456 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700457}
458
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700459void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700460qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
461 uint16_t *data)
462{
463 if (data[0] == MBS_COMMAND_COMPLETE) {
464 qla2x00_update_fcport(vha, fcport);
465
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700466 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700467 }
468
469 /* Retry login. */
470 fcport->flags &= ~FCF_ASYNC_SENT;
471 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
472 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
473 else
Andrew Vasquez6ac52602010-05-28 15:08:19 -0700474 qla2x00_mark_device_lost(vha, fcport, 1, 1);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700475
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700476 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700477}
478
Madhuranath Iyengar38222632010-05-04 15:01:29 -0700479void
480qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport,
481 struct srb_iocb *iocb)
482{
483 int rval;
484 uint32_t flags;
485 uint16_t lun;
486
487 flags = iocb->u.tmf.flags;
488 lun = (uint16_t)iocb->u.tmf.lun;
489
490 /* Issue Marker IOCB */
491 rval = qla2x00_async_marker(fcport, lun,
492 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
493
494 if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) {
495 DEBUG2_3_11(printk(KERN_WARNING
496 "%s(%ld): TM IOCB failed (%x).\n",
497 __func__, vha->host_no, rval));
498 }
499
500 return;
501}
502
503void
504qla2x00_async_marker_done(struct scsi_qla_host *vha, fc_port_t *fcport,
505 struct srb_iocb *iocb)
506{
507 /*
508 * Currently we dont have any specific post response processing
509 * for this IOCB. We'll just return success or failed
510 * depending on whether the IOCB command succeeded or failed.
511 */
512 if (iocb->u.tmf.data) {
513 DEBUG2_3_11(printk(KERN_WARNING
514 "%s(%ld): Marker IOCB failed (%x).\n",
515 __func__, vha->host_no, iocb->u.tmf.data));
516 }
517
518 return;
519}
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521/****************************************************************************/
522/* QLogic ISP2x00 Hardware Support Functions. */
523/****************************************************************************/
524
525/*
526* qla2x00_initialize_adapter
527* Initialize board.
528*
529* Input:
530* ha = adapter block pointer.
531*
532* Returns:
533* 0 = success
534*/
535int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800536qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
538 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800539 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800540 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700541
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800543 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700544 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800545 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800546 ha->flags.pci_channel_io_perm_failure = 0;
547 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800548 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
549 atomic_set(&vha->loop_state, LOOP_DOWN);
550 vha->device_flags = DFLG_NO_CABLE;
551 vha->dpc_flags = 0;
552 vha->flags.management_server_logged_in = 0;
553 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700554 ha->isp_abort_cnt = 0;
555 ha->beacon_blink_led = 0;
556
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800557 set_bit(0, ha->req_qid_map);
558 set_bit(0, ha->rsp_qid_map);
559
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700560 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800561 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800563 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800564 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 return (rval);
566 }
567
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800568 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800570 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700571 if (rval) {
572 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800573 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700574 return (rval);
575 }
576
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800577 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700580
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800581 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700583 if (ha->flags.disable_serdes) {
584 /* Mask HBA via NVRAM settings? */
585 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
586 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 vha->port_name[0], vha->port_name[1],
588 vha->port_name[2], vha->port_name[3],
589 vha->port_name[4], vha->port_name[5],
590 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700591 return QLA_FUNCTION_FAILED;
592 }
593
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
597 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800598 if (rval)
599 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800600 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800601 if (rval)
602 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700604
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700605 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800606 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700607 if (!ha->cs84xx) {
608 qla_printk(KERN_ERR, ha,
609 "Unable to configure ISP84XX.\n");
610 return QLA_FUNCTION_FAILED;
611 }
612 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800613 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700614 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800616 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700617 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800618 rval = qla84xx_init_chip(vha);
619 if (rval != QLA_SUCCESS) {
620 qla_printk(KERN_ERR, ha,
621 "Unable to initialize ISP84XX.\n");
622 qla84xx_put_chip(vha);
623 }
624 }
625
Sarang Radke09ff7012010-03-19 17:03:59 -0700626 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
627 if (qla24xx_read_fcp_prio_cfg(vha))
628 qla_printk(KERN_ERR, ha,
629 "Unable to read FCP priority data.\n");
630 }
631
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 return (rval);
633}
634
635/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700636 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 * @ha: HA context
638 *
639 * Returns 0 on success.
640 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700641int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800642qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700644 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700645 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800646 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700647 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700650 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700653 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
655
Andrew Vasquez737faec2008-10-24 15:13:45 -0700656 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700658 /* Get PCI bus information. */
659 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700660 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700661 spin_unlock_irqrestore(&ha->hardware_lock, flags);
662
663 return QLA_SUCCESS;
664}
665
666/**
667 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
668 * @ha: HA context
669 *
670 * Returns 0 on success.
671 */
672int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800673qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700674{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700675 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700676 unsigned long flags = 0;
677 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700679 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700680
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700681 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700682 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700683
684 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700685 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700686
687 if (IS_QLA2322(ha) || IS_QLA6322(ha))
688 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700689 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700690
691 /*
692 * If this is a 2300 card and not 2312, reset the
693 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
694 * the 2310 also reports itself as a 2300 so we need to get the
695 * fb revision level -- a 6 indicates it really is a 2300 and
696 * not a 2310.
697 */
698 if (IS_QLA2300(ha)) {
699 spin_lock_irqsave(&ha->hardware_lock, flags);
700
701 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700702 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700703 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700704 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700705 break;
706
707 udelay(10);
708 }
709
710 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700711 WRT_REG_WORD(&reg->ctrl_status, 0x20);
712 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700713
714 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700715 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700716
717 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700718 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700719
720 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700721 WRT_REG_WORD(&reg->ctrl_status, 0x0);
722 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700723
724 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700725 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700726 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700727 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700728 break;
729
730 udelay(10);
731 }
732
733 spin_unlock_irqrestore(&ha->hardware_lock, flags);
734 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700735
736 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
737
Andrew Vasquez737faec2008-10-24 15:13:45 -0700738 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700739
740 /* Get PCI bus information. */
741 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700742 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700743 spin_unlock_irqrestore(&ha->hardware_lock, flags);
744
745 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746}
747
748/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700749 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
750 * @ha: HA context
751 *
752 * Returns 0 on success.
753 */
754int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700756{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700757 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700758 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800759 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700760 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700761
762 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700763 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700764
765 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700766 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700767 w &= ~PCI_COMMAND_INTX_DISABLE;
768 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
769
770 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
771
772 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700773 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
774 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700775
776 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700777 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
778 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700779
Andrew Vasquez737faec2008-10-24 15:13:45 -0700780 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700781
Auke Kok44c10132007-06-08 15:46:36 -0700782 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800783
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700784 /* Get PCI bus information. */
785 spin_lock_irqsave(&ha->hardware_lock, flags);
786 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
787 spin_unlock_irqrestore(&ha->hardware_lock, flags);
788
789 return QLA_SUCCESS;
790}
791
792/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700793 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
794 * @ha: HA context
795 *
796 * Returns 0 on success.
797 */
798int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700800{
801 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700803
804 pci_set_master(ha->pdev);
805 pci_try_set_mwi(ha->pdev);
806
807 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
808 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
809 w &= ~PCI_COMMAND_INTX_DISABLE;
810 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
811
812 /* PCIe -- adjust Maximum Read Request Size (2048). */
813 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
814 pcie_set_readrq(ha->pdev, 2048);
815
Andrew Vasquez737faec2008-10-24 15:13:45 -0700816 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700817
818 ha->chip_revision = ha->pdev->revision;
819
820 return QLA_SUCCESS;
821}
822
823/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824 * qla2x00_isp_firmware() - Choose firmware image.
825 * @ha: HA context
826 *
827 * Returns 0 on success.
828 */
829static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800830qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831{
832 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700833 uint16_t loop_id, topo, sw_cap;
834 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800835 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
837 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700838 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
840 if (ha->flags.disable_risc_code_load) {
841 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800842 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
844
845 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800846 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700847 if (rval == QLA_SUCCESS) {
848 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800849 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700850 &area, &domain, &topo, &sw_cap);
851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852 }
853
854 if (rval) {
855 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800856 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857 }
858
859 return (rval);
860}
861
862/**
863 * qla2x00_reset_chip() - Reset ISP chip.
864 * @ha: HA context
865 *
866 * Returns 0 on success.
867 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700868void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800869qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870{
871 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800872 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700873 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875 uint16_t cmd;
876
Andrew Vasquez85880802009-12-15 21:29:46 -0800877 if (unlikely(pci_channel_offline(ha->pdev)))
878 return;
879
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700880 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
882 spin_lock_irqsave(&ha->hardware_lock, flags);
883
884 /* Turn off master enable */
885 cmd = 0;
886 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
887 cmd &= ~PCI_COMMAND_MASTER;
888 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
889
890 if (!IS_QLA2100(ha)) {
891 /* Pause RISC. */
892 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
893 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
894 for (cnt = 0; cnt < 30000; cnt++) {
895 if ((RD_REG_WORD(&reg->hccr) &
896 HCCR_RISC_PAUSE) != 0)
897 break;
898 udelay(100);
899 }
900 } else {
901 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
902 udelay(10);
903 }
904
905 /* Select FPM registers. */
906 WRT_REG_WORD(&reg->ctrl_status, 0x20);
907 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
908
909 /* FPM Soft Reset. */
910 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
911 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
912
913 /* Toggle Fpm Reset. */
914 if (!IS_QLA2200(ha)) {
915 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
916 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
917 }
918
919 /* Select frame buffer registers. */
920 WRT_REG_WORD(&reg->ctrl_status, 0x10);
921 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
922
923 /* Reset frame buffer FIFOs. */
924 if (IS_QLA2200(ha)) {
925 WRT_FB_CMD_REG(ha, reg, 0xa000);
926 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
927 } else {
928 WRT_FB_CMD_REG(ha, reg, 0x00fc);
929
930 /* Read back fb_cmd until zero or 3 seconds max */
931 for (cnt = 0; cnt < 3000; cnt++) {
932 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
933 break;
934 udelay(100);
935 }
936 }
937
938 /* Select RISC module registers. */
939 WRT_REG_WORD(&reg->ctrl_status, 0);
940 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
941
942 /* Reset RISC processor. */
943 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
944 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
945
946 /* Release RISC processor. */
947 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
948 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
949 }
950
951 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
952 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
953
954 /* Reset ISP chip. */
955 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
956
957 /* Wait for RISC to recover from reset. */
958 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
959 /*
960 * It is necessary to for a delay here since the card doesn't
961 * respond to PCI reads during a reset. On some architectures
962 * this will result in an MCA.
963 */
964 udelay(20);
965 for (cnt = 30000; cnt; cnt--) {
966 if ((RD_REG_WORD(&reg->ctrl_status) &
967 CSR_ISP_SOFT_RESET) == 0)
968 break;
969 udelay(100);
970 }
971 } else
972 udelay(10);
973
974 /* Reset RISC processor. */
975 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
976
977 WRT_REG_WORD(&reg->semaphore, 0);
978
979 /* Release RISC processor. */
980 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
981 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
982
983 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
984 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700985 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
988 udelay(100);
989 }
990 } else
991 udelay(100);
992
993 /* Turn on master enable */
994 cmd |= PCI_COMMAND_MASTER;
995 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
996
997 /* Disable RISC pause on FPM parity error. */
998 if (!IS_QLA2100(ha)) {
999 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
1000 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
1001 }
1002
1003 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1004}
1005
1006/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001007 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001008 * @ha: HA context
1009 *
1010 * Returns 0 on success.
1011 */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001012static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001013qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001014{
1015 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001016 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001017 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1018 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001019 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001020
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001021 spin_lock_irqsave(&ha->hardware_lock, flags);
1022
1023 /* Reset RISC. */
1024 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
1025 for (cnt = 0; cnt < 30000; cnt++) {
1026 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
1027 break;
1028
1029 udelay(10);
1030 }
1031
1032 WRT_REG_DWORD(&reg->ctrl_status,
1033 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001034 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001035
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001036 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001037 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -07001038 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1039 for (cnt = 10000 ; cnt && d2; cnt--) {
1040 udelay(5);
1041 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1042 barrier();
1043 }
1044
Andrew Vasquez335a1cc2005-11-08 14:37:48 -08001045 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001046 d2 = RD_REG_DWORD(&reg->ctrl_status);
1047 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
1048 udelay(5);
1049 d2 = RD_REG_DWORD(&reg->ctrl_status);
1050 barrier();
1051 }
1052
1053 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
1054 RD_REG_DWORD(&reg->hccr);
1055
1056 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
1057 RD_REG_DWORD(&reg->hccr);
1058
1059 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
1060 RD_REG_DWORD(&reg->hccr);
1061
1062 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1063 for (cnt = 6000000 ; cnt && d2; cnt--) {
1064 udelay(5);
1065 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
1066 barrier();
1067 }
1068
1069 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001070
1071 if (IS_NOPOLLING_TYPE(ha))
1072 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001073}
1074
1075/**
Andrew Vasquez88c26662005-07-08 17:59:26 -07001076 * qla24xx_reset_chip() - Reset ISP24xx chip.
1077 * @ha: HA context
1078 *
1079 * Returns 0 on success.
1080 */
1081void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001082qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -07001083{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001084 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -08001085
1086 if (pci_channel_offline(ha->pdev) &&
1087 ha->flags.pci_channel_io_perm_failure) {
1088 return;
1089 }
1090
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001091 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001092
1093 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001094 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -07001095}
1096
1097/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001098 * qla2x00_chip_diag() - Test chip for proper operation.
1099 * @ha: HA context
1100 *
1101 * Returns 0 on success.
1102 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001103int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001104qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105{
1106 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001107 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001108 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109 unsigned long flags = 0;
1110 uint16_t data;
1111 uint32_t cnt;
1112 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001113 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114
1115 /* Assume a failed state */
1116 rval = QLA_FUNCTION_FAILED;
1117
1118 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001119 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001120
1121 spin_lock_irqsave(&ha->hardware_lock, flags);
1122
1123 /* Reset ISP chip. */
1124 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
1125
1126 /*
1127 * We need to have a delay here since the card will not respond while
1128 * in reset causing an MCA on some architectures.
1129 */
1130 udelay(20);
1131 data = qla2x00_debounce_register(&reg->ctrl_status);
1132 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
1133 udelay(5);
1134 data = RD_REG_WORD(&reg->ctrl_status);
1135 barrier();
1136 }
1137
1138 if (!cnt)
1139 goto chip_diag_failed;
1140
1141 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07001142 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143
1144 /* Reset RISC processor. */
1145 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
1146 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
1147
1148 /* Workaround for QLA2312 PCI parity error */
1149 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
1150 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
1151 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
1152 udelay(5);
1153 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001154 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155 }
1156 } else
1157 udelay(10);
1158
1159 if (!cnt)
1160 goto chip_diag_failed;
1161
1162 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001163 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001164
1165 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1166 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1167 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1168 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1169 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1170 mb[3] != PROD_ID_3) {
1171 qla_printk(KERN_WARNING, ha,
1172 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1173
1174 goto chip_diag_failed;
1175 }
1176 ha->product_id[0] = mb[1];
1177 ha->product_id[1] = mb[2];
1178 ha->product_id[2] = mb[3];
1179 ha->product_id[3] = mb[4];
1180
1181 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001182 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1184 else
1185 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001186 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 if (IS_QLA2200(ha) &&
1189 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1190 /* Limit firmware transfer size with a 2200A */
1191 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001192 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001194 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 ha->fw_transfer_size = 128;
1196 }
1197
1198 /* Wrap Incoming Mailboxes Test. */
1199 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1200
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001201 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1202 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 if (rval) {
1204 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001205 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001206 qla_printk(KERN_WARNING, ha,
1207 "Failed mailbox send register test\n");
1208 }
1209 else {
1210 /* Flag a successful rval */
1211 rval = QLA_SUCCESS;
1212 }
1213 spin_lock_irqsave(&ha->hardware_lock, flags);
1214
1215chip_diag_failed:
1216 if (rval)
1217 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001218 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219
1220 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1221
1222 return (rval);
1223}
1224
1225/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001226 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1227 * @ha: HA context
1228 *
1229 * Returns 0 on success.
1230 */
1231int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001232qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001233{
1234 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001236 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001237
Giridhar Malavalia9083012010-04-12 17:59:55 -07001238 if (IS_QLA82XX(ha))
1239 return QLA_SUCCESS;
1240
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001241 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001242
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001243 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001244 if (rval) {
1245 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001246 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001247 qla_printk(KERN_WARNING, ha,
1248 "Failed mailbox send register test\n");
1249 } else {
1250 /* Flag a successful rval */
1251 rval = QLA_SUCCESS;
1252 }
1253
1254 return rval;
1255}
1256
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001257void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001258qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001259{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001260 int rval;
1261 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001262 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001263 dma_addr_t tc_dma;
1264 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001265 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001266 struct req_que *req = ha->req_q_map[0];
1267 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001268
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001269 if (ha->fw_dump) {
1270 qla_printk(KERN_WARNING, ha,
1271 "Firmware dump previously allocated.\n");
1272 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001273 }
1274
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001275 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001276 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001277 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1278 fixed_size = sizeof(struct qla2100_fw_dump);
1279 } else if (IS_QLA23XX(ha)) {
1280 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1281 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1282 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001283 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001284 if (IS_QLA81XX(ha))
1285 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1286 else if (IS_QLA25XX(ha))
1287 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1288 else
1289 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001290 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1291 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001292 if (ha->mqenable)
1293 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001294 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001295 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001296 goto try_eft;
1297
1298 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1299 GFP_KERNEL);
1300 if (!tc) {
1301 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1302 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001303 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001304 }
1305
1306 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001307 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001308 ha->fce_mb, &ha->fce_bufs);
1309 if (rval) {
1310 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1311 "FCE (%d).\n", rval);
1312 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1313 tc_dma);
1314 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001315 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001316 }
1317
1318 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1319 FCE_SIZE / 1024);
1320
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001321 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001322 ha->flags.fce_enabled = 1;
1323 ha->fce_dma = tc_dma;
1324 ha->fce = tc;
1325try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001326 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001327 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001328 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001329 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001330 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1331 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1332 goto cont_alloc;
1333 }
1334
Andrew Vasquezfc447652008-01-17 09:02:18 -08001335 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001336 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001337 if (rval) {
1338 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1339 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001340 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1341 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001342 goto cont_alloc;
1343 }
1344
1345 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1346 EFT_SIZE / 1024);
1347
1348 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001349 ha->eft_dma = tc_dma;
1350 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001351 }
1352cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001353 req_q_size = req->length * sizeof(request_t);
1354 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001355
1356 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001357 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001358 ha->chain_offset = dump_size;
1359 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001360
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001361 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001362 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001363 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001364 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001365
1366 if (ha->eft) {
1367 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1368 ha->eft_dma);
1369 ha->eft = NULL;
1370 ha->eft_dma = 0;
1371 }
1372 return;
1373 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001374 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1375 dump_size / 1024);
1376
1377 ha->fw_dump_len = dump_size;
1378 ha->fw_dump->signature[0] = 'Q';
1379 ha->fw_dump->signature[1] = 'L';
1380 ha->fw_dump->signature[2] = 'G';
1381 ha->fw_dump->signature[3] = 'C';
1382 ha->fw_dump->version = __constant_htonl(1);
1383
1384 ha->fw_dump->fixed_size = htonl(fixed_size);
1385 ha->fw_dump->mem_size = htonl(mem_size);
1386 ha->fw_dump->req_q_size = htonl(req_q_size);
1387 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1388
1389 ha->fw_dump->eft_size = htonl(eft_size);
1390 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1391 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1392
1393 ha->fw_dump->header_size =
1394 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001395}
1396
Andrew Vasquez18e75552009-06-03 09:55:30 -07001397static int
1398qla81xx_mpi_sync(scsi_qla_host_t *vha)
1399{
1400#define MPS_MASK 0xe0
1401 int rval;
1402 uint16_t dc;
1403 uint32_t dw;
1404 struct qla_hw_data *ha = vha->hw;
1405
1406 if (!IS_QLA81XX(vha->hw))
1407 return QLA_SUCCESS;
1408
1409 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1410 if (rval != QLA_SUCCESS) {
1411 DEBUG2(qla_printk(KERN_WARNING, ha,
1412 "Sync-MPI: Unable to acquire semaphore.\n"));
1413 goto done;
1414 }
1415
1416 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1417 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1418 if (rval != QLA_SUCCESS) {
1419 DEBUG2(qla_printk(KERN_WARNING, ha,
1420 "Sync-MPI: Unable to read sync.\n"));
1421 goto done_release;
1422 }
1423
1424 dc &= MPS_MASK;
1425 if (dc == (dw & MPS_MASK))
1426 goto done_release;
1427
1428 dw &= ~MPS_MASK;
1429 dw |= dc;
1430 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1431 if (rval != QLA_SUCCESS) {
1432 DEBUG2(qla_printk(KERN_WARNING, ha,
1433 "Sync-MPI: Unable to gain sync.\n"));
1434 }
1435
1436done_release:
1437 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1438 if (rval != QLA_SUCCESS) {
1439 DEBUG2(qla_printk(KERN_WARNING, ha,
1440 "Sync-MPI: Unable to release semaphore.\n"));
1441 }
1442
1443done:
1444 return rval;
1445}
1446
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001447/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 * qla2x00_setup_chip() - Load and start RISC firmware.
1449 * @ha: HA context
1450 *
1451 * Returns 0 on success.
1452 */
1453static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001456 int rval;
1457 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001458 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001459 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1460 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001461 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001462
Giridhar Malavalia9083012010-04-12 17:59:55 -07001463 if (IS_QLA82XX(ha)) {
1464 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1465 if (rval == QLA_SUCCESS)
1466 goto enable_82xx_npiv;
Giridhar Malavalib9637522010-05-28 15:08:15 -07001467 else
1468 goto failed;
Giridhar Malavalia9083012010-04-12 17:59:55 -07001469 }
1470
Andrew Vasquez3db06522008-01-31 12:33:49 -08001471 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1472 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1473 spin_lock_irqsave(&ha->hardware_lock, flags);
1474 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1475 RD_REG_WORD(&reg->hccr);
1476 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478
Andrew Vasquez18e75552009-06-03 09:55:30 -07001479 qla81xx_mpi_sync(vha);
1480
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001482 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001483 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001487 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488 if (rval == QLA_SUCCESS) {
1489 /* Start firmware execution. */
1490 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001493 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001495 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001496enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001497 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001498 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001499 &ha->fw_major_version,
1500 &ha->fw_minor_version,
1501 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001502 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001503 ha->mpi_version, &ha->mpi_capabilities,
1504 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001505 if (rval != QLA_SUCCESS)
1506 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001507 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001508 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001509 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001510 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001511 if ((!ha->max_npiv_vports) ||
1512 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001513 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001514 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001515 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001516 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001517 qla2x00_get_resource_cnts(vha, NULL,
1518 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001519 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001520
Giridhar Malavalia9083012010-04-12 17:59:55 -07001521 if (!fw_major_version && ql2xallocfwdump) {
1522 if (!IS_QLA82XX(ha))
1523 qla2x00_alloc_fw_dump(vha);
1524 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 }
1526 } else {
1527 DEBUG2(printk(KERN_INFO
1528 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001529 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 }
1531 }
1532
Andrew Vasquez3db06522008-01-31 12:33:49 -08001533 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1534 /* Enable proper parity. */
1535 spin_lock_irqsave(&ha->hardware_lock, flags);
1536 if (IS_QLA2300(ha))
1537 /* SRAM parity */
1538 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1539 else
1540 /* SRAM, Instruction RAM and GP RAM parity */
1541 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1542 RD_REG_WORD(&reg->hccr);
1543 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1544 }
1545
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001546 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1547 uint32_t size;
1548
1549 rval = qla81xx_fac_get_sector_size(vha, &size);
1550 if (rval == QLA_SUCCESS) {
1551 ha->flags.fac_supported = 1;
1552 ha->fdt_block_size = size << 2;
1553 } else {
1554 qla_printk(KERN_ERR, ha,
1555 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1556 ha->fw_major_version, ha->fw_minor_version,
1557 ha->fw_subminor_version);
1558 }
1559 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001560failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 if (rval) {
1562 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001563 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 }
1565
1566 return (rval);
1567}
1568
1569/**
1570 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1571 * @ha: HA context
1572 *
1573 * Beginning of request ring has initialization control block already built
1574 * by nvram config routine.
1575 *
1576 * Returns 0 on success.
1577 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001578void
1579qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580{
1581 uint16_t cnt;
1582 response_t *pkt;
1583
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001584 rsp->ring_ptr = rsp->ring;
1585 rsp->ring_index = 0;
1586 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001587 pkt = rsp->ring_ptr;
1588 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 pkt->signature = RESPONSE_PROCESSED;
1590 pkt++;
1591 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592}
1593
1594/**
1595 * qla2x00_update_fw_options() - Read and process firmware options.
1596 * @ha: HA context
1597 *
1598 * Returns 0 on success.
1599 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001600void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001601qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602{
1603 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
1606 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001607 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608
1609 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1610 return;
1611
1612 /* Serial Link options. */
1613 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001614 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1616 sizeof(ha->fw_seriallink_options)));
1617
1618 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1619 if (ha->fw_seriallink_options[3] & BIT_2) {
1620 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1621
1622 /* 1G settings */
1623 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1624 emphasis = (ha->fw_seriallink_options[2] &
1625 (BIT_4 | BIT_3)) >> 3;
1626 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001627 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 rx_sens = (ha->fw_seriallink_options[0] &
1629 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1630 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1631 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1632 if (rx_sens == 0x0)
1633 rx_sens = 0x3;
1634 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1635 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1636 ha->fw_options[10] |= BIT_5 |
1637 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1638 (tx_sens & (BIT_1 | BIT_0));
1639
1640 /* 2G settings */
1641 swing = (ha->fw_seriallink_options[2] &
1642 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1643 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1644 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001645 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 rx_sens = (ha->fw_seriallink_options[1] &
1647 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1648 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1649 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1650 if (rx_sens == 0x0)
1651 rx_sens = 0x3;
1652 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1653 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1654 ha->fw_options[11] |= BIT_5 |
1655 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1656 (tx_sens & (BIT_1 | BIT_0));
1657 }
1658
1659 /* FCP2 options. */
1660 /* Return command IOCBs without waiting for an ABTS to complete. */
1661 ha->fw_options[3] |= BIT_13;
1662
1663 /* LED scheme. */
1664 if (ha->flags.enable_led_scheme)
1665 ha->fw_options[2] |= BIT_12;
1666
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001667 /* Detect ISP6312. */
1668 if (IS_QLA6312(ha))
1669 ha->fw_options[2] |= BIT_13;
1670
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673}
1674
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001675void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001676qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001677{
1678 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001679 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001680
Giridhar Malavalia9083012010-04-12 17:59:55 -07001681 if (IS_QLA82XX(ha))
1682 return;
1683
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001684 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001685 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001686 return;
1687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001688 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001689 le16_to_cpu(ha->fw_seriallink_options24[1]),
1690 le16_to_cpu(ha->fw_seriallink_options24[2]),
1691 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001692 if (rval != QLA_SUCCESS) {
1693 qla_printk(KERN_WARNING, ha,
1694 "Unable to update Serial Link options (%x).\n", rval);
1695 }
1696}
1697
1698void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001699qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001700{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001701 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001702 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001703 struct req_que *req = ha->req_q_map[0];
1704 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001705
1706 /* Setup ring parameters in initialization control block. */
1707 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1708 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001709 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1710 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1711 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1712 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1713 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1714 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001715
1716 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1717 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1718 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1719 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1720 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1721}
1722
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001723void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001724qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001725{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001726 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001727 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1728 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1729 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001730 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001731 uint16_t rid = 0;
1732 struct req_que *req = ha->req_q_map[0];
1733 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001734
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001735/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001736 icb = (struct init_cb_24xx *)ha->init_cb;
1737 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1738 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001739 icb->request_q_length = cpu_to_le16(req->length);
1740 icb->response_q_length = cpu_to_le16(rsp->length);
1741 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1742 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1743 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1744 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001745
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001746 if (ha->mqenable) {
1747 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1748 icb->rid = __constant_cpu_to_le16(rid);
1749 if (ha->flags.msix_enabled) {
1750 msix = &ha->msix_entries[1];
1751 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001752 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001753 icb->msix = cpu_to_le16(msix->entry);
1754 }
1755 /* Use alternate PCI bus number */
1756 if (MSB(rid))
1757 icb->firmware_options_2 |=
1758 __constant_cpu_to_le32(BIT_19);
1759 /* Use alternate PCI devfn */
1760 if (LSB(rid))
1761 icb->firmware_options_2 |=
1762 __constant_cpu_to_le32(BIT_18);
1763
Anirban Chakraborty31557542009-12-02 10:36:55 -08001764 /* Use Disable MSIX Handshake mode for capable adapters */
1765 if (IS_MSIX_NACK_CAPABLE(ha)) {
1766 icb->firmware_options_2 &=
1767 __constant_cpu_to_le32(~BIT_22);
1768 ha->flags.disable_msix_handshake = 1;
1769 qla_printk(KERN_INFO, ha,
1770 "MSIX Handshake Disable Mode turned on\n");
1771 } else {
1772 icb->firmware_options_2 |=
1773 __constant_cpu_to_le32(BIT_22);
1774 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001775 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001776
1777 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1778 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1779 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1780 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1781 } else {
1782 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1783 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1784 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1785 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1786 }
1787 /* PCI posting */
1788 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001789}
1790
Linus Torvalds1da177e2005-04-16 15:20:36 -07001791/**
1792 * qla2x00_init_rings() - Initializes firmware.
1793 * @ha: HA context
1794 *
1795 * Beginning of request ring has initialization control block already built
1796 * by nvram config routine.
1797 *
1798 * Returns 0 on success.
1799 */
1800static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001801qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802{
1803 int rval;
1804 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001805 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001806 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001807 struct req_que *req;
1808 struct rsp_que *rsp;
1809 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001810 struct mid_init_cb_24xx *mid_init_cb =
1811 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
1813 spin_lock_irqsave(&ha->hardware_lock, flags);
1814
1815 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001816 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001817 req = ha->req_q_map[que];
1818 if (!req)
1819 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001820 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001821 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001823 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001824
1825 /* Initialize firmware. */
1826 req->ring_ptr = req->ring;
1827 req->ring_index = 0;
1828 req->cnt = req->length;
1829 }
1830
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001831 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001832 rsp = ha->rsp_q_map[que];
1833 if (!rsp)
1834 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001835 /* Initialize response queue entries */
1836 qla2x00_init_response_q_entries(rsp);
1837 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001840 list_for_each_entry(vp, &ha->vp_list, list) {
1841 vp->rscn_in_ptr = 0;
1842 vp->rscn_out_ptr = 0;
1843 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1847
1848 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001849 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001851 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001852
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001853 if (ha->flags.npiv_supported) {
1854 if (ha->operating_mode == LOOP)
1855 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001856 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001857 }
1858
Andrew Vasquez24a08132009-03-24 09:08:16 -07001859 if (IS_FWI2_CAPABLE(ha)) {
1860 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1861 mid_init_cb->init_cb.execution_throttle =
1862 cpu_to_le16(ha->fw_xcb_count);
1863 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001864
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001865 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 if (rval) {
1867 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001868 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 } else {
1870 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 }
1873
1874 return (rval);
1875}
1876
1877/**
1878 * qla2x00_fw_ready() - Waits for firmware ready.
1879 * @ha: HA context
1880 *
1881 * Returns 0 on success.
1882 */
1883static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001884qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885{
1886 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001887 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 uint16_t min_wait; /* Minimum wait time if loop is down */
1889 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001890 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001891 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892
1893 rval = QLA_SUCCESS;
1894
1895 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001896 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
1898 /*
1899 * Firmware should take at most one RATOV to login, plus 5 seconds for
1900 * our own processing.
1901 */
1902 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1903 wait_time = min_wait;
1904 }
1905
1906 /* Min wait time if loop down */
1907 mtime = jiffies + (min_wait * HZ);
1908
1909 /* wait time before firmware ready */
1910 wtime = jiffies + (wait_time * HZ);
1911
1912 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1915
1916 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918
1919 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001920 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001922 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001925 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1926 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001928 state[2]));
1929 if ((state[2] & FSTATE_LOGGED_IN) &&
1930 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1931 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001933
1934 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001935 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001936 if (rval != QLA_SUCCESS)
1937 break;
1938
1939 /* Add time taken to initialize. */
1940 cs84xx_time = jiffies - cs84xx_time;
1941 wtime += cs84xx_time;
1942 mtime += cs84xx_time;
1943 DEBUG16(printk("scsi(%ld): Increasing "
1944 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001945 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001946 }
1947 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001951 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001952 &ha->login_timeout, &ha->r_a_tov);
1953
1954 rval = QLA_SUCCESS;
1955 break;
1956 }
1957
1958 rval = QLA_FUNCTION_FAILED;
1959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001960 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001961 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001963 * other than Wait for Login.
1964 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965 if (time_after_eq(jiffies, mtime)) {
1966 qla_printk(KERN_INFO, ha,
1967 "Cable is unplugged...\n");
1968
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001969 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001970 break;
1971 }
1972 }
1973 } else {
1974 /* Mailbox cmd failed. Timeout on min_wait. */
1975 if (time_after_eq(jiffies, mtime))
1976 break;
1977 }
1978
1979 if (time_after_eq(jiffies, wtime))
1980 break;
1981
1982 /* Delay for a while */
1983 msleep(500);
1984
1985 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 } while (1);
1988
Andrew Vasquez656e8912009-06-03 09:55:29 -07001989 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1990 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1991 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
1993 if (rval) {
1994 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 }
1997
1998 return (rval);
1999}
2000
2001/*
2002* qla2x00_configure_hba
2003* Setup adapter context.
2004*
2005* Input:
2006* ha = adapter state pointer.
2007*
2008* Returns:
2009* 0 = success
2010*
2011* Context:
2012* Kernel context.
2013*/
2014static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016{
2017 int rval;
2018 uint16_t loop_id;
2019 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002020 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 uint8_t al_pa;
2022 uint8_t area;
2023 uint8_t domain;
2024 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
2027 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002028 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002029 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08002032 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
2033 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08002035 } else {
2036 qla_printk(KERN_WARNING, ha,
2037 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08002039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 return (rval);
2041 }
2042
2043 if (topo == 4) {
2044 qla_printk(KERN_INFO, ha,
2045 "Cannot get topology - retrying.\n");
2046 return (QLA_FUNCTION_FAILED);
2047 }
2048
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050
2051 /* initialize */
2052 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
2053 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002054 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
2056 switch (topo) {
2057 case 0:
2058 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 ha->current_topology = ISP_CFG_NL;
2061 strcpy(connect_type, "(Loop)");
2062 break;
2063
2064 case 1:
2065 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002067 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068 ha->current_topology = ISP_CFG_FL;
2069 strcpy(connect_type, "(FL_Port)");
2070 break;
2071
2072 case 2:
2073 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002074 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 ha->operating_mode = P2P;
2076 ha->current_topology = ISP_CFG_N;
2077 strcpy(connect_type, "(N_Port-to-N_Port)");
2078 break;
2079
2080 case 3:
2081 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002083 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 ha->operating_mode = P2P;
2085 ha->current_topology = ISP_CFG_F;
2086 strcpy(connect_type, "(F_Port)");
2087 break;
2088
2089 default:
2090 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
2091 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002092 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 ha->current_topology = ISP_CFG_NL;
2094 strcpy(connect_type, "(Loop)");
2095 break;
2096 }
2097
2098 /* Save Host port and loop ID. */
2099 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 vha->d_id.b.domain = domain;
2101 vha->d_id.b.area = area;
2102 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 qla_printk(KERN_INFO, ha,
2106 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002107 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002112 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 }
2114
2115 return(rval);
2116}
2117
Giridhar Malavalia9083012010-04-12 17:59:55 -07002118inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
2120 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002121{
2122 char *st, *en;
2123 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002124 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07002125 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07002126 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002127
2128 if (memcmp(model, BINZERO, len) != 0) {
2129 strncpy(ha->model_number, model, len);
2130 st = en = ha->model_number;
2131 en += len - 1;
2132 while (en > st) {
2133 if (*en != 0x20 && *en != 0x00)
2134 break;
2135 *en-- = '\0';
2136 }
2137
2138 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002139 if (use_tbl &&
2140 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002141 index < QLA_MODEL_NAMES)
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 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07002147 if (use_tbl &&
2148 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002149 index < QLA_MODEL_NAMES) {
2150 strcpy(ha->model_number,
2151 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002152 strncpy(ha->model_desc,
2153 qla2x00_model_name[index * 2 + 1],
2154 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002155 } else {
2156 strcpy(ha->model_number, def);
2157 }
2158 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002159 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002161 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002162}
2163
David Miller4e08df32007-04-16 12:37:43 -07002164/* On sparc systems, obtain port and node WWN from firmware
2165 * properties.
2166 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002168{
2169#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002171 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002172 struct device_node *dp = pci_device_to_OF_node(pdev);
2173 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002174 int len;
2175
2176 val = of_get_property(dp, "port-wwn", &len);
2177 if (val && len >= WWN_SIZE)
2178 memcpy(nv->port_name, val, WWN_SIZE);
2179
2180 val = of_get_property(dp, "node-wwn", &len);
2181 if (val && len >= WWN_SIZE)
2182 memcpy(nv->node_name, val, WWN_SIZE);
2183#endif
2184}
2185
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186/*
2187* NVRAM configuration for ISP 2xxx
2188*
2189* Input:
2190* ha = adapter block pointer.
2191*
2192* Output:
2193* initialization control block in response_ring
2194* host adapters parameters in host adapter block
2195*
2196* Returns:
2197* 0 = success.
2198*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002199int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002200qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
David Miller4e08df32007-04-16 12:37:43 -07002202 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002203 uint8_t chksum = 0;
2204 uint16_t cnt;
2205 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002206 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002207 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002208 nvram_t *nv = ha->nvram;
2209 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002210 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
David Miller4e08df32007-04-16 12:37:43 -07002212 rval = QLA_SUCCESS;
2213
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002215 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 ha->nvram_base = 0;
2217 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2218 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2219 ha->nvram_base = 0x80;
2220
2221 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002222 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002223 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2224 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002226 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002227 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228
2229 /* Bad NVRAM data, set defaults parameters. */
2230 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2231 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2232 /* Reset NVRAM data. */
2233 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2234 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2235 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002236 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2237 "invalid -- WWPN) defaults.\n");
2238
2239 /*
2240 * Set default initialization control block.
2241 */
2242 memset(nv, 0, ha->nvram_size);
2243 nv->parameter_block_version = ICB_VERSION;
2244
2245 if (IS_QLA23XX(ha)) {
2246 nv->firmware_options[0] = BIT_2 | BIT_1;
2247 nv->firmware_options[1] = BIT_7 | BIT_5;
2248 nv->add_firmware_options[0] = BIT_5;
2249 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2250 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2251 nv->special_options[1] = BIT_7;
2252 } else if (IS_QLA2200(ha)) {
2253 nv->firmware_options[0] = BIT_2 | BIT_1;
2254 nv->firmware_options[1] = BIT_7 | BIT_5;
2255 nv->add_firmware_options[0] = BIT_5;
2256 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2257 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2258 } else if (IS_QLA2100(ha)) {
2259 nv->firmware_options[0] = BIT_3 | BIT_1;
2260 nv->firmware_options[1] = BIT_5;
2261 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2262 }
2263
2264 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2265 nv->execution_throttle = __constant_cpu_to_le16(16);
2266 nv->retry_count = 8;
2267 nv->retry_delay = 1;
2268
2269 nv->port_name[0] = 33;
2270 nv->port_name[3] = 224;
2271 nv->port_name[4] = 139;
2272
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002274
2275 nv->login_timeout = 4;
2276
2277 /*
2278 * Set default host adapter parameters
2279 */
2280 nv->host_p[1] = BIT_2;
2281 nv->reset_delay = 5;
2282 nv->port_down_retry_count = 8;
2283 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2284 nv->link_down_timeout = 60;
2285
2286 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 }
2288
2289#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2290 /*
2291 * The SN2 does not provide BIOS emulation which means you can't change
2292 * potentially bogus BIOS settings. Force the use of default settings
2293 * for link rate and frame size. Hope that the rest of the settings
2294 * are valid.
2295 */
2296 if (ia64_platform_is("sn2")) {
2297 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2298 if (IS_QLA23XX(ha))
2299 nv->special_options[1] = BIT_7;
2300 }
2301#endif
2302
2303 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002304 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
2306 /*
2307 * Setup driver NVRAM options.
2308 */
2309 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2310 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2311 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2312 nv->firmware_options[1] &= ~BIT_4;
2313
2314 if (IS_QLA23XX(ha)) {
2315 nv->firmware_options[0] |= BIT_2;
2316 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002317 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002318 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319
2320 if (IS_QLA2300(ha)) {
2321 if (ha->fb_rev == FPM_2310) {
2322 strcpy(ha->model_number, "QLA2310");
2323 } else {
2324 strcpy(ha->model_number, "QLA2300");
2325 }
2326 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002328 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 }
2330 } else if (IS_QLA2200(ha)) {
2331 nv->firmware_options[0] |= BIT_2;
2332 /*
2333 * 'Point-to-point preferred, else loop' is not a safe
2334 * connection mode setting.
2335 */
2336 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2337 (BIT_5 | BIT_4)) {
2338 /* Force 'loop preferred, else point-to-point'. */
2339 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2340 nv->add_firmware_options[0] |= BIT_5;
2341 }
2342 strcpy(ha->model_number, "QLA22xx");
2343 } else /*if (IS_QLA2100(ha))*/ {
2344 strcpy(ha->model_number, "QLA2100");
2345 }
2346
2347 /*
2348 * Copy over NVRAM RISC parameter block to initialization control block.
2349 */
2350 dptr1 = (uint8_t *)icb;
2351 dptr2 = (uint8_t *)&nv->parameter_block_version;
2352 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2353 while (cnt--)
2354 *dptr1++ = *dptr2++;
2355
2356 /* Copy 2nd half. */
2357 dptr1 = (uint8_t *)icb->add_firmware_options;
2358 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2359 while (cnt--)
2360 *dptr1++ = *dptr2++;
2361
Andrew Vasquez5341e862006-05-17 15:09:16 -07002362 /* Use alternate WWN? */
2363 if (nv->host_p[1] & BIT_7) {
2364 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2365 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2366 }
2367
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 /* Prepare nodename */
2369 if ((icb->firmware_options[1] & BIT_6) == 0) {
2370 /*
2371 * Firmware will apply the following mask if the nodename was
2372 * not provided.
2373 */
2374 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2375 icb->node_name[0] &= 0xF0;
2376 }
2377
2378 /*
2379 * Set host adapter parameters.
2380 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002381 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002382 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2384 /* Always load RISC code on non ISP2[12]00 chips. */
2385 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2386 ha->flags.disable_risc_code_load = 0;
2387 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2388 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2389 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002390 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002391 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392
2393 ha->operating_mode =
2394 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2395
2396 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2397 sizeof(ha->fw_seriallink_options));
2398
2399 /* save HBA serial number */
2400 ha->serial0 = icb->port_name[5];
2401 ha->serial1 = icb->port_name[6];
2402 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2404 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405
2406 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2407
2408 ha->retry_count = nv->retry_count;
2409
2410 /* Set minimum login_timeout to 4 seconds. */
2411 if (nv->login_timeout < ql2xlogintimeout)
2412 nv->login_timeout = ql2xlogintimeout;
2413 if (nv->login_timeout < 4)
2414 nv->login_timeout = 4;
2415 ha->login_timeout = nv->login_timeout;
2416 icb->login_timeout = nv->login_timeout;
2417
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002418 /* Set minimum RATOV to 100 tenths of a second. */
2419 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 ha->loop_reset_delay = nv->reset_delay;
2422
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 /* Link Down Timeout = 0:
2424 *
2425 * When Port Down timer expires we will start returning
2426 * I/O's to OS with "DID_NO_CONNECT".
2427 *
2428 * Link Down Timeout != 0:
2429 *
2430 * The driver waits for the link to come up after link down
2431 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002432 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 if (nv->link_down_timeout == 0) {
2434 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002435 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 } else {
2437 ha->link_down_timeout = nv->link_down_timeout;
2438 ha->loop_down_abort_time =
2439 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002440 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 /*
2443 * Need enough time to try and get the port back.
2444 */
2445 ha->port_down_retry_count = nv->port_down_retry_count;
2446 if (qlport_down_retry)
2447 ha->port_down_retry_count = qlport_down_retry;
2448 /* Set login_retry_count */
2449 ha->login_retry_count = nv->retry_count;
2450 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2451 ha->port_down_retry_count > 3)
2452 ha->login_retry_count = ha->port_down_retry_count;
2453 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2454 ha->login_retry_count = ha->port_down_retry_count;
2455 if (ql2xloginretrycount)
2456 ha->login_retry_count = ql2xloginretrycount;
2457
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 icb->lun_enables = __constant_cpu_to_le16(0);
2459 icb->command_resource_count = 0;
2460 icb->immediate_notify_resource_count = 0;
2461 icb->timeout = __constant_cpu_to_le16(0);
2462
2463 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2464 /* Enable RIO */
2465 icb->firmware_options[0] &= ~BIT_3;
2466 icb->add_firmware_options[0] &=
2467 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2468 icb->add_firmware_options[0] |= BIT_2;
2469 icb->response_accumulation_timer = 3;
2470 icb->interrupt_delay_timer = 5;
2471
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002474 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002476 ha->zio_mode = icb->add_firmware_options[0] &
2477 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2478 ha->zio_timer = icb->interrupt_delay_timer ?
2479 icb->interrupt_delay_timer: 2;
2480 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 icb->add_firmware_options[0] &=
2482 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002484 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002485 ha->zio_mode = QLA_ZIO_MODE_6;
2486
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002487 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002488 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002489 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002491 "ZIO mode %d enabled; timer delay (%d us).\n",
2492 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002494 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2495 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002496 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 }
2498 }
2499
David Miller4e08df32007-04-16 12:37:43 -07002500 if (rval) {
2501 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002502 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002503 }
2504 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505}
2506
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002507static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002508qla2x00_rport_del(void *data)
2509{
2510 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002511 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002514 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002515 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002517 if (rport)
2518 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002519}
2520
Linus Torvalds1da177e2005-04-16 15:20:36 -07002521/**
2522 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2523 * @ha: HA context
2524 * @flags: allocation flags
2525 *
2526 * Returns a pointer to the allocated fcport, or NULL, if none available.
2527 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002528fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530{
2531 fc_port_t *fcport;
2532
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002533 fcport = kzalloc(sizeof(fc_port_t), flags);
2534 if (!fcport)
2535 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536
2537 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002538 fcport->vha = vha;
2539 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540 fcport->port_type = FCT_UNKNOWN;
2541 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002543 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002545 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546}
2547
2548/*
2549 * qla2x00_configure_loop
2550 * Updates Fibre Channel Device Database with what is actually on loop.
2551 *
2552 * Input:
2553 * ha = adapter block pointer.
2554 *
2555 * Returns:
2556 * 0 = success.
2557 * 1 = error.
2558 * 2 = database was full and device was not configured.
2559 */
2560static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002561qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002562{
2563 int rval;
2564 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 rval = QLA_SUCCESS;
2567
2568 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2570 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 if (rval != QLA_SUCCESS) {
2572 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 return (rval);
2575 }
2576 }
2577
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581
2582 /*
2583 * If we have both an RSCN and PORT UPDATE pending then handle them
2584 * both at the same time.
2585 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002586 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2587 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
Michael Hernandez3064ff32009-12-15 21:29:44 -08002589 qla2x00_get_data_rate(vha);
2590
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 /* Determine what we need to do */
2592 if (ha->current_topology == ISP_CFG_FL &&
2593 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2594
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 set_bit(RSCN_UPDATE, &flags);
2597
2598 } else if (ha->current_topology == ISP_CFG_F &&
2599 (test_bit(LOCAL_LOOP_UPDATE, &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 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2604
Andrew Vasquez21333b42006-05-17 15:09:56 -07002605 } else if (ha->current_topology == ISP_CFG_N) {
2606 clear_bit(RSCN_UPDATE, &flags);
2607
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002608 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2610
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 set_bit(RSCN_UPDATE, &flags);
2613 set_bit(LOCAL_LOOP_UPDATE, &flags);
2614 }
2615
2616 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002618 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 else
2620 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 }
2622
2623 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002626 else
2627 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 }
2629
2630 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002631 if (atomic_read(&vha->loop_down_timer) ||
2632 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 rval = QLA_FUNCTION_FAILED;
2634 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 }
2639 }
2640
2641 if (rval) {
2642 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002643 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 } else {
2645 DEBUG3(printk("%s: exiting normally\n", __func__));
2646 }
2647
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002648 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002649 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002651 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002652 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07002654 if (!IS_ALOGIO_CAPABLE(ha))
2655 vha->flags.rscn_queue_overflow = 1;
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 }
2658
2659 return (rval);
2660}
2661
2662
2663
2664/*
2665 * qla2x00_configure_local_loop
2666 * Updates Fibre Channel Device Database with local loop devices.
2667 *
2668 * Input:
2669 * ha = adapter block pointer.
2670 *
2671 * Returns:
2672 * 0 = success.
2673 */
2674static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002675qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676{
2677 int rval, rval2;
2678 int found_devs;
2679 int found;
2680 fc_port_t *fcport, *new_fcport;
2681
2682 uint16_t index;
2683 uint16_t entries;
2684 char *id_iter;
2685 uint16_t loop_id;
2686 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688
2689 found_devs = 0;
2690 new_fcport = NULL;
2691 entries = MAX_FIBRE_DEVICES;
2692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002693 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2694 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695
2696 /* Get list of logged in devices. */
2697 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002699 &entries);
2700 if (rval != QLA_SUCCESS)
2701 goto cleanup_allocation;
2702
2703 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002704 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2706 entries * sizeof(struct gid_list_info)));
2707
2708 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 if (new_fcport == NULL) {
2711 rval = QLA_MEMORY_ALLOC_FAILED;
2712 goto cleanup_allocation;
2713 }
2714 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2715
2716 /*
2717 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2718 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2721 fcport->port_type != FCT_BROADCAST &&
2722 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2723
2724 DEBUG(printk("scsi(%ld): Marking port lost, "
2725 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002726 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727
2728 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 }
2730 }
2731
2732 /* Add devices to port list. */
2733 id_iter = (char *)ha->gid_list;
2734 for (index = 0; index < entries; index++) {
2735 domain = ((struct gid_list_info *)id_iter)->domain;
2736 area = ((struct gid_list_info *)id_iter)->area;
2737 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002738 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 loop_id = (uint16_t)
2740 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002741 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 loop_id = le16_to_cpu(
2743 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002744 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745
2746 /* Bypass reserved domain fields. */
2747 if ((domain & 0xf0) == 0xf0)
2748 continue;
2749
2750 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002751 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 continue;
2754
2755 /* Bypass invalid local loop ID. */
2756 if (loop_id > LAST_LOCAL_LOOP_ID)
2757 continue;
2758
2759 /* Fill in member data. */
2760 new_fcport->d_id.b.domain = domain;
2761 new_fcport->d_id.b.area = area;
2762 new_fcport->d_id.b.al_pa = al_pa;
2763 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002764 new_fcport->vp_idx = vha->vp_idx;
2765 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 if (rval2 != QLA_SUCCESS) {
2767 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2768 "information -- get_port_database=%x, "
2769 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002771 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 vha->host_no));
2773 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 continue;
2775 }
2776
2777 /* Check for matching device in port list. */
2778 found = 0;
2779 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002780 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 if (memcmp(new_fcport->port_name, fcport->port_name,
2782 WWN_SIZE))
2783 continue;
2784
Shyam Sundarddb9b122009-03-24 09:08:10 -07002785 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 fcport->loop_id = new_fcport->loop_id;
2787 fcport->port_type = new_fcport->port_type;
2788 fcport->d_id.b24 = new_fcport->d_id.b24;
2789 memcpy(fcport->node_name, new_fcport->node_name,
2790 WWN_SIZE);
2791
2792 found++;
2793 break;
2794 }
2795
2796 if (!found) {
2797 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 if (vha->vp_idx) {
2799 new_fcport->vha = vha;
2800 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002801 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803
2804 /* Allocate a new replacement fcport. */
2805 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002806 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 if (new_fcport == NULL) {
2808 rval = QLA_MEMORY_ALLOC_FAILED;
2809 goto cleanup_allocation;
2810 }
2811 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2812 }
2813
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002814 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002815 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002816
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818
2819 found_devs++;
2820 }
2821
2822cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002823 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
2825 if (rval != QLA_SUCCESS) {
2826 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 }
2829
Linus Torvalds1da177e2005-04-16 15:20:36 -07002830 return (rval);
2831}
2832
2833static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002835{
2836#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002837 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2838 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002839 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002840 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002842
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002843 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002844 return;
2845
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002846 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2847 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002848 return;
2849
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002851 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002852 if (rval != QLA_SUCCESS) {
2853 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2854 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002856 fcport->port_name[2], fcport->port_name[3],
2857 fcport->port_name[4], fcport->port_name[5],
2858 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002859 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002860 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002861 link_speed = link_speeds[LS_UNKNOWN];
2862 if (fcport->fp_speed < 5)
2863 link_speed = link_speeds[fcport->fp_speed];
2864 else if (fcport->fp_speed == 0x13)
2865 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002866 DEBUG2(qla_printk(KERN_INFO, ha,
2867 "iIDMA adjusted to %s GB/s on "
2868 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002869 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002870 fcport->port_name[1], fcport->port_name[2],
2871 fcport->port_name[3], fcport->port_name[4],
2872 fcport->port_name[5], fcport->port_name[6],
2873 fcport->port_name[7]));
2874 }
2875}
2876
Adrian Bunk23be3312006-11-24 02:46:01 +01002877static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002878qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002879{
2880 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002881 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002882 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002883
Andrew Vasquezac280b62009-08-20 11:06:05 -07002884 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002885
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002886 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2887 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002888 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2889 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2890 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002892 if (!rport) {
2893 qla_printk(KERN_WARNING, ha,
2894 "Unable to allocate fc remote port!\n");
2895 return;
2896 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002897 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002898 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002899 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002900
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002901 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002902
2903 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002904 if (fcport->port_type == FCT_INITIATOR)
2905 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2906 if (fcport->port_type == FCT_TARGET)
2907 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002908 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002909}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
2911/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002912 * qla2x00_update_fcport
2913 * Updates device on list.
2914 *
2915 * Input:
2916 * ha = adapter block pointer.
2917 * fcport = port structure pointer.
2918 *
2919 * Return:
2920 * 0 - Success
2921 * BIT_0 - error
2922 *
2923 * Context:
2924 * Kernel context.
2925 */
2926void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002928{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002932 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002934 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002936 PORT_RETRY_TIME);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002937 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002940
2941 atomic_set(&fcport->state, FCS_ONLINE);
2942
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002944}
2945
2946/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 * qla2x00_configure_fabric
2948 * Setup SNS devices with loop ID's.
2949 *
2950 * Input:
2951 * ha = adapter block pointer.
2952 *
2953 * Returns:
2954 * 0 = success.
2955 * BIT_0 = error
2956 */
2957static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002958qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959{
2960 int rval, rval2;
2961 fc_port_t *fcport, *fcptemp;
2962 uint16_t next_loopid;
2963 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002964 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002966 struct qla_hw_data *ha = vha->hw;
2967 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
2969 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002970 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002971 loop_id = NPH_F_PORT;
2972 else
2973 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002974 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975 if (rval != QLA_SUCCESS) {
2976 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 return (QLA_SUCCESS);
2981 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002982 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002983
2984 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 if (rval2 == QLA_RSCNS_HANDLED) {
2987 /* No point doing the scan, just continue. */
2988 return (QLA_SUCCESS);
2989 }
2990 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002991 /* FDMI support. */
2992 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002993 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2994 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002995
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002997 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002998 loop_id = NPH_SNS;
2999 else
3000 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003002 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003003 if (mb[0] != MBS_COMMAND_COMPLETE) {
3004 DEBUG2(qla_printk(KERN_INFO, ha,
3005 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003006 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003007 mb[0], mb[1], mb[2], mb[6], mb[7]));
3008 return (QLA_SUCCESS);
3009 }
3010
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
3012 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 /* EMPTY */
3014 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003015 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 /* EMPTY */
3019 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 /* EMPTY */
3024 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 "failed.\n", vha->host_no));
3026 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 /* EMPTY */
3028 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 }
3031 }
3032
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003033 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 if (rval != QLA_SUCCESS)
3035 break;
3036
3037 /*
3038 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003039 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3042 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 break;
3044
3045 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
3046 continue;
3047
3048 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003049 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003050 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003052 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003053 fcport->port_type != FCT_INITIATOR &&
3054 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003055 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003056 fcport->loop_id,
3057 fcport->d_id.b.domain,
3058 fcport->d_id.b.area,
3059 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 fcport->loop_id = FC_NO_LOOP_ID;
3061 }
3062 }
3063 }
3064
3065 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003066 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
3068 /*
3069 * Scan through our port list and login entries that need to be
3070 * logged in.
3071 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003072 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3073 if (atomic_read(&vha->loop_down_timer) ||
3074 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 break;
3076
3077 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3078 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
3079 continue;
3080
3081 if (fcport->loop_id == FC_NO_LOOP_ID) {
3082 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07003083 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003084 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003085 if (rval != QLA_SUCCESS) {
3086 /* Ran out of IDs to use */
3087 break;
3088 }
3089 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003090 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003091 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 }
3093
3094 /* Exit if out of loop IDs. */
3095 if (rval != QLA_SUCCESS) {
3096 break;
3097 }
3098
3099 /*
3100 * Login and add the new devices to our port list.
3101 */
3102 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003103 if (atomic_read(&vha->loop_down_timer) ||
3104 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003105 break;
3106
3107 /* Find a new loop ID to use. */
3108 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003109 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 if (rval != QLA_SUCCESS) {
3111 /* Ran out of IDs to use */
3112 break;
3113 }
3114
bdf79622005-04-17 15:06:53 -05003115 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003116 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003117
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 if (vha->vp_idx) {
3119 fcport->vha = vha;
3120 fcport->vp_idx = vha->vp_idx;
3121 }
3122 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 }
3124 } while (0);
3125
3126 /* Free all new device structures not processed. */
3127 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
3128 list_del(&fcport->list);
3129 kfree(fcport);
3130 }
3131
3132 if (rval) {
3133 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 }
3136
3137 return (rval);
3138}
3139
3140
3141/*
3142 * qla2x00_find_all_fabric_devs
3143 *
3144 * Input:
3145 * ha = adapter block pointer.
3146 * dev = database device entry pointer.
3147 *
3148 * Returns:
3149 * 0 = success.
3150 *
3151 * Context:
3152 * Kernel context.
3153 */
3154static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
3156 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157{
3158 int rval;
3159 uint16_t loop_id;
3160 fc_port_t *fcport, *new_fcport, *fcptemp;
3161 int found;
3162
3163 sw_info_t *swl;
3164 int swl_idx;
3165 int first_dev, last_dev;
Mike Waychison1516ef42010-05-04 15:01:31 -07003166 port_id_t wrap = {}, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003167 struct qla_hw_data *ha = vha->hw;
3168 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003169 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 rval = QLA_SUCCESS;
3172
3173 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003174 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003175 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 /*EMPTY*/
3177 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003178 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003180 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 kfree(swl);
3182 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 kfree(swl);
3185 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003186 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 kfree(swl);
3188 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003189 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003190 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3191 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192 }
3193 }
3194 swl_idx = 0;
3195
3196 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003197 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003199 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 return (QLA_MEMORY_ALLOC_FAILED);
3201 }
3202 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 /* Set start port ID scan at adapter ID. */
3204 first_dev = 1;
3205 last_dev = 0;
3206
3207 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003208 loop_id = ha->min_external_loopid;
3209 for (; loop_id <= ha->max_loop_id; loop_id++) {
3210 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 continue;
3212
Giridhar Malavali3a6478d2010-05-28 15:08:20 -07003213 if (ha->current_topology == ISP_CFG_FL &&
3214 (atomic_read(&vha->loop_down_timer) ||
3215 LOOP_TRANSITION(vha))) {
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003216 atomic_set(&vha->loop_down_timer, 0);
3217 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3218 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003220 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
3222 if (swl != NULL) {
3223 if (last_dev) {
3224 wrap.b24 = new_fcport->d_id.b24;
3225 } else {
3226 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3227 memcpy(new_fcport->node_name,
3228 swl[swl_idx].node_name, WWN_SIZE);
3229 memcpy(new_fcport->port_name,
3230 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003231 memcpy(new_fcport->fabric_port_name,
3232 swl[swl_idx].fabric_port_name, WWN_SIZE);
3233 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234
3235 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3236 last_dev = 1;
3237 }
3238 swl_idx++;
3239 }
3240 } else {
3241 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 if (rval != QLA_SUCCESS) {
3244 qla_printk(KERN_WARNING, ha,
3245 "SNS scan failed -- assuming zero-entry "
3246 "result...\n");
3247 list_for_each_entry_safe(fcport, fcptemp,
3248 new_fcports, list) {
3249 list_del(&fcport->list);
3250 kfree(fcport);
3251 }
3252 rval = QLA_SUCCESS;
3253 break;
3254 }
3255 }
3256
3257 /* If wrap on switch device list, exit. */
3258 if (first_dev) {
3259 wrap.b24 = new_fcport->d_id.b24;
3260 first_dev = 0;
3261 } else if (new_fcport->d_id.b24 == wrap.b24) {
3262 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3265 break;
3266 }
3267
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003268 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003269 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 continue;
3271
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003272 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 found = 0;
3274 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003275 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3277 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003278 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003280 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003281 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003282 continue;
3283 }
3284
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003285 /* Bypass if same domain and area of adapter. */
3286 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003288 ISP_CFG_FL)
3289 continue;
3290
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 /* Bypass reserved domain fields. */
3292 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3293 continue;
3294
3295 /* Locate matching device in database. */
3296 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 if (memcmp(new_fcport->port_name, fcport->port_name,
3299 WWN_SIZE))
3300 continue;
3301
3302 found++;
3303
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003304 /* Update port state. */
3305 memcpy(fcport->fabric_port_name,
3306 new_fcport->fabric_port_name, WWN_SIZE);
3307 fcport->fp_speed = new_fcport->fp_speed;
3308
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 /*
3310 * If address the same and state FCS_ONLINE, nothing
3311 * changed.
3312 */
3313 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3314 atomic_read(&fcport->state) == FCS_ONLINE) {
3315 break;
3316 }
3317
3318 /*
3319 * If device was not a fabric device before.
3320 */
3321 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3322 fcport->d_id.b24 = new_fcport->d_id.b24;
3323 fcport->loop_id = FC_NO_LOOP_ID;
3324 fcport->flags |= (FCF_FABRIC_DEVICE |
3325 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326 break;
3327 }
3328
3329 /*
3330 * Port ID changed or device was marked to be updated;
3331 * Log it out if still logged in and mark it for
3332 * relogin later.
3333 */
3334 fcport->d_id.b24 = new_fcport->d_id.b24;
3335 fcport->flags |= FCF_LOGIN_NEEDED;
3336 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003337 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 fcport->port_type != FCT_INITIATOR &&
3339 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003341 fcport->d_id.b.domain, fcport->d_id.b.area,
3342 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 fcport->loop_id = FC_NO_LOOP_ID;
3344 }
3345
3346 break;
3347 }
3348
3349 if (found)
3350 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 /* If device was not in our fcports list, then add it. */
3352 list_add_tail(&new_fcport->list, new_fcports);
3353
3354 /* Allocate a new replacement fcport. */
3355 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003356 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003358 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 return (QLA_MEMORY_ALLOC_FAILED);
3360 }
3361 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3362 new_fcport->d_id.b24 = nxt_d_id.b24;
3363 }
3364
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003365 kfree(swl);
3366 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 return (rval);
3369}
3370
3371/*
3372 * qla2x00_find_new_loop_id
3373 * Scan through our port list and find a new usable loop ID.
3374 *
3375 * Input:
3376 * ha: adapter state pointer.
3377 * dev: port structure pointer.
3378 *
3379 * Returns:
3380 * qla2x00 local function return status code.
3381 *
3382 * Context:
3383 * Kernel context.
3384 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003385static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387{
3388 int rval;
3389 int found;
3390 fc_port_t *fcport;
3391 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003392 struct qla_hw_data *ha = vha->hw;
3393 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003394 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 rval = QLA_SUCCESS;
3397
3398 /* Save starting loop ID. */
3399 first_loop_id = dev->loop_id;
3400
3401 for (;;) {
3402 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405
3406 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003407 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409
3410 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 /* first loop ID. */
3413 dev->loop_id = ha->min_external_loopid;
3414 }
3415
3416 /* Check for loop ID being already in use. */
3417 found = 0;
3418 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003419 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003420 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3421 if (fcport->loop_id == dev->loop_id &&
3422 fcport != dev) {
3423 /* ID possibly in use */
3424 found++;
3425 break;
3426 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 if (found)
3429 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430 }
3431
3432 /* If not in use then it is free to use. */
3433 if (!found) {
3434 break;
3435 }
3436
3437 /* ID in use. Try next value. */
3438 dev->loop_id++;
3439
3440 /* If wrap around. No free ID to use. */
3441 if (dev->loop_id == first_loop_id) {
3442 dev->loop_id = FC_NO_LOOP_ID;
3443 rval = QLA_FUNCTION_FAILED;
3444 break;
3445 }
3446 }
3447
3448 return (rval);
3449}
3450
3451/*
3452 * qla2x00_device_resync
3453 * Marks devices in the database that needs resynchronization.
3454 *
3455 * Input:
3456 * ha = adapter block pointer.
3457 *
3458 * Context:
3459 * Kernel context.
3460 */
3461static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003463{
3464 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 uint32_t mask;
3466 fc_port_t *fcport;
3467 uint32_t rscn_entry;
3468 uint8_t rscn_out_iter;
3469 uint8_t format;
Mike Waychison1516ef42010-05-04 15:01:31 -07003470 port_id_t d_id = {};
Linus Torvalds1da177e2005-04-16 15:20:36 -07003471
3472 rval = QLA_RSCNS_HANDLED;
3473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003474 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3475 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 format = MSB(MSW(rscn_entry));
3479 d_id.b.domain = LSB(MSW(rscn_entry));
3480 d_id.b.area = MSB(LSW(rscn_entry));
3481 d_id.b.al_pa = LSB(LSW(rscn_entry));
3482
3483 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3484 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 d_id.b.area, d_id.b.al_pa));
3487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003488 vha->rscn_out_ptr++;
3489 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3490 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491
3492 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003493 for (rscn_out_iter = vha->rscn_out_ptr;
3494 !vha->flags.rscn_queue_overflow &&
3495 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496 rscn_out_iter = (rscn_out_iter ==
3497 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003499 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003500 break;
3501
3502 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003503 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003504 rscn_out_iter));
3505
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003506 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003507 }
3508
3509 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003510 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003512 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513
3514 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003515 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 }
3517
3518 switch (format) {
3519 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520 mask = 0xffffff;
3521 break;
3522 case 1:
3523 mask = 0xffff00;
3524 break;
3525 case 2:
3526 mask = 0xff0000;
3527 break;
3528 default:
3529 mask = 0x0;
3530 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532 break;
3533 }
3534
3535 rval = QLA_SUCCESS;
3536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003537 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003538 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3539 (fcport->d_id.b24 & mask) != d_id.b24 ||
3540 fcport->port_type == FCT_BROADCAST)
3541 continue;
3542
3543 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3544 if (format != 3 ||
3545 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003546 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003547 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 }
3549 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 }
3551 }
3552 return (rval);
3553}
3554
3555/*
3556 * qla2x00_fabric_dev_login
3557 * Login fabric target device and update FC port database.
3558 *
3559 * Input:
3560 * ha: adapter state pointer.
3561 * fcport: port structure list pointer.
3562 * next_loopid: contains value of a new loop ID that can be used
3563 * by the next login attempt.
3564 *
3565 * Returns:
3566 * qla2x00 local function return status code.
3567 *
3568 * Context:
3569 * Kernel context.
3570 */
3571static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573 uint16_t *next_loopid)
3574{
3575 int rval;
3576 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003577 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579
3580 rval = QLA_SUCCESS;
3581 retry = 0;
3582
Andrew Vasquezac280b62009-08-20 11:06:05 -07003583 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003584 if (fcport->flags & FCF_ASYNC_SENT)
3585 return rval;
3586 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003587 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3588 if (!rval)
3589 return rval;
3590 }
3591
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003592 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003593 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003594 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003595 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003596 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003597 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003598 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003599 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003601 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003602 fcport->d_id.b.domain, fcport->d_id.b.area,
3603 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003604 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003605 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003606 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003607 }
3608 }
3609
3610 return (rval);
3611}
3612
3613/*
3614 * qla2x00_fabric_login
3615 * Issue fabric login command.
3616 *
3617 * Input:
3618 * ha = adapter block pointer.
3619 * device = pointer to FC device type structure.
3620 *
3621 * Returns:
3622 * 0 - Login successfully
3623 * 1 - Login failed
3624 * 2 - Initiator device
3625 * 3 - Fatal error
3626 */
3627int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003628qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 uint16_t *next_loopid)
3630{
3631 int rval;
3632 int retry;
3633 uint16_t tmp_loopid;
3634 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003635 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003636
3637 retry = 0;
3638 tmp_loopid = 0;
3639
3640 for (;;) {
3641 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3642 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003643 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3645
3646 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003647 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 fcport->d_id.b.domain, fcport->d_id.b.area,
3649 fcport->d_id.b.al_pa, mb, BIT_0);
3650 if (mb[0] == MBS_PORT_ID_USED) {
3651 /*
3652 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003653 * recommends the driver perform an implicit login with
3654 * the specified ID again. The ID we just used is save
3655 * here so we return with an ID that can be tried by
3656 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003657 */
3658 retry++;
3659 tmp_loopid = fcport->loop_id;
3660 fcport->loop_id = mb[1];
3661
3662 DEBUG(printk("Fabric Login: port in use - next "
3663 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3664 fcport->loop_id, fcport->d_id.b.domain,
3665 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3666
3667 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3668 /*
3669 * Login succeeded.
3670 */
3671 if (retry) {
3672 /* A retry occurred before. */
3673 *next_loopid = tmp_loopid;
3674 } else {
3675 /*
3676 * No retry occurred before. Just increment the
3677 * ID value for next login.
3678 */
3679 *next_loopid = (fcport->loop_id + 1);
3680 }
3681
3682 if (mb[1] & BIT_0) {
3683 fcport->port_type = FCT_INITIATOR;
3684 } else {
3685 fcport->port_type = FCT_TARGET;
3686 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003687 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003688 }
3689 }
3690
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003691 if (mb[10] & BIT_0)
3692 fcport->supported_classes |= FC_COS_CLASS2;
3693 if (mb[10] & BIT_1)
3694 fcport->supported_classes |= FC_COS_CLASS3;
3695
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 rval = QLA_SUCCESS;
3697 break;
3698 } else if (mb[0] == MBS_LOOP_ID_USED) {
3699 /*
3700 * Loop ID already used, try next loop ID.
3701 */
3702 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003703 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003704 if (rval != QLA_SUCCESS) {
3705 /* Ran out of loop IDs to use */
3706 break;
3707 }
3708 } else if (mb[0] == MBS_COMMAND_ERROR) {
3709 /*
3710 * Firmware possibly timed out during login. If NO
3711 * retries are left to do then the device is declared
3712 * dead.
3713 */
3714 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003715 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003716 fcport->d_id.b.domain, fcport->d_id.b.area,
3717 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003718 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719
3720 rval = 1;
3721 break;
3722 } else {
3723 /*
3724 * unrecoverable / not handled error
3725 */
3726 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003727 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003728 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003729 fcport->d_id.b.domain, fcport->d_id.b.area,
3730 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3731
3732 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003733 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003734 fcport->d_id.b.domain, fcport->d_id.b.area,
3735 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003736 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003737 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003738
3739 rval = 3;
3740 break;
3741 }
3742 }
3743
3744 return (rval);
3745}
3746
3747/*
3748 * qla2x00_local_device_login
3749 * Issue local device login command.
3750 *
3751 * Input:
3752 * ha = adapter block pointer.
3753 * loop_id = loop id of device to login to.
3754 *
3755 * Returns (Where's the #define!!!!):
3756 * 0 - Login successfully
3757 * 1 - Login failed
3758 * 3 - Fatal error
3759 */
3760int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003761qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762{
3763 int rval;
3764 uint16_t mb[MAILBOX_REGISTER_COUNT];
3765
3766 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003767 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 if (rval == QLA_SUCCESS) {
3769 /* Interrogate mailbox registers for any errors */
3770 if (mb[0] == MBS_COMMAND_ERROR)
3771 rval = 1;
3772 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3773 /* device not in PCB table */
3774 rval = 3;
3775 }
3776
3777 return (rval);
3778}
3779
3780/*
3781 * qla2x00_loop_resync
3782 * Resync with fibre channel devices.
3783 *
3784 * Input:
3785 * ha = adapter block pointer.
3786 *
3787 * Returns:
3788 * 0 = success
3789 */
3790int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003791qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003792{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003793 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003794 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003795 struct req_que *req;
3796 struct rsp_que *rsp;
3797
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003798 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003799 req = vha->hw->req_q_map[0];
3800 else
3801 req = vha->req;
3802 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003804 atomic_set(&vha->loop_state, LOOP_UPDATE);
3805 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3806 if (vha->flags.online) {
3807 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3809 wait_time = 256;
3810 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003811 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003813 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003814 qla2x00_marker(vha, req, rsp, 0, 0,
3815 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817
3818 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003820
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003823 } while (!atomic_read(&vha->loop_down_timer) &&
3824 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3825 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3826 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003827 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 }
3829
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003832
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003834 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003835
3836 return (rval);
3837}
3838
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003840qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003841{
3842 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003843 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003844
3845 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003846 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3847 list_for_each_entry(fcport, &vha->vp_fcports, list)
3848 if (fcport && fcport->drport &&
3849 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3850 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003851}
3852
Giridhar Malavalia9083012010-04-12 17:59:55 -07003853void
3854qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3855{
3856 struct qla_hw_data *ha = vha->hw;
3857 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3858 struct scsi_qla_host *tvp;
3859
3860 vha->flags.online = 0;
3861 ha->flags.chip_reset_done = 0;
3862 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3863 ha->qla_stats.total_isp_aborts++;
3864
3865 qla_printk(KERN_INFO, ha,
3866 "Performing ISP error recovery - ha= %p.\n", ha);
3867
3868 /* Chip reset does not apply to 82XX */
3869 if (!IS_QLA82XX(ha))
3870 ha->isp_ops->reset_chip(vha);
3871
3872 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3873 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3874 atomic_set(&vha->loop_state, LOOP_DOWN);
3875 qla2x00_mark_all_devices_lost(vha, 0);
3876 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3877 qla2x00_mark_all_devices_lost(vp, 0);
3878 } else {
3879 if (!atomic_read(&vha->loop_down_timer))
3880 atomic_set(&vha->loop_down_timer,
3881 LOOP_DOWN_TIME);
3882 }
3883
3884 /* Make sure for ISP 82XX IO DMA is complete */
3885 if (IS_QLA82XX(ha))
3886 qla82xx_wait_for_pending_commands(vha);
3887
3888 /* Requeue all commands in outstanding command list. */
3889 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3890}
3891
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892/*
3893* qla2x00_abort_isp
3894* Resets ISP and aborts all outstanding commands.
3895*
3896* Input:
3897* ha = adapter block pointer.
3898*
3899* Returns:
3900* 0 = success
3901*/
3902int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003903qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003905 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003906 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 struct qla_hw_data *ha = vha->hw;
3908 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003909 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003910 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003913 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914
Andrew Vasquez85880802009-12-15 21:29:46 -08003915 if (unlikely(pci_channel_offline(ha->pdev) &&
3916 ha->flags.pci_channel_io_perm_failure)) {
3917 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3918 status = 0;
3919 return status;
3920 }
3921
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003922 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003924 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003925
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003926 if (!qla2x00_restart_isp(vha)) {
3927 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003929 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003930 /*
3931 * Issue marker command only when we are going
3932 * to start the I/O .
3933 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003934 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003935 }
3936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003937 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003938
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003939 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003940
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003941 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003942 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003943
Lalit Chandivade29c53972009-10-13 15:16:47 -07003944 if (IS_QLA81XX(ha))
3945 qla2x00_get_fw_version(vha,
3946 &ha->fw_major_version,
3947 &ha->fw_minor_version,
3948 &ha->fw_subminor_version,
3949 &ha->fw_attributes, &ha->fw_memory_size,
3950 ha->mpi_version, &ha->mpi_capabilities,
3951 ha->phy_version);
3952
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003953 if (ha->fce) {
3954 ha->flags.fce_enabled = 1;
3955 memset(ha->fce, 0,
3956 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003957 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003958 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3959 &ha->fce_bufs);
3960 if (rval) {
3961 qla_printk(KERN_WARNING, ha,
3962 "Unable to reinitialize FCE "
3963 "(%d).\n", rval);
3964 ha->flags.fce_enabled = 0;
3965 }
3966 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003967
3968 if (ha->eft) {
3969 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003970 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003971 ha->eft_dma, EFT_NUM_BUFFERS);
3972 if (rval) {
3973 qla_printk(KERN_WARNING, ha,
3974 "Unable to reinitialize EFT "
3975 "(%d).\n", rval);
3976 }
3977 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003978 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003979 vha->flags.online = 1;
3980 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003981 if (ha->isp_abort_cnt == 0) {
3982 qla_printk(KERN_WARNING, ha,
3983 "ISP error recovery failed - "
3984 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003985 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003986 * The next call disables the board
3987 * completely.
3988 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 ha->isp_ops->reset_adapter(vha);
3990 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003992 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003993 status = 0;
3994 } else { /* schedule another ISP abort */
3995 ha->isp_abort_cnt--;
3996 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003997 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003998 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999 status = 1;
4000 }
4001 } else {
4002 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
4003 DEBUG(printk("qla2x00(%ld): ISP error recovery "
4004 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004005 vha->host_no, ha->isp_abort_cnt));
4006 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004007 status = 1;
4008 }
4009 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07004010
Linus Torvalds1da177e2005-04-16 15:20:36 -07004011 }
4012
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004013 if (!status) {
4014 DEBUG(printk(KERN_INFO
4015 "qla2x00_abort_isp(%ld): succeeded.\n",
4016 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08004017 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004018 if (vp->vp_idx)
4019 qla2x00_vp_abort_isp(vp);
4020 }
4021 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004022 qla_printk(KERN_INFO, ha,
4023 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004024 }
4025
4026 return(status);
4027}
4028
4029/*
4030* qla2x00_restart_isp
4031* restarts the ISP after a reset
4032*
4033* Input:
4034* ha = adapter block pointer.
4035*
4036* Returns:
4037* 0 = success
4038*/
4039static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004041{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08004042 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004043 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004044 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004045 struct req_que *req = ha->req_q_map[0];
4046 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07004047
4048 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004049 if (qla2x00_isp_firmware(vha)) {
4050 vha->flags.online = 0;
4051 status = ha->isp_ops->chip_diag(vha);
4052 if (!status)
4053 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004054 }
4055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 if (!status && !(status = qla2x00_init_rings(vha))) {
4057 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07004058 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004059 /* Initialize the queues in use */
4060 qla25xx_init_queues(ha);
4061
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062 status = qla2x00_fw_ready(vha);
4063 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004064 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004065 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004066
4067 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004068 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004069
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004070 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004071 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4072 wait_time = 256;
4073 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004074 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4075 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004077 } while (!atomic_read(&vha->loop_down_timer) &&
4078 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
4079 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
4080 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004081 }
4082
4083 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004084 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004085 status = 0;
4086
4087 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
4088 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07004089 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004090 }
4091 return (status);
4092}
4093
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004094static int
4095qla25xx_init_queues(struct qla_hw_data *ha)
4096{
4097 struct rsp_que *rsp = NULL;
4098 struct req_que *req = NULL;
4099 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
4100 int ret = -1;
4101 int i;
4102
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004103 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004104 rsp = ha->rsp_q_map[i];
4105 if (rsp) {
4106 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004107 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004108 if (ret != QLA_SUCCESS)
4109 DEBUG2_17(printk(KERN_WARNING
4110 "%s Rsp que:%d init failed\n", __func__,
4111 rsp->id));
4112 else
4113 DEBUG2_17(printk(KERN_INFO
4114 "%s Rsp que:%d inited\n", __func__,
4115 rsp->id));
4116 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004117 }
4118 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004119 req = ha->req_q_map[i];
4120 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004121 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004122 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08004123 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004124 if (ret != QLA_SUCCESS)
4125 DEBUG2_17(printk(KERN_WARNING
4126 "%s Req que:%d init failed\n", __func__,
4127 req->id));
4128 else
4129 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004130 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004131 req->id));
4132 }
4133 }
4134 return ret;
4135}
4136
Linus Torvalds1da177e2005-04-16 15:20:36 -07004137/*
4138* qla2x00_reset_adapter
4139* Reset adapter.
4140*
4141* Input:
4142* ha = adapter block pointer.
4143*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07004144void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004145qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146{
4147 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07004149 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004150
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004152 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004153
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 spin_lock_irqsave(&ha->hardware_lock, flags);
4155 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
4156 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4157 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
4158 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
4159 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4160}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004161
4162void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004163qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004164{
4165 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004166 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004167 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4168
Giridhar Malavalia9083012010-04-12 17:59:55 -07004169 if (IS_QLA82XX(ha))
4170 return;
4171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004172 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004173 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004174
4175 spin_lock_irqsave(&ha->hardware_lock, flags);
4176 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4177 RD_REG_DWORD(&reg->hccr);
4178 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4179 RD_REG_DWORD(&reg->hccr);
4180 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004181
4182 if (IS_NOPOLLING_TYPE(ha))
4183 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004184}
4185
David Miller4e08df32007-04-16 12:37:43 -07004186/* On sparc systems, obtain port and node WWN from firmware
4187 * properties.
4188 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004189static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4190 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004191{
4192#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004194 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004195 struct device_node *dp = pci_device_to_OF_node(pdev);
4196 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004197 int len;
4198
4199 val = of_get_property(dp, "port-wwn", &len);
4200 if (val && len >= WWN_SIZE)
4201 memcpy(nv->port_name, val, WWN_SIZE);
4202
4203 val = of_get_property(dp, "node-wwn", &len);
4204 if (val && len >= WWN_SIZE)
4205 memcpy(nv->node_name, val, WWN_SIZE);
4206#endif
4207}
4208
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004209int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004210qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004211{
David Miller4e08df32007-04-16 12:37:43 -07004212 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004213 struct init_cb_24xx *icb;
4214 struct nvram_24xx *nv;
4215 uint32_t *dptr;
4216 uint8_t *dptr1, *dptr2;
4217 uint32_t chksum;
4218 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004219 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004220
David Miller4e08df32007-04-16 12:37:43 -07004221 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004222 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004223 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004224
4225 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004226 if (ha->flags.port0) {
4227 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4228 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4229 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004230 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004231 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4232 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004233 ha->nvram_size = sizeof(struct nvram_24xx);
4234 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004235 if (IS_QLA82XX(ha))
4236 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004237
Seokmann Ju281afe12007-07-26 13:43:34 -07004238 /* Get VPD data into cache */
4239 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004240 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004241 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4242
4243 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004244 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004245 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004246 ha->nvram_size);
4247 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4248 chksum += le32_to_cpu(*dptr++);
4249
Andrew Vasquez76403352009-04-06 22:33:39 -07004250 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004251 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004252
4253 /* Bad NVRAM data, set defaults parameters. */
4254 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4255 || nv->id[3] != ' ' ||
4256 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4257 /* Reset NVRAM data. */
4258 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4259 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4260 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004261 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4262 "invalid -- WWPN) defaults.\n");
4263
4264 /*
4265 * Set default initialization control block.
4266 */
4267 memset(nv, 0, ha->nvram_size);
4268 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4269 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4270 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4271 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4272 nv->exchange_count = __constant_cpu_to_le16(0);
4273 nv->hard_address = __constant_cpu_to_le16(124);
4274 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004275 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004276 nv->port_name[2] = 0x00;
4277 nv->port_name[3] = 0xe0;
4278 nv->port_name[4] = 0x8b;
4279 nv->port_name[5] = 0x1c;
4280 nv->port_name[6] = 0x55;
4281 nv->port_name[7] = 0x86;
4282 nv->node_name[0] = 0x20;
4283 nv->node_name[1] = 0x00;
4284 nv->node_name[2] = 0x00;
4285 nv->node_name[3] = 0xe0;
4286 nv->node_name[4] = 0x8b;
4287 nv->node_name[5] = 0x1c;
4288 nv->node_name[6] = 0x55;
4289 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004290 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004291 nv->login_retry_count = __constant_cpu_to_le16(8);
4292 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4293 nv->login_timeout = __constant_cpu_to_le16(0);
4294 nv->firmware_options_1 =
4295 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4296 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4297 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4298 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4299 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4300 nv->efi_parameters = __constant_cpu_to_le32(0);
4301 nv->reset_delay = 5;
4302 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4303 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4304 nv->link_down_timeout = __constant_cpu_to_le16(30);
4305
4306 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004307 }
4308
4309 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004310 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004311
4312 /* Copy 1st segment. */
4313 dptr1 = (uint8_t *)icb;
4314 dptr2 = (uint8_t *)&nv->version;
4315 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4316 while (cnt--)
4317 *dptr1++ = *dptr2++;
4318
4319 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004320 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004321
4322 /* Copy 2nd segment. */
4323 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4324 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4325 cnt = (uint8_t *)&icb->reserved_3 -
4326 (uint8_t *)&icb->interrupt_delay_timer;
4327 while (cnt--)
4328 *dptr1++ = *dptr2++;
4329
4330 /*
4331 * Setup driver NVRAM options.
4332 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004333 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004334 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004335
Andrew Vasquez5341e862006-05-17 15:09:16 -07004336 /* Use alternate WWN? */
4337 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4338 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4339 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4340 }
4341
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004342 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004343 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004344 /*
4345 * Firmware will apply the following mask if the nodename was
4346 * not provided.
4347 */
4348 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4349 icb->node_name[0] &= 0xF0;
4350 }
4351
4352 /* Set host adapter parameters. */
4353 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004354 ha->flags.enable_lip_reset = 0;
4355 ha->flags.enable_lip_full_login =
4356 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4357 ha->flags.enable_target_reset =
4358 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004359 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004360 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004361
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004362 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4363 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004364
4365 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4366 sizeof(ha->fw_seriallink_options24));
4367
4368 /* save HBA serial number */
4369 ha->serial0 = icb->port_name[5];
4370 ha->serial1 = icb->port_name[6];
4371 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004372 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4373 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004374
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004375 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4376
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004377 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4378
4379 /* Set minimum login_timeout to 4 seconds. */
4380 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4381 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4382 if (le16_to_cpu(nv->login_timeout) < 4)
4383 nv->login_timeout = __constant_cpu_to_le16(4);
4384 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004385 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004386
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004387 /* Set minimum RATOV to 100 tenths of a second. */
4388 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004389
4390 ha->loop_reset_delay = nv->reset_delay;
4391
4392 /* Link Down Timeout = 0:
4393 *
4394 * When Port Down timer expires we will start returning
4395 * I/O's to OS with "DID_NO_CONNECT".
4396 *
4397 * Link Down Timeout != 0:
4398 *
4399 * The driver waits for the link to come up after link down
4400 * before returning I/Os to OS with "DID_NO_CONNECT".
4401 */
4402 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4403 ha->loop_down_abort_time =
4404 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4405 } else {
4406 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4407 ha->loop_down_abort_time =
4408 (LOOP_DOWN_TIME - ha->link_down_timeout);
4409 }
4410
4411 /* Need enough time to try and get the port back. */
4412 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4413 if (qlport_down_retry)
4414 ha->port_down_retry_count = qlport_down_retry;
4415
4416 /* Set login_retry_count */
4417 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4418 if (ha->port_down_retry_count ==
4419 le16_to_cpu(nv->port_down_retry_count) &&
4420 ha->port_down_retry_count > 3)
4421 ha->login_retry_count = ha->port_down_retry_count;
4422 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4423 ha->login_retry_count = ha->port_down_retry_count;
4424 if (ql2xloginretrycount)
4425 ha->login_retry_count = ql2xloginretrycount;
4426
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004427 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004428 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004429 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4430 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4431 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4432 le16_to_cpu(icb->interrupt_delay_timer): 2;
4433 }
4434 icb->firmware_options_2 &= __constant_cpu_to_le32(
4435 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004436 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004437 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004438 ha->zio_mode = QLA_ZIO_MODE_6;
4439
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004440 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004441 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004442 ha->zio_timer * 100));
4443 qla_printk(KERN_INFO, ha,
4444 "ZIO mode %d enabled; timer delay (%d us).\n",
4445 ha->zio_mode, ha->zio_timer * 100);
4446
4447 icb->firmware_options_2 |= cpu_to_le32(
4448 (uint32_t)ha->zio_mode);
4449 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004450 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004451 }
4452
David Miller4e08df32007-04-16 12:37:43 -07004453 if (rval) {
4454 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004455 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004456 }
4457 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004458}
4459
Adrian Bunk413975a2006-06-30 02:33:06 -07004460static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004461qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4462 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004463{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004464 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004465 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004466 uint32_t *dcode, dlen;
4467 uint32_t risc_addr;
4468 uint32_t risc_size;
4469 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004470 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004471 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004472
4473 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004474 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004475
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004476 rval = QLA_SUCCESS;
4477
4478 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004479 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004480 *srisc_addr = 0;
4481
4482 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004483 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004484 for (i = 0; i < 4; i++)
4485 dcode[i] = be32_to_cpu(dcode[i]);
4486 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4487 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4488 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4489 dcode[3] == 0)) {
4490 qla_printk(KERN_WARNING, ha,
4491 "Unable to verify integrity of flash firmware image!\n");
4492 qla_printk(KERN_WARNING, ha,
4493 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4494 dcode[1], dcode[2], dcode[3]);
4495
4496 return QLA_FUNCTION_FAILED;
4497 }
4498
4499 while (segments && rval == QLA_SUCCESS) {
4500 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004501 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004502
4503 risc_addr = be32_to_cpu(dcode[2]);
4504 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4505 risc_size = be32_to_cpu(dcode[3]);
4506
4507 fragment = 0;
4508 while (risc_size > 0 && rval == QLA_SUCCESS) {
4509 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4510 if (dlen > risc_size)
4511 dlen = risc_size;
4512
4513 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4514 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004515 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004517 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004518 for (i = 0; i < dlen; i++)
4519 dcode[i] = swab32(dcode[i]);
4520
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004521 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004522 dlen);
4523 if (rval) {
4524 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004525 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004526 fragment));
4527 qla_printk(KERN_WARNING, ha,
4528 "[ERROR] Failed to load segment %d of "
4529 "firmware\n", fragment);
4530 break;
4531 }
4532
4533 faddr += dlen;
4534 risc_addr += dlen;
4535 risc_size -= dlen;
4536 fragment++;
4537 }
4538
4539 /* Next segment. */
4540 segments--;
4541 }
4542
4543 return rval;
4544}
4545
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004546#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4547
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004548int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004549qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004550{
4551 int rval;
4552 int i, fragment;
4553 uint16_t *wcode, *fwcode;
4554 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4555 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004556 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004557 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004558
4559 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004560 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004561 if (!blob) {
4562 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004563 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4564 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004565 return QLA_FUNCTION_FAILED;
4566 }
4567
4568 rval = QLA_SUCCESS;
4569
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004570 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004571 *srisc_addr = 0;
4572 fwcode = (uint16_t *)blob->fw->data;
4573 fwclen = 0;
4574
4575 /* Validate firmware image by checking version. */
4576 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4577 qla_printk(KERN_WARNING, ha,
4578 "Unable to verify integrity of firmware image (%Zd)!\n",
4579 blob->fw->size);
4580 goto fail_fw_integrity;
4581 }
4582 for (i = 0; i < 4; i++)
4583 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4584 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4585 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4586 wcode[2] == 0 && wcode[3] == 0)) {
4587 qla_printk(KERN_WARNING, ha,
4588 "Unable to verify integrity of firmware image!\n");
4589 qla_printk(KERN_WARNING, ha,
4590 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4591 wcode[1], wcode[2], wcode[3]);
4592 goto fail_fw_integrity;
4593 }
4594
4595 seg = blob->segs;
4596 while (*seg && rval == QLA_SUCCESS) {
4597 risc_addr = *seg;
4598 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4599 risc_size = be16_to_cpu(fwcode[3]);
4600
4601 /* Validate firmware image size. */
4602 fwclen += risc_size * sizeof(uint16_t);
4603 if (blob->fw->size < fwclen) {
4604 qla_printk(KERN_WARNING, ha,
4605 "Unable to verify integrity of firmware image "
4606 "(%Zd)!\n", blob->fw->size);
4607 goto fail_fw_integrity;
4608 }
4609
4610 fragment = 0;
4611 while (risc_size > 0 && rval == QLA_SUCCESS) {
4612 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4613 if (wlen > risc_size)
4614 wlen = risc_size;
4615
4616 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004617 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004618 risc_addr, wlen));
4619
4620 for (i = 0; i < wlen; i++)
4621 wcode[i] = swab16(fwcode[i]);
4622
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004623 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004624 wlen);
4625 if (rval) {
4626 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004627 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004628 fragment));
4629 qla_printk(KERN_WARNING, ha,
4630 "[ERROR] Failed to load segment %d of "
4631 "firmware\n", fragment);
4632 break;
4633 }
4634
4635 fwcode += wlen;
4636 risc_addr += wlen;
4637 risc_size -= wlen;
4638 fragment++;
4639 }
4640
4641 /* Next segment. */
4642 seg++;
4643 }
4644 return rval;
4645
4646fail_fw_integrity:
4647 return QLA_FUNCTION_FAILED;
4648}
4649
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004650static int
4651qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004652{
4653 int rval;
4654 int segments, fragment;
4655 uint32_t *dcode, dlen;
4656 uint32_t risc_addr;
4657 uint32_t risc_size;
4658 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004659 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004660 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004661 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004662 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004663
Andrew Vasquez54333832005-11-09 15:49:04 -08004664 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004665 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004666 if (!blob) {
4667 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004668 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4669 "from: " QLA_FW_URL ".\n");
4670
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004671 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004672 }
4673
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004674 qla_printk(KERN_INFO, ha,
4675 "FW: Loading via request-firmware...\n");
4676
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004677 rval = QLA_SUCCESS;
4678
4679 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004680 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004681 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004682 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004683 fwclen = 0;
4684
4685 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004686 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004687 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004688 "Unable to verify integrity of firmware image (%Zd)!\n",
4689 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004690 goto fail_fw_integrity;
4691 }
4692 for (i = 0; i < 4; i++)
4693 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4694 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4695 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4696 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4697 dcode[3] == 0)) {
4698 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004699 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004700 qla_printk(KERN_WARNING, ha,
4701 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4702 dcode[1], dcode[2], dcode[3]);
4703 goto fail_fw_integrity;
4704 }
4705
4706 while (segments && rval == QLA_SUCCESS) {
4707 risc_addr = be32_to_cpu(fwcode[2]);
4708 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4709 risc_size = be32_to_cpu(fwcode[3]);
4710
4711 /* Validate firmware image size. */
4712 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004713 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004714 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004715 "Unable to verify integrity of firmware image "
4716 "(%Zd)!\n", blob->fw->size);
4717
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004718 goto fail_fw_integrity;
4719 }
4720
4721 fragment = 0;
4722 while (risc_size > 0 && rval == QLA_SUCCESS) {
4723 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4724 if (dlen > risc_size)
4725 dlen = risc_size;
4726
4727 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004728 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004729 risc_addr, dlen));
4730
4731 for (i = 0; i < dlen; i++)
4732 dcode[i] = swab32(fwcode[i]);
4733
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004734 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004735 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004736 if (rval) {
4737 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004738 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004739 fragment));
4740 qla_printk(KERN_WARNING, ha,
4741 "[ERROR] Failed to load segment %d of "
4742 "firmware\n", fragment);
4743 break;
4744 }
4745
4746 fwcode += dlen;
4747 risc_addr += dlen;
4748 risc_size -= dlen;
4749 fragment++;
4750 }
4751
4752 /* Next segment. */
4753 segments--;
4754 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004755 return rval;
4756
4757fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004758 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004759}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004760
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004761int
4762qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4763{
4764 int rval;
4765
Andrew Vasqueze337d902009-04-06 22:33:49 -07004766 if (ql2xfwloadbin == 1)
4767 return qla81xx_load_risc(vha, srisc_addr);
4768
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004769 /*
4770 * FW Load priority:
4771 * 1) Firmware via request-firmware interface (.bin file).
4772 * 2) Firmware residing in flash.
4773 */
4774 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4775 if (rval == QLA_SUCCESS)
4776 return rval;
4777
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004778 return qla24xx_load_risc_flash(vha, srisc_addr,
4779 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004780}
4781
4782int
4783qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4784{
4785 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004786 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004787
Andrew Vasqueze337d902009-04-06 22:33:49 -07004788 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004789 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004790
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004791 /*
4792 * FW Load priority:
4793 * 1) Firmware residing in flash.
4794 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004795 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004796 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004797 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004798 if (rval == QLA_SUCCESS)
4799 return rval;
4800
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004801try_blob_fw:
4802 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4803 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4804 return rval;
4805
4806 qla_printk(KERN_ERR, ha,
4807 "FW: Attempting to fallback to golden firmware...\n");
4808 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4809 if (rval != QLA_SUCCESS)
4810 return rval;
4811
4812 qla_printk(KERN_ERR, ha,
4813 "FW: Please update operational firmware...\n");
4814 ha->flags.running_gold_fw = 1;
4815
4816 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004817}
4818
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004819void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004820qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004821{
4822 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004823 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004824
Andrew Vasquez85880802009-12-15 21:29:46 -08004825 if (ha->flags.pci_channel_io_perm_failure)
4826 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004827 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004828 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004829 if (!ha->fw_major_version)
4830 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004831
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004832 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004833 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004834 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004835 ha->isp_ops->reset_chip(vha);
4836 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004837 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004838 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004839 continue;
4840 qla_printk(KERN_INFO, ha,
4841 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004842 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004843 }
4844}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004845
4846int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004847qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004848{
4849 int rval = QLA_SUCCESS;
4850 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004851 struct qla_hw_data *ha = vha->hw;
4852 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004853 struct req_que *req;
4854 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004856 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004857 return -EINVAL;
4858
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004859 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004860 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004861 req = ha->req_q_map[0];
4862 else
4863 req = vha->req;
4864 rsp = req->rsp;
4865
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004866 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004867 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004868 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004869 }
4870
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004871 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004872
4873 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004874 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004875 if (mb[0] != MBS_COMMAND_COMPLETE) {
4876 DEBUG15(qla_printk(KERN_INFO, ha,
4877 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4878 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4879 mb[0], mb[1], mb[2], mb[6], mb[7]));
4880 return (QLA_FUNCTION_FAILED);
4881 }
4882
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004883 atomic_set(&vha->loop_down_timer, 0);
4884 atomic_set(&vha->loop_state, LOOP_UP);
4885 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4886 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4887 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004888
4889 return rval;
4890}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004891
4892/* 84XX Support **************************************************************/
4893
4894static LIST_HEAD(qla_cs84xx_list);
4895static DEFINE_MUTEX(qla_cs84xx_mutex);
4896
4897static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004898qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004899{
4900 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004901 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004902
4903 mutex_lock(&qla_cs84xx_mutex);
4904
4905 /* Find any shared 84xx chip. */
4906 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4907 if (cs84xx->bus == ha->pdev->bus) {
4908 kref_get(&cs84xx->kref);
4909 goto done;
4910 }
4911 }
4912
4913 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4914 if (!cs84xx)
4915 goto done;
4916
4917 kref_init(&cs84xx->kref);
4918 spin_lock_init(&cs84xx->access_lock);
4919 mutex_init(&cs84xx->fw_update_mutex);
4920 cs84xx->bus = ha->pdev->bus;
4921
4922 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4923done:
4924 mutex_unlock(&qla_cs84xx_mutex);
4925 return cs84xx;
4926}
4927
4928static void
4929__qla84xx_chip_release(struct kref *kref)
4930{
4931 struct qla_chip_state_84xx *cs84xx =
4932 container_of(kref, struct qla_chip_state_84xx, kref);
4933
4934 mutex_lock(&qla_cs84xx_mutex);
4935 list_del(&cs84xx->list);
4936 mutex_unlock(&qla_cs84xx_mutex);
4937 kfree(cs84xx);
4938}
4939
4940void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004941qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004942{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004943 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004944 if (ha->cs84xx)
4945 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4946}
4947
4948static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004949qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004950{
4951 int rval;
4952 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004953 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004954
4955 mutex_lock(&ha->cs84xx->fw_update_mutex);
4956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004957 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004958
4959 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4960
4961 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4962 QLA_SUCCESS;
4963}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004964
4965/* 81XX Support **************************************************************/
4966
4967int
4968qla81xx_nvram_config(scsi_qla_host_t *vha)
4969{
4970 int rval;
4971 struct init_cb_81xx *icb;
4972 struct nvram_81xx *nv;
4973 uint32_t *dptr;
4974 uint8_t *dptr1, *dptr2;
4975 uint32_t chksum;
4976 uint16_t cnt;
4977 struct qla_hw_data *ha = vha->hw;
4978
4979 rval = QLA_SUCCESS;
4980 icb = (struct init_cb_81xx *)ha->init_cb;
4981 nv = ha->nvram;
4982
4983 /* Determine NVRAM starting address. */
4984 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004985 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004986
4987 /* Get VPD data into cache */
4988 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004989 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4990 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004991
4992 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004993 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004994 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004995 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004996 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4997 chksum += le32_to_cpu(*dptr++);
4998
Andrew Vasquez76403352009-04-06 22:33:39 -07004999 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005000 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
5001
5002 /* Bad NVRAM data, set defaults parameters. */
5003 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
5004 || nv->id[3] != ' ' ||
5005 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
5006 /* Reset NVRAM data. */
5007 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
5008 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
5009 le16_to_cpu(nv->nvram_version));
5010 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
5011 "invalid -- WWPN) defaults.\n");
5012
5013 /*
5014 * Set default initialization control block.
5015 */
5016 memset(nv, 0, ha->nvram_size);
5017 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
5018 nv->version = __constant_cpu_to_le16(ICB_VERSION);
5019 nv->frame_payload_size = __constant_cpu_to_le16(2048);
5020 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5021 nv->exchange_count = __constant_cpu_to_le16(0);
5022 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005023 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005024 nv->port_name[2] = 0x00;
5025 nv->port_name[3] = 0xe0;
5026 nv->port_name[4] = 0x8b;
5027 nv->port_name[5] = 0x1c;
5028 nv->port_name[6] = 0x55;
5029 nv->port_name[7] = 0x86;
5030 nv->node_name[0] = 0x20;
5031 nv->node_name[1] = 0x00;
5032 nv->node_name[2] = 0x00;
5033 nv->node_name[3] = 0xe0;
5034 nv->node_name[4] = 0x8b;
5035 nv->node_name[5] = 0x1c;
5036 nv->node_name[6] = 0x55;
5037 nv->node_name[7] = 0x86;
5038 nv->login_retry_count = __constant_cpu_to_le16(8);
5039 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
5040 nv->login_timeout = __constant_cpu_to_le16(0);
5041 nv->firmware_options_1 =
5042 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
5043 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
5044 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
5045 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
5046 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
5047 nv->efi_parameters = __constant_cpu_to_le32(0);
5048 nv->reset_delay = 5;
5049 nv->max_luns_per_target = __constant_cpu_to_le16(128);
5050 nv->port_down_retry_count = __constant_cpu_to_le16(30);
5051 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07005052 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005053 nv->enode_mac[1] = 0x02;
5054 nv->enode_mac[2] = 0x03;
5055 nv->enode_mac[3] = 0x04;
5056 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005057 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005058
5059 rval = 1;
5060 }
5061
5062 /* Reset Initialization control block */
5063 memset(icb, 0, sizeof(struct init_cb_81xx));
5064
5065 /* Copy 1st segment. */
5066 dptr1 = (uint8_t *)icb;
5067 dptr2 = (uint8_t *)&nv->version;
5068 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
5069 while (cnt--)
5070 *dptr1++ = *dptr2++;
5071
5072 icb->login_retry_count = nv->login_retry_count;
5073
5074 /* Copy 2nd segment. */
5075 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
5076 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
5077 cnt = (uint8_t *)&icb->reserved_5 -
5078 (uint8_t *)&icb->interrupt_delay_timer;
5079 while (cnt--)
5080 *dptr1++ = *dptr2++;
5081
5082 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
5083 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5084 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
5085 icb->enode_mac[0] = 0x01;
5086 icb->enode_mac[1] = 0x02;
5087 icb->enode_mac[2] = 0x03;
5088 icb->enode_mac[3] = 0x04;
5089 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07005090 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005091 }
5092
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07005093 /* Use extended-initialization control block. */
5094 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
5095
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005096 /*
5097 * Setup driver NVRAM options.
5098 */
5099 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07005100 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005101
5102 /* Use alternate WWN? */
5103 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
5104 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
5105 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
5106 }
5107
5108 /* Prepare nodename */
5109 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
5110 /*
5111 * Firmware will apply the following mask if the nodename was
5112 * not provided.
5113 */
5114 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
5115 icb->node_name[0] &= 0xF0;
5116 }
5117
5118 /* Set host adapter parameters. */
5119 ha->flags.disable_risc_code_load = 0;
5120 ha->flags.enable_lip_reset = 0;
5121 ha->flags.enable_lip_full_login =
5122 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
5123 ha->flags.enable_target_reset =
5124 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
5125 ha->flags.enable_led_scheme = 0;
5126 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
5127
5128 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
5129 (BIT_6 | BIT_5 | BIT_4)) >> 4;
5130
5131 /* save HBA serial number */
5132 ha->serial0 = icb->port_name[5];
5133 ha->serial1 = icb->port_name[6];
5134 ha->serial2 = icb->port_name[7];
5135 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
5136 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
5137
5138 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
5139
5140 ha->retry_count = le16_to_cpu(nv->login_retry_count);
5141
5142 /* Set minimum login_timeout to 4 seconds. */
5143 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
5144 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
5145 if (le16_to_cpu(nv->login_timeout) < 4)
5146 nv->login_timeout = __constant_cpu_to_le16(4);
5147 ha->login_timeout = le16_to_cpu(nv->login_timeout);
5148 icb->login_timeout = nv->login_timeout;
5149
5150 /* Set minimum RATOV to 100 tenths of a second. */
5151 ha->r_a_tov = 100;
5152
5153 ha->loop_reset_delay = nv->reset_delay;
5154
5155 /* Link Down Timeout = 0:
5156 *
5157 * When Port Down timer expires we will start returning
5158 * I/O's to OS with "DID_NO_CONNECT".
5159 *
5160 * Link Down Timeout != 0:
5161 *
5162 * The driver waits for the link to come up after link down
5163 * before returning I/Os to OS with "DID_NO_CONNECT".
5164 */
5165 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5166 ha->loop_down_abort_time =
5167 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5168 } else {
5169 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5170 ha->loop_down_abort_time =
5171 (LOOP_DOWN_TIME - ha->link_down_timeout);
5172 }
5173
5174 /* Need enough time to try and get the port back. */
5175 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5176 if (qlport_down_retry)
5177 ha->port_down_retry_count = qlport_down_retry;
5178
5179 /* Set login_retry_count */
5180 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5181 if (ha->port_down_retry_count ==
5182 le16_to_cpu(nv->port_down_retry_count) &&
5183 ha->port_down_retry_count > 3)
5184 ha->login_retry_count = ha->port_down_retry_count;
5185 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5186 ha->login_retry_count = ha->port_down_retry_count;
5187 if (ql2xloginretrycount)
5188 ha->login_retry_count = ql2xloginretrycount;
5189
5190 /* Enable ZIO. */
5191 if (!vha->flags.init_done) {
5192 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5193 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5194 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5195 le16_to_cpu(icb->interrupt_delay_timer): 2;
5196 }
5197 icb->firmware_options_2 &= __constant_cpu_to_le32(
5198 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5199 vha->flags.process_response_queue = 0;
5200 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5201 ha->zio_mode = QLA_ZIO_MODE_6;
5202
5203 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5204 "(%d us).\n", vha->host_no, ha->zio_mode,
5205 ha->zio_timer * 100));
5206 qla_printk(KERN_INFO, ha,
5207 "ZIO mode %d enabled; timer delay (%d us).\n",
5208 ha->zio_mode, ha->zio_timer * 100);
5209
5210 icb->firmware_options_2 |= cpu_to_le32(
5211 (uint32_t)ha->zio_mode);
5212 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5213 vha->flags.process_response_queue = 1;
5214 }
5215
5216 if (rval) {
5217 DEBUG2_3(printk(KERN_WARNING
5218 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5219 }
5220 return (rval);
5221}
5222
Giridhar Malavalia9083012010-04-12 17:59:55 -07005223int
5224qla82xx_restart_isp(scsi_qla_host_t *vha)
5225{
5226 int status, rval;
5227 uint32_t wait_time;
5228 struct qla_hw_data *ha = vha->hw;
5229 struct req_que *req = ha->req_q_map[0];
5230 struct rsp_que *rsp = ha->rsp_q_map[0];
5231 struct scsi_qla_host *vp;
5232 struct scsi_qla_host *tvp;
5233
5234 status = qla2x00_init_rings(vha);
5235 if (!status) {
5236 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5237 ha->flags.chip_reset_done = 1;
5238
5239 status = qla2x00_fw_ready(vha);
5240 if (!status) {
5241 qla_printk(KERN_INFO, ha,
5242 "%s(): Start configure loop, "
5243 "status = %d\n", __func__, status);
5244
5245 /* Issue a marker after FW becomes ready. */
5246 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5247
5248 vha->flags.online = 1;
5249 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5250 wait_time = 256;
5251 do {
5252 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5253 qla2x00_configure_loop(vha);
5254 wait_time--;
5255 } while (!atomic_read(&vha->loop_down_timer) &&
5256 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5257 wait_time &&
5258 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5259 }
5260
5261 /* if no cable then assume it's good */
5262 if ((vha->device_flags & DFLG_NO_CABLE))
5263 status = 0;
5264
5265 qla_printk(KERN_INFO, ha,
5266 "%s(): Configure loop done, status = 0x%x\n",
5267 __func__, status);
5268 }
5269
5270 if (!status) {
5271 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5272
5273 if (!atomic_read(&vha->loop_down_timer)) {
5274 /*
5275 * Issue marker command only when we are going
5276 * to start the I/O .
5277 */
5278 vha->marker_needed = 1;
5279 }
5280
5281 vha->flags.online = 1;
5282
5283 ha->isp_ops->enable_intrs(ha);
5284
5285 ha->isp_abort_cnt = 0;
5286 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5287
5288 if (ha->fce) {
5289 ha->flags.fce_enabled = 1;
5290 memset(ha->fce, 0,
5291 fce_calc_size(ha->fce_bufs));
5292 rval = qla2x00_enable_fce_trace(vha,
5293 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5294 &ha->fce_bufs);
5295 if (rval) {
5296 qla_printk(KERN_WARNING, ha,
5297 "Unable to reinitialize FCE "
5298 "(%d).\n", rval);
5299 ha->flags.fce_enabled = 0;
5300 }
5301 }
5302
5303 if (ha->eft) {
5304 memset(ha->eft, 0, EFT_SIZE);
5305 rval = qla2x00_enable_eft_trace(vha,
5306 ha->eft_dma, EFT_NUM_BUFFERS);
5307 if (rval) {
5308 qla_printk(KERN_WARNING, ha,
5309 "Unable to reinitialize EFT "
5310 "(%d).\n", rval);
5311 }
5312 }
Giridhar Malavalia9083012010-04-12 17:59:55 -07005313 }
5314
5315 if (!status) {
5316 DEBUG(printk(KERN_INFO
5317 "qla82xx_restart_isp(%ld): succeeded.\n",
5318 vha->host_no));
5319 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5320 if (vp->vp_idx)
5321 qla2x00_vp_abort_isp(vp);
5322 }
5323 } else {
5324 qla_printk(KERN_INFO, ha,
5325 "qla82xx_restart_isp: **** FAILED ****\n");
5326 }
5327
5328 return status;
5329}
5330
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005331void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005332qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005333{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005334 struct qla_hw_data *ha = vha->hw;
5335
5336 if (!ql2xetsenable)
5337 return;
5338
5339 /* Enable ETS Burst. */
5340 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5341 ha->fw_options[2] |= BIT_9;
5342 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005343}
Sarang Radke09ff7012010-03-19 17:03:59 -07005344
5345/*
5346 * qla24xx_get_fcp_prio
5347 * Gets the fcp cmd priority value for the logged in port.
5348 * Looks for a match of the port descriptors within
5349 * each of the fcp prio config entries. If a match is found,
5350 * the tag (priority) value is returned.
5351 *
5352 * Input:
5353 * ha = adapter block po
5354 * fcport = port structure pointer.
5355 *
5356 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005357 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005358 * 0 (if not found)
5359 *
5360 * Context:
5361 * Kernel context
5362 */
5363uint8_t
5364qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5365{
5366 int i, entries;
5367 uint8_t pid_match, wwn_match;
5368 uint8_t priority;
5369 uint32_t pid1, pid2;
5370 uint64_t wwn1, wwn2;
5371 struct qla_fcp_prio_entry *pri_entry;
5372 struct qla_hw_data *ha = vha->hw;
5373
5374 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5375 return 0;
5376
5377 priority = 0;
5378 entries = ha->fcp_prio_cfg->num_entries;
5379 pri_entry = &ha->fcp_prio_cfg->entry[0];
5380
5381 for (i = 0; i < entries; i++) {
5382 pid_match = wwn_match = 0;
5383
5384 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5385 pri_entry++;
5386 continue;
5387 }
5388
5389 /* check source pid for a match */
5390 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5391 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5392 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5393 if (pid1 == INVALID_PORT_ID)
5394 pid_match++;
5395 else if (pid1 == pid2)
5396 pid_match++;
5397 }
5398
5399 /* check destination pid for a match */
5400 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5401 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5402 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5403 if (pid1 == INVALID_PORT_ID)
5404 pid_match++;
5405 else if (pid1 == pid2)
5406 pid_match++;
5407 }
5408
5409 /* check source WWN for a match */
5410 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5411 wwn1 = wwn_to_u64(vha->port_name);
5412 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5413 if (wwn2 == (uint64_t)-1)
5414 wwn_match++;
5415 else if (wwn1 == wwn2)
5416 wwn_match++;
5417 }
5418
5419 /* check destination WWN for a match */
5420 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5421 wwn1 = wwn_to_u64(fcport->port_name);
5422 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5423 if (wwn2 == (uint64_t)-1)
5424 wwn_match++;
5425 else if (wwn1 == wwn2)
5426 wwn_match++;
5427 }
5428
5429 if (pid_match == 2 || wwn_match == 2) {
5430 /* Found a matching entry */
5431 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5432 priority = pri_entry->tag;
5433 break;
5434 }
5435
5436 pri_entry++;
5437 }
5438
5439 return priority;
5440}
5441
5442/*
5443 * qla24xx_update_fcport_fcp_prio
5444 * Activates fcp priority for the logged in fc port
5445 *
5446 * Input:
5447 * ha = adapter block pointer.
5448 * fcp = port structure pointer.
5449 *
5450 * Return:
5451 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5452 *
5453 * Context:
5454 * Kernel context.
5455 */
5456int
5457qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5458{
5459 int ret;
5460 uint8_t priority;
5461 uint16_t mb[5];
5462
5463 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5464 fcport->port_type != FCT_TARGET ||
5465 fcport->loop_id == FC_NO_LOOP_ID)
5466 return QLA_FUNCTION_FAILED;
5467
5468 priority = qla24xx_get_fcp_prio(ha, fcport);
5469 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5470 if (ret == QLA_SUCCESS)
5471 fcport->fcp_prio = priority;
5472 else
5473 DEBUG2(printk(KERN_WARNING
5474 "scsi(%ld): Unable to activate fcp priority, "
5475 " ret=0x%x\n", ha->host_no, ret));
5476
5477 return ret;
5478}
5479
5480/*
5481 * qla24xx_update_all_fcp_prio
5482 * Activates fcp priority for all the logged in ports
5483 *
5484 * Input:
5485 * ha = adapter block pointer.
5486 *
5487 * Return:
5488 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5489 *
5490 * Context:
5491 * Kernel context.
5492 */
5493int
5494qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5495{
5496 int ret;
5497 fc_port_t *fcport;
5498
5499 ret = QLA_FUNCTION_FAILED;
5500 /* We need to set priority for all logged in ports */
5501 list_for_each_entry(fcport, &vha->vp_fcports, list)
5502 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5503
5504 return ret;
5505}