blob: 4e7a3d5493e66f8e7cdc779a74de8f03b6d9430c [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;
51 fc_port_t *fcport = sp->fcport;
52 struct qla_hw_data *ha = fcport->vha->hw;
53 struct req_que *req;
54 unsigned long flags;
55
56 spin_lock_irqsave(&ha->hardware_lock, flags);
57 req = ha->req_q_map[0];
58 req->outstanding_cmds[sp->handle] = NULL;
59 ctx = sp->ctx;
60 ctx->timeout(sp);
61 spin_unlock_irqrestore(&ha->hardware_lock, flags);
62
63 ctx->free(sp);
64}
65
Giridhar Malavali9a069e12010-01-12 13:02:47 -080066void
Andrew Vasquezac280b62009-08-20 11:06:05 -070067qla2x00_ctx_sp_free(srb_t *sp)
68{
69 struct srb_ctx *ctx = sp->ctx;
70
71 kfree(ctx);
72 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
73}
74
75inline srb_t *
76qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
77 unsigned long tmo)
78{
79 srb_t *sp;
80 struct qla_hw_data *ha = vha->hw;
81 struct srb_ctx *ctx;
82
83 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
84 if (!sp)
85 goto done;
86 ctx = kzalloc(size, GFP_KERNEL);
87 if (!ctx) {
88 mempool_free(sp, ha->srb_mempool);
89 goto done;
90 }
91
92 memset(sp, 0, sizeof(*sp));
93 sp->fcport = fcport;
94 sp->ctx = ctx;
95 ctx->free = qla2x00_ctx_sp_free;
96
97 init_timer(&ctx->timer);
98 if (!tmo)
99 goto done;
100 ctx->timer.expires = jiffies + tmo * HZ;
101 ctx->timer.data = (unsigned long)sp;
102 ctx->timer.function = qla2x00_ctx_sp_timeout;
103 add_timer(&ctx->timer);
104done:
105 return sp;
106}
107
108/* Asynchronous Login/Logout Routines -------------------------------------- */
109
110#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
111
112static void
113qla2x00_async_logio_timeout(srb_t *sp)
114{
115 fc_port_t *fcport = sp->fcport;
116 struct srb_logio *lio = sp->ctx;
117
118 DEBUG2(printk(KERN_WARNING
119 "scsi(%ld:%x): Async-%s timeout.\n",
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700120 fcport->vha->host_no, sp->handle, lio->ctx.name));
Andrew Vasquezac280b62009-08-20 11:06:05 -0700121
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700122 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700123 if (lio->ctx.type == SRB_LOGIN_CMD)
124 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
125}
126
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700127static void
128qla2x00_async_login_ctx_done(srb_t *sp)
129{
130 struct srb_logio *lio = sp->ctx;
131
132 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
133 lio->data);
134 lio->ctx.free(sp);
135}
136
Andrew Vasquezac280b62009-08-20 11:06:05 -0700137int
138qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
139 uint16_t *data)
140{
141 struct qla_hw_data *ha = vha->hw;
142 srb_t *sp;
143 struct srb_logio *lio;
144 int rval;
145
146 rval = QLA_FUNCTION_FAILED;
147 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
148 ELS_TMO_2_RATOV(ha) + 2);
149 if (!sp)
150 goto done;
151
152 lio = sp->ctx;
153 lio->ctx.type = SRB_LOGIN_CMD;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700154 lio->ctx.name = "login";
Andrew Vasquezac280b62009-08-20 11:06:05 -0700155 lio->ctx.timeout = qla2x00_async_logio_timeout;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700156 lio->ctx.done = qla2x00_async_login_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700157 lio->flags |= SRB_LOGIN_COND_PLOGI;
158 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
159 lio->flags |= SRB_LOGIN_RETRIED;
160 rval = qla2x00_start_sp(sp);
161 if (rval != QLA_SUCCESS)
162 goto done_free_sp;
163
164 DEBUG2(printk(KERN_DEBUG
165 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
166 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
167 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
168 fcport->login_retry));
169 return rval;
170
171done_free_sp:
172 del_timer_sync(&lio->ctx.timer);
173 lio->ctx.free(sp);
174done:
175 return rval;
176}
177
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700178static void
179qla2x00_async_logout_ctx_done(srb_t *sp)
180{
181 struct srb_logio *lio = sp->ctx;
182
183 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
184 lio->data);
185 lio->ctx.free(sp);
186}
187
Andrew Vasquezac280b62009-08-20 11:06:05 -0700188int
189qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
190{
191 struct qla_hw_data *ha = vha->hw;
192 srb_t *sp;
193 struct srb_logio *lio;
194 int rval;
195
196 rval = QLA_FUNCTION_FAILED;
197 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
198 ELS_TMO_2_RATOV(ha) + 2);
199 if (!sp)
200 goto done;
201
202 lio = sp->ctx;
203 lio->ctx.type = SRB_LOGOUT_CMD;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700204 lio->ctx.name = "logout";
Andrew Vasquezac280b62009-08-20 11:06:05 -0700205 lio->ctx.timeout = qla2x00_async_logio_timeout;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700206 lio->ctx.done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700207 rval = qla2x00_start_sp(sp);
208 if (rval != QLA_SUCCESS)
209 goto done_free_sp;
210
211 DEBUG2(printk(KERN_DEBUG
212 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
213 fcport->vha->host_no, sp->handle, fcport->loop_id,
214 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
215 return rval;
216
217done_free_sp:
218 del_timer_sync(&lio->ctx.timer);
219 lio->ctx.free(sp);
220done:
221 return rval;
222}
223
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700224static void
225qla2x00_async_adisc_ctx_done(srb_t *sp)
226{
227 struct srb_logio *lio = sp->ctx;
228
229 qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport,
230 lio->data);
231 lio->ctx.free(sp);
232}
233
234int
235qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
236 uint16_t *data)
237{
238 struct qla_hw_data *ha = vha->hw;
239 srb_t *sp;
240 struct srb_logio *lio;
241 int rval;
242
243 rval = QLA_FUNCTION_FAILED;
244 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
245 ELS_TMO_2_RATOV(ha) + 2);
246 if (!sp)
247 goto done;
248
249 lio = sp->ctx;
250 lio->ctx.type = SRB_ADISC_CMD;
251 lio->ctx.name = "adisc";
252 lio->ctx.timeout = qla2x00_async_logio_timeout;
253 lio->ctx.done = qla2x00_async_adisc_ctx_done;
254 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
255 lio->flags |= SRB_LOGIN_RETRIED;
256 rval = qla2x00_start_sp(sp);
257 if (rval != QLA_SUCCESS)
258 goto done_free_sp;
259
260 DEBUG2(printk(KERN_DEBUG
261 "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n",
262 fcport->vha->host_no, sp->handle, fcport->loop_id,
263 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
264
265 return rval;
266
267done_free_sp:
268 del_timer_sync(&lio->ctx.timer);
269 lio->ctx.free(sp);
270done:
271 return rval;
272}
273
Andrew Vasquezac280b62009-08-20 11:06:05 -0700274int
275qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
276 uint16_t *data)
277{
278 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700279
280 switch (data[0]) {
281 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700282 if (fcport->flags & FCF_FCP2_DEVICE) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700283 fcport->flags |= FCF_ASYNC_SENT;
284 qla2x00_post_async_adisc_work(vha, fcport, data);
285 break;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700286 }
287 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700288 break;
289 case MBS_COMMAND_ERROR:
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700290 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700291 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
292 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
293 else
294 qla2x00_mark_device_lost(vha, fcport, 1, 0);
295 break;
296 case MBS_PORT_ID_USED:
297 fcport->loop_id = data[1];
298 qla2x00_post_async_login_work(vha, fcport, NULL);
299 break;
300 case MBS_LOOP_ID_USED:
301 fcport->loop_id++;
302 rval = qla2x00_find_new_loop_id(vha, fcport);
303 if (rval != QLA_SUCCESS) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700304 fcport->flags &= ~FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700305 qla2x00_mark_device_lost(vha, fcport, 1, 0);
306 break;
307 }
308 qla2x00_post_async_login_work(vha, fcport, NULL);
309 break;
310 }
311 return QLA_SUCCESS;
312}
313
314int
315qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
316 uint16_t *data)
317{
318 qla2x00_mark_device_lost(vha, fcport, 1, 0);
319 return QLA_SUCCESS;
320}
321
Andrew Vasquez5ff1d582010-05-04 15:01:26 -0700322int
323qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
324 uint16_t *data)
325{
326 if (data[0] == MBS_COMMAND_COMPLETE) {
327 qla2x00_update_fcport(vha, fcport);
328
329 return QLA_SUCCESS;
330 }
331
332 /* Retry login. */
333 fcport->flags &= ~FCF_ASYNC_SENT;
334 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
335 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
336 else
337 qla2x00_mark_device_lost(vha, fcport, 1, 0);
338
339 return QLA_SUCCESS;
340}
341
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342/****************************************************************************/
343/* QLogic ISP2x00 Hardware Support Functions. */
344/****************************************************************************/
345
346/*
347* qla2x00_initialize_adapter
348* Initialize board.
349*
350* Input:
351* ha = adapter block pointer.
352*
353* Returns:
354* 0 = success
355*/
356int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800357qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358{
359 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800360 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800361 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700362
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800364 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700365 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800366 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800367 ha->flags.pci_channel_io_perm_failure = 0;
368 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800369 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
370 atomic_set(&vha->loop_state, LOOP_DOWN);
371 vha->device_flags = DFLG_NO_CABLE;
372 vha->dpc_flags = 0;
373 vha->flags.management_server_logged_in = 0;
374 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 ha->isp_abort_cnt = 0;
376 ha->beacon_blink_led = 0;
377
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800378 set_bit(0, ha->req_qid_map);
379 set_bit(0, ha->rsp_qid_map);
380
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700381 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800384 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800385 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386 return (rval);
387 }
388
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800389 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800391 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700392 if (rval) {
393 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800394 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700395 return (rval);
396 }
397
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800398 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800399
Linus Torvalds1da177e2005-04-16 15:20:36 -0700400 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800402 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700404 if (ha->flags.disable_serdes) {
405 /* Mask HBA via NVRAM settings? */
406 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
407 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800408 vha->port_name[0], vha->port_name[1],
409 vha->port_name[2], vha->port_name[3],
410 vha->port_name[4], vha->port_name[5],
411 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700412 return QLA_FUNCTION_FAILED;
413 }
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
416
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800417 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
418 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800419 if (rval)
420 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800421 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800422 if (rval)
423 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700425
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700426 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800427 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700428 if (!ha->cs84xx) {
429 qla_printk(KERN_ERR, ha,
430 "Unable to configure ISP84XX.\n");
431 return QLA_FUNCTION_FAILED;
432 }
433 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800434 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700435 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700436
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800437 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700438 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800439 rval = qla84xx_init_chip(vha);
440 if (rval != QLA_SUCCESS) {
441 qla_printk(KERN_ERR, ha,
442 "Unable to initialize ISP84XX.\n");
443 qla84xx_put_chip(vha);
444 }
445 }
446
Sarang Radke09ff7012010-03-19 17:03:59 -0700447 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
448 if (qla24xx_read_fcp_prio_cfg(vha))
449 qla_printk(KERN_ERR, ha,
450 "Unable to read FCP priority data.\n");
451 }
452
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 return (rval);
454}
455
456/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700457 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 * @ha: HA context
459 *
460 * Returns 0 on success.
461 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700462int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800463qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700465 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700466 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800467 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700468 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700471 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700474 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
476
Andrew Vasquez737faec2008-10-24 15:13:45 -0700477 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700479 /* Get PCI bus information. */
480 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700481 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700482 spin_unlock_irqrestore(&ha->hardware_lock, flags);
483
484 return QLA_SUCCESS;
485}
486
487/**
488 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
489 * @ha: HA context
490 *
491 * Returns 0 on success.
492 */
493int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800494qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700495{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700496 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700497 unsigned long flags = 0;
498 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800499 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700500 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700501
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700502 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700503 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700504
505 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700506 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700507
508 if (IS_QLA2322(ha) || IS_QLA6322(ha))
509 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700510 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700511
512 /*
513 * If this is a 2300 card and not 2312, reset the
514 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
515 * the 2310 also reports itself as a 2300 so we need to get the
516 * fb revision level -- a 6 indicates it really is a 2300 and
517 * not a 2310.
518 */
519 if (IS_QLA2300(ha)) {
520 spin_lock_irqsave(&ha->hardware_lock, flags);
521
522 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700523 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700524 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700525 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700526 break;
527
528 udelay(10);
529 }
530
531 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700532 WRT_REG_WORD(&reg->ctrl_status, 0x20);
533 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700534
535 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700536 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700537
538 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700539 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700540
541 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700542 WRT_REG_WORD(&reg->ctrl_status, 0x0);
543 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700544
545 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700546 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700547 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700548 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700549 break;
550
551 udelay(10);
552 }
553
554 spin_unlock_irqrestore(&ha->hardware_lock, flags);
555 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700556
557 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
558
Andrew Vasquez737faec2008-10-24 15:13:45 -0700559 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700560
561 /* Get PCI bus information. */
562 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700563 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700564 spin_unlock_irqrestore(&ha->hardware_lock, flags);
565
566 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567}
568
569/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700570 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
571 * @ha: HA context
572 *
573 * Returns 0 on success.
574 */
575int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800576qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700577{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700578 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700579 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800580 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700581 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700582
583 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700584 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700585
586 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700587 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700588 w &= ~PCI_COMMAND_INTX_DISABLE;
589 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
590
591 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
592
593 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700594 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
595 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700596
597 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700598 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
599 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700600
Andrew Vasquez737faec2008-10-24 15:13:45 -0700601 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700602
Auke Kok44c10132007-06-08 15:46:36 -0700603 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800604
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700605 /* Get PCI bus information. */
606 spin_lock_irqsave(&ha->hardware_lock, flags);
607 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
608 spin_unlock_irqrestore(&ha->hardware_lock, flags);
609
610 return QLA_SUCCESS;
611}
612
613/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700614 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
615 * @ha: HA context
616 *
617 * Returns 0 on success.
618 */
619int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800620qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700621{
622 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800623 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700624
625 pci_set_master(ha->pdev);
626 pci_try_set_mwi(ha->pdev);
627
628 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
629 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
630 w &= ~PCI_COMMAND_INTX_DISABLE;
631 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
632
633 /* PCIe -- adjust Maximum Read Request Size (2048). */
634 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
635 pcie_set_readrq(ha->pdev, 2048);
636
Andrew Vasquez737faec2008-10-24 15:13:45 -0700637 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700638
639 ha->chip_revision = ha->pdev->revision;
640
641 return QLA_SUCCESS;
642}
643
644/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 * qla2x00_isp_firmware() - Choose firmware image.
646 * @ha: HA context
647 *
648 * Returns 0 on success.
649 */
650static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800651qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652{
653 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700654 uint16_t loop_id, topo, sw_cap;
655 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800656 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657
658 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700659 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 if (ha->flags.disable_risc_code_load) {
662 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800663 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
665
666 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800667 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700668 if (rval == QLA_SUCCESS) {
669 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800670 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700671 &area, &domain, &topo, &sw_cap);
672 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 }
674
675 if (rval) {
676 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800677 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 }
679
680 return (rval);
681}
682
683/**
684 * qla2x00_reset_chip() - Reset ISP chip.
685 * @ha: HA context
686 *
687 * Returns 0 on success.
688 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700689void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800690qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691{
692 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800693 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700694 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 uint16_t cmd;
697
Andrew Vasquez85880802009-12-15 21:29:46 -0800698 if (unlikely(pci_channel_offline(ha->pdev)))
699 return;
700
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700701 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
703 spin_lock_irqsave(&ha->hardware_lock, flags);
704
705 /* Turn off master enable */
706 cmd = 0;
707 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
708 cmd &= ~PCI_COMMAND_MASTER;
709 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
710
711 if (!IS_QLA2100(ha)) {
712 /* Pause RISC. */
713 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
714 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
715 for (cnt = 0; cnt < 30000; cnt++) {
716 if ((RD_REG_WORD(&reg->hccr) &
717 HCCR_RISC_PAUSE) != 0)
718 break;
719 udelay(100);
720 }
721 } else {
722 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
723 udelay(10);
724 }
725
726 /* Select FPM registers. */
727 WRT_REG_WORD(&reg->ctrl_status, 0x20);
728 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
729
730 /* FPM Soft Reset. */
731 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
732 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
733
734 /* Toggle Fpm Reset. */
735 if (!IS_QLA2200(ha)) {
736 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
737 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
738 }
739
740 /* Select frame buffer registers. */
741 WRT_REG_WORD(&reg->ctrl_status, 0x10);
742 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
743
744 /* Reset frame buffer FIFOs. */
745 if (IS_QLA2200(ha)) {
746 WRT_FB_CMD_REG(ha, reg, 0xa000);
747 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
748 } else {
749 WRT_FB_CMD_REG(ha, reg, 0x00fc);
750
751 /* Read back fb_cmd until zero or 3 seconds max */
752 for (cnt = 0; cnt < 3000; cnt++) {
753 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
754 break;
755 udelay(100);
756 }
757 }
758
759 /* Select RISC module registers. */
760 WRT_REG_WORD(&reg->ctrl_status, 0);
761 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
762
763 /* Reset RISC processor. */
764 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
765 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
766
767 /* Release RISC processor. */
768 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
769 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
770 }
771
772 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
773 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
774
775 /* Reset ISP chip. */
776 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
777
778 /* Wait for RISC to recover from reset. */
779 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
780 /*
781 * It is necessary to for a delay here since the card doesn't
782 * respond to PCI reads during a reset. On some architectures
783 * this will result in an MCA.
784 */
785 udelay(20);
786 for (cnt = 30000; cnt; cnt--) {
787 if ((RD_REG_WORD(&reg->ctrl_status) &
788 CSR_ISP_SOFT_RESET) == 0)
789 break;
790 udelay(100);
791 }
792 } else
793 udelay(10);
794
795 /* Reset RISC processor. */
796 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
797
798 WRT_REG_WORD(&reg->semaphore, 0);
799
800 /* Release RISC processor. */
801 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
802 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
803
804 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
805 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700806 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808
809 udelay(100);
810 }
811 } else
812 udelay(100);
813
814 /* Turn on master enable */
815 cmd |= PCI_COMMAND_MASTER;
816 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
817
818 /* Disable RISC pause on FPM parity error. */
819 if (!IS_QLA2100(ha)) {
820 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
821 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
822 }
823
824 spin_unlock_irqrestore(&ha->hardware_lock, flags);
825}
826
827/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700828 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700829 * @ha: HA context
830 *
831 * Returns 0 on success.
832 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700833static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700835{
836 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800837 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700838 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
839 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800840 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700841
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700842 spin_lock_irqsave(&ha->hardware_lock, flags);
843
844 /* Reset RISC. */
845 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
846 for (cnt = 0; cnt < 30000; cnt++) {
847 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
848 break;
849
850 udelay(10);
851 }
852
853 WRT_REG_DWORD(&reg->ctrl_status,
854 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800855 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700856
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800857 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700858 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700859 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
860 for (cnt = 10000 ; cnt && d2; cnt--) {
861 udelay(5);
862 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
863 barrier();
864 }
865
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800866 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700867 d2 = RD_REG_DWORD(&reg->ctrl_status);
868 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
869 udelay(5);
870 d2 = RD_REG_DWORD(&reg->ctrl_status);
871 barrier();
872 }
873
874 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
875 RD_REG_DWORD(&reg->hccr);
876
877 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
878 RD_REG_DWORD(&reg->hccr);
879
880 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
881 RD_REG_DWORD(&reg->hccr);
882
883 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
884 for (cnt = 6000000 ; cnt && d2; cnt--) {
885 udelay(5);
886 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
887 barrier();
888 }
889
890 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800891
892 if (IS_NOPOLLING_TYPE(ha))
893 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700894}
895
896/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700897 * qla24xx_reset_chip() - Reset ISP24xx chip.
898 * @ha: HA context
899 *
900 * Returns 0 on success.
901 */
902void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700904{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800905 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -0800906
907 if (pci_channel_offline(ha->pdev) &&
908 ha->flags.pci_channel_io_perm_failure) {
909 return;
910 }
911
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700912 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700913
914 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800915 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700916}
917
918/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 * qla2x00_chip_diag() - Test chip for proper operation.
920 * @ha: HA context
921 *
922 * Returns 0 on success.
923 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700924int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926{
927 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700929 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 unsigned long flags = 0;
931 uint16_t data;
932 uint32_t cnt;
933 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800934 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935
936 /* Assume a failed state */
937 rval = QLA_FUNCTION_FAILED;
938
939 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941
942 spin_lock_irqsave(&ha->hardware_lock, flags);
943
944 /* Reset ISP chip. */
945 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
946
947 /*
948 * We need to have a delay here since the card will not respond while
949 * in reset causing an MCA on some architectures.
950 */
951 udelay(20);
952 data = qla2x00_debounce_register(&reg->ctrl_status);
953 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
954 udelay(5);
955 data = RD_REG_WORD(&reg->ctrl_status);
956 barrier();
957 }
958
959 if (!cnt)
960 goto chip_diag_failed;
961
962 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700963 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964
965 /* Reset RISC processor. */
966 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
967 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
968
969 /* Workaround for QLA2312 PCI parity error */
970 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
971 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
972 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
973 udelay(5);
974 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700975 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976 }
977 } else
978 udelay(10);
979
980 if (!cnt)
981 goto chip_diag_failed;
982
983 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -0700984 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
986 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
987 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
988 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
989 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
990 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
991 mb[3] != PROD_ID_3) {
992 qla_printk(KERN_WARNING, ha,
993 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
994
995 goto chip_diag_failed;
996 }
997 ha->product_id[0] = mb[1];
998 ha->product_id[1] = mb[2];
999 ha->product_id[2] = mb[3];
1000 ha->product_id[3] = mb[4];
1001
1002 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001003 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
1005 else
1006 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001007 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008
1009 if (IS_QLA2200(ha) &&
1010 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
1011 /* Limit firmware transfer size with a 2200A */
1012 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001013 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001014
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001015 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 ha->fw_transfer_size = 128;
1017 }
1018
1019 /* Wrap Incoming Mailboxes Test. */
1020 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1021
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001022 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
1023 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 if (rval) {
1025 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001026 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 qla_printk(KERN_WARNING, ha,
1028 "Failed mailbox send register test\n");
1029 }
1030 else {
1031 /* Flag a successful rval */
1032 rval = QLA_SUCCESS;
1033 }
1034 spin_lock_irqsave(&ha->hardware_lock, flags);
1035
1036chip_diag_failed:
1037 if (rval)
1038 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001039 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001040
1041 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1042
1043 return (rval);
1044}
1045
1046/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001047 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1048 * @ha: HA context
1049 *
1050 * Returns 0 on success.
1051 */
1052int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001053qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001054{
1055 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001056 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001057 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001058
Giridhar Malavalia9083012010-04-12 17:59:55 -07001059 if (IS_QLA82XX(ha))
1060 return QLA_SUCCESS;
1061
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001062 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001063
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001064 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001065 if (rval) {
1066 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001067 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001068 qla_printk(KERN_WARNING, ha,
1069 "Failed mailbox send register test\n");
1070 } else {
1071 /* Flag a successful rval */
1072 rval = QLA_SUCCESS;
1073 }
1074
1075 return rval;
1076}
1077
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001078void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001079qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001080{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001081 int rval;
1082 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001083 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001084 dma_addr_t tc_dma;
1085 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001086 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001087 struct req_que *req = ha->req_q_map[0];
1088 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001089
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001090 if (ha->fw_dump) {
1091 qla_printk(KERN_WARNING, ha,
1092 "Firmware dump previously allocated.\n");
1093 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001094 }
1095
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001096 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001097 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001098 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1099 fixed_size = sizeof(struct qla2100_fw_dump);
1100 } else if (IS_QLA23XX(ha)) {
1101 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1102 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1103 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001104 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001105 if (IS_QLA81XX(ha))
1106 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1107 else if (IS_QLA25XX(ha))
1108 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1109 else
1110 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001111 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1112 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001113 if (ha->mqenable)
1114 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001115 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001116 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001117 goto try_eft;
1118
1119 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1120 GFP_KERNEL);
1121 if (!tc) {
1122 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1123 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001124 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001125 }
1126
1127 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001129 ha->fce_mb, &ha->fce_bufs);
1130 if (rval) {
1131 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1132 "FCE (%d).\n", rval);
1133 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1134 tc_dma);
1135 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001136 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001137 }
1138
1139 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1140 FCE_SIZE / 1024);
1141
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001142 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001143 ha->flags.fce_enabled = 1;
1144 ha->fce_dma = tc_dma;
1145 ha->fce = tc;
1146try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001147 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001148 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001149 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001150 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001151 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1152 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1153 goto cont_alloc;
1154 }
1155
Andrew Vasquezfc447652008-01-17 09:02:18 -08001156 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001157 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001158 if (rval) {
1159 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1160 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001161 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1162 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001163 goto cont_alloc;
1164 }
1165
1166 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1167 EFT_SIZE / 1024);
1168
1169 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001170 ha->eft_dma = tc_dma;
1171 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001172 }
1173cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001174 req_q_size = req->length * sizeof(request_t);
1175 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001176
1177 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001178 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001179 ha->chain_offset = dump_size;
1180 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001181
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001182 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001183 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001184 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001185 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001186
1187 if (ha->eft) {
1188 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1189 ha->eft_dma);
1190 ha->eft = NULL;
1191 ha->eft_dma = 0;
1192 }
1193 return;
1194 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001195 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1196 dump_size / 1024);
1197
1198 ha->fw_dump_len = dump_size;
1199 ha->fw_dump->signature[0] = 'Q';
1200 ha->fw_dump->signature[1] = 'L';
1201 ha->fw_dump->signature[2] = 'G';
1202 ha->fw_dump->signature[3] = 'C';
1203 ha->fw_dump->version = __constant_htonl(1);
1204
1205 ha->fw_dump->fixed_size = htonl(fixed_size);
1206 ha->fw_dump->mem_size = htonl(mem_size);
1207 ha->fw_dump->req_q_size = htonl(req_q_size);
1208 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1209
1210 ha->fw_dump->eft_size = htonl(eft_size);
1211 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1212 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1213
1214 ha->fw_dump->header_size =
1215 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001216}
1217
Andrew Vasquez18e75552009-06-03 09:55:30 -07001218static int
1219qla81xx_mpi_sync(scsi_qla_host_t *vha)
1220{
1221#define MPS_MASK 0xe0
1222 int rval;
1223 uint16_t dc;
1224 uint32_t dw;
1225 struct qla_hw_data *ha = vha->hw;
1226
1227 if (!IS_QLA81XX(vha->hw))
1228 return QLA_SUCCESS;
1229
1230 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1231 if (rval != QLA_SUCCESS) {
1232 DEBUG2(qla_printk(KERN_WARNING, ha,
1233 "Sync-MPI: Unable to acquire semaphore.\n"));
1234 goto done;
1235 }
1236
1237 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1238 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1239 if (rval != QLA_SUCCESS) {
1240 DEBUG2(qla_printk(KERN_WARNING, ha,
1241 "Sync-MPI: Unable to read sync.\n"));
1242 goto done_release;
1243 }
1244
1245 dc &= MPS_MASK;
1246 if (dc == (dw & MPS_MASK))
1247 goto done_release;
1248
1249 dw &= ~MPS_MASK;
1250 dw |= dc;
1251 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1252 if (rval != QLA_SUCCESS) {
1253 DEBUG2(qla_printk(KERN_WARNING, ha,
1254 "Sync-MPI: Unable to gain sync.\n"));
1255 }
1256
1257done_release:
1258 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1259 if (rval != QLA_SUCCESS) {
1260 DEBUG2(qla_printk(KERN_WARNING, ha,
1261 "Sync-MPI: Unable to release semaphore.\n"));
1262 }
1263
1264done:
1265 return rval;
1266}
1267
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001268/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269 * qla2x00_setup_chip() - Load and start RISC firmware.
1270 * @ha: HA context
1271 *
1272 * Returns 0 on success.
1273 */
1274static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001275qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001276{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001277 int rval;
1278 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001279 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001280 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1281 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001282 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001283
Giridhar Malavalia9083012010-04-12 17:59:55 -07001284 if (IS_QLA82XX(ha)) {
1285 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1286 if (rval == QLA_SUCCESS)
1287 goto enable_82xx_npiv;
1288 }
1289
Andrew Vasquez3db06522008-01-31 12:33:49 -08001290 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1291 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1292 spin_lock_irqsave(&ha->hardware_lock, flags);
1293 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1294 RD_REG_WORD(&reg->hccr);
1295 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
Andrew Vasquez18e75552009-06-03 09:55:30 -07001298 qla81xx_mpi_sync(vha);
1299
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001301 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001302 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001304 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001306 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 if (rval == QLA_SUCCESS) {
1308 /* Start firmware execution. */
1309 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001310 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001312 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001314 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001315enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001316 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001317 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 &ha->fw_major_version,
1319 &ha->fw_minor_version,
1320 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001321 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001322 ha->mpi_version, &ha->mpi_capabilities,
1323 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001324 if (rval != QLA_SUCCESS)
1325 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001326 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001327 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001328 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001329 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001330 if ((!ha->max_npiv_vports) ||
1331 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001332 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001333 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001334 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001335 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001336 qla2x00_get_resource_cnts(vha, NULL,
1337 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001338 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001339
Giridhar Malavalia9083012010-04-12 17:59:55 -07001340 if (!fw_major_version && ql2xallocfwdump) {
1341 if (!IS_QLA82XX(ha))
1342 qla2x00_alloc_fw_dump(vha);
1343 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 }
1345 } else {
1346 DEBUG2(printk(KERN_INFO
1347 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 }
1350 }
1351
Andrew Vasquez3db06522008-01-31 12:33:49 -08001352 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1353 /* Enable proper parity. */
1354 spin_lock_irqsave(&ha->hardware_lock, flags);
1355 if (IS_QLA2300(ha))
1356 /* SRAM parity */
1357 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1358 else
1359 /* SRAM, Instruction RAM and GP RAM parity */
1360 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1361 RD_REG_WORD(&reg->hccr);
1362 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1363 }
1364
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001365 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1366 uint32_t size;
1367
1368 rval = qla81xx_fac_get_sector_size(vha, &size);
1369 if (rval == QLA_SUCCESS) {
1370 ha->flags.fac_supported = 1;
1371 ha->fdt_block_size = size << 2;
1372 } else {
1373 qla_printk(KERN_ERR, ha,
1374 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1375 ha->fw_major_version, ha->fw_minor_version,
1376 ha->fw_subminor_version);
1377 }
1378 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001379failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 if (rval) {
1381 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001382 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 }
1384
1385 return (rval);
1386}
1387
1388/**
1389 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1390 * @ha: HA context
1391 *
1392 * Beginning of request ring has initialization control block already built
1393 * by nvram config routine.
1394 *
1395 * Returns 0 on success.
1396 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001397void
1398qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399{
1400 uint16_t cnt;
1401 response_t *pkt;
1402
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001403 rsp->ring_ptr = rsp->ring;
1404 rsp->ring_index = 0;
1405 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001406 pkt = rsp->ring_ptr;
1407 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408 pkt->signature = RESPONSE_PROCESSED;
1409 pkt++;
1410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001411}
1412
1413/**
1414 * qla2x00_update_fw_options() - Read and process firmware options.
1415 * @ha: HA context
1416 *
1417 * Returns 0 on success.
1418 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001419void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001420qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421{
1422 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001423 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001424
1425 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001426 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427
1428 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1429 return;
1430
1431 /* Serial Link options. */
1432 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001433 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001434 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1435 sizeof(ha->fw_seriallink_options)));
1436
1437 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1438 if (ha->fw_seriallink_options[3] & BIT_2) {
1439 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1440
1441 /* 1G settings */
1442 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1443 emphasis = (ha->fw_seriallink_options[2] &
1444 (BIT_4 | BIT_3)) >> 3;
1445 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001446 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 rx_sens = (ha->fw_seriallink_options[0] &
1448 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1449 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1450 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1451 if (rx_sens == 0x0)
1452 rx_sens = 0x3;
1453 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1454 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1455 ha->fw_options[10] |= BIT_5 |
1456 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1457 (tx_sens & (BIT_1 | BIT_0));
1458
1459 /* 2G settings */
1460 swing = (ha->fw_seriallink_options[2] &
1461 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1462 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1463 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001464 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001465 rx_sens = (ha->fw_seriallink_options[1] &
1466 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1467 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1468 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1469 if (rx_sens == 0x0)
1470 rx_sens = 0x3;
1471 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1472 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1473 ha->fw_options[11] |= BIT_5 |
1474 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1475 (tx_sens & (BIT_1 | BIT_0));
1476 }
1477
1478 /* FCP2 options. */
1479 /* Return command IOCBs without waiting for an ABTS to complete. */
1480 ha->fw_options[3] |= BIT_13;
1481
1482 /* LED scheme. */
1483 if (ha->flags.enable_led_scheme)
1484 ha->fw_options[2] |= BIT_12;
1485
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001486 /* Detect ISP6312. */
1487 if (IS_QLA6312(ha))
1488 ha->fw_options[2] |= BIT_13;
1489
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492}
1493
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001494void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001495qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001496{
1497 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001499
Giridhar Malavalia9083012010-04-12 17:59:55 -07001500 if (IS_QLA82XX(ha))
1501 return;
1502
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001503 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001504 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001505 return;
1506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001507 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001508 le16_to_cpu(ha->fw_seriallink_options24[1]),
1509 le16_to_cpu(ha->fw_seriallink_options24[2]),
1510 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001511 if (rval != QLA_SUCCESS) {
1512 qla_printk(KERN_WARNING, ha,
1513 "Unable to update Serial Link options (%x).\n", rval);
1514 }
1515}
1516
1517void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001518qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001519{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001520 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001521 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001522 struct req_que *req = ha->req_q_map[0];
1523 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001524
1525 /* Setup ring parameters in initialization control block. */
1526 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1527 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001528 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1529 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1530 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1531 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1532 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1533 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001534
1535 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1536 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1537 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1538 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1539 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1540}
1541
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001542void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001543qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001544{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001545 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001546 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1547 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1548 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001549 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001550 uint16_t rid = 0;
1551 struct req_que *req = ha->req_q_map[0];
1552 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001553
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001554/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001555 icb = (struct init_cb_24xx *)ha->init_cb;
1556 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1557 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001558 icb->request_q_length = cpu_to_le16(req->length);
1559 icb->response_q_length = cpu_to_le16(rsp->length);
1560 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1561 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1562 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1563 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001564
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001565 if (ha->mqenable) {
1566 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1567 icb->rid = __constant_cpu_to_le16(rid);
1568 if (ha->flags.msix_enabled) {
1569 msix = &ha->msix_entries[1];
1570 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001571 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001572 icb->msix = cpu_to_le16(msix->entry);
1573 }
1574 /* Use alternate PCI bus number */
1575 if (MSB(rid))
1576 icb->firmware_options_2 |=
1577 __constant_cpu_to_le32(BIT_19);
1578 /* Use alternate PCI devfn */
1579 if (LSB(rid))
1580 icb->firmware_options_2 |=
1581 __constant_cpu_to_le32(BIT_18);
1582
Anirban Chakraborty31557542009-12-02 10:36:55 -08001583 /* Use Disable MSIX Handshake mode for capable adapters */
1584 if (IS_MSIX_NACK_CAPABLE(ha)) {
1585 icb->firmware_options_2 &=
1586 __constant_cpu_to_le32(~BIT_22);
1587 ha->flags.disable_msix_handshake = 1;
1588 qla_printk(KERN_INFO, ha,
1589 "MSIX Handshake Disable Mode turned on\n");
1590 } else {
1591 icb->firmware_options_2 |=
1592 __constant_cpu_to_le32(BIT_22);
1593 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001594 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001595
1596 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1597 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1598 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1599 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1600 } else {
1601 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1602 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1603 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1604 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1605 }
1606 /* PCI posting */
1607 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001608}
1609
Linus Torvalds1da177e2005-04-16 15:20:36 -07001610/**
1611 * qla2x00_init_rings() - Initializes firmware.
1612 * @ha: HA context
1613 *
1614 * Beginning of request ring has initialization control block already built
1615 * by nvram config routine.
1616 *
1617 * Returns 0 on success.
1618 */
1619static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001620qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621{
1622 int rval;
1623 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001624 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001626 struct req_que *req;
1627 struct rsp_que *rsp;
1628 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001629 struct mid_init_cb_24xx *mid_init_cb =
1630 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
1632 spin_lock_irqsave(&ha->hardware_lock, flags);
1633
1634 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001635 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001636 req = ha->req_q_map[que];
1637 if (!req)
1638 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001639 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001640 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001642 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001643
1644 /* Initialize firmware. */
1645 req->ring_ptr = req->ring;
1646 req->ring_index = 0;
1647 req->cnt = req->length;
1648 }
1649
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001650 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001651 rsp = ha->rsp_q_map[que];
1652 if (!rsp)
1653 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001654 /* Initialize response queue entries */
1655 qla2x00_init_response_q_entries(rsp);
1656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
1658 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001659 list_for_each_entry(vp, &ha->vp_list, list) {
1660 vp->rscn_in_ptr = 0;
1661 vp->rscn_out_ptr = 0;
1662 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001663 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
1665 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1666
1667 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001668 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001670 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001671
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001672 if (ha->flags.npiv_supported) {
1673 if (ha->operating_mode == LOOP)
1674 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001675 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001676 }
1677
Andrew Vasquez24a08132009-03-24 09:08:16 -07001678 if (IS_FWI2_CAPABLE(ha)) {
1679 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1680 mid_init_cb->init_cb.execution_throttle =
1681 cpu_to_le16(ha->fw_xcb_count);
1682 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001684 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 if (rval) {
1686 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001687 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688 } else {
1689 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001690 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 }
1692
1693 return (rval);
1694}
1695
1696/**
1697 * qla2x00_fw_ready() - Waits for firmware ready.
1698 * @ha: HA context
1699 *
1700 * Returns 0 on success.
1701 */
1702static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001703qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704{
1705 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001706 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 uint16_t min_wait; /* Minimum wait time if loop is down */
1708 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001709 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001710 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711
1712 rval = QLA_SUCCESS;
1713
1714 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001715 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
1717 /*
1718 * Firmware should take at most one RATOV to login, plus 5 seconds for
1719 * our own processing.
1720 */
1721 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1722 wait_time = min_wait;
1723 }
1724
1725 /* Min wait time if loop down */
1726 mtime = jiffies + (min_wait * HZ);
1727
1728 /* wait time before firmware ready */
1729 wtime = jiffies + (wait_time * HZ);
1730
1731 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001732 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1734
1735 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001736 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001737
1738 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001739 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001741 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001742 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001744 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1745 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001746 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001747 state[2]));
1748 if ((state[2] & FSTATE_LOGGED_IN) &&
1749 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1750 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001751 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001752
1753 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001754 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001755 if (rval != QLA_SUCCESS)
1756 break;
1757
1758 /* Add time taken to initialize. */
1759 cs84xx_time = jiffies - cs84xx_time;
1760 wtime += cs84xx_time;
1761 mtime += cs84xx_time;
1762 DEBUG16(printk("scsi(%ld): Increasing "
1763 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001764 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001765 }
1766 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001768 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001770 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771 &ha->login_timeout, &ha->r_a_tov);
1772
1773 rval = QLA_SUCCESS;
1774 break;
1775 }
1776
1777 rval = QLA_FUNCTION_FAILED;
1778
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001779 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001780 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001782 * other than Wait for Login.
1783 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 if (time_after_eq(jiffies, mtime)) {
1785 qla_printk(KERN_INFO, ha,
1786 "Cable is unplugged...\n");
1787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789 break;
1790 }
1791 }
1792 } else {
1793 /* Mailbox cmd failed. Timeout on min_wait. */
1794 if (time_after_eq(jiffies, mtime))
1795 break;
1796 }
1797
1798 if (time_after_eq(jiffies, wtime))
1799 break;
1800
1801 /* Delay for a while */
1802 msleep(500);
1803
1804 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001805 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001806 } while (1);
1807
Andrew Vasquez656e8912009-06-03 09:55:29 -07001808 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1809 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1810 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
1812 if (rval) {
1813 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001814 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815 }
1816
1817 return (rval);
1818}
1819
1820/*
1821* qla2x00_configure_hba
1822* Setup adapter context.
1823*
1824* Input:
1825* ha = adapter state pointer.
1826*
1827* Returns:
1828* 0 = success
1829*
1830* Context:
1831* Kernel context.
1832*/
1833static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001834qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835{
1836 int rval;
1837 uint16_t loop_id;
1838 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001839 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 uint8_t al_pa;
1841 uint8_t area;
1842 uint8_t domain;
1843 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001844 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845
1846 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001847 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001848 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001850 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001851 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1852 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001853 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001854 } else {
1855 qla_printk(KERN_WARNING, ha,
1856 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001857 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001858 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 return (rval);
1860 }
1861
1862 if (topo == 4) {
1863 qla_printk(KERN_INFO, ha,
1864 "Cannot get topology - retrying.\n");
1865 return (QLA_FUNCTION_FAILED);
1866 }
1867
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001868 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
1870 /* initialize */
1871 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1872 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001873 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874
1875 switch (topo) {
1876 case 0:
1877 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 ha->current_topology = ISP_CFG_NL;
1880 strcpy(connect_type, "(Loop)");
1881 break;
1882
1883 case 1:
1884 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001885 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001886 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 ha->current_topology = ISP_CFG_FL;
1888 strcpy(connect_type, "(FL_Port)");
1889 break;
1890
1891 case 2:
1892 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001893 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 ha->operating_mode = P2P;
1895 ha->current_topology = ISP_CFG_N;
1896 strcpy(connect_type, "(N_Port-to-N_Port)");
1897 break;
1898
1899 case 3:
1900 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001901 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001902 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 ha->operating_mode = P2P;
1904 ha->current_topology = ISP_CFG_F;
1905 strcpy(connect_type, "(F_Port)");
1906 break;
1907
1908 default:
1909 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1910 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 ha->current_topology = ISP_CFG_NL;
1913 strcpy(connect_type, "(Loop)");
1914 break;
1915 }
1916
1917 /* Save Host port and loop ID. */
1918 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001919 vha->d_id.b.domain = domain;
1920 vha->d_id.b.area = area;
1921 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001923 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001924 qla_printk(KERN_INFO, ha,
1925 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
1928 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 }
1933
1934 return(rval);
1935}
1936
Giridhar Malavalia9083012010-04-12 17:59:55 -07001937inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001938qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1939 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001940{
1941 char *st, *en;
1942 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001943 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07001944 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07001945 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001946
1947 if (memcmp(model, BINZERO, len) != 0) {
1948 strncpy(ha->model_number, model, len);
1949 st = en = ha->model_number;
1950 en += len - 1;
1951 while (en > st) {
1952 if (*en != 0x20 && *en != 0x00)
1953 break;
1954 *en-- = '\0';
1955 }
1956
1957 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001958 if (use_tbl &&
1959 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001960 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001961 strncpy(ha->model_desc,
1962 qla2x00_model_name[index * 2 + 1],
1963 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001964 } else {
1965 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001966 if (use_tbl &&
1967 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001968 index < QLA_MODEL_NAMES) {
1969 strcpy(ha->model_number,
1970 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001971 strncpy(ha->model_desc,
1972 qla2x00_model_name[index * 2 + 1],
1973 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001974 } else {
1975 strcpy(ha->model_number, def);
1976 }
1977 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001978 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001979 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001980 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001981}
1982
David Miller4e08df32007-04-16 12:37:43 -07001983/* On sparc systems, obtain port and node WWN from firmware
1984 * properties.
1985 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001987{
1988#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001990 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001991 struct device_node *dp = pci_device_to_OF_node(pdev);
1992 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001993 int len;
1994
1995 val = of_get_property(dp, "port-wwn", &len);
1996 if (val && len >= WWN_SIZE)
1997 memcpy(nv->port_name, val, WWN_SIZE);
1998
1999 val = of_get_property(dp, "node-wwn", &len);
2000 if (val && len >= WWN_SIZE)
2001 memcpy(nv->node_name, val, WWN_SIZE);
2002#endif
2003}
2004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005/*
2006* NVRAM configuration for ISP 2xxx
2007*
2008* Input:
2009* ha = adapter block pointer.
2010*
2011* Output:
2012* initialization control block in response_ring
2013* host adapters parameters in host adapter block
2014*
2015* Returns:
2016* 0 = success.
2017*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002018int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020{
David Miller4e08df32007-04-16 12:37:43 -07002021 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002022 uint8_t chksum = 0;
2023 uint16_t cnt;
2024 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002026 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07002027 nvram_t *nv = ha->nvram;
2028 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07002029 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030
David Miller4e08df32007-04-16 12:37:43 -07002031 rval = QLA_SUCCESS;
2032
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002034 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 ha->nvram_base = 0;
2036 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
2037 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
2038 ha->nvram_base = 0x80;
2039
2040 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002041 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002042 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
2043 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002045 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07002046 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047
2048 /* Bad NVRAM data, set defaults parameters. */
2049 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
2050 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
2051 /* Reset NVRAM data. */
2052 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
2053 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
2054 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07002055 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
2056 "invalid -- WWPN) defaults.\n");
2057
2058 /*
2059 * Set default initialization control block.
2060 */
2061 memset(nv, 0, ha->nvram_size);
2062 nv->parameter_block_version = ICB_VERSION;
2063
2064 if (IS_QLA23XX(ha)) {
2065 nv->firmware_options[0] = BIT_2 | BIT_1;
2066 nv->firmware_options[1] = BIT_7 | BIT_5;
2067 nv->add_firmware_options[0] = BIT_5;
2068 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2069 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2070 nv->special_options[1] = BIT_7;
2071 } else if (IS_QLA2200(ha)) {
2072 nv->firmware_options[0] = BIT_2 | BIT_1;
2073 nv->firmware_options[1] = BIT_7 | BIT_5;
2074 nv->add_firmware_options[0] = BIT_5;
2075 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2076 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2077 } else if (IS_QLA2100(ha)) {
2078 nv->firmware_options[0] = BIT_3 | BIT_1;
2079 nv->firmware_options[1] = BIT_5;
2080 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2081 }
2082
2083 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2084 nv->execution_throttle = __constant_cpu_to_le16(16);
2085 nv->retry_count = 8;
2086 nv->retry_delay = 1;
2087
2088 nv->port_name[0] = 33;
2089 nv->port_name[3] = 224;
2090 nv->port_name[4] = 139;
2091
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002092 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002093
2094 nv->login_timeout = 4;
2095
2096 /*
2097 * Set default host adapter parameters
2098 */
2099 nv->host_p[1] = BIT_2;
2100 nv->reset_delay = 5;
2101 nv->port_down_retry_count = 8;
2102 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2103 nv->link_down_timeout = 60;
2104
2105 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 }
2107
2108#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2109 /*
2110 * The SN2 does not provide BIOS emulation which means you can't change
2111 * potentially bogus BIOS settings. Force the use of default settings
2112 * for link rate and frame size. Hope that the rest of the settings
2113 * are valid.
2114 */
2115 if (ia64_platform_is("sn2")) {
2116 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2117 if (IS_QLA23XX(ha))
2118 nv->special_options[1] = BIT_7;
2119 }
2120#endif
2121
2122 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002123 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124
2125 /*
2126 * Setup driver NVRAM options.
2127 */
2128 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2129 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2130 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2131 nv->firmware_options[1] &= ~BIT_4;
2132
2133 if (IS_QLA23XX(ha)) {
2134 nv->firmware_options[0] |= BIT_2;
2135 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002136 nv->firmware_options[0] &= ~BIT_6;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002137 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
2139 if (IS_QLA2300(ha)) {
2140 if (ha->fb_rev == FPM_2310) {
2141 strcpy(ha->model_number, "QLA2310");
2142 } else {
2143 strcpy(ha->model_number, "QLA2300");
2144 }
2145 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002147 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 }
2149 } else if (IS_QLA2200(ha)) {
2150 nv->firmware_options[0] |= BIT_2;
2151 /*
2152 * 'Point-to-point preferred, else loop' is not a safe
2153 * connection mode setting.
2154 */
2155 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2156 (BIT_5 | BIT_4)) {
2157 /* Force 'loop preferred, else point-to-point'. */
2158 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2159 nv->add_firmware_options[0] |= BIT_5;
2160 }
2161 strcpy(ha->model_number, "QLA22xx");
2162 } else /*if (IS_QLA2100(ha))*/ {
2163 strcpy(ha->model_number, "QLA2100");
2164 }
2165
2166 /*
2167 * Copy over NVRAM RISC parameter block to initialization control block.
2168 */
2169 dptr1 = (uint8_t *)icb;
2170 dptr2 = (uint8_t *)&nv->parameter_block_version;
2171 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2172 while (cnt--)
2173 *dptr1++ = *dptr2++;
2174
2175 /* Copy 2nd half. */
2176 dptr1 = (uint8_t *)icb->add_firmware_options;
2177 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2178 while (cnt--)
2179 *dptr1++ = *dptr2++;
2180
Andrew Vasquez5341e862006-05-17 15:09:16 -07002181 /* Use alternate WWN? */
2182 if (nv->host_p[1] & BIT_7) {
2183 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2184 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2185 }
2186
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 /* Prepare nodename */
2188 if ((icb->firmware_options[1] & BIT_6) == 0) {
2189 /*
2190 * Firmware will apply the following mask if the nodename was
2191 * not provided.
2192 */
2193 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2194 icb->node_name[0] &= 0xF0;
2195 }
2196
2197 /*
2198 * Set host adapter parameters.
2199 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002200 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002201 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2203 /* Always load RISC code on non ISP2[12]00 chips. */
2204 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2205 ha->flags.disable_risc_code_load = 0;
2206 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2207 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2208 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002209 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002210 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211
2212 ha->operating_mode =
2213 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2214
2215 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2216 sizeof(ha->fw_seriallink_options));
2217
2218 /* save HBA serial number */
2219 ha->serial0 = icb->port_name[5];
2220 ha->serial1 = icb->port_name[6];
2221 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002222 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2223 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2226
2227 ha->retry_count = nv->retry_count;
2228
2229 /* Set minimum login_timeout to 4 seconds. */
2230 if (nv->login_timeout < ql2xlogintimeout)
2231 nv->login_timeout = ql2xlogintimeout;
2232 if (nv->login_timeout < 4)
2233 nv->login_timeout = 4;
2234 ha->login_timeout = nv->login_timeout;
2235 icb->login_timeout = nv->login_timeout;
2236
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002237 /* Set minimum RATOV to 100 tenths of a second. */
2238 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 ha->loop_reset_delay = nv->reset_delay;
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 /* Link Down Timeout = 0:
2243 *
2244 * When Port Down timer expires we will start returning
2245 * I/O's to OS with "DID_NO_CONNECT".
2246 *
2247 * Link Down Timeout != 0:
2248 *
2249 * The driver waits for the link to come up after link down
2250 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002251 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 if (nv->link_down_timeout == 0) {
2253 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002254 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255 } else {
2256 ha->link_down_timeout = nv->link_down_timeout;
2257 ha->loop_down_abort_time =
2258 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 /*
2262 * Need enough time to try and get the port back.
2263 */
2264 ha->port_down_retry_count = nv->port_down_retry_count;
2265 if (qlport_down_retry)
2266 ha->port_down_retry_count = qlport_down_retry;
2267 /* Set login_retry_count */
2268 ha->login_retry_count = nv->retry_count;
2269 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2270 ha->port_down_retry_count > 3)
2271 ha->login_retry_count = ha->port_down_retry_count;
2272 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2273 ha->login_retry_count = ha->port_down_retry_count;
2274 if (ql2xloginretrycount)
2275 ha->login_retry_count = ql2xloginretrycount;
2276
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 icb->lun_enables = __constant_cpu_to_le16(0);
2278 icb->command_resource_count = 0;
2279 icb->immediate_notify_resource_count = 0;
2280 icb->timeout = __constant_cpu_to_le16(0);
2281
2282 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2283 /* Enable RIO */
2284 icb->firmware_options[0] &= ~BIT_3;
2285 icb->add_firmware_options[0] &=
2286 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2287 icb->add_firmware_options[0] |= BIT_2;
2288 icb->response_accumulation_timer = 3;
2289 icb->interrupt_delay_timer = 5;
2290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002292 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002293 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002294 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002295 ha->zio_mode = icb->add_firmware_options[0] &
2296 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2297 ha->zio_timer = icb->interrupt_delay_timer ?
2298 icb->interrupt_delay_timer: 2;
2299 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002300 icb->add_firmware_options[0] &=
2301 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002302 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002303 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002304 ha->zio_mode = QLA_ZIO_MODE_6;
2305
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002306 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002307 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002308 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002310 "ZIO mode %d enabled; timer delay (%d us).\n",
2311 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002313 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2314 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002315 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002316 }
2317 }
2318
David Miller4e08df32007-04-16 12:37:43 -07002319 if (rval) {
2320 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002322 }
2323 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324}
2325
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002326static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002327qla2x00_rport_del(void *data)
2328{
2329 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002330 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002331
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002333 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002334 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002336 if (rport)
2337 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002338}
2339
Linus Torvalds1da177e2005-04-16 15:20:36 -07002340/**
2341 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2342 * @ha: HA context
2343 * @flags: allocation flags
2344 *
2345 * Returns a pointer to the allocated fcport, or NULL, if none available.
2346 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002347fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002348qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349{
2350 fc_port_t *fcport;
2351
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002352 fcport = kzalloc(sizeof(fc_port_t), flags);
2353 if (!fcport)
2354 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002357 fcport->vha = vha;
2358 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 fcport->port_type = FCT_UNKNOWN;
2360 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002362 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002364 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365}
2366
2367/*
2368 * qla2x00_configure_loop
2369 * Updates Fibre Channel Device Database with what is actually on loop.
2370 *
2371 * Input:
2372 * ha = adapter block pointer.
2373 *
2374 * Returns:
2375 * 0 = success.
2376 * 1 = error.
2377 * 2 = database was full and device was not configured.
2378 */
2379static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002380qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381{
2382 int rval;
2383 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 rval = QLA_SUCCESS;
2386
2387 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002388 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2389 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002390 if (rval != QLA_SUCCESS) {
2391 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002392 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 return (rval);
2394 }
2395 }
2396
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002399 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002400
2401 /*
2402 * If we have both an RSCN and PORT UPDATE pending then handle them
2403 * both at the same time.
2404 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2406 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407
Michael Hernandez3064ff32009-12-15 21:29:44 -08002408 qla2x00_get_data_rate(vha);
2409
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 /* Determine what we need to do */
2411 if (ha->current_topology == ISP_CFG_FL &&
2412 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2413
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 set_bit(RSCN_UPDATE, &flags);
2416
2417 } else if (ha->current_topology == ISP_CFG_F &&
2418 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2419
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 set_bit(RSCN_UPDATE, &flags);
2422 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2423
Andrew Vasquez21333b42006-05-17 15:09:56 -07002424 } else if (ha->current_topology == ISP_CFG_N) {
2425 clear_bit(RSCN_UPDATE, &flags);
2426
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2429
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002430 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 set_bit(RSCN_UPDATE, &flags);
2432 set_bit(LOCAL_LOOP_UPDATE, &flags);
2433 }
2434
2435 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 else
2439 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 }
2441
2442 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 else
2446 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 }
2448
2449 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002450 if (atomic_read(&vha->loop_down_timer) ||
2451 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 rval = QLA_FUNCTION_FAILED;
2453 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 }
2458 }
2459
2460 if (rval) {
2461 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 } else {
2464 DEBUG3(printk("%s: exiting normally\n", __func__));
2465 }
2466
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002467 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002471 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002473 vha->flags.rscn_queue_overflow = 1;
2474 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 }
2476
2477 return (rval);
2478}
2479
2480
2481
2482/*
2483 * qla2x00_configure_local_loop
2484 * Updates Fibre Channel Device Database with local loop devices.
2485 *
2486 * Input:
2487 * ha = adapter block pointer.
2488 *
2489 * Returns:
2490 * 0 = success.
2491 */
2492static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494{
2495 int rval, rval2;
2496 int found_devs;
2497 int found;
2498 fc_port_t *fcport, *new_fcport;
2499
2500 uint16_t index;
2501 uint16_t entries;
2502 char *id_iter;
2503 uint16_t loop_id;
2504 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002505 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506
2507 found_devs = 0;
2508 new_fcport = NULL;
2509 entries = MAX_FIBRE_DEVICES;
2510
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002511 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2512 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513
2514 /* Get list of logged in devices. */
2515 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002517 &entries);
2518 if (rval != QLA_SUCCESS)
2519 goto cleanup_allocation;
2520
2521 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002522 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2524 entries * sizeof(struct gid_list_info)));
2525
2526 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002527 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 if (new_fcport == NULL) {
2529 rval = QLA_MEMORY_ALLOC_FAILED;
2530 goto cleanup_allocation;
2531 }
2532 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2533
2534 /*
2535 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2536 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002537 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2539 fcport->port_type != FCT_BROADCAST &&
2540 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2541
2542 DEBUG(printk("scsi(%ld): Marking port lost, "
2543 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002544 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545
2546 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 }
2548 }
2549
2550 /* Add devices to port list. */
2551 id_iter = (char *)ha->gid_list;
2552 for (index = 0; index < entries; index++) {
2553 domain = ((struct gid_list_info *)id_iter)->domain;
2554 area = ((struct gid_list_info *)id_iter)->area;
2555 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002556 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 loop_id = (uint16_t)
2558 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002559 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002560 loop_id = le16_to_cpu(
2561 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002562 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563
2564 /* Bypass reserved domain fields. */
2565 if ((domain & 0xf0) == 0xf0)
2566 continue;
2567
2568 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002569 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002570 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 continue;
2572
2573 /* Bypass invalid local loop ID. */
2574 if (loop_id > LAST_LOCAL_LOOP_ID)
2575 continue;
2576
2577 /* Fill in member data. */
2578 new_fcport->d_id.b.domain = domain;
2579 new_fcport->d_id.b.area = area;
2580 new_fcport->d_id.b.al_pa = al_pa;
2581 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002582 new_fcport->vp_idx = vha->vp_idx;
2583 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584 if (rval2 != QLA_SUCCESS) {
2585 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2586 "information -- get_port_database=%x, "
2587 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002588 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002589 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 vha->host_no));
2591 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 continue;
2593 }
2594
2595 /* Check for matching device in port list. */
2596 found = 0;
2597 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 if (memcmp(new_fcport->port_name, fcport->port_name,
2600 WWN_SIZE))
2601 continue;
2602
Shyam Sundarddb9b122009-03-24 09:08:10 -07002603 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 fcport->loop_id = new_fcport->loop_id;
2605 fcport->port_type = new_fcport->port_type;
2606 fcport->d_id.b24 = new_fcport->d_id.b24;
2607 memcpy(fcport->node_name, new_fcport->node_name,
2608 WWN_SIZE);
2609
2610 found++;
2611 break;
2612 }
2613
2614 if (!found) {
2615 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616 if (vha->vp_idx) {
2617 new_fcport->vha = vha;
2618 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002619 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
2622 /* Allocate a new replacement fcport. */
2623 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 if (new_fcport == NULL) {
2626 rval = QLA_MEMORY_ALLOC_FAILED;
2627 goto cleanup_allocation;
2628 }
2629 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2630 }
2631
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002632 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002633 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
2637 found_devs++;
2638 }
2639
2640cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002641 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642
2643 if (rval != QLA_SUCCESS) {
2644 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 }
2647
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 return (rval);
2649}
2650
2651static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002653{
2654#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002655 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2656 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002657 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002658 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002659 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002660
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002661 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002662 return;
2663
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002664 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2665 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002666 return;
2667
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002668 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002669 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002670 if (rval != QLA_SUCCESS) {
2671 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2672 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002673 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002674 fcport->port_name[2], fcport->port_name[3],
2675 fcport->port_name[4], fcport->port_name[5],
2676 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002677 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002678 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002679 link_speed = link_speeds[LS_UNKNOWN];
2680 if (fcport->fp_speed < 5)
2681 link_speed = link_speeds[fcport->fp_speed];
2682 else if (fcport->fp_speed == 0x13)
2683 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002684 DEBUG2(qla_printk(KERN_INFO, ha,
2685 "iIDMA adjusted to %s GB/s on "
2686 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002687 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002688 fcport->port_name[1], fcport->port_name[2],
2689 fcport->port_name[3], fcport->port_name[4],
2690 fcport->port_name[5], fcport->port_name[6],
2691 fcport->port_name[7]));
2692 }
2693}
2694
Adrian Bunk23be3312006-11-24 02:46:01 +01002695static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002697{
2698 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002699 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002701
Andrew Vasquezac280b62009-08-20 11:06:05 -07002702 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002703
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002704 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2705 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002706 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2707 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2708 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002710 if (!rport) {
2711 qla_printk(KERN_WARNING, ha,
2712 "Unable to allocate fc remote port!\n");
2713 return;
2714 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002716 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002718
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002719 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002720
2721 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002722 if (fcport->port_type == FCT_INITIATOR)
2723 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2724 if (fcport->port_type == FCT_TARGET)
2725 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002726 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002727}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728
2729/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002730 * qla2x00_update_fcport
2731 * Updates device on list.
2732 *
2733 * Input:
2734 * ha = adapter block pointer.
2735 * fcport = port structure pointer.
2736 *
2737 * Return:
2738 * 0 - Success
2739 * BIT_0 - error
2740 *
2741 * Context:
2742 * Kernel context.
2743 */
2744void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002745qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002746{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002747 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002748
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002749 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002750 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002752 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002753 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002754 PORT_RETRY_TIME);
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07002755 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
Adrian Bunk23be3312006-11-24 02:46:01 +01002756
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002758
2759 atomic_set(&fcport->state, FCS_ONLINE);
2760
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002762}
2763
2764/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 * qla2x00_configure_fabric
2766 * Setup SNS devices with loop ID's.
2767 *
2768 * Input:
2769 * ha = adapter block pointer.
2770 *
2771 * Returns:
2772 * 0 = success.
2773 * BIT_0 = error
2774 */
2775static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777{
2778 int rval, rval2;
2779 fc_port_t *fcport, *fcptemp;
2780 uint16_t next_loopid;
2781 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002782 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002784 struct qla_hw_data *ha = vha->hw;
2785 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786
2787 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002788 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002789 loop_id = NPH_F_PORT;
2790 else
2791 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002792 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 if (rval != QLA_SUCCESS) {
2794 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002797 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 return (QLA_SUCCESS);
2799 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002800 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801
2802 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002803 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 if (rval2 == QLA_RSCNS_HANDLED) {
2805 /* No point doing the scan, just continue. */
2806 return (QLA_SUCCESS);
2807 }
2808 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002809 /* FDMI support. */
2810 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2812 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002813
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002815 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002816 loop_id = NPH_SNS;
2817 else
2818 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002819 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002820 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 if (mb[0] != MBS_COMMAND_COMPLETE) {
2822 DEBUG2(qla_printk(KERN_INFO, ha,
2823 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002824 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 mb[0], mb[1], mb[2], mb[6], mb[7]));
2826 return (QLA_SUCCESS);
2827 }
2828
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2830 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 /* EMPTY */
2832 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 /* EMPTY */
2837 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002838 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002839 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002840 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002841 /* EMPTY */
2842 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843 "failed.\n", vha->host_no));
2844 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 /* EMPTY */
2846 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 }
2849 }
2850
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 if (rval != QLA_SUCCESS)
2853 break;
2854
2855 /*
2856 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002857 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2860 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 break;
2862
2863 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2864 continue;
2865
2866 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002868 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002870 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 fcport->port_type != FCT_INITIATOR &&
2872 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002873 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002874 fcport->loop_id,
2875 fcport->d_id.b.domain,
2876 fcport->d_id.b.area,
2877 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 fcport->loop_id = FC_NO_LOOP_ID;
2879 }
2880 }
2881 }
2882
2883 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002884 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885
2886 /*
2887 * Scan through our port list and login entries that need to be
2888 * logged in.
2889 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002890 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2891 if (atomic_read(&vha->loop_down_timer) ||
2892 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 break;
2894
2895 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2896 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2897 continue;
2898
2899 if (fcport->loop_id == FC_NO_LOOP_ID) {
2900 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002901 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 if (rval != QLA_SUCCESS) {
2904 /* Ran out of IDs to use */
2905 break;
2906 }
2907 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 }
2911
2912 /* Exit if out of loop IDs. */
2913 if (rval != QLA_SUCCESS) {
2914 break;
2915 }
2916
2917 /*
2918 * Login and add the new devices to our port list.
2919 */
2920 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002921 if (atomic_read(&vha->loop_down_timer) ||
2922 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 break;
2924
2925 /* Find a new loop ID to use. */
2926 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 if (rval != QLA_SUCCESS) {
2929 /* Ran out of IDs to use */
2930 break;
2931 }
2932
bdf79622005-04-17 15:06:53 -05002933 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002935
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002936 if (vha->vp_idx) {
2937 fcport->vha = vha;
2938 fcport->vp_idx = vha->vp_idx;
2939 }
2940 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 }
2942 } while (0);
2943
2944 /* Free all new device structures not processed. */
2945 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2946 list_del(&fcport->list);
2947 kfree(fcport);
2948 }
2949
2950 if (rval) {
2951 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002952 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 }
2954
2955 return (rval);
2956}
2957
2958
2959/*
2960 * qla2x00_find_all_fabric_devs
2961 *
2962 * Input:
2963 * ha = adapter block pointer.
2964 * dev = database device entry pointer.
2965 *
2966 * Returns:
2967 * 0 = success.
2968 *
2969 * Context:
2970 * Kernel context.
2971 */
2972static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2974 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002975{
2976 int rval;
2977 uint16_t loop_id;
2978 fc_port_t *fcport, *new_fcport, *fcptemp;
2979 int found;
2980
2981 sw_info_t *swl;
2982 int swl_idx;
2983 int first_dev, last_dev;
2984 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 struct qla_hw_data *ha = vha->hw;
2986 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002987 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988
2989 rval = QLA_SUCCESS;
2990
2991 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002992 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002993 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 /*EMPTY*/
2995 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999 kfree(swl);
3000 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 kfree(swl);
3003 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003004 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 kfree(swl);
3006 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07003007 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
3009 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 }
3011 }
3012 swl_idx = 0;
3013
3014 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003015 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003016 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003017 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 return (QLA_MEMORY_ALLOC_FAILED);
3019 }
3020 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 /* Set start port ID scan at adapter ID. */
3022 first_dev = 1;
3023 last_dev = 0;
3024
3025 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 loop_id = ha->min_external_loopid;
3027 for (; loop_id <= ha->max_loop_id; loop_id++) {
3028 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 continue;
3030
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003031 if (atomic_read(&vha->loop_down_timer) ||
3032 LOOP_TRANSITION(vha)) {
3033 atomic_set(&vha->loop_down_timer, 0);
3034 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3035 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08003037 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038
3039 if (swl != NULL) {
3040 if (last_dev) {
3041 wrap.b24 = new_fcport->d_id.b24;
3042 } else {
3043 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
3044 memcpy(new_fcport->node_name,
3045 swl[swl_idx].node_name, WWN_SIZE);
3046 memcpy(new_fcport->port_name,
3047 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003048 memcpy(new_fcport->fabric_port_name,
3049 swl[swl_idx].fabric_port_name, WWN_SIZE);
3050 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051
3052 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
3053 last_dev = 1;
3054 }
3055 swl_idx++;
3056 }
3057 } else {
3058 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 if (rval != QLA_SUCCESS) {
3061 qla_printk(KERN_WARNING, ha,
3062 "SNS scan failed -- assuming zero-entry "
3063 "result...\n");
3064 list_for_each_entry_safe(fcport, fcptemp,
3065 new_fcports, list) {
3066 list_del(&fcport->list);
3067 kfree(fcport);
3068 }
3069 rval = QLA_SUCCESS;
3070 break;
3071 }
3072 }
3073
3074 /* If wrap on switch device list, exit. */
3075 if (first_dev) {
3076 wrap.b24 = new_fcport->d_id.b24;
3077 first_dev = 0;
3078 } else if (new_fcport->d_id.b24 == wrap.b24) {
3079 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003080 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3082 break;
3083 }
3084
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003085 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003086 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 continue;
3088
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003089 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003090 found = 0;
3091 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003092 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003093 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3094 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003095 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003096 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003097 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003098 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003099 continue;
3100 }
3101
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003102 /* Bypass if same domain and area of adapter. */
3103 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003104 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003105 ISP_CFG_FL)
3106 continue;
3107
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 /* Bypass reserved domain fields. */
3109 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3110 continue;
3111
3112 /* Locate matching device in database. */
3113 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003114 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 if (memcmp(new_fcport->port_name, fcport->port_name,
3116 WWN_SIZE))
3117 continue;
3118
3119 found++;
3120
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003121 /* Update port state. */
3122 memcpy(fcport->fabric_port_name,
3123 new_fcport->fabric_port_name, WWN_SIZE);
3124 fcport->fp_speed = new_fcport->fp_speed;
3125
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 /*
3127 * If address the same and state FCS_ONLINE, nothing
3128 * changed.
3129 */
3130 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3131 atomic_read(&fcport->state) == FCS_ONLINE) {
3132 break;
3133 }
3134
3135 /*
3136 * If device was not a fabric device before.
3137 */
3138 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3139 fcport->d_id.b24 = new_fcport->d_id.b24;
3140 fcport->loop_id = FC_NO_LOOP_ID;
3141 fcport->flags |= (FCF_FABRIC_DEVICE |
3142 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003143 break;
3144 }
3145
3146 /*
3147 * Port ID changed or device was marked to be updated;
3148 * Log it out if still logged in and mark it for
3149 * relogin later.
3150 */
3151 fcport->d_id.b24 = new_fcport->d_id.b24;
3152 fcport->flags |= FCF_LOGIN_NEEDED;
3153 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003154 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155 fcport->port_type != FCT_INITIATOR &&
3156 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003157 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003158 fcport->d_id.b.domain, fcport->d_id.b.area,
3159 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 fcport->loop_id = FC_NO_LOOP_ID;
3161 }
3162
3163 break;
3164 }
3165
3166 if (found)
3167 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 /* If device was not in our fcports list, then add it. */
3169 list_add_tail(&new_fcport->list, new_fcports);
3170
3171 /* Allocate a new replacement fcport. */
3172 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003175 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 return (QLA_MEMORY_ALLOC_FAILED);
3177 }
3178 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3179 new_fcport->d_id.b24 = nxt_d_id.b24;
3180 }
3181
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003182 kfree(swl);
3183 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185 return (rval);
3186}
3187
3188/*
3189 * qla2x00_find_new_loop_id
3190 * Scan through our port list and find a new usable loop ID.
3191 *
3192 * Input:
3193 * ha: adapter state pointer.
3194 * dev: port structure pointer.
3195 *
3196 * Returns:
3197 * qla2x00 local function return status code.
3198 *
3199 * Context:
3200 * Kernel context.
3201 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003202static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003203qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204{
3205 int rval;
3206 int found;
3207 fc_port_t *fcport;
3208 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003209 struct qla_hw_data *ha = vha->hw;
3210 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003211 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212
3213 rval = QLA_SUCCESS;
3214
3215 /* Save starting loop ID. */
3216 first_loop_id = dev->loop_id;
3217
3218 for (;;) {
3219 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003220 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
3223 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226
3227 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 /* first loop ID. */
3230 dev->loop_id = ha->min_external_loopid;
3231 }
3232
3233 /* Check for loop ID being already in use. */
3234 found = 0;
3235 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003236 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3238 if (fcport->loop_id == dev->loop_id &&
3239 fcport != dev) {
3240 /* ID possibly in use */
3241 found++;
3242 break;
3243 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245 if (found)
3246 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247 }
3248
3249 /* If not in use then it is free to use. */
3250 if (!found) {
3251 break;
3252 }
3253
3254 /* ID in use. Try next value. */
3255 dev->loop_id++;
3256
3257 /* If wrap around. No free ID to use. */
3258 if (dev->loop_id == first_loop_id) {
3259 dev->loop_id = FC_NO_LOOP_ID;
3260 rval = QLA_FUNCTION_FAILED;
3261 break;
3262 }
3263 }
3264
3265 return (rval);
3266}
3267
3268/*
3269 * qla2x00_device_resync
3270 * Marks devices in the database that needs resynchronization.
3271 *
3272 * Input:
3273 * ha = adapter block pointer.
3274 *
3275 * Context:
3276 * Kernel context.
3277 */
3278static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003280{
3281 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 uint32_t mask;
3283 fc_port_t *fcport;
3284 uint32_t rscn_entry;
3285 uint8_t rscn_out_iter;
3286 uint8_t format;
3287 port_id_t d_id;
3288
3289 rval = QLA_RSCNS_HANDLED;
3290
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3292 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003294 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 format = MSB(MSW(rscn_entry));
3296 d_id.b.domain = LSB(MSW(rscn_entry));
3297 d_id.b.area = MSB(LSW(rscn_entry));
3298 d_id.b.al_pa = LSB(LSW(rscn_entry));
3299
3300 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3301 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303 d_id.b.area, d_id.b.al_pa));
3304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 vha->rscn_out_ptr++;
3306 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3307 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003308
3309 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003310 for (rscn_out_iter = vha->rscn_out_ptr;
3311 !vha->flags.rscn_queue_overflow &&
3312 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 rscn_out_iter = (rscn_out_iter ==
3314 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3315
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 break;
3318
3319 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003320 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 rscn_out_iter));
3322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 }
3325
3326 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003327 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003329 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330
3331 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003332 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 }
3334
3335 switch (format) {
3336 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 mask = 0xffffff;
3338 break;
3339 case 1:
3340 mask = 0xffff00;
3341 break;
3342 case 2:
3343 mask = 0xff0000;
3344 break;
3345 default:
3346 mask = 0x0;
3347 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003348 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 break;
3350 }
3351
3352 rval = QLA_SUCCESS;
3353
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003354 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3356 (fcport->d_id.b24 & mask) != d_id.b24 ||
3357 fcport->port_type == FCT_BROADCAST)
3358 continue;
3359
3360 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3361 if (format != 3 ||
3362 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003363 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003364 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003365 }
3366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 }
3368 }
3369 return (rval);
3370}
3371
3372/*
3373 * qla2x00_fabric_dev_login
3374 * Login fabric target device and update FC port database.
3375 *
3376 * Input:
3377 * ha: adapter state pointer.
3378 * fcport: port structure list pointer.
3379 * next_loopid: contains value of a new loop ID that can be used
3380 * by the next login attempt.
3381 *
3382 * Returns:
3383 * qla2x00 local function return status code.
3384 *
3385 * Context:
3386 * Kernel context.
3387 */
3388static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003389qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 uint16_t *next_loopid)
3391{
3392 int rval;
3393 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003394 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
3397 rval = QLA_SUCCESS;
3398 retry = 0;
3399
Andrew Vasquezac280b62009-08-20 11:06:05 -07003400 if (IS_ALOGIO_CAPABLE(ha)) {
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003401 if (fcport->flags & FCF_ASYNC_SENT)
3402 return rval;
3403 fcport->flags |= FCF_ASYNC_SENT;
Andrew Vasquezac280b62009-08-20 11:06:05 -07003404 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3405 if (!rval)
3406 return rval;
3407 }
3408
Andrew Vasquez5ff1d582010-05-04 15:01:26 -07003409 fcport->flags &= ~FCF_ASYNC_SENT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003410 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003412 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003413 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003414 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003415 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003416 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003419 fcport->d_id.b.domain, fcport->d_id.b.area,
3420 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003423 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 }
3425 }
3426
3427 return (rval);
3428}
3429
3430/*
3431 * qla2x00_fabric_login
3432 * Issue fabric login command.
3433 *
3434 * Input:
3435 * ha = adapter block pointer.
3436 * device = pointer to FC device type structure.
3437 *
3438 * Returns:
3439 * 0 - Login successfully
3440 * 1 - Login failed
3441 * 2 - Initiator device
3442 * 3 - Fatal error
3443 */
3444int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003445qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446 uint16_t *next_loopid)
3447{
3448 int rval;
3449 int retry;
3450 uint16_t tmp_loopid;
3451 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003452 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453
3454 retry = 0;
3455 tmp_loopid = 0;
3456
3457 for (;;) {
3458 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3459 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3462
3463 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003464 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 fcport->d_id.b.domain, fcport->d_id.b.area,
3466 fcport->d_id.b.al_pa, mb, BIT_0);
3467 if (mb[0] == MBS_PORT_ID_USED) {
3468 /*
3469 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003470 * recommends the driver perform an implicit login with
3471 * the specified ID again. The ID we just used is save
3472 * here so we return with an ID that can be tried by
3473 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 */
3475 retry++;
3476 tmp_loopid = fcport->loop_id;
3477 fcport->loop_id = mb[1];
3478
3479 DEBUG(printk("Fabric Login: port in use - next "
3480 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3481 fcport->loop_id, fcport->d_id.b.domain,
3482 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3483
3484 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3485 /*
3486 * Login succeeded.
3487 */
3488 if (retry) {
3489 /* A retry occurred before. */
3490 *next_loopid = tmp_loopid;
3491 } else {
3492 /*
3493 * No retry occurred before. Just increment the
3494 * ID value for next login.
3495 */
3496 *next_loopid = (fcport->loop_id + 1);
3497 }
3498
3499 if (mb[1] & BIT_0) {
3500 fcport->port_type = FCT_INITIATOR;
3501 } else {
3502 fcport->port_type = FCT_TARGET;
3503 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003504 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003505 }
3506 }
3507
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003508 if (mb[10] & BIT_0)
3509 fcport->supported_classes |= FC_COS_CLASS2;
3510 if (mb[10] & BIT_1)
3511 fcport->supported_classes |= FC_COS_CLASS3;
3512
Linus Torvalds1da177e2005-04-16 15:20:36 -07003513 rval = QLA_SUCCESS;
3514 break;
3515 } else if (mb[0] == MBS_LOOP_ID_USED) {
3516 /*
3517 * Loop ID already used, try next loop ID.
3518 */
3519 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003520 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003521 if (rval != QLA_SUCCESS) {
3522 /* Ran out of loop IDs to use */
3523 break;
3524 }
3525 } else if (mb[0] == MBS_COMMAND_ERROR) {
3526 /*
3527 * Firmware possibly timed out during login. If NO
3528 * retries are left to do then the device is declared
3529 * dead.
3530 */
3531 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003533 fcport->d_id.b.domain, fcport->d_id.b.area,
3534 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003535 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536
3537 rval = 1;
3538 break;
3539 } else {
3540 /*
3541 * unrecoverable / not handled error
3542 */
3543 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003544 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546 fcport->d_id.b.domain, fcport->d_id.b.area,
3547 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3548
3549 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003551 fcport->d_id.b.domain, fcport->d_id.b.area,
3552 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003554 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003555
3556 rval = 3;
3557 break;
3558 }
3559 }
3560
3561 return (rval);
3562}
3563
3564/*
3565 * qla2x00_local_device_login
3566 * Issue local device login command.
3567 *
3568 * Input:
3569 * ha = adapter block pointer.
3570 * loop_id = loop id of device to login to.
3571 *
3572 * Returns (Where's the #define!!!!):
3573 * 0 - Login successfully
3574 * 1 - Login failed
3575 * 3 - Fatal error
3576 */
3577int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003579{
3580 int rval;
3581 uint16_t mb[MAILBOX_REGISTER_COUNT];
3582
3583 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003584 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003585 if (rval == QLA_SUCCESS) {
3586 /* Interrogate mailbox registers for any errors */
3587 if (mb[0] == MBS_COMMAND_ERROR)
3588 rval = 1;
3589 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3590 /* device not in PCB table */
3591 rval = 3;
3592 }
3593
3594 return (rval);
3595}
3596
3597/*
3598 * qla2x00_loop_resync
3599 * Resync with fibre channel devices.
3600 *
3601 * Input:
3602 * ha = adapter block pointer.
3603 *
3604 * Returns:
3605 * 0 = success
3606 */
3607int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003608qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003610 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003611 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003612 struct req_que *req;
3613 struct rsp_que *rsp;
3614
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003615 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003616 req = vha->hw->req_q_map[0];
3617 else
3618 req = vha->req;
3619 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003620
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003621 atomic_set(&vha->loop_state, LOOP_UPDATE);
3622 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3623 if (vha->flags.online) {
3624 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3626 wait_time = 256;
3627 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003628 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003630 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003631 qla2x00_marker(vha, req, rsp, 0, 0,
3632 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003633 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003634
3635 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003636 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003638 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003640 } while (!atomic_read(&vha->loop_down_timer) &&
3641 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3642 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3643 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645 }
3646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003647 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003648 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003650 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003651 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652
3653 return (rval);
3654}
3655
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003657qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003658{
3659 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003660 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003661
3662 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003663 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3664 list_for_each_entry(fcport, &vha->vp_fcports, list)
3665 if (fcport && fcport->drport &&
3666 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3667 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003668}
3669
Giridhar Malavalia9083012010-04-12 17:59:55 -07003670void
3671qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3672{
3673 struct qla_hw_data *ha = vha->hw;
3674 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3675 struct scsi_qla_host *tvp;
3676
3677 vha->flags.online = 0;
3678 ha->flags.chip_reset_done = 0;
3679 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3680 ha->qla_stats.total_isp_aborts++;
3681
3682 qla_printk(KERN_INFO, ha,
3683 "Performing ISP error recovery - ha= %p.\n", ha);
3684
3685 /* Chip reset does not apply to 82XX */
3686 if (!IS_QLA82XX(ha))
3687 ha->isp_ops->reset_chip(vha);
3688
3689 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3690 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3691 atomic_set(&vha->loop_state, LOOP_DOWN);
3692 qla2x00_mark_all_devices_lost(vha, 0);
3693 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3694 qla2x00_mark_all_devices_lost(vp, 0);
3695 } else {
3696 if (!atomic_read(&vha->loop_down_timer))
3697 atomic_set(&vha->loop_down_timer,
3698 LOOP_DOWN_TIME);
3699 }
3700
3701 /* Make sure for ISP 82XX IO DMA is complete */
3702 if (IS_QLA82XX(ha))
3703 qla82xx_wait_for_pending_commands(vha);
3704
3705 /* Requeue all commands in outstanding command list. */
3706 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3707}
3708
Linus Torvalds1da177e2005-04-16 15:20:36 -07003709/*
3710* qla2x00_abort_isp
3711* Resets ISP and aborts all outstanding commands.
3712*
3713* Input:
3714* ha = adapter block pointer.
3715*
3716* Returns:
3717* 0 = success
3718*/
3719int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003721{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003722 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003723 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003724 struct qla_hw_data *ha = vha->hw;
3725 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003726 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003727 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003728
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003729 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003730 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003731
Andrew Vasquez85880802009-12-15 21:29:46 -08003732 if (unlikely(pci_channel_offline(ha->pdev) &&
3733 ha->flags.pci_channel_io_perm_failure)) {
3734 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3735 status = 0;
3736 return status;
3737 }
3738
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003739 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003740
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003741 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003743 if (!qla2x00_restart_isp(vha)) {
3744 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003745
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003746 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003747 /*
3748 * Issue marker command only when we are going
3749 * to start the I/O .
3750 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003751 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 }
3753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003754 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003755
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003756 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003757
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003758 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003759 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003760
Lalit Chandivade29c53972009-10-13 15:16:47 -07003761 if (IS_QLA81XX(ha))
3762 qla2x00_get_fw_version(vha,
3763 &ha->fw_major_version,
3764 &ha->fw_minor_version,
3765 &ha->fw_subminor_version,
3766 &ha->fw_attributes, &ha->fw_memory_size,
3767 ha->mpi_version, &ha->mpi_capabilities,
3768 ha->phy_version);
3769
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003770 if (ha->fce) {
3771 ha->flags.fce_enabled = 1;
3772 memset(ha->fce, 0,
3773 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003774 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003775 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3776 &ha->fce_bufs);
3777 if (rval) {
3778 qla_printk(KERN_WARNING, ha,
3779 "Unable to reinitialize FCE "
3780 "(%d).\n", rval);
3781 ha->flags.fce_enabled = 0;
3782 }
3783 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003784
3785 if (ha->eft) {
3786 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003787 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003788 ha->eft_dma, EFT_NUM_BUFFERS);
3789 if (rval) {
3790 qla_printk(KERN_WARNING, ha,
3791 "Unable to reinitialize EFT "
3792 "(%d).\n", rval);
3793 }
3794 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003796 vha->flags.online = 1;
3797 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003798 if (ha->isp_abort_cnt == 0) {
3799 qla_printk(KERN_WARNING, ha,
3800 "ISP error recovery failed - "
3801 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003802 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 * The next call disables the board
3804 * completely.
3805 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806 ha->isp_ops->reset_adapter(vha);
3807 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003809 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 status = 0;
3811 } else { /* schedule another ISP abort */
3812 ha->isp_abort_cnt--;
3813 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003814 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003815 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003816 status = 1;
3817 }
3818 } else {
3819 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3820 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3821 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003822 vha->host_no, ha->isp_abort_cnt));
3823 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003824 status = 1;
3825 }
3826 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003827
Linus Torvalds1da177e2005-04-16 15:20:36 -07003828 }
3829
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 if (!status) {
3831 DEBUG(printk(KERN_INFO
3832 "qla2x00_abort_isp(%ld): succeeded.\n",
3833 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003834 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 if (vp->vp_idx)
3836 qla2x00_vp_abort_isp(vp);
3837 }
3838 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839 qla_printk(KERN_INFO, ha,
3840 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003841 }
3842
3843 return(status);
3844}
3845
3846/*
3847* qla2x00_restart_isp
3848* restarts the ISP after a reset
3849*
3850* Input:
3851* ha = adapter block pointer.
3852*
3853* Returns:
3854* 0 = success
3855*/
3856static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003857qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003858{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003859 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003860 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003861 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003862 struct req_que *req = ha->req_q_map[0];
3863 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003864
3865 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003866 if (qla2x00_isp_firmware(vha)) {
3867 vha->flags.online = 0;
3868 status = ha->isp_ops->chip_diag(vha);
3869 if (!status)
3870 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003871 }
3872
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003873 if (!status && !(status = qla2x00_init_rings(vha))) {
3874 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003875 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003876 /* Initialize the queues in use */
3877 qla25xx_init_queues(ha);
3878
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003879 status = qla2x00_fw_ready(vha);
3880 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003881 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003882 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003883
3884 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003885 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003887 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003888 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3889 wait_time = 256;
3890 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003891 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3892 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003893 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003894 } while (!atomic_read(&vha->loop_down_timer) &&
3895 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3896 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3897 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898 }
3899
3900 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003901 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 status = 0;
3903
3904 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3905 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003906 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 }
3908 return (status);
3909}
3910
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003911static int
3912qla25xx_init_queues(struct qla_hw_data *ha)
3913{
3914 struct rsp_que *rsp = NULL;
3915 struct req_que *req = NULL;
3916 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3917 int ret = -1;
3918 int i;
3919
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003920 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003921 rsp = ha->rsp_q_map[i];
3922 if (rsp) {
3923 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003924 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003925 if (ret != QLA_SUCCESS)
3926 DEBUG2_17(printk(KERN_WARNING
3927 "%s Rsp que:%d init failed\n", __func__,
3928 rsp->id));
3929 else
3930 DEBUG2_17(printk(KERN_INFO
3931 "%s Rsp que:%d inited\n", __func__,
3932 rsp->id));
3933 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003934 }
3935 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003936 req = ha->req_q_map[i];
3937 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003938 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003939 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003940 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003941 if (ret != QLA_SUCCESS)
3942 DEBUG2_17(printk(KERN_WARNING
3943 "%s Req que:%d init failed\n", __func__,
3944 req->id));
3945 else
3946 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003947 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003948 req->id));
3949 }
3950 }
3951 return ret;
3952}
3953
Linus Torvalds1da177e2005-04-16 15:20:36 -07003954/*
3955* qla2x00_reset_adapter
3956* Reset adapter.
3957*
3958* Input:
3959* ha = adapter block pointer.
3960*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003961void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003962qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003963{
3964 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003965 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003966 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003968 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003969 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003970
Linus Torvalds1da177e2005-04-16 15:20:36 -07003971 spin_lock_irqsave(&ha->hardware_lock, flags);
3972 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3973 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3974 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3975 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3976 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3977}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003978
3979void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003980qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003981{
3982 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003983 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003984 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3985
Giridhar Malavalia9083012010-04-12 17:59:55 -07003986 if (IS_QLA82XX(ha))
3987 return;
3988
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);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003991
3992 spin_lock_irqsave(&ha->hardware_lock, flags);
3993 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3994 RD_REG_DWORD(&reg->hccr);
3995 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3996 RD_REG_DWORD(&reg->hccr);
3997 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003998
3999 if (IS_NOPOLLING_TYPE(ha))
4000 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004001}
4002
David Miller4e08df32007-04-16 12:37:43 -07004003/* On sparc systems, obtain port and node WWN from firmware
4004 * properties.
4005 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004006static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
4007 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07004008{
4009#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004010 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07004011 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07004012 struct device_node *dp = pci_device_to_OF_node(pdev);
4013 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07004014 int len;
4015
4016 val = of_get_property(dp, "port-wwn", &len);
4017 if (val && len >= WWN_SIZE)
4018 memcpy(nv->port_name, val, WWN_SIZE);
4019
4020 val = of_get_property(dp, "node-wwn", &len);
4021 if (val && len >= WWN_SIZE)
4022 memcpy(nv->node_name, val, WWN_SIZE);
4023#endif
4024}
4025
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004026int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004027qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004028{
David Miller4e08df32007-04-16 12:37:43 -07004029 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004030 struct init_cb_24xx *icb;
4031 struct nvram_24xx *nv;
4032 uint32_t *dptr;
4033 uint8_t *dptr1, *dptr2;
4034 uint32_t chksum;
4035 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004036 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004037
David Miller4e08df32007-04-16 12:37:43 -07004038 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004039 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07004040 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004041
4042 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004043 if (ha->flags.port0) {
4044 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4045 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4046 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004047 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08004048 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4049 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004050 ha->nvram_size = sizeof(struct nvram_24xx);
4051 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07004052 if (IS_QLA82XX(ha))
4053 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004054
Seokmann Ju281afe12007-07-26 13:43:34 -07004055 /* Get VPD data into cache */
4056 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07004058 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4059
4060 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004061 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004062 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004063 ha->nvram_size);
4064 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4065 chksum += le32_to_cpu(*dptr++);
4066
Andrew Vasquez76403352009-04-06 22:33:39 -07004067 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07004068 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004069
4070 /* Bad NVRAM data, set defaults parameters. */
4071 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4072 || nv->id[3] != ' ' ||
4073 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4074 /* Reset NVRAM data. */
4075 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4076 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4077 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004078 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4079 "invalid -- WWPN) defaults.\n");
4080
4081 /*
4082 * Set default initialization control block.
4083 */
4084 memset(nv, 0, ha->nvram_size);
4085 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4086 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4087 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4088 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4089 nv->exchange_count = __constant_cpu_to_le16(0);
4090 nv->hard_address = __constant_cpu_to_le16(124);
4091 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004092 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004093 nv->port_name[2] = 0x00;
4094 nv->port_name[3] = 0xe0;
4095 nv->port_name[4] = 0x8b;
4096 nv->port_name[5] = 0x1c;
4097 nv->port_name[6] = 0x55;
4098 nv->port_name[7] = 0x86;
4099 nv->node_name[0] = 0x20;
4100 nv->node_name[1] = 0x00;
4101 nv->node_name[2] = 0x00;
4102 nv->node_name[3] = 0xe0;
4103 nv->node_name[4] = 0x8b;
4104 nv->node_name[5] = 0x1c;
4105 nv->node_name[6] = 0x55;
4106 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004107 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004108 nv->login_retry_count = __constant_cpu_to_le16(8);
4109 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4110 nv->login_timeout = __constant_cpu_to_le16(0);
4111 nv->firmware_options_1 =
4112 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4113 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4114 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4115 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4116 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4117 nv->efi_parameters = __constant_cpu_to_le32(0);
4118 nv->reset_delay = 5;
4119 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4120 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4121 nv->link_down_timeout = __constant_cpu_to_le16(30);
4122
4123 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004124 }
4125
4126 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004128
4129 /* Copy 1st segment. */
4130 dptr1 = (uint8_t *)icb;
4131 dptr2 = (uint8_t *)&nv->version;
4132 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4133 while (cnt--)
4134 *dptr1++ = *dptr2++;
4135
4136 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004137 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004138
4139 /* Copy 2nd segment. */
4140 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4141 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4142 cnt = (uint8_t *)&icb->reserved_3 -
4143 (uint8_t *)&icb->interrupt_delay_timer;
4144 while (cnt--)
4145 *dptr1++ = *dptr2++;
4146
4147 /*
4148 * Setup driver NVRAM options.
4149 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004150 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004151 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004152
Andrew Vasquez5341e862006-05-17 15:09:16 -07004153 /* Use alternate WWN? */
4154 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4155 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4156 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4157 }
4158
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004159 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004160 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004161 /*
4162 * Firmware will apply the following mask if the nodename was
4163 * not provided.
4164 */
4165 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4166 icb->node_name[0] &= 0xF0;
4167 }
4168
4169 /* Set host adapter parameters. */
4170 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004171 ha->flags.enable_lip_reset = 0;
4172 ha->flags.enable_lip_full_login =
4173 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4174 ha->flags.enable_target_reset =
4175 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004176 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004177 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004178
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004179 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4180 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004181
4182 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4183 sizeof(ha->fw_seriallink_options24));
4184
4185 /* save HBA serial number */
4186 ha->serial0 = icb->port_name[5];
4187 ha->serial1 = icb->port_name[6];
4188 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004189 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4190 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004191
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004192 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4193
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004194 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4195
4196 /* Set minimum login_timeout to 4 seconds. */
4197 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4198 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4199 if (le16_to_cpu(nv->login_timeout) < 4)
4200 nv->login_timeout = __constant_cpu_to_le16(4);
4201 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004202 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004203
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004204 /* Set minimum RATOV to 100 tenths of a second. */
4205 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004206
4207 ha->loop_reset_delay = nv->reset_delay;
4208
4209 /* Link Down Timeout = 0:
4210 *
4211 * When Port Down timer expires we will start returning
4212 * I/O's to OS with "DID_NO_CONNECT".
4213 *
4214 * Link Down Timeout != 0:
4215 *
4216 * The driver waits for the link to come up after link down
4217 * before returning I/Os to OS with "DID_NO_CONNECT".
4218 */
4219 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4220 ha->loop_down_abort_time =
4221 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4222 } else {
4223 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4224 ha->loop_down_abort_time =
4225 (LOOP_DOWN_TIME - ha->link_down_timeout);
4226 }
4227
4228 /* Need enough time to try and get the port back. */
4229 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4230 if (qlport_down_retry)
4231 ha->port_down_retry_count = qlport_down_retry;
4232
4233 /* Set login_retry_count */
4234 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4235 if (ha->port_down_retry_count ==
4236 le16_to_cpu(nv->port_down_retry_count) &&
4237 ha->port_down_retry_count > 3)
4238 ha->login_retry_count = ha->port_down_retry_count;
4239 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4240 ha->login_retry_count = ha->port_down_retry_count;
4241 if (ql2xloginretrycount)
4242 ha->login_retry_count = ql2xloginretrycount;
4243
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004244 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004245 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004246 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4247 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4248 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4249 le16_to_cpu(icb->interrupt_delay_timer): 2;
4250 }
4251 icb->firmware_options_2 &= __constant_cpu_to_le32(
4252 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004253 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004254 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004255 ha->zio_mode = QLA_ZIO_MODE_6;
4256
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004257 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004258 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004259 ha->zio_timer * 100));
4260 qla_printk(KERN_INFO, ha,
4261 "ZIO mode %d enabled; timer delay (%d us).\n",
4262 ha->zio_mode, ha->zio_timer * 100);
4263
4264 icb->firmware_options_2 |= cpu_to_le32(
4265 (uint32_t)ha->zio_mode);
4266 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004267 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004268 }
4269
David Miller4e08df32007-04-16 12:37:43 -07004270 if (rval) {
4271 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004272 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004273 }
4274 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004275}
4276
Adrian Bunk413975a2006-06-30 02:33:06 -07004277static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004278qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4279 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004280{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004281 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004282 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004283 uint32_t *dcode, dlen;
4284 uint32_t risc_addr;
4285 uint32_t risc_size;
4286 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004287 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004288 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004289
4290 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004291 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004292
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004293 rval = QLA_SUCCESS;
4294
4295 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004296 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004297 *srisc_addr = 0;
4298
4299 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004300 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004301 for (i = 0; i < 4; i++)
4302 dcode[i] = be32_to_cpu(dcode[i]);
4303 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4304 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4305 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4306 dcode[3] == 0)) {
4307 qla_printk(KERN_WARNING, ha,
4308 "Unable to verify integrity of flash firmware image!\n");
4309 qla_printk(KERN_WARNING, ha,
4310 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4311 dcode[1], dcode[2], dcode[3]);
4312
4313 return QLA_FUNCTION_FAILED;
4314 }
4315
4316 while (segments && rval == QLA_SUCCESS) {
4317 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004318 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004319
4320 risc_addr = be32_to_cpu(dcode[2]);
4321 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4322 risc_size = be32_to_cpu(dcode[3]);
4323
4324 fragment = 0;
4325 while (risc_size > 0 && rval == QLA_SUCCESS) {
4326 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4327 if (dlen > risc_size)
4328 dlen = risc_size;
4329
4330 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4331 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004332 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004333
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004334 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004335 for (i = 0; i < dlen; i++)
4336 dcode[i] = swab32(dcode[i]);
4337
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004338 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004339 dlen);
4340 if (rval) {
4341 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004342 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004343 fragment));
4344 qla_printk(KERN_WARNING, ha,
4345 "[ERROR] Failed to load segment %d of "
4346 "firmware\n", fragment);
4347 break;
4348 }
4349
4350 faddr += dlen;
4351 risc_addr += dlen;
4352 risc_size -= dlen;
4353 fragment++;
4354 }
4355
4356 /* Next segment. */
4357 segments--;
4358 }
4359
4360 return rval;
4361}
4362
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004363#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4364
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004365int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004366qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004367{
4368 int rval;
4369 int i, fragment;
4370 uint16_t *wcode, *fwcode;
4371 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4372 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004373 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004374 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004375
4376 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004377 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004378 if (!blob) {
4379 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004380 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4381 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004382 return QLA_FUNCTION_FAILED;
4383 }
4384
4385 rval = QLA_SUCCESS;
4386
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004387 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004388 *srisc_addr = 0;
4389 fwcode = (uint16_t *)blob->fw->data;
4390 fwclen = 0;
4391
4392 /* Validate firmware image by checking version. */
4393 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4394 qla_printk(KERN_WARNING, ha,
4395 "Unable to verify integrity of firmware image (%Zd)!\n",
4396 blob->fw->size);
4397 goto fail_fw_integrity;
4398 }
4399 for (i = 0; i < 4; i++)
4400 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4401 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4402 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4403 wcode[2] == 0 && wcode[3] == 0)) {
4404 qla_printk(KERN_WARNING, ha,
4405 "Unable to verify integrity of firmware image!\n");
4406 qla_printk(KERN_WARNING, ha,
4407 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4408 wcode[1], wcode[2], wcode[3]);
4409 goto fail_fw_integrity;
4410 }
4411
4412 seg = blob->segs;
4413 while (*seg && rval == QLA_SUCCESS) {
4414 risc_addr = *seg;
4415 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4416 risc_size = be16_to_cpu(fwcode[3]);
4417
4418 /* Validate firmware image size. */
4419 fwclen += risc_size * sizeof(uint16_t);
4420 if (blob->fw->size < fwclen) {
4421 qla_printk(KERN_WARNING, ha,
4422 "Unable to verify integrity of firmware image "
4423 "(%Zd)!\n", blob->fw->size);
4424 goto fail_fw_integrity;
4425 }
4426
4427 fragment = 0;
4428 while (risc_size > 0 && rval == QLA_SUCCESS) {
4429 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4430 if (wlen > risc_size)
4431 wlen = risc_size;
4432
4433 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004434 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004435 risc_addr, wlen));
4436
4437 for (i = 0; i < wlen; i++)
4438 wcode[i] = swab16(fwcode[i]);
4439
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004440 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004441 wlen);
4442 if (rval) {
4443 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004444 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004445 fragment));
4446 qla_printk(KERN_WARNING, ha,
4447 "[ERROR] Failed to load segment %d of "
4448 "firmware\n", fragment);
4449 break;
4450 }
4451
4452 fwcode += wlen;
4453 risc_addr += wlen;
4454 risc_size -= wlen;
4455 fragment++;
4456 }
4457
4458 /* Next segment. */
4459 seg++;
4460 }
4461 return rval;
4462
4463fail_fw_integrity:
4464 return QLA_FUNCTION_FAILED;
4465}
4466
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004467static int
4468qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004469{
4470 int rval;
4471 int segments, fragment;
4472 uint32_t *dcode, dlen;
4473 uint32_t risc_addr;
4474 uint32_t risc_size;
4475 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004476 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004477 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004478 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004479 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004480
Andrew Vasquez54333832005-11-09 15:49:04 -08004481 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004482 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004483 if (!blob) {
4484 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004485 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4486 "from: " QLA_FW_URL ".\n");
4487
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004488 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004489 }
4490
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004491 qla_printk(KERN_INFO, ha,
4492 "FW: Loading via request-firmware...\n");
4493
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004494 rval = QLA_SUCCESS;
4495
4496 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004497 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004498 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004499 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004500 fwclen = 0;
4501
4502 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004503 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004504 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004505 "Unable to verify integrity of firmware image (%Zd)!\n",
4506 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004507 goto fail_fw_integrity;
4508 }
4509 for (i = 0; i < 4; i++)
4510 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4511 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4512 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4513 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4514 dcode[3] == 0)) {
4515 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004516 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004517 qla_printk(KERN_WARNING, ha,
4518 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4519 dcode[1], dcode[2], dcode[3]);
4520 goto fail_fw_integrity;
4521 }
4522
4523 while (segments && rval == QLA_SUCCESS) {
4524 risc_addr = be32_to_cpu(fwcode[2]);
4525 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4526 risc_size = be32_to_cpu(fwcode[3]);
4527
4528 /* Validate firmware image size. */
4529 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004530 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004531 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004532 "Unable to verify integrity of firmware image "
4533 "(%Zd)!\n", blob->fw->size);
4534
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004535 goto fail_fw_integrity;
4536 }
4537
4538 fragment = 0;
4539 while (risc_size > 0 && rval == QLA_SUCCESS) {
4540 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4541 if (dlen > risc_size)
4542 dlen = risc_size;
4543
4544 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004545 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004546 risc_addr, dlen));
4547
4548 for (i = 0; i < dlen; i++)
4549 dcode[i] = swab32(fwcode[i]);
4550
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004551 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004552 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004553 if (rval) {
4554 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004555 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004556 fragment));
4557 qla_printk(KERN_WARNING, ha,
4558 "[ERROR] Failed to load segment %d of "
4559 "firmware\n", fragment);
4560 break;
4561 }
4562
4563 fwcode += dlen;
4564 risc_addr += dlen;
4565 risc_size -= dlen;
4566 fragment++;
4567 }
4568
4569 /* Next segment. */
4570 segments--;
4571 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004572 return rval;
4573
4574fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004575 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004576}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004577
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004578int
4579qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4580{
4581 int rval;
4582
Andrew Vasqueze337d902009-04-06 22:33:49 -07004583 if (ql2xfwloadbin == 1)
4584 return qla81xx_load_risc(vha, srisc_addr);
4585
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004586 /*
4587 * FW Load priority:
4588 * 1) Firmware via request-firmware interface (.bin file).
4589 * 2) Firmware residing in flash.
4590 */
4591 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4592 if (rval == QLA_SUCCESS)
4593 return rval;
4594
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004595 return qla24xx_load_risc_flash(vha, srisc_addr,
4596 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004597}
4598
4599int
4600qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4601{
4602 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004603 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004604
Andrew Vasqueze337d902009-04-06 22:33:49 -07004605 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004606 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004607
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004608 /*
4609 * FW Load priority:
4610 * 1) Firmware residing in flash.
4611 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004612 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004613 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004614 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004615 if (rval == QLA_SUCCESS)
4616 return rval;
4617
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004618try_blob_fw:
4619 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4620 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4621 return rval;
4622
4623 qla_printk(KERN_ERR, ha,
4624 "FW: Attempting to fallback to golden firmware...\n");
4625 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4626 if (rval != QLA_SUCCESS)
4627 return rval;
4628
4629 qla_printk(KERN_ERR, ha,
4630 "FW: Please update operational firmware...\n");
4631 ha->flags.running_gold_fw = 1;
4632
4633 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004634}
4635
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004636void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004637qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004638{
4639 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004640 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004641
Andrew Vasquez85880802009-12-15 21:29:46 -08004642 if (ha->flags.pci_channel_io_perm_failure)
4643 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004644 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004645 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004646 if (!ha->fw_major_version)
4647 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004648
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004649 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004650 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004651 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004652 ha->isp_ops->reset_chip(vha);
4653 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004654 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004655 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004656 continue;
4657 qla_printk(KERN_INFO, ha,
4658 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004659 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004660 }
4661}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004662
4663int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004664qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004665{
4666 int rval = QLA_SUCCESS;
4667 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004668 struct qla_hw_data *ha = vha->hw;
4669 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004670 struct req_que *req;
4671 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004673 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004674 return -EINVAL;
4675
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004676 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004677 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004678 req = ha->req_q_map[0];
4679 else
4680 req = vha->req;
4681 rsp = req->rsp;
4682
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004683 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004684 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004685 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004686 }
4687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004688 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004689
4690 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004691 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004692 if (mb[0] != MBS_COMMAND_COMPLETE) {
4693 DEBUG15(qla_printk(KERN_INFO, ha,
4694 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4695 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4696 mb[0], mb[1], mb[2], mb[6], mb[7]));
4697 return (QLA_FUNCTION_FAILED);
4698 }
4699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004700 atomic_set(&vha->loop_down_timer, 0);
4701 atomic_set(&vha->loop_state, LOOP_UP);
4702 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4703 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4704 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004705
4706 return rval;
4707}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004708
4709/* 84XX Support **************************************************************/
4710
4711static LIST_HEAD(qla_cs84xx_list);
4712static DEFINE_MUTEX(qla_cs84xx_mutex);
4713
4714static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004715qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004716{
4717 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004718 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004719
4720 mutex_lock(&qla_cs84xx_mutex);
4721
4722 /* Find any shared 84xx chip. */
4723 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4724 if (cs84xx->bus == ha->pdev->bus) {
4725 kref_get(&cs84xx->kref);
4726 goto done;
4727 }
4728 }
4729
4730 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4731 if (!cs84xx)
4732 goto done;
4733
4734 kref_init(&cs84xx->kref);
4735 spin_lock_init(&cs84xx->access_lock);
4736 mutex_init(&cs84xx->fw_update_mutex);
4737 cs84xx->bus = ha->pdev->bus;
4738
4739 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4740done:
4741 mutex_unlock(&qla_cs84xx_mutex);
4742 return cs84xx;
4743}
4744
4745static void
4746__qla84xx_chip_release(struct kref *kref)
4747{
4748 struct qla_chip_state_84xx *cs84xx =
4749 container_of(kref, struct qla_chip_state_84xx, kref);
4750
4751 mutex_lock(&qla_cs84xx_mutex);
4752 list_del(&cs84xx->list);
4753 mutex_unlock(&qla_cs84xx_mutex);
4754 kfree(cs84xx);
4755}
4756
4757void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004758qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004759{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004760 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004761 if (ha->cs84xx)
4762 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4763}
4764
4765static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004766qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004767{
4768 int rval;
4769 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004770 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004771
4772 mutex_lock(&ha->cs84xx->fw_update_mutex);
4773
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004774 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004775
4776 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4777
4778 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4779 QLA_SUCCESS;
4780}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004781
4782/* 81XX Support **************************************************************/
4783
4784int
4785qla81xx_nvram_config(scsi_qla_host_t *vha)
4786{
4787 int rval;
4788 struct init_cb_81xx *icb;
4789 struct nvram_81xx *nv;
4790 uint32_t *dptr;
4791 uint8_t *dptr1, *dptr2;
4792 uint32_t chksum;
4793 uint16_t cnt;
4794 struct qla_hw_data *ha = vha->hw;
4795
4796 rval = QLA_SUCCESS;
4797 icb = (struct init_cb_81xx *)ha->init_cb;
4798 nv = ha->nvram;
4799
4800 /* Determine NVRAM starting address. */
4801 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004802 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004803
4804 /* Get VPD data into cache */
4805 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004806 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4807 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004808
4809 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004810 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004811 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004812 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004813 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4814 chksum += le32_to_cpu(*dptr++);
4815
Andrew Vasquez76403352009-04-06 22:33:39 -07004816 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004817 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4818
4819 /* Bad NVRAM data, set defaults parameters. */
4820 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4821 || nv->id[3] != ' ' ||
4822 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4823 /* Reset NVRAM data. */
4824 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4825 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4826 le16_to_cpu(nv->nvram_version));
4827 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4828 "invalid -- WWPN) defaults.\n");
4829
4830 /*
4831 * Set default initialization control block.
4832 */
4833 memset(nv, 0, ha->nvram_size);
4834 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4835 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4836 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4837 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4838 nv->exchange_count = __constant_cpu_to_le16(0);
4839 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004840 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004841 nv->port_name[2] = 0x00;
4842 nv->port_name[3] = 0xe0;
4843 nv->port_name[4] = 0x8b;
4844 nv->port_name[5] = 0x1c;
4845 nv->port_name[6] = 0x55;
4846 nv->port_name[7] = 0x86;
4847 nv->node_name[0] = 0x20;
4848 nv->node_name[1] = 0x00;
4849 nv->node_name[2] = 0x00;
4850 nv->node_name[3] = 0xe0;
4851 nv->node_name[4] = 0x8b;
4852 nv->node_name[5] = 0x1c;
4853 nv->node_name[6] = 0x55;
4854 nv->node_name[7] = 0x86;
4855 nv->login_retry_count = __constant_cpu_to_le16(8);
4856 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4857 nv->login_timeout = __constant_cpu_to_le16(0);
4858 nv->firmware_options_1 =
4859 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4860 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4861 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4862 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4863 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4864 nv->efi_parameters = __constant_cpu_to_le32(0);
4865 nv->reset_delay = 5;
4866 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4867 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4868 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004869 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004870 nv->enode_mac[1] = 0x02;
4871 nv->enode_mac[2] = 0x03;
4872 nv->enode_mac[3] = 0x04;
4873 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004874 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004875
4876 rval = 1;
4877 }
4878
4879 /* Reset Initialization control block */
4880 memset(icb, 0, sizeof(struct init_cb_81xx));
4881
4882 /* Copy 1st segment. */
4883 dptr1 = (uint8_t *)icb;
4884 dptr2 = (uint8_t *)&nv->version;
4885 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4886 while (cnt--)
4887 *dptr1++ = *dptr2++;
4888
4889 icb->login_retry_count = nv->login_retry_count;
4890
4891 /* Copy 2nd segment. */
4892 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4893 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4894 cnt = (uint8_t *)&icb->reserved_5 -
4895 (uint8_t *)&icb->interrupt_delay_timer;
4896 while (cnt--)
4897 *dptr1++ = *dptr2++;
4898
4899 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4900 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4901 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4902 icb->enode_mac[0] = 0x01;
4903 icb->enode_mac[1] = 0x02;
4904 icb->enode_mac[2] = 0x03;
4905 icb->enode_mac[3] = 0x04;
4906 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004907 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004908 }
4909
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004910 /* Use extended-initialization control block. */
4911 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4912
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004913 /*
4914 * Setup driver NVRAM options.
4915 */
4916 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07004917 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004918
4919 /* Use alternate WWN? */
4920 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4921 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4922 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4923 }
4924
4925 /* Prepare nodename */
4926 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4927 /*
4928 * Firmware will apply the following mask if the nodename was
4929 * not provided.
4930 */
4931 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4932 icb->node_name[0] &= 0xF0;
4933 }
4934
4935 /* Set host adapter parameters. */
4936 ha->flags.disable_risc_code_load = 0;
4937 ha->flags.enable_lip_reset = 0;
4938 ha->flags.enable_lip_full_login =
4939 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4940 ha->flags.enable_target_reset =
4941 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4942 ha->flags.enable_led_scheme = 0;
4943 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4944
4945 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4946 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4947
4948 /* save HBA serial number */
4949 ha->serial0 = icb->port_name[5];
4950 ha->serial1 = icb->port_name[6];
4951 ha->serial2 = icb->port_name[7];
4952 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4953 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4954
4955 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4956
4957 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4958
4959 /* Set minimum login_timeout to 4 seconds. */
4960 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4961 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4962 if (le16_to_cpu(nv->login_timeout) < 4)
4963 nv->login_timeout = __constant_cpu_to_le16(4);
4964 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4965 icb->login_timeout = nv->login_timeout;
4966
4967 /* Set minimum RATOV to 100 tenths of a second. */
4968 ha->r_a_tov = 100;
4969
4970 ha->loop_reset_delay = nv->reset_delay;
4971
4972 /* Link Down Timeout = 0:
4973 *
4974 * When Port Down timer expires we will start returning
4975 * I/O's to OS with "DID_NO_CONNECT".
4976 *
4977 * Link Down Timeout != 0:
4978 *
4979 * The driver waits for the link to come up after link down
4980 * before returning I/Os to OS with "DID_NO_CONNECT".
4981 */
4982 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4983 ha->loop_down_abort_time =
4984 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4985 } else {
4986 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4987 ha->loop_down_abort_time =
4988 (LOOP_DOWN_TIME - ha->link_down_timeout);
4989 }
4990
4991 /* Need enough time to try and get the port back. */
4992 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4993 if (qlport_down_retry)
4994 ha->port_down_retry_count = qlport_down_retry;
4995
4996 /* Set login_retry_count */
4997 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4998 if (ha->port_down_retry_count ==
4999 le16_to_cpu(nv->port_down_retry_count) &&
5000 ha->port_down_retry_count > 3)
5001 ha->login_retry_count = ha->port_down_retry_count;
5002 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
5003 ha->login_retry_count = ha->port_down_retry_count;
5004 if (ql2xloginretrycount)
5005 ha->login_retry_count = ql2xloginretrycount;
5006
5007 /* Enable ZIO. */
5008 if (!vha->flags.init_done) {
5009 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
5010 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
5011 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
5012 le16_to_cpu(icb->interrupt_delay_timer): 2;
5013 }
5014 icb->firmware_options_2 &= __constant_cpu_to_le32(
5015 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
5016 vha->flags.process_response_queue = 0;
5017 if (ha->zio_mode != QLA_ZIO_DISABLED) {
5018 ha->zio_mode = QLA_ZIO_MODE_6;
5019
5020 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
5021 "(%d us).\n", vha->host_no, ha->zio_mode,
5022 ha->zio_timer * 100));
5023 qla_printk(KERN_INFO, ha,
5024 "ZIO mode %d enabled; timer delay (%d us).\n",
5025 ha->zio_mode, ha->zio_timer * 100);
5026
5027 icb->firmware_options_2 |= cpu_to_le32(
5028 (uint32_t)ha->zio_mode);
5029 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
5030 vha->flags.process_response_queue = 1;
5031 }
5032
5033 if (rval) {
5034 DEBUG2_3(printk(KERN_WARNING
5035 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
5036 }
5037 return (rval);
5038}
5039
Giridhar Malavalia9083012010-04-12 17:59:55 -07005040int
5041qla82xx_restart_isp(scsi_qla_host_t *vha)
5042{
5043 int status, rval;
5044 uint32_t wait_time;
5045 struct qla_hw_data *ha = vha->hw;
5046 struct req_que *req = ha->req_q_map[0];
5047 struct rsp_que *rsp = ha->rsp_q_map[0];
5048 struct scsi_qla_host *vp;
5049 struct scsi_qla_host *tvp;
5050
5051 status = qla2x00_init_rings(vha);
5052 if (!status) {
5053 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5054 ha->flags.chip_reset_done = 1;
5055
5056 status = qla2x00_fw_ready(vha);
5057 if (!status) {
5058 qla_printk(KERN_INFO, ha,
5059 "%s(): Start configure loop, "
5060 "status = %d\n", __func__, status);
5061
5062 /* Issue a marker after FW becomes ready. */
5063 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
5064
5065 vha->flags.online = 1;
5066 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5067 wait_time = 256;
5068 do {
5069 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5070 qla2x00_configure_loop(vha);
5071 wait_time--;
5072 } while (!atomic_read(&vha->loop_down_timer) &&
5073 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
5074 wait_time &&
5075 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5076 }
5077
5078 /* if no cable then assume it's good */
5079 if ((vha->device_flags & DFLG_NO_CABLE))
5080 status = 0;
5081
5082 qla_printk(KERN_INFO, ha,
5083 "%s(): Configure loop done, status = 0x%x\n",
5084 __func__, status);
5085 }
5086
5087 if (!status) {
5088 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5089
5090 if (!atomic_read(&vha->loop_down_timer)) {
5091 /*
5092 * Issue marker command only when we are going
5093 * to start the I/O .
5094 */
5095 vha->marker_needed = 1;
5096 }
5097
5098 vha->flags.online = 1;
5099
5100 ha->isp_ops->enable_intrs(ha);
5101
5102 ha->isp_abort_cnt = 0;
5103 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5104
5105 if (ha->fce) {
5106 ha->flags.fce_enabled = 1;
5107 memset(ha->fce, 0,
5108 fce_calc_size(ha->fce_bufs));
5109 rval = qla2x00_enable_fce_trace(vha,
5110 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5111 &ha->fce_bufs);
5112 if (rval) {
5113 qla_printk(KERN_WARNING, ha,
5114 "Unable to reinitialize FCE "
5115 "(%d).\n", rval);
5116 ha->flags.fce_enabled = 0;
5117 }
5118 }
5119
5120 if (ha->eft) {
5121 memset(ha->eft, 0, EFT_SIZE);
5122 rval = qla2x00_enable_eft_trace(vha,
5123 ha->eft_dma, EFT_NUM_BUFFERS);
5124 if (rval) {
5125 qla_printk(KERN_WARNING, ha,
5126 "Unable to reinitialize EFT "
5127 "(%d).\n", rval);
5128 }
5129 }
5130 } else { /* failed the ISP abort */
5131 vha->flags.online = 1;
5132 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
5133 if (ha->isp_abort_cnt == 0) {
5134 qla_printk(KERN_WARNING, ha,
5135 "ISP error recovery failed - "
5136 "board disabled\n");
5137 /*
5138 * The next call disables the board
5139 * completely.
5140 */
5141 ha->isp_ops->reset_adapter(vha);
5142 vha->flags.online = 0;
5143 clear_bit(ISP_ABORT_RETRY,
5144 &vha->dpc_flags);
5145 status = 0;
5146 } else { /* schedule another ISP abort */
5147 ha->isp_abort_cnt--;
5148 qla_printk(KERN_INFO, ha,
5149 "qla%ld: ISP abort - "
5150 "retry remaining %d\n",
5151 vha->host_no, ha->isp_abort_cnt);
5152 status = 1;
5153 }
5154 } else {
5155 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
5156 qla_printk(KERN_INFO, ha,
5157 "(%ld): ISP error recovery "
5158 "- retrying (%d) more times\n",
5159 vha->host_no, ha->isp_abort_cnt);
5160 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5161 status = 1;
5162 }
5163 }
5164
5165 if (!status) {
5166 DEBUG(printk(KERN_INFO
5167 "qla82xx_restart_isp(%ld): succeeded.\n",
5168 vha->host_no));
5169 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5170 if (vp->vp_idx)
5171 qla2x00_vp_abort_isp(vp);
5172 }
5173 } else {
5174 qla_printk(KERN_INFO, ha,
5175 "qla82xx_restart_isp: **** FAILED ****\n");
5176 }
5177
5178 return status;
5179}
5180
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005181void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005182qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005183{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005184 struct qla_hw_data *ha = vha->hw;
5185
5186 if (!ql2xetsenable)
5187 return;
5188
5189 /* Enable ETS Burst. */
5190 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5191 ha->fw_options[2] |= BIT_9;
5192 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005193}
Sarang Radke09ff7012010-03-19 17:03:59 -07005194
5195/*
5196 * qla24xx_get_fcp_prio
5197 * Gets the fcp cmd priority value for the logged in port.
5198 * Looks for a match of the port descriptors within
5199 * each of the fcp prio config entries. If a match is found,
5200 * the tag (priority) value is returned.
5201 *
5202 * Input:
5203 * ha = adapter block po
5204 * fcport = port structure pointer.
5205 *
5206 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005207 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005208 * 0 (if not found)
5209 *
5210 * Context:
5211 * Kernel context
5212 */
5213uint8_t
5214qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5215{
5216 int i, entries;
5217 uint8_t pid_match, wwn_match;
5218 uint8_t priority;
5219 uint32_t pid1, pid2;
5220 uint64_t wwn1, wwn2;
5221 struct qla_fcp_prio_entry *pri_entry;
5222 struct qla_hw_data *ha = vha->hw;
5223
5224 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5225 return 0;
5226
5227 priority = 0;
5228 entries = ha->fcp_prio_cfg->num_entries;
5229 pri_entry = &ha->fcp_prio_cfg->entry[0];
5230
5231 for (i = 0; i < entries; i++) {
5232 pid_match = wwn_match = 0;
5233
5234 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5235 pri_entry++;
5236 continue;
5237 }
5238
5239 /* check source pid for a match */
5240 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5241 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5242 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5243 if (pid1 == INVALID_PORT_ID)
5244 pid_match++;
5245 else if (pid1 == pid2)
5246 pid_match++;
5247 }
5248
5249 /* check destination pid for a match */
5250 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5251 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5252 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5253 if (pid1 == INVALID_PORT_ID)
5254 pid_match++;
5255 else if (pid1 == pid2)
5256 pid_match++;
5257 }
5258
5259 /* check source WWN for a match */
5260 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5261 wwn1 = wwn_to_u64(vha->port_name);
5262 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5263 if (wwn2 == (uint64_t)-1)
5264 wwn_match++;
5265 else if (wwn1 == wwn2)
5266 wwn_match++;
5267 }
5268
5269 /* check destination WWN for a match */
5270 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5271 wwn1 = wwn_to_u64(fcport->port_name);
5272 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5273 if (wwn2 == (uint64_t)-1)
5274 wwn_match++;
5275 else if (wwn1 == wwn2)
5276 wwn_match++;
5277 }
5278
5279 if (pid_match == 2 || wwn_match == 2) {
5280 /* Found a matching entry */
5281 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5282 priority = pri_entry->tag;
5283 break;
5284 }
5285
5286 pri_entry++;
5287 }
5288
5289 return priority;
5290}
5291
5292/*
5293 * qla24xx_update_fcport_fcp_prio
5294 * Activates fcp priority for the logged in fc port
5295 *
5296 * Input:
5297 * ha = adapter block pointer.
5298 * fcp = port structure pointer.
5299 *
5300 * Return:
5301 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5302 *
5303 * Context:
5304 * Kernel context.
5305 */
5306int
5307qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5308{
5309 int ret;
5310 uint8_t priority;
5311 uint16_t mb[5];
5312
5313 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5314 fcport->port_type != FCT_TARGET ||
5315 fcport->loop_id == FC_NO_LOOP_ID)
5316 return QLA_FUNCTION_FAILED;
5317
5318 priority = qla24xx_get_fcp_prio(ha, fcport);
5319 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5320 if (ret == QLA_SUCCESS)
5321 fcport->fcp_prio = priority;
5322 else
5323 DEBUG2(printk(KERN_WARNING
5324 "scsi(%ld): Unable to activate fcp priority, "
5325 " ret=0x%x\n", ha->host_no, ret));
5326
5327 return ret;
5328}
5329
5330/*
5331 * qla24xx_update_all_fcp_prio
5332 * Activates fcp priority for all the logged in ports
5333 *
5334 * Input:
5335 * ha = adapter block pointer.
5336 *
5337 * Return:
5338 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5339 *
5340 * Context:
5341 * Kernel context.
5342 */
5343int
5344qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5345{
5346 int ret;
5347 fc_port_t *fcport;
5348
5349 ret = QLA_FUNCTION_FAILED;
5350 /* We need to set priority for all logged in ports */
5351 list_for_each_entry(fcport, &vha->vp_fcports, list)
5352 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5353
5354 return ret;
5355}