blob: 37c99a27874c78b316f579a366fcd3abcb812000 [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>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070011#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#include "qla_devtbl.h"
14
David Miller4e08df32007-04-16 12:37:43 -070015#ifdef CONFIG_SPARC
16#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070017#endif
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20* QLogic ISP2x00 Hardware Support Function Prototypes.
21*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_init_rings(scsi_qla_host_t *);
25static int qla2x00_fw_ready(scsi_qla_host_t *);
26static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int qla2x00_configure_loop(scsi_qla_host_t *);
28static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static int qla2x00_configure_fabric(scsi_qla_host_t *);
30static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
31static int qla2x00_device_resync(scsi_qla_host_t *);
32static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
33 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080037static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070038
Harihara Kadayam4d4df192008-04-03 13:13:26 -070039static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080041static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070042
Andrew Vasquezac280b62009-08-20 11:06:05 -070043/* SRB Extensions ---------------------------------------------------------- */
44
45static void
46qla2x00_ctx_sp_timeout(unsigned long __data)
47{
48 srb_t *sp = (srb_t *)__data;
49 struct srb_ctx *ctx;
50 fc_port_t *fcport = sp->fcport;
51 struct qla_hw_data *ha = fcport->vha->hw;
52 struct req_que *req;
53 unsigned long flags;
54
55 spin_lock_irqsave(&ha->hardware_lock, flags);
56 req = ha->req_q_map[0];
57 req->outstanding_cmds[sp->handle] = NULL;
58 ctx = sp->ctx;
59 ctx->timeout(sp);
60 spin_unlock_irqrestore(&ha->hardware_lock, flags);
61
62 ctx->free(sp);
63}
64
65static void
66qla2x00_ctx_sp_free(srb_t *sp)
67{
68 struct srb_ctx *ctx = sp->ctx;
69
70 kfree(ctx);
71 mempool_free(sp, sp->fcport->vha->hw->srb_mempool);
72}
73
74inline srb_t *
75qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size,
76 unsigned long tmo)
77{
78 srb_t *sp;
79 struct qla_hw_data *ha = vha->hw;
80 struct srb_ctx *ctx;
81
82 sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL);
83 if (!sp)
84 goto done;
85 ctx = kzalloc(size, GFP_KERNEL);
86 if (!ctx) {
87 mempool_free(sp, ha->srb_mempool);
88 goto done;
89 }
90
91 memset(sp, 0, sizeof(*sp));
92 sp->fcport = fcport;
93 sp->ctx = ctx;
94 ctx->free = qla2x00_ctx_sp_free;
95
96 init_timer(&ctx->timer);
97 if (!tmo)
98 goto done;
99 ctx->timer.expires = jiffies + tmo * HZ;
100 ctx->timer.data = (unsigned long)sp;
101 ctx->timer.function = qla2x00_ctx_sp_timeout;
102 add_timer(&ctx->timer);
103done:
104 return sp;
105}
106
107/* Asynchronous Login/Logout Routines -------------------------------------- */
108
109#define ELS_TMO_2_RATOV(ha) ((ha)->r_a_tov / 10 * 2)
110
111static void
112qla2x00_async_logio_timeout(srb_t *sp)
113{
114 fc_port_t *fcport = sp->fcport;
115 struct srb_logio *lio = sp->ctx;
116
117 DEBUG2(printk(KERN_WARNING
118 "scsi(%ld:%x): Async-%s timeout.\n",
119 fcport->vha->host_no, sp->handle,
120 lio->ctx.type == SRB_LOGIN_CMD ? "login": "logout"));
121
122 if (lio->ctx.type == SRB_LOGIN_CMD)
123 qla2x00_post_async_logout_work(fcport->vha, fcport, NULL);
124}
125
126int
127qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
128 uint16_t *data)
129{
130 struct qla_hw_data *ha = vha->hw;
131 srb_t *sp;
132 struct srb_logio *lio;
133 int rval;
134
135 rval = QLA_FUNCTION_FAILED;
136 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
137 ELS_TMO_2_RATOV(ha) + 2);
138 if (!sp)
139 goto done;
140
141 lio = sp->ctx;
142 lio->ctx.type = SRB_LOGIN_CMD;
143 lio->ctx.timeout = qla2x00_async_logio_timeout;
144 lio->flags |= SRB_LOGIN_COND_PLOGI;
145 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
146 lio->flags |= SRB_LOGIN_RETRIED;
147 rval = qla2x00_start_sp(sp);
148 if (rval != QLA_SUCCESS)
149 goto done_free_sp;
150
151 DEBUG2(printk(KERN_DEBUG
152 "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x "
153 "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id,
154 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
155 fcport->login_retry));
156 return rval;
157
158done_free_sp:
159 del_timer_sync(&lio->ctx.timer);
160 lio->ctx.free(sp);
161done:
162 return rval;
163}
164
165int
166qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
167{
168 struct qla_hw_data *ha = vha->hw;
169 srb_t *sp;
170 struct srb_logio *lio;
171 int rval;
172
173 rval = QLA_FUNCTION_FAILED;
174 sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_logio),
175 ELS_TMO_2_RATOV(ha) + 2);
176 if (!sp)
177 goto done;
178
179 lio = sp->ctx;
180 lio->ctx.type = SRB_LOGOUT_CMD;
181 lio->ctx.timeout = qla2x00_async_logio_timeout;
182 rval = qla2x00_start_sp(sp);
183 if (rval != QLA_SUCCESS)
184 goto done_free_sp;
185
186 DEBUG2(printk(KERN_DEBUG
187 "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n",
188 fcport->vha->host_no, sp->handle, fcport->loop_id,
189 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa));
190 return rval;
191
192done_free_sp:
193 del_timer_sync(&lio->ctx.timer);
194 lio->ctx.free(sp);
195done:
196 return rval;
197}
198
199int
200qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport,
201 uint16_t *data)
202{
203 int rval;
204 uint8_t opts = 0;
205
206 switch (data[0]) {
207 case MBS_COMMAND_COMPLETE:
208 if (fcport->flags & FCF_TAPE_PRESENT)
209 opts |= BIT_1;
210 rval = qla2x00_get_port_database(vha, fcport, opts);
211 if (rval != QLA_SUCCESS)
212 qla2x00_mark_device_lost(vha, fcport, 1, 0);
213 else
214 qla2x00_update_fcport(vha, fcport);
215 break;
216 case MBS_COMMAND_ERROR:
217 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
218 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
219 else
220 qla2x00_mark_device_lost(vha, fcport, 1, 0);
221 break;
222 case MBS_PORT_ID_USED:
223 fcport->loop_id = data[1];
224 qla2x00_post_async_login_work(vha, fcport, NULL);
225 break;
226 case MBS_LOOP_ID_USED:
227 fcport->loop_id++;
228 rval = qla2x00_find_new_loop_id(vha, fcport);
229 if (rval != QLA_SUCCESS) {
230 qla2x00_mark_device_lost(vha, fcport, 1, 0);
231 break;
232 }
233 qla2x00_post_async_login_work(vha, fcport, NULL);
234 break;
235 }
236 return QLA_SUCCESS;
237}
238
239int
240qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
241 uint16_t *data)
242{
243 qla2x00_mark_device_lost(vha, fcport, 1, 0);
244 return QLA_SUCCESS;
245}
246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247/****************************************************************************/
248/* QLogic ISP2x00 Hardware Support Functions. */
249/****************************************************************************/
250
251/*
252* qla2x00_initialize_adapter
253* Initialize board.
254*
255* Input:
256* ha = adapter block pointer.
257*
258* Returns:
259* 0 = success
260*/
261int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800262qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
264 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800265 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800266 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700267
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800269 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700270 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800271 vha->flags.reset_active = 0;
272 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
273 atomic_set(&vha->loop_state, LOOP_DOWN);
274 vha->device_flags = DFLG_NO_CABLE;
275 vha->dpc_flags = 0;
276 vha->flags.management_server_logged_in = 0;
277 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 ha->isp_abort_cnt = 0;
279 ha->beacon_blink_led = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800280 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800282 set_bit(0, ha->req_qid_map);
283 set_bit(0, ha->rsp_qid_map);
284
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700285 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800286 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -0800288 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800289 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 return (rval);
291 }
292
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800293 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800295 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700296 if (rval) {
297 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800298 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -0700299 return (rval);
300 }
301
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800302 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -0800303
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800306 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700308 if (ha->flags.disable_serdes) {
309 /* Mask HBA via NVRAM settings? */
310 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
311 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800312 vha->port_name[0], vha->port_name[1],
313 vha->port_name[2], vha->port_name[3],
314 vha->port_name[4], vha->port_name[5],
315 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700316 return QLA_FUNCTION_FAILED;
317 }
318
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
320
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800321 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
322 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800323 if (rval)
324 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800325 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800326 if (rval)
327 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700329 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800330 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700331 if (!ha->cs84xx) {
332 qla_printk(KERN_ERR, ha,
333 "Unable to configure ISP84XX.\n");
334 return QLA_FUNCTION_FAILED;
335 }
336 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800337 rval = qla2x00_init_rings(vha);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700338 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 return (rval);
341}
342
343/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700344 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 * @ha: HA context
346 *
347 * Returns 0 on success.
348 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700349int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700352 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700353 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800354 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700355 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700358 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700361 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
363
Andrew Vasquez737faec2008-10-24 15:13:45 -0700364 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700366 /* Get PCI bus information. */
367 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700368 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700369 spin_unlock_irqrestore(&ha->hardware_lock, flags);
370
371 return QLA_SUCCESS;
372}
373
374/**
375 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
376 * @ha: HA context
377 *
378 * Returns 0 on success.
379 */
380int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800381qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700382{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700383 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700384 unsigned long flags = 0;
385 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800386 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700387 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700388
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700389 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700390 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700391
392 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700393 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700394
395 if (IS_QLA2322(ha) || IS_QLA6322(ha))
396 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700397 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700398
399 /*
400 * If this is a 2300 card and not 2312, reset the
401 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
402 * the 2310 also reports itself as a 2300 so we need to get the
403 * fb revision level -- a 6 indicates it really is a 2300 and
404 * not a 2310.
405 */
406 if (IS_QLA2300(ha)) {
407 spin_lock_irqsave(&ha->hardware_lock, flags);
408
409 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700410 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700411 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700412 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700413 break;
414
415 udelay(10);
416 }
417
418 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700419 WRT_REG_WORD(&reg->ctrl_status, 0x20);
420 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700421
422 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700423 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700424
425 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700426 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700427
428 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700429 WRT_REG_WORD(&reg->ctrl_status, 0x0);
430 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700431
432 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700433 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700434 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700435 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700436 break;
437
438 udelay(10);
439 }
440
441 spin_unlock_irqrestore(&ha->hardware_lock, flags);
442 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700443
444 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
445
Andrew Vasquez737faec2008-10-24 15:13:45 -0700446 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700447
448 /* Get PCI bus information. */
449 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700450 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700451 spin_unlock_irqrestore(&ha->hardware_lock, flags);
452
453 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454}
455
456/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700457 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
458 * @ha: HA context
459 *
460 * Returns 0 on success.
461 */
462int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800463qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700464{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700465 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700466 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800467 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700468 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700469
470 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700471 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700472
473 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700474 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700475 w &= ~PCI_COMMAND_INTX_DISABLE;
476 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
477
478 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
479
480 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700481 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
482 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700483
484 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700485 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
486 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700487
Andrew Vasquez737faec2008-10-24 15:13:45 -0700488 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700489
Auke Kok44c10132007-06-08 15:46:36 -0700490 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800491
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700492 /* Get PCI bus information. */
493 spin_lock_irqsave(&ha->hardware_lock, flags);
494 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
496
497 return QLA_SUCCESS;
498}
499
500/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700501 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
502 * @ha: HA context
503 *
504 * Returns 0 on success.
505 */
506int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700508{
509 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800510 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700511
512 pci_set_master(ha->pdev);
513 pci_try_set_mwi(ha->pdev);
514
515 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
516 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
517 w &= ~PCI_COMMAND_INTX_DISABLE;
518 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
519
520 /* PCIe -- adjust Maximum Read Request Size (2048). */
521 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
522 pcie_set_readrq(ha->pdev, 2048);
523
Andrew Vasquez737faec2008-10-24 15:13:45 -0700524 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700525
526 ha->chip_revision = ha->pdev->revision;
527
528 return QLA_SUCCESS;
529}
530
531/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 * qla2x00_isp_firmware() - Choose firmware image.
533 * @ha: HA context
534 *
535 * Returns 0 on success.
536 */
537static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800538qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539{
540 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700541 uint16_t loop_id, topo, sw_cap;
542 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800543 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700544
545 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700546 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 if (ha->flags.disable_risc_code_load) {
549 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800550 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
552
553 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800554 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700555 if (rval == QLA_SUCCESS) {
556 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800557 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700558 &area, &domain, &topo, &sw_cap);
559 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700560 }
561
562 if (rval) {
563 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800564 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566
567 return (rval);
568}
569
570/**
571 * qla2x00_reset_chip() - Reset ISP chip.
572 * @ha: HA context
573 *
574 * Returns 0 on success.
575 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700576void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800577qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700578{
579 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800580 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700581 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583 uint16_t cmd;
584
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700585 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700586
587 spin_lock_irqsave(&ha->hardware_lock, flags);
588
589 /* Turn off master enable */
590 cmd = 0;
591 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
592 cmd &= ~PCI_COMMAND_MASTER;
593 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
594
595 if (!IS_QLA2100(ha)) {
596 /* Pause RISC. */
597 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
598 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
599 for (cnt = 0; cnt < 30000; cnt++) {
600 if ((RD_REG_WORD(&reg->hccr) &
601 HCCR_RISC_PAUSE) != 0)
602 break;
603 udelay(100);
604 }
605 } else {
606 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
607 udelay(10);
608 }
609
610 /* Select FPM registers. */
611 WRT_REG_WORD(&reg->ctrl_status, 0x20);
612 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
613
614 /* FPM Soft Reset. */
615 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
616 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
617
618 /* Toggle Fpm Reset. */
619 if (!IS_QLA2200(ha)) {
620 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
621 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
622 }
623
624 /* Select frame buffer registers. */
625 WRT_REG_WORD(&reg->ctrl_status, 0x10);
626 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
627
628 /* Reset frame buffer FIFOs. */
629 if (IS_QLA2200(ha)) {
630 WRT_FB_CMD_REG(ha, reg, 0xa000);
631 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
632 } else {
633 WRT_FB_CMD_REG(ha, reg, 0x00fc);
634
635 /* Read back fb_cmd until zero or 3 seconds max */
636 for (cnt = 0; cnt < 3000; cnt++) {
637 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
638 break;
639 udelay(100);
640 }
641 }
642
643 /* Select RISC module registers. */
644 WRT_REG_WORD(&reg->ctrl_status, 0);
645 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
646
647 /* Reset RISC processor. */
648 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
649 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
650
651 /* Release RISC processor. */
652 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
653 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
654 }
655
656 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
657 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
658
659 /* Reset ISP chip. */
660 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
661
662 /* Wait for RISC to recover from reset. */
663 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
664 /*
665 * It is necessary to for a delay here since the card doesn't
666 * respond to PCI reads during a reset. On some architectures
667 * this will result in an MCA.
668 */
669 udelay(20);
670 for (cnt = 30000; cnt; cnt--) {
671 if ((RD_REG_WORD(&reg->ctrl_status) &
672 CSR_ISP_SOFT_RESET) == 0)
673 break;
674 udelay(100);
675 }
676 } else
677 udelay(10);
678
679 /* Reset RISC processor. */
680 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
681
682 WRT_REG_WORD(&reg->semaphore, 0);
683
684 /* Release RISC processor. */
685 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
686 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
687
688 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
689 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700690 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
693 udelay(100);
694 }
695 } else
696 udelay(100);
697
698 /* Turn on master enable */
699 cmd |= PCI_COMMAND_MASTER;
700 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
701
702 /* Disable RISC pause on FPM parity error. */
703 if (!IS_QLA2100(ha)) {
704 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
705 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
706 }
707
708 spin_unlock_irqrestore(&ha->hardware_lock, flags);
709}
710
711/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700712 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700713 * @ha: HA context
714 *
715 * Returns 0 on success.
716 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700717static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800718qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700719{
720 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800721 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700722 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
723 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800724 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700725
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700726 spin_lock_irqsave(&ha->hardware_lock, flags);
727
728 /* Reset RISC. */
729 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
730 for (cnt = 0; cnt < 30000; cnt++) {
731 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
732 break;
733
734 udelay(10);
735 }
736
737 WRT_REG_DWORD(&reg->ctrl_status,
738 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800739 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700740
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800741 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700742 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700743 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
744 for (cnt = 10000 ; cnt && d2; cnt--) {
745 udelay(5);
746 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
747 barrier();
748 }
749
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800750 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700751 d2 = RD_REG_DWORD(&reg->ctrl_status);
752 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
753 udelay(5);
754 d2 = RD_REG_DWORD(&reg->ctrl_status);
755 barrier();
756 }
757
758 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
759 RD_REG_DWORD(&reg->hccr);
760
761 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
762 RD_REG_DWORD(&reg->hccr);
763
764 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
765 RD_REG_DWORD(&reg->hccr);
766
767 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
768 for (cnt = 6000000 ; cnt && d2; cnt--) {
769 udelay(5);
770 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
771 barrier();
772 }
773
774 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800775
776 if (IS_NOPOLLING_TYPE(ha))
777 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700778}
779
780/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700781 * qla24xx_reset_chip() - Reset ISP24xx chip.
782 * @ha: HA context
783 *
784 * Returns 0 on success.
785 */
786void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800787qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700788{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800789 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700790 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700791
792 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800793 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700794}
795
796/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 * qla2x00_chip_diag() - Test chip for proper operation.
798 * @ha: HA context
799 *
800 * Returns 0 on success.
801 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700802int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800803qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804{
805 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800806 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700807 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700808 unsigned long flags = 0;
809 uint16_t data;
810 uint32_t cnt;
811 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800812 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700813
814 /* Assume a failed state */
815 rval = QLA_FUNCTION_FAILED;
816
817 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800818 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819
820 spin_lock_irqsave(&ha->hardware_lock, flags);
821
822 /* Reset ISP chip. */
823 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
824
825 /*
826 * We need to have a delay here since the card will not respond while
827 * in reset causing an MCA on some architectures.
828 */
829 udelay(20);
830 data = qla2x00_debounce_register(&reg->ctrl_status);
831 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
832 udelay(5);
833 data = RD_REG_WORD(&reg->ctrl_status);
834 barrier();
835 }
836
837 if (!cnt)
838 goto chip_diag_failed;
839
840 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700841 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700842
843 /* Reset RISC processor. */
844 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
845 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
846
847 /* Workaround for QLA2312 PCI parity error */
848 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
849 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
850 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
851 udelay(5);
852 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700853 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 }
855 } else
856 udelay(10);
857
858 if (!cnt)
859 goto chip_diag_failed;
860
861 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -0700862 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700863
864 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
865 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
866 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
867 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
868 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
869 mb[3] != PROD_ID_3) {
870 qla_printk(KERN_WARNING, ha,
871 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
872
873 goto chip_diag_failed;
874 }
875 ha->product_id[0] = mb[1];
876 ha->product_id[1] = mb[2];
877 ha->product_id[2] = mb[3];
878 ha->product_id[3] = mb[4];
879
880 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800881 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700882 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
883 else
884 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800885 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700886
887 if (IS_QLA2200(ha) &&
888 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
889 /* Limit firmware transfer size with a 2200A */
890 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800891 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700892
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800893 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 ha->fw_transfer_size = 128;
895 }
896
897 /* Wrap Incoming Mailboxes Test. */
898 spin_unlock_irqrestore(&ha->hardware_lock, flags);
899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800900 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
901 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700902 if (rval) {
903 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800904 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 qla_printk(KERN_WARNING, ha,
906 "Failed mailbox send register test\n");
907 }
908 else {
909 /* Flag a successful rval */
910 rval = QLA_SUCCESS;
911 }
912 spin_lock_irqsave(&ha->hardware_lock, flags);
913
914chip_diag_failed:
915 if (rval)
916 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
919 spin_unlock_irqrestore(&ha->hardware_lock, flags);
920
921 return (rval);
922}
923
924/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700925 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
926 * @ha: HA context
927 *
928 * Returns 0 on success.
929 */
930int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800931qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700932{
933 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800934 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800935 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700936
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800937 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700940 if (rval) {
941 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700943 qla_printk(KERN_WARNING, ha,
944 "Failed mailbox send register test\n");
945 } else {
946 /* Flag a successful rval */
947 rval = QLA_SUCCESS;
948 }
949
950 return rval;
951}
952
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700953void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800954qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700955{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700956 int rval;
957 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800958 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800959 dma_addr_t tc_dma;
960 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800961 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800962 struct req_que *req = ha->req_q_map[0];
963 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700964
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700965 if (ha->fw_dump) {
966 qla_printk(KERN_WARNING, ha,
967 "Firmware dump previously allocated.\n");
968 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700969 }
970
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700971 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800972 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700973 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
974 fixed_size = sizeof(struct qla2100_fw_dump);
975 } else if (IS_QLA23XX(ha)) {
976 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
977 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
978 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700979 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800980 if (IS_QLA81XX(ha))
981 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
982 else if (IS_QLA25XX(ha))
983 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
984 else
985 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700986 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
987 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800988 if (ha->mqenable)
989 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700990 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800991 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700992 goto try_eft;
993
994 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
995 GFP_KERNEL);
996 if (!tc) {
997 qla_printk(KERN_WARNING, ha, "Unable to allocate "
998 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800999 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001000 }
1001
1002 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001003 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001004 ha->fce_mb, &ha->fce_bufs);
1005 if (rval) {
1006 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1007 "FCE (%d).\n", rval);
1008 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
1009 tc_dma);
1010 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001011 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001012 }
1013
1014 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
1015 FCE_SIZE / 1024);
1016
Giridhar Malavali7d9dade2009-03-24 09:07:58 -07001017 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -07001018 ha->flags.fce_enabled = 1;
1019 ha->fce_dma = tc_dma;
1020 ha->fce = tc;
1021try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001022 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001023 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001024 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001025 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001026 qla_printk(KERN_WARNING, ha, "Unable to allocate "
1027 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
1028 goto cont_alloc;
1029 }
1030
Andrew Vasquezfc447652008-01-17 09:02:18 -08001031 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001032 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001033 if (rval) {
1034 qla_printk(KERN_WARNING, ha, "Unable to initialize "
1035 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001036 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
1037 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001038 goto cont_alloc;
1039 }
1040
1041 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
1042 EFT_SIZE / 1024);
1043
1044 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001045 ha->eft_dma = tc_dma;
1046 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001047 }
1048cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001049 req_q_size = req->length * sizeof(request_t);
1050 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001051
1052 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001053 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -08001054 ha->chain_offset = dump_size;
1055 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001056
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001057 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001058 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001059 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -07001060 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001061
1062 if (ha->eft) {
1063 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
1064 ha->eft_dma);
1065 ha->eft = NULL;
1066 ha->eft_dma = 0;
1067 }
1068 return;
1069 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001070 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
1071 dump_size / 1024);
1072
1073 ha->fw_dump_len = dump_size;
1074 ha->fw_dump->signature[0] = 'Q';
1075 ha->fw_dump->signature[1] = 'L';
1076 ha->fw_dump->signature[2] = 'G';
1077 ha->fw_dump->signature[3] = 'C';
1078 ha->fw_dump->version = __constant_htonl(1);
1079
1080 ha->fw_dump->fixed_size = htonl(fixed_size);
1081 ha->fw_dump->mem_size = htonl(mem_size);
1082 ha->fw_dump->req_q_size = htonl(req_q_size);
1083 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
1084
1085 ha->fw_dump->eft_size = htonl(eft_size);
1086 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
1087 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
1088
1089 ha->fw_dump->header_size =
1090 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001091}
1092
Andrew Vasquez18e75552009-06-03 09:55:30 -07001093static int
1094qla81xx_mpi_sync(scsi_qla_host_t *vha)
1095{
1096#define MPS_MASK 0xe0
1097 int rval;
1098 uint16_t dc;
1099 uint32_t dw;
1100 struct qla_hw_data *ha = vha->hw;
1101
1102 if (!IS_QLA81XX(vha->hw))
1103 return QLA_SUCCESS;
1104
1105 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
1106 if (rval != QLA_SUCCESS) {
1107 DEBUG2(qla_printk(KERN_WARNING, ha,
1108 "Sync-MPI: Unable to acquire semaphore.\n"));
1109 goto done;
1110 }
1111
1112 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
1113 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
1114 if (rval != QLA_SUCCESS) {
1115 DEBUG2(qla_printk(KERN_WARNING, ha,
1116 "Sync-MPI: Unable to read sync.\n"));
1117 goto done_release;
1118 }
1119
1120 dc &= MPS_MASK;
1121 if (dc == (dw & MPS_MASK))
1122 goto done_release;
1123
1124 dw &= ~MPS_MASK;
1125 dw |= dc;
1126 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
1127 if (rval != QLA_SUCCESS) {
1128 DEBUG2(qla_printk(KERN_WARNING, ha,
1129 "Sync-MPI: Unable to gain sync.\n"));
1130 }
1131
1132done_release:
1133 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
1134 if (rval != QLA_SUCCESS) {
1135 DEBUG2(qla_printk(KERN_WARNING, ha,
1136 "Sync-MPI: Unable to release semaphore.\n"));
1137 }
1138
1139done:
1140 return rval;
1141}
1142
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001143/**
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144 * qla2x00_setup_chip() - Load and start RISC firmware.
1145 * @ha: HA context
1146 *
1147 * Returns 0 on success.
1148 */
1149static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001150qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001151{
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001152 int rval;
1153 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001154 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001155 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1156 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001157 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -08001158
1159 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1160 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1161 spin_lock_irqsave(&ha->hardware_lock, flags);
1162 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
1163 RD_REG_WORD(&reg->hccr);
1164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1165 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166
Andrew Vasquez18e75552009-06-03 09:55:30 -07001167 qla81xx_mpi_sync(vha);
1168
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001170 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001171 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001173 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 if (rval == QLA_SUCCESS) {
1177 /* Start firmware execution. */
1178 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001179 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001181 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001183 if (rval == QLA_SUCCESS) {
1184 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001185 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 &ha->fw_major_version,
1187 &ha->fw_minor_version,
1188 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001189 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -07001190 ha->mpi_version, &ha->mpi_capabilities,
1191 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001192 if (rval != QLA_SUCCESS)
1193 goto failed;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001194 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001195 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001196 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001197 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001198 if ((!ha->max_npiv_vports) ||
1199 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001200 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001201 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001202 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001203 }
Andrew Vasquez24a08132009-03-24 09:08:16 -07001204 qla2x00_get_resource_cnts(vha, NULL,
1205 &ha->fw_xcb_count, NULL, NULL,
1206 &ha->max_npiv_vports);
Andrew Vasquezd743de62009-03-24 09:08:15 -07001207
1208 if (!fw_major_version && ql2xallocfwdump)
1209 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210 }
1211 } else {
1212 DEBUG2(printk(KERN_INFO
1213 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001214 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 }
1216 }
1217
Andrew Vasquez3db06522008-01-31 12:33:49 -08001218 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1219 /* Enable proper parity. */
1220 spin_lock_irqsave(&ha->hardware_lock, flags);
1221 if (IS_QLA2300(ha))
1222 /* SRAM parity */
1223 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1224 else
1225 /* SRAM, Instruction RAM and GP RAM parity */
1226 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1227 RD_REG_WORD(&reg->hccr);
1228 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1229 }
1230
Joe Carnuccio1d2874d2009-03-24 09:08:06 -07001231 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
1232 uint32_t size;
1233
1234 rval = qla81xx_fac_get_sector_size(vha, &size);
1235 if (rval == QLA_SUCCESS) {
1236 ha->flags.fac_supported = 1;
1237 ha->fdt_block_size = size << 2;
1238 } else {
1239 qla_printk(KERN_ERR, ha,
1240 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1241 ha->fw_major_version, ha->fw_minor_version,
1242 ha->fw_subminor_version);
1243 }
1244 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -07001245failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246 if (rval) {
1247 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001248 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249 }
1250
1251 return (rval);
1252}
1253
1254/**
1255 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1256 * @ha: HA context
1257 *
1258 * Beginning of request ring has initialization control block already built
1259 * by nvram config routine.
1260 *
1261 * Returns 0 on success.
1262 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001263void
1264qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265{
1266 uint16_t cnt;
1267 response_t *pkt;
1268
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001269 rsp->ring_ptr = rsp->ring;
1270 rsp->ring_index = 0;
1271 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 pkt = rsp->ring_ptr;
1273 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001274 pkt->signature = RESPONSE_PROCESSED;
1275 pkt++;
1276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277}
1278
1279/**
1280 * qla2x00_update_fw_options() - Read and process firmware options.
1281 * @ha: HA context
1282 *
1283 * Returns 0 on success.
1284 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001285void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001286qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287{
1288 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001289 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001292 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001293
1294 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1295 return;
1296
1297 /* Serial Link options. */
1298 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001299 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1301 sizeof(ha->fw_seriallink_options)));
1302
1303 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1304 if (ha->fw_seriallink_options[3] & BIT_2) {
1305 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1306
1307 /* 1G settings */
1308 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1309 emphasis = (ha->fw_seriallink_options[2] &
1310 (BIT_4 | BIT_3)) >> 3;
1311 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001312 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001313 rx_sens = (ha->fw_seriallink_options[0] &
1314 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1315 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1316 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1317 if (rx_sens == 0x0)
1318 rx_sens = 0x3;
1319 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1320 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1321 ha->fw_options[10] |= BIT_5 |
1322 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1323 (tx_sens & (BIT_1 | BIT_0));
1324
1325 /* 2G settings */
1326 swing = (ha->fw_seriallink_options[2] &
1327 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1328 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1329 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001330 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 rx_sens = (ha->fw_seriallink_options[1] &
1332 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1333 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1334 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1335 if (rx_sens == 0x0)
1336 rx_sens = 0x3;
1337 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1338 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1339 ha->fw_options[11] |= BIT_5 |
1340 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1341 (tx_sens & (BIT_1 | BIT_0));
1342 }
1343
1344 /* FCP2 options. */
1345 /* Return command IOCBs without waiting for an ABTS to complete. */
1346 ha->fw_options[3] |= BIT_13;
1347
1348 /* LED scheme. */
1349 if (ha->flags.enable_led_scheme)
1350 ha->fw_options[2] |= BIT_12;
1351
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001352 /* Detect ISP6312. */
1353 if (IS_QLA6312(ha))
1354 ha->fw_options[2] |= BIT_13;
1355
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001357 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358}
1359
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001360void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001361qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001362{
1363 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001364 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001365
1366 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001367 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001368 return;
1369
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001370 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001371 le16_to_cpu(ha->fw_seriallink_options24[1]),
1372 le16_to_cpu(ha->fw_seriallink_options24[2]),
1373 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001374 if (rval != QLA_SUCCESS) {
1375 qla_printk(KERN_WARNING, ha,
1376 "Unable to update Serial Link options (%x).\n", rval);
1377 }
1378}
1379
1380void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001381qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001382{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001383 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001384 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001385 struct req_que *req = ha->req_q_map[0];
1386 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001387
1388 /* Setup ring parameters in initialization control block. */
1389 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1390 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001391 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1392 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1393 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1394 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1395 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1396 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001397
1398 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1399 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1400 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1401 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1402 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1403}
1404
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001405void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001406qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001407{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001408 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001409 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1410 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1411 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001412 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001413 uint16_t rid = 0;
1414 struct req_que *req = ha->req_q_map[0];
1415 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001416
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001417/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001418 icb = (struct init_cb_24xx *)ha->init_cb;
1419 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1420 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001421 icb->request_q_length = cpu_to_le16(req->length);
1422 icb->response_q_length = cpu_to_le16(rsp->length);
1423 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1424 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1425 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1426 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001427
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001428 if (ha->mqenable) {
1429 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1430 icb->rid = __constant_cpu_to_le16(rid);
1431 if (ha->flags.msix_enabled) {
1432 msix = &ha->msix_entries[1];
1433 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001434 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001435 icb->msix = cpu_to_le16(msix->entry);
1436 }
1437 /* Use alternate PCI bus number */
1438 if (MSB(rid))
1439 icb->firmware_options_2 |=
1440 __constant_cpu_to_le32(BIT_19);
1441 /* Use alternate PCI devfn */
1442 if (LSB(rid))
1443 icb->firmware_options_2 |=
1444 __constant_cpu_to_le32(BIT_18);
1445
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001446 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001447 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001448
1449 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1450 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1451 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1452 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1453 } else {
1454 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1455 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1456 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1457 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1458 }
1459 /* PCI posting */
1460 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001461}
1462
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463/**
1464 * qla2x00_init_rings() - Initializes firmware.
1465 * @ha: HA context
1466 *
1467 * Beginning of request ring has initialization control block already built
1468 * by nvram config routine.
1469 *
1470 * Returns 0 on success.
1471 */
1472static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001473qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474{
1475 int rval;
1476 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001477 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001479 struct req_que *req;
1480 struct rsp_que *rsp;
1481 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001482 struct mid_init_cb_24xx *mid_init_cb =
1483 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 spin_lock_irqsave(&ha->hardware_lock, flags);
1486
1487 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001488 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001489 req = ha->req_q_map[que];
1490 if (!req)
1491 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001492 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001493 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001495 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001496
1497 /* Initialize firmware. */
1498 req->ring_ptr = req->ring;
1499 req->ring_index = 0;
1500 req->cnt = req->length;
1501 }
1502
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001503 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001504 rsp = ha->rsp_q_map[que];
1505 if (!rsp)
1506 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001507 /* Initialize response queue entries */
1508 qla2x00_init_response_q_entries(rsp);
1509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510
1511 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001512 list_for_each_entry(vp, &ha->vp_list, list) {
1513 vp->rscn_in_ptr = 0;
1514 vp->rscn_out_ptr = 0;
1515 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
1518 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1519
1520 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001521 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001524
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001525 if (ha->flags.npiv_supported) {
1526 if (ha->operating_mode == LOOP)
1527 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001528 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001529 }
1530
Andrew Vasquez24a08132009-03-24 09:08:16 -07001531 if (IS_FWI2_CAPABLE(ha)) {
1532 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1533 mid_init_cb->init_cb.execution_throttle =
1534 cpu_to_le16(ha->fw_xcb_count);
1535 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001537 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 if (rval) {
1539 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001540 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 } else {
1542 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001543 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 }
1545
1546 return (rval);
1547}
1548
1549/**
1550 * qla2x00_fw_ready() - Waits for firmware ready.
1551 * @ha: HA context
1552 *
1553 * Returns 0 on success.
1554 */
1555static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001556qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557{
1558 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001559 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 uint16_t min_wait; /* Minimum wait time if loop is down */
1561 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001562 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001563 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
1565 rval = QLA_SUCCESS;
1566
1567 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001568 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001569
1570 /*
1571 * Firmware should take at most one RATOV to login, plus 5 seconds for
1572 * our own processing.
1573 */
1574 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1575 wait_time = min_wait;
1576 }
1577
1578 /* Min wait time if loop down */
1579 mtime = jiffies + (min_wait * HZ);
1580
1581 /* wait time before firmware ready */
1582 wtime = jiffies + (wait_time * HZ);
1583
1584 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001586 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1587
1588 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001589 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590
1591 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001592 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001594 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001595 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001596 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001597 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1598 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001599 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001600 state[2]));
1601 if ((state[2] & FSTATE_LOGGED_IN) &&
1602 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1603 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001604 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001605
1606 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001607 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001608 if (rval != QLA_SUCCESS)
1609 break;
1610
1611 /* Add time taken to initialize. */
1612 cs84xx_time = jiffies - cs84xx_time;
1613 wtime += cs84xx_time;
1614 mtime += cs84xx_time;
1615 DEBUG16(printk("scsi(%ld): Increasing "
1616 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001617 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001618 }
1619 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001621 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001622
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001623 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 &ha->login_timeout, &ha->r_a_tov);
1625
1626 rval = QLA_SUCCESS;
1627 break;
1628 }
1629
1630 rval = QLA_FUNCTION_FAILED;
1631
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001632 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001633 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001635 * other than Wait for Login.
1636 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 if (time_after_eq(jiffies, mtime)) {
1638 qla_printk(KERN_INFO, ha,
1639 "Cable is unplugged...\n");
1640
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001641 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001642 break;
1643 }
1644 }
1645 } else {
1646 /* Mailbox cmd failed. Timeout on min_wait. */
1647 if (time_after_eq(jiffies, mtime))
1648 break;
1649 }
1650
1651 if (time_after_eq(jiffies, wtime))
1652 break;
1653
1654 /* Delay for a while */
1655 msleep(500);
1656
1657 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001658 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 } while (1);
1660
Andrew Vasquez656e8912009-06-03 09:55:29 -07001661 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1662 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1663 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
1665 if (rval) {
1666 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001667 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001668 }
1669
1670 return (rval);
1671}
1672
1673/*
1674* qla2x00_configure_hba
1675* Setup adapter context.
1676*
1677* Input:
1678* ha = adapter state pointer.
1679*
1680* Returns:
1681* 0 = success
1682*
1683* Context:
1684* Kernel context.
1685*/
1686static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001687qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688{
1689 int rval;
1690 uint16_t loop_id;
1691 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001692 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 uint8_t al_pa;
1694 uint8_t area;
1695 uint8_t domain;
1696 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001697 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698
1699 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001700 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001701 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001703 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001704 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1705 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001707 } else {
1708 qla_printk(KERN_WARNING, ha,
1709 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001710 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001711 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 return (rval);
1713 }
1714
1715 if (topo == 4) {
1716 qla_printk(KERN_INFO, ha,
1717 "Cannot get topology - retrying.\n");
1718 return (QLA_FUNCTION_FAILED);
1719 }
1720
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001721 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001722
1723 /* initialize */
1724 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1725 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001726 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001727
1728 switch (topo) {
1729 case 0:
1730 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001731 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732 ha->current_topology = ISP_CFG_NL;
1733 strcpy(connect_type, "(Loop)");
1734 break;
1735
1736 case 1:
1737 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001738 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001739 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 ha->current_topology = ISP_CFG_FL;
1741 strcpy(connect_type, "(FL_Port)");
1742 break;
1743
1744 case 2:
1745 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001746 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001747 ha->operating_mode = P2P;
1748 ha->current_topology = ISP_CFG_N;
1749 strcpy(connect_type, "(N_Port-to-N_Port)");
1750 break;
1751
1752 case 3:
1753 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001754 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001755 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001756 ha->operating_mode = P2P;
1757 ha->current_topology = ISP_CFG_F;
1758 strcpy(connect_type, "(F_Port)");
1759 break;
1760
1761 default:
1762 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1763 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001764 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765 ha->current_topology = ISP_CFG_NL;
1766 strcpy(connect_type, "(Loop)");
1767 break;
1768 }
1769
1770 /* Save Host port and loop ID. */
1771 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772 vha->d_id.b.domain = domain;
1773 vha->d_id.b.area = area;
1774 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001776 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 qla_printk(KERN_INFO, ha,
1778 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001779 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001780
1781 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001782 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001784 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 }
1786
1787 return(rval);
1788}
1789
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001790static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001791qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1792 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001793{
1794 char *st, *en;
1795 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001796 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1b91a2e2009-06-03 09:55:15 -07001797 int use_tbl = !IS_QLA25XX(ha) && !IS_QLA81XX(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001798
1799 if (memcmp(model, BINZERO, len) != 0) {
1800 strncpy(ha->model_number, model, len);
1801 st = en = ha->model_number;
1802 en += len - 1;
1803 while (en > st) {
1804 if (*en != 0x20 && *en != 0x00)
1805 break;
1806 *en-- = '\0';
1807 }
1808
1809 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001810 if (use_tbl &&
1811 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001812 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001813 strncpy(ha->model_desc,
1814 qla2x00_model_name[index * 2 + 1],
1815 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001816 } else {
1817 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001818 if (use_tbl &&
1819 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001820 index < QLA_MODEL_NAMES) {
1821 strcpy(ha->model_number,
1822 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001823 strncpy(ha->model_desc,
1824 qla2x00_model_name[index * 2 + 1],
1825 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001826 } else {
1827 strcpy(ha->model_number, def);
1828 }
1829 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001830 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001831 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001832 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001833}
1834
David Miller4e08df32007-04-16 12:37:43 -07001835/* On sparc systems, obtain port and node WWN from firmware
1836 * properties.
1837 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001838static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001839{
1840#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001841 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001842 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001843 struct device_node *dp = pci_device_to_OF_node(pdev);
1844 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001845 int len;
1846
1847 val = of_get_property(dp, "port-wwn", &len);
1848 if (val && len >= WWN_SIZE)
1849 memcpy(nv->port_name, val, WWN_SIZE);
1850
1851 val = of_get_property(dp, "node-wwn", &len);
1852 if (val && len >= WWN_SIZE)
1853 memcpy(nv->node_name, val, WWN_SIZE);
1854#endif
1855}
1856
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857/*
1858* NVRAM configuration for ISP 2xxx
1859*
1860* Input:
1861* ha = adapter block pointer.
1862*
1863* Output:
1864* initialization control block in response_ring
1865* host adapters parameters in host adapter block
1866*
1867* Returns:
1868* 0 = success.
1869*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001870int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001871qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872{
David Miller4e08df32007-04-16 12:37:43 -07001873 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001874 uint8_t chksum = 0;
1875 uint16_t cnt;
1876 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001877 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001878 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001879 nvram_t *nv = ha->nvram;
1880 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001881 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882
David Miller4e08df32007-04-16 12:37:43 -07001883 rval = QLA_SUCCESS;
1884
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001886 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 ha->nvram_base = 0;
1888 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1889 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1890 ha->nvram_base = 0x80;
1891
1892 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001893 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001894 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1895 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001897 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001898 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
1900 /* Bad NVRAM data, set defaults parameters. */
1901 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1902 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1903 /* Reset NVRAM data. */
1904 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1905 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1906 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001907 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1908 "invalid -- WWPN) defaults.\n");
1909
1910 /*
1911 * Set default initialization control block.
1912 */
1913 memset(nv, 0, ha->nvram_size);
1914 nv->parameter_block_version = ICB_VERSION;
1915
1916 if (IS_QLA23XX(ha)) {
1917 nv->firmware_options[0] = BIT_2 | BIT_1;
1918 nv->firmware_options[1] = BIT_7 | BIT_5;
1919 nv->add_firmware_options[0] = BIT_5;
1920 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1921 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1922 nv->special_options[1] = BIT_7;
1923 } else if (IS_QLA2200(ha)) {
1924 nv->firmware_options[0] = BIT_2 | BIT_1;
1925 nv->firmware_options[1] = BIT_7 | BIT_5;
1926 nv->add_firmware_options[0] = BIT_5;
1927 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1928 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1929 } else if (IS_QLA2100(ha)) {
1930 nv->firmware_options[0] = BIT_3 | BIT_1;
1931 nv->firmware_options[1] = BIT_5;
1932 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1933 }
1934
1935 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1936 nv->execution_throttle = __constant_cpu_to_le16(16);
1937 nv->retry_count = 8;
1938 nv->retry_delay = 1;
1939
1940 nv->port_name[0] = 33;
1941 nv->port_name[3] = 224;
1942 nv->port_name[4] = 139;
1943
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001944 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001945
1946 nv->login_timeout = 4;
1947
1948 /*
1949 * Set default host adapter parameters
1950 */
1951 nv->host_p[1] = BIT_2;
1952 nv->reset_delay = 5;
1953 nv->port_down_retry_count = 8;
1954 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1955 nv->link_down_timeout = 60;
1956
1957 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 }
1959
1960#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1961 /*
1962 * The SN2 does not provide BIOS emulation which means you can't change
1963 * potentially bogus BIOS settings. Force the use of default settings
1964 * for link rate and frame size. Hope that the rest of the settings
1965 * are valid.
1966 */
1967 if (ia64_platform_is("sn2")) {
1968 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1969 if (IS_QLA23XX(ha))
1970 nv->special_options[1] = BIT_7;
1971 }
1972#endif
1973
1974 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001975 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
1977 /*
1978 * Setup driver NVRAM options.
1979 */
1980 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1981 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1982 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1983 nv->firmware_options[1] &= ~BIT_4;
1984
1985 if (IS_QLA23XX(ha)) {
1986 nv->firmware_options[0] |= BIT_2;
1987 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001988 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
1990 if (IS_QLA2300(ha)) {
1991 if (ha->fb_rev == FPM_2310) {
1992 strcpy(ha->model_number, "QLA2310");
1993 } else {
1994 strcpy(ha->model_number, "QLA2300");
1995 }
1996 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001997 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001998 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 }
2000 } else if (IS_QLA2200(ha)) {
2001 nv->firmware_options[0] |= BIT_2;
2002 /*
2003 * 'Point-to-point preferred, else loop' is not a safe
2004 * connection mode setting.
2005 */
2006 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2007 (BIT_5 | BIT_4)) {
2008 /* Force 'loop preferred, else point-to-point'. */
2009 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2010 nv->add_firmware_options[0] |= BIT_5;
2011 }
2012 strcpy(ha->model_number, "QLA22xx");
2013 } else /*if (IS_QLA2100(ha))*/ {
2014 strcpy(ha->model_number, "QLA2100");
2015 }
2016
2017 /*
2018 * Copy over NVRAM RISC parameter block to initialization control block.
2019 */
2020 dptr1 = (uint8_t *)icb;
2021 dptr2 = (uint8_t *)&nv->parameter_block_version;
2022 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2023 while (cnt--)
2024 *dptr1++ = *dptr2++;
2025
2026 /* Copy 2nd half. */
2027 dptr1 = (uint8_t *)icb->add_firmware_options;
2028 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2029 while (cnt--)
2030 *dptr1++ = *dptr2++;
2031
Andrew Vasquez5341e862006-05-17 15:09:16 -07002032 /* Use alternate WWN? */
2033 if (nv->host_p[1] & BIT_7) {
2034 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2035 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2036 }
2037
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 /* Prepare nodename */
2039 if ((icb->firmware_options[1] & BIT_6) == 0) {
2040 /*
2041 * Firmware will apply the following mask if the nodename was
2042 * not provided.
2043 */
2044 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2045 icb->node_name[0] &= 0xF0;
2046 }
2047
2048 /*
2049 * Set host adapter parameters.
2050 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002051 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002052 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2054 /* Always load RISC code on non ISP2[12]00 chips. */
2055 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2056 ha->flags.disable_risc_code_load = 0;
2057 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2058 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2059 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002060 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002061 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
2063 ha->operating_mode =
2064 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2065
2066 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2067 sizeof(ha->fw_seriallink_options));
2068
2069 /* save HBA serial number */
2070 ha->serial0 = icb->port_name[5];
2071 ha->serial1 = icb->port_name[6];
2072 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002073 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2074 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
2076 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2077
2078 ha->retry_count = nv->retry_count;
2079
2080 /* Set minimum login_timeout to 4 seconds. */
2081 if (nv->login_timeout < ql2xlogintimeout)
2082 nv->login_timeout = ql2xlogintimeout;
2083 if (nv->login_timeout < 4)
2084 nv->login_timeout = 4;
2085 ha->login_timeout = nv->login_timeout;
2086 icb->login_timeout = nv->login_timeout;
2087
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002088 /* Set minimum RATOV to 100 tenths of a second. */
2089 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 ha->loop_reset_delay = nv->reset_delay;
2092
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093 /* Link Down Timeout = 0:
2094 *
2095 * When Port Down timer expires we will start returning
2096 * I/O's to OS with "DID_NO_CONNECT".
2097 *
2098 * Link Down Timeout != 0:
2099 *
2100 * The driver waits for the link to come up after link down
2101 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002102 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002103 if (nv->link_down_timeout == 0) {
2104 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002105 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002106 } else {
2107 ha->link_down_timeout = nv->link_down_timeout;
2108 ha->loop_down_abort_time =
2109 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002110 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112 /*
2113 * Need enough time to try and get the port back.
2114 */
2115 ha->port_down_retry_count = nv->port_down_retry_count;
2116 if (qlport_down_retry)
2117 ha->port_down_retry_count = qlport_down_retry;
2118 /* Set login_retry_count */
2119 ha->login_retry_count = nv->retry_count;
2120 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2121 ha->port_down_retry_count > 3)
2122 ha->login_retry_count = ha->port_down_retry_count;
2123 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2124 ha->login_retry_count = ha->port_down_retry_count;
2125 if (ql2xloginretrycount)
2126 ha->login_retry_count = ql2xloginretrycount;
2127
Linus Torvalds1da177e2005-04-16 15:20:36 -07002128 icb->lun_enables = __constant_cpu_to_le16(0);
2129 icb->command_resource_count = 0;
2130 icb->immediate_notify_resource_count = 0;
2131 icb->timeout = __constant_cpu_to_le16(0);
2132
2133 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2134 /* Enable RIO */
2135 icb->firmware_options[0] &= ~BIT_3;
2136 icb->add_firmware_options[0] &=
2137 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2138 icb->add_firmware_options[0] |= BIT_2;
2139 icb->response_accumulation_timer = 3;
2140 icb->interrupt_delay_timer = 5;
2141
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002142 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002144 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002145 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002146 ha->zio_mode = icb->add_firmware_options[0] &
2147 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2148 ha->zio_timer = icb->interrupt_delay_timer ?
2149 icb->interrupt_delay_timer: 2;
2150 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 icb->add_firmware_options[0] &=
2152 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002153 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002154 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002155 ha->zio_mode = QLA_ZIO_MODE_6;
2156
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002157 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002159 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002161 "ZIO mode %d enabled; timer delay (%d us).\n",
2162 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002164 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2165 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167 }
2168 }
2169
David Miller4e08df32007-04-16 12:37:43 -07002170 if (rval) {
2171 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002172 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002173 }
2174 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175}
2176
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002177static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002178qla2x00_rport_del(void *data)
2179{
2180 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002181 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002182
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002183 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002184 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002185 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002186 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002187 if (rport)
2188 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002189}
2190
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191/**
2192 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2193 * @ha: HA context
2194 * @flags: allocation flags
2195 *
2196 * Returns a pointer to the allocated fcport, or NULL, if none available.
2197 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002198static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200{
2201 fc_port_t *fcport;
2202
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002203 fcport = kzalloc(sizeof(fc_port_t), flags);
2204 if (!fcport)
2205 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206
2207 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 fcport->vha = vha;
2209 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210 fcport->port_type = FCT_UNKNOWN;
2211 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002213 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002214
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002215 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216}
2217
2218/*
2219 * qla2x00_configure_loop
2220 * Updates Fibre Channel Device Database with what is actually on loop.
2221 *
2222 * Input:
2223 * ha = adapter block pointer.
2224 *
2225 * Returns:
2226 * 0 = success.
2227 * 1 = error.
2228 * 2 = database was full and device was not configured.
2229 */
2230static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002231qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002232{
2233 int rval;
2234 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002235 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 rval = QLA_SUCCESS;
2237
2238 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002239 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2240 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241 if (rval != QLA_SUCCESS) {
2242 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002244 return (rval);
2245 }
2246 }
2247
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002248 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002249 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251
2252 /*
2253 * If we have both an RSCN and PORT UPDATE pending then handle them
2254 * both at the same time.
2255 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002256 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2257 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258
2259 /* Determine what we need to do */
2260 if (ha->current_topology == ISP_CFG_FL &&
2261 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2262
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002264 set_bit(RSCN_UPDATE, &flags);
2265
2266 } else if (ha->current_topology == ISP_CFG_F &&
2267 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2268
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002269 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002270 set_bit(RSCN_UPDATE, &flags);
2271 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2272
Andrew Vasquez21333b42006-05-17 15:09:56 -07002273 } else if (ha->current_topology == ISP_CFG_N) {
2274 clear_bit(RSCN_UPDATE, &flags);
2275
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2278
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002279 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280 set_bit(RSCN_UPDATE, &flags);
2281 set_bit(LOCAL_LOOP_UPDATE, &flags);
2282 }
2283
2284 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002285 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002286 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002287 else
2288 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289 }
2290
2291 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002293 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002294 else
2295 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002296 }
2297
2298 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002299 if (atomic_read(&vha->loop_down_timer) ||
2300 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002301 rval = QLA_FUNCTION_FAILED;
2302 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002305 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 }
2307 }
2308
2309 if (rval) {
2310 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002312 } else {
2313 DEBUG3(printk("%s: exiting normally\n", __func__));
2314 }
2315
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002316 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002317 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002318 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002320 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002322 vha->flags.rscn_queue_overflow = 1;
2323 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002324 }
2325
2326 return (rval);
2327}
2328
2329
2330
2331/*
2332 * qla2x00_configure_local_loop
2333 * Updates Fibre Channel Device Database with local loop devices.
2334 *
2335 * Input:
2336 * ha = adapter block pointer.
2337 *
2338 * Returns:
2339 * 0 = success.
2340 */
2341static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343{
2344 int rval, rval2;
2345 int found_devs;
2346 int found;
2347 fc_port_t *fcport, *new_fcport;
2348
2349 uint16_t index;
2350 uint16_t entries;
2351 char *id_iter;
2352 uint16_t loop_id;
2353 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356 found_devs = 0;
2357 new_fcport = NULL;
2358 entries = MAX_FIBRE_DEVICES;
2359
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002360 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2361 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
2363 /* Get list of logged in devices. */
2364 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002365 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 &entries);
2367 if (rval != QLA_SUCCESS)
2368 goto cleanup_allocation;
2369
2370 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002371 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2373 entries * sizeof(struct gid_list_info)));
2374
2375 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002377 if (new_fcport == NULL) {
2378 rval = QLA_MEMORY_ALLOC_FAILED;
2379 goto cleanup_allocation;
2380 }
2381 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2382
2383 /*
2384 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2385 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2388 fcport->port_type != FCT_BROADCAST &&
2389 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2390
2391 DEBUG(printk("scsi(%ld): Marking port lost, "
2392 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
2395 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396 }
2397 }
2398
2399 /* Add devices to port list. */
2400 id_iter = (char *)ha->gid_list;
2401 for (index = 0; index < entries; index++) {
2402 domain = ((struct gid_list_info *)id_iter)->domain;
2403 area = ((struct gid_list_info *)id_iter)->area;
2404 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002405 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406 loop_id = (uint16_t)
2407 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002408 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 loop_id = le16_to_cpu(
2410 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002411 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
2413 /* Bypass reserved domain fields. */
2414 if ((domain & 0xf0) == 0xf0)
2415 continue;
2416
2417 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002418 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002419 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 continue;
2421
2422 /* Bypass invalid local loop ID. */
2423 if (loop_id > LAST_LOCAL_LOOP_ID)
2424 continue;
2425
2426 /* Fill in member data. */
2427 new_fcport->d_id.b.domain = domain;
2428 new_fcport->d_id.b.area = area;
2429 new_fcport->d_id.b.al_pa = al_pa;
2430 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002431 new_fcport->vp_idx = vha->vp_idx;
2432 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002433 if (rval2 != QLA_SUCCESS) {
2434 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2435 "information -- get_port_database=%x, "
2436 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002438 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002439 vha->host_no));
2440 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 continue;
2442 }
2443
2444 /* Check for matching device in port list. */
2445 found = 0;
2446 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 if (memcmp(new_fcport->port_name, fcport->port_name,
2449 WWN_SIZE))
2450 continue;
2451
Shyam Sundarddb9b122009-03-24 09:08:10 -07002452 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 fcport->loop_id = new_fcport->loop_id;
2454 fcport->port_type = new_fcport->port_type;
2455 fcport->d_id.b24 = new_fcport->d_id.b24;
2456 memcpy(fcport->node_name, new_fcport->node_name,
2457 WWN_SIZE);
2458
2459 found++;
2460 break;
2461 }
2462
2463 if (!found) {
2464 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 if (vha->vp_idx) {
2466 new_fcport->vha = vha;
2467 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002468 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470
2471 /* Allocate a new replacement fcport. */
2472 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 if (new_fcport == NULL) {
2475 rval = QLA_MEMORY_ALLOC_FAILED;
2476 goto cleanup_allocation;
2477 }
2478 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2479 }
2480
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002481 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002482 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485
2486 found_devs++;
2487 }
2488
2489cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002490 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491
2492 if (rval != QLA_SUCCESS) {
2493 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002494 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 }
2496
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 return (rval);
2498}
2499
2500static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002501qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002502{
2503#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002504 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2505 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002506 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002507 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002509
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002510 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002511 return;
2512
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002513 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2514 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002515 return;
2516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002518 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002519 if (rval != QLA_SUCCESS) {
2520 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2521 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002522 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002523 fcport->port_name[2], fcport->port_name[3],
2524 fcport->port_name[4], fcport->port_name[5],
2525 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002526 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002527 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002528 link_speed = link_speeds[LS_UNKNOWN];
2529 if (fcport->fp_speed < 5)
2530 link_speed = link_speeds[fcport->fp_speed];
2531 else if (fcport->fp_speed == 0x13)
2532 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002533 DEBUG2(qla_printk(KERN_INFO, ha,
2534 "iIDMA adjusted to %s GB/s on "
2535 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002536 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002537 fcport->port_name[1], fcport->port_name[2],
2538 fcport->port_name[3], fcport->port_name[4],
2539 fcport->port_name[5], fcport->port_name[6],
2540 fcport->port_name[7]));
2541 }
2542}
2543
Adrian Bunk23be3312006-11-24 02:46:01 +01002544static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002545qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002546{
2547 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002548 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002549 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002550
Andrew Vasquezac280b62009-08-20 11:06:05 -07002551 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002552
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002553 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2554 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002555 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2556 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2557 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002558 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002559 if (!rport) {
2560 qla_printk(KERN_WARNING, ha,
2561 "Unable to allocate fc remote port!\n");
2562 return;
2563 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002564 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002565 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002566 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002567
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002568 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002569
2570 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002571 if (fcport->port_type == FCT_INITIATOR)
2572 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2573 if (fcport->port_type == FCT_TARGET)
2574 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002575 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002576}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577
2578/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002579 * qla2x00_update_fcport
2580 * Updates device on list.
2581 *
2582 * Input:
2583 * ha = adapter block pointer.
2584 * fcport = port structure pointer.
2585 *
2586 * Return:
2587 * 0 - Success
2588 * BIT_0 - error
2589 *
2590 * Context:
2591 * Kernel context.
2592 */
2593void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002594qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002595{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002597
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002599 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002601 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002602 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002603 PORT_RETRY_TIME);
2604 fcport->flags &= ~FCF_LOGIN_NEEDED;
2605
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002607
2608 atomic_set(&fcport->state, FCS_ONLINE);
2609
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002611}
2612
2613/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 * qla2x00_configure_fabric
2615 * Setup SNS devices with loop ID's.
2616 *
2617 * Input:
2618 * ha = adapter block pointer.
2619 *
2620 * Returns:
2621 * 0 = success.
2622 * BIT_0 = error
2623 */
2624static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002625qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002626{
2627 int rval, rval2;
2628 fc_port_t *fcport, *fcptemp;
2629 uint16_t next_loopid;
2630 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002631 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 struct qla_hw_data *ha = vha->hw;
2634 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
2636 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002637 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002638 loop_id = NPH_F_PORT;
2639 else
2640 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 if (rval != QLA_SUCCESS) {
2643 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002644 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002646 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 return (QLA_SUCCESS);
2648 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002649 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 if (rval2 == QLA_RSCNS_HANDLED) {
2654 /* No point doing the scan, just continue. */
2655 return (QLA_SUCCESS);
2656 }
2657 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002658 /* FDMI support. */
2659 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002660 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2661 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002662
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002664 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002665 loop_id = NPH_SNS;
2666 else
2667 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002668 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002669 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002670 if (mb[0] != MBS_COMMAND_COMPLETE) {
2671 DEBUG2(qla_printk(KERN_INFO, ha,
2672 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002673 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 mb[0], mb[1], mb[2], mb[6], mb[7]));
2675 return (QLA_SUCCESS);
2676 }
2677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002678 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2679 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 /* EMPTY */
2681 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 /* EMPTY */
2686 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002690 /* EMPTY */
2691 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 "failed.\n", vha->host_no));
2693 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 /* EMPTY */
2695 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002696 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002697 }
2698 }
2699
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 if (rval != QLA_SUCCESS)
2702 break;
2703
2704 /*
2705 * Logout all previous fabric devices marked lost, except
2706 * tape devices.
2707 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2709 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710 break;
2711
2712 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2713 continue;
2714
2715 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002717 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 if (fcport->loop_id != FC_NO_LOOP_ID &&
2719 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2720 fcport->port_type != FCT_INITIATOR &&
2721 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002722 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002723 fcport->loop_id,
2724 fcport->d_id.b.domain,
2725 fcport->d_id.b.area,
2726 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002727 fcport->loop_id = FC_NO_LOOP_ID;
2728 }
2729 }
2730 }
2731
2732 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002733 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734
2735 /*
2736 * Scan through our port list and login entries that need to be
2737 * logged in.
2738 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2740 if (atomic_read(&vha->loop_down_timer) ||
2741 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742 break;
2743
2744 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2745 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2746 continue;
2747
2748 if (fcport->loop_id == FC_NO_LOOP_ID) {
2749 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002750 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 if (rval != QLA_SUCCESS) {
2753 /* Ran out of IDs to use */
2754 break;
2755 }
2756 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002758 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002759 }
2760
2761 /* Exit if out of loop IDs. */
2762 if (rval != QLA_SUCCESS) {
2763 break;
2764 }
2765
2766 /*
2767 * Login and add the new devices to our port list.
2768 */
2769 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002770 if (atomic_read(&vha->loop_down_timer) ||
2771 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 break;
2773
2774 /* Find a new loop ID to use. */
2775 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 if (rval != QLA_SUCCESS) {
2778 /* Ran out of IDs to use */
2779 break;
2780 }
2781
bdf79622005-04-17 15:06:53 -05002782 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002784
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002785 if (vha->vp_idx) {
2786 fcport->vha = vha;
2787 fcport->vp_idx = vha->vp_idx;
2788 }
2789 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 }
2791 } while (0);
2792
2793 /* Free all new device structures not processed. */
2794 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2795 list_del(&fcport->list);
2796 kfree(fcport);
2797 }
2798
2799 if (rval) {
2800 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002801 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 }
2803
2804 return (rval);
2805}
2806
2807
2808/*
2809 * qla2x00_find_all_fabric_devs
2810 *
2811 * Input:
2812 * ha = adapter block pointer.
2813 * dev = database device entry pointer.
2814 *
2815 * Returns:
2816 * 0 = success.
2817 *
2818 * Context:
2819 * Kernel context.
2820 */
2821static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2823 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824{
2825 int rval;
2826 uint16_t loop_id;
2827 fc_port_t *fcport, *new_fcport, *fcptemp;
2828 int found;
2829
2830 sw_info_t *swl;
2831 int swl_idx;
2832 int first_dev, last_dev;
2833 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834 struct qla_hw_data *ha = vha->hw;
2835 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002836 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837
2838 rval = QLA_SUCCESS;
2839
2840 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002841 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002842 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002843 /*EMPTY*/
2844 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002845 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 kfree(swl);
2849 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 kfree(swl);
2852 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002853 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 kfree(swl);
2855 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002856 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2858 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 }
2860 }
2861 swl_idx = 0;
2862
2863 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002864 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002866 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 return (QLA_MEMORY_ALLOC_FAILED);
2868 }
2869 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 /* Set start port ID scan at adapter ID. */
2871 first_dev = 1;
2872 last_dev = 0;
2873
2874 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 loop_id = ha->min_external_loopid;
2876 for (; loop_id <= ha->max_loop_id; loop_id++) {
2877 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878 continue;
2879
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 break;
2882
2883 if (swl != NULL) {
2884 if (last_dev) {
2885 wrap.b24 = new_fcport->d_id.b24;
2886 } else {
2887 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2888 memcpy(new_fcport->node_name,
2889 swl[swl_idx].node_name, WWN_SIZE);
2890 memcpy(new_fcport->port_name,
2891 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002892 memcpy(new_fcport->fabric_port_name,
2893 swl[swl_idx].fabric_port_name, WWN_SIZE);
2894 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
2896 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2897 last_dev = 1;
2898 }
2899 swl_idx++;
2900 }
2901 } else {
2902 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 if (rval != QLA_SUCCESS) {
2905 qla_printk(KERN_WARNING, ha,
2906 "SNS scan failed -- assuming zero-entry "
2907 "result...\n");
2908 list_for_each_entry_safe(fcport, fcptemp,
2909 new_fcports, list) {
2910 list_del(&fcport->list);
2911 kfree(fcport);
2912 }
2913 rval = QLA_SUCCESS;
2914 break;
2915 }
2916 }
2917
2918 /* If wrap on switch device list, exit. */
2919 if (first_dev) {
2920 wrap.b24 = new_fcport->d_id.b24;
2921 first_dev = 0;
2922 } else if (new_fcport->d_id.b24 == wrap.b24) {
2923 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002924 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2926 break;
2927 }
2928
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002929 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 continue;
2932
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002933 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 found = 0;
2935 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002936 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2938 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002939 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002940 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002941 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002943 continue;
2944 }
2945
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002946 /* Bypass if same domain and area of adapter. */
2947 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002949 ISP_CFG_FL)
2950 continue;
2951
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 /* Bypass reserved domain fields. */
2953 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2954 continue;
2955
2956 /* Locate matching device in database. */
2957 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002958 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002959 if (memcmp(new_fcport->port_name, fcport->port_name,
2960 WWN_SIZE))
2961 continue;
2962
2963 found++;
2964
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002965 /* Update port state. */
2966 memcpy(fcport->fabric_port_name,
2967 new_fcport->fabric_port_name, WWN_SIZE);
2968 fcport->fp_speed = new_fcport->fp_speed;
2969
Linus Torvalds1da177e2005-04-16 15:20:36 -07002970 /*
2971 * If address the same and state FCS_ONLINE, nothing
2972 * changed.
2973 */
2974 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2975 atomic_read(&fcport->state) == FCS_ONLINE) {
2976 break;
2977 }
2978
2979 /*
2980 * If device was not a fabric device before.
2981 */
2982 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2983 fcport->d_id.b24 = new_fcport->d_id.b24;
2984 fcport->loop_id = FC_NO_LOOP_ID;
2985 fcport->flags |= (FCF_FABRIC_DEVICE |
2986 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 break;
2988 }
2989
2990 /*
2991 * Port ID changed or device was marked to be updated;
2992 * Log it out if still logged in and mark it for
2993 * relogin later.
2994 */
2995 fcport->d_id.b24 = new_fcport->d_id.b24;
2996 fcport->flags |= FCF_LOGIN_NEEDED;
2997 if (fcport->loop_id != FC_NO_LOOP_ID &&
2998 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2999 fcport->port_type != FCT_INITIATOR &&
3000 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003002 fcport->d_id.b.domain, fcport->d_id.b.area,
3003 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 fcport->loop_id = FC_NO_LOOP_ID;
3005 }
3006
3007 break;
3008 }
3009
3010 if (found)
3011 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003012 /* If device was not in our fcports list, then add it. */
3013 list_add_tail(&new_fcport->list, new_fcports);
3014
3015 /* Allocate a new replacement fcport. */
3016 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003017 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003018 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003019 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 return (QLA_MEMORY_ALLOC_FAILED);
3021 }
3022 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3023 new_fcport->d_id.b24 = nxt_d_id.b24;
3024 }
3025
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003026 kfree(swl);
3027 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 return (rval);
3030}
3031
3032/*
3033 * qla2x00_find_new_loop_id
3034 * Scan through our port list and find a new usable loop ID.
3035 *
3036 * Input:
3037 * ha: adapter state pointer.
3038 * dev: port structure pointer.
3039 *
3040 * Returns:
3041 * qla2x00 local function return status code.
3042 *
3043 * Context:
3044 * Kernel context.
3045 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003046static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048{
3049 int rval;
3050 int found;
3051 fc_port_t *fcport;
3052 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 struct qla_hw_data *ha = vha->hw;
3054 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003055 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003056
3057 rval = QLA_SUCCESS;
3058
3059 /* Save starting loop ID. */
3060 first_loop_id = dev->loop_id;
3061
3062 for (;;) {
3063 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003064 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003065 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
3067 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003068 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070
3071 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003072 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 /* first loop ID. */
3074 dev->loop_id = ha->min_external_loopid;
3075 }
3076
3077 /* Check for loop ID being already in use. */
3078 found = 0;
3079 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003080 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003081 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3082 if (fcport->loop_id == dev->loop_id &&
3083 fcport != dev) {
3084 /* ID possibly in use */
3085 found++;
3086 break;
3087 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003089 if (found)
3090 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003091 }
3092
3093 /* If not in use then it is free to use. */
3094 if (!found) {
3095 break;
3096 }
3097
3098 /* ID in use. Try next value. */
3099 dev->loop_id++;
3100
3101 /* If wrap around. No free ID to use. */
3102 if (dev->loop_id == first_loop_id) {
3103 dev->loop_id = FC_NO_LOOP_ID;
3104 rval = QLA_FUNCTION_FAILED;
3105 break;
3106 }
3107 }
3108
3109 return (rval);
3110}
3111
3112/*
3113 * qla2x00_device_resync
3114 * Marks devices in the database that needs resynchronization.
3115 *
3116 * Input:
3117 * ha = adapter block pointer.
3118 *
3119 * Context:
3120 * Kernel context.
3121 */
3122static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003123qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003124{
3125 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 uint32_t mask;
3127 fc_port_t *fcport;
3128 uint32_t rscn_entry;
3129 uint8_t rscn_out_iter;
3130 uint8_t format;
3131 port_id_t d_id;
3132
3133 rval = QLA_RSCNS_HANDLED;
3134
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3136 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 format = MSB(MSW(rscn_entry));
3140 d_id.b.domain = LSB(MSW(rscn_entry));
3141 d_id.b.area = MSB(LSW(rscn_entry));
3142 d_id.b.al_pa = LSB(LSW(rscn_entry));
3143
3144 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3145 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 d_id.b.area, d_id.b.al_pa));
3148
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003149 vha->rscn_out_ptr++;
3150 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3151 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152
3153 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003154 for (rscn_out_iter = vha->rscn_out_ptr;
3155 !vha->flags.rscn_queue_overflow &&
3156 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003157 rscn_out_iter = (rscn_out_iter ==
3158 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3159
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003160 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 break;
3162
3163 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 rscn_out_iter));
3166
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003167 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 }
3169
3170 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003174
3175 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177 }
3178
3179 switch (format) {
3180 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 mask = 0xffffff;
3182 break;
3183 case 1:
3184 mask = 0xffff00;
3185 break;
3186 case 2:
3187 mask = 0xff0000;
3188 break;
3189 default:
3190 mask = 0x0;
3191 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193 break;
3194 }
3195
3196 rval = QLA_SUCCESS;
3197
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3200 (fcport->d_id.b24 & mask) != d_id.b24 ||
3201 fcport->port_type == FCT_BROADCAST)
3202 continue;
3203
3204 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3205 if (format != 3 ||
3206 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003208 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 }
3210 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 }
3212 }
3213 return (rval);
3214}
3215
3216/*
3217 * qla2x00_fabric_dev_login
3218 * Login fabric target device and update FC port database.
3219 *
3220 * Input:
3221 * ha: adapter state pointer.
3222 * fcport: port structure list pointer.
3223 * next_loopid: contains value of a new loop ID that can be used
3224 * by the next login attempt.
3225 *
3226 * Returns:
3227 * qla2x00 local function return status code.
3228 *
3229 * Context:
3230 * Kernel context.
3231 */
3232static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 uint16_t *next_loopid)
3235{
3236 int rval;
3237 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003238 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003239 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
3241 rval = QLA_SUCCESS;
3242 retry = 0;
3243
Andrew Vasquezac280b62009-08-20 11:06:05 -07003244 if (IS_ALOGIO_CAPABLE(ha)) {
3245 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3246 if (!rval)
3247 return rval;
3248 }
3249
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003252 /* Send an ADISC to tape devices.*/
3253 opts = 0;
3254 if (fcport->flags & FCF_TAPE_PRESENT)
3255 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003258 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003259 fcport->d_id.b.domain, fcport->d_id.b.area,
3260 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003261 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264 }
3265 }
3266
3267 return (rval);
3268}
3269
3270/*
3271 * qla2x00_fabric_login
3272 * Issue fabric login command.
3273 *
3274 * Input:
3275 * ha = adapter block pointer.
3276 * device = pointer to FC device type structure.
3277 *
3278 * Returns:
3279 * 0 - Login successfully
3280 * 1 - Login failed
3281 * 2 - Initiator device
3282 * 3 - Fatal error
3283 */
3284int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286 uint16_t *next_loopid)
3287{
3288 int rval;
3289 int retry;
3290 uint16_t tmp_loopid;
3291 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
3294 retry = 0;
3295 tmp_loopid = 0;
3296
3297 for (;;) {
3298 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3299 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3302
3303 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003304 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 fcport->d_id.b.domain, fcport->d_id.b.area,
3306 fcport->d_id.b.al_pa, mb, BIT_0);
3307 if (mb[0] == MBS_PORT_ID_USED) {
3308 /*
3309 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003310 * recommends the driver perform an implicit login with
3311 * the specified ID again. The ID we just used is save
3312 * here so we return with an ID that can be tried by
3313 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 */
3315 retry++;
3316 tmp_loopid = fcport->loop_id;
3317 fcport->loop_id = mb[1];
3318
3319 DEBUG(printk("Fabric Login: port in use - next "
3320 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3321 fcport->loop_id, fcport->d_id.b.domain,
3322 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3323
3324 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3325 /*
3326 * Login succeeded.
3327 */
3328 if (retry) {
3329 /* A retry occurred before. */
3330 *next_loopid = tmp_loopid;
3331 } else {
3332 /*
3333 * No retry occurred before. Just increment the
3334 * ID value for next login.
3335 */
3336 *next_loopid = (fcport->loop_id + 1);
3337 }
3338
3339 if (mb[1] & BIT_0) {
3340 fcport->port_type = FCT_INITIATOR;
3341 } else {
3342 fcport->port_type = FCT_TARGET;
3343 if (mb[1] & BIT_1) {
3344 fcport->flags |= FCF_TAPE_PRESENT;
3345 }
3346 }
3347
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003348 if (mb[10] & BIT_0)
3349 fcport->supported_classes |= FC_COS_CLASS2;
3350 if (mb[10] & BIT_1)
3351 fcport->supported_classes |= FC_COS_CLASS3;
3352
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 rval = QLA_SUCCESS;
3354 break;
3355 } else if (mb[0] == MBS_LOOP_ID_USED) {
3356 /*
3357 * Loop ID already used, try next loop ID.
3358 */
3359 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003360 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 if (rval != QLA_SUCCESS) {
3362 /* Ran out of loop IDs to use */
3363 break;
3364 }
3365 } else if (mb[0] == MBS_COMMAND_ERROR) {
3366 /*
3367 * Firmware possibly timed out during login. If NO
3368 * retries are left to do then the device is declared
3369 * dead.
3370 */
3371 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003372 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003373 fcport->d_id.b.domain, fcport->d_id.b.area,
3374 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003375 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376
3377 rval = 1;
3378 break;
3379 } else {
3380 /*
3381 * unrecoverable / not handled error
3382 */
3383 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003384 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003385 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 fcport->d_id.b.domain, fcport->d_id.b.area,
3387 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3388
3389 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003390 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003391 fcport->d_id.b.domain, fcport->d_id.b.area,
3392 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003393 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003394 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395
3396 rval = 3;
3397 break;
3398 }
3399 }
3400
3401 return (rval);
3402}
3403
3404/*
3405 * qla2x00_local_device_login
3406 * Issue local device login command.
3407 *
3408 * Input:
3409 * ha = adapter block pointer.
3410 * loop_id = loop id of device to login to.
3411 *
3412 * Returns (Where's the #define!!!!):
3413 * 0 - Login successfully
3414 * 1 - Login failed
3415 * 3 - Fatal error
3416 */
3417int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419{
3420 int rval;
3421 uint16_t mb[MAILBOX_REGISTER_COUNT];
3422
3423 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 if (rval == QLA_SUCCESS) {
3426 /* Interrogate mailbox registers for any errors */
3427 if (mb[0] == MBS_COMMAND_ERROR)
3428 rval = 1;
3429 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3430 /* device not in PCB table */
3431 rval = 3;
3432 }
3433
3434 return (rval);
3435}
3436
3437/*
3438 * qla2x00_loop_resync
3439 * Resync with fibre channel devices.
3440 *
3441 * Input:
3442 * ha = adapter block pointer.
3443 *
3444 * Returns:
3445 * 0 = success
3446 */
3447int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003450 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003451 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003452 struct req_que *req;
3453 struct rsp_que *rsp;
3454
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003455 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003456 req = vha->hw->req_q_map[0];
3457 else
3458 req = vha->req;
3459 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003461 atomic_set(&vha->loop_state, LOOP_UPDATE);
3462 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3463 if (vha->flags.online) {
3464 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3466 wait_time = 256;
3467 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003470 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003471 qla2x00_marker(vha, req, rsp, 0, 0,
3472 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
3475 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003476 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003478 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003480 } while (!atomic_read(&vha->loop_down_timer) &&
3481 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3482 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3483 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 }
3486
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003487 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003490 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003491 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492
3493 return (rval);
3494}
3495
Linus Torvalds1da177e2005-04-16 15:20:36 -07003496void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003497qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003498{
3499 fc_port_t *fcport;
3500
3501 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003502 list_for_each_entry(fcport, &vha->vp_fcports, list)
3503 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003504 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003505 qla2x00_rport_del(fcport);
3506}
3507
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508/*
3509* qla2x00_abort_isp
3510* Resets ISP and aborts all outstanding commands.
3511*
3512* Input:
3513* ha = adapter block pointer.
3514*
3515* Returns:
3516* 0 = success
3517*/
3518int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003519qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003521 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003523 struct qla_hw_data *ha = vha->hw;
3524 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003525 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003526 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003528 if (vha->flags.online) {
3529 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003530 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003532 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533
3534 qla_printk(KERN_INFO, ha,
3535 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003536 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3539 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3540 atomic_set(&vha->loop_state, LOOP_DOWN);
3541 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003542 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003543 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003544 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003545 if (!atomic_read(&vha->loop_down_timer))
3546 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547 LOOP_DOWN_TIME);
3548 }
3549
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003552
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003553 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003555 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003556
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003557 if (!qla2x00_restart_isp(vha)) {
3558 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003559
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003561 /*
3562 * Issue marker command only when we are going
3563 * to start the I/O .
3564 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003565 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003566 }
3567
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003568 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003569
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003570 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003571
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003572 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003573 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003574
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003575 if (ha->fce) {
3576 ha->flags.fce_enabled = 1;
3577 memset(ha->fce, 0,
3578 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003579 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003580 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3581 &ha->fce_bufs);
3582 if (rval) {
3583 qla_printk(KERN_WARNING, ha,
3584 "Unable to reinitialize FCE "
3585 "(%d).\n", rval);
3586 ha->flags.fce_enabled = 0;
3587 }
3588 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003589
3590 if (ha->eft) {
3591 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003592 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003593 ha->eft_dma, EFT_NUM_BUFFERS);
3594 if (rval) {
3595 qla_printk(KERN_WARNING, ha,
3596 "Unable to reinitialize EFT "
3597 "(%d).\n", rval);
3598 }
3599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003600 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003601 vha->flags.online = 1;
3602 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 if (ha->isp_abort_cnt == 0) {
3604 qla_printk(KERN_WARNING, ha,
3605 "ISP error recovery failed - "
3606 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003607 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003608 * The next call disables the board
3609 * completely.
3610 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 ha->isp_ops->reset_adapter(vha);
3612 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003614 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003615 status = 0;
3616 } else { /* schedule another ISP abort */
3617 ha->isp_abort_cnt--;
3618 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003619 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003620 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621 status = 1;
3622 }
3623 } else {
3624 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3625 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3626 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003627 vha->host_no, ha->isp_abort_cnt));
3628 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 status = 1;
3630 }
3631 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003632
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 }
3634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003635 if (!status) {
3636 DEBUG(printk(KERN_INFO
3637 "qla2x00_abort_isp(%ld): succeeded.\n",
3638 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003639 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003640 if (vp->vp_idx)
3641 qla2x00_vp_abort_isp(vp);
3642 }
3643 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003644 qla_printk(KERN_INFO, ha,
3645 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003646 }
3647
3648 return(status);
3649}
3650
3651/*
3652* qla2x00_restart_isp
3653* restarts the ISP after a reset
3654*
3655* Input:
3656* ha = adapter block pointer.
3657*
3658* Returns:
3659* 0 = success
3660*/
3661static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003662qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003663{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003664 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003665 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003666 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003667 struct req_que *req = ha->req_q_map[0];
3668 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003669
3670 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003671 if (qla2x00_isp_firmware(vha)) {
3672 vha->flags.online = 0;
3673 status = ha->isp_ops->chip_diag(vha);
3674 if (!status)
3675 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003676 }
3677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003678 if (!status && !(status = qla2x00_init_rings(vha))) {
3679 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003680 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003681 /* Initialize the queues in use */
3682 qla25xx_init_queues(ha);
3683
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003684 status = qla2x00_fw_ready(vha);
3685 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003687 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003688
3689 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003690 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003691
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003692 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003693 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3694 wait_time = 256;
3695 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003696 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3697 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003698 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003699 } while (!atomic_read(&vha->loop_down_timer) &&
3700 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3701 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3702 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 }
3704
3705 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003706 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003707 status = 0;
3708
3709 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3710 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003711 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003712 }
3713 return (status);
3714}
3715
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003716static int
3717qla25xx_init_queues(struct qla_hw_data *ha)
3718{
3719 struct rsp_que *rsp = NULL;
3720 struct req_que *req = NULL;
3721 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3722 int ret = -1;
3723 int i;
3724
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003725 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003726 rsp = ha->rsp_q_map[i];
3727 if (rsp) {
3728 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003729 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003730 if (ret != QLA_SUCCESS)
3731 DEBUG2_17(printk(KERN_WARNING
3732 "%s Rsp que:%d init failed\n", __func__,
3733 rsp->id));
3734 else
3735 DEBUG2_17(printk(KERN_INFO
3736 "%s Rsp que:%d inited\n", __func__,
3737 rsp->id));
3738 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003739 }
3740 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003741 req = ha->req_q_map[i];
3742 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003743 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003744 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003745 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003746 if (ret != QLA_SUCCESS)
3747 DEBUG2_17(printk(KERN_WARNING
3748 "%s Req que:%d init failed\n", __func__,
3749 req->id));
3750 else
3751 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003752 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003753 req->id));
3754 }
3755 }
3756 return ret;
3757}
3758
Linus Torvalds1da177e2005-04-16 15:20:36 -07003759/*
3760* qla2x00_reset_adapter
3761* Reset adapter.
3762*
3763* Input:
3764* ha = adapter block pointer.
3765*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003766void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003767qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003768{
3769 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003770 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003771 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003772
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003773 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003774 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003775
Linus Torvalds1da177e2005-04-16 15:20:36 -07003776 spin_lock_irqsave(&ha->hardware_lock, flags);
3777 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3778 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3779 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3780 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3781 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3782}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003783
3784void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003785qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003786{
3787 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003788 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003789 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3790
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003791 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003792 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003793
3794 spin_lock_irqsave(&ha->hardware_lock, flags);
3795 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3796 RD_REG_DWORD(&reg->hccr);
3797 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3798 RD_REG_DWORD(&reg->hccr);
3799 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003800
3801 if (IS_NOPOLLING_TYPE(ha))
3802 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003803}
3804
David Miller4e08df32007-04-16 12:37:43 -07003805/* On sparc systems, obtain port and node WWN from firmware
3806 * properties.
3807 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3809 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003810{
3811#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003813 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003814 struct device_node *dp = pci_device_to_OF_node(pdev);
3815 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003816 int len;
3817
3818 val = of_get_property(dp, "port-wwn", &len);
3819 if (val && len >= WWN_SIZE)
3820 memcpy(nv->port_name, val, WWN_SIZE);
3821
3822 val = of_get_property(dp, "node-wwn", &len);
3823 if (val && len >= WWN_SIZE)
3824 memcpy(nv->node_name, val, WWN_SIZE);
3825#endif
3826}
3827
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003828int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003829qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003830{
David Miller4e08df32007-04-16 12:37:43 -07003831 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003832 struct init_cb_24xx *icb;
3833 struct nvram_24xx *nv;
3834 uint32_t *dptr;
3835 uint8_t *dptr1, *dptr2;
3836 uint32_t chksum;
3837 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003838 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003839
David Miller4e08df32007-04-16 12:37:43 -07003840 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003841 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003842 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003843
3844 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003845 if (ha->flags.port0) {
3846 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3847 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3848 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003849 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003850 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3851 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003852 ha->nvram_size = sizeof(struct nvram_24xx);
3853 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003854
Seokmann Ju281afe12007-07-26 13:43:34 -07003855 /* Get VPD data into cache */
3856 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003857 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003858 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3859
3860 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003861 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003862 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003863 ha->nvram_size);
3864 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3865 chksum += le32_to_cpu(*dptr++);
3866
Andrew Vasquez76403352009-04-06 22:33:39 -07003867 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003868 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003869
3870 /* Bad NVRAM data, set defaults parameters. */
3871 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3872 || nv->id[3] != ' ' ||
3873 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3874 /* Reset NVRAM data. */
3875 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3876 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3877 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003878 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3879 "invalid -- WWPN) defaults.\n");
3880
3881 /*
3882 * Set default initialization control block.
3883 */
3884 memset(nv, 0, ha->nvram_size);
3885 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3886 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3887 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3888 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3889 nv->exchange_count = __constant_cpu_to_le16(0);
3890 nv->hard_address = __constant_cpu_to_le16(124);
3891 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003892 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07003893 nv->port_name[2] = 0x00;
3894 nv->port_name[3] = 0xe0;
3895 nv->port_name[4] = 0x8b;
3896 nv->port_name[5] = 0x1c;
3897 nv->port_name[6] = 0x55;
3898 nv->port_name[7] = 0x86;
3899 nv->node_name[0] = 0x20;
3900 nv->node_name[1] = 0x00;
3901 nv->node_name[2] = 0x00;
3902 nv->node_name[3] = 0xe0;
3903 nv->node_name[4] = 0x8b;
3904 nv->node_name[5] = 0x1c;
3905 nv->node_name[6] = 0x55;
3906 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003907 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003908 nv->login_retry_count = __constant_cpu_to_le16(8);
3909 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3910 nv->login_timeout = __constant_cpu_to_le16(0);
3911 nv->firmware_options_1 =
3912 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3913 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3914 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3915 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3916 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3917 nv->efi_parameters = __constant_cpu_to_le32(0);
3918 nv->reset_delay = 5;
3919 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3920 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3921 nv->link_down_timeout = __constant_cpu_to_le16(30);
3922
3923 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003924 }
3925
3926 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003927 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003928
3929 /* Copy 1st segment. */
3930 dptr1 = (uint8_t *)icb;
3931 dptr2 = (uint8_t *)&nv->version;
3932 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3933 while (cnt--)
3934 *dptr1++ = *dptr2++;
3935
3936 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003937 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003938
3939 /* Copy 2nd segment. */
3940 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3941 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3942 cnt = (uint8_t *)&icb->reserved_3 -
3943 (uint8_t *)&icb->interrupt_delay_timer;
3944 while (cnt--)
3945 *dptr1++ = *dptr2++;
3946
3947 /*
3948 * Setup driver NVRAM options.
3949 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003950 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003951 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003952
Andrew Vasquez5341e862006-05-17 15:09:16 -07003953 /* Use alternate WWN? */
3954 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3955 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3956 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3957 }
3958
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003959 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003960 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003961 /*
3962 * Firmware will apply the following mask if the nodename was
3963 * not provided.
3964 */
3965 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3966 icb->node_name[0] &= 0xF0;
3967 }
3968
3969 /* Set host adapter parameters. */
3970 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003971 ha->flags.enable_lip_reset = 0;
3972 ha->flags.enable_lip_full_login =
3973 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3974 ha->flags.enable_target_reset =
3975 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003976 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003977 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003978
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003979 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3980 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003981
3982 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3983 sizeof(ha->fw_seriallink_options24));
3984
3985 /* save HBA serial number */
3986 ha->serial0 = icb->port_name[5];
3987 ha->serial1 = icb->port_name[6];
3988 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003989 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3990 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003991
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003992 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3993
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003994 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3995
3996 /* Set minimum login_timeout to 4 seconds. */
3997 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3998 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3999 if (le16_to_cpu(nv->login_timeout) < 4)
4000 nv->login_timeout = __constant_cpu_to_le16(4);
4001 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004002 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004003
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004004 /* Set minimum RATOV to 100 tenths of a second. */
4005 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004006
4007 ha->loop_reset_delay = nv->reset_delay;
4008
4009 /* Link Down Timeout = 0:
4010 *
4011 * When Port Down timer expires we will start returning
4012 * I/O's to OS with "DID_NO_CONNECT".
4013 *
4014 * Link Down Timeout != 0:
4015 *
4016 * The driver waits for the link to come up after link down
4017 * before returning I/Os to OS with "DID_NO_CONNECT".
4018 */
4019 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4020 ha->loop_down_abort_time =
4021 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4022 } else {
4023 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4024 ha->loop_down_abort_time =
4025 (LOOP_DOWN_TIME - ha->link_down_timeout);
4026 }
4027
4028 /* Need enough time to try and get the port back. */
4029 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4030 if (qlport_down_retry)
4031 ha->port_down_retry_count = qlport_down_retry;
4032
4033 /* Set login_retry_count */
4034 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4035 if (ha->port_down_retry_count ==
4036 le16_to_cpu(nv->port_down_retry_count) &&
4037 ha->port_down_retry_count > 3)
4038 ha->login_retry_count = ha->port_down_retry_count;
4039 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4040 ha->login_retry_count = ha->port_down_retry_count;
4041 if (ql2xloginretrycount)
4042 ha->login_retry_count = ql2xloginretrycount;
4043
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004044 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004045 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004046 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4047 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4048 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4049 le16_to_cpu(icb->interrupt_delay_timer): 2;
4050 }
4051 icb->firmware_options_2 &= __constant_cpu_to_le32(
4052 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004053 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004054 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004055 ha->zio_mode = QLA_ZIO_MODE_6;
4056
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004057 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004058 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004059 ha->zio_timer * 100));
4060 qla_printk(KERN_INFO, ha,
4061 "ZIO mode %d enabled; timer delay (%d us).\n",
4062 ha->zio_mode, ha->zio_timer * 100);
4063
4064 icb->firmware_options_2 |= cpu_to_le32(
4065 (uint32_t)ha->zio_mode);
4066 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004068 }
4069
David Miller4e08df32007-04-16 12:37:43 -07004070 if (rval) {
4071 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004072 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004073 }
4074 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004075}
4076
Adrian Bunk413975a2006-06-30 02:33:06 -07004077static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004078qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4079 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004080{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004081 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004082 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004083 uint32_t *dcode, dlen;
4084 uint32_t risc_addr;
4085 uint32_t risc_size;
4086 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004087 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004088 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004089
4090 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004091 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004092
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004093 rval = QLA_SUCCESS;
4094
4095 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004096 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004097 *srisc_addr = 0;
4098
4099 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004100 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004101 for (i = 0; i < 4; i++)
4102 dcode[i] = be32_to_cpu(dcode[i]);
4103 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4104 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4105 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4106 dcode[3] == 0)) {
4107 qla_printk(KERN_WARNING, ha,
4108 "Unable to verify integrity of flash firmware image!\n");
4109 qla_printk(KERN_WARNING, ha,
4110 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4111 dcode[1], dcode[2], dcode[3]);
4112
4113 return QLA_FUNCTION_FAILED;
4114 }
4115
4116 while (segments && rval == QLA_SUCCESS) {
4117 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004118 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004119
4120 risc_addr = be32_to_cpu(dcode[2]);
4121 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4122 risc_size = be32_to_cpu(dcode[3]);
4123
4124 fragment = 0;
4125 while (risc_size > 0 && rval == QLA_SUCCESS) {
4126 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4127 if (dlen > risc_size)
4128 dlen = risc_size;
4129
4130 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4131 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004132 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004133
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004134 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004135 for (i = 0; i < dlen; i++)
4136 dcode[i] = swab32(dcode[i]);
4137
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004138 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004139 dlen);
4140 if (rval) {
4141 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004143 fragment));
4144 qla_printk(KERN_WARNING, ha,
4145 "[ERROR] Failed to load segment %d of "
4146 "firmware\n", fragment);
4147 break;
4148 }
4149
4150 faddr += dlen;
4151 risc_addr += dlen;
4152 risc_size -= dlen;
4153 fragment++;
4154 }
4155
4156 /* Next segment. */
4157 segments--;
4158 }
4159
4160 return rval;
4161}
4162
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004163#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4164
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004165int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004166qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004167{
4168 int rval;
4169 int i, fragment;
4170 uint16_t *wcode, *fwcode;
4171 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4172 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004173 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004174 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004175
4176 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004177 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004178 if (!blob) {
4179 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004180 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4181 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004182 return QLA_FUNCTION_FAILED;
4183 }
4184
4185 rval = QLA_SUCCESS;
4186
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004187 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004188 *srisc_addr = 0;
4189 fwcode = (uint16_t *)blob->fw->data;
4190 fwclen = 0;
4191
4192 /* Validate firmware image by checking version. */
4193 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4194 qla_printk(KERN_WARNING, ha,
4195 "Unable to verify integrity of firmware image (%Zd)!\n",
4196 blob->fw->size);
4197 goto fail_fw_integrity;
4198 }
4199 for (i = 0; i < 4; i++)
4200 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4201 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4202 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4203 wcode[2] == 0 && wcode[3] == 0)) {
4204 qla_printk(KERN_WARNING, ha,
4205 "Unable to verify integrity of firmware image!\n");
4206 qla_printk(KERN_WARNING, ha,
4207 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4208 wcode[1], wcode[2], wcode[3]);
4209 goto fail_fw_integrity;
4210 }
4211
4212 seg = blob->segs;
4213 while (*seg && rval == QLA_SUCCESS) {
4214 risc_addr = *seg;
4215 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4216 risc_size = be16_to_cpu(fwcode[3]);
4217
4218 /* Validate firmware image size. */
4219 fwclen += risc_size * sizeof(uint16_t);
4220 if (blob->fw->size < fwclen) {
4221 qla_printk(KERN_WARNING, ha,
4222 "Unable to verify integrity of firmware image "
4223 "(%Zd)!\n", blob->fw->size);
4224 goto fail_fw_integrity;
4225 }
4226
4227 fragment = 0;
4228 while (risc_size > 0 && rval == QLA_SUCCESS) {
4229 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4230 if (wlen > risc_size)
4231 wlen = risc_size;
4232
4233 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004234 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004235 risc_addr, wlen));
4236
4237 for (i = 0; i < wlen; i++)
4238 wcode[i] = swab16(fwcode[i]);
4239
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004240 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004241 wlen);
4242 if (rval) {
4243 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004244 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004245 fragment));
4246 qla_printk(KERN_WARNING, ha,
4247 "[ERROR] Failed to load segment %d of "
4248 "firmware\n", fragment);
4249 break;
4250 }
4251
4252 fwcode += wlen;
4253 risc_addr += wlen;
4254 risc_size -= wlen;
4255 fragment++;
4256 }
4257
4258 /* Next segment. */
4259 seg++;
4260 }
4261 return rval;
4262
4263fail_fw_integrity:
4264 return QLA_FUNCTION_FAILED;
4265}
4266
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004267static int
4268qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004269{
4270 int rval;
4271 int segments, fragment;
4272 uint32_t *dcode, dlen;
4273 uint32_t risc_addr;
4274 uint32_t risc_size;
4275 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004276 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004277 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004278 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004279 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004280
Andrew Vasquez54333832005-11-09 15:49:04 -08004281 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004282 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004283 if (!blob) {
4284 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004285 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4286 "from: " QLA_FW_URL ".\n");
4287
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004288 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004289 }
4290
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004291 qla_printk(KERN_INFO, ha,
4292 "FW: Loading via request-firmware...\n");
4293
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004294 rval = QLA_SUCCESS;
4295
4296 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004297 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004298 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004299 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004300 fwclen = 0;
4301
4302 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004303 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004304 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004305 "Unable to verify integrity of firmware image (%Zd)!\n",
4306 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004307 goto fail_fw_integrity;
4308 }
4309 for (i = 0; i < 4; i++)
4310 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4311 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4312 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4313 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4314 dcode[3] == 0)) {
4315 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004316 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004317 qla_printk(KERN_WARNING, ha,
4318 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4319 dcode[1], dcode[2], dcode[3]);
4320 goto fail_fw_integrity;
4321 }
4322
4323 while (segments && rval == QLA_SUCCESS) {
4324 risc_addr = be32_to_cpu(fwcode[2]);
4325 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4326 risc_size = be32_to_cpu(fwcode[3]);
4327
4328 /* Validate firmware image size. */
4329 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004330 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004331 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004332 "Unable to verify integrity of firmware image "
4333 "(%Zd)!\n", blob->fw->size);
4334
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004335 goto fail_fw_integrity;
4336 }
4337
4338 fragment = 0;
4339 while (risc_size > 0 && rval == QLA_SUCCESS) {
4340 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4341 if (dlen > risc_size)
4342 dlen = risc_size;
4343
4344 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004345 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004346 risc_addr, dlen));
4347
4348 for (i = 0; i < dlen; i++)
4349 dcode[i] = swab32(fwcode[i]);
4350
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004351 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004352 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004353 if (rval) {
4354 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004355 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004356 fragment));
4357 qla_printk(KERN_WARNING, ha,
4358 "[ERROR] Failed to load segment %d of "
4359 "firmware\n", fragment);
4360 break;
4361 }
4362
4363 fwcode += dlen;
4364 risc_addr += dlen;
4365 risc_size -= dlen;
4366 fragment++;
4367 }
4368
4369 /* Next segment. */
4370 segments--;
4371 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004372 return rval;
4373
4374fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004375 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004376}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004377
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004378int
4379qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4380{
4381 int rval;
4382
Andrew Vasqueze337d902009-04-06 22:33:49 -07004383 if (ql2xfwloadbin == 1)
4384 return qla81xx_load_risc(vha, srisc_addr);
4385
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004386 /*
4387 * FW Load priority:
4388 * 1) Firmware via request-firmware interface (.bin file).
4389 * 2) Firmware residing in flash.
4390 */
4391 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4392 if (rval == QLA_SUCCESS)
4393 return rval;
4394
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004395 return qla24xx_load_risc_flash(vha, srisc_addr,
4396 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004397}
4398
4399int
4400qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4401{
4402 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004403 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004404
Andrew Vasqueze337d902009-04-06 22:33:49 -07004405 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004406 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004407
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004408 /*
4409 * FW Load priority:
4410 * 1) Firmware residing in flash.
4411 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004412 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004413 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004414 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004415 if (rval == QLA_SUCCESS)
4416 return rval;
4417
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004418try_blob_fw:
4419 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4420 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4421 return rval;
4422
4423 qla_printk(KERN_ERR, ha,
4424 "FW: Attempting to fallback to golden firmware...\n");
4425 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4426 if (rval != QLA_SUCCESS)
4427 return rval;
4428
4429 qla_printk(KERN_ERR, ha,
4430 "FW: Please update operational firmware...\n");
4431 ha->flags.running_gold_fw = 1;
4432
4433 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004434}
4435
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004436void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004437qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004438{
4439 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004440 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004441
Andrew Vasqueze4289242007-07-19 15:05:56 -07004442 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004443 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004444 if (!ha->fw_major_version)
4445 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004446
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004447 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004448 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004449 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004450 ha->isp_ops->reset_chip(vha);
4451 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004452 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004453 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004454 continue;
4455 qla_printk(KERN_INFO, ha,
4456 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004457 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004458 }
4459}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004460
4461int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004462qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004463{
4464 int rval = QLA_SUCCESS;
4465 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004466 struct qla_hw_data *ha = vha->hw;
4467 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004468 struct req_que *req;
4469 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004470
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004471 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004472 return -EINVAL;
4473
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004474 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004475 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004476 req = ha->req_q_map[0];
4477 else
4478 req = vha->req;
4479 rsp = req->rsp;
4480
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004481 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004482 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004483 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004484 }
4485
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004486 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004487
4488 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004489 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004490 if (mb[0] != MBS_COMMAND_COMPLETE) {
4491 DEBUG15(qla_printk(KERN_INFO, ha,
4492 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4493 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4494 mb[0], mb[1], mb[2], mb[6], mb[7]));
4495 return (QLA_FUNCTION_FAILED);
4496 }
4497
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004498 atomic_set(&vha->loop_down_timer, 0);
4499 atomic_set(&vha->loop_state, LOOP_UP);
4500 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4501 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4502 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004503
4504 return rval;
4505}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004506
4507/* 84XX Support **************************************************************/
4508
4509static LIST_HEAD(qla_cs84xx_list);
4510static DEFINE_MUTEX(qla_cs84xx_mutex);
4511
4512static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004513qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004514{
4515 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004516 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004517
4518 mutex_lock(&qla_cs84xx_mutex);
4519
4520 /* Find any shared 84xx chip. */
4521 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4522 if (cs84xx->bus == ha->pdev->bus) {
4523 kref_get(&cs84xx->kref);
4524 goto done;
4525 }
4526 }
4527
4528 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4529 if (!cs84xx)
4530 goto done;
4531
4532 kref_init(&cs84xx->kref);
4533 spin_lock_init(&cs84xx->access_lock);
4534 mutex_init(&cs84xx->fw_update_mutex);
4535 cs84xx->bus = ha->pdev->bus;
4536
4537 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4538done:
4539 mutex_unlock(&qla_cs84xx_mutex);
4540 return cs84xx;
4541}
4542
4543static void
4544__qla84xx_chip_release(struct kref *kref)
4545{
4546 struct qla_chip_state_84xx *cs84xx =
4547 container_of(kref, struct qla_chip_state_84xx, kref);
4548
4549 mutex_lock(&qla_cs84xx_mutex);
4550 list_del(&cs84xx->list);
4551 mutex_unlock(&qla_cs84xx_mutex);
4552 kfree(cs84xx);
4553}
4554
4555void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004556qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004557{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004558 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004559 if (ha->cs84xx)
4560 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4561}
4562
4563static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004564qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004565{
4566 int rval;
4567 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004568 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004569
4570 mutex_lock(&ha->cs84xx->fw_update_mutex);
4571
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004572 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004573
4574 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4575
4576 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4577 QLA_SUCCESS;
4578}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004579
4580/* 81XX Support **************************************************************/
4581
4582int
4583qla81xx_nvram_config(scsi_qla_host_t *vha)
4584{
4585 int rval;
4586 struct init_cb_81xx *icb;
4587 struct nvram_81xx *nv;
4588 uint32_t *dptr;
4589 uint8_t *dptr1, *dptr2;
4590 uint32_t chksum;
4591 uint16_t cnt;
4592 struct qla_hw_data *ha = vha->hw;
4593
4594 rval = QLA_SUCCESS;
4595 icb = (struct init_cb_81xx *)ha->init_cb;
4596 nv = ha->nvram;
4597
4598 /* Determine NVRAM starting address. */
4599 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004600 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004601
4602 /* Get VPD data into cache */
4603 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004604 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4605 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004606
4607 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004608 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004609 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004610 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004611 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4612 chksum += le32_to_cpu(*dptr++);
4613
Andrew Vasquez76403352009-04-06 22:33:39 -07004614 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004615 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4616
4617 /* Bad NVRAM data, set defaults parameters. */
4618 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4619 || nv->id[3] != ' ' ||
4620 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4621 /* Reset NVRAM data. */
4622 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4623 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4624 le16_to_cpu(nv->nvram_version));
4625 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4626 "invalid -- WWPN) defaults.\n");
4627
4628 /*
4629 * Set default initialization control block.
4630 */
4631 memset(nv, 0, ha->nvram_size);
4632 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4633 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4634 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4635 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4636 nv->exchange_count = __constant_cpu_to_le16(0);
4637 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004638 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004639 nv->port_name[2] = 0x00;
4640 nv->port_name[3] = 0xe0;
4641 nv->port_name[4] = 0x8b;
4642 nv->port_name[5] = 0x1c;
4643 nv->port_name[6] = 0x55;
4644 nv->port_name[7] = 0x86;
4645 nv->node_name[0] = 0x20;
4646 nv->node_name[1] = 0x00;
4647 nv->node_name[2] = 0x00;
4648 nv->node_name[3] = 0xe0;
4649 nv->node_name[4] = 0x8b;
4650 nv->node_name[5] = 0x1c;
4651 nv->node_name[6] = 0x55;
4652 nv->node_name[7] = 0x86;
4653 nv->login_retry_count = __constant_cpu_to_le16(8);
4654 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4655 nv->login_timeout = __constant_cpu_to_le16(0);
4656 nv->firmware_options_1 =
4657 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4658 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4659 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4660 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4661 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4662 nv->efi_parameters = __constant_cpu_to_le32(0);
4663 nv->reset_delay = 5;
4664 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4665 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4666 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004667 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004668 nv->enode_mac[1] = 0x02;
4669 nv->enode_mac[2] = 0x03;
4670 nv->enode_mac[3] = 0x04;
4671 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004672 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004673
4674 rval = 1;
4675 }
4676
4677 /* Reset Initialization control block */
4678 memset(icb, 0, sizeof(struct init_cb_81xx));
4679
4680 /* Copy 1st segment. */
4681 dptr1 = (uint8_t *)icb;
4682 dptr2 = (uint8_t *)&nv->version;
4683 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4684 while (cnt--)
4685 *dptr1++ = *dptr2++;
4686
4687 icb->login_retry_count = nv->login_retry_count;
4688
4689 /* Copy 2nd segment. */
4690 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4691 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4692 cnt = (uint8_t *)&icb->reserved_5 -
4693 (uint8_t *)&icb->interrupt_delay_timer;
4694 while (cnt--)
4695 *dptr1++ = *dptr2++;
4696
4697 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4698 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4699 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4700 icb->enode_mac[0] = 0x01;
4701 icb->enode_mac[1] = 0x02;
4702 icb->enode_mac[2] = 0x03;
4703 icb->enode_mac[3] = 0x04;
4704 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004705 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004706 }
4707
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004708 /* Use extended-initialization control block. */
4709 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4710
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004711 /*
4712 * Setup driver NVRAM options.
4713 */
4714 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4715 "QLE81XX");
4716
4717 /* Use alternate WWN? */
4718 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4719 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4720 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4721 }
4722
4723 /* Prepare nodename */
4724 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4725 /*
4726 * Firmware will apply the following mask if the nodename was
4727 * not provided.
4728 */
4729 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4730 icb->node_name[0] &= 0xF0;
4731 }
4732
4733 /* Set host adapter parameters. */
4734 ha->flags.disable_risc_code_load = 0;
4735 ha->flags.enable_lip_reset = 0;
4736 ha->flags.enable_lip_full_login =
4737 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4738 ha->flags.enable_target_reset =
4739 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4740 ha->flags.enable_led_scheme = 0;
4741 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4742
4743 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4744 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4745
4746 /* save HBA serial number */
4747 ha->serial0 = icb->port_name[5];
4748 ha->serial1 = icb->port_name[6];
4749 ha->serial2 = icb->port_name[7];
4750 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4751 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4752
4753 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4754
4755 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4756
4757 /* Set minimum login_timeout to 4 seconds. */
4758 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4759 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4760 if (le16_to_cpu(nv->login_timeout) < 4)
4761 nv->login_timeout = __constant_cpu_to_le16(4);
4762 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4763 icb->login_timeout = nv->login_timeout;
4764
4765 /* Set minimum RATOV to 100 tenths of a second. */
4766 ha->r_a_tov = 100;
4767
4768 ha->loop_reset_delay = nv->reset_delay;
4769
4770 /* Link Down Timeout = 0:
4771 *
4772 * When Port Down timer expires we will start returning
4773 * I/O's to OS with "DID_NO_CONNECT".
4774 *
4775 * Link Down Timeout != 0:
4776 *
4777 * The driver waits for the link to come up after link down
4778 * before returning I/Os to OS with "DID_NO_CONNECT".
4779 */
4780 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4781 ha->loop_down_abort_time =
4782 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4783 } else {
4784 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4785 ha->loop_down_abort_time =
4786 (LOOP_DOWN_TIME - ha->link_down_timeout);
4787 }
4788
4789 /* Need enough time to try and get the port back. */
4790 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4791 if (qlport_down_retry)
4792 ha->port_down_retry_count = qlport_down_retry;
4793
4794 /* Set login_retry_count */
4795 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4796 if (ha->port_down_retry_count ==
4797 le16_to_cpu(nv->port_down_retry_count) &&
4798 ha->port_down_retry_count > 3)
4799 ha->login_retry_count = ha->port_down_retry_count;
4800 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4801 ha->login_retry_count = ha->port_down_retry_count;
4802 if (ql2xloginretrycount)
4803 ha->login_retry_count = ql2xloginretrycount;
4804
4805 /* Enable ZIO. */
4806 if (!vha->flags.init_done) {
4807 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4808 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4809 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4810 le16_to_cpu(icb->interrupt_delay_timer): 2;
4811 }
4812 icb->firmware_options_2 &= __constant_cpu_to_le32(
4813 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4814 vha->flags.process_response_queue = 0;
4815 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4816 ha->zio_mode = QLA_ZIO_MODE_6;
4817
4818 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4819 "(%d us).\n", vha->host_no, ha->zio_mode,
4820 ha->zio_timer * 100));
4821 qla_printk(KERN_INFO, ha,
4822 "ZIO mode %d enabled; timer delay (%d us).\n",
4823 ha->zio_mode, ha->zio_timer * 100);
4824
4825 icb->firmware_options_2 |= cpu_to_le32(
4826 (uint32_t)ha->zio_mode);
4827 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4828 vha->flags.process_response_queue = 1;
4829 }
4830
4831 if (rval) {
4832 DEBUG2_3(printk(KERN_WARNING
4833 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4834 }
4835 return (rval);
4836}
4837
4838void
4839qla81xx_update_fw_options(scsi_qla_host_t *ha)
4840{
4841}