blob: c2494ca6ba1c64990ccd86b4455fd239d37df59f [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 Vasquezab671142009-08-25 11:36:17 -07001797 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
1798 !IS_QLA81XX(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001799
1800 if (memcmp(model, BINZERO, len) != 0) {
1801 strncpy(ha->model_number, model, len);
1802 st = en = ha->model_number;
1803 en += len - 1;
1804 while (en > st) {
1805 if (*en != 0x20 && *en != 0x00)
1806 break;
1807 *en-- = '\0';
1808 }
1809
1810 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001811 if (use_tbl &&
1812 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001813 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001814 strncpy(ha->model_desc,
1815 qla2x00_model_name[index * 2 + 1],
1816 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001817 } else {
1818 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001819 if (use_tbl &&
1820 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001821 index < QLA_MODEL_NAMES) {
1822 strcpy(ha->model_number,
1823 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001824 strncpy(ha->model_desc,
1825 qla2x00_model_name[index * 2 + 1],
1826 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001827 } else {
1828 strcpy(ha->model_number, def);
1829 }
1830 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001831 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001832 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001833 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001834}
1835
David Miller4e08df32007-04-16 12:37:43 -07001836/* On sparc systems, obtain port and node WWN from firmware
1837 * properties.
1838 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001839static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001840{
1841#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001842 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001843 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001844 struct device_node *dp = pci_device_to_OF_node(pdev);
1845 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001846 int len;
1847
1848 val = of_get_property(dp, "port-wwn", &len);
1849 if (val && len >= WWN_SIZE)
1850 memcpy(nv->port_name, val, WWN_SIZE);
1851
1852 val = of_get_property(dp, "node-wwn", &len);
1853 if (val && len >= WWN_SIZE)
1854 memcpy(nv->node_name, val, WWN_SIZE);
1855#endif
1856}
1857
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858/*
1859* NVRAM configuration for ISP 2xxx
1860*
1861* Input:
1862* ha = adapter block pointer.
1863*
1864* Output:
1865* initialization control block in response_ring
1866* host adapters parameters in host adapter block
1867*
1868* Returns:
1869* 0 = success.
1870*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001871int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001872qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873{
David Miller4e08df32007-04-16 12:37:43 -07001874 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001875 uint8_t chksum = 0;
1876 uint16_t cnt;
1877 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001878 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001879 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001880 nvram_t *nv = ha->nvram;
1881 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001882 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
David Miller4e08df32007-04-16 12:37:43 -07001884 rval = QLA_SUCCESS;
1885
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001887 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 ha->nvram_base = 0;
1889 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1890 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1891 ha->nvram_base = 0x80;
1892
1893 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001894 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001895 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1896 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001899 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900
1901 /* Bad NVRAM data, set defaults parameters. */
1902 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1903 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1904 /* Reset NVRAM data. */
1905 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1906 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1907 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001908 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1909 "invalid -- WWPN) defaults.\n");
1910
1911 /*
1912 * Set default initialization control block.
1913 */
1914 memset(nv, 0, ha->nvram_size);
1915 nv->parameter_block_version = ICB_VERSION;
1916
1917 if (IS_QLA23XX(ha)) {
1918 nv->firmware_options[0] = BIT_2 | BIT_1;
1919 nv->firmware_options[1] = BIT_7 | BIT_5;
1920 nv->add_firmware_options[0] = BIT_5;
1921 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1922 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1923 nv->special_options[1] = BIT_7;
1924 } else if (IS_QLA2200(ha)) {
1925 nv->firmware_options[0] = BIT_2 | BIT_1;
1926 nv->firmware_options[1] = BIT_7 | BIT_5;
1927 nv->add_firmware_options[0] = BIT_5;
1928 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1929 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1930 } else if (IS_QLA2100(ha)) {
1931 nv->firmware_options[0] = BIT_3 | BIT_1;
1932 nv->firmware_options[1] = BIT_5;
1933 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1934 }
1935
1936 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1937 nv->execution_throttle = __constant_cpu_to_le16(16);
1938 nv->retry_count = 8;
1939 nv->retry_delay = 1;
1940
1941 nv->port_name[0] = 33;
1942 nv->port_name[3] = 224;
1943 nv->port_name[4] = 139;
1944
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001945 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001946
1947 nv->login_timeout = 4;
1948
1949 /*
1950 * Set default host adapter parameters
1951 */
1952 nv->host_p[1] = BIT_2;
1953 nv->reset_delay = 5;
1954 nv->port_down_retry_count = 8;
1955 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1956 nv->link_down_timeout = 60;
1957
1958 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959 }
1960
1961#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1962 /*
1963 * The SN2 does not provide BIOS emulation which means you can't change
1964 * potentially bogus BIOS settings. Force the use of default settings
1965 * for link rate and frame size. Hope that the rest of the settings
1966 * are valid.
1967 */
1968 if (ia64_platform_is("sn2")) {
1969 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1970 if (IS_QLA23XX(ha))
1971 nv->special_options[1] = BIT_7;
1972 }
1973#endif
1974
1975 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001976 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977
1978 /*
1979 * Setup driver NVRAM options.
1980 */
1981 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1982 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1983 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1984 nv->firmware_options[1] &= ~BIT_4;
1985
1986 if (IS_QLA23XX(ha)) {
1987 nv->firmware_options[0] |= BIT_2;
1988 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001989 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
1991 if (IS_QLA2300(ha)) {
1992 if (ha->fb_rev == FPM_2310) {
1993 strcpy(ha->model_number, "QLA2310");
1994 } else {
1995 strcpy(ha->model_number, "QLA2300");
1996 }
1997 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001999 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000 }
2001 } else if (IS_QLA2200(ha)) {
2002 nv->firmware_options[0] |= BIT_2;
2003 /*
2004 * 'Point-to-point preferred, else loop' is not a safe
2005 * connection mode setting.
2006 */
2007 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
2008 (BIT_5 | BIT_4)) {
2009 /* Force 'loop preferred, else point-to-point'. */
2010 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
2011 nv->add_firmware_options[0] |= BIT_5;
2012 }
2013 strcpy(ha->model_number, "QLA22xx");
2014 } else /*if (IS_QLA2100(ha))*/ {
2015 strcpy(ha->model_number, "QLA2100");
2016 }
2017
2018 /*
2019 * Copy over NVRAM RISC parameter block to initialization control block.
2020 */
2021 dptr1 = (uint8_t *)icb;
2022 dptr2 = (uint8_t *)&nv->parameter_block_version;
2023 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
2024 while (cnt--)
2025 *dptr1++ = *dptr2++;
2026
2027 /* Copy 2nd half. */
2028 dptr1 = (uint8_t *)icb->add_firmware_options;
2029 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
2030 while (cnt--)
2031 *dptr1++ = *dptr2++;
2032
Andrew Vasquez5341e862006-05-17 15:09:16 -07002033 /* Use alternate WWN? */
2034 if (nv->host_p[1] & BIT_7) {
2035 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
2036 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
2037 }
2038
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 /* Prepare nodename */
2040 if ((icb->firmware_options[1] & BIT_6) == 0) {
2041 /*
2042 * Firmware will apply the following mask if the nodename was
2043 * not provided.
2044 */
2045 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
2046 icb->node_name[0] &= 0xF0;
2047 }
2048
2049 /*
2050 * Set host adapter parameters.
2051 */
Andrew Vasquez01819442006-06-23 16:11:10 -07002052 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07002053 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
2055 /* Always load RISC code on non ISP2[12]00 chips. */
2056 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
2057 ha->flags.disable_risc_code_load = 0;
2058 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
2059 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
2060 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07002061 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07002062 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063
2064 ha->operating_mode =
2065 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
2066
2067 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
2068 sizeof(ha->fw_seriallink_options));
2069
2070 /* save HBA serial number */
2071 ha->serial0 = icb->port_name[5];
2072 ha->serial1 = icb->port_name[6];
2073 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002074 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
2075 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
2078
2079 ha->retry_count = nv->retry_count;
2080
2081 /* Set minimum login_timeout to 4 seconds. */
2082 if (nv->login_timeout < ql2xlogintimeout)
2083 nv->login_timeout = ql2xlogintimeout;
2084 if (nv->login_timeout < 4)
2085 nv->login_timeout = 4;
2086 ha->login_timeout = nv->login_timeout;
2087 icb->login_timeout = nv->login_timeout;
2088
Andrew Vasquez00a537b2008-02-28 14:06:11 -08002089 /* Set minimum RATOV to 100 tenths of a second. */
2090 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 ha->loop_reset_delay = nv->reset_delay;
2093
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 /* Link Down Timeout = 0:
2095 *
2096 * When Port Down timer expires we will start returning
2097 * I/O's to OS with "DID_NO_CONNECT".
2098 *
2099 * Link Down Timeout != 0:
2100 *
2101 * The driver waits for the link to come up after link down
2102 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002103 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002104 if (nv->link_down_timeout == 0) {
2105 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04002106 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107 } else {
2108 ha->link_down_timeout = nv->link_down_timeout;
2109 ha->loop_down_abort_time =
2110 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002111 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113 /*
2114 * Need enough time to try and get the port back.
2115 */
2116 ha->port_down_retry_count = nv->port_down_retry_count;
2117 if (qlport_down_retry)
2118 ha->port_down_retry_count = qlport_down_retry;
2119 /* Set login_retry_count */
2120 ha->login_retry_count = nv->retry_count;
2121 if (ha->port_down_retry_count == nv->port_down_retry_count &&
2122 ha->port_down_retry_count > 3)
2123 ha->login_retry_count = ha->port_down_retry_count;
2124 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
2125 ha->login_retry_count = ha->port_down_retry_count;
2126 if (ql2xloginretrycount)
2127 ha->login_retry_count = ql2xloginretrycount;
2128
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 icb->lun_enables = __constant_cpu_to_le16(0);
2130 icb->command_resource_count = 0;
2131 icb->immediate_notify_resource_count = 0;
2132 icb->timeout = __constant_cpu_to_le16(0);
2133
2134 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2135 /* Enable RIO */
2136 icb->firmware_options[0] &= ~BIT_3;
2137 icb->add_firmware_options[0] &=
2138 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
2139 icb->add_firmware_options[0] |= BIT_2;
2140 icb->response_accumulation_timer = 3;
2141 icb->interrupt_delay_timer = 5;
2142
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002143 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002144 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002145 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002147 ha->zio_mode = icb->add_firmware_options[0] &
2148 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
2149 ha->zio_timer = icb->interrupt_delay_timer ?
2150 icb->interrupt_delay_timer: 2;
2151 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 icb->add_firmware_options[0] &=
2153 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002155 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08002156 ha->zio_mode = QLA_ZIO_MODE_6;
2157
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002158 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002159 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002160 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002162 "ZIO mode %d enabled; timer delay (%d us).\n",
2163 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07002165 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
2166 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 }
2169 }
2170
David Miller4e08df32007-04-16 12:37:43 -07002171 if (rval) {
2172 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07002174 }
2175 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176}
2177
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002178static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002179qla2x00_rport_del(void *data)
2180{
2181 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002182 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002183
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002184 spin_lock_irq(fcport->vha->host->host_lock);
Andrew Vasquezac280b62009-08-20 11:06:05 -07002185 rport = fcport->drport ? fcport->drport: fcport->rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002186 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002187 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002188 if (rport)
2189 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002190}
2191
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192/**
2193 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2194 * @ha: HA context
2195 * @flags: allocation flags
2196 *
2197 * Returns a pointer to the allocated fcport, or NULL, if none available.
2198 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002199static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002200qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201{
2202 fc_port_t *fcport;
2203
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002204 fcport = kzalloc(sizeof(fc_port_t), flags);
2205 if (!fcport)
2206 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207
2208 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002209 fcport->vha = vha;
2210 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002211 fcport->port_type = FCT_UNKNOWN;
2212 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002214 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002216 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217}
2218
2219/*
2220 * qla2x00_configure_loop
2221 * Updates Fibre Channel Device Database with what is actually on loop.
2222 *
2223 * Input:
2224 * ha = adapter block pointer.
2225 *
2226 * Returns:
2227 * 0 = success.
2228 * 1 = error.
2229 * 2 = database was full and device was not configured.
2230 */
2231static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002232qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233{
2234 int rval;
2235 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002236 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002237 rval = QLA_SUCCESS;
2238
2239 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002240 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2241 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 if (rval != QLA_SUCCESS) {
2243 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002244 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 return (rval);
2246 }
2247 }
2248
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002249 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002250 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002251 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253 /*
2254 * If we have both an RSCN and PORT UPDATE pending then handle them
2255 * both at the same time.
2256 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002257 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2258 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
2260 /* Determine what we need to do */
2261 if (ha->current_topology == ISP_CFG_FL &&
2262 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2263
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002264 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002265 set_bit(RSCN_UPDATE, &flags);
2266
2267 } else if (ha->current_topology == ISP_CFG_F &&
2268 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2269
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002270 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271 set_bit(RSCN_UPDATE, &flags);
2272 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2273
Andrew Vasquez21333b42006-05-17 15:09:56 -07002274 } else if (ha->current_topology == ISP_CFG_N) {
2275 clear_bit(RSCN_UPDATE, &flags);
2276
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002280 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002281 set_bit(RSCN_UPDATE, &flags);
2282 set_bit(LOCAL_LOOP_UPDATE, &flags);
2283 }
2284
2285 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002286 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002288 else
2289 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290 }
2291
2292 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002293 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002295 else
2296 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002297 }
2298
2299 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002300 if (atomic_read(&vha->loop_down_timer) ||
2301 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302 rval = QLA_FUNCTION_FAILED;
2303 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002306 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002307 }
2308 }
2309
2310 if (rval) {
2311 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002313 } else {
2314 DEBUG3(printk("%s: exiting normally\n", __func__));
2315 }
2316
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002317 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002318 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002319 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002320 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002321 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002322 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002323 vha->flags.rscn_queue_overflow = 1;
2324 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002325 }
2326
2327 return (rval);
2328}
2329
2330
2331
2332/*
2333 * qla2x00_configure_local_loop
2334 * Updates Fibre Channel Device Database with local loop devices.
2335 *
2336 * Input:
2337 * ha = adapter block pointer.
2338 *
2339 * Returns:
2340 * 0 = success.
2341 */
2342static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002343qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002344{
2345 int rval, rval2;
2346 int found_devs;
2347 int found;
2348 fc_port_t *fcport, *new_fcport;
2349
2350 uint16_t index;
2351 uint16_t entries;
2352 char *id_iter;
2353 uint16_t loop_id;
2354 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002356
2357 found_devs = 0;
2358 new_fcport = NULL;
2359 entries = MAX_FIBRE_DEVICES;
2360
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2362 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363
2364 /* Get list of logged in devices. */
2365 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 &entries);
2368 if (rval != QLA_SUCCESS)
2369 goto cleanup_allocation;
2370
2371 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002372 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002373 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2374 entries * sizeof(struct gid_list_info)));
2375
2376 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 if (new_fcport == NULL) {
2379 rval = QLA_MEMORY_ALLOC_FAILED;
2380 goto cleanup_allocation;
2381 }
2382 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2383
2384 /*
2385 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2386 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2389 fcport->port_type != FCT_BROADCAST &&
2390 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2391
2392 DEBUG(printk("scsi(%ld): Marking port lost, "
2393 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395
2396 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 }
2398 }
2399
2400 /* Add devices to port list. */
2401 id_iter = (char *)ha->gid_list;
2402 for (index = 0; index < entries; index++) {
2403 domain = ((struct gid_list_info *)id_iter)->domain;
2404 area = ((struct gid_list_info *)id_iter)->area;
2405 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002406 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002407 loop_id = (uint16_t)
2408 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002409 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 loop_id = le16_to_cpu(
2411 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002412 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
2414 /* Bypass reserved domain fields. */
2415 if ((domain & 0xf0) == 0xf0)
2416 continue;
2417
2418 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002419 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 continue;
2422
2423 /* Bypass invalid local loop ID. */
2424 if (loop_id > LAST_LOCAL_LOOP_ID)
2425 continue;
2426
2427 /* Fill in member data. */
2428 new_fcport->d_id.b.domain = domain;
2429 new_fcport->d_id.b.area = area;
2430 new_fcport->d_id.b.al_pa = al_pa;
2431 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002432 new_fcport->vp_idx = vha->vp_idx;
2433 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 if (rval2 != QLA_SUCCESS) {
2435 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2436 "information -- get_port_database=%x, "
2437 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002439 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 vha->host_no));
2441 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002442 continue;
2443 }
2444
2445 /* Check for matching device in port list. */
2446 found = 0;
2447 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 if (memcmp(new_fcport->port_name, fcport->port_name,
2450 WWN_SIZE))
2451 continue;
2452
Shyam Sundarddb9b122009-03-24 09:08:10 -07002453 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 fcport->loop_id = new_fcport->loop_id;
2455 fcport->port_type = new_fcport->port_type;
2456 fcport->d_id.b24 = new_fcport->d_id.b24;
2457 memcpy(fcport->node_name, new_fcport->node_name,
2458 WWN_SIZE);
2459
2460 found++;
2461 break;
2462 }
2463
2464 if (!found) {
2465 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 if (vha->vp_idx) {
2467 new_fcport->vha = vha;
2468 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002469 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
2472 /* Allocate a new replacement fcport. */
2473 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002474 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 if (new_fcport == NULL) {
2476 rval = QLA_MEMORY_ALLOC_FAILED;
2477 goto cleanup_allocation;
2478 }
2479 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2480 }
2481
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002482 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002483 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486
2487 found_devs++;
2488 }
2489
2490cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002491 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492
2493 if (rval != QLA_SUCCESS) {
2494 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 }
2497
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 return (rval);
2499}
2500
2501static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002502qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002503{
2504#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002505 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2506 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002507 int rval;
Harish Zunjarrao1bb39542009-06-17 10:30:29 -07002508 uint16_t mb[4];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002509 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002510
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002511 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002512 return;
2513
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002514 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2515 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002516 return;
2517
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002518 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002519 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002520 if (rval != QLA_SUCCESS) {
2521 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2522 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002524 fcport->port_name[2], fcport->port_name[3],
2525 fcport->port_name[4], fcport->port_name[5],
2526 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002527 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002528 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002529 link_speed = link_speeds[LS_UNKNOWN];
2530 if (fcport->fp_speed < 5)
2531 link_speed = link_speeds[fcport->fp_speed];
2532 else if (fcport->fp_speed == 0x13)
2533 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002534 DEBUG2(qla_printk(KERN_INFO, ha,
2535 "iIDMA adjusted to %s GB/s on "
2536 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002537 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002538 fcport->port_name[1], fcport->port_name[2],
2539 fcport->port_name[3], fcport->port_name[4],
2540 fcport->port_name[5], fcport->port_name[6],
2541 fcport->port_name[7]));
2542 }
2543}
2544
Adrian Bunk23be3312006-11-24 02:46:01 +01002545static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002546qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002547{
2548 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002549 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002550 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002551
Andrew Vasquezac280b62009-08-20 11:06:05 -07002552 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002553
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002554 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2555 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002556 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2557 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2558 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002560 if (!rport) {
2561 qla_printk(KERN_WARNING, ha,
2562 "Unable to allocate fc remote port!\n");
2563 return;
2564 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002565 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002566 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002568
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002569 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002570
2571 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002572 if (fcport->port_type == FCT_INITIATOR)
2573 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2574 if (fcport->port_type == FCT_TARGET)
2575 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002576 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002577}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
2579/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002580 * qla2x00_update_fcport
2581 * Updates device on list.
2582 *
2583 * Input:
2584 * ha = adapter block pointer.
2585 * fcport = port structure pointer.
2586 *
2587 * Return:
2588 * 0 - Success
2589 * BIT_0 - error
2590 *
2591 * Context:
2592 * Kernel context.
2593 */
2594void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002596{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002598
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002600 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002602 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002604 PORT_RETRY_TIME);
2605 fcport->flags &= ~FCF_LOGIN_NEEDED;
2606
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002607 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002608
2609 atomic_set(&fcport->state, FCS_ONLINE);
2610
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002612}
2613
2614/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 * qla2x00_configure_fabric
2616 * Setup SNS devices with loop ID's.
2617 *
2618 * Input:
2619 * ha = adapter block pointer.
2620 *
2621 * Returns:
2622 * 0 = success.
2623 * BIT_0 = error
2624 */
2625static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002626qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627{
2628 int rval, rval2;
2629 fc_port_t *fcport, *fcptemp;
2630 uint16_t next_loopid;
2631 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002632 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 struct qla_hw_data *ha = vha->hw;
2635 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636
2637 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002638 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002639 loop_id = NPH_F_PORT;
2640 else
2641 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 if (rval != QLA_SUCCESS) {
2644 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002645 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648 return (QLA_SUCCESS);
2649 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002650 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651
2652 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002653 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 if (rval2 == QLA_RSCNS_HANDLED) {
2655 /* No point doing the scan, just continue. */
2656 return (QLA_SUCCESS);
2657 }
2658 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002659 /* FDMI support. */
2660 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002661 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2662 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002663
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002665 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002666 loop_id = NPH_SNS;
2667 else
2668 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002669 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002670 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 if (mb[0] != MBS_COMMAND_COMPLETE) {
2672 DEBUG2(qla_printk(KERN_INFO, ha,
2673 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002674 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675 mb[0], mb[1], mb[2], mb[6], mb[7]));
2676 return (QLA_SUCCESS);
2677 }
2678
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2680 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 /* EMPTY */
2682 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002683 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 /* EMPTY */
2687 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002689 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002690 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 /* EMPTY */
2692 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002693 "failed.\n", vha->host_no));
2694 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002695 /* EMPTY */
2696 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 }
2699 }
2700
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 if (rval != QLA_SUCCESS)
2703 break;
2704
2705 /*
2706 * Logout all previous fabric devices marked lost, except
2707 * tape devices.
2708 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002709 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2710 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 break;
2712
2713 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2714 continue;
2715
2716 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002718 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 if (fcport->loop_id != FC_NO_LOOP_ID &&
2720 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2721 fcport->port_type != FCT_INITIATOR &&
2722 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002723 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002724 fcport->loop_id,
2725 fcport->d_id.b.domain,
2726 fcport->d_id.b.area,
2727 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 fcport->loop_id = FC_NO_LOOP_ID;
2729 }
2730 }
2731 }
2732
2733 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
2736 /*
2737 * Scan through our port list and login entries that need to be
2738 * logged in.
2739 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002740 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2741 if (atomic_read(&vha->loop_down_timer) ||
2742 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 break;
2744
2745 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2746 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2747 continue;
2748
2749 if (fcport->loop_id == FC_NO_LOOP_ID) {
2750 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002751 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002752 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753 if (rval != QLA_SUCCESS) {
2754 /* Ran out of IDs to use */
2755 break;
2756 }
2757 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 }
2761
2762 /* Exit if out of loop IDs. */
2763 if (rval != QLA_SUCCESS) {
2764 break;
2765 }
2766
2767 /*
2768 * Login and add the new devices to our port list.
2769 */
2770 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002771 if (atomic_read(&vha->loop_down_timer) ||
2772 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 break;
2774
2775 /* Find a new loop ID to use. */
2776 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002777 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002778 if (rval != QLA_SUCCESS) {
2779 /* Ran out of IDs to use */
2780 break;
2781 }
2782
bdf79622005-04-17 15:06:53 -05002783 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002784 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002785
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002786 if (vha->vp_idx) {
2787 fcport->vha = vha;
2788 fcport->vp_idx = vha->vp_idx;
2789 }
2790 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002791 }
2792 } while (0);
2793
2794 /* Free all new device structures not processed. */
2795 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2796 list_del(&fcport->list);
2797 kfree(fcport);
2798 }
2799
2800 if (rval) {
2801 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 }
2804
2805 return (rval);
2806}
2807
2808
2809/*
2810 * qla2x00_find_all_fabric_devs
2811 *
2812 * Input:
2813 * ha = adapter block pointer.
2814 * dev = database device entry pointer.
2815 *
2816 * Returns:
2817 * 0 = success.
2818 *
2819 * Context:
2820 * Kernel context.
2821 */
2822static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2824 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825{
2826 int rval;
2827 uint16_t loop_id;
2828 fc_port_t *fcport, *new_fcport, *fcptemp;
2829 int found;
2830
2831 sw_info_t *swl;
2832 int swl_idx;
2833 int first_dev, last_dev;
2834 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 struct qla_hw_data *ha = vha->hw;
2836 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002837 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002838
2839 rval = QLA_SUCCESS;
2840
2841 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002842 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002843 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 /*EMPTY*/
2845 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002846 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002847 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 kfree(swl);
2850 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 kfree(swl);
2853 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002854 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 kfree(swl);
2856 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002857 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002858 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2859 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 }
2861 }
2862 swl_idx = 0;
2863
2864 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002865 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002867 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 return (QLA_MEMORY_ALLOC_FAILED);
2869 }
2870 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 /* Set start port ID scan at adapter ID. */
2872 first_dev = 1;
2873 last_dev = 0;
2874
2875 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 loop_id = ha->min_external_loopid;
2877 for (; loop_id <= ha->max_loop_id; loop_id++) {
2878 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 continue;
2880
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882 break;
2883
2884 if (swl != NULL) {
2885 if (last_dev) {
2886 wrap.b24 = new_fcport->d_id.b24;
2887 } else {
2888 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2889 memcpy(new_fcport->node_name,
2890 swl[swl_idx].node_name, WWN_SIZE);
2891 memcpy(new_fcport->port_name,
2892 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002893 memcpy(new_fcport->fabric_port_name,
2894 swl[swl_idx].fabric_port_name, WWN_SIZE);
2895 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896
2897 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2898 last_dev = 1;
2899 }
2900 swl_idx++;
2901 }
2902 } else {
2903 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002904 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 if (rval != QLA_SUCCESS) {
2906 qla_printk(KERN_WARNING, ha,
2907 "SNS scan failed -- assuming zero-entry "
2908 "result...\n");
2909 list_for_each_entry_safe(fcport, fcptemp,
2910 new_fcports, list) {
2911 list_del(&fcport->list);
2912 kfree(fcport);
2913 }
2914 rval = QLA_SUCCESS;
2915 break;
2916 }
2917 }
2918
2919 /* If wrap on switch device list, exit. */
2920 if (first_dev) {
2921 wrap.b24 = new_fcport->d_id.b24;
2922 first_dev = 0;
2923 } else if (new_fcport->d_id.b24 == wrap.b24) {
2924 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2927 break;
2928 }
2929
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002930 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932 continue;
2933
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002934 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 found = 0;
2936 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002937 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2939 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002940 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002941 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002942 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002944 continue;
2945 }
2946
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002947 /* Bypass if same domain and area of adapter. */
2948 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002949 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002950 ISP_CFG_FL)
2951 continue;
2952
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 /* Bypass reserved domain fields. */
2954 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2955 continue;
2956
2957 /* Locate matching device in database. */
2958 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 if (memcmp(new_fcport->port_name, fcport->port_name,
2961 WWN_SIZE))
2962 continue;
2963
2964 found++;
2965
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002966 /* Update port state. */
2967 memcpy(fcport->fabric_port_name,
2968 new_fcport->fabric_port_name, WWN_SIZE);
2969 fcport->fp_speed = new_fcport->fp_speed;
2970
Linus Torvalds1da177e2005-04-16 15:20:36 -07002971 /*
2972 * If address the same and state FCS_ONLINE, nothing
2973 * changed.
2974 */
2975 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2976 atomic_read(&fcport->state) == FCS_ONLINE) {
2977 break;
2978 }
2979
2980 /*
2981 * If device was not a fabric device before.
2982 */
2983 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2984 fcport->d_id.b24 = new_fcport->d_id.b24;
2985 fcport->loop_id = FC_NO_LOOP_ID;
2986 fcport->flags |= (FCF_FABRIC_DEVICE |
2987 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 break;
2989 }
2990
2991 /*
2992 * Port ID changed or device was marked to be updated;
2993 * Log it out if still logged in and mark it for
2994 * relogin later.
2995 */
2996 fcport->d_id.b24 = new_fcport->d_id.b24;
2997 fcport->flags |= FCF_LOGIN_NEEDED;
2998 if (fcport->loop_id != FC_NO_LOOP_ID &&
2999 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
3000 fcport->port_type != FCT_INITIATOR &&
3001 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003003 fcport->d_id.b.domain, fcport->d_id.b.area,
3004 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 fcport->loop_id = FC_NO_LOOP_ID;
3006 }
3007
3008 break;
3009 }
3010
3011 if (found)
3012 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 /* If device was not in our fcports list, then add it. */
3014 list_add_tail(&new_fcport->list, new_fcports);
3015
3016 /* Allocate a new replacement fcport. */
3017 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003018 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003020 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021 return (QLA_MEMORY_ALLOC_FAILED);
3022 }
3023 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
3024 new_fcport->d_id.b24 = nxt_d_id.b24;
3025 }
3026
Jesper Juhlc9475cb2005-11-07 01:01:26 -08003027 kfree(swl);
3028 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030 return (rval);
3031}
3032
3033/*
3034 * qla2x00_find_new_loop_id
3035 * Scan through our port list and find a new usable loop ID.
3036 *
3037 * Input:
3038 * ha: adapter state pointer.
3039 * dev: port structure pointer.
3040 *
3041 * Returns:
3042 * qla2x00 local function return status code.
3043 *
3044 * Context:
3045 * Kernel context.
3046 */
Adrian Bunk413975a2006-06-30 02:33:06 -07003047static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003048qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049{
3050 int rval;
3051 int found;
3052 fc_port_t *fcport;
3053 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003054 struct qla_hw_data *ha = vha->hw;
3055 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003056 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
3058 rval = QLA_SUCCESS;
3059
3060 /* Save starting loop ID. */
3061 first_loop_id = dev->loop_id;
3062
3063 for (;;) {
3064 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003065 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
3068 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003069 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003070 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071
3072 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003073 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003074 /* first loop ID. */
3075 dev->loop_id = ha->min_external_loopid;
3076 }
3077
3078 /* Check for loop ID being already in use. */
3079 found = 0;
3080 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003081 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 list_for_each_entry(fcport, &vp->vp_fcports, list) {
3083 if (fcport->loop_id == dev->loop_id &&
3084 fcport != dev) {
3085 /* ID possibly in use */
3086 found++;
3087 break;
3088 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003090 if (found)
3091 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 }
3093
3094 /* If not in use then it is free to use. */
3095 if (!found) {
3096 break;
3097 }
3098
3099 /* ID in use. Try next value. */
3100 dev->loop_id++;
3101
3102 /* If wrap around. No free ID to use. */
3103 if (dev->loop_id == first_loop_id) {
3104 dev->loop_id = FC_NO_LOOP_ID;
3105 rval = QLA_FUNCTION_FAILED;
3106 break;
3107 }
3108 }
3109
3110 return (rval);
3111}
3112
3113/*
3114 * qla2x00_device_resync
3115 * Marks devices in the database that needs resynchronization.
3116 *
3117 * Input:
3118 * ha = adapter block pointer.
3119 *
3120 * Context:
3121 * Kernel context.
3122 */
3123static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003124qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125{
3126 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 uint32_t mask;
3128 fc_port_t *fcport;
3129 uint32_t rscn_entry;
3130 uint8_t rscn_out_iter;
3131 uint8_t format;
3132 port_id_t d_id;
3133
3134 rval = QLA_RSCNS_HANDLED;
3135
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003136 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
3137 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003139 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003140 format = MSB(MSW(rscn_entry));
3141 d_id.b.domain = LSB(MSW(rscn_entry));
3142 d_id.b.area = MSB(LSW(rscn_entry));
3143 d_id.b.al_pa = LSB(LSW(rscn_entry));
3144
3145 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
3146 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003147 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148 d_id.b.area, d_id.b.al_pa));
3149
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 vha->rscn_out_ptr++;
3151 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
3152 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
3154 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 for (rscn_out_iter = vha->rscn_out_ptr;
3156 !vha->flags.rscn_queue_overflow &&
3157 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003158 rscn_out_iter = (rscn_out_iter ==
3159 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
3160
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003161 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07003162 break;
3163
3164 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003165 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003166 rscn_out_iter));
3167
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
3170
3171 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003172 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003174 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003175
3176 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003177 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 }
3179
3180 switch (format) {
3181 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 mask = 0xffffff;
3183 break;
3184 case 1:
3185 mask = 0xffff00;
3186 break;
3187 case 2:
3188 mask = 0xff0000;
3189 break;
3190 default:
3191 mask = 0x0;
3192 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 break;
3195 }
3196
3197 rval = QLA_SUCCESS;
3198
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003199 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
3201 (fcport->d_id.b24 & mask) != d_id.b24 ||
3202 fcport->port_type == FCT_BROADCAST)
3203 continue;
3204
3205 if (atomic_read(&fcport->state) == FCS_ONLINE) {
3206 if (format != 3 ||
3207 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003208 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003209 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 }
3211 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 }
3213 }
3214 return (rval);
3215}
3216
3217/*
3218 * qla2x00_fabric_dev_login
3219 * Login fabric target device and update FC port database.
3220 *
3221 * Input:
3222 * ha: adapter state pointer.
3223 * fcport: port structure list pointer.
3224 * next_loopid: contains value of a new loop ID that can be used
3225 * by the next login attempt.
3226 *
3227 * Returns:
3228 * qla2x00 local function return status code.
3229 *
3230 * Context:
3231 * Kernel context.
3232 */
3233static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 uint16_t *next_loopid)
3236{
3237 int rval;
3238 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003239 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003240 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
3242 rval = QLA_SUCCESS;
3243 retry = 0;
3244
Andrew Vasquezac280b62009-08-20 11:06:05 -07003245 if (IS_ALOGIO_CAPABLE(ha)) {
3246 rval = qla2x00_post_async_login_work(vha, fcport, NULL);
3247 if (!rval)
3248 return rval;
3249 }
3250
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003253 /* Send an ADISC to tape devices.*/
3254 opts = 0;
3255 if (fcport->flags & FCF_TAPE_PRESENT)
3256 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003260 fcport->d_id.b.domain, fcport->d_id.b.area,
3261 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003262 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003264 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265 }
3266 }
3267
3268 return (rval);
3269}
3270
3271/*
3272 * qla2x00_fabric_login
3273 * Issue fabric login command.
3274 *
3275 * Input:
3276 * ha = adapter block pointer.
3277 * device = pointer to FC device type structure.
3278 *
3279 * Returns:
3280 * 0 - Login successfully
3281 * 1 - Login failed
3282 * 2 - Initiator device
3283 * 3 - Fatal error
3284 */
3285int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003286qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 uint16_t *next_loopid)
3288{
3289 int rval;
3290 int retry;
3291 uint16_t tmp_loopid;
3292 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294
3295 retry = 0;
3296 tmp_loopid = 0;
3297
3298 for (;;) {
3299 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3300 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3303
3304 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 fcport->d_id.b.domain, fcport->d_id.b.area,
3307 fcport->d_id.b.al_pa, mb, BIT_0);
3308 if (mb[0] == MBS_PORT_ID_USED) {
3309 /*
3310 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003311 * recommends the driver perform an implicit login with
3312 * the specified ID again. The ID we just used is save
3313 * here so we return with an ID that can be tried by
3314 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 */
3316 retry++;
3317 tmp_loopid = fcport->loop_id;
3318 fcport->loop_id = mb[1];
3319
3320 DEBUG(printk("Fabric Login: port in use - next "
3321 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3322 fcport->loop_id, fcport->d_id.b.domain,
3323 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3324
3325 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3326 /*
3327 * Login succeeded.
3328 */
3329 if (retry) {
3330 /* A retry occurred before. */
3331 *next_loopid = tmp_loopid;
3332 } else {
3333 /*
3334 * No retry occurred before. Just increment the
3335 * ID value for next login.
3336 */
3337 *next_loopid = (fcport->loop_id + 1);
3338 }
3339
3340 if (mb[1] & BIT_0) {
3341 fcport->port_type = FCT_INITIATOR;
3342 } else {
3343 fcport->port_type = FCT_TARGET;
3344 if (mb[1] & BIT_1) {
Santosh Vernekar8474f3a2009-08-25 11:36:16 -07003345 fcport->flags |= FCF_FCP2_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 }
3347 }
3348
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003349 if (mb[10] & BIT_0)
3350 fcport->supported_classes |= FC_COS_CLASS2;
3351 if (mb[10] & BIT_1)
3352 fcport->supported_classes |= FC_COS_CLASS3;
3353
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 rval = QLA_SUCCESS;
3355 break;
3356 } else if (mb[0] == MBS_LOOP_ID_USED) {
3357 /*
3358 * Loop ID already used, try next loop ID.
3359 */
3360 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003361 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003362 if (rval != QLA_SUCCESS) {
3363 /* Ran out of loop IDs to use */
3364 break;
3365 }
3366 } else if (mb[0] == MBS_COMMAND_ERROR) {
3367 /*
3368 * Firmware possibly timed out during login. If NO
3369 * retries are left to do then the device is declared
3370 * dead.
3371 */
3372 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003373 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003374 fcport->d_id.b.domain, fcport->d_id.b.area,
3375 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003376 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377
3378 rval = 1;
3379 break;
3380 } else {
3381 /*
3382 * unrecoverable / not handled error
3383 */
3384 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003385 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 fcport->d_id.b.domain, fcport->d_id.b.area,
3388 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3389
3390 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003391 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003392 fcport->d_id.b.domain, fcport->d_id.b.area,
3393 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003395 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396
3397 rval = 3;
3398 break;
3399 }
3400 }
3401
3402 return (rval);
3403}
3404
3405/*
3406 * qla2x00_local_device_login
3407 * Issue local device login command.
3408 *
3409 * Input:
3410 * ha = adapter block pointer.
3411 * loop_id = loop id of device to login to.
3412 *
3413 * Returns (Where's the #define!!!!):
3414 * 0 - Login successfully
3415 * 1 - Login failed
3416 * 3 - Fatal error
3417 */
3418int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003419qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420{
3421 int rval;
3422 uint16_t mb[MAILBOX_REGISTER_COUNT];
3423
3424 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003425 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 if (rval == QLA_SUCCESS) {
3427 /* Interrogate mailbox registers for any errors */
3428 if (mb[0] == MBS_COMMAND_ERROR)
3429 rval = 1;
3430 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3431 /* device not in PCB table */
3432 rval = 3;
3433 }
3434
3435 return (rval);
3436}
3437
3438/*
3439 * qla2x00_loop_resync
3440 * Resync with fibre channel devices.
3441 *
3442 * Input:
3443 * ha = adapter block pointer.
3444 *
3445 * Returns:
3446 * 0 = success
3447 */
3448int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003449qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003451 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003453 struct req_que *req;
3454 struct rsp_que *rsp;
3455
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07003456 if (vha->hw->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003457 req = vha->hw->req_q_map[0];
3458 else
3459 req = vha->req;
3460 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462 atomic_set(&vha->loop_state, LOOP_UPDATE);
3463 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3464 if (vha->flags.online) {
3465 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003466 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3467 wait_time = 256;
3468 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003469 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003471 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003472 qla2x00_marker(vha, req, rsp, 0, 0,
3473 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003474 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003475
3476 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003477 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003479 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003480 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003481 } while (!atomic_read(&vha->loop_down_timer) &&
3482 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3483 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3484 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003485 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003486 }
3487
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003488 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003489 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003491 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003493
3494 return (rval);
3495}
3496
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497void
Andrew Vasquez67becc02009-08-25 11:36:20 -07003498qla2x00_update_fcports(scsi_qla_host_t *base_vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003499{
3500 fc_port_t *fcport;
Andrew Vasquez67becc02009-08-25 11:36:20 -07003501 struct scsi_qla_host *tvp, *vha;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003502
3503 /* Go with deferred removal of rport references. */
Andrew Vasquez67becc02009-08-25 11:36:20 -07003504 list_for_each_entry_safe(vha, tvp, &base_vha->hw->vp_list, list)
3505 list_for_each_entry(fcport, &vha->vp_fcports, list)
3506 if (fcport && fcport->drport &&
3507 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
3508 qla2x00_rport_del(fcport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003509}
3510
Linus Torvalds1da177e2005-04-16 15:20:36 -07003511/*
3512* qla2x00_abort_isp
3513* Resets ISP and aborts all outstanding commands.
3514*
3515* Input:
3516* ha = adapter block pointer.
3517*
3518* Returns:
3519* 0 = success
3520*/
3521int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003522qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003524 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003526 struct qla_hw_data *ha = vha->hw;
3527 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003528 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003529 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 if (vha->flags.online) {
3532 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003533 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003534 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003535 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536
3537 qla_printk(KERN_INFO, ha,
3538 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003539 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3542 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3543 atomic_set(&vha->loop_state, LOOP_DOWN);
3544 qla2x00_mark_all_devices_lost(vha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003545 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003546 if (!atomic_read(&vha->loop_down_timer))
3547 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548 LOOP_DOWN_TIME);
3549 }
3550
Linus Torvalds1da177e2005-04-16 15:20:36 -07003551 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003554 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003555
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003557
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003558 if (!qla2x00_restart_isp(vha)) {
3559 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003560
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003561 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003562 /*
3563 * Issue marker command only when we are going
3564 * to start the I/O .
3565 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003566 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003567 }
3568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003569 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003570
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003571 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003572
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003573 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003575
Lalit Chandivade29c53972009-10-13 15:16:47 -07003576 if (IS_QLA81XX(ha))
3577 qla2x00_get_fw_version(vha,
3578 &ha->fw_major_version,
3579 &ha->fw_minor_version,
3580 &ha->fw_subminor_version,
3581 &ha->fw_attributes, &ha->fw_memory_size,
3582 ha->mpi_version, &ha->mpi_capabilities,
3583 ha->phy_version);
3584
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003585 if (ha->fce) {
3586 ha->flags.fce_enabled = 1;
3587 memset(ha->fce, 0,
3588 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003589 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003590 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3591 &ha->fce_bufs);
3592 if (rval) {
3593 qla_printk(KERN_WARNING, ha,
3594 "Unable to reinitialize FCE "
3595 "(%d).\n", rval);
3596 ha->flags.fce_enabled = 0;
3597 }
3598 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003599
3600 if (ha->eft) {
3601 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003603 ha->eft_dma, EFT_NUM_BUFFERS);
3604 if (rval) {
3605 qla_printk(KERN_WARNING, ha,
3606 "Unable to reinitialize EFT "
3607 "(%d).\n", rval);
3608 }
3609 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003610 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003611 vha->flags.online = 1;
3612 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003613 if (ha->isp_abort_cnt == 0) {
3614 qla_printk(KERN_WARNING, ha,
3615 "ISP error recovery failed - "
3616 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003617 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003618 * The next call disables the board
3619 * completely.
3620 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003621 ha->isp_ops->reset_adapter(vha);
3622 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003623 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003624 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003625 status = 0;
3626 } else { /* schedule another ISP abort */
3627 ha->isp_abort_cnt--;
3628 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003629 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003630 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003631 status = 1;
3632 }
3633 } else {
3634 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3635 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3636 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003637 vha->host_no, ha->isp_abort_cnt));
3638 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003639 status = 1;
3640 }
3641 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003642
Linus Torvalds1da177e2005-04-16 15:20:36 -07003643 }
3644
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003645 if (!status) {
3646 DEBUG(printk(KERN_INFO
3647 "qla2x00_abort_isp(%ld): succeeded.\n",
3648 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003649 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003650 if (vp->vp_idx)
3651 qla2x00_vp_abort_isp(vp);
3652 }
3653 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003654 qla_printk(KERN_INFO, ha,
3655 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003656 }
3657
3658 return(status);
3659}
3660
3661/*
3662* qla2x00_restart_isp
3663* restarts the ISP after a reset
3664*
3665* Input:
3666* ha = adapter block pointer.
3667*
3668* Returns:
3669* 0 = success
3670*/
3671static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003672qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003673{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003674 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003675 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003676 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003677 struct req_que *req = ha->req_q_map[0];
3678 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003679
3680 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003681 if (qla2x00_isp_firmware(vha)) {
3682 vha->flags.online = 0;
3683 status = ha->isp_ops->chip_diag(vha);
3684 if (!status)
3685 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003686 }
3687
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688 if (!status && !(status = qla2x00_init_rings(vha))) {
3689 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003690 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003691 /* Initialize the queues in use */
3692 qla25xx_init_queues(ha);
3693
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003694 status = qla2x00_fw_ready(vha);
3695 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003696 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003697 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003698
3699 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003700 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003701
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003702 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003703 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3704 wait_time = 256;
3705 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003706 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3707 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003708 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003709 } while (!atomic_read(&vha->loop_down_timer) &&
3710 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3711 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3712 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003713 }
3714
3715 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003716 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003717 status = 0;
3718
3719 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3720 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003721 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003722 }
3723 return (status);
3724}
3725
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003726static int
3727qla25xx_init_queues(struct qla_hw_data *ha)
3728{
3729 struct rsp_que *rsp = NULL;
3730 struct req_que *req = NULL;
3731 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3732 int ret = -1;
3733 int i;
3734
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003735 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003736 rsp = ha->rsp_q_map[i];
3737 if (rsp) {
3738 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003739 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003740 if (ret != QLA_SUCCESS)
3741 DEBUG2_17(printk(KERN_WARNING
3742 "%s Rsp que:%d init failed\n", __func__,
3743 rsp->id));
3744 else
3745 DEBUG2_17(printk(KERN_INFO
3746 "%s Rsp que:%d inited\n", __func__,
3747 rsp->id));
3748 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003749 }
3750 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003751 req = ha->req_q_map[i];
3752 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003753 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003754 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003755 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003756 if (ret != QLA_SUCCESS)
3757 DEBUG2_17(printk(KERN_WARNING
3758 "%s Req que:%d init failed\n", __func__,
3759 req->id));
3760 else
3761 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003762 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003763 req->id));
3764 }
3765 }
3766 return ret;
3767}
3768
Linus Torvalds1da177e2005-04-16 15:20:36 -07003769/*
3770* qla2x00_reset_adapter
3771* Reset adapter.
3772*
3773* Input:
3774* ha = adapter block pointer.
3775*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003776void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003777qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003778{
3779 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003780 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003781 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003782
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003784 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003785
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 spin_lock_irqsave(&ha->hardware_lock, flags);
3787 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3788 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3789 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3790 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3791 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3792}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003793
3794void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003795qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003796{
3797 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003798 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003799 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3800
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003802 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003803
3804 spin_lock_irqsave(&ha->hardware_lock, flags);
3805 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3806 RD_REG_DWORD(&reg->hccr);
3807 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3808 RD_REG_DWORD(&reg->hccr);
3809 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003810
3811 if (IS_NOPOLLING_TYPE(ha))
3812 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003813}
3814
David Miller4e08df32007-04-16 12:37:43 -07003815/* On sparc systems, obtain port and node WWN from firmware
3816 * properties.
3817 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3819 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003820{
3821#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003822 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003823 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003824 struct device_node *dp = pci_device_to_OF_node(pdev);
3825 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003826 int len;
3827
3828 val = of_get_property(dp, "port-wwn", &len);
3829 if (val && len >= WWN_SIZE)
3830 memcpy(nv->port_name, val, WWN_SIZE);
3831
3832 val = of_get_property(dp, "node-wwn", &len);
3833 if (val && len >= WWN_SIZE)
3834 memcpy(nv->node_name, val, WWN_SIZE);
3835#endif
3836}
3837
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003838int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003839qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003840{
David Miller4e08df32007-04-16 12:37:43 -07003841 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003842 struct init_cb_24xx *icb;
3843 struct nvram_24xx *nv;
3844 uint32_t *dptr;
3845 uint8_t *dptr1, *dptr2;
3846 uint32_t chksum;
3847 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003848 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003849
David Miller4e08df32007-04-16 12:37:43 -07003850 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003851 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003852 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003853
3854 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003855 if (ha->flags.port0) {
3856 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3857 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3858 } else {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003859 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003860 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3861 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003862 ha->nvram_size = sizeof(struct nvram_24xx);
3863 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003864
Seokmann Ju281afe12007-07-26 13:43:34 -07003865 /* Get VPD data into cache */
3866 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003867 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003868 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3869
3870 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003871 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003873 ha->nvram_size);
3874 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3875 chksum += le32_to_cpu(*dptr++);
3876
Andrew Vasquez76403352009-04-06 22:33:39 -07003877 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003878 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003879
3880 /* Bad NVRAM data, set defaults parameters. */
3881 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3882 || nv->id[3] != ' ' ||
3883 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3884 /* Reset NVRAM data. */
3885 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3886 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3887 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003888 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3889 "invalid -- WWPN) defaults.\n");
3890
3891 /*
3892 * Set default initialization control block.
3893 */
3894 memset(nv, 0, ha->nvram_size);
3895 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3896 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3897 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3898 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3899 nv->exchange_count = __constant_cpu_to_le16(0);
3900 nv->hard_address = __constant_cpu_to_le16(124);
3901 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003902 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07003903 nv->port_name[2] = 0x00;
3904 nv->port_name[3] = 0xe0;
3905 nv->port_name[4] = 0x8b;
3906 nv->port_name[5] = 0x1c;
3907 nv->port_name[6] = 0x55;
3908 nv->port_name[7] = 0x86;
3909 nv->node_name[0] = 0x20;
3910 nv->node_name[1] = 0x00;
3911 nv->node_name[2] = 0x00;
3912 nv->node_name[3] = 0xe0;
3913 nv->node_name[4] = 0x8b;
3914 nv->node_name[5] = 0x1c;
3915 nv->node_name[6] = 0x55;
3916 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003918 nv->login_retry_count = __constant_cpu_to_le16(8);
3919 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3920 nv->login_timeout = __constant_cpu_to_le16(0);
3921 nv->firmware_options_1 =
3922 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3923 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3924 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3925 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3926 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3927 nv->efi_parameters = __constant_cpu_to_le32(0);
3928 nv->reset_delay = 5;
3929 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3930 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3931 nv->link_down_timeout = __constant_cpu_to_le16(30);
3932
3933 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003934 }
3935
3936 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003937 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003938
3939 /* Copy 1st segment. */
3940 dptr1 = (uint8_t *)icb;
3941 dptr2 = (uint8_t *)&nv->version;
3942 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3943 while (cnt--)
3944 *dptr1++ = *dptr2++;
3945
3946 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003947 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003948
3949 /* Copy 2nd segment. */
3950 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3951 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3952 cnt = (uint8_t *)&icb->reserved_3 -
3953 (uint8_t *)&icb->interrupt_delay_timer;
3954 while (cnt--)
3955 *dptr1++ = *dptr2++;
3956
3957 /*
3958 * Setup driver NVRAM options.
3959 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003960 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003961 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003962
Andrew Vasquez5341e862006-05-17 15:09:16 -07003963 /* Use alternate WWN? */
3964 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3965 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3966 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3967 }
3968
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003969 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003970 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003971 /*
3972 * Firmware will apply the following mask if the nodename was
3973 * not provided.
3974 */
3975 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3976 icb->node_name[0] &= 0xF0;
3977 }
3978
3979 /* Set host adapter parameters. */
3980 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003981 ha->flags.enable_lip_reset = 0;
3982 ha->flags.enable_lip_full_login =
3983 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3984 ha->flags.enable_target_reset =
3985 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003986 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003987 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003988
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003989 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3990 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003991
3992 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3993 sizeof(ha->fw_seriallink_options24));
3994
3995 /* save HBA serial number */
3996 ha->serial0 = icb->port_name[5];
3997 ha->serial1 = icb->port_name[6];
3998 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003999 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4000 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004001
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08004002 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4003
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004004 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4005
4006 /* Set minimum login_timeout to 4 seconds. */
4007 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4008 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4009 if (le16_to_cpu(nv->login_timeout) < 4)
4010 nv->login_timeout = __constant_cpu_to_le16(4);
4011 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07004012 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004013
Andrew Vasquez00a537b2008-02-28 14:06:11 -08004014 /* Set minimum RATOV to 100 tenths of a second. */
4015 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004016
4017 ha->loop_reset_delay = nv->reset_delay;
4018
4019 /* Link Down Timeout = 0:
4020 *
4021 * When Port Down timer expires we will start returning
4022 * I/O's to OS with "DID_NO_CONNECT".
4023 *
4024 * Link Down Timeout != 0:
4025 *
4026 * The driver waits for the link to come up after link down
4027 * before returning I/Os to OS with "DID_NO_CONNECT".
4028 */
4029 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4030 ha->loop_down_abort_time =
4031 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4032 } else {
4033 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4034 ha->loop_down_abort_time =
4035 (LOOP_DOWN_TIME - ha->link_down_timeout);
4036 }
4037
4038 /* Need enough time to try and get the port back. */
4039 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4040 if (qlport_down_retry)
4041 ha->port_down_retry_count = qlport_down_retry;
4042
4043 /* Set login_retry_count */
4044 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4045 if (ha->port_down_retry_count ==
4046 le16_to_cpu(nv->port_down_retry_count) &&
4047 ha->port_down_retry_count > 3)
4048 ha->login_retry_count = ha->port_down_retry_count;
4049 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4050 ha->login_retry_count = ha->port_down_retry_count;
4051 if (ql2xloginretrycount)
4052 ha->login_retry_count = ql2xloginretrycount;
4053
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004054 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004055 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004056 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4057 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4058 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4059 le16_to_cpu(icb->interrupt_delay_timer): 2;
4060 }
4061 icb->firmware_options_2 &= __constant_cpu_to_le32(
4062 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004063 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004064 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08004065 ha->zio_mode = QLA_ZIO_MODE_6;
4066
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004067 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004068 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004069 ha->zio_timer * 100));
4070 qla_printk(KERN_INFO, ha,
4071 "ZIO mode %d enabled; timer delay (%d us).\n",
4072 ha->zio_mode, ha->zio_timer * 100);
4073
4074 icb->firmware_options_2 |= cpu_to_le32(
4075 (uint32_t)ha->zio_mode);
4076 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004077 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07004078 }
4079
David Miller4e08df32007-04-16 12:37:43 -07004080 if (rval) {
4081 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004082 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07004083 }
4084 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004085}
4086
Adrian Bunk413975a2006-06-30 02:33:06 -07004087static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004088qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
4089 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004090{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004091 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004092 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004093 uint32_t *dcode, dlen;
4094 uint32_t risc_addr;
4095 uint32_t risc_size;
4096 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004097 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004098 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004099
4100 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004101 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004102
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004103 rval = QLA_SUCCESS;
4104
4105 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004106 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004107 *srisc_addr = 0;
4108
4109 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004110 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004111 for (i = 0; i < 4; i++)
4112 dcode[i] = be32_to_cpu(dcode[i]);
4113 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4114 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4115 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4116 dcode[3] == 0)) {
4117 qla_printk(KERN_WARNING, ha,
4118 "Unable to verify integrity of flash firmware image!\n");
4119 qla_printk(KERN_WARNING, ha,
4120 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4121 dcode[1], dcode[2], dcode[3]);
4122
4123 return QLA_FUNCTION_FAILED;
4124 }
4125
4126 while (segments && rval == QLA_SUCCESS) {
4127 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004128 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004129
4130 risc_addr = be32_to_cpu(dcode[2]);
4131 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4132 risc_size = be32_to_cpu(dcode[3]);
4133
4134 fragment = 0;
4135 while (risc_size > 0 && rval == QLA_SUCCESS) {
4136 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4137 if (dlen > risc_size)
4138 dlen = risc_size;
4139
4140 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
4141 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004142 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004143
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004144 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004145 for (i = 0; i < dlen; i++)
4146 dcode[i] = swab32(dcode[i]);
4147
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004148 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004149 dlen);
4150 if (rval) {
4151 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004152 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004153 fragment));
4154 qla_printk(KERN_WARNING, ha,
4155 "[ERROR] Failed to load segment %d of "
4156 "firmware\n", fragment);
4157 break;
4158 }
4159
4160 faddr += dlen;
4161 risc_addr += dlen;
4162 risc_size -= dlen;
4163 fragment++;
4164 }
4165
4166 /* Next segment. */
4167 segments--;
4168 }
4169
4170 return rval;
4171}
4172
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004173#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4174
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004175int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08004177{
4178 int rval;
4179 int i, fragment;
4180 uint16_t *wcode, *fwcode;
4181 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
4182 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004183 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004184 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08004185
4186 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004188 if (!blob) {
4189 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004190 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4191 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08004192 return QLA_FUNCTION_FAILED;
4193 }
4194
4195 rval = QLA_SUCCESS;
4196
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004197 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08004198 *srisc_addr = 0;
4199 fwcode = (uint16_t *)blob->fw->data;
4200 fwclen = 0;
4201
4202 /* Validate firmware image by checking version. */
4203 if (blob->fw->size < 8 * sizeof(uint16_t)) {
4204 qla_printk(KERN_WARNING, ha,
4205 "Unable to verify integrity of firmware image (%Zd)!\n",
4206 blob->fw->size);
4207 goto fail_fw_integrity;
4208 }
4209 for (i = 0; i < 4; i++)
4210 wcode[i] = be16_to_cpu(fwcode[i + 4]);
4211 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
4212 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
4213 wcode[2] == 0 && wcode[3] == 0)) {
4214 qla_printk(KERN_WARNING, ha,
4215 "Unable to verify integrity of firmware image!\n");
4216 qla_printk(KERN_WARNING, ha,
4217 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
4218 wcode[1], wcode[2], wcode[3]);
4219 goto fail_fw_integrity;
4220 }
4221
4222 seg = blob->segs;
4223 while (*seg && rval == QLA_SUCCESS) {
4224 risc_addr = *seg;
4225 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
4226 risc_size = be16_to_cpu(fwcode[3]);
4227
4228 /* Validate firmware image size. */
4229 fwclen += risc_size * sizeof(uint16_t);
4230 if (blob->fw->size < fwclen) {
4231 qla_printk(KERN_WARNING, ha,
4232 "Unable to verify integrity of firmware image "
4233 "(%Zd)!\n", blob->fw->size);
4234 goto fail_fw_integrity;
4235 }
4236
4237 fragment = 0;
4238 while (risc_size > 0 && rval == QLA_SUCCESS) {
4239 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4240 if (wlen > risc_size)
4241 wlen = risc_size;
4242
4243 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004244 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004245 risc_addr, wlen));
4246
4247 for (i = 0; i < wlen; i++)
4248 wcode[i] = swab16(fwcode[i]);
4249
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004250 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004251 wlen);
4252 if (rval) {
4253 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004254 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004255 fragment));
4256 qla_printk(KERN_WARNING, ha,
4257 "[ERROR] Failed to load segment %d of "
4258 "firmware\n", fragment);
4259 break;
4260 }
4261
4262 fwcode += wlen;
4263 risc_addr += wlen;
4264 risc_size -= wlen;
4265 fragment++;
4266 }
4267
4268 /* Next segment. */
4269 seg++;
4270 }
4271 return rval;
4272
4273fail_fw_integrity:
4274 return QLA_FUNCTION_FAILED;
4275}
4276
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004277static int
4278qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004279{
4280 int rval;
4281 int segments, fragment;
4282 uint32_t *dcode, dlen;
4283 uint32_t risc_addr;
4284 uint32_t risc_size;
4285 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004286 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004287 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004288 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004289 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004290
Andrew Vasquez54333832005-11-09 15:49:04 -08004291 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004292 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004293 if (!blob) {
4294 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004295 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4296 "from: " QLA_FW_URL ".\n");
4297
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004298 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004299 }
4300
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004301 qla_printk(KERN_INFO, ha,
4302 "FW: Loading via request-firmware...\n");
4303
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004304 rval = QLA_SUCCESS;
4305
4306 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004307 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004308 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004309 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004310 fwclen = 0;
4311
4312 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004313 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004314 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004315 "Unable to verify integrity of firmware image (%Zd)!\n",
4316 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004317 goto fail_fw_integrity;
4318 }
4319 for (i = 0; i < 4; i++)
4320 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4321 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4322 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4323 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4324 dcode[3] == 0)) {
4325 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004326 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004327 qla_printk(KERN_WARNING, ha,
4328 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4329 dcode[1], dcode[2], dcode[3]);
4330 goto fail_fw_integrity;
4331 }
4332
4333 while (segments && rval == QLA_SUCCESS) {
4334 risc_addr = be32_to_cpu(fwcode[2]);
4335 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4336 risc_size = be32_to_cpu(fwcode[3]);
4337
4338 /* Validate firmware image size. */
4339 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004340 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004341 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004342 "Unable to verify integrity of firmware image "
4343 "(%Zd)!\n", blob->fw->size);
4344
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004345 goto fail_fw_integrity;
4346 }
4347
4348 fragment = 0;
4349 while (risc_size > 0 && rval == QLA_SUCCESS) {
4350 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4351 if (dlen > risc_size)
4352 dlen = risc_size;
4353
4354 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004355 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004356 risc_addr, dlen));
4357
4358 for (i = 0; i < dlen; i++)
4359 dcode[i] = swab32(fwcode[i]);
4360
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004361 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004362 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004363 if (rval) {
4364 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004365 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004366 fragment));
4367 qla_printk(KERN_WARNING, ha,
4368 "[ERROR] Failed to load segment %d of "
4369 "firmware\n", fragment);
4370 break;
4371 }
4372
4373 fwcode += dlen;
4374 risc_addr += dlen;
4375 risc_size -= dlen;
4376 fragment++;
4377 }
4378
4379 /* Next segment. */
4380 segments--;
4381 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004382 return rval;
4383
4384fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004385 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004386}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004387
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004388int
4389qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4390{
4391 int rval;
4392
Andrew Vasqueze337d902009-04-06 22:33:49 -07004393 if (ql2xfwloadbin == 1)
4394 return qla81xx_load_risc(vha, srisc_addr);
4395
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004396 /*
4397 * FW Load priority:
4398 * 1) Firmware via request-firmware interface (.bin file).
4399 * 2) Firmware residing in flash.
4400 */
4401 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4402 if (rval == QLA_SUCCESS)
4403 return rval;
4404
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004405 return qla24xx_load_risc_flash(vha, srisc_addr,
4406 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004407}
4408
4409int
4410qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4411{
4412 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004413 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004414
Andrew Vasqueze337d902009-04-06 22:33:49 -07004415 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004416 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004417
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004418 /*
4419 * FW Load priority:
4420 * 1) Firmware residing in flash.
4421 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004422 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004423 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004424 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004425 if (rval == QLA_SUCCESS)
4426 return rval;
4427
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004428try_blob_fw:
4429 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4430 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4431 return rval;
4432
4433 qla_printk(KERN_ERR, ha,
4434 "FW: Attempting to fallback to golden firmware...\n");
4435 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4436 if (rval != QLA_SUCCESS)
4437 return rval;
4438
4439 qla_printk(KERN_ERR, ha,
4440 "FW: Please update operational firmware...\n");
4441 ha->flags.running_gold_fw = 1;
4442
4443 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004444}
4445
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004446void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004447qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004448{
4449 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004450 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004451
Andrew Vasqueze4289242007-07-19 15:05:56 -07004452 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004453 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004454 if (!ha->fw_major_version)
4455 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004457 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004458 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004459 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004460 ha->isp_ops->reset_chip(vha);
4461 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004462 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004463 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004464 continue;
4465 qla_printk(KERN_INFO, ha,
4466 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004467 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004468 }
4469}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004470
4471int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004472qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004473{
4474 int rval = QLA_SUCCESS;
4475 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004476 struct qla_hw_data *ha = vha->hw;
4477 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004478 struct req_que *req;
4479 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004480
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004481 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004482 return -EINVAL;
4483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004484 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty7163ea82009-08-05 09:18:40 -07004485 if (ha->flags.cpu_affinity_enabled)
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004486 req = ha->req_q_map[0];
4487 else
4488 req = vha->req;
4489 rsp = req->rsp;
4490
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004491 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004492 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004493 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004494 }
4495
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004496 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004497
4498 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004499 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004500 if (mb[0] != MBS_COMMAND_COMPLETE) {
4501 DEBUG15(qla_printk(KERN_INFO, ha,
4502 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4503 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4504 mb[0], mb[1], mb[2], mb[6], mb[7]));
4505 return (QLA_FUNCTION_FAILED);
4506 }
4507
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004508 atomic_set(&vha->loop_down_timer, 0);
4509 atomic_set(&vha->loop_state, LOOP_UP);
4510 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4511 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4512 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004513
4514 return rval;
4515}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004516
4517/* 84XX Support **************************************************************/
4518
4519static LIST_HEAD(qla_cs84xx_list);
4520static DEFINE_MUTEX(qla_cs84xx_mutex);
4521
4522static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004523qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004524{
4525 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004526 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004527
4528 mutex_lock(&qla_cs84xx_mutex);
4529
4530 /* Find any shared 84xx chip. */
4531 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4532 if (cs84xx->bus == ha->pdev->bus) {
4533 kref_get(&cs84xx->kref);
4534 goto done;
4535 }
4536 }
4537
4538 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4539 if (!cs84xx)
4540 goto done;
4541
4542 kref_init(&cs84xx->kref);
4543 spin_lock_init(&cs84xx->access_lock);
4544 mutex_init(&cs84xx->fw_update_mutex);
4545 cs84xx->bus = ha->pdev->bus;
4546
4547 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4548done:
4549 mutex_unlock(&qla_cs84xx_mutex);
4550 return cs84xx;
4551}
4552
4553static void
4554__qla84xx_chip_release(struct kref *kref)
4555{
4556 struct qla_chip_state_84xx *cs84xx =
4557 container_of(kref, struct qla_chip_state_84xx, kref);
4558
4559 mutex_lock(&qla_cs84xx_mutex);
4560 list_del(&cs84xx->list);
4561 mutex_unlock(&qla_cs84xx_mutex);
4562 kfree(cs84xx);
4563}
4564
4565void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004566qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004567{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004568 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004569 if (ha->cs84xx)
4570 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4571}
4572
4573static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004574qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004575{
4576 int rval;
4577 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004578 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004579
4580 mutex_lock(&ha->cs84xx->fw_update_mutex);
4581
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004582 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004583
4584 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4585
4586 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4587 QLA_SUCCESS;
4588}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004589
4590/* 81XX Support **************************************************************/
4591
4592int
4593qla81xx_nvram_config(scsi_qla_host_t *vha)
4594{
4595 int rval;
4596 struct init_cb_81xx *icb;
4597 struct nvram_81xx *nv;
4598 uint32_t *dptr;
4599 uint8_t *dptr1, *dptr2;
4600 uint32_t chksum;
4601 uint16_t cnt;
4602 struct qla_hw_data *ha = vha->hw;
4603
4604 rval = QLA_SUCCESS;
4605 icb = (struct init_cb_81xx *)ha->init_cb;
4606 nv = ha->nvram;
4607
4608 /* Determine NVRAM starting address. */
4609 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004610 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004611
4612 /* Get VPD data into cache */
4613 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004614 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4615 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004616
4617 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004618 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004619 ha->nvram_size);
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07004620 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004621 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4622 chksum += le32_to_cpu(*dptr++);
4623
Andrew Vasquez76403352009-04-06 22:33:39 -07004624 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004625 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4626
4627 /* Bad NVRAM data, set defaults parameters. */
4628 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4629 || nv->id[3] != ' ' ||
4630 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4631 /* Reset NVRAM data. */
4632 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4633 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4634 le16_to_cpu(nv->nvram_version));
4635 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4636 "invalid -- WWPN) defaults.\n");
4637
4638 /*
4639 * Set default initialization control block.
4640 */
4641 memset(nv, 0, ha->nvram_size);
4642 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4643 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4644 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4645 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4646 nv->exchange_count = __constant_cpu_to_le16(0);
4647 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004648 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004649 nv->port_name[2] = 0x00;
4650 nv->port_name[3] = 0xe0;
4651 nv->port_name[4] = 0x8b;
4652 nv->port_name[5] = 0x1c;
4653 nv->port_name[6] = 0x55;
4654 nv->port_name[7] = 0x86;
4655 nv->node_name[0] = 0x20;
4656 nv->node_name[1] = 0x00;
4657 nv->node_name[2] = 0x00;
4658 nv->node_name[3] = 0xe0;
4659 nv->node_name[4] = 0x8b;
4660 nv->node_name[5] = 0x1c;
4661 nv->node_name[6] = 0x55;
4662 nv->node_name[7] = 0x86;
4663 nv->login_retry_count = __constant_cpu_to_le16(8);
4664 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4665 nv->login_timeout = __constant_cpu_to_le16(0);
4666 nv->firmware_options_1 =
4667 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4668 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4669 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4670 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4671 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4672 nv->efi_parameters = __constant_cpu_to_le32(0);
4673 nv->reset_delay = 5;
4674 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4675 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4676 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004677 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004678 nv->enode_mac[1] = 0x02;
4679 nv->enode_mac[2] = 0x03;
4680 nv->enode_mac[3] = 0x04;
4681 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004682 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004683
4684 rval = 1;
4685 }
4686
4687 /* Reset Initialization control block */
4688 memset(icb, 0, sizeof(struct init_cb_81xx));
4689
4690 /* Copy 1st segment. */
4691 dptr1 = (uint8_t *)icb;
4692 dptr2 = (uint8_t *)&nv->version;
4693 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4694 while (cnt--)
4695 *dptr1++ = *dptr2++;
4696
4697 icb->login_retry_count = nv->login_retry_count;
4698
4699 /* Copy 2nd segment. */
4700 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4701 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4702 cnt = (uint8_t *)&icb->reserved_5 -
4703 (uint8_t *)&icb->interrupt_delay_timer;
4704 while (cnt--)
4705 *dptr1++ = *dptr2++;
4706
4707 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4708 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4709 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4710 icb->enode_mac[0] = 0x01;
4711 icb->enode_mac[1] = 0x02;
4712 icb->enode_mac[2] = 0x03;
4713 icb->enode_mac[3] = 0x04;
4714 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004715 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004716 }
4717
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004718 /* Use extended-initialization control block. */
4719 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4720
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004721 /*
4722 * Setup driver NVRAM options.
4723 */
4724 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4725 "QLE81XX");
4726
4727 /* Use alternate WWN? */
4728 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4729 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4730 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4731 }
4732
4733 /* Prepare nodename */
4734 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4735 /*
4736 * Firmware will apply the following mask if the nodename was
4737 * not provided.
4738 */
4739 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4740 icb->node_name[0] &= 0xF0;
4741 }
4742
4743 /* Set host adapter parameters. */
4744 ha->flags.disable_risc_code_load = 0;
4745 ha->flags.enable_lip_reset = 0;
4746 ha->flags.enable_lip_full_login =
4747 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4748 ha->flags.enable_target_reset =
4749 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4750 ha->flags.enable_led_scheme = 0;
4751 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4752
4753 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4754 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4755
4756 /* save HBA serial number */
4757 ha->serial0 = icb->port_name[5];
4758 ha->serial1 = icb->port_name[6];
4759 ha->serial2 = icb->port_name[7];
4760 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4761 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4762
4763 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4764
4765 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4766
4767 /* Set minimum login_timeout to 4 seconds. */
4768 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4769 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4770 if (le16_to_cpu(nv->login_timeout) < 4)
4771 nv->login_timeout = __constant_cpu_to_le16(4);
4772 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4773 icb->login_timeout = nv->login_timeout;
4774
4775 /* Set minimum RATOV to 100 tenths of a second. */
4776 ha->r_a_tov = 100;
4777
4778 ha->loop_reset_delay = nv->reset_delay;
4779
4780 /* Link Down Timeout = 0:
4781 *
4782 * When Port Down timer expires we will start returning
4783 * I/O's to OS with "DID_NO_CONNECT".
4784 *
4785 * Link Down Timeout != 0:
4786 *
4787 * The driver waits for the link to come up after link down
4788 * before returning I/Os to OS with "DID_NO_CONNECT".
4789 */
4790 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4791 ha->loop_down_abort_time =
4792 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4793 } else {
4794 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4795 ha->loop_down_abort_time =
4796 (LOOP_DOWN_TIME - ha->link_down_timeout);
4797 }
4798
4799 /* Need enough time to try and get the port back. */
4800 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4801 if (qlport_down_retry)
4802 ha->port_down_retry_count = qlport_down_retry;
4803
4804 /* Set login_retry_count */
4805 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4806 if (ha->port_down_retry_count ==
4807 le16_to_cpu(nv->port_down_retry_count) &&
4808 ha->port_down_retry_count > 3)
4809 ha->login_retry_count = ha->port_down_retry_count;
4810 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4811 ha->login_retry_count = ha->port_down_retry_count;
4812 if (ql2xloginretrycount)
4813 ha->login_retry_count = ql2xloginretrycount;
4814
4815 /* Enable ZIO. */
4816 if (!vha->flags.init_done) {
4817 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4818 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4819 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4820 le16_to_cpu(icb->interrupt_delay_timer): 2;
4821 }
4822 icb->firmware_options_2 &= __constant_cpu_to_le32(
4823 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4824 vha->flags.process_response_queue = 0;
4825 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4826 ha->zio_mode = QLA_ZIO_MODE_6;
4827
4828 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4829 "(%d us).\n", vha->host_no, ha->zio_mode,
4830 ha->zio_timer * 100));
4831 qla_printk(KERN_INFO, ha,
4832 "ZIO mode %d enabled; timer delay (%d us).\n",
4833 ha->zio_mode, ha->zio_timer * 100);
4834
4835 icb->firmware_options_2 |= cpu_to_le32(
4836 (uint32_t)ha->zio_mode);
4837 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4838 vha->flags.process_response_queue = 1;
4839 }
4840
4841 if (rval) {
4842 DEBUG2_3(printk(KERN_WARNING
4843 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4844 }
4845 return (rval);
4846}
4847
4848void
4849qla81xx_update_fw_options(scsi_qla_host_t *ha)
4850{
4851}