blob: 72b4ef2701584b111a4e6f5d28a35851a0c4bccc [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090011#include <linux/slab.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070012#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
14#include "qla_devtbl.h"
15
David Miller4e08df32007-04-16 12:37:43 -070016#ifdef CONFIG_SPARC
17#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070018#endif
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020/*
21* QLogic ISP2x00 Hardware Support Function Prototypes.
22*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Andrew Vasquezac280b62009-08-20 11:06:05 -070044/* SRB Extensions ---------------------------------------------------------- */
45
46static void
47qla2x00_ctx_sp_timeout(unsigned long __data)
48{
49 srb_t *sp = (srb_t *)__data;
50 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070051 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070052 fc_port_t *fcport = sp->fcport;
53 struct qla_hw_data *ha = fcport->vha->hw;
54 struct req_que *req;
55 unsigned long flags;
56
57 spin_lock_irqsave(&ha->hardware_lock, flags);
58 req = ha->req_q_map[0];
59 req->outstanding_cmds[sp->handle] = NULL;
60 ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070061 iocb = ctx->u.iocb_cmd;
62 iocb->timeout(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070063 spin_unlock_irqrestore(&ha->hardware_lock, flags);
64
Madhuranath Iyengar49163922010-05-04 15:01:28 -070065 iocb->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -070066}
67
Giridhar Malavali9a069e12010-01-12 13:02:47 -080068void
Andrew Vasquezac280b62009-08-20 11:06:05 -070069qla2x00_ctx_sp_free(srb_t *sp)
70{
71 struct srb_ctx *ctx = sp->ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070072 struct srb_iocb *iocb = ctx->u.iocb_cmd;
Andrew Vasquezac280b62009-08-20 11:06:05 -070073
Madhuranath Iyengar49163922010-05-04 15:01:28 -070074 del_timer_sync(&iocb->timer);
75 kfree(iocb);
Andrew Vasquezac280b62009-08-20 11:06:05 -070076 kfree(ctx);
77 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
78}
79
80inline srb_t *
81qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
82 unsigned long tmo)
83{
84 srb_t *sp;
85 struct qla_hw_data *ha = vha->hw;
86 struct srb_ctx *ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -070087 struct srb_iocb *iocb;
Andrew Vasquezac280b62009-08-20 11:06:05 -070088
89 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
90 if (!sp)
91 goto done;
92 ctx = kzalloc(size, GFP_KERNEL);
93 if (!ctx) {
94 mempool_free(sp, ha->srb_mempool);
Madhuranath Iyengar49163922010-05-04 15:01:28 -070095 sp = NULL;
96 goto done;
97 }
98 iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL);
99 if (!iocb) {
100 mempool_free(sp, ha->srb_mempool);
101 sp = NULL;
102 kfree(ctx);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700103 goto done;
104 }
105
106 memset(sp, 0, sizeof(*sp));
107 sp->fcport = fcport;
108 sp->ctx = ctx;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700109 ctx->u.iocb_cmd = iocb;
110 iocb->free = qla2x00_ctx_sp_free;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700111
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700112 init_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700113 if (!tmo)
114 goto done;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700115 iocb->timer.expires = jiffies + tmo * HZ;
116 iocb->timer.data = (unsigned long)sp;
117 iocb->timer.function = qla2x00_ctx_sp_timeout;
118 add_timer(&iocb->timer);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700119done:
120 return sp;
121}
122
123/* Asynchronous Login/Logout Routines -------------------------------------- */
124
125#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
126
127static void
128qla2x00_async_logio_timeout(srb_t *sp)
129{
130 fc_port_t *fcport = sp->fcport;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700131 struct srb_ctx *ctx = sp->ctx;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700132
133 DEBUG2(printk(KERN_WARNING
134 "scsi(%ld:%x): Async-%s timeout.\n",
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700135 fcport->vha->host_no, sp->handle, ctx->name));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700136
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700137 fcport->flags &= ~FCF_ASYNC_SENT;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700138 if (ctx->type == SRB_LOGIN_CMD)
Andrew Vasquezac280b62009-08-20 11:06:05 -0700139 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
140}
141
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700142static void
143qla2x00_async_login_ctx_done(srb_t *sp)
144{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700145 struct srb_ctx *ctx = sp->ctx;
146 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700147
148 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700149 lio->u.logio.data);
150 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700151}
152
Andrew Vasquezac280b62009-08-20 11:06:05 -0700153int
154qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
155 uint16_t *data)
156{
157 struct qla_hw_data *ha = vha->hw;
158 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700159 struct srb_ctx *ctx;
160 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700161 int rval;
162
163 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700164 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700165 ELS_TMO_2_RATOV(ha) + 2);
166 if (!sp)
167 goto done;
168
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700169 ctx = sp->ctx;
170 ctx->type = SRB_LOGIN_CMD;
171 ctx->name = "login";
172 lio = ctx->u.iocb_cmd;
173 lio->timeout = qla2x00_async_logio_timeout;
174 lio->done = qla2x00_async_login_ctx_done;
175 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700176 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700177 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700178 rval = qla2x00_start_sp(sp);
179 if (rval != QLA_SUCCESS)
180 goto done_free_sp;
181
182 DEBUG2(printk(KERN_DEBUG
183 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
184 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
185 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
186 fcport->login_retry));
187 return rval;
188
189done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700190 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700191done:
192 return rval;
193}
194
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700195static void
196qla2x00_async_logout_ctx_done(srb_t *sp)
197{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700198 struct srb_ctx *ctx = sp->ctx;
199 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700200
201 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700202 lio->u.logio.data);
203 lio->free(sp);
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700204}
205
Andrew Vasquezac280b62009-08-20 11:06:05 -0700206int
207qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
208{
209 struct qla_hw_data *ha = vha->hw;
210 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700211 struct srb_ctx *ctx;
212 struct srb_iocb *lio;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700213 int rval;
214
215 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700216 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquezac280b62009-08-20 11:06:05 -0700217 ELS_TMO_2_RATOV(ha) + 2);
218 if (!sp)
219 goto done;
220
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700221 ctx = sp->ctx;
222 ctx->type = SRB_LOGOUT_CMD;
223 ctx->name = "logout";
224 lio = ctx->u.iocb_cmd;
225 lio->timeout = qla2x00_async_logio_timeout;
226 lio->done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700227 rval = qla2x00_start_sp(sp);
228 if (rval != QLA_SUCCESS)
229 goto done_free_sp;
230
231 DEBUG2(printk(KERN_DEBUG
232 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
233 fcport->vha->host_no, sp->handle, fcport->loop_id,
234 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
235 return rval;
236
237done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700238 lio->free(sp);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700239done:
240 return rval;
241}
242
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700243static void
244qla2x00_async_adisc_ctx_done(srb_t *sp)
245{
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700246 struct srb_ctx *ctx = sp->ctx;
247 struct srb_iocb *lio = ctx->u.iocb_cmd;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700248
249 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700250 lio->u.logio.data);
251 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700252}
253
254int
255qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
256 uint16_t *data)
257{
258 struct qla_hw_data *ha = vha->hw;
259 srb_t *sp;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700260 struct srb_ctx *ctx;
261 struct srb_iocb *lio;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700262 int rval;
263
264 rval = QLA_FUNCTION_FAILED;
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700265 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx),
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700266 ELS_TMO_2_RATOV(ha) + 2);
267 if (!sp)
268 goto done;
269
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700270 ctx = sp->ctx;
271 ctx->type = SRB_ADISC_CMD;
272 ctx->name = "adisc";
273 lio = ctx->u.iocb_cmd;
274 lio->timeout = qla2x00_async_logio_timeout;
275 lio->done = qla2x00_async_adisc_ctx_done;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700276 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700277 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700278 rval = qla2x00_start_sp(sp);
279 if (rval != QLA_SUCCESS)
280 goto done_free_sp;
281
282 DEBUG2(printk(KERN_DEBUG
283 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
284 fcport->vha->host_no, sp->handle, fcport->loop_id,
285 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
286
287 return rval;
288
289done_free_sp:
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700290 lio->free(sp);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700291done:
292 return rval;
293}
294
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700295void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700296qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
297 uint16_t *data)
298{
299 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700300
301 switch (data[0]) {
302 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700303 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700304 fcport->flags |= FCF_ASYNC_SENT;
305 qla2x00_post_async_adisc_work(vha, fcport, data);
306 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700307 }
308 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700309 break;
310 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700311 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700312 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
313 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
314 else
315 qla2x00_mark_device_lost(vha, fcport, 1, 0);
316 break;
317 case MBS_PORT_ID_USED:
318 fcport->loop_id = data[1];
319 qla2x00_post_async_login_work(vha, fcport, NULL);
320 break;
321 case MBS_LOOP_ID_USED:
322 fcport->loop_id++;
323 rval = qla2x00_find_new_loop_id(vha, fcport);
324 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700325 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700326 qla2x00_mark_device_lost(vha, fcport, 1, 0);
327 break;
328 }
329 qla2x00_post_async_login_work(vha, fcport, NULL);
330 break;
331 }
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700332 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700333}
334
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700335void
Andrew Vasquezac280b62009-08-20 11:06:05 -0700336qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
337 uint16_t *data)
338{
339 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700340 return;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700341}
342
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700343void
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700344qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
345 uint16_t *data)
346{
347 if (data[0] == MBS_COMMAND_COMPLETE) {
348 qla2x00_update_fcport(vha, fcport);
349
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700350 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700351 }
352
353 /* Retry login. */
354 fcport->flags &= ~FCF_ASYNC_SENT;
355 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
356 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
357 else
358 qla2x00_mark_device_lost(vha, fcport, 1, 0);
359
Madhuranath Iyengar49163922010-05-04 15:01:28 -0700360 return;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700361}
362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363/****************************************************************************/
364/* QLogic ISP2x00 Hardware Support Functions. */
365/****************************************************************************/
366
367/*
368* qla2x00_initialize_adapter
369* Initialize board.
370*
371* Input:
372* ha = adapter block pointer.
373*
374* Returns:
375* 0 = success
376*/
377int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800378qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379{
380 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800381 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800382 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700383
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800385 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700386 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800387 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800388 ha->flags.pci_channel_io_perm_failure = 0;
389 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800390 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
391 atomic_set(&vha->loop_state, LOOP_DOWN);
392 vha->device_flags = DFLG_NO_CABLE;
393 vha->dpc_flags = 0;
394 vha->flags.management_server_logged_in = 0;
395 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396 ha->isp_abort_cnt = 0;
397 ha->beacon_blink_led = 0;
398
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800399 set_bit(0, ha->req_qid_map);
400 set_bit(0, ha->rsp_qid_map);
401
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700402 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800403 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800405 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800406 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 return (rval);
408 }
409
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800410 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800412 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700413 if (rval) {
414 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800415 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700416 return (rval);
417 }
418
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800419 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700422
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800423 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700425 if (ha->flags.disable_serdes) {
426 /* Mask HBA via NVRAM settings? */
427 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
428 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800429 vha->port_name[0], vha->port_name[1],
430 vha->port_name[2], vha->port_name[3],
431 vha->port_name[4], vha->port_name[5],
432 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700433 return QLA_FUNCTION_FAILED;
434 }
435
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
437
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800438 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
439 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800440 if (rval)
441 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800442 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800443 if (rval)
444 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700446
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700447 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800448 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700449 if (!ha->cs84xx) {
450 qla_printk(KERN_ERR, ha,
451 "Unable to configure ISP84XX.\n");
452 return QLA_FUNCTION_FAILED;
453 }
454 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800455 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700456 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800458 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700459 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800460 rval = qla84xx_init_chip(vha);
461 if (rval != QLA_SUCCESS) {
462 qla_printk(KERN_ERR, ha,
463 "Unable to initialize ISP84XX.\n");
464 qla84xx_put_chip(vha);
465 }
466 }
467
Sarang Radke09ff7012010-03-19 17:03:59 -0700468 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
469 if (qla24xx_read_fcp_prio_cfg(vha))
470 qla_printk(KERN_ERR, ha,
471 "Unable to read FCP priority data.\n");
472 }
473
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 return (rval);
475}
476
477/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700478 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 * @ha: HA context
480 *
481 * Returns 0 on success.
482 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700483int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800484qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700486 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700487 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800488 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700489 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700492 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700495 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
497
Andrew Vasquez737faec2008-10-24 15:13:45 -0700498 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700499
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700500 /* Get PCI bus information. */
501 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700502 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700503 spin_unlock_irqrestore(&ha->hardware_lock, flags);
504
505 return QLA_SUCCESS;
506}
507
508/**
509 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
510 * @ha: HA context
511 *
512 * Returns 0 on success.
513 */
514int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700516{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700517 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700518 unsigned long flags = 0;
519 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800520 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700521 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700522
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700523 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700524 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700525
526 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700527 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700528
529 if (IS_QLA2322(ha) || IS_QLA6322(ha))
530 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700531 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700532
533 /*
534 * If this is a 2300 card and not 2312, reset the
535 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
536 * the 2310 also reports itself as a 2300 so we need to get the
537 * fb revision level -- a 6 indicates it really is a 2300 and
538 * not a 2310.
539 */
540 if (IS_QLA2300(ha)) {
541 spin_lock_irqsave(&ha->hardware_lock, flags);
542
543 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700544 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700545 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700546 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700547 break;
548
549 udelay(10);
550 }
551
552 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700553 WRT_REG_WORD(&reg->ctrl_status, 0x20);
554 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700555
556 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700557 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700558
559 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700560 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700561
562 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700563 WRT_REG_WORD(&reg->ctrl_status, 0x0);
564 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700565
566 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700567 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700568 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700569 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700570 break;
571
572 udelay(10);
573 }
574
575 spin_unlock_irqrestore(&ha->hardware_lock, flags);
576 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700577
578 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
579
Andrew Vasquez737faec2008-10-24 15:13:45 -0700580 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700581
582 /* Get PCI bus information. */
583 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700584 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700585 spin_unlock_irqrestore(&ha->hardware_lock, flags);
586
587 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700588}
589
590/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700591 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
592 * @ha: HA context
593 *
594 * Returns 0 on success.
595 */
596int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800597qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700598{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700599 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700600 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700602 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700603
604 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700605 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700606
607 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700608 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700609 w &= ~PCI_COMMAND_INTX_DISABLE;
610 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
611
612 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
613
614 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700615 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
616 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700617
618 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700619 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
620 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700621
Andrew Vasquez737faec2008-10-24 15:13:45 -0700622 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700623
Auke Kok44c10132007-06-08 15:46:36 -0700624 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800625
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700626 /* Get PCI bus information. */
627 spin_lock_irqsave(&ha->hardware_lock, flags);
628 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
629 spin_unlock_irqrestore(&ha->hardware_lock, flags);
630
631 return QLA_SUCCESS;
632}
633
634/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700635 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
636 * @ha: HA context
637 *
638 * Returns 0 on success.
639 */
640int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800641qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700642{
643 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800644 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700645
646 pci_set_master(ha->pdev);
647 pci_try_set_mwi(ha->pdev);
648
649 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
650 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
651 w &= ~PCI_COMMAND_INTX_DISABLE;
652 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
653
654 /* PCIe -- adjust Maximum Read Request Size (2048). */
655 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
656 pcie_set_readrq(ha->pdev, 2048);
657
Andrew Vasquez737faec2008-10-24 15:13:45 -0700658 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700659
660 ha->chip_revision = ha->pdev->revision;
661
662 return QLA_SUCCESS;
663}
664
665/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 * qla2x00_isp_firmware() - Choose firmware image.
667 * @ha: HA context
668 *
669 * Returns 0 on success.
670 */
671static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800672qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
674 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700675 uint16_t loop_id, topo, sw_cap;
676 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800677 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678
679 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700680 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 if (ha->flags.disable_risc_code_load) {
683 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
686
687 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800688 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700689 if (rval == QLA_SUCCESS) {
690 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800691 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700692 &area, &domain, &topo, &sw_cap);
693 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
695
696 if (rval) {
697 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700699 }
700
701 return (rval);
702}
703
704/**
705 * qla2x00_reset_chip() - Reset ISP chip.
706 * @ha: HA context
707 *
708 * Returns 0 on success.
709 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700710void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800711qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712{
713 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800714 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700715 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700717 uint16_t cmd;
718
Andrew Vasquez85880802009-12-15 21:29:46 -0800719 if (unlikely(pci_channel_offline(ha->pdev)))
720 return;
721
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700722 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700723
724 spin_lock_irqsave(&ha->hardware_lock, flags);
725
726 /* Turn off master enable */
727 cmd = 0;
728 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
729 cmd &= ~PCI_COMMAND_MASTER;
730 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
731
732 if (!IS_QLA2100(ha)) {
733 /* Pause RISC. */
734 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
735 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
736 for (cnt = 0; cnt < 30000; cnt++) {
737 if ((RD_REG_WORD(&reg->hccr) &
738 HCCR_RISC_PAUSE) != 0)
739 break;
740 udelay(100);
741 }
742 } else {
743 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
744 udelay(10);
745 }
746
747 /* Select FPM registers. */
748 WRT_REG_WORD(&reg->ctrl_status, 0x20);
749 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
750
751 /* FPM Soft Reset. */
752 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
753 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
754
755 /* Toggle Fpm Reset. */
756 if (!IS_QLA2200(ha)) {
757 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
758 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
759 }
760
761 /* Select frame buffer registers. */
762 WRT_REG_WORD(&reg->ctrl_status, 0x10);
763 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
764
765 /* Reset frame buffer FIFOs. */
766 if (IS_QLA2200(ha)) {
767 WRT_FB_CMD_REG(ha, reg, 0xa000);
768 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
769 } else {
770 WRT_FB_CMD_REG(ha, reg, 0x00fc);
771
772 /* Read back fb_cmd until zero or 3 seconds max */
773 for (cnt = 0; cnt < 3000; cnt++) {
774 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
775 break;
776 udelay(100);
777 }
778 }
779
780 /* Select RISC module registers. */
781 WRT_REG_WORD(&reg->ctrl_status, 0);
782 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
783
784 /* Reset RISC processor. */
785 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
786 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
787
788 /* Release RISC processor. */
789 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
790 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
791 }
792
793 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
794 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
795
796 /* Reset ISP chip. */
797 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
798
799 /* Wait for RISC to recover from reset. */
800 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
801 /*
802 * It is necessary to for a delay here since the card doesn't
803 * respond to PCI reads during a reset. On some architectures
804 * this will result in an MCA.
805 */
806 udelay(20);
807 for (cnt = 30000; cnt; cnt--) {
808 if ((RD_REG_WORD(&reg->ctrl_status) &
809 CSR_ISP_SOFT_RESET) == 0)
810 break;
811 udelay(100);
812 }
813 } else
814 udelay(10);
815
816 /* Reset RISC processor. */
817 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
818
819 WRT_REG_WORD(&reg->semaphore, 0);
820
821 /* Release RISC processor. */
822 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
823 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
824
825 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
826 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700827 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700828 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700829
830 udelay(100);
831 }
832 } else
833 udelay(100);
834
835 /* Turn on master enable */
836 cmd |= PCI_COMMAND_MASTER;
837 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
838
839 /* Disable RISC pause on FPM parity error. */
840 if (!IS_QLA2100(ha)) {
841 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
842 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
843 }
844
845 spin_unlock_irqrestore(&ha->hardware_lock, flags);
846}
847
848/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700849 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700850 * @ha: HA context
851 *
852 * Returns 0 on success.
853 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700854static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800855qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700856{
857 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800858 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700859 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
860 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800861 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700862
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700863 spin_lock_irqsave(&ha->hardware_lock, flags);
864
865 /* Reset RISC. */
866 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
867 for (cnt = 0; cnt < 30000; cnt++) {
868 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
869 break;
870
871 udelay(10);
872 }
873
874 WRT_REG_DWORD(&reg->ctrl_status,
875 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800876 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700877
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800878 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700879 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700880 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
881 for (cnt = 10000 ; cnt && d2; cnt--) {
882 udelay(5);
883 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
884 barrier();
885 }
886
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800887 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700888 d2 = RD_REG_DWORD(&reg->ctrl_status);
889 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
890 udelay(5);
891 d2 = RD_REG_DWORD(&reg->ctrl_status);
892 barrier();
893 }
894
895 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
896 RD_REG_DWORD(&reg->hccr);
897
898 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
899 RD_REG_DWORD(&reg->hccr);
900
901 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
902 RD_REG_DWORD(&reg->hccr);
903
904 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
905 for (cnt = 6000000 ; cnt && d2; cnt--) {
906 udelay(5);
907 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
908 barrier();
909 }
910
911 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800912
913 if (IS_NOPOLLING_TYPE(ha))
914 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700915}
916
917/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700918 * qla24xx_reset_chip() - Reset ISP24xx chip.
919 * @ha: HA context
920 *
921 * Returns 0 on success.
922 */
923void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800924qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700925{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800926 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -0800927
928 if (pci_channel_offline(ha->pdev) &&
929 ha->flags.pci_channel_io_perm_failure) {
930 return;
931 }
932
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700933 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700934
935 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800936 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700937}
938
939/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940 * qla2x00_chip_diag() - Test chip for proper operation.
941 * @ha: HA context
942 *
943 * Returns 0 on success.
944 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700945int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800946qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947{
948 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800949 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700950 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700951 unsigned long flags = 0;
952 uint16_t data;
953 uint32_t cnt;
954 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800955 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956
957 /* Assume a failed state */
958 rval = QLA_FUNCTION_FAILED;
959
960 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800961 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
963 spin_lock_irqsave(&ha->hardware_lock, flags);
964
965 /* Reset ISP chip. */
966 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
967
968 /*
969 * We need to have a delay here since the card will not respond while
970 * in reset causing an MCA on some architectures.
971 */
972 udelay(20);
973 data = qla2x00_debounce_register(&reg->ctrl_status);
974 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
975 udelay(5);
976 data = RD_REG_WORD(&reg->ctrl_status);
977 barrier();
978 }
979
980 if (!cnt)
981 goto chip_diag_failed;
982
983 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700984 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 /* Reset RISC processor. */
987 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
988 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
989
990 /* Workaround for QLA2312 PCI parity error */
991 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
992 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
993 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
994 udelay(5);
995 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700996 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997 }
998 } else
999 udelay(10);
1000
1001 if (!cnt)
1002 goto chip_diag_failed;
1003
1004 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -07001005 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
1007 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
1008 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
1009 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
1010 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
1011 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
1012 mb[3] != PROD_ID_3) {
1013 qla_printk(KERN_WARNING, ha,
1014 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
1015
1016 goto chip_diag_failed;
1017 }
1018 ha->product_id[0] = mb[1];
1019 ha->product_id[1] = mb[2];
1020 ha->product_id[2] = mb[3];
1021 ha->product_id[3] = mb[4];
1022
1023 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001024 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1026 else
1027 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001028 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001029
1030 if (IS_QLA2200(ha) &&
1031 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1032 /* Limit firmware transfer size with a 2200A */
1033 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001034 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001036 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 ha->fw_transfer_size = 128;
1038 }
1039
1040 /* Wrap Incoming Mailboxes Test. */
1041 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1042
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001043 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1044 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 if (rval) {
1046 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001047 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 qla_printk(KERN_WARNING, ha,
1049 "Failed mailbox send register test\n");
1050 }
1051 else {
1052 /* Flag a successful rval */
1053 rval = QLA_SUCCESS;
1054 }
1055 spin_lock_irqsave(&ha->hardware_lock, flags);
1056
1057chip_diag_failed:
1058 if (rval)
1059 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061
1062 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1063
1064 return (rval);
1065}
1066
1067/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001068 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1069 * @ha: HA context
1070 *
1071 * Returns 0 on success.
1072 */
1073int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001074qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001075{
1076 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001077 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001078 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001079
Giridhar Malavalia9083012010-04-12 17:59:55 -07001080 if (IS_QLA82XX(ha))
1081 return QLA_SUCCESS;
1082
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001083 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001084
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001086 if (rval) {
1087 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001088 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001089 qla_printk(KERN_WARNING, ha,
1090 "Failed mailbox send register test\n");
1091 } else {
1092 /* Flag a successful rval */
1093 rval = QLA_SUCCESS;
1094 }
1095
1096 return rval;
1097}
1098
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001099void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001100qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001101{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001102 int rval;
1103 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001104 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001105 dma_addr_t tc_dma;
1106 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001107 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001108 struct req_que *req = ha->req_q_map[0];
1109 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001110
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001111 if (ha->fw_dump) {
1112 qla_printk(KERN_WARNING, ha,
1113 "Firmware dump previously allocated.\n");
1114 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001115 }
1116
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001117 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001118 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001119 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1120 fixed_size = sizeof(struct qla2100_fw_dump);
1121 } else if (IS_QLA23XX(ha)) {
1122 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1123 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1124 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001125 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001126 if (IS_QLA81XX(ha))
1127 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1128 else if (IS_QLA25XX(ha))
1129 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1130 else
1131 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001132 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1133 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001134 if (ha->mqenable)
1135 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001136 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001137 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001138 goto try_eft;
1139
1140 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1141 GFP_KERNEL);
1142 if (!tc) {
1143 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1144 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001145 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001146 }
1147
1148 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001149 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001150 ha->fce_mb, &ha->fce_bufs);
1151 if (rval) {
1152 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1153 "FCE (%d).\n", rval);
1154 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1155 tc_dma);
1156 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001157 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001158 }
1159
1160 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1161 FCE_SIZE / 1024);
1162
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001163 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001164 ha->flags.fce_enabled = 1;
1165 ha->fce_dma = tc_dma;
1166 ha->fce = tc;
1167try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001168 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001169 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001170 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001171 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001172 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1173 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1174 goto cont_alloc;
1175 }
1176
Andrew Vasquezfc447652008-01-17 09:02:18 -08001177 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001178 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001179 if (rval) {
1180 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1181 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001182 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1183 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001184 goto cont_alloc;
1185 }
1186
1187 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1188 EFT_SIZE / 1024);
1189
1190 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001191 ha->eft_dma = tc_dma;
1192 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001193 }
1194cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001195 req_q_size = req->length * sizeof(request_t);
1196 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001197
1198 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001199 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001200 ha->chain_offset = dump_size;
1201 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001202
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001203 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001204 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001205 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001206 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001207
1208 if (ha->eft) {
1209 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1210 ha->eft_dma);
1211 ha->eft = NULL;
1212 ha->eft_dma = 0;
1213 }
1214 return;
1215 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001216 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1217 dump_size / 1024);
1218
1219 ha->fw_dump_len = dump_size;
1220 ha->fw_dump->signature[0] = 'Q';
1221 ha->fw_dump->signature[1] = 'L';
1222 ha->fw_dump->signature[2] = 'G';
1223 ha->fw_dump->signature[3] = 'C';
1224 ha->fw_dump->version = __constant_htonl(1);
1225
1226 ha->fw_dump->fixed_size = htonl(fixed_size);
1227 ha->fw_dump->mem_size = htonl(mem_size);
1228 ha->fw_dump->req_q_size = htonl(req_q_size);
1229 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1230
1231 ha->fw_dump->eft_size = htonl(eft_size);
1232 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1233 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1234
1235 ha->fw_dump->header_size =
1236 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001237}
1238
Andrew Vasquez18e75552009-06-03 09:55:30 -07001239static int
1240qla81xx_mpi_sync(scsi_qla_host_t *vha)
1241{
1242#define MPS_MASK 0xe0
1243 int rval;
1244 uint16_t dc;
1245 uint32_t dw;
1246 struct qla_hw_data *ha = vha->hw;
1247
1248 if (!IS_QLA81XX(vha->hw))
1249 return QLA_SUCCESS;
1250
1251 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1252 if (rval != QLA_SUCCESS) {
1253 DEBUG2(qla_printk(KERN_WARNING, ha,
1254 "Sync-MPI: Unable to acquire semaphore.\n"));
1255 goto done;
1256 }
1257
1258 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1259 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1260 if (rval != QLA_SUCCESS) {
1261 DEBUG2(qla_printk(KERN_WARNING, ha,
1262 "Sync-MPI: Unable to read sync.\n"));
1263 goto done_release;
1264 }
1265
1266 dc &= MPS_MASK;
1267 if (dc == (dw & MPS_MASK))
1268 goto done_release;
1269
1270 dw &= ~MPS_MASK;
1271 dw |= dc;
1272 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1273 if (rval != QLA_SUCCESS) {
1274 DEBUG2(qla_printk(KERN_WARNING, ha,
1275 "Sync-MPI: Unable to gain sync.\n"));
1276 }
1277
1278done_release:
1279 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1280 if (rval != QLA_SUCCESS) {
1281 DEBUG2(qla_printk(KERN_WARNING, ha,
1282 "Sync-MPI: Unable to release semaphore.\n"));
1283 }
1284
1285done:
1286 return rval;
1287}
1288
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001289/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 * qla2x00_setup_chip() - Load and start RISC firmware.
1291 * @ha: HA context
1292 *
1293 * Returns 0 on success.
1294 */
1295static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001296qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001298 int rval;
1299 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001300 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001301 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1302 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001303 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001304
Giridhar Malavalia9083012010-04-12 17:59:55 -07001305 if (IS_QLA82XX(ha)) {
1306 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1307 if (rval == QLA_SUCCESS)
1308 goto enable_82xx_npiv;
1309 }
1310
Andrew Vasquez3db06522008-01-31 12:33:49 -08001311 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1312 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1313 spin_lock_irqsave(&ha->hardware_lock, flags);
1314 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1315 RD_REG_WORD(&reg->hccr);
1316 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318
Andrew Vasquez18e75552009-06-03 09:55:30 -07001319 qla81xx_mpi_sync(vha);
1320
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001322 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001323 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001325 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328 if (rval == QLA_SUCCESS) {
1329 /* Start firmware execution. */
1330 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001331 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001333 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001334 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001335 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001336enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001337 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001338 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 &ha->fw_major_version,
1340 &ha->fw_minor_version,
1341 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001342 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001343 ha->mpi_version, &ha->mpi_capabilities,
1344 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001345 if (rval != QLA_SUCCESS)
1346 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001347 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001349 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001350 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001351 if ((!ha->max_npiv_vports) ||
1352 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001353 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001354 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001355 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001356 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001357 qla2x00_get_resource_cnts(vha, NULL,
1358 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001359 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001360
Giridhar Malavalia9083012010-04-12 17:59:55 -07001361 if (!fw_major_version && ql2xallocfwdump) {
1362 if (!IS_QLA82XX(ha))
1363 qla2x00_alloc_fw_dump(vha);
1364 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 }
1366 } else {
1367 DEBUG2(printk(KERN_INFO
1368 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001369 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370 }
1371 }
1372
Andrew Vasquez3db06522008-01-31 12:33:49 -08001373 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1374 /* Enable proper parity. */
1375 spin_lock_irqsave(&ha->hardware_lock, flags);
1376 if (IS_QLA2300(ha))
1377 /* SRAM parity */
1378 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1379 else
1380 /* SRAM, Instruction RAM and GP RAM parity */
1381 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1382 RD_REG_WORD(&reg->hccr);
1383 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1384 }
1385
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001386 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1387 uint32_t size;
1388
1389 rval = qla81xx_fac_get_sector_size(vha, &size);
1390 if (rval == QLA_SUCCESS) {
1391 ha->flags.fac_supported = 1;
1392 ha->fdt_block_size = size << 2;
1393 } else {
1394 qla_printk(KERN_ERR, ha,
1395 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1396 ha->fw_major_version, ha->fw_minor_version,
1397 ha->fw_subminor_version);
1398 }
1399 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001400failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401 if (rval) {
1402 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001403 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 }
1405
1406 return (rval);
1407}
1408
1409/**
1410 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1411 * @ha: HA context
1412 *
1413 * Beginning of request ring has initialization control block already built
1414 * by nvram config routine.
1415 *
1416 * Returns 0 on success.
1417 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001418void
1419qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420{
1421 uint16_t cnt;
1422 response_t *pkt;
1423
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001424 rsp->ring_ptr = rsp->ring;
1425 rsp->ring_index = 0;
1426 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001427 pkt = rsp->ring_ptr;
1428 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001429 pkt->signature = RESPONSE_PROCESSED;
1430 pkt++;
1431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432}
1433
1434/**
1435 * qla2x00_update_fw_options() - Read and process firmware options.
1436 * @ha: HA context
1437 *
1438 * Returns 0 on success.
1439 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001440void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001441qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442{
1443 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
1446 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448
1449 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1450 return;
1451
1452 /* Serial Link options. */
1453 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1456 sizeof(ha->fw_seriallink_options)));
1457
1458 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1459 if (ha->fw_seriallink_options[3] & BIT_2) {
1460 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1461
1462 /* 1G settings */
1463 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1464 emphasis = (ha->fw_seriallink_options[2] &
1465 (BIT_4 | BIT_3)) >> 3;
1466 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001467 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468 rx_sens = (ha->fw_seriallink_options[0] &
1469 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1470 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1471 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1472 if (rx_sens == 0x0)
1473 rx_sens = 0x3;
1474 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1475 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1476 ha->fw_options[10] |= BIT_5 |
1477 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1478 (tx_sens & (BIT_1 | BIT_0));
1479
1480 /* 2G settings */
1481 swing = (ha->fw_seriallink_options[2] &
1482 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1483 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1484 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001485 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001486 rx_sens = (ha->fw_seriallink_options[1] &
1487 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1488 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1489 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1490 if (rx_sens == 0x0)
1491 rx_sens = 0x3;
1492 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1493 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1494 ha->fw_options[11] |= BIT_5 |
1495 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1496 (tx_sens & (BIT_1 | BIT_0));
1497 }
1498
1499 /* FCP2 options. */
1500 /* Return command IOCBs without waiting for an ABTS to complete. */
1501 ha->fw_options[3] |= BIT_13;
1502
1503 /* LED scheme. */
1504 if (ha->flags.enable_led_scheme)
1505 ha->fw_options[2] |= BIT_12;
1506
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001507 /* Detect ISP6312. */
1508 if (IS_QLA6312(ha))
1509 ha->fw_options[2] |= BIT_13;
1510
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001512 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513}
1514
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001515void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001517{
1518 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001519 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001520
Giridhar Malavalia9083012010-04-12 17:59:55 -07001521 if (IS_QLA82XX(ha))
1522 return;
1523
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001524 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001525 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001526 return;
1527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001528 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001529 le16_to_cpu(ha->fw_seriallink_options24[1]),
1530 le16_to_cpu(ha->fw_seriallink_options24[2]),
1531 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001532 if (rval != QLA_SUCCESS) {
1533 qla_printk(KERN_WARNING, ha,
1534 "Unable to update Serial Link options (%x).\n", rval);
1535 }
1536}
1537
1538void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001540{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001541 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001542 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001543 struct req_que *req = ha->req_q_map[0];
1544 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001545
1546 /* Setup ring parameters in initialization control block. */
1547 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1548 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001549 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1550 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1551 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1552 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1553 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1554 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001555
1556 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1557 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1558 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1559 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1560 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1561}
1562
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001563void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001564qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001565{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001566 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001567 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1568 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1569 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001570 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001571 uint16_t rid = 0;
1572 struct req_que *req = ha->req_q_map[0];
1573 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001574
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001575/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001576 icb = (struct init_cb_24xx *)ha->init_cb;
1577 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1578 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001579 icb->request_q_length = cpu_to_le16(req->length);
1580 icb->response_q_length = cpu_to_le16(rsp->length);
1581 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1582 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1583 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1584 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001585
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001586 if (ha->mqenable) {
1587 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1588 icb->rid = __constant_cpu_to_le16(rid);
1589 if (ha->flags.msix_enabled) {
1590 msix = &ha->msix_entries[1];
1591 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001592 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001593 icb->msix = cpu_to_le16(msix->entry);
1594 }
1595 /* Use alternate PCI bus number */
1596 if (MSB(rid))
1597 icb->firmware_options_2 |=
1598 __constant_cpu_to_le32(BIT_19);
1599 /* Use alternate PCI devfn */
1600 if (LSB(rid))
1601 icb->firmware_options_2 |=
1602 __constant_cpu_to_le32(BIT_18);
1603
Anirban Chakraborty31557542009-12-02 10:36:55 -08001604 /* Use Disable MSIX Handshake mode for capable adapters */
1605 if (IS_MSIX_NACK_CAPABLE(ha)) {
1606 icb->firmware_options_2 &=
1607 __constant_cpu_to_le32(~BIT_22);
1608 ha->flags.disable_msix_handshake = 1;
1609 qla_printk(KERN_INFO, ha,
1610 "MSIX Handshake Disable Mode turned on\n");
1611 } else {
1612 icb->firmware_options_2 |=
1613 __constant_cpu_to_le32(BIT_22);
1614 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001615 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001616
1617 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1618 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1619 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1620 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1621 } else {
1622 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1623 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1624 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1625 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1626 }
1627 /* PCI posting */
1628 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001629}
1630
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631/**
1632 * qla2x00_init_rings() - Initializes firmware.
1633 * @ha: HA context
1634 *
1635 * Beginning of request ring has initialization control block already built
1636 * by nvram config routine.
1637 *
1638 * Returns 0 on success.
1639 */
1640static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642{
1643 int rval;
1644 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001645 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001646 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001647 struct req_que *req;
1648 struct rsp_que *rsp;
1649 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001650 struct mid_init_cb_24xx *mid_init_cb =
1651 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001652
1653 spin_lock_irqsave(&ha->hardware_lock, flags);
1654
1655 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001656 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001657 req = ha->req_q_map[que];
1658 if (!req)
1659 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001660 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001661 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001663 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001664
1665 /* Initialize firmware. */
1666 req->ring_ptr = req->ring;
1667 req->ring_index = 0;
1668 req->cnt = req->length;
1669 }
1670
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001671 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001672 rsp = ha->rsp_q_map[que];
1673 if (!rsp)
1674 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001675 /* Initialize response queue entries */
1676 qla2x00_init_response_q_entries(rsp);
1677 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
1679 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001680 list_for_each_entry(vp, &ha->vp_list, list) {
1681 vp->rscn_in_ptr = 0;
1682 vp->rscn_out_ptr = 0;
1683 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001684 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685
1686 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1687
1688 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001690
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001691 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001692
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001693 if (ha->flags.npiv_supported) {
1694 if (ha->operating_mode == LOOP)
1695 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001696 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001697 }
1698
Andrew Vasquez24a08132009-03-24 09:08:16 -07001699 if (IS_FWI2_CAPABLE(ha)) {
1700 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1701 mid_init_cb->init_cb.execution_throttle =
1702 cpu_to_le16(ha->fw_xcb_count);
1703 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001704
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001705 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001706 if (rval) {
1707 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 } else {
1710 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001711 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 }
1713
1714 return (rval);
1715}
1716
1717/**
1718 * qla2x00_fw_ready() - Waits for firmware ready.
1719 * @ha: HA context
1720 *
1721 * Returns 0 on success.
1722 */
1723static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001724qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001725{
1726 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001727 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 uint16_t min_wait; /* Minimum wait time if loop is down */
1729 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001730 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001731 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732
1733 rval = QLA_SUCCESS;
1734
1735 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001736 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 /*
1739 * Firmware should take at most one RATOV to login, plus 5 seconds for
1740 * our own processing.
1741 */
1742 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1743 wait_time = min_wait;
1744 }
1745
1746 /* Min wait time if loop down */
1747 mtime = jiffies + (min_wait * HZ);
1748
1749 /* wait time before firmware ready */
1750 wtime = jiffies + (wait_time * HZ);
1751
1752 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001753 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1755
1756 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001757 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
1759 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001760 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001761 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001762 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001763 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001765 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1766 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001767 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001768 state[2]));
1769 if ((state[2] & FSTATE_LOGGED_IN) &&
1770 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1771 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001773
1774 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001775 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001776 if (rval != QLA_SUCCESS)
1777 break;
1778
1779 /* Add time taken to initialize. */
1780 cs84xx_time = jiffies - cs84xx_time;
1781 wtime += cs84xx_time;
1782 mtime += cs84xx_time;
1783 DEBUG16(printk("scsi(%ld): Increasing "
1784 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001785 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001786 }
1787 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001789 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 &ha->login_timeout, &ha->r_a_tov);
1793
1794 rval = QLA_SUCCESS;
1795 break;
1796 }
1797
1798 rval = QLA_FUNCTION_FAILED;
1799
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001800 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001801 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001803 * other than Wait for Login.
1804 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 if (time_after_eq(jiffies, mtime)) {
1806 qla_printk(KERN_INFO, ha,
1807 "Cable is unplugged...\n");
1808
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810 break;
1811 }
1812 }
1813 } else {
1814 /* Mailbox cmd failed. Timeout on min_wait. */
1815 if (time_after_eq(jiffies, mtime))
1816 break;
1817 }
1818
1819 if (time_after_eq(jiffies, wtime))
1820 break;
1821
1822 /* Delay for a while */
1823 msleep(500);
1824
1825 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001826 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 } while (1);
1828
Andrew Vasquez656e8912009-06-03 09:55:29 -07001829 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1830 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1831 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
1833 if (rval) {
1834 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001835 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 }
1837
1838 return (rval);
1839}
1840
1841/*
1842* qla2x00_configure_hba
1843* Setup adapter context.
1844*
1845* Input:
1846* ha = adapter state pointer.
1847*
1848* Returns:
1849* 0 = success
1850*
1851* Context:
1852* Kernel context.
1853*/
1854static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001855qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856{
1857 int rval;
1858 uint16_t loop_id;
1859 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001860 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 uint8_t al_pa;
1862 uint8_t area;
1863 uint8_t domain;
1864 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001865 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
1867 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001868 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001869 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001872 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1873 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001875 } else {
1876 qla_printk(KERN_WARNING, ha,
1877 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001879 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001880 return (rval);
1881 }
1882
1883 if (topo == 4) {
1884 qla_printk(KERN_INFO, ha,
1885 "Cannot get topology - retrying.\n");
1886 return (QLA_FUNCTION_FAILED);
1887 }
1888
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001889 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001890
1891 /* initialize */
1892 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1893 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001894 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001895
1896 switch (topo) {
1897 case 0:
1898 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 ha->current_topology = ISP_CFG_NL;
1901 strcpy(connect_type, "(Loop)");
1902 break;
1903
1904 case 1:
1905 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001906 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001907 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 ha->current_topology = ISP_CFG_FL;
1909 strcpy(connect_type, "(FL_Port)");
1910 break;
1911
1912 case 2:
1913 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001914 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001915 ha->operating_mode = P2P;
1916 ha->current_topology = ISP_CFG_N;
1917 strcpy(connect_type, "(N_Port-to-N_Port)");
1918 break;
1919
1920 case 3:
1921 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001922 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001923 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 ha->operating_mode = P2P;
1925 ha->current_topology = ISP_CFG_F;
1926 strcpy(connect_type, "(F_Port)");
1927 break;
1928
1929 default:
1930 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1931 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001932 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 ha->current_topology = ISP_CFG_NL;
1934 strcpy(connect_type, "(Loop)");
1935 break;
1936 }
1937
1938 /* Save Host port and loop ID. */
1939 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 vha->d_id.b.domain = domain;
1941 vha->d_id.b.area = area;
1942 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001944 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945 qla_printk(KERN_INFO, ha,
1946 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001947 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948
1949 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001950 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001952 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 }
1954
1955 return(rval);
1956}
1957
Giridhar Malavalia9083012010-04-12 17:59:55 -07001958inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001959qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1960 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001961{
1962 char *st, *en;
1963 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07001965 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07001966 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001967
1968 if (memcmp(model, BINZERO, len) != 0) {
1969 strncpy(ha->model_number, model, len);
1970 st = en = ha->model_number;
1971 en += len - 1;
1972 while (en > st) {
1973 if (*en != 0x20 && *en != 0x00)
1974 break;
1975 *en-- = '\0';
1976 }
1977
1978 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001979 if (use_tbl &&
1980 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001981 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001982 strncpy(ha->model_desc,
1983 qla2x00_model_name[index * 2 + 1],
1984 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001985 } else {
1986 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001987 if (use_tbl &&
1988 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001989 index < QLA_MODEL_NAMES) {
1990 strcpy(ha->model_number,
1991 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001992 strncpy(ha->model_desc,
1993 qla2x00_model_name[index * 2 + 1],
1994 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001995 } else {
1996 strcpy(ha->model_number, def);
1997 }
1998 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001999 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002000 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07002001 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002002}
2003
David Miller4e08df32007-04-16 12:37:43 -07002004/* On sparc systems, obtain port and node WWN from firmware
2005 * properties.
2006 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07002008{
2009#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07002011 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07002012 struct device_node *dp = pci_device_to_OF_node(pdev);
2013 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07002014 int len;
2015
2016 val = of_get_property(dp, "port-wwn", &len);
2017 if (val && len >= WWN_SIZE)
2018 memcpy(nv->port_name, val, WWN_SIZE);
2019
2020 val = of_get_property(dp, "node-wwn", &len);
2021 if (val && len >= WWN_SIZE)
2022 memcpy(nv->node_name, val, WWN_SIZE);
2023#endif
2024}
2025
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026/*
2027* NVRAM configuration for ISP 2xxx
2028*
2029* Input:
2030* ha = adapter block pointer.
2031*
2032* Output:
2033* initialization control block in response_ring
2034* host adapters parameters in host adapter block
2035*
2036* Returns:
2037* 0 = success.
2038*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002039int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041{
David Miller4e08df32007-04-16 12:37:43 -07002042 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002043 uint8_t chksum = 0;
2044 uint16_t cnt;
2045 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002047 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002048 nvram_t *nv = ha->nvram;
2049 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002050 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051
David Miller4e08df32007-04-16 12:37:43 -07002052 rval = QLA_SUCCESS;
2053
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002055 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 ha->nvram_base = 0;
2057 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2058 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2059 ha->nvram_base = 0x80;
2060
2061 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002063 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2064 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002067 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068
2069 /* Bad NVRAM data, set defaults parameters. */
2070 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2071 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2072 /* Reset NVRAM data. */
2073 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2074 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2075 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002076 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2077 "invalid -- WWPN) defaults.\n");
2078
2079 /*
2080 * Set default initialization control block.
2081 */
2082 memset(nv, 0, ha->nvram_size);
2083 nv->parameter_block_version = ICB_VERSION;
2084
2085 if (IS_QLA23XX(ha)) {
2086 nv->firmware_options[0] = BIT_2 | BIT_1;
2087 nv->firmware_options[1] = BIT_7 | BIT_5;
2088 nv->add_firmware_options[0] = BIT_5;
2089 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2090 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2091 nv->special_options[1] = BIT_7;
2092 } else if (IS_QLA2200(ha)) {
2093 nv->firmware_options[0] = BIT_2 | BIT_1;
2094 nv->firmware_options[1] = BIT_7 | BIT_5;
2095 nv->add_firmware_options[0] = BIT_5;
2096 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2097 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2098 } else if (IS_QLA2100(ha)) {
2099 nv->firmware_options[0] = BIT_3 | BIT_1;
2100 nv->firmware_options[1] = BIT_5;
2101 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2102 }
2103
2104 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2105 nv->execution_throttle = __constant_cpu_to_le16(16);
2106 nv->retry_count = 8;
2107 nv->retry_delay = 1;
2108
2109 nv->port_name[0] = 33;
2110 nv->port_name[3] = 224;
2111 nv->port_name[4] = 139;
2112
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002114
2115 nv->login_timeout = 4;
2116
2117 /*
2118 * Set default host adapter parameters
2119 */
2120 nv->host_p[1] = BIT_2;
2121 nv->reset_delay = 5;
2122 nv->port_down_retry_count = 8;
2123 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2124 nv->link_down_timeout = 60;
2125
2126 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002127 }
2128
2129#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2130 /*
2131 * The SN2 does not provide BIOS emulation which means you can't change
2132 * potentially bogus BIOS settings. Force the use of default settings
2133 * for link rate and frame size. Hope that the rest of the settings
2134 * are valid.
2135 */
2136 if (ia64_platform_is("sn2")) {
2137 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2138 if (IS_QLA23XX(ha))
2139 nv->special_options[1] = BIT_7;
2140 }
2141#endif
2142
2143 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002144 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145
2146 /*
2147 * Setup driver NVRAM options.
2148 */
2149 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2150 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2151 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2152 nv->firmware_options[1] &= ~BIT_4;
2153
2154 if (IS_QLA23XX(ha)) {
2155 nv->firmware_options[0] |= BIT_2;
2156 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002157 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002158 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159
2160 if (IS_QLA2300(ha)) {
2161 if (ha->fb_rev == FPM_2310) {
2162 strcpy(ha->model_number, "QLA2310");
2163 } else {
2164 strcpy(ha->model_number, "QLA2300");
2165 }
2166 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002168 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169 }
2170 } else if (IS_QLA2200(ha)) {
2171 nv->firmware_options[0] |= BIT_2;
2172 /*
2173 * 'Point-to-point preferred, else loop' is not a safe
2174 * connection mode setting.
2175 */
2176 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2177 (BIT_5 | BIT_4)) {
2178 /* Force 'loop preferred, else point-to-point'. */
2179 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2180 nv->add_firmware_options[0] |= BIT_5;
2181 }
2182 strcpy(ha->model_number, "QLA22xx");
2183 } else /*if (IS_QLA2100(ha))*/ {
2184 strcpy(ha->model_number, "QLA2100");
2185 }
2186
2187 /*
2188 * Copy over NVRAM RISC parameter block to initialization control block.
2189 */
2190 dptr1 = (uint8_t *)icb;
2191 dptr2 = (uint8_t *)&nv->parameter_block_version;
2192 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2193 while (cnt--)
2194 *dptr1++ = *dptr2++;
2195
2196 /* Copy 2nd half. */
2197 dptr1 = (uint8_t *)icb->add_firmware_options;
2198 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2199 while (cnt--)
2200 *dptr1++ = *dptr2++;
2201
Andrew Vasquez5341e862006-05-17 15:09:16 -07002202 /* Use alternate WWN? */
2203 if (nv->host_p[1] & BIT_7) {
2204 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2205 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2206 }
2207
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 /* Prepare nodename */
2209 if ((icb->firmware_options[1] & BIT_6) == 0) {
2210 /*
2211 * Firmware will apply the following mask if the nodename was
2212 * not provided.
2213 */
2214 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2215 icb->node_name[0] &= 0xF0;
2216 }
2217
2218 /*
2219 * Set host adapter parameters.
2220 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002221 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002222 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2224 /* Always load RISC code on non ISP2[12]00 chips. */
2225 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2226 ha->flags.disable_risc_code_load = 0;
2227 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2228 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2229 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002230 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002231 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232
2233 ha->operating_mode =
2234 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2235
2236 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2237 sizeof(ha->fw_seriallink_options));
2238
2239 /* save HBA serial number */
2240 ha->serial0 = icb->port_name[5];
2241 ha->serial1 = icb->port_name[6];
2242 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2244 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245
2246 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2247
2248 ha->retry_count = nv->retry_count;
2249
2250 /* Set minimum login_timeout to 4 seconds. */
2251 if (nv->login_timeout < ql2xlogintimeout)
2252 nv->login_timeout = ql2xlogintimeout;
2253 if (nv->login_timeout < 4)
2254 nv->login_timeout = 4;
2255 ha->login_timeout = nv->login_timeout;
2256 icb->login_timeout = nv->login_timeout;
2257
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002258 /* Set minimum RATOV to 100 tenths of a second. */
2259 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 ha->loop_reset_delay = nv->reset_delay;
2262
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263 /* Link Down Timeout = 0:
2264 *
2265 * When Port Down timer expires we will start returning
2266 * I/O's to OS with "DID_NO_CONNECT".
2267 *
2268 * Link Down Timeout != 0:
2269 *
2270 * The driver waits for the link to come up after link down
2271 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002272 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 if (nv->link_down_timeout == 0) {
2274 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002275 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002276 } else {
2277 ha->link_down_timeout = nv->link_down_timeout;
2278 ha->loop_down_abort_time =
2279 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002280 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281
Linus Torvalds1da177e2005-04-16 15:20:36 -07002282 /*
2283 * Need enough time to try and get the port back.
2284 */
2285 ha->port_down_retry_count = nv->port_down_retry_count;
2286 if (qlport_down_retry)
2287 ha->port_down_retry_count = qlport_down_retry;
2288 /* Set login_retry_count */
2289 ha->login_retry_count = nv->retry_count;
2290 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2291 ha->port_down_retry_count > 3)
2292 ha->login_retry_count = ha->port_down_retry_count;
2293 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2294 ha->login_retry_count = ha->port_down_retry_count;
2295 if (ql2xloginretrycount)
2296 ha->login_retry_count = ql2xloginretrycount;
2297
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 icb->lun_enables = __constant_cpu_to_le16(0);
2299 icb->command_resource_count = 0;
2300 icb->immediate_notify_resource_count = 0;
2301 icb->timeout = __constant_cpu_to_le16(0);
2302
2303 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2304 /* Enable RIO */
2305 icb->firmware_options[0] &= ~BIT_3;
2306 icb->add_firmware_options[0] &=
2307 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2308 icb->add_firmware_options[0] |= BIT_2;
2309 icb->response_accumulation_timer = 3;
2310 icb->interrupt_delay_timer = 5;
2311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002314 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002316 ha->zio_mode = icb->add_firmware_options[0] &
2317 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2318 ha->zio_timer = icb->interrupt_delay_timer ?
2319 icb->interrupt_delay_timer: 2;
2320 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 icb->add_firmware_options[0] &=
2322 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002324 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002325 ha->zio_mode = QLA_ZIO_MODE_6;
2326
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002327 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002328 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002329 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002330 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002331 "ZIO mode %d enabled; timer delay (%d us).\n",
2332 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002334 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2335 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 }
2338 }
2339
David Miller4e08df32007-04-16 12:37:43 -07002340 if (rval) {
2341 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002343 }
2344 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345}
2346
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002347static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002348qla2x00_rport_del(void *data)
2349{
2350 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002351 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002352
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002353 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002354 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002355 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002356 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002357 if (rport)
2358 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002359}
2360
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361/**
2362 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2363 * @ha: HA context
2364 * @flags: allocation flags
2365 *
2366 * Returns a pointer to the allocated fcport, or NULL, if none available.
2367 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002368fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370{
2371 fc_port_t *fcport;
2372
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002373 fcport = kzalloc(sizeof(fc_port_t), flags);
2374 if (!fcport)
2375 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
2377 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 fcport->vha = vha;
2379 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 fcport->port_type = FCT_UNKNOWN;
2381 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002383 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002385 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386}
2387
2388/*
2389 * qla2x00_configure_loop
2390 * Updates Fibre Channel Device Database with what is actually on loop.
2391 *
2392 * Input:
2393 * ha = adapter block pointer.
2394 *
2395 * Returns:
2396 * 0 = success.
2397 * 1 = error.
2398 * 2 = database was full and device was not configured.
2399 */
2400static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002401qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002402{
2403 int rval;
2404 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 rval = QLA_SUCCESS;
2407
2408 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2410 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411 if (rval != QLA_SUCCESS) {
2412 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002413 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 return (rval);
2415 }
2416 }
2417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421
2422 /*
2423 * If we have both an RSCN and PORT UPDATE pending then handle them
2424 * both at the same time.
2425 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002426 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2427 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
Michael Hernandez3064ff32009-12-15 21:29:44 -08002429 qla2x00_get_data_rate(vha);
2430
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 /* Determine what we need to do */
2432 if (ha->current_topology == ISP_CFG_FL &&
2433 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2434
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002435 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 set_bit(RSCN_UPDATE, &flags);
2437
2438 } else if (ha->current_topology == ISP_CFG_F &&
2439 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002441 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 set_bit(RSCN_UPDATE, &flags);
2443 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2444
Andrew Vasquez21333b42006-05-17 15:09:56 -07002445 } else if (ha->current_topology == ISP_CFG_N) {
2446 clear_bit(RSCN_UPDATE, &flags);
2447
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2450
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002451 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 set_bit(RSCN_UPDATE, &flags);
2453 set_bit(LOCAL_LOOP_UPDATE, &flags);
2454 }
2455
2456 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459 else
2460 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 }
2462
2463 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002464 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 else
2467 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 }
2469
2470 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002471 if (atomic_read(&vha->loop_down_timer) ||
2472 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 rval = QLA_FUNCTION_FAILED;
2474 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002475 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 }
2479 }
2480
2481 if (rval) {
2482 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 } else {
2485 DEBUG3(printk("%s: exiting normally\n", __func__));
2486 }
2487
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002488 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002491 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002492 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002494 vha->flags.rscn_queue_overflow = 1;
2495 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 }
2497
2498 return (rval);
2499}
2500
2501
2502
2503/*
2504 * qla2x00_configure_local_loop
2505 * Updates Fibre Channel Device Database with local loop devices.
2506 *
2507 * Input:
2508 * ha = adapter block pointer.
2509 *
2510 * Returns:
2511 * 0 = success.
2512 */
2513static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002514qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515{
2516 int rval, rval2;
2517 int found_devs;
2518 int found;
2519 fc_port_t *fcport, *new_fcport;
2520
2521 uint16_t index;
2522 uint16_t entries;
2523 char *id_iter;
2524 uint16_t loop_id;
2525 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527
2528 found_devs = 0;
2529 new_fcport = NULL;
2530 entries = MAX_FIBRE_DEVICES;
2531
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002532 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2533 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534
2535 /* Get list of logged in devices. */
2536 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002537 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 &entries);
2539 if (rval != QLA_SUCCESS)
2540 goto cleanup_allocation;
2541
2542 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002543 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2545 entries * sizeof(struct gid_list_info)));
2546
2547 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 if (new_fcport == NULL) {
2550 rval = QLA_MEMORY_ALLOC_FAILED;
2551 goto cleanup_allocation;
2552 }
2553 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2554
2555 /*
2556 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2557 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002558 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002559 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2560 fcport->port_type != FCT_BROADCAST &&
2561 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2562
2563 DEBUG(printk("scsi(%ld): Marking port lost, "
2564 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566
2567 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 }
2569 }
2570
2571 /* Add devices to port list. */
2572 id_iter = (char *)ha->gid_list;
2573 for (index = 0; index < entries; index++) {
2574 domain = ((struct gid_list_info *)id_iter)->domain;
2575 area = ((struct gid_list_info *)id_iter)->area;
2576 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002577 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 loop_id = (uint16_t)
2579 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002580 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 loop_id = le16_to_cpu(
2582 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002583 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
2585 /* Bypass reserved domain fields. */
2586 if ((domain & 0xf0) == 0xf0)
2587 continue;
2588
2589 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002590 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 continue;
2593
2594 /* Bypass invalid local loop ID. */
2595 if (loop_id > LAST_LOCAL_LOOP_ID)
2596 continue;
2597
2598 /* Fill in member data. */
2599 new_fcport->d_id.b.domain = domain;
2600 new_fcport->d_id.b.area = area;
2601 new_fcport->d_id.b.al_pa = al_pa;
2602 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 new_fcport->vp_idx = vha->vp_idx;
2604 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 if (rval2 != QLA_SUCCESS) {
2606 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2607 "information -- get_port_database=%x, "
2608 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002610 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 vha->host_no));
2612 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 continue;
2614 }
2615
2616 /* Check for matching device in port list. */
2617 found = 0;
2618 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 if (memcmp(new_fcport->port_name, fcport->port_name,
2621 WWN_SIZE))
2622 continue;
2623
Shyam Sundarddb9b122009-03-24 09:08:10 -07002624 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 fcport->loop_id = new_fcport->loop_id;
2626 fcport->port_type = new_fcport->port_type;
2627 fcport->d_id.b24 = new_fcport->d_id.b24;
2628 memcpy(fcport->node_name, new_fcport->node_name,
2629 WWN_SIZE);
2630
2631 found++;
2632 break;
2633 }
2634
2635 if (!found) {
2636 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 if (vha->vp_idx) {
2638 new_fcport->vha = vha;
2639 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002640 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
2643 /* Allocate a new replacement fcport. */
2644 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 if (new_fcport == NULL) {
2647 rval = QLA_MEMORY_ALLOC_FAILED;
2648 goto cleanup_allocation;
2649 }
2650 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2651 }
2652
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002653 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002654 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002656 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657
2658 found_devs++;
2659 }
2660
2661cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002662 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
2664 if (rval != QLA_SUCCESS) {
2665 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 }
2668
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669 return (rval);
2670}
2671
2672static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002673qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002674{
2675#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002676 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2677 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002678 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002679 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002681
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002682 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002683 return;
2684
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002685 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2686 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002687 return;
2688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002690 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002691 if (rval != QLA_SUCCESS) {
2692 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2693 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002695 fcport->port_name[2], fcport->port_name[3],
2696 fcport->port_name[4], fcport->port_name[5],
2697 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002698 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002699 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002700 link_speed = link_speeds[LS_UNKNOWN];
2701 if (fcport->fp_speed < 5)
2702 link_speed = link_speeds[fcport->fp_speed];
2703 else if (fcport->fp_speed == 0x13)
2704 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002705 DEBUG2(qla_printk(KERN_INFO, ha,
2706 "iIDMA adjusted to %s GB/s on "
2707 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002708 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002709 fcport->port_name[1], fcport->port_name[2],
2710 fcport->port_name[3], fcport->port_name[4],
2711 fcport->port_name[5], fcport->port_name[6],
2712 fcport->port_name[7]));
2713 }
2714}
2715
Adrian Bunk23be3312006-11-24 02:46:01 +01002716static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002718{
2719 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002720 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002722
Andrew Vasquezac280b62009-08-20 11:06:05 -07002723 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002724
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002725 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2726 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002727 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2728 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2729 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002730 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002731 if (!rport) {
2732 qla_printk(KERN_WARNING, ha,
2733 "Unable to allocate fc remote port!\n");
2734 return;
2735 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002737 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002738 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002739
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002740 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002741
2742 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002743 if (fcport->port_type == FCT_INITIATOR)
2744 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2745 if (fcport->port_type == FCT_TARGET)
2746 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002747 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002748}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
2750/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002751 * qla2x00_update_fcport
2752 * Updates device on list.
2753 *
2754 * Input:
2755 * ha = adapter block pointer.
2756 * fcport = port structure pointer.
2757 *
2758 * Return:
2759 * 0 - Success
2760 * BIT_0 - error
2761 *
2762 * Context:
2763 * Kernel context.
2764 */
2765void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002767{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002768 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002769
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002771 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002773 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002774 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002775 PORT_RETRY_TIME);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002776 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002777
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002779
2780 atomic_set(&fcport->state, FCS_ONLINE);
2781
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002782 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002783}
2784
2785/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 * qla2x00_configure_fabric
2787 * Setup SNS devices with loop ID's.
2788 *
2789 * Input:
2790 * ha = adapter block pointer.
2791 *
2792 * Returns:
2793 * 0 = success.
2794 * BIT_0 = error
2795 */
2796static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798{
2799 int rval, rval2;
2800 fc_port_t *fcport, *fcptemp;
2801 uint16_t next_loopid;
2802 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002803 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002805 struct qla_hw_data *ha = vha->hw;
2806 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807
2808 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002809 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002810 loop_id = NPH_F_PORT;
2811 else
2812 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002813 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 if (rval != QLA_SUCCESS) {
2815 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002818 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 return (QLA_SUCCESS);
2820 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002821 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
2823 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002824 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 if (rval2 == QLA_RSCNS_HANDLED) {
2826 /* No point doing the scan, just continue. */
2827 return (QLA_SUCCESS);
2828 }
2829 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002830 /* FDMI support. */
2831 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2833 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002834
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002836 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002837 loop_id = NPH_SNS;
2838 else
2839 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002841 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002842 if (mb[0] != MBS_COMMAND_COMPLETE) {
2843 DEBUG2(qla_printk(KERN_INFO, ha,
2844 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002845 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 mb[0], mb[1], mb[2], mb[6], mb[7]));
2847 return (QLA_SUCCESS);
2848 }
2849
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2851 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 /* EMPTY */
2853 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002854 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 /* EMPTY */
2858 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002861 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 /* EMPTY */
2863 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 "failed.\n", vha->host_no));
2865 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 /* EMPTY */
2867 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 }
2870 }
2871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 if (rval != QLA_SUCCESS)
2874 break;
2875
2876 /*
2877 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002878 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2881 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 break;
2883
2884 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2885 continue;
2886
2887 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002888 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002889 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002891 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 fcport->port_type != FCT_INITIATOR &&
2893 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002895 fcport->loop_id,
2896 fcport->d_id.b.domain,
2897 fcport->d_id.b.area,
2898 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 fcport->loop_id = FC_NO_LOOP_ID;
2900 }
2901 }
2902 }
2903
2904 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906
2907 /*
2908 * Scan through our port list and login entries that need to be
2909 * logged in.
2910 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002911 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2912 if (atomic_read(&vha->loop_down_timer) ||
2913 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 break;
2915
2916 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2917 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2918 continue;
2919
2920 if (fcport->loop_id == FC_NO_LOOP_ID) {
2921 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002922 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 if (rval != QLA_SUCCESS) {
2925 /* Ran out of IDs to use */
2926 break;
2927 }
2928 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002929 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 }
2932
2933 /* Exit if out of loop IDs. */
2934 if (rval != QLA_SUCCESS) {
2935 break;
2936 }
2937
2938 /*
2939 * Login and add the new devices to our port list.
2940 */
2941 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942 if (atomic_read(&vha->loop_down_timer) ||
2943 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 break;
2945
2946 /* Find a new loop ID to use. */
2947 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 if (rval != QLA_SUCCESS) {
2950 /* Ran out of IDs to use */
2951 break;
2952 }
2953
bdf79622005-04-17 15:06:53 -05002954 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002957 if (vha->vp_idx) {
2958 fcport->vha = vha;
2959 fcport->vp_idx = vha->vp_idx;
2960 }
2961 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 }
2963 } while (0);
2964
2965 /* Free all new device structures not processed. */
2966 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2967 list_del(&fcport->list);
2968 kfree(fcport);
2969 }
2970
2971 if (rval) {
2972 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 }
2975
2976 return (rval);
2977}
2978
2979
2980/*
2981 * qla2x00_find_all_fabric_devs
2982 *
2983 * Input:
2984 * ha = adapter block pointer.
2985 * dev = database device entry pointer.
2986 *
2987 * Returns:
2988 * 0 = success.
2989 *
2990 * Context:
2991 * Kernel context.
2992 */
2993static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002994qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2995 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002996{
2997 int rval;
2998 uint16_t loop_id;
2999 fc_port_t *fcport, *new_fcport, *fcptemp;
3000 int found;
3001
3002 sw_info_t *swl;
3003 int swl_idx;
3004 int first_dev, last_dev;
3005 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 struct qla_hw_data *ha = vha->hw;
3007 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003008 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009
3010 rval = QLA_SUCCESS;
3011
3012 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07003013 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02003014 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 /*EMPTY*/
3016 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 kfree(swl);
3021 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 kfree(swl);
3024 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 kfree(swl);
3027 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003028 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003029 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3030 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 }
3032 }
3033 swl_idx = 0;
3034
3035 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003038 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 return (QLA_MEMORY_ALLOC_FAILED);
3040 }
3041 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 /* Set start port ID scan at adapter ID. */
3043 first_dev = 1;
3044 last_dev = 0;
3045
3046 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 loop_id = ha->min_external_loopid;
3048 for (; loop_id <= ha->max_loop_id; loop_id++) {
3049 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 continue;
3051
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003052 if (atomic_read(&vha->loop_down_timer) ||
3053 LOOP_TRANSITION(vha)) {
3054 atomic_set(&vha->loop_down_timer, 0);
3055 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3056 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003058 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059
3060 if (swl != NULL) {
3061 if (last_dev) {
3062 wrap.b24 = new_fcport->d_id.b24;
3063 } else {
3064 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3065 memcpy(new_fcport->node_name,
3066 swl[swl_idx].node_name, WWN_SIZE);
3067 memcpy(new_fcport->port_name,
3068 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003069 memcpy(new_fcport->fabric_port_name,
3070 swl[swl_idx].fabric_port_name, WWN_SIZE);
3071 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072
3073 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3074 last_dev = 1;
3075 }
3076 swl_idx++;
3077 }
3078 } else {
3079 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 if (rval != QLA_SUCCESS) {
3082 qla_printk(KERN_WARNING, ha,
3083 "SNS scan failed -- assuming zero-entry "
3084 "result...\n");
3085 list_for_each_entry_safe(fcport, fcptemp,
3086 new_fcports, list) {
3087 list_del(&fcport->list);
3088 kfree(fcport);
3089 }
3090 rval = QLA_SUCCESS;
3091 break;
3092 }
3093 }
3094
3095 /* If wrap on switch device list, exit. */
3096 if (first_dev) {
3097 wrap.b24 = new_fcport->d_id.b24;
3098 first_dev = 0;
3099 } else if (new_fcport->d_id.b24 == wrap.b24) {
3100 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003101 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3103 break;
3104 }
3105
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003106 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003107 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 continue;
3109
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003110 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003111 found = 0;
3112 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003113 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003114 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3115 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003116 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003117 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003118 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003119 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003120 continue;
3121 }
3122
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003123 /* Bypass if same domain and area of adapter. */
3124 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003126 ISP_CFG_FL)
3127 continue;
3128
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129 /* Bypass reserved domain fields. */
3130 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3131 continue;
3132
3133 /* Locate matching device in database. */
3134 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 if (memcmp(new_fcport->port_name, fcport->port_name,
3137 WWN_SIZE))
3138 continue;
3139
3140 found++;
3141
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003142 /* Update port state. */
3143 memcpy(fcport->fabric_port_name,
3144 new_fcport->fabric_port_name, WWN_SIZE);
3145 fcport->fp_speed = new_fcport->fp_speed;
3146
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 /*
3148 * If address the same and state FCS_ONLINE, nothing
3149 * changed.
3150 */
3151 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3152 atomic_read(&fcport->state) == FCS_ONLINE) {
3153 break;
3154 }
3155
3156 /*
3157 * If device was not a fabric device before.
3158 */
3159 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3160 fcport->d_id.b24 = new_fcport->d_id.b24;
3161 fcport->loop_id = FC_NO_LOOP_ID;
3162 fcport->flags |= (FCF_FABRIC_DEVICE |
3163 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003164 break;
3165 }
3166
3167 /*
3168 * Port ID changed or device was marked to be updated;
3169 * Log it out if still logged in and mark it for
3170 * relogin later.
3171 */
3172 fcport->d_id.b24 = new_fcport->d_id.b24;
3173 fcport->flags |= FCF_LOGIN_NEEDED;
3174 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003175 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 fcport->port_type != FCT_INITIATOR &&
3177 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003178 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003179 fcport->d_id.b.domain, fcport->d_id.b.area,
3180 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 fcport->loop_id = FC_NO_LOOP_ID;
3182 }
3183
3184 break;
3185 }
3186
3187 if (found)
3188 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189 /* If device was not in our fcports list, then add it. */
3190 list_add_tail(&new_fcport->list, new_fcports);
3191
3192 /* Allocate a new replacement fcport. */
3193 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003194 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003196 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003197 return (QLA_MEMORY_ALLOC_FAILED);
3198 }
3199 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3200 new_fcport->d_id.b24 = nxt_d_id.b24;
3201 }
3202
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003203 kfree(swl);
3204 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 return (rval);
3207}
3208
3209/*
3210 * qla2x00_find_new_loop_id
3211 * Scan through our port list and find a new usable loop ID.
3212 *
3213 * Input:
3214 * ha: adapter state pointer.
3215 * dev: port structure pointer.
3216 *
3217 * Returns:
3218 * qla2x00 local function return status code.
3219 *
3220 * Context:
3221 * Kernel context.
3222 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003223static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225{
3226 int rval;
3227 int found;
3228 fc_port_t *fcport;
3229 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230 struct qla_hw_data *ha = vha->hw;
3231 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003232 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233
3234 rval = QLA_SUCCESS;
3235
3236 /* Save starting loop ID. */
3237 first_loop_id = dev->loop_id;
3238
3239 for (;;) {
3240 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003241 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
3244 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
3248 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 /* first loop ID. */
3251 dev->loop_id = ha->min_external_loopid;
3252 }
3253
3254 /* Check for loop ID being already in use. */
3255 found = 0;
3256 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003257 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003258 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3259 if (fcport->loop_id == dev->loop_id &&
3260 fcport != dev) {
3261 /* ID possibly in use */
3262 found++;
3263 break;
3264 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266 if (found)
3267 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 }
3269
3270 /* If not in use then it is free to use. */
3271 if (!found) {
3272 break;
3273 }
3274
3275 /* ID in use. Try next value. */
3276 dev->loop_id++;
3277
3278 /* If wrap around. No free ID to use. */
3279 if (dev->loop_id == first_loop_id) {
3280 dev->loop_id = FC_NO_LOOP_ID;
3281 rval = QLA_FUNCTION_FAILED;
3282 break;
3283 }
3284 }
3285
3286 return (rval);
3287}
3288
3289/*
3290 * qla2x00_device_resync
3291 * Marks devices in the database that needs resynchronization.
3292 *
3293 * Input:
3294 * ha = adapter block pointer.
3295 *
3296 * Context:
3297 * Kernel context.
3298 */
3299static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301{
3302 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 uint32_t mask;
3304 fc_port_t *fcport;
3305 uint32_t rscn_entry;
3306 uint8_t rscn_out_iter;
3307 uint8_t format;
3308 port_id_t d_id;
3309
3310 rval = QLA_RSCNS_HANDLED;
3311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3313 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 format = MSB(MSW(rscn_entry));
3317 d_id.b.domain = LSB(MSW(rscn_entry));
3318 d_id.b.area = MSB(LSW(rscn_entry));
3319 d_id.b.al_pa = LSB(LSW(rscn_entry));
3320
3321 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3322 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 d_id.b.area, d_id.b.al_pa));
3325
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003326 vha->rscn_out_ptr++;
3327 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3328 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
3330 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003331 for (rscn_out_iter = vha->rscn_out_ptr;
3332 !vha->flags.rscn_queue_overflow &&
3333 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 rscn_out_iter = (rscn_out_iter ==
3335 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3336
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003337 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 break;
3339
3340 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 rscn_out_iter));
3343
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003344 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 }
3346
3347 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351
3352 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003353 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 }
3355
3356 switch (format) {
3357 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 mask = 0xffffff;
3359 break;
3360 case 1:
3361 mask = 0xffff00;
3362 break;
3363 case 2:
3364 mask = 0xff0000;
3365 break;
3366 default:
3367 mask = 0x0;
3368 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 break;
3371 }
3372
3373 rval = QLA_SUCCESS;
3374
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003375 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3377 (fcport->d_id.b24 & mask) != d_id.b24 ||
3378 fcport->port_type == FCT_BROADCAST)
3379 continue;
3380
3381 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3382 if (format != 3 ||
3383 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003385 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 }
3387 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 }
3389 }
3390 return (rval);
3391}
3392
3393/*
3394 * qla2x00_fabric_dev_login
3395 * Login fabric target device and update FC port database.
3396 *
3397 * Input:
3398 * ha: adapter state pointer.
3399 * fcport: port structure list pointer.
3400 * next_loopid: contains value of a new loop ID that can be used
3401 * by the next login attempt.
3402 *
3403 * Returns:
3404 * qla2x00 local function return status code.
3405 *
3406 * Context:
3407 * Kernel context.
3408 */
3409static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 uint16_t *next_loopid)
3412{
3413 int rval;
3414 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003415 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417
3418 rval = QLA_SUCCESS;
3419 retry = 0;
3420
Andrew Vasquezac280b62009-08-20 11:06:05 -07003421 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003422 if (fcport->flags & FCF_ASYNC_SENT)
3423 return rval;
3424 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003425 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3426 if (!rval)
3427 return rval;
3428 }
3429
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003430 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003431 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003433 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003434 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003435 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003436 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003437 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003440 fcport->d_id.b.domain, fcport->d_id.b.area,
3441 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003442 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003444 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 }
3446 }
3447
3448 return (rval);
3449}
3450
3451/*
3452 * qla2x00_fabric_login
3453 * Issue fabric login command.
3454 *
3455 * Input:
3456 * ha = adapter block pointer.
3457 * device = pointer to FC device type structure.
3458 *
3459 * Returns:
3460 * 0 - Login successfully
3461 * 1 - Login failed
3462 * 2 - Initiator device
3463 * 3 - Fatal error
3464 */
3465int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003466qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 uint16_t *next_loopid)
3468{
3469 int rval;
3470 int retry;
3471 uint16_t tmp_loopid;
3472 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
3475 retry = 0;
3476 tmp_loopid = 0;
3477
3478 for (;;) {
3479 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3480 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3483
3484 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003485 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 fcport->d_id.b.domain, fcport->d_id.b.area,
3487 fcport->d_id.b.al_pa, mb, BIT_0);
3488 if (mb[0] == MBS_PORT_ID_USED) {
3489 /*
3490 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003491 * recommends the driver perform an implicit login with
3492 * the specified ID again. The ID we just used is save
3493 * here so we return with an ID that can be tried by
3494 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003495 */
3496 retry++;
3497 tmp_loopid = fcport->loop_id;
3498 fcport->loop_id = mb[1];
3499
3500 DEBUG(printk("Fabric Login: port in use - next "
3501 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3502 fcport->loop_id, fcport->d_id.b.domain,
3503 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3504
3505 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3506 /*
3507 * Login succeeded.
3508 */
3509 if (retry) {
3510 /* A retry occurred before. */
3511 *next_loopid = tmp_loopid;
3512 } else {
3513 /*
3514 * No retry occurred before. Just increment the
3515 * ID value for next login.
3516 */
3517 *next_loopid = (fcport->loop_id + 1);
3518 }
3519
3520 if (mb[1] & BIT_0) {
3521 fcport->port_type = FCT_INITIATOR;
3522 } else {
3523 fcport->port_type = FCT_TARGET;
3524 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003525 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526 }
3527 }
3528
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003529 if (mb[10] & BIT_0)
3530 fcport->supported_classes |= FC_COS_CLASS2;
3531 if (mb[10] & BIT_1)
3532 fcport->supported_classes |= FC_COS_CLASS3;
3533
Linus Torvalds1da177e2005-04-16 15:20:36 -07003534 rval = QLA_SUCCESS;
3535 break;
3536 } else if (mb[0] == MBS_LOOP_ID_USED) {
3537 /*
3538 * Loop ID already used, try next loop ID.
3539 */
3540 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542 if (rval != QLA_SUCCESS) {
3543 /* Ran out of loop IDs to use */
3544 break;
3545 }
3546 } else if (mb[0] == MBS_COMMAND_ERROR) {
3547 /*
3548 * Firmware possibly timed out during login. If NO
3549 * retries are left to do then the device is declared
3550 * dead.
3551 */
3552 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003553 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003554 fcport->d_id.b.domain, fcport->d_id.b.area,
3555 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557
3558 rval = 1;
3559 break;
3560 } else {
3561 /*
3562 * unrecoverable / not handled error
3563 */
3564 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003565 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003566 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 fcport->d_id.b.domain, fcport->d_id.b.area,
3568 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3569
3570 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003571 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003572 fcport->d_id.b.domain, fcport->d_id.b.area,
3573 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003574 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003575 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576
3577 rval = 3;
3578 break;
3579 }
3580 }
3581
3582 return (rval);
3583}
3584
3585/*
3586 * qla2x00_local_device_login
3587 * Issue local device login command.
3588 *
3589 * Input:
3590 * ha = adapter block pointer.
3591 * loop_id = loop id of device to login to.
3592 *
3593 * Returns (Where's the #define!!!!):
3594 * 0 - Login successfully
3595 * 1 - Login failed
3596 * 3 - Fatal error
3597 */
3598int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003599qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600{
3601 int rval;
3602 uint16_t mb[MAILBOX_REGISTER_COUNT];
3603
3604 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003605 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003606 if (rval == QLA_SUCCESS) {
3607 /* Interrogate mailbox registers for any errors */
3608 if (mb[0] == MBS_COMMAND_ERROR)
3609 rval = 1;
3610 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3611 /* device not in PCB table */
3612 rval = 3;
3613 }
3614
3615 return (rval);
3616}
3617
3618/*
3619 * qla2x00_loop_resync
3620 * Resync with fibre channel devices.
3621 *
3622 * Input:
3623 * ha = adapter block pointer.
3624 *
3625 * Returns:
3626 * 0 = success
3627 */
3628int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003629qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003630{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003631 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003632 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003633 struct req_que *req;
3634 struct rsp_que *rsp;
3635
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003636 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003637 req = vha->hw->req_q_map[0];
3638 else
3639 req = vha->req;
3640 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003641
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003642 atomic_set(&vha->loop_state, LOOP_UPDATE);
3643 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3644 if (vha->flags.online) {
3645 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3647 wait_time = 256;
3648 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003649 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003651 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003652 qla2x00_marker(vha, req, rsp, 0, 0,
3653 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003654 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
3656 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003657 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003658
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003659 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003660 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003661 } while (!atomic_read(&vha->loop_down_timer) &&
3662 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3663 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3664 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666 }
3667
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003668 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003671 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003672 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673
3674 return (rval);
3675}
3676
Linus Torvalds1da177e2005-04-16 15:20:36 -07003677void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003678qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003679{
3680 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003681 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003682
3683 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003684 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3685 list_for_each_entry(fcport, &vha->vp_fcports, list)
3686 if (fcport && fcport->drport &&
3687 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3688 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003689}
3690
Giridhar Malavalia9083012010-04-12 17:59:55 -07003691void
3692qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3693{
3694 struct qla_hw_data *ha = vha->hw;
3695 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3696 struct scsi_qla_host *tvp;
3697
3698 vha->flags.online = 0;
3699 ha->flags.chip_reset_done = 0;
3700 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3701 ha->qla_stats.total_isp_aborts++;
3702
3703 qla_printk(KERN_INFO, ha,
3704 "Performing ISP error recovery - ha= %p.\n", ha);
3705
3706 /* Chip reset does not apply to 82XX */
3707 if (!IS_QLA82XX(ha))
3708 ha->isp_ops->reset_chip(vha);
3709
3710 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3711 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3712 atomic_set(&vha->loop_state, LOOP_DOWN);
3713 qla2x00_mark_all_devices_lost(vha, 0);
3714 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3715 qla2x00_mark_all_devices_lost(vp, 0);
3716 } else {
3717 if (!atomic_read(&vha->loop_down_timer))
3718 atomic_set(&vha->loop_down_timer,
3719 LOOP_DOWN_TIME);
3720 }
3721
3722 /* Make sure for ISP 82XX IO DMA is complete */
3723 if (IS_QLA82XX(ha))
3724 qla82xx_wait_for_pending_commands(vha);
3725
3726 /* Requeue all commands in outstanding command list. */
3727 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3728}
3729
Linus Torvalds1da177e2005-04-16 15:20:36 -07003730/*
3731* qla2x00_abort_isp
3732* Resets ISP and aborts all outstanding commands.
3733*
3734* Input:
3735* ha = adapter block pointer.
3736*
3737* Returns:
3738* 0 = success
3739*/
3740int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003741qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003743 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003744 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003745 struct qla_hw_data *ha = vha->hw;
3746 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003747 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003748 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003749
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003750 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003751 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752
Andrew Vasquez85880802009-12-15 21:29:46 -08003753 if (unlikely(pci_channel_offline(ha->pdev) &&
3754 ha->flags.pci_channel_io_perm_failure)) {
3755 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3756 status = 0;
3757 return status;
3758 }
3759
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003760 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003761
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003762 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003764 if (!qla2x00_restart_isp(vha)) {
3765 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003767 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768 /*
3769 * Issue marker command only when we are going
3770 * to start the I/O .
3771 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003772 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003773 }
3774
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003775 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003777 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003779 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003780 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003781
Lalit Chandivade29c53972009-10-13 15:16:47 -07003782 if (IS_QLA81XX(ha))
3783 qla2x00_get_fw_version(vha,
3784 &ha->fw_major_version,
3785 &ha->fw_minor_version,
3786 &ha->fw_subminor_version,
3787 &ha->fw_attributes, &ha->fw_memory_size,
3788 ha->mpi_version, &ha->mpi_capabilities,
3789 ha->phy_version);
3790
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003791 if (ha->fce) {
3792 ha->flags.fce_enabled = 1;
3793 memset(ha->fce, 0,
3794 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003795 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003796 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3797 &ha->fce_bufs);
3798 if (rval) {
3799 qla_printk(KERN_WARNING, ha,
3800 "Unable to reinitialize FCE "
3801 "(%d).\n", rval);
3802 ha->flags.fce_enabled = 0;
3803 }
3804 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003805
3806 if (ha->eft) {
3807 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003809 ha->eft_dma, EFT_NUM_BUFFERS);
3810 if (rval) {
3811 qla_printk(KERN_WARNING, ha,
3812 "Unable to reinitialize EFT "
3813 "(%d).\n", rval);
3814 }
3815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003817 vha->flags.online = 1;
3818 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003819 if (ha->isp_abort_cnt == 0) {
3820 qla_printk(KERN_WARNING, ha,
3821 "ISP error recovery failed - "
3822 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003823 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 * The next call disables the board
3825 * completely.
3826 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003827 ha->isp_ops->reset_adapter(vha);
3828 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003829 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 status = 0;
3832 } else { /* schedule another ISP abort */
3833 ha->isp_abort_cnt--;
3834 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003835 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003836 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003837 status = 1;
3838 }
3839 } else {
3840 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3841 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3842 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003843 vha->host_no, ha->isp_abort_cnt));
3844 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003845 status = 1;
3846 }
3847 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003848
Linus Torvalds1da177e2005-04-16 15:20:36 -07003849 }
3850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003851 if (!status) {
3852 DEBUG(printk(KERN_INFO
3853 "qla2x00_abort_isp(%ld): succeeded.\n",
3854 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003855 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 if (vp->vp_idx)
3857 qla2x00_vp_abort_isp(vp);
3858 }
3859 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 qla_printk(KERN_INFO, ha,
3861 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003862 }
3863
3864 return(status);
3865}
3866
3867/*
3868* qla2x00_restart_isp
3869* restarts the ISP after a reset
3870*
3871* Input:
3872* ha = adapter block pointer.
3873*
3874* Returns:
3875* 0 = success
3876*/
3877static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003878qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003879{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003880 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003883 struct req_que *req = ha->req_q_map[0];
3884 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003885
3886 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003887 if (qla2x00_isp_firmware(vha)) {
3888 vha->flags.online = 0;
3889 status = ha->isp_ops->chip_diag(vha);
3890 if (!status)
3891 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003892 }
3893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003894 if (!status && !(status = qla2x00_init_rings(vha))) {
3895 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003896 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003897 /* Initialize the queues in use */
3898 qla25xx_init_queues(ha);
3899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003900 status = qla2x00_fw_ready(vha);
3901 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003903 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003904
3905 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003906 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003907
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003909 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3910 wait_time = 256;
3911 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3913 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003914 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003915 } while (!atomic_read(&vha->loop_down_timer) &&
3916 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3917 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3918 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003919 }
3920
3921 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003923 status = 0;
3924
3925 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3926 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003927 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003928 }
3929 return (status);
3930}
3931
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003932static int
3933qla25xx_init_queues(struct qla_hw_data *ha)
3934{
3935 struct rsp_que *rsp = NULL;
3936 struct req_que *req = NULL;
3937 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3938 int ret = -1;
3939 int i;
3940
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003941 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003942 rsp = ha->rsp_q_map[i];
3943 if (rsp) {
3944 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003945 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003946 if (ret != QLA_SUCCESS)
3947 DEBUG2_17(printk(KERN_WARNING
3948 "%s Rsp que:%d init failed\n", __func__,
3949 rsp->id));
3950 else
3951 DEBUG2_17(printk(KERN_INFO
3952 "%s Rsp que:%d inited\n", __func__,
3953 rsp->id));
3954 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003955 }
3956 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003957 req = ha->req_q_map[i];
3958 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003959 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003960 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003961 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003962 if (ret != QLA_SUCCESS)
3963 DEBUG2_17(printk(KERN_WARNING
3964 "%s Req que:%d init failed\n", __func__,
3965 req->id));
3966 else
3967 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003968 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003969 req->id));
3970 }
3971 }
3972 return ret;
3973}
3974
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975/*
3976* qla2x00_reset_adapter
3977* Reset adapter.
3978*
3979* Input:
3980* ha = adapter block pointer.
3981*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003982void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003984{
3985 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003986 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003987 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003988
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003990 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003991
Linus Torvalds1da177e2005-04-16 15:20:36 -07003992 spin_lock_irqsave(&ha->hardware_lock, flags);
3993 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3994 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3995 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3996 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3997 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3998}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003999
4000void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004001qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004002{
4003 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004005 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
4006
Giridhar Malavalia9083012010-04-12 17:59:55 -07004007 if (IS_QLA82XX(ha))
4008 return;
4009
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07004011 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004012
4013 spin_lock_irqsave(&ha->hardware_lock, flags);
4014 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
4015 RD_REG_DWORD(&reg->hccr);
4016 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
4017 RD_REG_DWORD(&reg->hccr);
4018 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08004019
4020 if (IS_NOPOLLING_TYPE(ha))
4021 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004022}
4023
David Miller4e08df32007-04-16 12:37:43 -07004024/* On sparc systems, obtain port and node WWN from firmware
4025 * properties.
4026 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004027static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4028 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004029{
4030#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004031 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004032 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004033 struct device_node *dp = pci_device_to_OF_node(pdev);
4034 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004035 int len;
4036
4037 val = of_get_property(dp, "port-wwn", &len);
4038 if (val && len >= WWN_SIZE)
4039 memcpy(nv->port_name, val, WWN_SIZE);
4040
4041 val = of_get_property(dp, "node-wwn", &len);
4042 if (val && len >= WWN_SIZE)
4043 memcpy(nv->node_name, val, WWN_SIZE);
4044#endif
4045}
4046
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004047int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004048qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004049{
David Miller4e08df32007-04-16 12:37:43 -07004050 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004051 struct init_cb_24xx *icb;
4052 struct nvram_24xx *nv;
4053 uint32_t *dptr;
4054 uint8_t *dptr1, *dptr2;
4055 uint32_t chksum;
4056 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004058
David Miller4e08df32007-04-16 12:37:43 -07004059 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004060 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004061 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004062
4063 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004064 if (ha->flags.port0) {
4065 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4066 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4067 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004068 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004069 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4070 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004071 ha->nvram_size = sizeof(struct nvram_24xx);
4072 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004073 if (IS_QLA82XX(ha))
4074 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004075
Seokmann Ju281afe12007-07-26 13:43:34 -07004076 /* Get VPD data into cache */
4077 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004078 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004079 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4080
4081 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004082 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004083 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004084 ha->nvram_size);
4085 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4086 chksum += le32_to_cpu(*dptr++);
4087
Andrew Vasquez76403352009-04-06 22:33:39 -07004088 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004089 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004090
4091 /* Bad NVRAM data, set defaults parameters. */
4092 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4093 || nv->id[3] != ' ' ||
4094 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4095 /* Reset NVRAM data. */
4096 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4097 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4098 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004099 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4100 "invalid -- WWPN) defaults.\n");
4101
4102 /*
4103 * Set default initialization control block.
4104 */
4105 memset(nv, 0, ha->nvram_size);
4106 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4107 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4108 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4109 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4110 nv->exchange_count = __constant_cpu_to_le16(0);
4111 nv->hard_address = __constant_cpu_to_le16(124);
4112 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004113 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004114 nv->port_name[2] = 0x00;
4115 nv->port_name[3] = 0xe0;
4116 nv->port_name[4] = 0x8b;
4117 nv->port_name[5] = 0x1c;
4118 nv->port_name[6] = 0x55;
4119 nv->port_name[7] = 0x86;
4120 nv->node_name[0] = 0x20;
4121 nv->node_name[1] = 0x00;
4122 nv->node_name[2] = 0x00;
4123 nv->node_name[3] = 0xe0;
4124 nv->node_name[4] = 0x8b;
4125 nv->node_name[5] = 0x1c;
4126 nv->node_name[6] = 0x55;
4127 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004128 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004129 nv->login_retry_count = __constant_cpu_to_le16(8);
4130 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4131 nv->login_timeout = __constant_cpu_to_le16(0);
4132 nv->firmware_options_1 =
4133 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4134 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4135 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4136 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4137 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4138 nv->efi_parameters = __constant_cpu_to_le32(0);
4139 nv->reset_delay = 5;
4140 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4141 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4142 nv->link_down_timeout = __constant_cpu_to_le16(30);
4143
4144 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004145 }
4146
4147 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004149
4150 /* Copy 1st segment. */
4151 dptr1 = (uint8_t *)icb;
4152 dptr2 = (uint8_t *)&nv->version;
4153 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4154 while (cnt--)
4155 *dptr1++ = *dptr2++;
4156
4157 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004158 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004159
4160 /* Copy 2nd segment. */
4161 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4162 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4163 cnt = (uint8_t *)&icb->reserved_3 -
4164 (uint8_t *)&icb->interrupt_delay_timer;
4165 while (cnt--)
4166 *dptr1++ = *dptr2++;
4167
4168 /*
4169 * Setup driver NVRAM options.
4170 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004171 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004172 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004173
Andrew Vasquez5341e862006-05-17 15:09:16 -07004174 /* Use alternate WWN? */
4175 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4176 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4177 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4178 }
4179
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004180 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004181 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004182 /*
4183 * Firmware will apply the following mask if the nodename was
4184 * not provided.
4185 */
4186 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4187 icb->node_name[0] &= 0xF0;
4188 }
4189
4190 /* Set host adapter parameters. */
4191 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004192 ha->flags.enable_lip_reset = 0;
4193 ha->flags.enable_lip_full_login =
4194 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4195 ha->flags.enable_target_reset =
4196 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004197 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004198 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004199
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004200 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4201 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004202
4203 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4204 sizeof(ha->fw_seriallink_options24));
4205
4206 /* save HBA serial number */
4207 ha->serial0 = icb->port_name[5];
4208 ha->serial1 = icb->port_name[6];
4209 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004210 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4211 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004212
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004213 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4214
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004215 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4216
4217 /* Set minimum login_timeout to 4 seconds. */
4218 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4219 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4220 if (le16_to_cpu(nv->login_timeout) < 4)
4221 nv->login_timeout = __constant_cpu_to_le16(4);
4222 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004223 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004224
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004225 /* Set minimum RATOV to 100 tenths of a second. */
4226 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004227
4228 ha->loop_reset_delay = nv->reset_delay;
4229
4230 /* Link Down Timeout = 0:
4231 *
4232 * When Port Down timer expires we will start returning
4233 * I/O's to OS with "DID_NO_CONNECT".
4234 *
4235 * Link Down Timeout != 0:
4236 *
4237 * The driver waits for the link to come up after link down
4238 * before returning I/Os to OS with "DID_NO_CONNECT".
4239 */
4240 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4241 ha->loop_down_abort_time =
4242 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4243 } else {
4244 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4245 ha->loop_down_abort_time =
4246 (LOOP_DOWN_TIME - ha->link_down_timeout);
4247 }
4248
4249 /* Need enough time to try and get the port back. */
4250 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4251 if (qlport_down_retry)
4252 ha->port_down_retry_count = qlport_down_retry;
4253
4254 /* Set login_retry_count */
4255 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4256 if (ha->port_down_retry_count ==
4257 le16_to_cpu(nv->port_down_retry_count) &&
4258 ha->port_down_retry_count > 3)
4259 ha->login_retry_count = ha->port_down_retry_count;
4260 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4261 ha->login_retry_count = ha->port_down_retry_count;
4262 if (ql2xloginretrycount)
4263 ha->login_retry_count = ql2xloginretrycount;
4264
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004265 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004267 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4268 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4269 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4270 le16_to_cpu(icb->interrupt_delay_timer): 2;
4271 }
4272 icb->firmware_options_2 &= __constant_cpu_to_le32(
4273 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004274 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004275 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004276 ha->zio_mode = QLA_ZIO_MODE_6;
4277
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004278 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004279 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004280 ha->zio_timer * 100));
4281 qla_printk(KERN_INFO, ha,
4282 "ZIO mode %d enabled; timer delay (%d us).\n",
4283 ha->zio_mode, ha->zio_timer * 100);
4284
4285 icb->firmware_options_2 |= cpu_to_le32(
4286 (uint32_t)ha->zio_mode);
4287 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004288 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004289 }
4290
David Miller4e08df32007-04-16 12:37:43 -07004291 if (rval) {
4292 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004293 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004294 }
4295 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004296}
4297
Adrian Bunk413975a2006-06-30 02:33:06 -07004298static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004299qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4300 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004301{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004302 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004303 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004304 uint32_t *dcode, dlen;
4305 uint32_t risc_addr;
4306 uint32_t risc_size;
4307 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004308 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004309 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004310
4311 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004312 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004313
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004314 rval = QLA_SUCCESS;
4315
4316 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004317 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004318 *srisc_addr = 0;
4319
4320 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004321 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004322 for (i = 0; i < 4; i++)
4323 dcode[i] = be32_to_cpu(dcode[i]);
4324 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4325 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4326 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4327 dcode[3] == 0)) {
4328 qla_printk(KERN_WARNING, ha,
4329 "Unable to verify integrity of flash firmware image!\n");
4330 qla_printk(KERN_WARNING, ha,
4331 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4332 dcode[1], dcode[2], dcode[3]);
4333
4334 return QLA_FUNCTION_FAILED;
4335 }
4336
4337 while (segments && rval == QLA_SUCCESS) {
4338 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004339 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004340
4341 risc_addr = be32_to_cpu(dcode[2]);
4342 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4343 risc_size = be32_to_cpu(dcode[3]);
4344
4345 fragment = 0;
4346 while (risc_size > 0 && rval == QLA_SUCCESS) {
4347 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4348 if (dlen > risc_size)
4349 dlen = risc_size;
4350
4351 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4352 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004353 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004354
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004355 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004356 for (i = 0; i < dlen; i++)
4357 dcode[i] = swab32(dcode[i]);
4358
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004359 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004360 dlen);
4361 if (rval) {
4362 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004363 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004364 fragment));
4365 qla_printk(KERN_WARNING, ha,
4366 "[ERROR] Failed to load segment %d of "
4367 "firmware\n", fragment);
4368 break;
4369 }
4370
4371 faddr += dlen;
4372 risc_addr += dlen;
4373 risc_size -= dlen;
4374 fragment++;
4375 }
4376
4377 /* Next segment. */
4378 segments--;
4379 }
4380
4381 return rval;
4382}
4383
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004384#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4385
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004386int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004387qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004388{
4389 int rval;
4390 int i, fragment;
4391 uint16_t *wcode, *fwcode;
4392 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4393 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004394 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004395 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004396
4397 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004398 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004399 if (!blob) {
4400 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004401 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4402 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004403 return QLA_FUNCTION_FAILED;
4404 }
4405
4406 rval = QLA_SUCCESS;
4407
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004408 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004409 *srisc_addr = 0;
4410 fwcode = (uint16_t *)blob->fw->data;
4411 fwclen = 0;
4412
4413 /* Validate firmware image by checking version. */
4414 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4415 qla_printk(KERN_WARNING, ha,
4416 "Unable to verify integrity of firmware image (%Zd)!\n",
4417 blob->fw->size);
4418 goto fail_fw_integrity;
4419 }
4420 for (i = 0; i < 4; i++)
4421 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4422 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4423 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4424 wcode[2] == 0 && wcode[3] == 0)) {
4425 qla_printk(KERN_WARNING, ha,
4426 "Unable to verify integrity of firmware image!\n");
4427 qla_printk(KERN_WARNING, ha,
4428 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4429 wcode[1], wcode[2], wcode[3]);
4430 goto fail_fw_integrity;
4431 }
4432
4433 seg = blob->segs;
4434 while (*seg && rval == QLA_SUCCESS) {
4435 risc_addr = *seg;
4436 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4437 risc_size = be16_to_cpu(fwcode[3]);
4438
4439 /* Validate firmware image size. */
4440 fwclen += risc_size * sizeof(uint16_t);
4441 if (blob->fw->size < fwclen) {
4442 qla_printk(KERN_WARNING, ha,
4443 "Unable to verify integrity of firmware image "
4444 "(%Zd)!\n", blob->fw->size);
4445 goto fail_fw_integrity;
4446 }
4447
4448 fragment = 0;
4449 while (risc_size > 0 && rval == QLA_SUCCESS) {
4450 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4451 if (wlen > risc_size)
4452 wlen = risc_size;
4453
4454 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004455 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004456 risc_addr, wlen));
4457
4458 for (i = 0; i < wlen; i++)
4459 wcode[i] = swab16(fwcode[i]);
4460
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004461 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004462 wlen);
4463 if (rval) {
4464 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004465 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004466 fragment));
4467 qla_printk(KERN_WARNING, ha,
4468 "[ERROR] Failed to load segment %d of "
4469 "firmware\n", fragment);
4470 break;
4471 }
4472
4473 fwcode += wlen;
4474 risc_addr += wlen;
4475 risc_size -= wlen;
4476 fragment++;
4477 }
4478
4479 /* Next segment. */
4480 seg++;
4481 }
4482 return rval;
4483
4484fail_fw_integrity:
4485 return QLA_FUNCTION_FAILED;
4486}
4487
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004488static int
4489qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004490{
4491 int rval;
4492 int segments, fragment;
4493 uint32_t *dcode, dlen;
4494 uint32_t risc_addr;
4495 uint32_t risc_size;
4496 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004497 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004498 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004499 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004500 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004501
Andrew Vasquez54333832005-11-09 15:49:04 -08004502 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004503 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004504 if (!blob) {
4505 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004506 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4507 "from: " QLA_FW_URL ".\n");
4508
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004509 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004510 }
4511
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004512 qla_printk(KERN_INFO, ha,
4513 "FW: Loading via request-firmware...\n");
4514
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004515 rval = QLA_SUCCESS;
4516
4517 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004518 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004519 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004520 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004521 fwclen = 0;
4522
4523 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004524 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004525 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004526 "Unable to verify integrity of firmware image (%Zd)!\n",
4527 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004528 goto fail_fw_integrity;
4529 }
4530 for (i = 0; i < 4; i++)
4531 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4532 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4533 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4534 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4535 dcode[3] == 0)) {
4536 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004537 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004538 qla_printk(KERN_WARNING, ha,
4539 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4540 dcode[1], dcode[2], dcode[3]);
4541 goto fail_fw_integrity;
4542 }
4543
4544 while (segments && rval == QLA_SUCCESS) {
4545 risc_addr = be32_to_cpu(fwcode[2]);
4546 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4547 risc_size = be32_to_cpu(fwcode[3]);
4548
4549 /* Validate firmware image size. */
4550 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004551 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004552 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004553 "Unable to verify integrity of firmware image "
4554 "(%Zd)!\n", blob->fw->size);
4555
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004556 goto fail_fw_integrity;
4557 }
4558
4559 fragment = 0;
4560 while (risc_size > 0 && rval == QLA_SUCCESS) {
4561 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4562 if (dlen > risc_size)
4563 dlen = risc_size;
4564
4565 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004566 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004567 risc_addr, dlen));
4568
4569 for (i = 0; i < dlen; i++)
4570 dcode[i] = swab32(fwcode[i]);
4571
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004572 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004573 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004574 if (rval) {
4575 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004576 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004577 fragment));
4578 qla_printk(KERN_WARNING, ha,
4579 "[ERROR] Failed to load segment %d of "
4580 "firmware\n", fragment);
4581 break;
4582 }
4583
4584 fwcode += dlen;
4585 risc_addr += dlen;
4586 risc_size -= dlen;
4587 fragment++;
4588 }
4589
4590 /* Next segment. */
4591 segments--;
4592 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004593 return rval;
4594
4595fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004596 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004597}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004598
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004599int
4600qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4601{
4602 int rval;
4603
Andrew Vasqueze337d902009-04-06 22:33:49 -07004604 if (ql2xfwloadbin == 1)
4605 return qla81xx_load_risc(vha, srisc_addr);
4606
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004607 /*
4608 * FW Load priority:
4609 * 1) Firmware via request-firmware interface (.bin file).
4610 * 2) Firmware residing in flash.
4611 */
4612 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4613 if (rval == QLA_SUCCESS)
4614 return rval;
4615
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004616 return qla24xx_load_risc_flash(vha, srisc_addr,
4617 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004618}
4619
4620int
4621qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4622{
4623 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004624 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004625
Andrew Vasqueze337d902009-04-06 22:33:49 -07004626 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004627 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004628
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004629 /*
4630 * FW Load priority:
4631 * 1) Firmware residing in flash.
4632 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004633 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004634 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004635 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004636 if (rval == QLA_SUCCESS)
4637 return rval;
4638
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004639try_blob_fw:
4640 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4641 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4642 return rval;
4643
4644 qla_printk(KERN_ERR, ha,
4645 "FW: Attempting to fallback to golden firmware...\n");
4646 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4647 if (rval != QLA_SUCCESS)
4648 return rval;
4649
4650 qla_printk(KERN_ERR, ha,
4651 "FW: Please update operational firmware...\n");
4652 ha->flags.running_gold_fw = 1;
4653
4654 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004655}
4656
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004657void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004658qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004659{
4660 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004661 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004662
Andrew Vasquez85880802009-12-15 21:29:46 -08004663 if (ha->flags.pci_channel_io_perm_failure)
4664 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004665 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004666 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004667 if (!ha->fw_major_version)
4668 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004670 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004671 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004672 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004673 ha->isp_ops->reset_chip(vha);
4674 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004675 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004676 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004677 continue;
4678 qla_printk(KERN_INFO, ha,
4679 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004680 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004681 }
4682}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004683
4684int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004685qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004686{
4687 int rval = QLA_SUCCESS;
4688 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004689 struct qla_hw_data *ha = vha->hw;
4690 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004691 struct req_que *req;
4692 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004693
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004694 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004695 return -EINVAL;
4696
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004697 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004698 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004699 req = ha->req_q_map[0];
4700 else
4701 req = vha->req;
4702 rsp = req->rsp;
4703
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004704 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004705 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004706 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004707 }
4708
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004709 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004710
4711 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004712 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004713 if (mb[0] != MBS_COMMAND_COMPLETE) {
4714 DEBUG15(qla_printk(KERN_INFO, ha,
4715 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4716 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4717 mb[0], mb[1], mb[2], mb[6], mb[7]));
4718 return (QLA_FUNCTION_FAILED);
4719 }
4720
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004721 atomic_set(&vha->loop_down_timer, 0);
4722 atomic_set(&vha->loop_state, LOOP_UP);
4723 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4724 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4725 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004726
4727 return rval;
4728}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004729
4730/* 84XX Support **************************************************************/
4731
4732static LIST_HEAD(qla_cs84xx_list);
4733static DEFINE_MUTEX(qla_cs84xx_mutex);
4734
4735static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004736qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004737{
4738 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004739 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004740
4741 mutex_lock(&qla_cs84xx_mutex);
4742
4743 /* Find any shared 84xx chip. */
4744 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4745 if (cs84xx->bus == ha->pdev->bus) {
4746 kref_get(&cs84xx->kref);
4747 goto done;
4748 }
4749 }
4750
4751 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4752 if (!cs84xx)
4753 goto done;
4754
4755 kref_init(&cs84xx->kref);
4756 spin_lock_init(&cs84xx->access_lock);
4757 mutex_init(&cs84xx->fw_update_mutex);
4758 cs84xx->bus = ha->pdev->bus;
4759
4760 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4761done:
4762 mutex_unlock(&qla_cs84xx_mutex);
4763 return cs84xx;
4764}
4765
4766static void
4767__qla84xx_chip_release(struct kref *kref)
4768{
4769 struct qla_chip_state_84xx *cs84xx =
4770 container_of(kref, struct qla_chip_state_84xx, kref);
4771
4772 mutex_lock(&qla_cs84xx_mutex);
4773 list_del(&cs84xx->list);
4774 mutex_unlock(&qla_cs84xx_mutex);
4775 kfree(cs84xx);
4776}
4777
4778void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004779qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004780{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004781 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004782 if (ha->cs84xx)
4783 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4784}
4785
4786static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004787qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004788{
4789 int rval;
4790 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004791 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004792
4793 mutex_lock(&ha->cs84xx->fw_update_mutex);
4794
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004795 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004796
4797 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4798
4799 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4800 QLA_SUCCESS;
4801}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004802
4803/* 81XX Support **************************************************************/
4804
4805int
4806qla81xx_nvram_config(scsi_qla_host_t *vha)
4807{
4808 int rval;
4809 struct init_cb_81xx *icb;
4810 struct nvram_81xx *nv;
4811 uint32_t *dptr;
4812 uint8_t *dptr1, *dptr2;
4813 uint32_t chksum;
4814 uint16_t cnt;
4815 struct qla_hw_data *ha = vha->hw;
4816
4817 rval = QLA_SUCCESS;
4818 icb = (struct init_cb_81xx *)ha->init_cb;
4819 nv = ha->nvram;
4820
4821 /* Determine NVRAM starting address. */
4822 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004823 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004824
4825 /* Get VPD data into cache */
4826 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004827 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4828 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004829
4830 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004831 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004832 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004833 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004834 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4835 chksum += le32_to_cpu(*dptr++);
4836
Andrew Vasquez76403352009-04-06 22:33:39 -07004837 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004838 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4839
4840 /* Bad NVRAM data, set defaults parameters. */
4841 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4842 || nv->id[3] != ' ' ||
4843 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4844 /* Reset NVRAM data. */
4845 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4846 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4847 le16_to_cpu(nv->nvram_version));
4848 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4849 "invalid -- WWPN) defaults.\n");
4850
4851 /*
4852 * Set default initialization control block.
4853 */
4854 memset(nv, 0, ha->nvram_size);
4855 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4856 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4857 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4858 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4859 nv->exchange_count = __constant_cpu_to_le16(0);
4860 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004861 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004862 nv->port_name[2] = 0x00;
4863 nv->port_name[3] = 0xe0;
4864 nv->port_name[4] = 0x8b;
4865 nv->port_name[5] = 0x1c;
4866 nv->port_name[6] = 0x55;
4867 nv->port_name[7] = 0x86;
4868 nv->node_name[0] = 0x20;
4869 nv->node_name[1] = 0x00;
4870 nv->node_name[2] = 0x00;
4871 nv->node_name[3] = 0xe0;
4872 nv->node_name[4] = 0x8b;
4873 nv->node_name[5] = 0x1c;
4874 nv->node_name[6] = 0x55;
4875 nv->node_name[7] = 0x86;
4876 nv->login_retry_count = __constant_cpu_to_le16(8);
4877 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4878 nv->login_timeout = __constant_cpu_to_le16(0);
4879 nv->firmware_options_1 =
4880 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4881 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4882 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4883 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4884 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4885 nv->efi_parameters = __constant_cpu_to_le32(0);
4886 nv->reset_delay = 5;
4887 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4888 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4889 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004890 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004891 nv->enode_mac[1] = 0x02;
4892 nv->enode_mac[2] = 0x03;
4893 nv->enode_mac[3] = 0x04;
4894 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004895 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004896
4897 rval = 1;
4898 }
4899
4900 /* Reset Initialization control block */
4901 memset(icb, 0, sizeof(struct init_cb_81xx));
4902
4903 /* Copy 1st segment. */
4904 dptr1 = (uint8_t *)icb;
4905 dptr2 = (uint8_t *)&nv->version;
4906 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4907 while (cnt--)
4908 *dptr1++ = *dptr2++;
4909
4910 icb->login_retry_count = nv->login_retry_count;
4911
4912 /* Copy 2nd segment. */
4913 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4914 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4915 cnt = (uint8_t *)&icb->reserved_5 -
4916 (uint8_t *)&icb->interrupt_delay_timer;
4917 while (cnt--)
4918 *dptr1++ = *dptr2++;
4919
4920 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4921 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4922 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4923 icb->enode_mac[0] = 0x01;
4924 icb->enode_mac[1] = 0x02;
4925 icb->enode_mac[2] = 0x03;
4926 icb->enode_mac[3] = 0x04;
4927 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004928 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004929 }
4930
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004931 /* Use extended-initialization control block. */
4932 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4933
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004934 /*
4935 * Setup driver NVRAM options.
4936 */
4937 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07004938 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004939
4940 /* Use alternate WWN? */
4941 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4942 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4943 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4944 }
4945
4946 /* Prepare nodename */
4947 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4948 /*
4949 * Firmware will apply the following mask if the nodename was
4950 * not provided.
4951 */
4952 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4953 icb->node_name[0] &= 0xF0;
4954 }
4955
4956 /* Set host adapter parameters. */
4957 ha->flags.disable_risc_code_load = 0;
4958 ha->flags.enable_lip_reset = 0;
4959 ha->flags.enable_lip_full_login =
4960 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4961 ha->flags.enable_target_reset =
4962 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4963 ha->flags.enable_led_scheme = 0;
4964 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4965
4966 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4967 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4968
4969 /* save HBA serial number */
4970 ha->serial0 = icb->port_name[5];
4971 ha->serial1 = icb->port_name[6];
4972 ha->serial2 = icb->port_name[7];
4973 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4974 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4975
4976 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4977
4978 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4979
4980 /* Set minimum login_timeout to 4 seconds. */
4981 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4982 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4983 if (le16_to_cpu(nv->login_timeout) < 4)
4984 nv->login_timeout = __constant_cpu_to_le16(4);
4985 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4986 icb->login_timeout = nv->login_timeout;
4987
4988 /* Set minimum RATOV to 100 tenths of a second. */
4989 ha->r_a_tov = 100;
4990
4991 ha->loop_reset_delay = nv->reset_delay;
4992
4993 /* Link Down Timeout = 0:
4994 *
4995 * When Port Down timer expires we will start returning
4996 * I/O's to OS with "DID_NO_CONNECT".
4997 *
4998 * Link Down Timeout != 0:
4999 *
5000 * The driver waits for the link to come up after link down
5001 * before returning I/Os to OS with "DID_NO_CONNECT".
5002 */
5003 if (le16_to_cpu(nv->link_down_timeout) == 0) {
5004 ha->loop_down_abort_time =
5005 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
5006 } else {
5007 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
5008 ha->loop_down_abort_time =
5009 (LOOP_DOWN_TIME - ha->link_down_timeout);
5010 }
5011
5012 /* Need enough time to try and get the port back. */
5013 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
5014 if (qlport_down_retry)
5015 ha->port_down_retry_count = qlport_down_retry;
5016
5017 /* Set login_retry_count */
5018 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
5019 if (ha->port_down_retry_count ==
5020 le16_to_cpu(nv->port_down_retry_count) &&
5021 ha->port_down_retry_count > 3)
5022 ha->login_retry_count = ha->port_down_retry_count;
5023 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5024 ha->login_retry_count = ha->port_down_retry_count;
5025 if (ql2xloginretrycount)
5026 ha->login_retry_count = ql2xloginretrycount;
5027
5028 /* Enable ZIO. */
5029 if (!vha->flags.init_done) {
5030 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5031 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5032 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5033 le16_to_cpu(icb->interrupt_delay_timer): 2;
5034 }
5035 icb->firmware_options_2 &= __constant_cpu_to_le32(
5036 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5037 vha->flags.process_response_queue = 0;
5038 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5039 ha->zio_mode = QLA_ZIO_MODE_6;
5040
5041 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5042 "(%d us).\n", vha->host_no, ha->zio_mode,
5043 ha->zio_timer * 100));
5044 qla_printk(KERN_INFO, ha,
5045 "ZIO mode %d enabled; timer delay (%d us).\n",
5046 ha->zio_mode, ha->zio_timer * 100);
5047
5048 icb->firmware_options_2 |= cpu_to_le32(
5049 (uint32_t)ha->zio_mode);
5050 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5051 vha->flags.process_response_queue = 1;
5052 }
5053
5054 if (rval) {
5055 DEBUG2_3(printk(KERN_WARNING
5056 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5057 }
5058 return (rval);
5059}
5060
Giridhar Malavalia9083012010-04-12 17:59:55 -07005061int
5062qla82xx_restart_isp(scsi_qla_host_t *vha)
5063{
5064 int status, rval;
5065 uint32_t wait_time;
5066 struct qla_hw_data *ha = vha->hw;
5067 struct req_que *req = ha->req_q_map[0];
5068 struct rsp_que *rsp = ha->rsp_q_map[0];
5069 struct scsi_qla_host *vp;
5070 struct scsi_qla_host *tvp;
5071
5072 status = qla2x00_init_rings(vha);
5073 if (!status) {
5074 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5075 ha->flags.chip_reset_done = 1;
5076
5077 status = qla2x00_fw_ready(vha);
5078 if (!status) {
5079 qla_printk(KERN_INFO, ha,
5080 "%s(): Start configure loop, "
5081 "status = %d\n", __func__, status);
5082
5083 /* Issue a marker after FW becomes ready. */
5084 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5085
5086 vha->flags.online = 1;
5087 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5088 wait_time = 256;
5089 do {
5090 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5091 qla2x00_configure_loop(vha);
5092 wait_time--;
5093 } while (!atomic_read(&vha->loop_down_timer) &&
5094 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5095 wait_time &&
5096 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5097 }
5098
5099 /* if no cable then assume it's good */
5100 if ((vha->device_flags & DFLG_NO_CABLE))
5101 status = 0;
5102
5103 qla_printk(KERN_INFO, ha,
5104 "%s(): Configure loop done, status = 0x%x\n",
5105 __func__, status);
5106 }
5107
5108 if (!status) {
5109 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5110
5111 if (!atomic_read(&vha->loop_down_timer)) {
5112 /*
5113 * Issue marker command only when we are going
5114 * to start the I/O .
5115 */
5116 vha->marker_needed = 1;
5117 }
5118
5119 vha->flags.online = 1;
5120
5121 ha->isp_ops->enable_intrs(ha);
5122
5123 ha->isp_abort_cnt = 0;
5124 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5125
5126 if (ha->fce) {
5127 ha->flags.fce_enabled = 1;
5128 memset(ha->fce, 0,
5129 fce_calc_size(ha->fce_bufs));
5130 rval = qla2x00_enable_fce_trace(vha,
5131 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5132 &ha->fce_bufs);
5133 if (rval) {
5134 qla_printk(KERN_WARNING, ha,
5135 "Unable to reinitialize FCE "
5136 "(%d).\n", rval);
5137 ha->flags.fce_enabled = 0;
5138 }
5139 }
5140
5141 if (ha->eft) {
5142 memset(ha->eft, 0, EFT_SIZE);
5143 rval = qla2x00_enable_eft_trace(vha,
5144 ha->eft_dma, EFT_NUM_BUFFERS);
5145 if (rval) {
5146 qla_printk(KERN_WARNING, ha,
5147 "Unable to reinitialize EFT "
5148 "(%d).\n", rval);
5149 }
5150 }
5151 } else { /* failed the ISP abort */
5152 vha->flags.online = 1;
5153 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
5154 if (ha->isp_abort_cnt == 0) {
5155 qla_printk(KERN_WARNING, ha,
5156 "ISP error recovery failed - "
5157 "board disabled\n");
5158 /*
5159 * The next call disables the board
5160 * completely.
5161 */
5162 ha->isp_ops->reset_adapter(vha);
5163 vha->flags.online = 0;
5164 clear_bit(ISP_ABORT_RETRY,
5165 &vha->dpc_flags);
5166 status = 0;
5167 } else { /* schedule another ISP abort */
5168 ha->isp_abort_cnt--;
5169 qla_printk(KERN_INFO, ha,
5170 "qla%ld: ISP abort - "
5171 "retry remaining %d\n",
5172 vha->host_no, ha->isp_abort_cnt);
5173 status = 1;
5174 }
5175 } else {
5176 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
5177 qla_printk(KERN_INFO, ha,
5178 "(%ld): ISP error recovery "
5179 "- retrying (%d) more times\n",
5180 vha->host_no, ha->isp_abort_cnt);
5181 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5182 status = 1;
5183 }
5184 }
5185
5186 if (!status) {
5187 DEBUG(printk(KERN_INFO
5188 "qla82xx_restart_isp(%ld): succeeded.\n",
5189 vha->host_no));
5190 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5191 if (vp->vp_idx)
5192 qla2x00_vp_abort_isp(vp);
5193 }
5194 } else {
5195 qla_printk(KERN_INFO, ha,
5196 "qla82xx_restart_isp: **** FAILED ****\n");
5197 }
5198
5199 return status;
5200}
5201
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005202void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005203qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005204{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005205 struct qla_hw_data *ha = vha->hw;
5206
5207 if (!ql2xetsenable)
5208 return;
5209
5210 /* Enable ETS Burst. */
5211 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5212 ha->fw_options[2] |= BIT_9;
5213 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005214}
Sarang Radke09ff7012010-03-19 17:03:59 -07005215
5216/*
5217 * qla24xx_get_fcp_prio
5218 * Gets the fcp cmd priority value for the logged in port.
5219 * Looks for a match of the port descriptors within
5220 * each of the fcp prio config entries. If a match is found,
5221 * the tag (priority) value is returned.
5222 *
5223 * Input:
5224 * ha = adapter block po
5225 * fcport = port structure pointer.
5226 *
5227 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005228 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005229 * 0 (if not found)
5230 *
5231 * Context:
5232 * Kernel context
5233 */
5234uint8_t
5235qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5236{
5237 int i, entries;
5238 uint8_t pid_match, wwn_match;
5239 uint8_t priority;
5240 uint32_t pid1, pid2;
5241 uint64_t wwn1, wwn2;
5242 struct qla_fcp_prio_entry *pri_entry;
5243 struct qla_hw_data *ha = vha->hw;
5244
5245 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5246 return 0;
5247
5248 priority = 0;
5249 entries = ha->fcp_prio_cfg->num_entries;
5250 pri_entry = &ha->fcp_prio_cfg->entry[0];
5251
5252 for (i = 0; i < entries; i++) {
5253 pid_match = wwn_match = 0;
5254
5255 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5256 pri_entry++;
5257 continue;
5258 }
5259
5260 /* check source pid for a match */
5261 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5262 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5263 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5264 if (pid1 == INVALID_PORT_ID)
5265 pid_match++;
5266 else if (pid1 == pid2)
5267 pid_match++;
5268 }
5269
5270 /* check destination pid for a match */
5271 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5272 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5273 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5274 if (pid1 == INVALID_PORT_ID)
5275 pid_match++;
5276 else if (pid1 == pid2)
5277 pid_match++;
5278 }
5279
5280 /* check source WWN for a match */
5281 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5282 wwn1 = wwn_to_u64(vha->port_name);
5283 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5284 if (wwn2 == (uint64_t)-1)
5285 wwn_match++;
5286 else if (wwn1 == wwn2)
5287 wwn_match++;
5288 }
5289
5290 /* check destination WWN for a match */
5291 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5292 wwn1 = wwn_to_u64(fcport->port_name);
5293 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5294 if (wwn2 == (uint64_t)-1)
5295 wwn_match++;
5296 else if (wwn1 == wwn2)
5297 wwn_match++;
5298 }
5299
5300 if (pid_match == 2 || wwn_match == 2) {
5301 /* Found a matching entry */
5302 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5303 priority = pri_entry->tag;
5304 break;
5305 }
5306
5307 pri_entry++;
5308 }
5309
5310 return priority;
5311}
5312
5313/*
5314 * qla24xx_update_fcport_fcp_prio
5315 * Activates fcp priority for the logged in fc port
5316 *
5317 * Input:
5318 * ha = adapter block pointer.
5319 * fcp = port structure pointer.
5320 *
5321 * Return:
5322 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5323 *
5324 * Context:
5325 * Kernel context.
5326 */
5327int
5328qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5329{
5330 int ret;
5331 uint8_t priority;
5332 uint16_t mb[5];
5333
5334 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5335 fcport->port_type != FCT_TARGET ||
5336 fcport->loop_id == FC_NO_LOOP_ID)
5337 return QLA_FUNCTION_FAILED;
5338
5339 priority = qla24xx_get_fcp_prio(ha, fcport);
5340 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5341 if (ret == QLA_SUCCESS)
5342 fcport->fcp_prio = priority;
5343 else
5344 DEBUG2(printk(KERN_WARNING
5345 "scsi(%ld): Unable to activate fcp priority, "
5346 " ret=0x%x\n", ha->host_no, ret));
5347
5348 return ret;
5349}
5350
5351/*
5352 * qla24xx_update_all_fcp_prio
5353 * Activates fcp priority for all the logged in ports
5354 *
5355 * Input:
5356 * ha = adapter block pointer.
5357 *
5358 * Return:
5359 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5360 *
5361 * Context:
5362 * Kernel context.
5363 */
5364int
5365qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5366{
5367 int ret;
5368 fc_port_t *fcport;
5369
5370 ret = QLA_FUNCTION_FAILED;
5371 /* We need to set priority for all logged in ports */
5372 list_for_each_entry(fcport, &vha->vp_fcports, list)
5373 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5374
5375 return ret;
5376}