blob: c3c2c3627a70707870b9cfe32c94aeb878d68ca7 [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
122 if (lio->ctx.type == SRB_LOGIN_CMD)
123 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
124}
125
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700126static void
127qla2x00_async_login_ctx_done(srb_t *sp)
128{
129 struct srb_logio *lio = sp->ctx;
130
131 qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport,
132 lio->data);
133 lio->ctx.free(sp);
134}
135
Andrew Vasquezac280b62009-08-20 11:06:05 -0700136int
137qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
138 uint16_t *data)
139{
140 struct qla_hw_data *ha = vha->hw;
141 srb_t *sp;
142 struct srb_logio *lio;
143 int rval;
144
145 rval = QLA_FUNCTION_FAILED;
146 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
147 ELS_TMO_2_RATOV(ha) + 2);
148 if (!sp)
149 goto done;
150
151 lio = sp->ctx;
152 lio->ctx.type = SRB_LOGIN_CMD;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700153 lio->ctx.name = "login";
Andrew Vasquezac280b62009-08-20 11:06:05 -0700154 lio->ctx.timeout = qla2x00_async_logio_timeout;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700155 lio->ctx.done = qla2x00_async_login_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700156 lio->flags |= SRB_LOGIN_COND_PLOGI;
157 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
158 lio->flags |= SRB_LOGIN_RETRIED;
159 rval = qla2x00_start_sp(sp);
160 if (rval != QLA_SUCCESS)
161 goto done_free_sp;
162
163 DEBUG2(printk(KERN_DEBUG
164 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
165 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
166 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
167 fcport->login_retry));
168 return rval;
169
170done_free_sp:
171 del_timer_sync(&lio->ctx.timer);
172 lio->ctx.free(sp);
173done:
174 return rval;
175}
176
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700177static void
178qla2x00_async_logout_ctx_done(srb_t *sp)
179{
180 struct srb_logio *lio = sp->ctx;
181
182 qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport,
183 lio->data);
184 lio->ctx.free(sp);
185}
186
Andrew Vasquezac280b62009-08-20 11:06:05 -0700187int
188qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
189{
190 struct qla_hw_data *ha = vha->hw;
191 srb_t *sp;
192 struct srb_logio *lio;
193 int rval;
194
195 rval = QLA_FUNCTION_FAILED;
196 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
197 ELS_TMO_2_RATOV(ha) + 2);
198 if (!sp)
199 goto done;
200
201 lio = sp->ctx;
202 lio->ctx.type = SRB_LOGOUT_CMD;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700203 lio->ctx.name = "logout";
Andrew Vasquezac280b62009-08-20 11:06:05 -0700204 lio->ctx.timeout = qla2x00_async_logio_timeout;
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700205 lio->ctx.done = qla2x00_async_logout_ctx_done;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700206 rval = qla2x00_start_sp(sp);
207 if (rval != QLA_SUCCESS)
208 goto done_free_sp;
209
210 DEBUG2(printk(KERN_DEBUG
211 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
212 fcport->vha->host_no, sp->handle, fcport->loop_id,
213 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
214 return rval;
215
216done_free_sp:
217 del_timer_sync(&lio->ctx.timer);
218 lio->ctx.free(sp);
219done:
220 return rval;
221}
222
223int
224qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
225 uint16_t *data)
226{
227 int rval;
Andrew Vasquezac280b62009-08-20 11:06:05 -0700228
229 switch (data[0]) {
230 case MBS_COMMAND_COMPLETE:
Andrew Vasquez99b0bec2010-05-04 15:01:25 -0700231 if (fcport->flags & FCF_FCP2_DEVICE) {
232 rval = qla2x00_get_port_database(vha, fcport, BIT_1);
233 if (rval != QLA_SUCCESS) {
234 qla2x00_mark_device_lost(vha, fcport, 1, 0);
235 break;
236 }
237 }
238 qla2x00_update_fcport(vha, fcport);
Andrew Vasquezac280b62009-08-20 11:06:05 -0700239 break;
240 case MBS_COMMAND_ERROR:
241 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
242 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
243 else
244 qla2x00_mark_device_lost(vha, fcport, 1, 0);
245 break;
246 case MBS_PORT_ID_USED:
247 fcport->loop_id = data[1];
248 qla2x00_post_async_login_work(vha, fcport, NULL);
249 break;
250 case MBS_LOOP_ID_USED:
251 fcport->loop_id++;
252 rval = qla2x00_find_new_loop_id(vha, fcport);
253 if (rval != QLA_SUCCESS) {
254 qla2x00_mark_device_lost(vha, fcport, 1, 0);
255 break;
256 }
257 qla2x00_post_async_login_work(vha, fcport, NULL);
258 break;
259 }
260 return QLA_SUCCESS;
261}
262
263int
264qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
265 uint16_t *data)
266{
267 qla2x00_mark_device_lost(vha, fcport, 1, 0);
268 return QLA_SUCCESS;
269}
270
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271/****************************************************************************/
272/* QLogic ISP2x00 Hardware Support Functions. */
273/****************************************************************************/
274
275/*
276* qla2x00_initialize_adapter
277* Initialize board.
278*
279* Input:
280* ha = adapter block pointer.
281*
282* Returns:
283* 0 = success
284*/
285int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800286qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287{
288 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800289 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800290 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700291
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800293 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700294 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800295 vha->flags.reset_active = 0;
Andrew Vasquez85880802009-12-15 21:29:46 -0800296 ha->flags.pci_channel_io_perm_failure = 0;
297 ha->flags.eeh_busy = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800298 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
299 atomic_set(&vha->loop_state, LOOP_DOWN);
300 vha->device_flags = DFLG_NO_CABLE;
301 vha->dpc_flags = 0;
302 vha->flags.management_server_logged_in = 0;
303 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 ha->isp_abort_cnt = 0;
305 ha->beacon_blink_led = 0;
306
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800307 set_bit(0, ha->req_qid_map);
308 set_bit(0, ha->rsp_qid_map);
309
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700310 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800311 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800313 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800314 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 return (rval);
316 }
317
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800318 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800320 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700321 if (rval) {
322 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800323 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700324 return (rval);
325 }
326
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800327 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800328
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700330
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800331 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700332
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700333 if (ha->flags.disable_serdes) {
334 /* Mask HBA via NVRAM settings? */
335 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
336 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800337 vha->port_name[0], vha->port_name[1],
338 vha->port_name[2], vha->port_name[3],
339 vha->port_name[4], vha->port_name[5],
340 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700341 return QLA_FUNCTION_FAILED;
342 }
343
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
345
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800346 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
347 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800348 if (rval)
349 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800351 if (rval)
352 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 }
Giridhar Malavalia9083012010-04-12 17:59:55 -0700354
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700355 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800356 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700357 if (!ha->cs84xx) {
358 qla_printk(KERN_ERR, ha,
359 "Unable to configure ISP84XX.\n");
360 return QLA_FUNCTION_FAILED;
361 }
362 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800363 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700364 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800366 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
Andrew Vasquez6c452a42010-03-19 17:04:02 -0700367 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
Giridhar Malavali9a069e12010-01-12 13:02:47 -0800368 rval = qla84xx_init_chip(vha);
369 if (rval != QLA_SUCCESS) {
370 qla_printk(KERN_ERR, ha,
371 "Unable to initialize ISP84XX.\n");
372 qla84xx_put_chip(vha);
373 }
374 }
375
Sarang Radke09ff7012010-03-19 17:03:59 -0700376 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) {
377 if (qla24xx_read_fcp_prio_cfg(vha))
378 qla_printk(KERN_ERR, ha,
379 "Unable to read FCP priority data.\n");
380 }
381
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382 return (rval);
383}
384
385/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700386 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387 * @ha: HA context
388 *
389 * Returns 0 on success.
390 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700391int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800392qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700394 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700395 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800396 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700397 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
Linus Torvalds1da177e2005-04-16 15:20:36 -0700399 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700400 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700403 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700404 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
405
Andrew Vasquez737faec2008-10-24 15:13:45 -0700406 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700408 /* Get PCI bus information. */
409 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700410 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700411 spin_unlock_irqrestore(&ha->hardware_lock, flags);
412
413 return QLA_SUCCESS;
414}
415
416/**
417 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
418 * @ha: HA context
419 *
420 * Returns 0 on success.
421 */
422int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800423qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700424{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700425 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700426 unsigned long flags = 0;
427 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800428 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700429 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700430
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700431 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700432 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700433
434 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700435 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700436
437 if (IS_QLA2322(ha) || IS_QLA6322(ha))
438 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700439 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700440
441 /*
442 * If this is a 2300 card and not 2312, reset the
443 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
444 * the 2310 also reports itself as a 2300 so we need to get the
445 * fb revision level -- a 6 indicates it really is a 2300 and
446 * not a 2310.
447 */
448 if (IS_QLA2300(ha)) {
449 spin_lock_irqsave(&ha->hardware_lock, flags);
450
451 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700452 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700453 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700454 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700455 break;
456
457 udelay(10);
458 }
459
460 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700461 WRT_REG_WORD(&reg->ctrl_status, 0x20);
462 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700463
464 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700465 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700466
467 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700468 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700469
470 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700471 WRT_REG_WORD(&reg->ctrl_status, 0x0);
472 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700473
474 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700475 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700476 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700477 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700478 break;
479
480 udelay(10);
481 }
482
483 spin_unlock_irqrestore(&ha->hardware_lock, flags);
484 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700485
486 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
487
Andrew Vasquez737faec2008-10-24 15:13:45 -0700488 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700489
490 /* Get PCI bus information. */
491 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700492 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700493 spin_unlock_irqrestore(&ha->hardware_lock, flags);
494
495 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496}
497
498/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700499 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
500 * @ha: HA context
501 *
502 * Returns 0 on success.
503 */
504int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800505qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700506{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700507 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700508 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800509 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700510 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700511
512 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700513 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700514
515 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700516 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700517 w &= ~PCI_COMMAND_INTX_DISABLE;
518 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
519
520 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
521
522 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700523 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
524 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700525
526 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700527 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
528 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700529
Andrew Vasquez737faec2008-10-24 15:13:45 -0700530 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700531
Auke Kok44c10132007-06-08 15:46:36 -0700532 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800533
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700534 /* Get PCI bus information. */
535 spin_lock_irqsave(&ha->hardware_lock, flags);
536 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
537 spin_unlock_irqrestore(&ha->hardware_lock, flags);
538
539 return QLA_SUCCESS;
540}
541
542/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700543 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
544 * @ha: HA context
545 *
546 * Returns 0 on success.
547 */
548int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800549qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700550{
551 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800552 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700553
554 pci_set_master(ha->pdev);
555 pci_try_set_mwi(ha->pdev);
556
557 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
558 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
559 w &= ~PCI_COMMAND_INTX_DISABLE;
560 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
561
562 /* PCIe -- adjust Maximum Read Request Size (2048). */
563 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
564 pcie_set_readrq(ha->pdev, 2048);
565
Andrew Vasquez737faec2008-10-24 15:13:45 -0700566 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700567
568 ha->chip_revision = ha->pdev->revision;
569
570 return QLA_SUCCESS;
571}
572
573/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 * qla2x00_isp_firmware() - Choose firmware image.
575 * @ha: HA context
576 *
577 * Returns 0 on success.
578 */
579static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800580qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581{
582 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700583 uint16_t loop_id, topo, sw_cap;
584 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700588 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 if (ha->flags.disable_risc_code_load) {
591 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800592 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
594
595 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800596 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700597 if (rval == QLA_SUCCESS) {
598 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700600 &area, &domain, &topo, &sw_cap);
601 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 }
603
604 if (rval) {
605 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800606 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 }
608
609 return (rval);
610}
611
612/**
613 * qla2x00_reset_chip() - Reset ISP chip.
614 * @ha: HA context
615 *
616 * Returns 0 on success.
617 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700618void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800619qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620{
621 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800622 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700623 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 uint16_t cmd;
626
Andrew Vasquez85880802009-12-15 21:29:46 -0800627 if (unlikely(pci_channel_offline(ha->pdev)))
628 return;
629
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700630 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631
632 spin_lock_irqsave(&ha->hardware_lock, flags);
633
634 /* Turn off master enable */
635 cmd = 0;
636 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
637 cmd &= ~PCI_COMMAND_MASTER;
638 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
639
640 if (!IS_QLA2100(ha)) {
641 /* Pause RISC. */
642 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
643 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
644 for (cnt = 0; cnt < 30000; cnt++) {
645 if ((RD_REG_WORD(&reg->hccr) &
646 HCCR_RISC_PAUSE) != 0)
647 break;
648 udelay(100);
649 }
650 } else {
651 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
652 udelay(10);
653 }
654
655 /* Select FPM registers. */
656 WRT_REG_WORD(&reg->ctrl_status, 0x20);
657 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
658
659 /* FPM Soft Reset. */
660 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
661 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
662
663 /* Toggle Fpm Reset. */
664 if (!IS_QLA2200(ha)) {
665 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
666 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
667 }
668
669 /* Select frame buffer registers. */
670 WRT_REG_WORD(&reg->ctrl_status, 0x10);
671 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
672
673 /* Reset frame buffer FIFOs. */
674 if (IS_QLA2200(ha)) {
675 WRT_FB_CMD_REG(ha, reg, 0xa000);
676 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
677 } else {
678 WRT_FB_CMD_REG(ha, reg, 0x00fc);
679
680 /* Read back fb_cmd until zero or 3 seconds max */
681 for (cnt = 0; cnt < 3000; cnt++) {
682 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
683 break;
684 udelay(100);
685 }
686 }
687
688 /* Select RISC module registers. */
689 WRT_REG_WORD(&reg->ctrl_status, 0);
690 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
691
692 /* Reset RISC processor. */
693 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
694 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
695
696 /* Release RISC processor. */
697 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
698 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
699 }
700
701 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
702 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
703
704 /* Reset ISP chip. */
705 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
706
707 /* Wait for RISC to recover from reset. */
708 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
709 /*
710 * It is necessary to for a delay here since the card doesn't
711 * respond to PCI reads during a reset. On some architectures
712 * this will result in an MCA.
713 */
714 udelay(20);
715 for (cnt = 30000; cnt; cnt--) {
716 if ((RD_REG_WORD(&reg->ctrl_status) &
717 CSR_ISP_SOFT_RESET) == 0)
718 break;
719 udelay(100);
720 }
721 } else
722 udelay(10);
723
724 /* Reset RISC processor. */
725 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
726
727 WRT_REG_WORD(&reg->semaphore, 0);
728
729 /* Release RISC processor. */
730 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
731 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
732
733 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
734 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700735 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
738 udelay(100);
739 }
740 } else
741 udelay(100);
742
743 /* Turn on master enable */
744 cmd |= PCI_COMMAND_MASTER;
745 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
746
747 /* Disable RISC pause on FPM parity error. */
748 if (!IS_QLA2100(ha)) {
749 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
750 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
751 }
752
753 spin_unlock_irqrestore(&ha->hardware_lock, flags);
754}
755
756/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700757 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700758 * @ha: HA context
759 *
760 * Returns 0 on success.
761 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700762static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800763qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700764{
765 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800766 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700767 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
768 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800769 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700770
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700771 spin_lock_irqsave(&ha->hardware_lock, flags);
772
773 /* Reset RISC. */
774 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
775 for (cnt = 0; cnt < 30000; cnt++) {
776 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
777 break;
778
779 udelay(10);
780 }
781
782 WRT_REG_DWORD(&reg->ctrl_status,
783 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800784 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700785
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800786 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700787 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700788 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
789 for (cnt = 10000 ; cnt && d2; cnt--) {
790 udelay(5);
791 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
792 barrier();
793 }
794
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800795 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700796 d2 = RD_REG_DWORD(&reg->ctrl_status);
797 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
798 udelay(5);
799 d2 = RD_REG_DWORD(&reg->ctrl_status);
800 barrier();
801 }
802
803 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
804 RD_REG_DWORD(&reg->hccr);
805
806 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
807 RD_REG_DWORD(&reg->hccr);
808
809 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
810 RD_REG_DWORD(&reg->hccr);
811
812 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
813 for (cnt = 6000000 ; cnt && d2; cnt--) {
814 udelay(5);
815 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
816 barrier();
817 }
818
819 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800820
821 if (IS_NOPOLLING_TYPE(ha))
822 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700823}
824
825/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700826 * qla24xx_reset_chip() - Reset ISP24xx chip.
827 * @ha: HA context
828 *
829 * Returns 0 on success.
830 */
831void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800832qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700833{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez85880802009-12-15 21:29:46 -0800835
836 if (pci_channel_offline(ha->pdev) &&
837 ha->flags.pci_channel_io_perm_failure) {
838 return;
839 }
840
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700841 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700842
843 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700845}
846
847/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700848 * qla2x00_chip_diag() - Test chip for proper operation.
849 * @ha: HA context
850 *
851 * Returns 0 on success.
852 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700853int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800854qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855{
856 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800857 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700858 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 unsigned long flags = 0;
860 uint16_t data;
861 uint32_t cnt;
862 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800863 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865 /* Assume a failed state */
866 rval = QLA_FUNCTION_FAILED;
867
868 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800869 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
871 spin_lock_irqsave(&ha->hardware_lock, flags);
872
873 /* Reset ISP chip. */
874 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
875
876 /*
877 * We need to have a delay here since the card will not respond while
878 * in reset causing an MCA on some architectures.
879 */
880 udelay(20);
881 data = qla2x00_debounce_register(&reg->ctrl_status);
882 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
883 udelay(5);
884 data = RD_REG_WORD(&reg->ctrl_status);
885 barrier();
886 }
887
888 if (!cnt)
889 goto chip_diag_failed;
890
891 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700892 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893
894 /* Reset RISC processor. */
895 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
896 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
897
898 /* Workaround for QLA2312 PCI parity error */
899 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
900 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
901 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
902 udelay(5);
903 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700904 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 }
906 } else
907 udelay(10);
908
909 if (!cnt)
910 goto chip_diag_failed;
911
912 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -0700913 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
915 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
916 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
917 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
918 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
919 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
920 mb[3] != PROD_ID_3) {
921 qla_printk(KERN_WARNING, ha,
922 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
923
924 goto chip_diag_failed;
925 }
926 ha->product_id[0] = mb[1];
927 ha->product_id[1] = mb[2];
928 ha->product_id[2] = mb[3];
929 ha->product_id[3] = mb[4];
930
931 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800932 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
934 else
935 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800936 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 if (IS_QLA2200(ha) &&
939 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
940 /* Limit firmware transfer size with a 2200A */
941 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800944 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 ha->fw_transfer_size = 128;
946 }
947
948 /* Wrap Incoming Mailboxes Test. */
949 spin_unlock_irqrestore(&ha->hardware_lock, flags);
950
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800951 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
952 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953 if (rval) {
954 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800955 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700956 qla_printk(KERN_WARNING, ha,
957 "Failed mailbox send register test\n");
958 }
959 else {
960 /* Flag a successful rval */
961 rval = QLA_SUCCESS;
962 }
963 spin_lock_irqsave(&ha->hardware_lock, flags);
964
965chip_diag_failed:
966 if (rval)
967 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800968 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969
970 spin_unlock_irqrestore(&ha->hardware_lock, flags);
971
972 return (rval);
973}
974
975/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700976 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
977 * @ha: HA context
978 *
979 * Returns 0 on success.
980 */
981int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700983{
984 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800986 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700987
Giridhar Malavalia9083012010-04-12 17:59:55 -0700988 if (IS_QLA82XX(ha))
989 return QLA_SUCCESS;
990
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800991 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700992
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800993 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700994 if (rval) {
995 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800996 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700997 qla_printk(KERN_WARNING, ha,
998 "Failed mailbox send register test\n");
999 } else {
1000 /* Flag a successful rval */
1001 rval = QLA_SUCCESS;
1002 }
1003
1004 return rval;
1005}
1006
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001007void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001008qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001009{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001010 int rval;
1011 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001012 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001013 dma_addr_t tc_dma;
1014 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001015 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001016 struct req_que *req = ha->req_q_map[0];
1017 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001018
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001019 if (ha->fw_dump) {
1020 qla_printk(KERN_WARNING, ha,
1021 "Firmware dump previously allocated.\n");
1022 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001023 }
1024
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001025 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001026 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001027 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1028 fixed_size = sizeof(struct qla2100_fw_dump);
1029 } else if (IS_QLA23XX(ha)) {
1030 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
1031 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
1032 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -07001033 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001034 if (IS_QLA81XX(ha))
1035 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
1036 else if (IS_QLA25XX(ha))
1037 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
1038 else
1039 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001040 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
1041 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001042 if (ha->mqenable)
1043 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001044 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001045 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001046 goto try_eft;
1047
1048 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
1049 GFP_KERNEL);
1050 if (!tc) {
1051 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1052 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001053 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001054 }
1055
1056 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001057 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001058 ha->fce_mb, &ha->fce_bufs);
1059 if (rval) {
1060 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1061 "FCE (%d).\n", rval);
1062 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1063 tc_dma);
1064 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001065 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001066 }
1067
1068 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1069 FCE_SIZE / 1024);
1070
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001071 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001072 ha->flags.fce_enabled = 1;
1073 ha->fce_dma = tc_dma;
1074 ha->fce = tc;
1075try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001076 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001077 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001078 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001079 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001080 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1081 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1082 goto cont_alloc;
1083 }
1084
Andrew Vasquezfc447652008-01-17 09:02:18 -08001085 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001086 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001087 if (rval) {
1088 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1089 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001090 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1091 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001092 goto cont_alloc;
1093 }
1094
1095 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1096 EFT_SIZE / 1024);
1097
1098 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001099 ha->eft_dma = tc_dma;
1100 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001101 }
1102cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001103 req_q_size = req->length * sizeof(request_t);
1104 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001105
1106 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001107 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001108 ha->chain_offset = dump_size;
1109 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001110
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001111 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001112 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001113 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001114 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001115
1116 if (ha->eft) {
1117 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1118 ha->eft_dma);
1119 ha->eft = NULL;
1120 ha->eft_dma = 0;
1121 }
1122 return;
1123 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001124 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1125 dump_size / 1024);
1126
1127 ha->fw_dump_len = dump_size;
1128 ha->fw_dump->signature[0] = 'Q';
1129 ha->fw_dump->signature[1] = 'L';
1130 ha->fw_dump->signature[2] = 'G';
1131 ha->fw_dump->signature[3] = 'C';
1132 ha->fw_dump->version = __constant_htonl(1);
1133
1134 ha->fw_dump->fixed_size = htonl(fixed_size);
1135 ha->fw_dump->mem_size = htonl(mem_size);
1136 ha->fw_dump->req_q_size = htonl(req_q_size);
1137 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1138
1139 ha->fw_dump->eft_size = htonl(eft_size);
1140 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1141 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1142
1143 ha->fw_dump->header_size =
1144 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001145}
1146
Andrew Vasquez18e75552009-06-03 09:55:30 -07001147static int
1148qla81xx_mpi_sync(scsi_qla_host_t *vha)
1149{
1150#define MPS_MASK 0xe0
1151 int rval;
1152 uint16_t dc;
1153 uint32_t dw;
1154 struct qla_hw_data *ha = vha->hw;
1155
1156 if (!IS_QLA81XX(vha->hw))
1157 return QLA_SUCCESS;
1158
1159 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1160 if (rval != QLA_SUCCESS) {
1161 DEBUG2(qla_printk(KERN_WARNING, ha,
1162 "Sync-MPI: Unable to acquire semaphore.\n"));
1163 goto done;
1164 }
1165
1166 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1167 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1168 if (rval != QLA_SUCCESS) {
1169 DEBUG2(qla_printk(KERN_WARNING, ha,
1170 "Sync-MPI: Unable to read sync.\n"));
1171 goto done_release;
1172 }
1173
1174 dc &= MPS_MASK;
1175 if (dc == (dw & MPS_MASK))
1176 goto done_release;
1177
1178 dw &= ~MPS_MASK;
1179 dw |= dc;
1180 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1181 if (rval != QLA_SUCCESS) {
1182 DEBUG2(qla_printk(KERN_WARNING, ha,
1183 "Sync-MPI: Unable to gain sync.\n"));
1184 }
1185
1186done_release:
1187 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1188 if (rval != QLA_SUCCESS) {
1189 DEBUG2(qla_printk(KERN_WARNING, ha,
1190 "Sync-MPI: Unable to release semaphore.\n"));
1191 }
1192
1193done:
1194 return rval;
1195}
1196
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001197/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198 * qla2x00_setup_chip() - Load and start RISC firmware.
1199 * @ha: HA context
1200 *
1201 * Returns 0 on success.
1202 */
1203static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001204qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001205{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001206 int rval;
1207 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001209 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1210 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001211 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001212
Giridhar Malavalia9083012010-04-12 17:59:55 -07001213 if (IS_QLA82XX(ha)) {
1214 rval = ha->isp_ops->load_risc(vha, &srisc_address);
1215 if (rval == QLA_SUCCESS)
1216 goto enable_82xx_npiv;
1217 }
1218
Andrew Vasquez3db06522008-01-31 12:33:49 -08001219 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1220 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1221 spin_lock_irqsave(&ha->hardware_lock, flags);
1222 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1223 RD_REG_WORD(&reg->hccr);
1224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1225 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226
Andrew Vasquez18e75552009-06-03 09:55:30 -07001227 qla81xx_mpi_sync(vha);
1228
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001230 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001231 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001233 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236 if (rval == QLA_SUCCESS) {
1237 /* Start firmware execution. */
1238 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001239 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001241 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001243 if (rval == QLA_SUCCESS) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07001244enable_82xx_npiv:
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001245 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001246 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 &ha->fw_major_version,
1248 &ha->fw_minor_version,
1249 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001250 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001251 ha->mpi_version, &ha->mpi_capabilities,
1252 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001253 if (rval != QLA_SUCCESS)
1254 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001255 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001256 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001257 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001258 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001259 if ((!ha->max_npiv_vports) ||
1260 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001261 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001262 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001263 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001264 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001265 qla2x00_get_resource_cnts(vha, NULL,
1266 &ha->fw_xcb_count, NULL, NULL,
Andrew Vasquezf3a0a772009-10-13 15:16:49 -07001267 &ha->max_npiv_vports, NULL);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001268
Giridhar Malavalia9083012010-04-12 17:59:55 -07001269 if (!fw_major_version && ql2xallocfwdump) {
1270 if (!IS_QLA82XX(ha))
1271 qla2x00_alloc_fw_dump(vha);
1272 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001273 }
1274 } else {
1275 DEBUG2(printk(KERN_INFO
1276 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001277 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 }
1279 }
1280
Andrew Vasquez3db06522008-01-31 12:33:49 -08001281 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1282 /* Enable proper parity. */
1283 spin_lock_irqsave(&ha->hardware_lock, flags);
1284 if (IS_QLA2300(ha))
1285 /* SRAM parity */
1286 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1287 else
1288 /* SRAM, Instruction RAM and GP RAM parity */
1289 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1290 RD_REG_WORD(&reg->hccr);
1291 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1292 }
1293
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001294 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1295 uint32_t size;
1296
1297 rval = qla81xx_fac_get_sector_size(vha, &size);
1298 if (rval == QLA_SUCCESS) {
1299 ha->flags.fac_supported = 1;
1300 ha->fdt_block_size = size << 2;
1301 } else {
1302 qla_printk(KERN_ERR, ha,
1303 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1304 ha->fw_major_version, ha->fw_minor_version,
1305 ha->fw_subminor_version);
1306 }
1307 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001308failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309 if (rval) {
1310 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001311 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 }
1313
1314 return (rval);
1315}
1316
1317/**
1318 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1319 * @ha: HA context
1320 *
1321 * Beginning of request ring has initialization control block already built
1322 * by nvram config routine.
1323 *
1324 * Returns 0 on success.
1325 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001326void
1327qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001328{
1329 uint16_t cnt;
1330 response_t *pkt;
1331
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001332 rsp->ring_ptr = rsp->ring;
1333 rsp->ring_index = 0;
1334 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001335 pkt = rsp->ring_ptr;
1336 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337 pkt->signature = RESPONSE_PROCESSED;
1338 pkt++;
1339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340}
1341
1342/**
1343 * qla2x00_update_fw_options() - Read and process firmware options.
1344 * @ha: HA context
1345 *
1346 * Returns 0 on success.
1347 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001348void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001349qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350{
1351 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
1354 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356
1357 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1358 return;
1359
1360 /* Serial Link options. */
1361 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1364 sizeof(ha->fw_seriallink_options)));
1365
1366 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1367 if (ha->fw_seriallink_options[3] & BIT_2) {
1368 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1369
1370 /* 1G settings */
1371 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1372 emphasis = (ha->fw_seriallink_options[2] &
1373 (BIT_4 | BIT_3)) >> 3;
1374 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001375 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 rx_sens = (ha->fw_seriallink_options[0] &
1377 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1378 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1379 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1380 if (rx_sens == 0x0)
1381 rx_sens = 0x3;
1382 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1383 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1384 ha->fw_options[10] |= BIT_5 |
1385 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1386 (tx_sens & (BIT_1 | BIT_0));
1387
1388 /* 2G settings */
1389 swing = (ha->fw_seriallink_options[2] &
1390 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1391 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1392 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001393 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001394 rx_sens = (ha->fw_seriallink_options[1] &
1395 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1396 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1397 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1398 if (rx_sens == 0x0)
1399 rx_sens = 0x3;
1400 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1401 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1402 ha->fw_options[11] |= BIT_5 |
1403 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1404 (tx_sens & (BIT_1 | BIT_0));
1405 }
1406
1407 /* FCP2 options. */
1408 /* Return command IOCBs without waiting for an ABTS to complete. */
1409 ha->fw_options[3] |= BIT_13;
1410
1411 /* LED scheme. */
1412 if (ha->flags.enable_led_scheme)
1413 ha->fw_options[2] |= BIT_12;
1414
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001415 /* Detect ISP6312. */
1416 if (IS_QLA6312(ha))
1417 ha->fw_options[2] |= BIT_13;
1418
Linus Torvalds1da177e2005-04-16 15:20:36 -07001419 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001420 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421}
1422
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001423void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001424qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001425{
1426 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001427 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001428
Giridhar Malavalia9083012010-04-12 17:59:55 -07001429 if (IS_QLA82XX(ha))
1430 return;
1431
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001432 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001433 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001434 return;
1435
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001436 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001437 le16_to_cpu(ha->fw_seriallink_options24[1]),
1438 le16_to_cpu(ha->fw_seriallink_options24[2]),
1439 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001440 if (rval != QLA_SUCCESS) {
1441 qla_printk(KERN_WARNING, ha,
1442 "Unable to update Serial Link options (%x).\n", rval);
1443 }
1444}
1445
1446void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001448{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001450 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001451 struct req_que *req = ha->req_q_map[0];
1452 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001453
1454 /* Setup ring parameters in initialization control block. */
1455 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1456 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1458 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1459 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1460 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1461 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1462 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001463
1464 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1465 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1466 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1467 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1468 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1469}
1470
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001471void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001473{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001474 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001475 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1476 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1477 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001478 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001479 uint16_t rid = 0;
1480 struct req_que *req = ha->req_q_map[0];
1481 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001482
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001483/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001484 icb = (struct init_cb_24xx *)ha->init_cb;
1485 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1486 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001487 icb->request_q_length = cpu_to_le16(req->length);
1488 icb->response_q_length = cpu_to_le16(rsp->length);
1489 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1490 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1491 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1492 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001493
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001494 if (ha->mqenable) {
1495 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1496 icb->rid = __constant_cpu_to_le16(rid);
1497 if (ha->flags.msix_enabled) {
1498 msix = &ha->msix_entries[1];
1499 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001500 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001501 icb->msix = cpu_to_le16(msix->entry);
1502 }
1503 /* Use alternate PCI bus number */
1504 if (MSB(rid))
1505 icb->firmware_options_2 |=
1506 __constant_cpu_to_le32(BIT_19);
1507 /* Use alternate PCI devfn */
1508 if (LSB(rid))
1509 icb->firmware_options_2 |=
1510 __constant_cpu_to_le32(BIT_18);
1511
Anirban Chakraborty31557542009-12-02 10:36:55 -08001512 /* Use Disable MSIX Handshake mode for capable adapters */
1513 if (IS_MSIX_NACK_CAPABLE(ha)) {
1514 icb->firmware_options_2 &=
1515 __constant_cpu_to_le32(~BIT_22);
1516 ha->flags.disable_msix_handshake = 1;
1517 qla_printk(KERN_INFO, ha,
1518 "MSIX Handshake Disable Mode turned on\n");
1519 } else {
1520 icb->firmware_options_2 |=
1521 __constant_cpu_to_le32(BIT_22);
1522 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001523 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001524
1525 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1526 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1527 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1528 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1529 } else {
1530 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1531 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1532 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1533 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1534 }
1535 /* PCI posting */
1536 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001537}
1538
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539/**
1540 * qla2x00_init_rings() - Initializes firmware.
1541 * @ha: HA context
1542 *
1543 * Beginning of request ring has initialization control block already built
1544 * by nvram config routine.
1545 *
1546 * Returns 0 on success.
1547 */
1548static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001549qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550{
1551 int rval;
1552 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001553 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001554 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001555 struct req_que *req;
1556 struct rsp_que *rsp;
1557 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001558 struct mid_init_cb_24xx *mid_init_cb =
1559 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
1561 spin_lock_irqsave(&ha->hardware_lock, flags);
1562
1563 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001564 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001565 req = ha->req_q_map[que];
1566 if (!req)
1567 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001568 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001569 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001571 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001572
1573 /* Initialize firmware. */
1574 req->ring_ptr = req->ring;
1575 req->ring_index = 0;
1576 req->cnt = req->length;
1577 }
1578
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001579 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001580 rsp = ha->rsp_q_map[que];
1581 if (!rsp)
1582 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001583 /* Initialize response queue entries */
1584 qla2x00_init_response_q_entries(rsp);
1585 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586
1587 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001588 list_for_each_entry(vp, &ha->vp_list, list) {
1589 vp->rscn_in_ptr = 0;
1590 vp->rscn_out_ptr = 0;
1591 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001592 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593
1594 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1595
1596 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001599 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001600
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001601 if (ha->flags.npiv_supported) {
1602 if (ha->operating_mode == LOOP)
1603 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001604 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001605 }
1606
Andrew Vasquez24a08132009-03-24 09:08:16 -07001607 if (IS_FWI2_CAPABLE(ha)) {
1608 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1609 mid_init_cb->init_cb.execution_throttle =
1610 cpu_to_le16(ha->fw_xcb_count);
1611 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001612
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 if (rval) {
1615 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617 } else {
1618 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001619 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 }
1621
1622 return (rval);
1623}
1624
1625/**
1626 * qla2x00_fw_ready() - Waits for firmware ready.
1627 * @ha: HA context
1628 *
1629 * Returns 0 on success.
1630 */
1631static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001632qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633{
1634 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001635 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636 uint16_t min_wait; /* Minimum wait time if loop is down */
1637 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001638 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001639 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 rval = QLA_SUCCESS;
1642
1643 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001644 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645
1646 /*
1647 * Firmware should take at most one RATOV to login, plus 5 seconds for
1648 * our own processing.
1649 */
1650 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1651 wait_time = min_wait;
1652 }
1653
1654 /* Min wait time if loop down */
1655 mtime = jiffies + (min_wait * HZ);
1656
1657 /* wait time before firmware ready */
1658 wtime = jiffies + (wait_time * HZ);
1659
1660 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001661 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1663
1664 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001665 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001668 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001670 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001671 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001673 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1674 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001675 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001676 state[2]));
1677 if ((state[2] & FSTATE_LOGGED_IN) &&
1678 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1679 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001680 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001681
1682 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001683 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001684 if (rval != QLA_SUCCESS)
1685 break;
1686
1687 /* Add time taken to initialize. */
1688 cs84xx_time = jiffies - cs84xx_time;
1689 wtime += cs84xx_time;
1690 mtime += cs84xx_time;
1691 DEBUG16(printk("scsi(%ld): Increasing "
1692 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001693 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001694 }
1695 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001697 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001699 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001700 &ha->login_timeout, &ha->r_a_tov);
1701
1702 rval = QLA_SUCCESS;
1703 break;
1704 }
1705
1706 rval = QLA_FUNCTION_FAILED;
1707
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001708 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001709 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001711 * other than Wait for Login.
1712 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001713 if (time_after_eq(jiffies, mtime)) {
1714 qla_printk(KERN_INFO, ha,
1715 "Cable is unplugged...\n");
1716
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001717 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001718 break;
1719 }
1720 }
1721 } else {
1722 /* Mailbox cmd failed. Timeout on min_wait. */
1723 if (time_after_eq(jiffies, mtime))
1724 break;
1725 }
1726
1727 if (time_after_eq(jiffies, wtime))
1728 break;
1729
1730 /* Delay for a while */
1731 msleep(500);
1732
1733 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001734 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 } while (1);
1736
Andrew Vasquez656e8912009-06-03 09:55:29 -07001737 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1738 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1739 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740
1741 if (rval) {
1742 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001743 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 }
1745
1746 return (rval);
1747}
1748
1749/*
1750* qla2x00_configure_hba
1751* Setup adapter context.
1752*
1753* Input:
1754* ha = adapter state pointer.
1755*
1756* Returns:
1757* 0 = success
1758*
1759* Context:
1760* Kernel context.
1761*/
1762static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001763qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764{
1765 int rval;
1766 uint16_t loop_id;
1767 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001768 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001769 uint8_t al_pa;
1770 uint8_t area;
1771 uint8_t domain;
1772 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
1775 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001776 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001777 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001778 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001779 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001780 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1781 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001782 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001783 } else {
1784 qla_printk(KERN_WARNING, ha,
1785 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001786 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001787 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788 return (rval);
1789 }
1790
1791 if (topo == 4) {
1792 qla_printk(KERN_INFO, ha,
1793 "Cannot get topology - retrying.\n");
1794 return (QLA_FUNCTION_FAILED);
1795 }
1796
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001797 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 /* initialize */
1800 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1801 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001802 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 switch (topo) {
1805 case 0:
1806 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001807 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 ha->current_topology = ISP_CFG_NL;
1809 strcpy(connect_type, "(Loop)");
1810 break;
1811
1812 case 1:
1813 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001814 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001815 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816 ha->current_topology = ISP_CFG_FL;
1817 strcpy(connect_type, "(FL_Port)");
1818 break;
1819
1820 case 2:
1821 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001822 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001823 ha->operating_mode = P2P;
1824 ha->current_topology = ISP_CFG_N;
1825 strcpy(connect_type, "(N_Port-to-N_Port)");
1826 break;
1827
1828 case 3:
1829 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001830 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001831 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 ha->operating_mode = P2P;
1833 ha->current_topology = ISP_CFG_F;
1834 strcpy(connect_type, "(F_Port)");
1835 break;
1836
1837 default:
1838 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1839 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001840 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001841 ha->current_topology = ISP_CFG_NL;
1842 strcpy(connect_type, "(Loop)");
1843 break;
1844 }
1845
1846 /* Save Host port and loop ID. */
1847 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001848 vha->d_id.b.domain = domain;
1849 vha->d_id.b.area = area;
1850 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001852 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 qla_printk(KERN_INFO, ha,
1854 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001855 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
1857 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001858 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001859 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001860 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 }
1862
1863 return(rval);
1864}
1865
Giridhar Malavalia9083012010-04-12 17:59:55 -07001866inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001867qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1868 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001869{
1870 char *st, *en;
1871 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001872 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezab671142009-08-25 11:36:17 -07001873 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
Giridhar Malavalia9083012010-04-12 17:59:55 -07001874 !IS_QLA8XXX_TYPE(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001875
1876 if (memcmp(model, BINZERO, len) != 0) {
1877 strncpy(ha->model_number, model, len);
1878 st = en = ha->model_number;
1879 en += len - 1;
1880 while (en > st) {
1881 if (*en != 0x20 && *en != 0x00)
1882 break;
1883 *en-- = '\0';
1884 }
1885
1886 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001887 if (use_tbl &&
1888 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001889 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001890 strncpy(ha->model_desc,
1891 qla2x00_model_name[index * 2 + 1],
1892 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001893 } else {
1894 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001895 if (use_tbl &&
1896 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001897 index < QLA_MODEL_NAMES) {
1898 strcpy(ha->model_number,
1899 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001900 strncpy(ha->model_desc,
1901 qla2x00_model_name[index * 2 + 1],
1902 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001903 } else {
1904 strcpy(ha->model_number, def);
1905 }
1906 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001907 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001908 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001909 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001910}
1911
David Miller4e08df32007-04-16 12:37:43 -07001912/* On sparc systems, obtain port and node WWN from firmware
1913 * properties.
1914 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001915static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001916{
1917#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001918 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001919 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001920 struct device_node *dp = pci_device_to_OF_node(pdev);
1921 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001922 int len;
1923
1924 val = of_get_property(dp, "port-wwn", &len);
1925 if (val && len >= WWN_SIZE)
1926 memcpy(nv->port_name, val, WWN_SIZE);
1927
1928 val = of_get_property(dp, "node-wwn", &len);
1929 if (val && len >= WWN_SIZE)
1930 memcpy(nv->node_name, val, WWN_SIZE);
1931#endif
1932}
1933
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934/*
1935* NVRAM configuration for ISP 2xxx
1936*
1937* Input:
1938* ha = adapter block pointer.
1939*
1940* Output:
1941* initialization control block in response_ring
1942* host adapters parameters in host adapter block
1943*
1944* Returns:
1945* 0 = success.
1946*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001947int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001948qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949{
David Miller4e08df32007-04-16 12:37:43 -07001950 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001951 uint8_t chksum = 0;
1952 uint16_t cnt;
1953 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001955 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001956 nvram_t *nv = ha->nvram;
1957 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001958 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
David Miller4e08df32007-04-16 12:37:43 -07001960 rval = QLA_SUCCESS;
1961
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001963 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 ha->nvram_base = 0;
1965 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1966 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1967 ha->nvram_base = 0x80;
1968
1969 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001970 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001971 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1972 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001975 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
1977 /* Bad NVRAM data, set defaults parameters. */
1978 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1979 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1980 /* Reset NVRAM data. */
1981 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1982 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1983 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001984 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1985 "invalid -- WWPN) defaults.\n");
1986
1987 /*
1988 * Set default initialization control block.
1989 */
1990 memset(nv, 0, ha->nvram_size);
1991 nv->parameter_block_version = ICB_VERSION;
1992
1993 if (IS_QLA23XX(ha)) {
1994 nv->firmware_options[0] = BIT_2 | BIT_1;
1995 nv->firmware_options[1] = BIT_7 | BIT_5;
1996 nv->add_firmware_options[0] = BIT_5;
1997 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1998 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1999 nv->special_options[1] = BIT_7;
2000 } else if (IS_QLA2200(ha)) {
2001 nv->firmware_options[0] = BIT_2 | BIT_1;
2002 nv->firmware_options[1] = BIT_7 | BIT_5;
2003 nv->add_firmware_options[0] = BIT_5;
2004 nv->add_firmware_options[1] = BIT_5 | BIT_4;
2005 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2006 } else if (IS_QLA2100(ha)) {
2007 nv->firmware_options[0] = BIT_3 | BIT_1;
2008 nv->firmware_options[1] = BIT_5;
2009 nv->frame_payload_size = __constant_cpu_to_le16(1024);
2010 }
2011
2012 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
2013 nv->execution_throttle = __constant_cpu_to_le16(16);
2014 nv->retry_count = 8;
2015 nv->retry_delay = 1;
2016
2017 nv->port_name[0] = 33;
2018 nv->port_name[3] = 224;
2019 nv->port_name[4] = 139;
2020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07002022
2023 nv->login_timeout = 4;
2024
2025 /*
2026 * Set default host adapter parameters
2027 */
2028 nv->host_p[1] = BIT_2;
2029 nv->reset_delay = 5;
2030 nv->port_down_retry_count = 8;
2031 nv->max_luns_per_target = __constant_cpu_to_le16(8);
2032 nv->link_down_timeout = 60;
2033
2034 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 }
2036
2037#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2038 /*
2039 * The SN2 does not provide BIOS emulation which means you can't change
2040 * potentially bogus BIOS settings. Force the use of default settings
2041 * for link rate and frame size. Hope that the rest of the settings
2042 * are valid.
2043 */
2044 if (ia64_platform_is("sn2")) {
2045 nv->frame_payload_size = __constant_cpu_to_le16(2048);
2046 if (IS_QLA23XX(ha))
2047 nv->special_options[1] = BIT_7;
2048 }
2049#endif
2050
2051 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002052 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053
2054 /*
2055 * Setup driver NVRAM options.
2056 */
2057 nv->firmware_options[0] |= (BIT_6 | BIT_1);
2058 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
2059 nv->firmware_options[1] |= (BIT_5 | BIT_0);
2060 nv->firmware_options[1] &= ~BIT_4;
2061
2062 if (IS_QLA23XX(ha)) {
2063 nv->firmware_options[0] |= BIT_2;
2064 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002065 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066
2067 if (IS_QLA2300(ha)) {
2068 if (ha->fb_rev == FPM_2310) {
2069 strcpy(ha->model_number, "QLA2310");
2070 } else {
2071 strcpy(ha->model_number, "QLA2300");
2072 }
2073 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002074 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08002075 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 }
2077 } else if (IS_QLA2200(ha)) {
2078 nv->firmware_options[0] |= BIT_2;
2079 /*
2080 * 'Point-to-point preferred, else loop' is not a safe
2081 * connection mode setting.
2082 */
2083 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2084 (BIT_5 | BIT_4)) {
2085 /* Force 'loop preferred, else point-to-point'. */
2086 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2087 nv->add_firmware_options[0] |= BIT_5;
2088 }
2089 strcpy(ha->model_number, "QLA22xx");
2090 } else /*if (IS_QLA2100(ha))*/ {
2091 strcpy(ha->model_number, "QLA2100");
2092 }
2093
2094 /*
2095 * Copy over NVRAM RISC parameter block to initialization control block.
2096 */
2097 dptr1 = (uint8_t *)icb;
2098 dptr2 = (uint8_t *)&nv->parameter_block_version;
2099 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2100 while (cnt--)
2101 *dptr1++ = *dptr2++;
2102
2103 /* Copy 2nd half. */
2104 dptr1 = (uint8_t *)icb->add_firmware_options;
2105 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2106 while (cnt--)
2107 *dptr1++ = *dptr2++;
2108
Andrew Vasquez5341e862006-05-17 15:09:16 -07002109 /* Use alternate WWN? */
2110 if (nv->host_p[1] & BIT_7) {
2111 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2112 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2113 }
2114
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 /* Prepare nodename */
2116 if ((icb->firmware_options[1] & BIT_6) == 0) {
2117 /*
2118 * Firmware will apply the following mask if the nodename was
2119 * not provided.
2120 */
2121 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2122 icb->node_name[0] &= 0xF0;
2123 }
2124
2125 /*
2126 * Set host adapter parameters.
2127 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002128 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002129 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2131 /* Always load RISC code on non ISP2[12]00 chips. */
2132 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2133 ha->flags.disable_risc_code_load = 0;
2134 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2135 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2136 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002137 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002138 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 ha->operating_mode =
2141 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2142
2143 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2144 sizeof(ha->fw_seriallink_options));
2145
2146 /* save HBA serial number */
2147 ha->serial0 = icb->port_name[5];
2148 ha->serial1 = icb->port_name[6];
2149 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002150 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2151 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2154
2155 ha->retry_count = nv->retry_count;
2156
2157 /* Set minimum login_timeout to 4 seconds. */
2158 if (nv->login_timeout < ql2xlogintimeout)
2159 nv->login_timeout = ql2xlogintimeout;
2160 if (nv->login_timeout < 4)
2161 nv->login_timeout = 4;
2162 ha->login_timeout = nv->login_timeout;
2163 icb->login_timeout = nv->login_timeout;
2164
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002165 /* Set minimum RATOV to 100 tenths of a second. */
2166 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 ha->loop_reset_delay = nv->reset_delay;
2169
Linus Torvalds1da177e2005-04-16 15:20:36 -07002170 /* Link Down Timeout = 0:
2171 *
2172 * When Port Down timer expires we will start returning
2173 * I/O's to OS with "DID_NO_CONNECT".
2174 *
2175 * Link Down Timeout != 0:
2176 *
2177 * The driver waits for the link to come up after link down
2178 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002179 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 if (nv->link_down_timeout == 0) {
2181 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002182 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 } else {
2184 ha->link_down_timeout = nv->link_down_timeout;
2185 ha->loop_down_abort_time =
2186 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002187 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
Linus Torvalds1da177e2005-04-16 15:20:36 -07002189 /*
2190 * Need enough time to try and get the port back.
2191 */
2192 ha->port_down_retry_count = nv->port_down_retry_count;
2193 if (qlport_down_retry)
2194 ha->port_down_retry_count = qlport_down_retry;
2195 /* Set login_retry_count */
2196 ha->login_retry_count = nv->retry_count;
2197 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2198 ha->port_down_retry_count > 3)
2199 ha->login_retry_count = ha->port_down_retry_count;
2200 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2201 ha->login_retry_count = ha->port_down_retry_count;
2202 if (ql2xloginretrycount)
2203 ha->login_retry_count = ql2xloginretrycount;
2204
Linus Torvalds1da177e2005-04-16 15:20:36 -07002205 icb->lun_enables = __constant_cpu_to_le16(0);
2206 icb->command_resource_count = 0;
2207 icb->immediate_notify_resource_count = 0;
2208 icb->timeout = __constant_cpu_to_le16(0);
2209
2210 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2211 /* Enable RIO */
2212 icb->firmware_options[0] &= ~BIT_3;
2213 icb->add_firmware_options[0] &=
2214 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2215 icb->add_firmware_options[0] |= BIT_2;
2216 icb->response_accumulation_timer = 3;
2217 icb->interrupt_delay_timer = 5;
2218
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002219 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002221 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002222 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002223 ha->zio_mode = icb->add_firmware_options[0] &
2224 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2225 ha->zio_timer = icb->interrupt_delay_timer ?
2226 icb->interrupt_delay_timer: 2;
2227 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228 icb->add_firmware_options[0] &=
2229 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002230 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002231 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002232 ha->zio_mode = QLA_ZIO_MODE_6;
2233
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002234 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002236 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002238 "ZIO mode %d enabled; timer delay (%d us).\n",
2239 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002241 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2242 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 }
2245 }
2246
David Miller4e08df32007-04-16 12:37:43 -07002247 if (rval) {
2248 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002249 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002250 }
2251 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252}
2253
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002254static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002255qla2x00_rport_del(void *data)
2256{
2257 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002258 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002259
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002261 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002262 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002264 if (rport)
2265 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002266}
2267
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268/**
2269 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2270 * @ha: HA context
2271 * @flags: allocation flags
2272 *
2273 * Returns a pointer to the allocated fcport, or NULL, if none available.
2274 */
Giridhar Malavali9a069e12010-01-12 13:02:47 -08002275fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277{
2278 fc_port_t *fcport;
2279
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002280 fcport = kzalloc(sizeof(fc_port_t), flags);
2281 if (!fcport)
2282 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002283
2284 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285 fcport->vha = vha;
2286 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 fcport->port_type = FCT_UNKNOWN;
2288 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002290 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002291
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002292 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293}
2294
2295/*
2296 * qla2x00_configure_loop
2297 * Updates Fibre Channel Device Database with what is actually on loop.
2298 *
2299 * Input:
2300 * ha = adapter block pointer.
2301 *
2302 * Returns:
2303 * 0 = success.
2304 * 1 = error.
2305 * 2 = database was full and device was not configured.
2306 */
2307static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002308qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002309{
2310 int rval;
2311 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 rval = QLA_SUCCESS;
2314
2315 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002316 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2317 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 if (rval != QLA_SUCCESS) {
2319 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002320 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002321 return (rval);
2322 }
2323 }
2324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002326 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002328
2329 /*
2330 * If we have both an RSCN and PORT UPDATE pending then handle them
2331 * both at the same time.
2332 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002333 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2334 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335
Michael Hernandez3064ff32009-12-15 21:29:44 -08002336 qla2x00_get_data_rate(vha);
2337
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338 /* Determine what we need to do */
2339 if (ha->current_topology == ISP_CFG_FL &&
2340 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2341
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 set_bit(RSCN_UPDATE, &flags);
2344
2345 } else if (ha->current_topology == ISP_CFG_F &&
2346 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2347
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002348 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 set_bit(RSCN_UPDATE, &flags);
2350 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2351
Andrew Vasquez21333b42006-05-17 15:09:56 -07002352 } else if (ha->current_topology == ISP_CFG_N) {
2353 clear_bit(RSCN_UPDATE, &flags);
2354
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2357
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002358 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002359 set_bit(RSCN_UPDATE, &flags);
2360 set_bit(LOCAL_LOOP_UPDATE, &flags);
2361 }
2362
2363 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002364 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002365 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 else
2367 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002368 }
2369
2370 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 else
2374 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 }
2376
2377 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 if (atomic_read(&vha->loop_down_timer) ||
2379 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002380 rval = QLA_FUNCTION_FAILED;
2381 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002382 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002385 }
2386 }
2387
2388 if (rval) {
2389 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 } else {
2392 DEBUG3(printk("%s: exiting normally\n", __func__));
2393 }
2394
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002395 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002396 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002399 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002401 vha->flags.rscn_queue_overflow = 1;
2402 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 }
2404
2405 return (rval);
2406}
2407
2408
2409
2410/*
2411 * qla2x00_configure_local_loop
2412 * Updates Fibre Channel Device Database with local loop devices.
2413 *
2414 * Input:
2415 * ha = adapter block pointer.
2416 *
2417 * Returns:
2418 * 0 = success.
2419 */
2420static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422{
2423 int rval, rval2;
2424 int found_devs;
2425 int found;
2426 fc_port_t *fcport, *new_fcport;
2427
2428 uint16_t index;
2429 uint16_t entries;
2430 char *id_iter;
2431 uint16_t loop_id;
2432 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
2435 found_devs = 0;
2436 new_fcport = NULL;
2437 entries = MAX_FIBRE_DEVICES;
2438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002439 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2440 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441
2442 /* Get list of logged in devices. */
2443 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445 &entries);
2446 if (rval != QLA_SUCCESS)
2447 goto cleanup_allocation;
2448
2449 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002450 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2452 entries * sizeof(struct gid_list_info)));
2453
2454 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002455 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 if (new_fcport == NULL) {
2457 rval = QLA_MEMORY_ALLOC_FAILED;
2458 goto cleanup_allocation;
2459 }
2460 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2461
2462 /*
2463 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2464 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2467 fcport->port_type != FCT_BROADCAST &&
2468 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2469
2470 DEBUG(printk("scsi(%ld): Marking port lost, "
2471 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473
2474 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 }
2476 }
2477
2478 /* Add devices to port list. */
2479 id_iter = (char *)ha->gid_list;
2480 for (index = 0; index < entries; index++) {
2481 domain = ((struct gid_list_info *)id_iter)->domain;
2482 area = ((struct gid_list_info *)id_iter)->area;
2483 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002484 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 loop_id = (uint16_t)
2486 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002487 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 loop_id = le16_to_cpu(
2489 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002490 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
2492 /* Bypass reserved domain fields. */
2493 if ((domain & 0xf0) == 0xf0)
2494 continue;
2495
2496 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002497 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002498 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002499 continue;
2500
2501 /* Bypass invalid local loop ID. */
2502 if (loop_id > LAST_LOCAL_LOOP_ID)
2503 continue;
2504
2505 /* Fill in member data. */
2506 new_fcport->d_id.b.domain = domain;
2507 new_fcport->d_id.b.area = area;
2508 new_fcport->d_id.b.al_pa = al_pa;
2509 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 new_fcport->vp_idx = vha->vp_idx;
2511 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 if (rval2 != QLA_SUCCESS) {
2513 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2514 "information -- get_port_database=%x, "
2515 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002517 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002518 vha->host_no));
2519 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 continue;
2521 }
2522
2523 /* Check for matching device in port list. */
2524 found = 0;
2525 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 if (memcmp(new_fcport->port_name, fcport->port_name,
2528 WWN_SIZE))
2529 continue;
2530
Shyam Sundarddb9b122009-03-24 09:08:10 -07002531 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002532 fcport->loop_id = new_fcport->loop_id;
2533 fcport->port_type = new_fcport->port_type;
2534 fcport->d_id.b24 = new_fcport->d_id.b24;
2535 memcpy(fcport->node_name, new_fcport->node_name,
2536 WWN_SIZE);
2537
2538 found++;
2539 break;
2540 }
2541
2542 if (!found) {
2543 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002544 if (vha->vp_idx) {
2545 new_fcport->vha = vha;
2546 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002547 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549
2550 /* Allocate a new replacement fcport. */
2551 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 if (new_fcport == NULL) {
2554 rval = QLA_MEMORY_ALLOC_FAILED;
2555 goto cleanup_allocation;
2556 }
2557 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2558 }
2559
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002560 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002561 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002564
2565 found_devs++;
2566 }
2567
2568cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002569 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570
2571 if (rval != QLA_SUCCESS) {
2572 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002573 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 }
2575
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576 return (rval);
2577}
2578
2579static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002581{
2582#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002583 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2584 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002585 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002586 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002588
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002589 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002590 return;
2591
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002592 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2593 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002594 return;
2595
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002597 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002598 if (rval != QLA_SUCCESS) {
2599 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2600 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002602 fcport->port_name[2], fcport->port_name[3],
2603 fcport->port_name[4], fcport->port_name[5],
2604 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002605 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002606 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002607 link_speed = link_speeds[LS_UNKNOWN];
2608 if (fcport->fp_speed < 5)
2609 link_speed = link_speeds[fcport->fp_speed];
2610 else if (fcport->fp_speed == 0x13)
2611 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002612 DEBUG2(qla_printk(KERN_INFO, ha,
2613 "iIDMA adjusted to %s GB/s on "
2614 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002615 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002616 fcport->port_name[1], fcport->port_name[2],
2617 fcport->port_name[3], fcport->port_name[4],
2618 fcport->port_name[5], fcport->port_name[6],
2619 fcport->port_name[7]));
2620 }
2621}
2622
Adrian Bunk23be3312006-11-24 02:46:01 +01002623static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002625{
2626 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002627 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002628 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002629
Andrew Vasquezac280b62009-08-20 11:06:05 -07002630 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002631
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002632 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2633 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002634 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2635 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2636 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002638 if (!rport) {
2639 qla_printk(KERN_WARNING, ha,
2640 "Unable to allocate fc remote port!\n");
2641 return;
2642 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002643 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002644 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002646
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002647 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002648
2649 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002650 if (fcport->port_type == FCT_INITIATOR)
2651 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2652 if (fcport->port_type == FCT_TARGET)
2653 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002654 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002655}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002656
2657/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002658 * qla2x00_update_fcport
2659 * Updates device on list.
2660 *
2661 * Input:
2662 * ha = adapter block pointer.
2663 * fcport = port structure pointer.
2664 *
2665 * Return:
2666 * 0 - Success
2667 * BIT_0 - error
2668 *
2669 * Context:
2670 * Kernel context.
2671 */
2672void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002673qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002674{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002675 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002676
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002677 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002678 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002680 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002681 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002682 PORT_RETRY_TIME);
2683 fcport->flags &= ~FCF_LOGIN_NEEDED;
2684
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002686
2687 atomic_set(&fcport->state, FCS_ONLINE);
2688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002690}
2691
2692/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 * qla2x00_configure_fabric
2694 * Setup SNS devices with loop ID's.
2695 *
2696 * Input:
2697 * ha = adapter block pointer.
2698 *
2699 * Returns:
2700 * 0 = success.
2701 * BIT_0 = error
2702 */
2703static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002704qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705{
2706 int rval, rval2;
2707 fc_port_t *fcport, *fcptemp;
2708 uint16_t next_loopid;
2709 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002710 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002712 struct qla_hw_data *ha = vha->hw;
2713 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714
2715 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002716 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002717 loop_id = NPH_F_PORT;
2718 else
2719 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 if (rval != QLA_SUCCESS) {
2722 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002726 return (QLA_SUCCESS);
2727 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002728 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
2730 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002731 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732 if (rval2 == QLA_RSCNS_HANDLED) {
2733 /* No point doing the scan, just continue. */
2734 return (QLA_SUCCESS);
2735 }
2736 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002737 /* FDMI support. */
2738 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2740 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002741
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002743 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002744 loop_id = NPH_SNS;
2745 else
2746 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002747 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002748 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749 if (mb[0] != MBS_COMMAND_COMPLETE) {
2750 DEBUG2(qla_printk(KERN_INFO, ha,
2751 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002752 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 mb[0], mb[1], mb[2], mb[6], mb[7]));
2754 return (QLA_SUCCESS);
2755 }
2756
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2758 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 /* EMPTY */
2760 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 /* EMPTY */
2765 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002768 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002769 /* EMPTY */
2770 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 "failed.\n", vha->host_no));
2772 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 /* EMPTY */
2774 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002775 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 }
2777 }
2778
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002780 if (rval != QLA_SUCCESS)
2781 break;
2782
2783 /*
2784 * Logout all previous fabric devices marked lost, except
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002785 * FCP2 devices.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2788 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 break;
2790
2791 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2792 continue;
2793
2794 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002796 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08002798 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 fcport->port_type != FCT_INITIATOR &&
2800 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002801 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002802 fcport->loop_id,
2803 fcport->d_id.b.domain,
2804 fcport->d_id.b.area,
2805 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806 fcport->loop_id = FC_NO_LOOP_ID;
2807 }
2808 }
2809 }
2810
2811 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 /*
2815 * Scan through our port list and login entries that need to be
2816 * logged in.
2817 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002818 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2819 if (atomic_read(&vha->loop_down_timer) ||
2820 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 break;
2822
2823 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2824 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2825 continue;
2826
2827 if (fcport->loop_id == FC_NO_LOOP_ID) {
2828 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002829 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 if (rval != QLA_SUCCESS) {
2832 /* Ran out of IDs to use */
2833 break;
2834 }
2835 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002837 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838 }
2839
2840 /* Exit if out of loop IDs. */
2841 if (rval != QLA_SUCCESS) {
2842 break;
2843 }
2844
2845 /*
2846 * Login and add the new devices to our port list.
2847 */
2848 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002849 if (atomic_read(&vha->loop_down_timer) ||
2850 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 break;
2852
2853 /* Find a new loop ID to use. */
2854 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002855 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002856 if (rval != QLA_SUCCESS) {
2857 /* Ran out of IDs to use */
2858 break;
2859 }
2860
bdf79622005-04-17 15:06:53 -05002861 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002862 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002863
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 if (vha->vp_idx) {
2865 fcport->vha = vha;
2866 fcport->vp_idx = vha->vp_idx;
2867 }
2868 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 }
2870 } while (0);
2871
2872 /* Free all new device structures not processed. */
2873 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2874 list_del(&fcport->list);
2875 kfree(fcport);
2876 }
2877
2878 if (rval) {
2879 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 }
2882
2883 return (rval);
2884}
2885
2886
2887/*
2888 * qla2x00_find_all_fabric_devs
2889 *
2890 * Input:
2891 * ha = adapter block pointer.
2892 * dev = database device entry pointer.
2893 *
2894 * Returns:
2895 * 0 = success.
2896 *
2897 * Context:
2898 * Kernel context.
2899 */
2900static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2902 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903{
2904 int rval;
2905 uint16_t loop_id;
2906 fc_port_t *fcport, *new_fcport, *fcptemp;
2907 int found;
2908
2909 sw_info_t *swl;
2910 int swl_idx;
2911 int first_dev, last_dev;
2912 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 struct qla_hw_data *ha = vha->hw;
2914 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002915 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
2917 rval = QLA_SUCCESS;
2918
2919 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002920 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002921 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922 /*EMPTY*/
2923 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 kfree(swl);
2928 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 kfree(swl);
2931 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 kfree(swl);
2934 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002935 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002936 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2937 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938 }
2939 }
2940 swl_idx = 0;
2941
2942 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002945 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002946 return (QLA_MEMORY_ALLOC_FAILED);
2947 }
2948 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 /* Set start port ID scan at adapter ID. */
2950 first_dev = 1;
2951 last_dev = 0;
2952
2953 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002954 loop_id = ha->min_external_loopid;
2955 for (; loop_id <= ha->max_loop_id; loop_id++) {
2956 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 continue;
2958
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08002959 if (atomic_read(&vha->loop_down_timer) ||
2960 LOOP_TRANSITION(vha)) {
2961 atomic_set(&vha->loop_down_timer, 0);
2962 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2963 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002964 break;
Andrew Vasquezbb2d52b2010-02-18 10:07:27 -08002965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966
2967 if (swl != NULL) {
2968 if (last_dev) {
2969 wrap.b24 = new_fcport->d_id.b24;
2970 } else {
2971 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2972 memcpy(new_fcport->node_name,
2973 swl[swl_idx].node_name, WWN_SIZE);
2974 memcpy(new_fcport->port_name,
2975 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002976 memcpy(new_fcport->fabric_port_name,
2977 swl[swl_idx].fabric_port_name, WWN_SIZE);
2978 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979
2980 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2981 last_dev = 1;
2982 }
2983 swl_idx++;
2984 }
2985 } else {
2986 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 if (rval != QLA_SUCCESS) {
2989 qla_printk(KERN_WARNING, ha,
2990 "SNS scan failed -- assuming zero-entry "
2991 "result...\n");
2992 list_for_each_entry_safe(fcport, fcptemp,
2993 new_fcports, list) {
2994 list_del(&fcport->list);
2995 kfree(fcport);
2996 }
2997 rval = QLA_SUCCESS;
2998 break;
2999 }
3000 }
3001
3002 /* If wrap on switch device list, exit. */
3003 if (first_dev) {
3004 wrap.b24 = new_fcport->d_id.b24;
3005 first_dev = 0;
3006 } else if (new_fcport->d_id.b24 == wrap.b24) {
3007 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
3010 break;
3011 }
3012
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003013 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 continue;
3016
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003017 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 found = 0;
3019 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003020 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003021 if (new_fcport->d_id.b24 == vp->d_id.b24) {
3022 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003023 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003025 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003027 continue;
3028 }
3029
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003030 /* Bypass if same domain and area of adapter. */
3031 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07003033 ISP_CFG_FL)
3034 continue;
3035
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 /* Bypass reserved domain fields. */
3037 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
3038 continue;
3039
3040 /* Locate matching device in database. */
3041 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003042 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043 if (memcmp(new_fcport->port_name, fcport->port_name,
3044 WWN_SIZE))
3045 continue;
3046
3047 found++;
3048
Andrew Vasquezd8b45212006-10-02 12:00:43 -07003049 /* Update port state. */
3050 memcpy(fcport->fabric_port_name,
3051 new_fcport->fabric_port_name, WWN_SIZE);
3052 fcport->fp_speed = new_fcport->fp_speed;
3053
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 /*
3055 * If address the same and state FCS_ONLINE, nothing
3056 * changed.
3057 */
3058 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
3059 atomic_read(&fcport->state) == FCS_ONLINE) {
3060 break;
3061 }
3062
3063 /*
3064 * If device was not a fabric device before.
3065 */
3066 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
3067 fcport->d_id.b24 = new_fcport->d_id.b24;
3068 fcport->loop_id = FC_NO_LOOP_ID;
3069 fcport->flags |= (FCF_FABRIC_DEVICE |
3070 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071 break;
3072 }
3073
3074 /*
3075 * Port ID changed or device was marked to be updated;
3076 * Log it out if still logged in and mark it for
3077 * relogin later.
3078 */
3079 fcport->d_id.b24 = new_fcport->d_id.b24;
3080 fcport->flags |= FCF_LOGIN_NEEDED;
3081 if (fcport->loop_id != FC_NO_LOOP_ID &&
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003082 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 fcport->port_type != FCT_INITIATOR &&
3084 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003085 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003086 fcport->d_id.b.domain, fcport->d_id.b.area,
3087 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 fcport->loop_id = FC_NO_LOOP_ID;
3089 }
3090
3091 break;
3092 }
3093
3094 if (found)
3095 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 /* If device was not in our fcports list, then add it. */
3097 list_add_tail(&new_fcport->list, new_fcports);
3098
3099 /* Allocate a new replacement fcport. */
3100 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003101 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003102 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003103 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 return (QLA_MEMORY_ALLOC_FAILED);
3105 }
3106 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3107 new_fcport->d_id.b24 = nxt_d_id.b24;
3108 }
3109
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003110 kfree(swl);
3111 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112
Linus Torvalds1da177e2005-04-16 15:20:36 -07003113 return (rval);
3114}
3115
3116/*
3117 * qla2x00_find_new_loop_id
3118 * Scan through our port list and find a new usable loop ID.
3119 *
3120 * Input:
3121 * ha: adapter state pointer.
3122 * dev: port structure pointer.
3123 *
3124 * Returns:
3125 * qla2x00 local function return status code.
3126 *
3127 * Context:
3128 * Kernel context.
3129 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003130static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003131qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003132{
3133 int rval;
3134 int found;
3135 fc_port_t *fcport;
3136 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003137 struct qla_hw_data *ha = vha->hw;
3138 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003139 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140
3141 rval = QLA_SUCCESS;
3142
3143 /* Save starting loop ID. */
3144 first_loop_id = dev->loop_id;
3145
3146 for (;;) {
3147 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
3151 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154
3155 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003156 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 /* first loop ID. */
3158 dev->loop_id = ha->min_external_loopid;
3159 }
3160
3161 /* Check for loop ID being already in use. */
3162 found = 0;
3163 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003164 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003165 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3166 if (fcport->loop_id == dev->loop_id &&
3167 fcport != dev) {
3168 /* ID possibly in use */
3169 found++;
3170 break;
3171 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 if (found)
3174 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175 }
3176
3177 /* If not in use then it is free to use. */
3178 if (!found) {
3179 break;
3180 }
3181
3182 /* ID in use. Try next value. */
3183 dev->loop_id++;
3184
3185 /* If wrap around. No free ID to use. */
3186 if (dev->loop_id == first_loop_id) {
3187 dev->loop_id = FC_NO_LOOP_ID;
3188 rval = QLA_FUNCTION_FAILED;
3189 break;
3190 }
3191 }
3192
3193 return (rval);
3194}
3195
3196/*
3197 * qla2x00_device_resync
3198 * Marks devices in the database that needs resynchronization.
3199 *
3200 * Input:
3201 * ha = adapter block pointer.
3202 *
3203 * Context:
3204 * Kernel context.
3205 */
3206static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208{
3209 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 uint32_t mask;
3211 fc_port_t *fcport;
3212 uint32_t rscn_entry;
3213 uint8_t rscn_out_iter;
3214 uint8_t format;
3215 port_id_t d_id;
3216
3217 rval = QLA_RSCNS_HANDLED;
3218
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003219 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3220 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003221
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223 format = MSB(MSW(rscn_entry));
3224 d_id.b.domain = LSB(MSW(rscn_entry));
3225 d_id.b.area = MSB(LSW(rscn_entry));
3226 d_id.b.al_pa = LSB(LSW(rscn_entry));
3227
3228 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3229 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 d_id.b.area, d_id.b.al_pa));
3232
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233 vha->rscn_out_ptr++;
3234 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3235 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236
3237 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 for (rscn_out_iter = vha->rscn_out_ptr;
3239 !vha->flags.rscn_queue_overflow &&
3240 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 rscn_out_iter = (rscn_out_iter ==
3242 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3243
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003244 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 break;
3246
3247 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003248 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 rscn_out_iter));
3250
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 }
3253
3254 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258
3259 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 }
3262
3263 switch (format) {
3264 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 mask = 0xffffff;
3266 break;
3267 case 1:
3268 mask = 0xffff00;
3269 break;
3270 case 2:
3271 mask = 0xff0000;
3272 break;
3273 default:
3274 mask = 0x0;
3275 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277 break;
3278 }
3279
3280 rval = QLA_SUCCESS;
3281
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003282 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3284 (fcport->d_id.b24 & mask) != d_id.b24 ||
3285 fcport->port_type == FCT_BROADCAST)
3286 continue;
3287
3288 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3289 if (format != 3 ||
3290 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003292 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 }
3294 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 }
3296 }
3297 return (rval);
3298}
3299
3300/*
3301 * qla2x00_fabric_dev_login
3302 * Login fabric target device and update FC port database.
3303 *
3304 * Input:
3305 * ha: adapter state pointer.
3306 * fcport: port structure list pointer.
3307 * next_loopid: contains value of a new loop ID that can be used
3308 * by the next login attempt.
3309 *
3310 * Returns:
3311 * qla2x00 local function return status code.
3312 *
3313 * Context:
3314 * Kernel context.
3315 */
3316static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003317qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 uint16_t *next_loopid)
3319{
3320 int rval;
3321 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003322 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
3325 rval = QLA_SUCCESS;
3326 retry = 0;
3327
Andrew Vasquezac280b62009-08-20 11:06:05 -07003328 if (IS_ALOGIO_CAPABLE(ha)) {
3329 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3330 if (!rval)
3331 return rval;
3332 }
3333
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003334 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 if (rval == QLA_SUCCESS) {
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003336 /* Send an ADISC to FCP2 devices.*/
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003337 opts = 0;
Andrew Vasquezf08b7252010-01-12 12:59:48 -08003338 if (fcport->flags & FCF_FCP2_DEVICE)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003339 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003343 fcport->d_id.b.domain, fcport->d_id.b.area,
3344 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003345 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 }
3349 }
3350
3351 return (rval);
3352}
3353
3354/*
3355 * qla2x00_fabric_login
3356 * Issue fabric login command.
3357 *
3358 * Input:
3359 * ha = adapter block pointer.
3360 * device = pointer to FC device type structure.
3361 *
3362 * Returns:
3363 * 0 - Login successfully
3364 * 1 - Login failed
3365 * 2 - Initiator device
3366 * 3 - Fatal error
3367 */
3368int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 uint16_t *next_loopid)
3371{
3372 int rval;
3373 int retry;
3374 uint16_t tmp_loopid;
3375 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003376 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
3378 retry = 0;
3379 tmp_loopid = 0;
3380
3381 for (;;) {
3382 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3383 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3386
3387 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 fcport->d_id.b.domain, fcport->d_id.b.area,
3390 fcport->d_id.b.al_pa, mb, BIT_0);
3391 if (mb[0] == MBS_PORT_ID_USED) {
3392 /*
3393 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003394 * recommends the driver perform an implicit login with
3395 * the specified ID again. The ID we just used is save
3396 * here so we return with an ID that can be tried by
3397 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 */
3399 retry++;
3400 tmp_loopid = fcport->loop_id;
3401 fcport->loop_id = mb[1];
3402
3403 DEBUG(printk("Fabric Login: port in use - next "
3404 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3405 fcport->loop_id, fcport->d_id.b.domain,
3406 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3407
3408 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3409 /*
3410 * Login succeeded.
3411 */
3412 if (retry) {
3413 /* A retry occurred before. */
3414 *next_loopid = tmp_loopid;
3415 } else {
3416 /*
3417 * No retry occurred before. Just increment the
3418 * ID value for next login.
3419 */
3420 *next_loopid = (fcport->loop_id + 1);
3421 }
3422
3423 if (mb[1] & BIT_0) {
3424 fcport->port_type = FCT_INITIATOR;
3425 } else {
3426 fcport->port_type = FCT_TARGET;
3427 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003428 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 }
3430 }
3431
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003432 if (mb[10] & BIT_0)
3433 fcport->supported_classes |= FC_COS_CLASS2;
3434 if (mb[10] & BIT_1)
3435 fcport->supported_classes |= FC_COS_CLASS3;
3436
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437 rval = QLA_SUCCESS;
3438 break;
3439 } else if (mb[0] == MBS_LOOP_ID_USED) {
3440 /*
3441 * Loop ID already used, try next loop ID.
3442 */
3443 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003444 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 if (rval != QLA_SUCCESS) {
3446 /* Ran out of loop IDs to use */
3447 break;
3448 }
3449 } else if (mb[0] == MBS_COMMAND_ERROR) {
3450 /*
3451 * Firmware possibly timed out during login. If NO
3452 * retries are left to do then the device is declared
3453 * dead.
3454 */
3455 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003456 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003457 fcport->d_id.b.domain, fcport->d_id.b.area,
3458 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
3461 rval = 1;
3462 break;
3463 } else {
3464 /*
3465 * unrecoverable / not handled error
3466 */
3467 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003468 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 fcport->d_id.b.domain, fcport->d_id.b.area,
3471 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3472
3473 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003474 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003475 fcport->d_id.b.domain, fcport->d_id.b.area,
3476 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003478 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
3480 rval = 3;
3481 break;
3482 }
3483 }
3484
3485 return (rval);
3486}
3487
3488/*
3489 * qla2x00_local_device_login
3490 * Issue local device login command.
3491 *
3492 * Input:
3493 * ha = adapter block pointer.
3494 * loop_id = loop id of device to login to.
3495 *
3496 * Returns (Where's the #define!!!!):
3497 * 0 - Login successfully
3498 * 1 - Login failed
3499 * 3 - Fatal error
3500 */
3501int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003502qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003503{
3504 int rval;
3505 uint16_t mb[MAILBOX_REGISTER_COUNT];
3506
3507 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003508 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003509 if (rval == QLA_SUCCESS) {
3510 /* Interrogate mailbox registers for any errors */
3511 if (mb[0] == MBS_COMMAND_ERROR)
3512 rval = 1;
3513 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3514 /* device not in PCB table */
3515 rval = 3;
3516 }
3517
3518 return (rval);
3519}
3520
3521/*
3522 * qla2x00_loop_resync
3523 * Resync with fibre channel devices.
3524 *
3525 * Input:
3526 * ha = adapter block pointer.
3527 *
3528 * Returns:
3529 * 0 = success
3530 */
3531int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003534 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003536 struct req_que *req;
3537 struct rsp_que *rsp;
3538
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003539 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003540 req = vha->hw->req_q_map[0];
3541 else
3542 req = vha->req;
3543 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 atomic_set(&vha->loop_state, LOOP_UPDATE);
3546 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3547 if (vha->flags.online) {
3548 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3550 wait_time = 256;
3551 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003554 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003555 qla2x00_marker(vha, req, rsp, 0, 0,
3556 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003558
3559 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003563 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003564 } while (!atomic_read(&vha->loop_down_timer) &&
3565 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3566 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3567 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003568 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569 }
3570
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003571 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003575 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576
3577 return (rval);
3578}
3579
Linus Torvalds1da177e2005-04-16 15:20:36 -07003580void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003581qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003582{
3583 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003584 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003585
3586 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003587 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3588 list_for_each_entry(fcport, &vha->vp_fcports, list)
3589 if (fcport && fcport->drport &&
3590 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3591 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003592}
3593
Giridhar Malavalia9083012010-04-12 17:59:55 -07003594void
3595qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
3596{
3597 struct qla_hw_data *ha = vha->hw;
3598 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
3599 struct scsi_qla_host *tvp;
3600
3601 vha->flags.online = 0;
3602 ha->flags.chip_reset_done = 0;
3603 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3604 ha->qla_stats.total_isp_aborts++;
3605
3606 qla_printk(KERN_INFO, ha,
3607 "Performing ISP error recovery - ha= %p.\n", ha);
3608
3609 /* Chip reset does not apply to 82XX */
3610 if (!IS_QLA82XX(ha))
3611 ha->isp_ops->reset_chip(vha);
3612
3613 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3614 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3615 atomic_set(&vha->loop_state, LOOP_DOWN);
3616 qla2x00_mark_all_devices_lost(vha, 0);
3617 list_for_each_entry_safe(vp, tvp, &base_vha->hw->vp_list, list)
3618 qla2x00_mark_all_devices_lost(vp, 0);
3619 } else {
3620 if (!atomic_read(&vha->loop_down_timer))
3621 atomic_set(&vha->loop_down_timer,
3622 LOOP_DOWN_TIME);
3623 }
3624
3625 /* Make sure for ISP 82XX IO DMA is complete */
3626 if (IS_QLA82XX(ha))
3627 qla82xx_wait_for_pending_commands(vha);
3628
3629 /* Requeue all commands in outstanding command list. */
3630 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
3631}
3632
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633/*
3634* qla2x00_abort_isp
3635* Resets ISP and aborts all outstanding commands.
3636*
3637* Input:
3638* ha = adapter block pointer.
3639*
3640* Returns:
3641* 0 = success
3642*/
3643int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003644qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003645{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003646 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003647 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 struct qla_hw_data *ha = vha->hw;
3649 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003650 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003651 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003652
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003653 if (vha->flags.online) {
Giridhar Malavalia9083012010-04-12 17:59:55 -07003654 qla2x00_abort_isp_cleanup(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003655
Andrew Vasquez85880802009-12-15 21:29:46 -08003656 if (unlikely(pci_channel_offline(ha->pdev) &&
3657 ha->flags.pci_channel_io_perm_failure)) {
3658 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3659 status = 0;
3660 return status;
3661 }
3662
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003663 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003664
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003665 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003667 if (!qla2x00_restart_isp(vha)) {
3668 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003670 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 /*
3672 * Issue marker command only when we are going
3673 * to start the I/O .
3674 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003675 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 }
3677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003678 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003680 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003681
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003682 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003683 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003684
Lalit Chandivade29c53972009-10-13 15:16:47 -07003685 if (IS_QLA81XX(ha))
3686 qla2x00_get_fw_version(vha,
3687 &ha->fw_major_version,
3688 &ha->fw_minor_version,
3689 &ha->fw_subminor_version,
3690 &ha->fw_attributes, &ha->fw_memory_size,
3691 ha->mpi_version, &ha->mpi_capabilities,
3692 ha->phy_version);
3693
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003694 if (ha->fce) {
3695 ha->flags.fce_enabled = 1;
3696 memset(ha->fce, 0,
3697 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003698 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003699 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3700 &ha->fce_bufs);
3701 if (rval) {
3702 qla_printk(KERN_WARNING, ha,
3703 "Unable to reinitialize FCE "
3704 "(%d).\n", rval);
3705 ha->flags.fce_enabled = 0;
3706 }
3707 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003708
3709 if (ha->eft) {
3710 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003711 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003712 ha->eft_dma, EFT_NUM_BUFFERS);
3713 if (rval) {
3714 qla_printk(KERN_WARNING, ha,
3715 "Unable to reinitialize EFT "
3716 "(%d).\n", rval);
3717 }
3718 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003719 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003720 vha->flags.online = 1;
3721 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 if (ha->isp_abort_cnt == 0) {
3723 qla_printk(KERN_WARNING, ha,
3724 "ISP error recovery failed - "
3725 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003726 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003727 * The next call disables the board
3728 * completely.
3729 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003730 ha->isp_ops->reset_adapter(vha);
3731 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003732 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003733 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 status = 0;
3735 } else { /* schedule another ISP abort */
3736 ha->isp_abort_cnt--;
3737 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003738 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003739 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003740 status = 1;
3741 }
3742 } else {
3743 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3744 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3745 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003746 vha->host_no, ha->isp_abort_cnt));
3747 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003748 status = 1;
3749 }
3750 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003751
Linus Torvalds1da177e2005-04-16 15:20:36 -07003752 }
3753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003754 if (!status) {
3755 DEBUG(printk(KERN_INFO
3756 "qla2x00_abort_isp(%ld): succeeded.\n",
3757 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003758 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003759 if (vp->vp_idx)
3760 qla2x00_vp_abort_isp(vp);
3761 }
3762 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003763 qla_printk(KERN_INFO, ha,
3764 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003765 }
3766
3767 return(status);
3768}
3769
3770/*
3771* qla2x00_restart_isp
3772* restarts the ISP after a reset
3773*
3774* Input:
3775* ha = adapter block pointer.
3776*
3777* Returns:
3778* 0 = success
3779*/
3780static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003781qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003783 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003784 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003785 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003786 struct req_que *req = ha->req_q_map[0];
3787 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003788
3789 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003790 if (qla2x00_isp_firmware(vha)) {
3791 vha->flags.online = 0;
3792 status = ha->isp_ops->chip_diag(vha);
3793 if (!status)
3794 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003795 }
3796
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003797 if (!status && !(status = qla2x00_init_rings(vha))) {
3798 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003799 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003800 /* Initialize the queues in use */
3801 qla25xx_init_queues(ha);
3802
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003803 status = qla2x00_fw_ready(vha);
3804 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003805 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003806 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003807
3808 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003809 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003811 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003812 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3813 wait_time = 256;
3814 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003815 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3816 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818 } while (!atomic_read(&vha->loop_down_timer) &&
3819 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3820 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3821 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003822 }
3823
3824 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003825 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003826 status = 0;
3827
3828 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3829 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003830 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 }
3832 return (status);
3833}
3834
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003835static int
3836qla25xx_init_queues(struct qla_hw_data *ha)
3837{
3838 struct rsp_que *rsp = NULL;
3839 struct req_que *req = NULL;
3840 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3841 int ret = -1;
3842 int i;
3843
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003844 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003845 rsp = ha->rsp_q_map[i];
3846 if (rsp) {
3847 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003848 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003849 if (ret != QLA_SUCCESS)
3850 DEBUG2_17(printk(KERN_WARNING
3851 "%s Rsp que:%d init failed\n", __func__,
3852 rsp->id));
3853 else
3854 DEBUG2_17(printk(KERN_INFO
3855 "%s Rsp que:%d inited\n", __func__,
3856 rsp->id));
3857 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003858 }
3859 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003860 req = ha->req_q_map[i];
3861 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003862 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003863 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003864 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003865 if (ret != QLA_SUCCESS)
3866 DEBUG2_17(printk(KERN_WARNING
3867 "%s Req que:%d init failed\n", __func__,
3868 req->id));
3869 else
3870 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003871 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003872 req->id));
3873 }
3874 }
3875 return ret;
3876}
3877
Linus Torvalds1da177e2005-04-16 15:20:36 -07003878/*
3879* qla2x00_reset_adapter
3880* Reset adapter.
3881*
3882* Input:
3883* ha = adapter block pointer.
3884*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003885void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003886qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003887{
3888 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003889 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003890 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003892 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003893 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003894
Linus Torvalds1da177e2005-04-16 15:20:36 -07003895 spin_lock_irqsave(&ha->hardware_lock, flags);
3896 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3897 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3898 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3899 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3900 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3901}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003902
3903void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003904qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003905{
3906 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003908 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3909
Giridhar Malavalia9083012010-04-12 17:59:55 -07003910 if (IS_QLA82XX(ha))
3911 return;
3912
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003913 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003914 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003915
3916 spin_lock_irqsave(&ha->hardware_lock, flags);
3917 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3918 RD_REG_DWORD(&reg->hccr);
3919 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3920 RD_REG_DWORD(&reg->hccr);
3921 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003922
3923 if (IS_NOPOLLING_TYPE(ha))
3924 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003925}
3926
David Miller4e08df32007-04-16 12:37:43 -07003927/* On sparc systems, obtain port and node WWN from firmware
3928 * properties.
3929 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003930static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3931 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003932{
3933#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003934 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003935 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003936 struct device_node *dp = pci_device_to_OF_node(pdev);
3937 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003938 int len;
3939
3940 val = of_get_property(dp, "port-wwn", &len);
3941 if (val && len >= WWN_SIZE)
3942 memcpy(nv->port_name, val, WWN_SIZE);
3943
3944 val = of_get_property(dp, "node-wwn", &len);
3945 if (val && len >= WWN_SIZE)
3946 memcpy(nv->node_name, val, WWN_SIZE);
3947#endif
3948}
3949
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003950int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003951qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003952{
David Miller4e08df32007-04-16 12:37:43 -07003953 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003954 struct init_cb_24xx *icb;
3955 struct nvram_24xx *nv;
3956 uint32_t *dptr;
3957 uint8_t *dptr1, *dptr2;
3958 uint32_t chksum;
3959 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003960 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003961
David Miller4e08df32007-04-16 12:37:43 -07003962 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003963 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003964 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003965
3966 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003967 if (ha->flags.port0) {
3968 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3969 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3970 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003971 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003972 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3973 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003974 ha->nvram_size = sizeof(struct nvram_24xx);
3975 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Giridhar Malavalia9083012010-04-12 17:59:55 -07003976 if (IS_QLA82XX(ha))
3977 ha->vpd_size = FA_VPD_SIZE_82XX;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003978
Seokmann Ju281afe12007-07-26 13:43:34 -07003979 /* Get VPD data into cache */
3980 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003981 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003982 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3983
3984 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003985 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003986 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003987 ha->nvram_size);
3988 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3989 chksum += le32_to_cpu(*dptr++);
3990
Andrew Vasquez76403352009-04-06 22:33:39 -07003991 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003992 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003993
3994 /* Bad NVRAM data, set defaults parameters. */
3995 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3996 || nv->id[3] != ' ' ||
3997 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3998 /* Reset NVRAM data. */
3999 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4000 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4001 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07004002 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4003 "invalid -- WWPN) defaults.\n");
4004
4005 /*
4006 * Set default initialization control block.
4007 */
4008 memset(nv, 0, ha->nvram_size);
4009 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4010 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4011 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4012 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4013 nv->exchange_count = __constant_cpu_to_le16(0);
4014 nv->hard_address = __constant_cpu_to_le16(124);
4015 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004016 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07004017 nv->port_name[2] = 0x00;
4018 nv->port_name[3] = 0xe0;
4019 nv->port_name[4] = 0x8b;
4020 nv->port_name[5] = 0x1c;
4021 nv->port_name[6] = 0x55;
4022 nv->port_name[7] = 0x86;
4023 nv->node_name[0] = 0x20;
4024 nv->node_name[1] = 0x00;
4025 nv->node_name[2] = 0x00;
4026 nv->node_name[3] = 0xe0;
4027 nv->node_name[4] = 0x8b;
4028 nv->node_name[5] = 0x1c;
4029 nv->node_name[6] = 0x55;
4030 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004031 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07004032 nv->login_retry_count = __constant_cpu_to_le16(8);
4033 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4034 nv->login_timeout = __constant_cpu_to_le16(0);
4035 nv->firmware_options_1 =
4036 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4037 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4038 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4039 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4040 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4041 nv->efi_parameters = __constant_cpu_to_le32(0);
4042 nv->reset_delay = 5;
4043 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4044 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4045 nv->link_down_timeout = __constant_cpu_to_le16(30);
4046
4047 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004048 }
4049
4050 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004051 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004052
4053 /* Copy 1st segment. */
4054 dptr1 = (uint8_t *)icb;
4055 dptr2 = (uint8_t *)&nv->version;
4056 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4057 while (cnt--)
4058 *dptr1++ = *dptr2++;
4059
4060 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07004061 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004062
4063 /* Copy 2nd segment. */
4064 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4065 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4066 cnt = (uint8_t *)&icb->reserved_3 -
4067 (uint8_t *)&icb->interrupt_delay_timer;
4068 while (cnt--)
4069 *dptr1++ = *dptr2++;
4070
4071 /*
4072 * Setup driver NVRAM options.
4073 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004074 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08004075 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004076
Andrew Vasquez5341e862006-05-17 15:09:16 -07004077 /* Use alternate WWN? */
4078 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4079 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4080 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4081 }
4082
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004083 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004084 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004085 /*
4086 * Firmware will apply the following mask if the nodename was
4087 * not provided.
4088 */
4089 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4090 icb->node_name[0] &= 0xF0;
4091 }
4092
4093 /* Set host adapter parameters. */
4094 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08004095 ha->flags.enable_lip_reset = 0;
4096 ha->flags.enable_lip_full_login =
4097 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4098 ha->flags.enable_target_reset =
4099 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004100 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07004101 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004102
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07004103 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4104 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004105
4106 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
4107 sizeof(ha->fw_seriallink_options24));
4108
4109 /* save HBA serial number */
4110 ha->serial0 = icb->port_name[5];
4111 ha->serial1 = icb->port_name[6];
4112 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004113 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4114 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004115
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004116 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4117
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004118 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4119
4120 /* Set minimum login_timeout to 4 seconds. */
4121 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4122 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4123 if (le16_to_cpu(nv->login_timeout) < 4)
4124 nv->login_timeout = __constant_cpu_to_le16(4);
4125 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004126 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004127
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004128 /* Set minimum RATOV to 100 tenths of a second. */
4129 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004130
4131 ha->loop_reset_delay = nv->reset_delay;
4132
4133 /* Link Down Timeout = 0:
4134 *
4135 * When Port Down timer expires we will start returning
4136 * I/O's to OS with "DID_NO_CONNECT".
4137 *
4138 * Link Down Timeout != 0:
4139 *
4140 * The driver waits for the link to come up after link down
4141 * before returning I/Os to OS with "DID_NO_CONNECT".
4142 */
4143 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4144 ha->loop_down_abort_time =
4145 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4146 } else {
4147 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4148 ha->loop_down_abort_time =
4149 (LOOP_DOWN_TIME - ha->link_down_timeout);
4150 }
4151
4152 /* Need enough time to try and get the port back. */
4153 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4154 if (qlport_down_retry)
4155 ha->port_down_retry_count = qlport_down_retry;
4156
4157 /* Set login_retry_count */
4158 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4159 if (ha->port_down_retry_count ==
4160 le16_to_cpu(nv->port_down_retry_count) &&
4161 ha->port_down_retry_count > 3)
4162 ha->login_retry_count = ha->port_down_retry_count;
4163 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4164 ha->login_retry_count = ha->port_down_retry_count;
4165 if (ql2xloginretrycount)
4166 ha->login_retry_count = ql2xloginretrycount;
4167
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004168 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004169 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004170 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4171 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4172 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4173 le16_to_cpu(icb->interrupt_delay_timer): 2;
4174 }
4175 icb->firmware_options_2 &= __constant_cpu_to_le32(
4176 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004177 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004178 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004179 ha->zio_mode = QLA_ZIO_MODE_6;
4180
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004181 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004182 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004183 ha->zio_timer * 100));
4184 qla_printk(KERN_INFO, ha,
4185 "ZIO mode %d enabled; timer delay (%d us).\n",
4186 ha->zio_mode, ha->zio_timer * 100);
4187
4188 icb->firmware_options_2 |= cpu_to_le32(
4189 (uint32_t)ha->zio_mode);
4190 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004191 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004192 }
4193
David Miller4e08df32007-04-16 12:37:43 -07004194 if (rval) {
4195 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004196 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004197 }
4198 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004199}
4200
Adrian Bunk413975a2006-06-30 02:33:06 -07004201static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004202qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4203 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004204{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004205 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004206 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004207 uint32_t *dcode, dlen;
4208 uint32_t risc_addr;
4209 uint32_t risc_size;
4210 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004211 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004212 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004213
4214 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004215 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004216
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004217 rval = QLA_SUCCESS;
4218
4219 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004220 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004221 *srisc_addr = 0;
4222
4223 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004224 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004225 for (i = 0; i < 4; i++)
4226 dcode[i] = be32_to_cpu(dcode[i]);
4227 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4228 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4229 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4230 dcode[3] == 0)) {
4231 qla_printk(KERN_WARNING, ha,
4232 "Unable to verify integrity of flash firmware image!\n");
4233 qla_printk(KERN_WARNING, ha,
4234 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4235 dcode[1], dcode[2], dcode[3]);
4236
4237 return QLA_FUNCTION_FAILED;
4238 }
4239
4240 while (segments && rval == QLA_SUCCESS) {
4241 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004242 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004243
4244 risc_addr = be32_to_cpu(dcode[2]);
4245 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4246 risc_size = be32_to_cpu(dcode[3]);
4247
4248 fragment = 0;
4249 while (risc_size > 0 && rval == QLA_SUCCESS) {
4250 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4251 if (dlen > risc_size)
4252 dlen = risc_size;
4253
4254 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4255 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004256 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004258 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004259 for (i = 0; i < dlen; i++)
4260 dcode[i] = swab32(dcode[i]);
4261
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004262 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004263 dlen);
4264 if (rval) {
4265 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004267 fragment));
4268 qla_printk(KERN_WARNING, ha,
4269 "[ERROR] Failed to load segment %d of "
4270 "firmware\n", fragment);
4271 break;
4272 }
4273
4274 faddr += dlen;
4275 risc_addr += dlen;
4276 risc_size -= dlen;
4277 fragment++;
4278 }
4279
4280 /* Next segment. */
4281 segments--;
4282 }
4283
4284 return rval;
4285}
4286
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004287#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4288
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004289int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004290qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004291{
4292 int rval;
4293 int i, fragment;
4294 uint16_t *wcode, *fwcode;
4295 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4296 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004297 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004298 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004299
4300 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004301 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004302 if (!blob) {
4303 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004304 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4305 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004306 return QLA_FUNCTION_FAILED;
4307 }
4308
4309 rval = QLA_SUCCESS;
4310
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004311 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004312 *srisc_addr = 0;
4313 fwcode = (uint16_t *)blob->fw->data;
4314 fwclen = 0;
4315
4316 /* Validate firmware image by checking version. */
4317 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4318 qla_printk(KERN_WARNING, ha,
4319 "Unable to verify integrity of firmware image (%Zd)!\n",
4320 blob->fw->size);
4321 goto fail_fw_integrity;
4322 }
4323 for (i = 0; i < 4; i++)
4324 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4325 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4326 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4327 wcode[2] == 0 && wcode[3] == 0)) {
4328 qla_printk(KERN_WARNING, ha,
4329 "Unable to verify integrity of firmware image!\n");
4330 qla_printk(KERN_WARNING, ha,
4331 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4332 wcode[1], wcode[2], wcode[3]);
4333 goto fail_fw_integrity;
4334 }
4335
4336 seg = blob->segs;
4337 while (*seg && rval == QLA_SUCCESS) {
4338 risc_addr = *seg;
4339 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4340 risc_size = be16_to_cpu(fwcode[3]);
4341
4342 /* Validate firmware image size. */
4343 fwclen += risc_size * sizeof(uint16_t);
4344 if (blob->fw->size < fwclen) {
4345 qla_printk(KERN_WARNING, ha,
4346 "Unable to verify integrity of firmware image "
4347 "(%Zd)!\n", blob->fw->size);
4348 goto fail_fw_integrity;
4349 }
4350
4351 fragment = 0;
4352 while (risc_size > 0 && rval == QLA_SUCCESS) {
4353 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4354 if (wlen > risc_size)
4355 wlen = risc_size;
4356
4357 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004358 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004359 risc_addr, wlen));
4360
4361 for (i = 0; i < wlen; i++)
4362 wcode[i] = swab16(fwcode[i]);
4363
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004364 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004365 wlen);
4366 if (rval) {
4367 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004368 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004369 fragment));
4370 qla_printk(KERN_WARNING, ha,
4371 "[ERROR] Failed to load segment %d of "
4372 "firmware\n", fragment);
4373 break;
4374 }
4375
4376 fwcode += wlen;
4377 risc_addr += wlen;
4378 risc_size -= wlen;
4379 fragment++;
4380 }
4381
4382 /* Next segment. */
4383 seg++;
4384 }
4385 return rval;
4386
4387fail_fw_integrity:
4388 return QLA_FUNCTION_FAILED;
4389}
4390
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004391static int
4392qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004393{
4394 int rval;
4395 int segments, fragment;
4396 uint32_t *dcode, dlen;
4397 uint32_t risc_addr;
4398 uint32_t risc_size;
4399 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004400 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004401 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004402 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004403 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004404
Andrew Vasquez54333832005-11-09 15:49:04 -08004405 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004406 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004407 if (!blob) {
4408 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004409 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4410 "from: " QLA_FW_URL ".\n");
4411
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004412 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004413 }
4414
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004415 qla_printk(KERN_INFO, ha,
4416 "FW: Loading via request-firmware...\n");
4417
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004418 rval = QLA_SUCCESS;
4419
4420 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004421 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004422 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004423 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004424 fwclen = 0;
4425
4426 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004427 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004428 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004429 "Unable to verify integrity of firmware image (%Zd)!\n",
4430 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004431 goto fail_fw_integrity;
4432 }
4433 for (i = 0; i < 4; i++)
4434 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4435 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4436 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4437 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4438 dcode[3] == 0)) {
4439 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004440 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004441 qla_printk(KERN_WARNING, ha,
4442 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4443 dcode[1], dcode[2], dcode[3]);
4444 goto fail_fw_integrity;
4445 }
4446
4447 while (segments && rval == QLA_SUCCESS) {
4448 risc_addr = be32_to_cpu(fwcode[2]);
4449 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4450 risc_size = be32_to_cpu(fwcode[3]);
4451
4452 /* Validate firmware image size. */
4453 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004454 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004455 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004456 "Unable to verify integrity of firmware image "
4457 "(%Zd)!\n", blob->fw->size);
4458
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004459 goto fail_fw_integrity;
4460 }
4461
4462 fragment = 0;
4463 while (risc_size > 0 && rval == QLA_SUCCESS) {
4464 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4465 if (dlen > risc_size)
4466 dlen = risc_size;
4467
4468 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004469 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004470 risc_addr, dlen));
4471
4472 for (i = 0; i < dlen; i++)
4473 dcode[i] = swab32(fwcode[i]);
4474
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004475 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004476 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004477 if (rval) {
4478 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004479 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004480 fragment));
4481 qla_printk(KERN_WARNING, ha,
4482 "[ERROR] Failed to load segment %d of "
4483 "firmware\n", fragment);
4484 break;
4485 }
4486
4487 fwcode += dlen;
4488 risc_addr += dlen;
4489 risc_size -= dlen;
4490 fragment++;
4491 }
4492
4493 /* Next segment. */
4494 segments--;
4495 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004496 return rval;
4497
4498fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004499 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004500}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004501
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004502int
4503qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4504{
4505 int rval;
4506
Andrew Vasqueze337d902009-04-06 22:33:49 -07004507 if (ql2xfwloadbin == 1)
4508 return qla81xx_load_risc(vha, srisc_addr);
4509
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004510 /*
4511 * FW Load priority:
4512 * 1) Firmware via request-firmware interface (.bin file).
4513 * 2) Firmware residing in flash.
4514 */
4515 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4516 if (rval == QLA_SUCCESS)
4517 return rval;
4518
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004519 return qla24xx_load_risc_flash(vha, srisc_addr,
4520 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004521}
4522
4523int
4524qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4525{
4526 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004527 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004528
Andrew Vasqueze337d902009-04-06 22:33:49 -07004529 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004530 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004531
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004532 /*
4533 * FW Load priority:
4534 * 1) Firmware residing in flash.
4535 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004536 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004537 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004538 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004539 if (rval == QLA_SUCCESS)
4540 return rval;
4541
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004542try_blob_fw:
4543 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4544 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4545 return rval;
4546
4547 qla_printk(KERN_ERR, ha,
4548 "FW: Attempting to fallback to golden firmware...\n");
4549 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4550 if (rval != QLA_SUCCESS)
4551 return rval;
4552
4553 qla_printk(KERN_ERR, ha,
4554 "FW: Please update operational firmware...\n");
4555 ha->flags.running_gold_fw = 1;
4556
4557 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004558}
4559
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004560void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004561qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004562{
4563 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004564 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004565
Andrew Vasquez85880802009-12-15 21:29:46 -08004566 if (ha->flags.pci_channel_io_perm_failure)
4567 return;
Andrew Vasqueze4289242007-07-19 15:05:56 -07004568 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004569 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004570 if (!ha->fw_major_version)
4571 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004572
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004573 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004574 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004575 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004576 ha->isp_ops->reset_chip(vha);
4577 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004578 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004579 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004580 continue;
4581 qla_printk(KERN_INFO, ha,
4582 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004583 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004584 }
4585}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004586
4587int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004588qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004589{
4590 int rval = QLA_SUCCESS;
4591 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004592 struct qla_hw_data *ha = vha->hw;
4593 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004594 struct req_que *req;
4595 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004596
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004597 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004598 return -EINVAL;
4599
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004600 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004601 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004602 req = ha->req_q_map[0];
4603 else
4604 req = vha->req;
4605 rsp = req->rsp;
4606
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004607 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004608 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004609 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004610 }
4611
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004612 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004613
4614 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004615 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004616 if (mb[0] != MBS_COMMAND_COMPLETE) {
4617 DEBUG15(qla_printk(KERN_INFO, ha,
4618 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4619 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4620 mb[0], mb[1], mb[2], mb[6], mb[7]));
4621 return (QLA_FUNCTION_FAILED);
4622 }
4623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004624 atomic_set(&vha->loop_down_timer, 0);
4625 atomic_set(&vha->loop_state, LOOP_UP);
4626 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4627 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4628 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004629
4630 return rval;
4631}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004632
4633/* 84XX Support **************************************************************/
4634
4635static LIST_HEAD(qla_cs84xx_list);
4636static DEFINE_MUTEX(qla_cs84xx_mutex);
4637
4638static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004639qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004640{
4641 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004642 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004643
4644 mutex_lock(&qla_cs84xx_mutex);
4645
4646 /* Find any shared 84xx chip. */
4647 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4648 if (cs84xx->bus == ha->pdev->bus) {
4649 kref_get(&cs84xx->kref);
4650 goto done;
4651 }
4652 }
4653
4654 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4655 if (!cs84xx)
4656 goto done;
4657
4658 kref_init(&cs84xx->kref);
4659 spin_lock_init(&cs84xx->access_lock);
4660 mutex_init(&cs84xx->fw_update_mutex);
4661 cs84xx->bus = ha->pdev->bus;
4662
4663 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4664done:
4665 mutex_unlock(&qla_cs84xx_mutex);
4666 return cs84xx;
4667}
4668
4669static void
4670__qla84xx_chip_release(struct kref *kref)
4671{
4672 struct qla_chip_state_84xx *cs84xx =
4673 container_of(kref, struct qla_chip_state_84xx, kref);
4674
4675 mutex_lock(&qla_cs84xx_mutex);
4676 list_del(&cs84xx->list);
4677 mutex_unlock(&qla_cs84xx_mutex);
4678 kfree(cs84xx);
4679}
4680
4681void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004682qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004683{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004684 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004685 if (ha->cs84xx)
4686 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4687}
4688
4689static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004690qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004691{
4692 int rval;
4693 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004694 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004695
4696 mutex_lock(&ha->cs84xx->fw_update_mutex);
4697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004698 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004699
4700 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4701
4702 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4703 QLA_SUCCESS;
4704}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004705
4706/* 81XX Support **************************************************************/
4707
4708int
4709qla81xx_nvram_config(scsi_qla_host_t *vha)
4710{
4711 int rval;
4712 struct init_cb_81xx *icb;
4713 struct nvram_81xx *nv;
4714 uint32_t *dptr;
4715 uint8_t *dptr1, *dptr2;
4716 uint32_t chksum;
4717 uint16_t cnt;
4718 struct qla_hw_data *ha = vha->hw;
4719
4720 rval = QLA_SUCCESS;
4721 icb = (struct init_cb_81xx *)ha->init_cb;
4722 nv = ha->nvram;
4723
4724 /* Determine NVRAM starting address. */
4725 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004726 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004727
4728 /* Get VPD data into cache */
4729 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004730 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4731 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004732
4733 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004734 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004735 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004736 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004737 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4738 chksum += le32_to_cpu(*dptr++);
4739
Andrew Vasquez76403352009-04-06 22:33:39 -07004740 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004741 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4742
4743 /* Bad NVRAM data, set defaults parameters. */
4744 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4745 || nv->id[3] != ' ' ||
4746 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4747 /* Reset NVRAM data. */
4748 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4749 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4750 le16_to_cpu(nv->nvram_version));
4751 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4752 "invalid -- WWPN) defaults.\n");
4753
4754 /*
4755 * Set default initialization control block.
4756 */
4757 memset(nv, 0, ha->nvram_size);
4758 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4759 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4760 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4761 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4762 nv->exchange_count = __constant_cpu_to_le16(0);
4763 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004764 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004765 nv->port_name[2] = 0x00;
4766 nv->port_name[3] = 0xe0;
4767 nv->port_name[4] = 0x8b;
4768 nv->port_name[5] = 0x1c;
4769 nv->port_name[6] = 0x55;
4770 nv->port_name[7] = 0x86;
4771 nv->node_name[0] = 0x20;
4772 nv->node_name[1] = 0x00;
4773 nv->node_name[2] = 0x00;
4774 nv->node_name[3] = 0xe0;
4775 nv->node_name[4] = 0x8b;
4776 nv->node_name[5] = 0x1c;
4777 nv->node_name[6] = 0x55;
4778 nv->node_name[7] = 0x86;
4779 nv->login_retry_count = __constant_cpu_to_le16(8);
4780 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4781 nv->login_timeout = __constant_cpu_to_le16(0);
4782 nv->firmware_options_1 =
4783 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4784 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4785 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4786 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4787 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4788 nv->efi_parameters = __constant_cpu_to_le32(0);
4789 nv->reset_delay = 5;
4790 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4791 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4792 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004793 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004794 nv->enode_mac[1] = 0x02;
4795 nv->enode_mac[2] = 0x03;
4796 nv->enode_mac[3] = 0x04;
4797 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004798 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004799
4800 rval = 1;
4801 }
4802
4803 /* Reset Initialization control block */
4804 memset(icb, 0, sizeof(struct init_cb_81xx));
4805
4806 /* Copy 1st segment. */
4807 dptr1 = (uint8_t *)icb;
4808 dptr2 = (uint8_t *)&nv->version;
4809 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4810 while (cnt--)
4811 *dptr1++ = *dptr2++;
4812
4813 icb->login_retry_count = nv->login_retry_count;
4814
4815 /* Copy 2nd segment. */
4816 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4817 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4818 cnt = (uint8_t *)&icb->reserved_5 -
4819 (uint8_t *)&icb->interrupt_delay_timer;
4820 while (cnt--)
4821 *dptr1++ = *dptr2++;
4822
4823 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4824 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4825 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4826 icb->enode_mac[0] = 0x01;
4827 icb->enode_mac[1] = 0x02;
4828 icb->enode_mac[2] = 0x03;
4829 icb->enode_mac[3] = 0x04;
4830 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004831 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004832 }
4833
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004834 /* Use extended-initialization control block. */
4835 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4836
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004837 /*
4838 * Setup driver NVRAM options.
4839 */
4840 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Giridhar Malavalia9083012010-04-12 17:59:55 -07004841 "QLE8XXX");
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004842
4843 /* Use alternate WWN? */
4844 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4845 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4846 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4847 }
4848
4849 /* Prepare nodename */
4850 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4851 /*
4852 * Firmware will apply the following mask if the nodename was
4853 * not provided.
4854 */
4855 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4856 icb->node_name[0] &= 0xF0;
4857 }
4858
4859 /* Set host adapter parameters. */
4860 ha->flags.disable_risc_code_load = 0;
4861 ha->flags.enable_lip_reset = 0;
4862 ha->flags.enable_lip_full_login =
4863 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4864 ha->flags.enable_target_reset =
4865 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4866 ha->flags.enable_led_scheme = 0;
4867 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4868
4869 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4870 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4871
4872 /* save HBA serial number */
4873 ha->serial0 = icb->port_name[5];
4874 ha->serial1 = icb->port_name[6];
4875 ha->serial2 = icb->port_name[7];
4876 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4877 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4878
4879 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4880
4881 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4882
4883 /* Set minimum login_timeout to 4 seconds. */
4884 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4885 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4886 if (le16_to_cpu(nv->login_timeout) < 4)
4887 nv->login_timeout = __constant_cpu_to_le16(4);
4888 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4889 icb->login_timeout = nv->login_timeout;
4890
4891 /* Set minimum RATOV to 100 tenths of a second. */
4892 ha->r_a_tov = 100;
4893
4894 ha->loop_reset_delay = nv->reset_delay;
4895
4896 /* Link Down Timeout = 0:
4897 *
4898 * When Port Down timer expires we will start returning
4899 * I/O's to OS with "DID_NO_CONNECT".
4900 *
4901 * Link Down Timeout != 0:
4902 *
4903 * The driver waits for the link to come up after link down
4904 * before returning I/Os to OS with "DID_NO_CONNECT".
4905 */
4906 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4907 ha->loop_down_abort_time =
4908 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4909 } else {
4910 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4911 ha->loop_down_abort_time =
4912 (LOOP_DOWN_TIME - ha->link_down_timeout);
4913 }
4914
4915 /* Need enough time to try and get the port back. */
4916 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4917 if (qlport_down_retry)
4918 ha->port_down_retry_count = qlport_down_retry;
4919
4920 /* Set login_retry_count */
4921 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4922 if (ha->port_down_retry_count ==
4923 le16_to_cpu(nv->port_down_retry_count) &&
4924 ha->port_down_retry_count > 3)
4925 ha->login_retry_count = ha->port_down_retry_count;
4926 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4927 ha->login_retry_count = ha->port_down_retry_count;
4928 if (ql2xloginretrycount)
4929 ha->login_retry_count = ql2xloginretrycount;
4930
4931 /* Enable ZIO. */
4932 if (!vha->flags.init_done) {
4933 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4934 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4935 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4936 le16_to_cpu(icb->interrupt_delay_timer): 2;
4937 }
4938 icb->firmware_options_2 &= __constant_cpu_to_le32(
4939 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4940 vha->flags.process_response_queue = 0;
4941 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4942 ha->zio_mode = QLA_ZIO_MODE_6;
4943
4944 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4945 "(%d us).\n", vha->host_no, ha->zio_mode,
4946 ha->zio_timer * 100));
4947 qla_printk(KERN_INFO, ha,
4948 "ZIO mode %d enabled; timer delay (%d us).\n",
4949 ha->zio_mode, ha->zio_timer * 100);
4950
4951 icb->firmware_options_2 |= cpu_to_le32(
4952 (uint32_t)ha->zio_mode);
4953 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4954 vha->flags.process_response_queue = 1;
4955 }
4956
4957 if (rval) {
4958 DEBUG2_3(printk(KERN_WARNING
4959 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4960 }
4961 return (rval);
4962}
4963
Giridhar Malavalia9083012010-04-12 17:59:55 -07004964int
4965qla82xx_restart_isp(scsi_qla_host_t *vha)
4966{
4967 int status, rval;
4968 uint32_t wait_time;
4969 struct qla_hw_data *ha = vha->hw;
4970 struct req_que *req = ha->req_q_map[0];
4971 struct rsp_que *rsp = ha->rsp_q_map[0];
4972 struct scsi_qla_host *vp;
4973 struct scsi_qla_host *tvp;
4974
4975 status = qla2x00_init_rings(vha);
4976 if (!status) {
4977 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4978 ha->flags.chip_reset_done = 1;
4979
4980 status = qla2x00_fw_ready(vha);
4981 if (!status) {
4982 qla_printk(KERN_INFO, ha,
4983 "%s(): Start configure loop, "
4984 "status = %d\n", __func__, status);
4985
4986 /* Issue a marker after FW becomes ready. */
4987 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
4988
4989 vha->flags.online = 1;
4990 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4991 wait_time = 256;
4992 do {
4993 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4994 qla2x00_configure_loop(vha);
4995 wait_time--;
4996 } while (!atomic_read(&vha->loop_down_timer) &&
4997 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) &&
4998 wait_time &&
4999 (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)));
5000 }
5001
5002 /* if no cable then assume it's good */
5003 if ((vha->device_flags & DFLG_NO_CABLE))
5004 status = 0;
5005
5006 qla_printk(KERN_INFO, ha,
5007 "%s(): Configure loop done, status = 0x%x\n",
5008 __func__, status);
5009 }
5010
5011 if (!status) {
5012 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
5013
5014 if (!atomic_read(&vha->loop_down_timer)) {
5015 /*
5016 * Issue marker command only when we are going
5017 * to start the I/O .
5018 */
5019 vha->marker_needed = 1;
5020 }
5021
5022 vha->flags.online = 1;
5023
5024 ha->isp_ops->enable_intrs(ha);
5025
5026 ha->isp_abort_cnt = 0;
5027 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5028
5029 if (ha->fce) {
5030 ha->flags.fce_enabled = 1;
5031 memset(ha->fce, 0,
5032 fce_calc_size(ha->fce_bufs));
5033 rval = qla2x00_enable_fce_trace(vha,
5034 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
5035 &ha->fce_bufs);
5036 if (rval) {
5037 qla_printk(KERN_WARNING, ha,
5038 "Unable to reinitialize FCE "
5039 "(%d).\n", rval);
5040 ha->flags.fce_enabled = 0;
5041 }
5042 }
5043
5044 if (ha->eft) {
5045 memset(ha->eft, 0, EFT_SIZE);
5046 rval = qla2x00_enable_eft_trace(vha,
5047 ha->eft_dma, EFT_NUM_BUFFERS);
5048 if (rval) {
5049 qla_printk(KERN_WARNING, ha,
5050 "Unable to reinitialize EFT "
5051 "(%d).\n", rval);
5052 }
5053 }
5054 } else { /* failed the ISP abort */
5055 vha->flags.online = 1;
5056 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
5057 if (ha->isp_abort_cnt == 0) {
5058 qla_printk(KERN_WARNING, ha,
5059 "ISP error recovery failed - "
5060 "board disabled\n");
5061 /*
5062 * The next call disables the board
5063 * completely.
5064 */
5065 ha->isp_ops->reset_adapter(vha);
5066 vha->flags.online = 0;
5067 clear_bit(ISP_ABORT_RETRY,
5068 &vha->dpc_flags);
5069 status = 0;
5070 } else { /* schedule another ISP abort */
5071 ha->isp_abort_cnt--;
5072 qla_printk(KERN_INFO, ha,
5073 "qla%ld: ISP abort - "
5074 "retry remaining %d\n",
5075 vha->host_no, ha->isp_abort_cnt);
5076 status = 1;
5077 }
5078 } else {
5079 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
5080 qla_printk(KERN_INFO, ha,
5081 "(%ld): ISP error recovery "
5082 "- retrying (%d) more times\n",
5083 vha->host_no, ha->isp_abort_cnt);
5084 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5085 status = 1;
5086 }
5087 }
5088
5089 if (!status) {
5090 DEBUG(printk(KERN_INFO
5091 "qla82xx_restart_isp(%ld): succeeded.\n",
5092 vha->host_no));
5093 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
5094 if (vp->vp_idx)
5095 qla2x00_vp_abort_isp(vp);
5096 }
5097 } else {
5098 qla_printk(KERN_INFO, ha,
5099 "qla82xx_restart_isp: **** FAILED ****\n");
5100 }
5101
5102 return status;
5103}
5104
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005105void
Andrew Vasquezae97c912010-02-18 10:07:28 -08005106qla81xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005107{
Andrew Vasquezae97c912010-02-18 10:07:28 -08005108 struct qla_hw_data *ha = vha->hw;
5109
5110 if (!ql2xetsenable)
5111 return;
5112
5113 /* Enable ETS Burst. */
5114 memset(ha->fw_options, 0, sizeof(ha->fw_options));
5115 ha->fw_options[2] |= BIT_9;
5116 qla2x00_set_fw_options(vha, ha->fw_options);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08005117}
Sarang Radke09ff7012010-03-19 17:03:59 -07005118
5119/*
5120 * qla24xx_get_fcp_prio
5121 * Gets the fcp cmd priority value for the logged in port.
5122 * Looks for a match of the port descriptors within
5123 * each of the fcp prio config entries. If a match is found,
5124 * the tag (priority) value is returned.
5125 *
5126 * Input:
5127 * ha = adapter block po
5128 * fcport = port structure pointer.
5129 *
5130 * Return:
Andrew Vasquez6c452a42010-03-19 17:04:02 -07005131 * non-zero (if found)
Sarang Radke09ff7012010-03-19 17:03:59 -07005132 * 0 (if not found)
5133 *
5134 * Context:
5135 * Kernel context
5136 */
5137uint8_t
5138qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
5139{
5140 int i, entries;
5141 uint8_t pid_match, wwn_match;
5142 uint8_t priority;
5143 uint32_t pid1, pid2;
5144 uint64_t wwn1, wwn2;
5145 struct qla_fcp_prio_entry *pri_entry;
5146 struct qla_hw_data *ha = vha->hw;
5147
5148 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
5149 return 0;
5150
5151 priority = 0;
5152 entries = ha->fcp_prio_cfg->num_entries;
5153 pri_entry = &ha->fcp_prio_cfg->entry[0];
5154
5155 for (i = 0; i < entries; i++) {
5156 pid_match = wwn_match = 0;
5157
5158 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
5159 pri_entry++;
5160 continue;
5161 }
5162
5163 /* check source pid for a match */
5164 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
5165 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
5166 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
5167 if (pid1 == INVALID_PORT_ID)
5168 pid_match++;
5169 else if (pid1 == pid2)
5170 pid_match++;
5171 }
5172
5173 /* check destination pid for a match */
5174 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
5175 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
5176 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
5177 if (pid1 == INVALID_PORT_ID)
5178 pid_match++;
5179 else if (pid1 == pid2)
5180 pid_match++;
5181 }
5182
5183 /* check source WWN for a match */
5184 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
5185 wwn1 = wwn_to_u64(vha->port_name);
5186 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
5187 if (wwn2 == (uint64_t)-1)
5188 wwn_match++;
5189 else if (wwn1 == wwn2)
5190 wwn_match++;
5191 }
5192
5193 /* check destination WWN for a match */
5194 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
5195 wwn1 = wwn_to_u64(fcport->port_name);
5196 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
5197 if (wwn2 == (uint64_t)-1)
5198 wwn_match++;
5199 else if (wwn1 == wwn2)
5200 wwn_match++;
5201 }
5202
5203 if (pid_match == 2 || wwn_match == 2) {
5204 /* Found a matching entry */
5205 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
5206 priority = pri_entry->tag;
5207 break;
5208 }
5209
5210 pri_entry++;
5211 }
5212
5213 return priority;
5214}
5215
5216/*
5217 * qla24xx_update_fcport_fcp_prio
5218 * Activates fcp priority for the logged in fc port
5219 *
5220 * Input:
5221 * ha = adapter block pointer.
5222 * fcp = port structure pointer.
5223 *
5224 * Return:
5225 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5226 *
5227 * Context:
5228 * Kernel context.
5229 */
5230int
5231qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *ha, fc_port_t *fcport)
5232{
5233 int ret;
5234 uint8_t priority;
5235 uint16_t mb[5];
5236
5237 if (atomic_read(&fcport->state) == FCS_UNCONFIGURED ||
5238 fcport->port_type != FCT_TARGET ||
5239 fcport->loop_id == FC_NO_LOOP_ID)
5240 return QLA_FUNCTION_FAILED;
5241
5242 priority = qla24xx_get_fcp_prio(ha, fcport);
5243 ret = qla24xx_set_fcp_prio(ha, fcport->loop_id, priority, mb);
5244 if (ret == QLA_SUCCESS)
5245 fcport->fcp_prio = priority;
5246 else
5247 DEBUG2(printk(KERN_WARNING
5248 "scsi(%ld): Unable to activate fcp priority, "
5249 " ret=0x%x\n", ha->host_no, ret));
5250
5251 return ret;
5252}
5253
5254/*
5255 * qla24xx_update_all_fcp_prio
5256 * Activates fcp priority for all the logged in ports
5257 *
5258 * Input:
5259 * ha = adapter block pointer.
5260 *
5261 * Return:
5262 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5263 *
5264 * Context:
5265 * Kernel context.
5266 */
5267int
5268qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
5269{
5270 int ret;
5271 fc_port_t *fcport;
5272
5273 ret = QLA_FUNCTION_FAILED;
5274 /* We need to set priority for all logged in ports */
5275 list_for_each_entry(fcport, &vha->vp_fcports, list)
5276 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
5277
5278 return ret;
5279}