]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - drivers/scsi/qla2xxx/qla_init.c
[SCSI] qla2xxx: Don't pollute kernel logs with ZIO/RIO status messages.
[mirror_ubuntu-bionic-kernel.git] / drivers / scsi / qla2xxx / qla_init.c
CommitLineData
1da177e4 1/*
fa90c54f 2 * QLogic Fibre Channel HBA Driver
01e58d8e 3 * Copyright (c) 2003-2008 QLogic Corporation
1da177e4 4 *
fa90c54f 5 * See LICENSE.qla2xxx for copyright and licensing details.
1da177e4
LT
6 */
7#include "qla_def.h"
73208dfd 8#include "qla_gbl.h"
1da177e4
LT
9
10#include <linux/delay.h>
0107109e 11#include <linux/vmalloc.h>
1da177e4
LT
12
13#include "qla_devtbl.h"
14
4e08df3f
DM
15#ifdef CONFIG_SPARC
16#include <asm/prom.h>
4e08df3f
DM
17#endif
18
1da177e4
LT
19/*
20* QLogic ISP2x00 Hardware Support Function Prototypes.
21*/
1da177e4 22static int qla2x00_isp_firmware(scsi_qla_host_t *);
1da177e4
LT
23static void qla2x00_resize_request_q(scsi_qla_host_t *);
24static int qla2x00_setup_chip(scsi_qla_host_t *);
1da177e4
LT
25static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
1da177e4
LT
28static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
1da177e4
LT
30static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
1da177e4
LT
35
36static int qla2x00_restart_isp(scsi_qla_host_t *);
1da177e4 37
e315cd28 38static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
413975a0 39
4d4df193
HK
40static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
73208dfd 42static int qla25xx_init_queues(struct qla_hw_data *);
4d4df193 43
1da177e4
LT
44/****************************************************************************/
45/* QLogic ISP2x00 Hardware Support Functions. */
46/****************************************************************************/
47
48/*
49* qla2x00_initialize_adapter
50* Initialize board.
51*
52* Input:
53* ha = adapter block pointer.
54*
55* Returns:
56* 0 = success
57*/
58int
e315cd28 59qla2x00_initialize_adapter(scsi_qla_host_t *vha)
1da177e4
LT
60{
61 int rval;
e315cd28 62 struct qla_hw_data *ha = vha->hw;
73208dfd 63 struct req_que *req = ha->req_q_map[0];
1da177e4 64 /* Clear adapter flags. */
e315cd28
AC
65 vha->flags.online = 0;
66 vha->flags.reset_active = 0;
67 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
68 atomic_set(&vha->loop_state, LOOP_DOWN);
69 vha->device_flags = DFLG_NO_CABLE;
70 vha->dpc_flags = 0;
71 vha->flags.management_server_logged_in = 0;
72 vha->marker_needed = 0;
1da177e4
LT
73 ha->mbx_flags = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
e315cd28 76 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
1da177e4 77
73208dfd
AC
78 set_bit(0, ha->req_qid_map);
79 set_bit(0, ha->rsp_qid_map);
80
0107109e 81 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
e315cd28 82 rval = ha->isp_ops->pci_config(vha);
1da177e4 83 if (rval) {
7c98a046 84 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
e315cd28 85 vha->host_no));
1da177e4
LT
86 return (rval);
87 }
88
e315cd28 89 ha->isp_ops->reset_chip(vha);
1da177e4 90
e315cd28 91 rval = qla2xxx_get_flash_info(vha);
c00d8994
AV
92 if (rval) {
93 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
e315cd28 94 vha->host_no));
c00d8994
AV
95 return (rval);
96 }
97
73208dfd 98 ha->isp_ops->get_flash_version(vha, req->ring);
30c47662 99
1da177e4 100 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
0107109e 101
e315cd28 102 ha->isp_ops->nvram_config(vha);
1da177e4 103
d4c760c2
AV
104 if (ha->flags.disable_serdes) {
105 /* Mask HBA via NVRAM settings? */
106 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
107 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
e315cd28
AC
108 vha->port_name[0], vha->port_name[1],
109 vha->port_name[2], vha->port_name[3],
110 vha->port_name[4], vha->port_name[5],
111 vha->port_name[6], vha->port_name[7]);
d4c760c2
AV
112 return QLA_FUNCTION_FAILED;
113 }
114
1da177e4
LT
115 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
116
e315cd28
AC
117 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
118 rval = ha->isp_ops->chip_diag(vha);
d19044c3
AV
119 if (rval)
120 return (rval);
e315cd28 121 rval = qla2x00_setup_chip(vha);
d19044c3
AV
122 if (rval)
123 return (rval);
1da177e4 124 }
4d4df193 125 if (IS_QLA84XX(ha)) {
e315cd28 126 ha->cs84xx = qla84xx_get_chip(vha);
4d4df193
HK
127 if (!ha->cs84xx) {
128 qla_printk(KERN_ERR, ha,
129 "Unable to configure ISP84XX.\n");
130 return QLA_FUNCTION_FAILED;
131 }
132 }
e315cd28 133 rval = qla2x00_init_rings(vha);
1da177e4
LT
134
135 return (rval);
136}
137
138/**
abbd8870 139 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
1da177e4
LT
140 * @ha: HA context
141 *
142 * Returns 0 on success.
143 */
abbd8870 144int
e315cd28 145qla2100_pci_config(scsi_qla_host_t *vha)
1da177e4 146{
a157b101 147 uint16_t w;
abbd8870 148 unsigned long flags;
e315cd28 149 struct qla_hw_data *ha = vha->hw;
3d71644c 150 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4 151
1da177e4 152 pci_set_master(ha->pdev);
af6177d8 153 pci_try_set_mwi(ha->pdev);
1da177e4 154
1da177e4 155 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
a157b101 156 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
abbd8870
AV
157 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
158
737faece 159 pci_disable_rom(ha->pdev);
1da177e4
LT
160
161 /* Get PCI bus information. */
162 spin_lock_irqsave(&ha->hardware_lock, flags);
3d71644c 163 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
1da177e4
LT
164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
165
abbd8870
AV
166 return QLA_SUCCESS;
167}
1da177e4 168
abbd8870
AV
169/**
170 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
171 * @ha: HA context
172 *
173 * Returns 0 on success.
174 */
175int
e315cd28 176qla2300_pci_config(scsi_qla_host_t *vha)
abbd8870 177{
a157b101 178 uint16_t w;
abbd8870
AV
179 unsigned long flags = 0;
180 uint32_t cnt;
e315cd28 181 struct qla_hw_data *ha = vha->hw;
3d71644c 182 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4 183
abbd8870 184 pci_set_master(ha->pdev);
af6177d8 185 pci_try_set_mwi(ha->pdev);
1da177e4 186
abbd8870 187 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
a157b101 188 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
1da177e4 189
abbd8870
AV
190 if (IS_QLA2322(ha) || IS_QLA6322(ha))
191 w &= ~PCI_COMMAND_INTX_DISABLE;
a157b101 192 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
1da177e4 193
abbd8870
AV
194 /*
195 * If this is a 2300 card and not 2312, reset the
196 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
197 * the 2310 also reports itself as a 2300 so we need to get the
198 * fb revision level -- a 6 indicates it really is a 2300 and
199 * not a 2310.
200 */
201 if (IS_QLA2300(ha)) {
202 spin_lock_irqsave(&ha->hardware_lock, flags);
1da177e4 203
abbd8870 204 /* Pause RISC. */
3d71644c 205 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
abbd8870 206 for (cnt = 0; cnt < 30000; cnt++) {
3d71644c 207 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
abbd8870 208 break;
1da177e4 209
abbd8870
AV
210 udelay(10);
211 }
1da177e4 212
abbd8870 213 /* Select FPM registers. */
3d71644c
AV
214 WRT_REG_WORD(&reg->ctrl_status, 0x20);
215 RD_REG_WORD(&reg->ctrl_status);
abbd8870
AV
216
217 /* Get the fb rev level */
3d71644c 218 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
abbd8870
AV
219
220 if (ha->fb_rev == FPM_2300)
a157b101 221 pci_clear_mwi(ha->pdev);
abbd8870
AV
222
223 /* Deselect FPM registers. */
3d71644c
AV
224 WRT_REG_WORD(&reg->ctrl_status, 0x0);
225 RD_REG_WORD(&reg->ctrl_status);
abbd8870
AV
226
227 /* Release RISC module. */
3d71644c 228 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
abbd8870 229 for (cnt = 0; cnt < 30000; cnt++) {
3d71644c 230 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
abbd8870
AV
231 break;
232
233 udelay(10);
1da177e4 234 }
1da177e4 235
abbd8870
AV
236 spin_unlock_irqrestore(&ha->hardware_lock, flags);
237 }
1da177e4 238
abbd8870
AV
239 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
240
737faece 241 pci_disable_rom(ha->pdev);
1da177e4 242
abbd8870
AV
243 /* Get PCI bus information. */
244 spin_lock_irqsave(&ha->hardware_lock, flags);
3d71644c 245 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
abbd8870
AV
246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
247
248 return QLA_SUCCESS;
1da177e4
LT
249}
250
0107109e
AV
251/**
252 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
253 * @ha: HA context
254 *
255 * Returns 0 on success.
256 */
257int
e315cd28 258qla24xx_pci_config(scsi_qla_host_t *vha)
0107109e 259{
a157b101 260 uint16_t w;
0107109e 261 unsigned long flags = 0;
e315cd28 262 struct qla_hw_data *ha = vha->hw;
0107109e 263 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
0107109e
AV
264
265 pci_set_master(ha->pdev);
af6177d8 266 pci_try_set_mwi(ha->pdev);
0107109e
AV
267
268 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
a157b101 269 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
0107109e
AV
270 w &= ~PCI_COMMAND_INTX_DISABLE;
271 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
272
273 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
274
275 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
f85ec187
AV
276 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
277 pcix_set_mmrbc(ha->pdev, 2048);
0107109e
AV
278
279 /* PCIe -- adjust Maximum Read Request Size (2048). */
f85ec187
AV
280 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
281 pcie_set_readrq(ha->pdev, 2048);
0107109e 282
737faece 283 pci_disable_rom(ha->pdev);
0107109e 284
44c10138 285 ha->chip_revision = ha->pdev->revision;
a8488abe 286
0107109e
AV
287 /* Get PCI bus information. */
288 spin_lock_irqsave(&ha->hardware_lock, flags);
289 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
291
292 return QLA_SUCCESS;
293}
294
c3a2f0df
AV
295/**
296 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
297 * @ha: HA context
298 *
299 * Returns 0 on success.
300 */
301int
e315cd28 302qla25xx_pci_config(scsi_qla_host_t *vha)
c3a2f0df
AV
303{
304 uint16_t w;
e315cd28 305 struct qla_hw_data *ha = vha->hw;
c3a2f0df
AV
306
307 pci_set_master(ha->pdev);
308 pci_try_set_mwi(ha->pdev);
309
310 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
311 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
312 w &= ~PCI_COMMAND_INTX_DISABLE;
313 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
314
315 /* PCIe -- adjust Maximum Read Request Size (2048). */
316 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
317 pcie_set_readrq(ha->pdev, 2048);
318
737faece 319 pci_disable_rom(ha->pdev);
c3a2f0df
AV
320
321 ha->chip_revision = ha->pdev->revision;
322
323 return QLA_SUCCESS;
324}
325
1da177e4
LT
326/**
327 * qla2x00_isp_firmware() - Choose firmware image.
328 * @ha: HA context
329 *
330 * Returns 0 on success.
331 */
332static int
e315cd28 333qla2x00_isp_firmware(scsi_qla_host_t *vha)
1da177e4
LT
334{
335 int rval;
42e421b1
AV
336 uint16_t loop_id, topo, sw_cap;
337 uint8_t domain, area, al_pa;
e315cd28 338 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
339
340 /* Assume loading risc code */
fa2a1ce5 341 rval = QLA_FUNCTION_FAILED;
1da177e4
LT
342
343 if (ha->flags.disable_risc_code_load) {
344 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
e315cd28 345 vha->host_no));
1da177e4
LT
346 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
347
348 /* Verify checksum of loaded RISC code. */
e315cd28 349 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
42e421b1
AV
350 if (rval == QLA_SUCCESS) {
351 /* And, verify we are not in ROM code. */
e315cd28 352 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
42e421b1
AV
353 &area, &domain, &topo, &sw_cap);
354 }
1da177e4
LT
355 }
356
357 if (rval) {
358 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
e315cd28 359 vha->host_no));
1da177e4
LT
360 }
361
362 return (rval);
363}
364
365/**
366 * qla2x00_reset_chip() - Reset ISP chip.
367 * @ha: HA context
368 *
369 * Returns 0 on success.
370 */
abbd8870 371void
e315cd28 372qla2x00_reset_chip(scsi_qla_host_t *vha)
1da177e4
LT
373{
374 unsigned long flags = 0;
e315cd28 375 struct qla_hw_data *ha = vha->hw;
3d71644c 376 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4 377 uint32_t cnt;
1da177e4
LT
378 uint16_t cmd;
379
fd34f556 380 ha->isp_ops->disable_intrs(ha);
1da177e4
LT
381
382 spin_lock_irqsave(&ha->hardware_lock, flags);
383
384 /* Turn off master enable */
385 cmd = 0;
386 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
387 cmd &= ~PCI_COMMAND_MASTER;
388 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
389
390 if (!IS_QLA2100(ha)) {
391 /* Pause RISC. */
392 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
393 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
394 for (cnt = 0; cnt < 30000; cnt++) {
395 if ((RD_REG_WORD(&reg->hccr) &
396 HCCR_RISC_PAUSE) != 0)
397 break;
398 udelay(100);
399 }
400 } else {
401 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
402 udelay(10);
403 }
404
405 /* Select FPM registers. */
406 WRT_REG_WORD(&reg->ctrl_status, 0x20);
407 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
408
409 /* FPM Soft Reset. */
410 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
411 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
412
413 /* Toggle Fpm Reset. */
414 if (!IS_QLA2200(ha)) {
415 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
416 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
417 }
418
419 /* Select frame buffer registers. */
420 WRT_REG_WORD(&reg->ctrl_status, 0x10);
421 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
422
423 /* Reset frame buffer FIFOs. */
424 if (IS_QLA2200(ha)) {
425 WRT_FB_CMD_REG(ha, reg, 0xa000);
426 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
427 } else {
428 WRT_FB_CMD_REG(ha, reg, 0x00fc);
429
430 /* Read back fb_cmd until zero or 3 seconds max */
431 for (cnt = 0; cnt < 3000; cnt++) {
432 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
433 break;
434 udelay(100);
435 }
436 }
437
438 /* Select RISC module registers. */
439 WRT_REG_WORD(&reg->ctrl_status, 0);
440 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
441
442 /* Reset RISC processor. */
443 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
444 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
445
446 /* Release RISC processor. */
447 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
448 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
449 }
450
451 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
452 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
453
454 /* Reset ISP chip. */
455 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
456
457 /* Wait for RISC to recover from reset. */
458 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
459 /*
460 * It is necessary to for a delay here since the card doesn't
461 * respond to PCI reads during a reset. On some architectures
462 * this will result in an MCA.
463 */
464 udelay(20);
465 for (cnt = 30000; cnt; cnt--) {
466 if ((RD_REG_WORD(&reg->ctrl_status) &
467 CSR_ISP_SOFT_RESET) == 0)
468 break;
469 udelay(100);
470 }
471 } else
472 udelay(10);
473
474 /* Reset RISC processor. */
475 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
476
477 WRT_REG_WORD(&reg->semaphore, 0);
478
479 /* Release RISC processor. */
480 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
481 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
482
483 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
484 for (cnt = 0; cnt < 30000; cnt++) {
ffb39f03 485 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
1da177e4 486 break;
1da177e4
LT
487
488 udelay(100);
489 }
490 } else
491 udelay(100);
492
493 /* Turn on master enable */
494 cmd |= PCI_COMMAND_MASTER;
495 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
496
497 /* Disable RISC pause on FPM parity error. */
498 if (!IS_QLA2100(ha)) {
499 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
500 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
501 }
502
503 spin_unlock_irqrestore(&ha->hardware_lock, flags);
504}
505
0107109e 506/**
88c26663 507 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
0107109e
AV
508 * @ha: HA context
509 *
510 * Returns 0 on success.
511 */
88c26663 512static inline void
e315cd28 513qla24xx_reset_risc(scsi_qla_host_t *vha)
0107109e 514{
cb8dacbf 515 int hw_evt = 0;
0107109e 516 unsigned long flags = 0;
e315cd28 517 struct qla_hw_data *ha = vha->hw;
0107109e
AV
518 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
519 uint32_t cnt, d2;
335a1cc9 520 uint16_t wd;
0107109e 521
0107109e
AV
522 spin_lock_irqsave(&ha->hardware_lock, flags);
523
524 /* Reset RISC. */
525 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
526 for (cnt = 0; cnt < 30000; cnt++) {
527 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
528 break;
529
530 udelay(10);
531 }
532
533 WRT_REG_DWORD(&reg->ctrl_status,
534 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
335a1cc9 535 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
88c26663 536
335a1cc9 537 udelay(100);
88c26663 538 /* Wait for firmware to complete NVRAM accesses. */
88c26663
AV
539 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
540 for (cnt = 10000 ; cnt && d2; cnt--) {
541 udelay(5);
542 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
543 barrier();
544 }
cb8dacbf
AV
545 if (cnt == 0)
546 hw_evt = 1;
88c26663 547
335a1cc9 548 /* Wait for soft-reset to complete. */
0107109e
AV
549 d2 = RD_REG_DWORD(&reg->ctrl_status);
550 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
551 udelay(5);
552 d2 = RD_REG_DWORD(&reg->ctrl_status);
553 barrier();
554 }
555
556 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
557 RD_REG_DWORD(&reg->hccr);
558
559 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
560 RD_REG_DWORD(&reg->hccr);
561
562 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
563 RD_REG_DWORD(&reg->hccr);
564
565 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
566 for (cnt = 6000000 ; cnt && d2; cnt--) {
567 udelay(5);
568 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
569 barrier();
570 }
571
572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
124f85e6
AV
573
574 if (IS_NOPOLLING_TYPE(ha))
575 ha->isp_ops->enable_intrs(ha);
0107109e
AV
576}
577
88c26663
AV
578/**
579 * qla24xx_reset_chip() - Reset ISP24xx chip.
580 * @ha: HA context
581 *
582 * Returns 0 on success.
583 */
584void
e315cd28 585qla24xx_reset_chip(scsi_qla_host_t *vha)
88c26663 586{
e315cd28 587 struct qla_hw_data *ha = vha->hw;
fd34f556 588 ha->isp_ops->disable_intrs(ha);
88c26663
AV
589
590 /* Perform RISC reset. */
e315cd28 591 qla24xx_reset_risc(vha);
88c26663
AV
592}
593
1da177e4
LT
594/**
595 * qla2x00_chip_diag() - Test chip for proper operation.
596 * @ha: HA context
597 *
598 * Returns 0 on success.
599 */
abbd8870 600int
e315cd28 601qla2x00_chip_diag(scsi_qla_host_t *vha)
1da177e4
LT
602{
603 int rval;
e315cd28 604 struct qla_hw_data *ha = vha->hw;
3d71644c 605 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4
LT
606 unsigned long flags = 0;
607 uint16_t data;
608 uint32_t cnt;
609 uint16_t mb[5];
73208dfd 610 struct req_que *req = ha->req_q_map[0];
1da177e4
LT
611
612 /* Assume a failed state */
613 rval = QLA_FUNCTION_FAILED;
614
615 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
e315cd28 616 vha->host_no, (u_long)&reg->flash_address));
1da177e4
LT
617
618 spin_lock_irqsave(&ha->hardware_lock, flags);
619
620 /* Reset ISP chip. */
621 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
622
623 /*
624 * We need to have a delay here since the card will not respond while
625 * in reset causing an MCA on some architectures.
626 */
627 udelay(20);
628 data = qla2x00_debounce_register(&reg->ctrl_status);
629 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
630 udelay(5);
631 data = RD_REG_WORD(&reg->ctrl_status);
632 barrier();
633 }
634
635 if (!cnt)
636 goto chip_diag_failed;
637
638 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
639 ha->host_no));
640
641 /* Reset RISC processor. */
642 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
643 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
644
645 /* Workaround for QLA2312 PCI parity error */
646 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
647 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
648 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
649 udelay(5);
650 data = RD_MAILBOX_REG(ha, reg, 0);
fa2a1ce5 651 barrier();
1da177e4
LT
652 }
653 } else
654 udelay(10);
655
656 if (!cnt)
657 goto chip_diag_failed;
658
659 /* Check product ID of chip */
660 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
661
662 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
663 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
664 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
665 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
666 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
667 mb[3] != PROD_ID_3) {
668 qla_printk(KERN_WARNING, ha,
669 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
670
671 goto chip_diag_failed;
672 }
673 ha->product_id[0] = mb[1];
674 ha->product_id[1] = mb[2];
675 ha->product_id[2] = mb[3];
676 ha->product_id[3] = mb[4];
677
678 /* Adjust fw RISC transfer size */
73208dfd 679 if (req->length > 1024)
1da177e4
LT
680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
681 else
682 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
73208dfd 683 req->length;
1da177e4
LT
684
685 if (IS_QLA2200(ha) &&
686 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
687 /* Limit firmware transfer size with a 2200A */
688 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
e315cd28 689 vha->host_no));
1da177e4 690
ea5b6382 691 ha->device_type |= DT_ISP2200A;
1da177e4
LT
692 ha->fw_transfer_size = 128;
693 }
694
695 /* Wrap Incoming Mailboxes Test. */
696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
697
e315cd28
AC
698 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
699 rval = qla2x00_mbx_reg_test(vha);
1da177e4
LT
700 if (rval) {
701 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
e315cd28 702 vha->host_no));
1da177e4
LT
703 qla_printk(KERN_WARNING, ha,
704 "Failed mailbox send register test\n");
705 }
706 else {
707 /* Flag a successful rval */
708 rval = QLA_SUCCESS;
709 }
710 spin_lock_irqsave(&ha->hardware_lock, flags);
711
712chip_diag_failed:
713 if (rval)
714 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
e315cd28 715 "****\n", vha->host_no));
1da177e4
LT
716
717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
718
719 return (rval);
720}
721
0107109e
AV
722/**
723 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
724 * @ha: HA context
725 *
726 * Returns 0 on success.
727 */
728int
e315cd28 729qla24xx_chip_diag(scsi_qla_host_t *vha)
0107109e
AV
730{
731 int rval;
e315cd28 732 struct qla_hw_data *ha = vha->hw;
73208dfd 733 struct req_que *req = ha->req_q_map[0];
0107109e 734
88c26663 735 /* Perform RISC reset. */
e315cd28 736 qla24xx_reset_risc(vha);
0107109e 737
73208dfd 738 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
0107109e 739
e315cd28 740 rval = qla2x00_mbx_reg_test(vha);
0107109e
AV
741 if (rval) {
742 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
e315cd28 743 vha->host_no));
0107109e
AV
744 qla_printk(KERN_WARNING, ha,
745 "Failed mailbox send register test\n");
746 } else {
747 /* Flag a successful rval */
748 rval = QLA_SUCCESS;
749 }
750
751 return rval;
752}
753
a7a167bf 754void
e315cd28 755qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
0107109e 756{
a7a167bf
AV
757 int rval;
758 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
73208dfd 759 eft_size, fce_size, mq_size;
df613b96
AV
760 dma_addr_t tc_dma;
761 void *tc;
e315cd28 762 struct qla_hw_data *ha = vha->hw;
73208dfd
AC
763 struct req_que *req = ha->req_q_map[0];
764 struct rsp_que *rsp = ha->rsp_q_map[0];
a7a167bf
AV
765
766 if (ha->fw_dump) {
767 qla_printk(KERN_WARNING, ha,
768 "Firmware dump previously allocated.\n");
769 return;
770 }
d4e3e04d 771
0107109e 772 ha->fw_dumped = 0;
73208dfd 773 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
d4e3e04d 774 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
a7a167bf 775 fixed_size = sizeof(struct qla2100_fw_dump);
d4e3e04d 776 } else if (IS_QLA23XX(ha)) {
a7a167bf
AV
777 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
778 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
779 sizeof(uint16_t);
e428924c 780 } else if (IS_FWI2_CAPABLE(ha)) {
c3a2f0df 781 fixed_size = IS_QLA25XX(ha) ?
73208dfd
AC
782 offsetof(struct qla25xx_fw_dump, ext_mem) :
783 offsetof(struct qla24xx_fw_dump, ext_mem);
a7a167bf
AV
784 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
785 sizeof(uint32_t);
73208dfd
AC
786 if (ha->mqenable)
787 mq_size = sizeof(struct qla2xxx_mq_chain);
a7a167bf 788
df613b96
AV
789 /* Allocate memory for Fibre Channel Event Buffer. */
790 if (!IS_QLA25XX(ha))
436a7b11 791 goto try_eft;
df613b96
AV
792
793 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
794 GFP_KERNEL);
795 if (!tc) {
796 qla_printk(KERN_WARNING, ha, "Unable to allocate "
797 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
17d98630 798 goto try_eft;
df613b96
AV
799 }
800
801 memset(tc, 0, FCE_SIZE);
e315cd28 802 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
df613b96
AV
803 ha->fce_mb, &ha->fce_bufs);
804 if (rval) {
805 qla_printk(KERN_WARNING, ha, "Unable to initialize "
806 "FCE (%d).\n", rval);
807 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
808 tc_dma);
809 ha->flags.fce_enabled = 0;
17d98630 810 goto try_eft;
df613b96
AV
811 }
812
813 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
814 FCE_SIZE / 1024);
815
816 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
817 ha->flags.fce_enabled = 1;
818 ha->fce_dma = tc_dma;
819 ha->fce = tc;
436a7b11
AV
820try_eft:
821 /* Allocate memory for Extended Trace Buffer. */
822 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
823 GFP_KERNEL);
824 if (!tc) {
825 qla_printk(KERN_WARNING, ha, "Unable to allocate "
826 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
827 goto cont_alloc;
828 }
829
830 memset(tc, 0, EFT_SIZE);
e315cd28 831 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
436a7b11
AV
832 if (rval) {
833 qla_printk(KERN_WARNING, ha, "Unable to initialize "
834 "EFT (%d).\n", rval);
835 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
836 tc_dma);
837 goto cont_alloc;
838 }
839
840 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
841 EFT_SIZE / 1024);
842
843 eft_size = EFT_SIZE;
844 ha->eft_dma = tc_dma;
845 ha->eft = tc;
d4e3e04d 846 }
a7a167bf 847cont_alloc:
73208dfd
AC
848 req_q_size = req->length * sizeof(request_t);
849 rsp_q_size = rsp->length * sizeof(response_t);
a7a167bf
AV
850
851 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
852 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
73208dfd 853 mq_size + eft_size + fce_size;
d4e3e04d
AV
854
855 ha->fw_dump = vmalloc(dump_size);
a7a167bf 856 if (!ha->fw_dump) {
0107109e 857 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
d4e3e04d 858 "firmware dump!!!\n", dump_size / 1024);
a7a167bf
AV
859
860 if (ha->eft) {
861 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
862 ha->eft_dma);
863 ha->eft = NULL;
864 ha->eft_dma = 0;
865 }
866 return;
867 }
a7a167bf
AV
868 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
869 dump_size / 1024);
870
871 ha->fw_dump_len = dump_size;
872 ha->fw_dump->signature[0] = 'Q';
873 ha->fw_dump->signature[1] = 'L';
874 ha->fw_dump->signature[2] = 'G';
875 ha->fw_dump->signature[3] = 'C';
876 ha->fw_dump->version = __constant_htonl(1);
877
878 ha->fw_dump->fixed_size = htonl(fixed_size);
879 ha->fw_dump->mem_size = htonl(mem_size);
880 ha->fw_dump->req_q_size = htonl(req_q_size);
881 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
882
883 ha->fw_dump->eft_size = htonl(eft_size);
884 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
885 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
886
887 ha->fw_dump->header_size =
888 htonl(offsetof(struct qla2xxx_fw_dump, isp));
0107109e
AV
889}
890
1da177e4
LT
891/**
892 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
893 * @ha: HA context
894 *
895 * Returns 0 on success.
896 */
897static void
e315cd28 898qla2x00_resize_request_q(scsi_qla_host_t *vha)
1da177e4
LT
899{
900 int rval;
901 uint16_t fw_iocb_cnt = 0;
902 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
903 dma_addr_t request_dma;
904 request_t *request_ring;
e315cd28 905 struct qla_hw_data *ha = vha->hw;
73208dfd 906 struct req_que *req = ha->req_q_map[0];
1da177e4
LT
907
908 /* Valid only on recent ISPs. */
909 if (IS_QLA2100(ha) || IS_QLA2200(ha))
910 return;
911
912 /* Retrieve IOCB counts available to the firmware. */
e315cd28
AC
913 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
914 &ha->max_npiv_vports);
1da177e4
LT
915 if (rval)
916 return;
917 /* No point in continuing if current settings are sufficient. */
918 if (fw_iocb_cnt < 1024)
919 return;
e315cd28 920 if (req->length >= request_q_length)
1da177e4
LT
921 return;
922
923 /* Attempt to claim larger area for request queue. */
924 request_ring = dma_alloc_coherent(&ha->pdev->dev,
925 (request_q_length + 1) * sizeof(request_t), &request_dma,
926 GFP_KERNEL);
927 if (request_ring == NULL)
928 return;
929
930 /* Resize successful, report extensions. */
931 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
932 (ha->fw_memory_size + 1) / 1024);
933 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
e315cd28 934 "(%d -> %d)...\n", req->length, request_q_length);
1da177e4
LT
935
936 /* Clear old allocations. */
937 dma_free_coherent(&ha->pdev->dev,
e315cd28
AC
938 (req->length + 1) * sizeof(request_t), req->ring,
939 req->dma);
1da177e4
LT
940
941 /* Begin using larger queue. */
e315cd28
AC
942 req->length = request_q_length;
943 req->ring = request_ring;
944 req->dma = request_dma;
1da177e4
LT
945}
946
947/**
948 * qla2x00_setup_chip() - Load and start RISC firmware.
949 * @ha: HA context
950 *
951 * Returns 0 on success.
952 */
953static int
e315cd28 954qla2x00_setup_chip(scsi_qla_host_t *vha)
1da177e4 955{
0107109e
AV
956 int rval;
957 uint32_t srisc_address = 0;
e315cd28 958 struct qla_hw_data *ha = vha->hw;
3db0652e
AV
959 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
960 unsigned long flags;
961
962 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
963 /* Disable SRAM, Instruction RAM and GP RAM parity. */
964 spin_lock_irqsave(&ha->hardware_lock, flags);
965 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
966 RD_REG_WORD(&reg->hccr);
967 spin_unlock_irqrestore(&ha->hardware_lock, flags);
968 }
1da177e4
LT
969
970 /* Load firmware sequences */
e315cd28 971 rval = ha->isp_ops->load_risc(vha, &srisc_address);
0107109e 972 if (rval == QLA_SUCCESS) {
1da177e4 973 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
e315cd28 974 "code.\n", vha->host_no));
1da177e4 975
e315cd28 976 rval = qla2x00_verify_checksum(vha, srisc_address);
1da177e4
LT
977 if (rval == QLA_SUCCESS) {
978 /* Start firmware execution. */
979 DEBUG(printk("scsi(%ld): Checksum OK, start "
e315cd28 980 "firmware.\n", vha->host_no));
1da177e4 981
e315cd28 982 rval = qla2x00_execute_fw(vha, srisc_address);
1da177e4
LT
983 /* Retrieve firmware information. */
984 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
e315cd28 985 qla2x00_get_fw_version(vha,
1da177e4
LT
986 &ha->fw_major_version,
987 &ha->fw_minor_version,
988 &ha->fw_subminor_version,
989 &ha->fw_attributes, &ha->fw_memory_size);
2c3dfe3f 990 ha->flags.npiv_supported = 0;
e315cd28 991 if (IS_QLA2XXX_MIDTYPE(ha) &&
946fb891 992 (ha->fw_attributes & BIT_2)) {
2c3dfe3f 993 ha->flags.npiv_supported = 1;
4d0ea247
SJ
994 if ((!ha->max_npiv_vports) ||
995 ((ha->max_npiv_vports + 1) %
eb66dc60 996 MIN_MULTI_ID_FABRIC))
4d0ea247 997 ha->max_npiv_vports =
eb66dc60 998 MIN_MULTI_ID_FABRIC - 1;
4d0ea247 999 }
e315cd28 1000 qla2x00_resize_request_q(vha);
a7a167bf
AV
1001
1002 if (ql2xallocfwdump)
e315cd28 1003 qla2x00_alloc_fw_dump(vha);
1da177e4
LT
1004 }
1005 } else {
1006 DEBUG2(printk(KERN_INFO
1007 "scsi(%ld): ISP Firmware failed checksum.\n",
e315cd28 1008 vha->host_no));
1da177e4
LT
1009 }
1010 }
1011
3db0652e
AV
1012 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1013 /* Enable proper parity. */
1014 spin_lock_irqsave(&ha->hardware_lock, flags);
1015 if (IS_QLA2300(ha))
1016 /* SRAM parity */
1017 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1018 else
1019 /* SRAM, Instruction RAM and GP RAM parity */
1020 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1021 RD_REG_WORD(&reg->hccr);
1022 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1023 }
1024
1da177e4
LT
1025 if (rval) {
1026 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
e315cd28 1027 vha->host_no));
1da177e4
LT
1028 }
1029
1030 return (rval);
1031}
1032
1033/**
1034 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1035 * @ha: HA context
1036 *
1037 * Beginning of request ring has initialization control block already built
1038 * by nvram config routine.
1039 *
1040 * Returns 0 on success.
1041 */
73208dfd
AC
1042void
1043qla2x00_init_response_q_entries(struct rsp_que *rsp)
1da177e4
LT
1044{
1045 uint16_t cnt;
1046 response_t *pkt;
1047
e315cd28
AC
1048 pkt = rsp->ring_ptr;
1049 for (cnt = 0; cnt < rsp->length; cnt++) {
1da177e4
LT
1050 pkt->signature = RESPONSE_PROCESSED;
1051 pkt++;
1052 }
1053
1054}
1055
1056/**
1057 * qla2x00_update_fw_options() - Read and process firmware options.
1058 * @ha: HA context
1059 *
1060 * Returns 0 on success.
1061 */
abbd8870 1062void
e315cd28 1063qla2x00_update_fw_options(scsi_qla_host_t *vha)
1da177e4
LT
1064{
1065 uint16_t swing, emphasis, tx_sens, rx_sens;
e315cd28 1066 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
1067
1068 memset(ha->fw_options, 0, sizeof(ha->fw_options));
e315cd28 1069 qla2x00_get_fw_options(vha, ha->fw_options);
1da177e4
LT
1070
1071 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1072 return;
1073
1074 /* Serial Link options. */
1075 DEBUG3(printk("scsi(%ld): Serial link options:\n",
e315cd28 1076 vha->host_no));
1da177e4
LT
1077 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1078 sizeof(ha->fw_seriallink_options)));
1079
1080 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1081 if (ha->fw_seriallink_options[3] & BIT_2) {
1082 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1083
1084 /* 1G settings */
1085 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1086 emphasis = (ha->fw_seriallink_options[2] &
1087 (BIT_4 | BIT_3)) >> 3;
1088 tx_sens = ha->fw_seriallink_options[0] &
fa2a1ce5 1089 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1da177e4
LT
1090 rx_sens = (ha->fw_seriallink_options[0] &
1091 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1092 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1093 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1094 if (rx_sens == 0x0)
1095 rx_sens = 0x3;
1096 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1097 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1098 ha->fw_options[10] |= BIT_5 |
1099 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1100 (tx_sens & (BIT_1 | BIT_0));
1101
1102 /* 2G settings */
1103 swing = (ha->fw_seriallink_options[2] &
1104 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1105 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1106 tx_sens = ha->fw_seriallink_options[1] &
fa2a1ce5 1107 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1da177e4
LT
1108 rx_sens = (ha->fw_seriallink_options[1] &
1109 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1110 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1111 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1112 if (rx_sens == 0x0)
1113 rx_sens = 0x3;
1114 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1115 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1116 ha->fw_options[11] |= BIT_5 |
1117 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1118 (tx_sens & (BIT_1 | BIT_0));
1119 }
1120
1121 /* FCP2 options. */
1122 /* Return command IOCBs without waiting for an ABTS to complete. */
1123 ha->fw_options[3] |= BIT_13;
1124
1125 /* LED scheme. */
1126 if (ha->flags.enable_led_scheme)
1127 ha->fw_options[2] |= BIT_12;
1128
48c02fde
AV
1129 /* Detect ISP6312. */
1130 if (IS_QLA6312(ha))
1131 ha->fw_options[2] |= BIT_13;
1132
1da177e4 1133 /* Update firmware options. */
e315cd28 1134 qla2x00_set_fw_options(vha, ha->fw_options);
1da177e4
LT
1135}
1136
0107109e 1137void
e315cd28 1138qla24xx_update_fw_options(scsi_qla_host_t *vha)
0107109e
AV
1139{
1140 int rval;
e315cd28 1141 struct qla_hw_data *ha = vha->hw;
0107109e
AV
1142
1143 /* Update Serial Link options. */
f94097ed 1144 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
0107109e
AV
1145 return;
1146
e315cd28 1147 rval = qla2x00_set_serdes_params(vha,
f94097ed
AV
1148 le16_to_cpu(ha->fw_seriallink_options24[1]),
1149 le16_to_cpu(ha->fw_seriallink_options24[2]),
1150 le16_to_cpu(ha->fw_seriallink_options24[3]));
0107109e
AV
1151 if (rval != QLA_SUCCESS) {
1152 qla_printk(KERN_WARNING, ha,
1153 "Unable to update Serial Link options (%x).\n", rval);
1154 }
1155}
1156
abbd8870 1157void
e315cd28 1158qla2x00_config_rings(struct scsi_qla_host *vha)
abbd8870 1159{
e315cd28 1160 struct qla_hw_data *ha = vha->hw;
3d71644c 1161 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
73208dfd
AC
1162 struct req_que *req = ha->req_q_map[0];
1163 struct rsp_que *rsp = ha->rsp_q_map[0];
abbd8870
AV
1164
1165 /* Setup ring parameters in initialization control block. */
1166 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1167 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
e315cd28
AC
1168 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1169 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1170 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1171 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1172 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1173 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
abbd8870
AV
1174
1175 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1176 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1177 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1178 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1179 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1180}
1181
0107109e 1182void
e315cd28 1183qla24xx_config_rings(struct scsi_qla_host *vha)
0107109e 1184{
e315cd28 1185 struct qla_hw_data *ha = vha->hw;
73208dfd
AC
1186 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1187 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1188 struct qla_msix_entry *msix;
0107109e 1189 struct init_cb_24xx *icb;
73208dfd
AC
1190 uint16_t rid = 0;
1191 struct req_que *req = ha->req_q_map[0];
1192 struct rsp_que *rsp = ha->rsp_q_map[0];
0107109e 1193
73208dfd 1194/* Setup ring parameters in initialization control block. */
0107109e
AV
1195 icb = (struct init_cb_24xx *)ha->init_cb;
1196 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1197 icb->response_q_inpointer = __constant_cpu_to_le16(0);
e315cd28
AC
1198 icb->request_q_length = cpu_to_le16(req->length);
1199 icb->response_q_length = cpu_to_le16(rsp->length);
1200 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1201 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1202 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1203 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
0107109e 1204
73208dfd
AC
1205 if (ha->mqenable) {
1206 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1207 icb->rid = __constant_cpu_to_le16(rid);
1208 if (ha->flags.msix_enabled) {
1209 msix = &ha->msix_entries[1];
1210 DEBUG2_17(printk(KERN_INFO
1211 "Reistering vector 0x%x for base que\n", msix->entry));
1212 icb->msix = cpu_to_le16(msix->entry);
1213 }
1214 /* Use alternate PCI bus number */
1215 if (MSB(rid))
1216 icb->firmware_options_2 |=
1217 __constant_cpu_to_le32(BIT_19);
1218 /* Use alternate PCI devfn */
1219 if (LSB(rid))
1220 icb->firmware_options_2 |=
1221 __constant_cpu_to_le32(BIT_18);
1222
1223 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
1224 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1225 ha->rsp_q_map[0]->options = icb->firmware_options_2;
1226
1227 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1228 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1229 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1230 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1231 } else {
1232 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1233 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1234 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1235 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1236 }
1237 /* PCI posting */
1238 RD_REG_DWORD(&ioreg->hccr);
0107109e
AV
1239}
1240
1da177e4
LT
1241/**
1242 * qla2x00_init_rings() - Initializes firmware.
1243 * @ha: HA context
1244 *
1245 * Beginning of request ring has initialization control block already built
1246 * by nvram config routine.
1247 *
1248 * Returns 0 on success.
1249 */
1250static int
e315cd28 1251qla2x00_init_rings(scsi_qla_host_t *vha)
1da177e4
LT
1252{
1253 int rval;
1254 unsigned long flags = 0;
1255 int cnt;
e315cd28 1256 struct qla_hw_data *ha = vha->hw;
73208dfd
AC
1257 struct req_que *req = ha->req_q_map[0];
1258 struct rsp_que *rsp = ha->rsp_q_map[0];
2c3dfe3f
SJ
1259 struct mid_init_cb_24xx *mid_init_cb =
1260 (struct mid_init_cb_24xx *) ha->init_cb;
1da177e4
LT
1261
1262 spin_lock_irqsave(&ha->hardware_lock, flags);
1263
1264 /* Clear outstanding commands array. */
1265 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
e315cd28 1266 req->outstanding_cmds[cnt] = NULL;
1da177e4 1267
e315cd28 1268 req->current_outstanding_cmd = 0;
1da177e4
LT
1269
1270 /* Clear RSCN queue. */
e315cd28
AC
1271 vha->rscn_in_ptr = 0;
1272 vha->rscn_out_ptr = 0;
1da177e4
LT
1273
1274 /* Initialize firmware. */
e315cd28
AC
1275 req->ring_ptr = req->ring;
1276 req->ring_index = 0;
1277 req->cnt = req->length;
1278 rsp->ring_ptr = rsp->ring;
1279 rsp->ring_index = 0;
1da177e4 1280
1da177e4 1281 /* Initialize response queue entries */
73208dfd 1282 qla2x00_init_response_q_entries(rsp);
1da177e4 1283
e315cd28 1284 ha->isp_ops->config_rings(vha);
1da177e4
LT
1285
1286 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1287
1288 /* Update any ISP specific firmware options before initialization. */
e315cd28 1289 ha->isp_ops->update_fw_options(vha);
1da177e4 1290
e315cd28 1291 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
2c3dfe3f 1292
c48339de
SJ
1293 if (ha->flags.npiv_supported)
1294 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1295
eb66dc60 1296 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
2c3dfe3f 1297
e315cd28 1298 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
1da177e4
LT
1299 if (rval) {
1300 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
e315cd28 1301 vha->host_no));
1da177e4
LT
1302 } else {
1303 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
e315cd28 1304 vha->host_no));
1da177e4
LT
1305 }
1306
1307 return (rval);
1308}
1309
1310/**
1311 * qla2x00_fw_ready() - Waits for firmware ready.
1312 * @ha: HA context
1313 *
1314 * Returns 0 on success.
1315 */
1316static int
e315cd28 1317qla2x00_fw_ready(scsi_qla_host_t *vha)
1da177e4
LT
1318{
1319 int rval;
4d4df193 1320 unsigned long wtime, mtime, cs84xx_time;
1da177e4
LT
1321 uint16_t min_wait; /* Minimum wait time if loop is down */
1322 uint16_t wait_time; /* Wait time if loop is coming ready */
4d4df193 1323 uint16_t state[3];
e315cd28 1324 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
1325
1326 rval = QLA_SUCCESS;
1327
1328 /* 20 seconds for loop down. */
fa2a1ce5 1329 min_wait = 20;
1da177e4
LT
1330
1331 /*
1332 * Firmware should take at most one RATOV to login, plus 5 seconds for
1333 * our own processing.
1334 */
1335 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1336 wait_time = min_wait;
1337 }
1338
1339 /* Min wait time if loop down */
1340 mtime = jiffies + (min_wait * HZ);
1341
1342 /* wait time before firmware ready */
1343 wtime = jiffies + (wait_time * HZ);
1344
1345 /* Wait for ISP to finish LIP */
e315cd28 1346 if (!vha->flags.init_done)
1da177e4
LT
1347 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1348
1349 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
e315cd28 1350 vha->host_no));
1da177e4
LT
1351
1352 do {
e315cd28 1353 rval = qla2x00_get_firmware_state(vha, state);
1da177e4 1354 if (rval == QLA_SUCCESS) {
4d4df193 1355 if (state[0] < FSTATE_LOSS_OF_SYNC) {
e315cd28 1356 vha->device_flags &= ~DFLG_NO_CABLE;
1da177e4 1357 }
4d4df193
HK
1358 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1359 DEBUG16(printk("scsi(%ld): fw_state=%x "
e315cd28 1360 "84xx=%x.\n", vha->host_no, state[0],
4d4df193
HK
1361 state[2]));
1362 if ((state[2] & FSTATE_LOGGED_IN) &&
1363 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1364 DEBUG16(printk("scsi(%ld): Sending "
e315cd28 1365 "verify iocb.\n", vha->host_no));
4d4df193
HK
1366
1367 cs84xx_time = jiffies;
e315cd28 1368 rval = qla84xx_init_chip(vha);
4d4df193
HK
1369 if (rval != QLA_SUCCESS)
1370 break;
1371
1372 /* Add time taken to initialize. */
1373 cs84xx_time = jiffies - cs84xx_time;
1374 wtime += cs84xx_time;
1375 mtime += cs84xx_time;
1376 DEBUG16(printk("scsi(%ld): Increasing "
1377 "wait time by %ld. New time %ld\n",
e315cd28 1378 vha->host_no, cs84xx_time, wtime));
4d4df193
HK
1379 }
1380 } else if (state[0] == FSTATE_READY) {
1da177e4 1381 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
e315cd28 1382 vha->host_no));
1da177e4 1383
e315cd28 1384 qla2x00_get_retry_cnt(vha, &ha->retry_count,
1da177e4
LT
1385 &ha->login_timeout, &ha->r_a_tov);
1386
1387 rval = QLA_SUCCESS;
1388 break;
1389 }
1390
1391 rval = QLA_FUNCTION_FAILED;
1392
e315cd28 1393 if (atomic_read(&vha->loop_down_timer) &&
4d4df193 1394 state[0] != FSTATE_READY) {
1da177e4 1395 /* Loop down. Timeout on min_wait for states
fa2a1ce5
AV
1396 * other than Wait for Login.
1397 */
1da177e4
LT
1398 if (time_after_eq(jiffies, mtime)) {
1399 qla_printk(KERN_INFO, ha,
1400 "Cable is unplugged...\n");
1401
e315cd28 1402 vha->device_flags |= DFLG_NO_CABLE;
1da177e4
LT
1403 break;
1404 }
1405 }
1406 } else {
1407 /* Mailbox cmd failed. Timeout on min_wait. */
1408 if (time_after_eq(jiffies, mtime))
1409 break;
1410 }
1411
1412 if (time_after_eq(jiffies, wtime))
1413 break;
1414
1415 /* Delay for a while */
1416 msleep(500);
1417
1418 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
e315cd28 1419 vha->host_no, state[0], jiffies));
1da177e4
LT
1420 } while (1);
1421
1422 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
e315cd28 1423 vha->host_no, state[0], jiffies));
1da177e4
LT
1424
1425 if (rval) {
1426 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
e315cd28 1427 vha->host_no));
1da177e4
LT
1428 }
1429
1430 return (rval);
1431}
1432
1433/*
1434* qla2x00_configure_hba
1435* Setup adapter context.
1436*
1437* Input:
1438* ha = adapter state pointer.
1439*
1440* Returns:
1441* 0 = success
1442*
1443* Context:
1444* Kernel context.
1445*/
1446static int
e315cd28 1447qla2x00_configure_hba(scsi_qla_host_t *vha)
1da177e4
LT
1448{
1449 int rval;
1450 uint16_t loop_id;
1451 uint16_t topo;
2c3dfe3f 1452 uint16_t sw_cap;
1da177e4
LT
1453 uint8_t al_pa;
1454 uint8_t area;
1455 uint8_t domain;
1456 char connect_type[22];
e315cd28 1457 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
1458
1459 /* Get host addresses. */
e315cd28 1460 rval = qla2x00_get_adapter_id(vha,
2c3dfe3f 1461 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
1da177e4 1462 if (rval != QLA_SUCCESS) {
e315cd28 1463 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
33135aa2
RA
1464 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1465 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
e315cd28 1466 __func__, vha->host_no));
33135aa2
RA
1467 } else {
1468 qla_printk(KERN_WARNING, ha,
1469 "ERROR -- Unable to get host loop ID.\n");
e315cd28 1470 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
33135aa2 1471 }
1da177e4
LT
1472 return (rval);
1473 }
1474
1475 if (topo == 4) {
1476 qla_printk(KERN_INFO, ha,
1477 "Cannot get topology - retrying.\n");
1478 return (QLA_FUNCTION_FAILED);
1479 }
1480
e315cd28 1481 vha->loop_id = loop_id;
1da177e4
LT
1482
1483 /* initialize */
1484 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1485 ha->operating_mode = LOOP;
2c3dfe3f 1486 ha->switch_cap = 0;
1da177e4
LT
1487
1488 switch (topo) {
1489 case 0:
1490 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
e315cd28 1491 vha->host_no));
1da177e4
LT
1492 ha->current_topology = ISP_CFG_NL;
1493 strcpy(connect_type, "(Loop)");
1494 break;
1495
1496 case 1:
1497 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
e315cd28 1498 vha->host_no));
2c3dfe3f 1499 ha->switch_cap = sw_cap;
1da177e4
LT
1500 ha->current_topology = ISP_CFG_FL;
1501 strcpy(connect_type, "(FL_Port)");
1502 break;
1503
1504 case 2:
1505 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
e315cd28 1506 vha->host_no));
1da177e4
LT
1507 ha->operating_mode = P2P;
1508 ha->current_topology = ISP_CFG_N;
1509 strcpy(connect_type, "(N_Port-to-N_Port)");
1510 break;
1511
1512 case 3:
1513 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
e315cd28 1514 vha->host_no));
2c3dfe3f 1515 ha->switch_cap = sw_cap;
1da177e4
LT
1516 ha->operating_mode = P2P;
1517 ha->current_topology = ISP_CFG_F;
1518 strcpy(connect_type, "(F_Port)");
1519 break;
1520
1521 default:
1522 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1523 "Using NL.\n",
e315cd28 1524 vha->host_no, topo));
1da177e4
LT
1525 ha->current_topology = ISP_CFG_NL;
1526 strcpy(connect_type, "(Loop)");
1527 break;
1528 }
1529
1530 /* Save Host port and loop ID. */
1531 /* byte order - Big Endian */
e315cd28
AC
1532 vha->d_id.b.domain = domain;
1533 vha->d_id.b.area = area;
1534 vha->d_id.b.al_pa = al_pa;
1da177e4 1535
e315cd28 1536 if (!vha->flags.init_done)
1da177e4
LT
1537 qla_printk(KERN_INFO, ha,
1538 "Topology - %s, Host Loop address 0x%x\n",
e315cd28 1539 connect_type, vha->loop_id);
1da177e4
LT
1540
1541 if (rval) {
e315cd28 1542 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
1da177e4 1543 } else {
e315cd28 1544 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
1da177e4
LT
1545 }
1546
1547 return(rval);
1548}
1549
9bb9fcf2 1550static inline void
e315cd28
AC
1551qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1552 char *def)
9bb9fcf2
AV
1553{
1554 char *st, *en;
1555 uint16_t index;
e315cd28 1556 struct qla_hw_data *ha = vha->hw;
9bb9fcf2
AV
1557
1558 if (memcmp(model, BINZERO, len) != 0) {
1559 strncpy(ha->model_number, model, len);
1560 st = en = ha->model_number;
1561 en += len - 1;
1562 while (en > st) {
1563 if (*en != 0x20 && *en != 0x00)
1564 break;
1565 *en-- = '\0';
1566 }
1567
1568 index = (ha->pdev->subsystem_device & 0xff);
1569 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1570 index < QLA_MODEL_NAMES)
1ee27146
JC
1571 strncpy(ha->model_desc,
1572 qla2x00_model_name[index * 2 + 1],
1573 sizeof(ha->model_desc) - 1);
9bb9fcf2
AV
1574 } else {
1575 index = (ha->pdev->subsystem_device & 0xff);
1576 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1577 index < QLA_MODEL_NAMES) {
1578 strcpy(ha->model_number,
1579 qla2x00_model_name[index * 2]);
1ee27146
JC
1580 strncpy(ha->model_desc,
1581 qla2x00_model_name[index * 2 + 1],
1582 sizeof(ha->model_desc) - 1);
9bb9fcf2
AV
1583 } else {
1584 strcpy(ha->model_number, def);
1585 }
1586 }
1ee27146 1587 if (IS_FWI2_CAPABLE(ha))
e315cd28 1588 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
1ee27146 1589 sizeof(ha->model_desc));
9bb9fcf2
AV
1590}
1591
4e08df3f
DM
1592/* On sparc systems, obtain port and node WWN from firmware
1593 * properties.
1594 */
e315cd28 1595static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4e08df3f
DM
1596{
1597#ifdef CONFIG_SPARC
e315cd28 1598 struct qla_hw_data *ha = vha->hw;
4e08df3f 1599 struct pci_dev *pdev = ha->pdev;
15576bc8
DM
1600 struct device_node *dp = pci_device_to_OF_node(pdev);
1601 const u8 *val;
4e08df3f
DM
1602 int len;
1603
1604 val = of_get_property(dp, "port-wwn", &len);
1605 if (val && len >= WWN_SIZE)
1606 memcpy(nv->port_name, val, WWN_SIZE);
1607
1608 val = of_get_property(dp, "node-wwn", &len);
1609 if (val && len >= WWN_SIZE)
1610 memcpy(nv->node_name, val, WWN_SIZE);
1611#endif
1612}
1613
1da177e4
LT
1614/*
1615* NVRAM configuration for ISP 2xxx
1616*
1617* Input:
1618* ha = adapter block pointer.
1619*
1620* Output:
1621* initialization control block in response_ring
1622* host adapters parameters in host adapter block
1623*
1624* Returns:
1625* 0 = success.
1626*/
abbd8870 1627int
e315cd28 1628qla2x00_nvram_config(scsi_qla_host_t *vha)
1da177e4 1629{
4e08df3f 1630 int rval;
0107109e
AV
1631 uint8_t chksum = 0;
1632 uint16_t cnt;
1633 uint8_t *dptr1, *dptr2;
e315cd28 1634 struct qla_hw_data *ha = vha->hw;
0107109e 1635 init_cb_t *icb = ha->init_cb;
281afe19
SJ
1636 nvram_t *nv = ha->nvram;
1637 uint8_t *ptr = ha->nvram;
3d71644c 1638 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4 1639
4e08df3f
DM
1640 rval = QLA_SUCCESS;
1641
1da177e4 1642 /* Determine NVRAM starting address. */
0107109e 1643 ha->nvram_size = sizeof(nvram_t);
1da177e4
LT
1644 ha->nvram_base = 0;
1645 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1646 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1647 ha->nvram_base = 0x80;
1648
1649 /* Get NVRAM data and calculate checksum. */
e315cd28 1650 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
0107109e
AV
1651 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1652 chksum += *ptr++;
1da177e4 1653
e315cd28 1654 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
281afe19 1655 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
1da177e4
LT
1656
1657 /* Bad NVRAM data, set defaults parameters. */
1658 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1659 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1660 /* Reset NVRAM data. */
1661 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1662 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1663 nv->nvram_version);
4e08df3f
DM
1664 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1665 "invalid -- WWPN) defaults.\n");
1666
1667 /*
1668 * Set default initialization control block.
1669 */
1670 memset(nv, 0, ha->nvram_size);
1671 nv->parameter_block_version = ICB_VERSION;
1672
1673 if (IS_QLA23XX(ha)) {
1674 nv->firmware_options[0] = BIT_2 | BIT_1;
1675 nv->firmware_options[1] = BIT_7 | BIT_5;
1676 nv->add_firmware_options[0] = BIT_5;
1677 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1678 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1679 nv->special_options[1] = BIT_7;
1680 } else if (IS_QLA2200(ha)) {
1681 nv->firmware_options[0] = BIT_2 | BIT_1;
1682 nv->firmware_options[1] = BIT_7 | BIT_5;
1683 nv->add_firmware_options[0] = BIT_5;
1684 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1685 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1686 } else if (IS_QLA2100(ha)) {
1687 nv->firmware_options[0] = BIT_3 | BIT_1;
1688 nv->firmware_options[1] = BIT_5;
1689 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1690 }
1691
1692 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1693 nv->execution_throttle = __constant_cpu_to_le16(16);
1694 nv->retry_count = 8;
1695 nv->retry_delay = 1;
1696
1697 nv->port_name[0] = 33;
1698 nv->port_name[3] = 224;
1699 nv->port_name[4] = 139;
1700
e315cd28 1701 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4e08df3f
DM
1702
1703 nv->login_timeout = 4;
1704
1705 /*
1706 * Set default host adapter parameters
1707 */
1708 nv->host_p[1] = BIT_2;
1709 nv->reset_delay = 5;
1710 nv->port_down_retry_count = 8;
1711 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1712 nv->link_down_timeout = 60;
1713
1714 rval = 1;
1da177e4
LT
1715 }
1716
1717#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1718 /*
1719 * The SN2 does not provide BIOS emulation which means you can't change
1720 * potentially bogus BIOS settings. Force the use of default settings
1721 * for link rate and frame size. Hope that the rest of the settings
1722 * are valid.
1723 */
1724 if (ia64_platform_is("sn2")) {
1725 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1726 if (IS_QLA23XX(ha))
1727 nv->special_options[1] = BIT_7;
1728 }
1729#endif
1730
1731 /* Reset Initialization control block */
0107109e 1732 memset(icb, 0, ha->init_cb_size);
1da177e4
LT
1733
1734 /*
1735 * Setup driver NVRAM options.
1736 */
1737 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1738 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1739 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1740 nv->firmware_options[1] &= ~BIT_4;
1741
1742 if (IS_QLA23XX(ha)) {
1743 nv->firmware_options[0] |= BIT_2;
1744 nv->firmware_options[0] &= ~BIT_3;
0107109e 1745 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
1da177e4
LT
1746
1747 if (IS_QLA2300(ha)) {
1748 if (ha->fb_rev == FPM_2310) {
1749 strcpy(ha->model_number, "QLA2310");
1750 } else {
1751 strcpy(ha->model_number, "QLA2300");
1752 }
1753 } else {
e315cd28 1754 qla2x00_set_model_info(vha, nv->model_number,
9bb9fcf2 1755 sizeof(nv->model_number), "QLA23xx");
1da177e4
LT
1756 }
1757 } else if (IS_QLA2200(ha)) {
1758 nv->firmware_options[0] |= BIT_2;
1759 /*
1760 * 'Point-to-point preferred, else loop' is not a safe
1761 * connection mode setting.
1762 */
1763 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1764 (BIT_5 | BIT_4)) {
1765 /* Force 'loop preferred, else point-to-point'. */
1766 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1767 nv->add_firmware_options[0] |= BIT_5;
1768 }
1769 strcpy(ha->model_number, "QLA22xx");
1770 } else /*if (IS_QLA2100(ha))*/ {
1771 strcpy(ha->model_number, "QLA2100");
1772 }
1773
1774 /*
1775 * Copy over NVRAM RISC parameter block to initialization control block.
1776 */
1777 dptr1 = (uint8_t *)icb;
1778 dptr2 = (uint8_t *)&nv->parameter_block_version;
1779 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1780 while (cnt--)
1781 *dptr1++ = *dptr2++;
1782
1783 /* Copy 2nd half. */
1784 dptr1 = (uint8_t *)icb->add_firmware_options;
1785 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1786 while (cnt--)
1787 *dptr1++ = *dptr2++;
1788
5341e868
AV
1789 /* Use alternate WWN? */
1790 if (nv->host_p[1] & BIT_7) {
1791 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1792 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1793 }
1794
1da177e4
LT
1795 /* Prepare nodename */
1796 if ((icb->firmware_options[1] & BIT_6) == 0) {
1797 /*
1798 * Firmware will apply the following mask if the nodename was
1799 * not provided.
1800 */
1801 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1802 icb->node_name[0] &= 0xF0;
1803 }
1804
1805 /*
1806 * Set host adapter parameters.
1807 */
0181944f 1808 if (nv->host_p[0] & BIT_7)
11010fec 1809 ql2xextended_error_logging = 1;
1da177e4
LT
1810 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1811 /* Always load RISC code on non ISP2[12]00 chips. */
1812 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1813 ha->flags.disable_risc_code_load = 0;
1814 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1815 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1816 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
06c22bd1 1817 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
d4c760c2 1818 ha->flags.disable_serdes = 0;
1da177e4
LT
1819
1820 ha->operating_mode =
1821 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1822
1823 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1824 sizeof(ha->fw_seriallink_options));
1825
1826 /* save HBA serial number */
1827 ha->serial0 = icb->port_name[5];
1828 ha->serial1 = icb->port_name[6];
1829 ha->serial2 = icb->port_name[7];
e315cd28
AC
1830 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1831 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
1da177e4
LT
1832
1833 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1834
1835 ha->retry_count = nv->retry_count;
1836
1837 /* Set minimum login_timeout to 4 seconds. */
1838 if (nv->login_timeout < ql2xlogintimeout)
1839 nv->login_timeout = ql2xlogintimeout;
1840 if (nv->login_timeout < 4)
1841 nv->login_timeout = 4;
1842 ha->login_timeout = nv->login_timeout;
1843 icb->login_timeout = nv->login_timeout;
1844
00a537b8
AV
1845 /* Set minimum RATOV to 100 tenths of a second. */
1846 ha->r_a_tov = 100;
1da177e4 1847
1da177e4
LT
1848 ha->loop_reset_delay = nv->reset_delay;
1849
1da177e4
LT
1850 /* Link Down Timeout = 0:
1851 *
1852 * When Port Down timer expires we will start returning
1853 * I/O's to OS with "DID_NO_CONNECT".
1854 *
1855 * Link Down Timeout != 0:
1856 *
1857 * The driver waits for the link to come up after link down
1858 * before returning I/Os to OS with "DID_NO_CONNECT".
fa2a1ce5 1859 */
1da177e4
LT
1860 if (nv->link_down_timeout == 0) {
1861 ha->loop_down_abort_time =
354d6b21 1862 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
1da177e4
LT
1863 } else {
1864 ha->link_down_timeout = nv->link_down_timeout;
1865 ha->loop_down_abort_time =
1866 (LOOP_DOWN_TIME - ha->link_down_timeout);
fa2a1ce5 1867 }
1da177e4 1868
1da177e4
LT
1869 /*
1870 * Need enough time to try and get the port back.
1871 */
1872 ha->port_down_retry_count = nv->port_down_retry_count;
1873 if (qlport_down_retry)
1874 ha->port_down_retry_count = qlport_down_retry;
1875 /* Set login_retry_count */
1876 ha->login_retry_count = nv->retry_count;
1877 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1878 ha->port_down_retry_count > 3)
1879 ha->login_retry_count = ha->port_down_retry_count;
1880 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1881 ha->login_retry_count = ha->port_down_retry_count;
1882 if (ql2xloginretrycount)
1883 ha->login_retry_count = ql2xloginretrycount;
1884
1da177e4
LT
1885 icb->lun_enables = __constant_cpu_to_le16(0);
1886 icb->command_resource_count = 0;
1887 icb->immediate_notify_resource_count = 0;
1888 icb->timeout = __constant_cpu_to_le16(0);
1889
1890 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1891 /* Enable RIO */
1892 icb->firmware_options[0] &= ~BIT_3;
1893 icb->add_firmware_options[0] &=
1894 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1895 icb->add_firmware_options[0] |= BIT_2;
1896 icb->response_accumulation_timer = 3;
1897 icb->interrupt_delay_timer = 5;
1898
e315cd28 1899 vha->flags.process_response_queue = 1;
1da177e4 1900 } else {
4fdfefe5 1901 /* Enable ZIO. */
e315cd28 1902 if (!vha->flags.init_done) {
4fdfefe5
AV
1903 ha->zio_mode = icb->add_firmware_options[0] &
1904 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1905 ha->zio_timer = icb->interrupt_delay_timer ?
1906 icb->interrupt_delay_timer: 2;
1907 }
1da177e4
LT
1908 icb->add_firmware_options[0] &=
1909 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
e315cd28 1910 vha->flags.process_response_queue = 0;
4fdfefe5 1911 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4a59f71d
AV
1912 ha->zio_mode = QLA_ZIO_MODE_6;
1913
4fdfefe5 1914 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
e315cd28 1915 "delay (%d us).\n", vha->host_no, ha->zio_mode,
4fdfefe5 1916 ha->zio_timer * 100));
1da177e4 1917 qla_printk(KERN_INFO, ha,
4fdfefe5
AV
1918 "ZIO mode %d enabled; timer delay (%d us).\n",
1919 ha->zio_mode, ha->zio_timer * 100);
1da177e4 1920
4fdfefe5
AV
1921 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1922 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
e315cd28 1923 vha->flags.process_response_queue = 1;
1da177e4
LT
1924 }
1925 }
1926
4e08df3f
DM
1927 if (rval) {
1928 DEBUG2_3(printk(KERN_WARNING
e315cd28 1929 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4e08df3f
DM
1930 }
1931 return (rval);
1da177e4
LT
1932}
1933
19a7b4ae
JSEC
1934static void
1935qla2x00_rport_del(void *data)
1936{
1937 fc_port_t *fcport = data;
d97994dc 1938 struct fc_rport *rport;
d97994dc 1939
e315cd28 1940 spin_lock_irq(fcport->vha->host->host_lock);
d97994dc
AV
1941 rport = fcport->drport;
1942 fcport->drport = NULL;
e315cd28 1943 spin_unlock_irq(fcport->vha->host->host_lock);
d97994dc
AV
1944 if (rport)
1945 fc_remote_port_delete(rport);
19a7b4ae
JSEC
1946}
1947
1da177e4
LT
1948/**
1949 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1950 * @ha: HA context
1951 * @flags: allocation flags
1952 *
1953 * Returns a pointer to the allocated fcport, or NULL, if none available.
1954 */
413975a0 1955static fc_port_t *
e315cd28 1956qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
1da177e4
LT
1957{
1958 fc_port_t *fcport;
1959
bbfbbbc1
MK
1960 fcport = kzalloc(sizeof(fc_port_t), flags);
1961 if (!fcport)
1962 return NULL;
1da177e4
LT
1963
1964 /* Setup fcport template structure. */
e315cd28
AC
1965 fcport->vha = vha;
1966 fcport->vp_idx = vha->vp_idx;
1da177e4
LT
1967 fcport->port_type = FCT_UNKNOWN;
1968 fcport->loop_id = FC_NO_LOOP_ID;
1da177e4
LT
1969 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1970 fcport->flags = FCF_RLC_SUPPORT;
ad3e0eda 1971 fcport->supported_classes = FC_COS_UNSPECIFIED;
1da177e4 1972
bbfbbbc1 1973 return fcport;
1da177e4
LT
1974}
1975
1976/*
1977 * qla2x00_configure_loop
1978 * Updates Fibre Channel Device Database with what is actually on loop.
1979 *
1980 * Input:
1981 * ha = adapter block pointer.
1982 *
1983 * Returns:
1984 * 0 = success.
1985 * 1 = error.
1986 * 2 = database was full and device was not configured.
1987 */
1988static int
e315cd28 1989qla2x00_configure_loop(scsi_qla_host_t *vha)
1da177e4
LT
1990{
1991 int rval;
1992 unsigned long flags, save_flags;
e315cd28 1993 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
1994 rval = QLA_SUCCESS;
1995
1996 /* Get Initiator ID */
e315cd28
AC
1997 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1998 rval = qla2x00_configure_hba(vha);
1da177e4
LT
1999 if (rval != QLA_SUCCESS) {
2000 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
e315cd28 2001 vha->host_no));
1da177e4
LT
2002 return (rval);
2003 }
2004 }
2005
e315cd28 2006 save_flags = flags = vha->dpc_flags;
1da177e4 2007 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
e315cd28 2008 vha->host_no, flags));
1da177e4
LT
2009
2010 /*
2011 * If we have both an RSCN and PORT UPDATE pending then handle them
2012 * both at the same time.
2013 */
e315cd28
AC
2014 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2015 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
1da177e4
LT
2016
2017 /* Determine what we need to do */
2018 if (ha->current_topology == ISP_CFG_FL &&
2019 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2020
e315cd28 2021 vha->flags.rscn_queue_overflow = 1;
1da177e4
LT
2022 set_bit(RSCN_UPDATE, &flags);
2023
2024 } else if (ha->current_topology == ISP_CFG_F &&
2025 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2026
e315cd28 2027 vha->flags.rscn_queue_overflow = 1;
1da177e4
LT
2028 set_bit(RSCN_UPDATE, &flags);
2029 clear_bit(LOCAL_LOOP_UPDATE, &flags);
21333b48
AV
2030
2031 } else if (ha->current_topology == ISP_CFG_N) {
2032 clear_bit(RSCN_UPDATE, &flags);
1da177e4 2033
e315cd28 2034 } else if (!vha->flags.online ||
1da177e4
LT
2035 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2036
e315cd28 2037 vha->flags.rscn_queue_overflow = 1;
1da177e4
LT
2038 set_bit(RSCN_UPDATE, &flags);
2039 set_bit(LOCAL_LOOP_UPDATE, &flags);
2040 }
2041
2042 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
e315cd28 2043 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
1da177e4 2044 rval = QLA_FUNCTION_FAILED;
e315cd28
AC
2045 else
2046 rval = qla2x00_configure_local_loop(vha);
1da177e4
LT
2047 }
2048
2049 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
e315cd28 2050 if (LOOP_TRANSITION(vha))
1da177e4 2051 rval = QLA_FUNCTION_FAILED;
e315cd28
AC
2052 else
2053 rval = qla2x00_configure_fabric(vha);
1da177e4
LT
2054 }
2055
2056 if (rval == QLA_SUCCESS) {
e315cd28
AC
2057 if (atomic_read(&vha->loop_down_timer) ||
2058 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
1da177e4
LT
2059 rval = QLA_FUNCTION_FAILED;
2060 } else {
e315cd28 2061 atomic_set(&vha->loop_state, LOOP_READY);
1da177e4 2062
e315cd28 2063 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
1da177e4
LT
2064 }
2065 }
2066
2067 if (rval) {
2068 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
e315cd28 2069 __func__, vha->host_no));
1da177e4
LT
2070 } else {
2071 DEBUG3(printk("%s: exiting normally\n", __func__));
2072 }
2073
cc3ef7bc 2074 /* Restore state if a resync event occurred during processing */
e315cd28 2075 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
1da177e4 2076 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
e315cd28 2077 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
73208dfd 2078 if (test_bit(RSCN_UPDATE, &save_flags))
e315cd28 2079 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1da177e4
LT
2080 }
2081
2082 return (rval);
2083}
2084
2085
2086
2087/*
2088 * qla2x00_configure_local_loop
2089 * Updates Fibre Channel Device Database with local loop devices.
2090 *
2091 * Input:
2092 * ha = adapter block pointer.
2093 *
2094 * Returns:
2095 * 0 = success.
2096 */
2097static int
e315cd28 2098qla2x00_configure_local_loop(scsi_qla_host_t *vha)
1da177e4
LT
2099{
2100 int rval, rval2;
2101 int found_devs;
2102 int found;
2103 fc_port_t *fcport, *new_fcport;
2104
2105 uint16_t index;
2106 uint16_t entries;
2107 char *id_iter;
2108 uint16_t loop_id;
2109 uint8_t domain, area, al_pa;
e315cd28 2110 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
2111
2112 found_devs = 0;
2113 new_fcport = NULL;
2114 entries = MAX_FIBRE_DEVICES;
2115
e315cd28
AC
2116 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2117 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
1da177e4
LT
2118
2119 /* Get list of logged in devices. */
2120 memset(ha->gid_list, 0, GID_LIST_SIZE);
e315cd28 2121 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
1da177e4
LT
2122 &entries);
2123 if (rval != QLA_SUCCESS)
2124 goto cleanup_allocation;
2125
2126 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2127 ha->host_no, entries));
2128 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2129 entries * sizeof(struct gid_list_info)));
2130
2131 /* Allocate temporary fcport for any new fcports discovered. */
e315cd28 2132 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1da177e4
LT
2133 if (new_fcport == NULL) {
2134 rval = QLA_MEMORY_ALLOC_FAILED;
2135 goto cleanup_allocation;
2136 }
2137 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2138
2139 /*
2140 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2141 */
e315cd28 2142 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1da177e4
LT
2143 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2144 fcport->port_type != FCT_BROADCAST &&
2145 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2146
2147 DEBUG(printk("scsi(%ld): Marking port lost, "
2148 "loop_id=0x%04x\n",
e315cd28 2149 vha->host_no, fcport->loop_id));
1da177e4
LT
2150
2151 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2152 fcport->flags &= ~FCF_FARP_DONE;
2153 }
2154 }
2155
2156 /* Add devices to port list. */
2157 id_iter = (char *)ha->gid_list;
2158 for (index = 0; index < entries; index++) {
2159 domain = ((struct gid_list_info *)id_iter)->domain;
2160 area = ((struct gid_list_info *)id_iter)->area;
2161 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
abbd8870 2162 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1da177e4
LT
2163 loop_id = (uint16_t)
2164 ((struct gid_list_info *)id_iter)->loop_id_2100;
abbd8870 2165 else
1da177e4
LT
2166 loop_id = le16_to_cpu(
2167 ((struct gid_list_info *)id_iter)->loop_id);
abbd8870 2168 id_iter += ha->gid_list_info_size;
1da177e4
LT
2169
2170 /* Bypass reserved domain fields. */
2171 if ((domain & 0xf0) == 0xf0)
2172 continue;
2173
2174 /* Bypass if not same domain and area of adapter. */
f7d289f6 2175 if (area && domain &&
e315cd28 2176 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
1da177e4
LT
2177 continue;
2178
2179 /* Bypass invalid local loop ID. */
2180 if (loop_id > LAST_LOCAL_LOOP_ID)
2181 continue;
2182
2183 /* Fill in member data. */
2184 new_fcport->d_id.b.domain = domain;
2185 new_fcport->d_id.b.area = area;
2186 new_fcport->d_id.b.al_pa = al_pa;
2187 new_fcport->loop_id = loop_id;
e315cd28
AC
2188 new_fcport->vp_idx = vha->vp_idx;
2189 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
1da177e4
LT
2190 if (rval2 != QLA_SUCCESS) {
2191 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2192 "information -- get_port_database=%x, "
2193 "loop_id=0x%04x\n",
e315cd28 2194 vha->host_no, rval2, new_fcport->loop_id));
c9d02acf 2195 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
e315cd28
AC
2196 vha->host_no));
2197 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1da177e4
LT
2198 continue;
2199 }
2200
2201 /* Check for matching device in port list. */
2202 found = 0;
2203 fcport = NULL;
e315cd28 2204 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1da177e4
LT
2205 if (memcmp(new_fcport->port_name, fcport->port_name,
2206 WWN_SIZE))
2207 continue;
2208
2209 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2210 FCF_PERSISTENT_BOUND);
2211 fcport->loop_id = new_fcport->loop_id;
2212 fcport->port_type = new_fcport->port_type;
2213 fcport->d_id.b24 = new_fcport->d_id.b24;
2214 memcpy(fcport->node_name, new_fcport->node_name,
2215 WWN_SIZE);
2216
2217 found++;
2218 break;
2219 }
2220
2221 if (!found) {
2222 /* New device, add to fcports list. */
2223 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
e315cd28
AC
2224 if (vha->vp_idx) {
2225 new_fcport->vha = vha;
2226 new_fcport->vp_idx = vha->vp_idx;
2c3dfe3f 2227 }
e315cd28 2228 list_add_tail(&new_fcport->list, &vha->vp_fcports);
1da177e4
LT
2229
2230 /* Allocate a new replacement fcport. */
2231 fcport = new_fcport;
e315cd28 2232 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1da177e4
LT
2233 if (new_fcport == NULL) {
2234 rval = QLA_MEMORY_ALLOC_FAILED;
2235 goto cleanup_allocation;
2236 }
2237 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2238 }
2239
d8b45213 2240 /* Base iIDMA settings on HBA port speed. */
a3cbdfad 2241 fcport->fp_speed = ha->link_data_rate;
d8b45213 2242
e315cd28 2243 qla2x00_update_fcport(vha, fcport);
1da177e4
LT
2244
2245 found_devs++;
2246 }
2247
2248cleanup_allocation:
c9475cb0 2249 kfree(new_fcport);
1da177e4
LT
2250
2251 if (rval != QLA_SUCCESS) {
2252 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
e315cd28 2253 "rval=%x\n", vha->host_no, rval));
1da177e4
LT
2254 }
2255
2256 if (found_devs) {
e315cd28
AC
2257 vha->device_flags |= DFLG_LOCAL_DEVICES;
2258 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
1da177e4
LT
2259 }
2260
2261 return (rval);
2262}
2263
d8b45213 2264static void
e315cd28 2265qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
d8b45213
AV
2266{
2267#define LS_UNKNOWN 2
a3cbdfad 2268 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
d8b45213 2269 int rval;
a3cbdfad 2270 uint16_t mb[6];
e315cd28 2271 struct qla_hw_data *ha = vha->hw;
d8b45213 2272
c76f2c01 2273 if (!IS_IIDMA_CAPABLE(ha))
d8b45213
AV
2274 return;
2275
39bd9622
AV
2276 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2277 fcport->fp_speed > ha->link_data_rate)
d8b45213
AV
2278 return;
2279
e315cd28 2280 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
a3cbdfad 2281 mb);
d8b45213
AV
2282 if (rval != QLA_SUCCESS) {
2283 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2284 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
e315cd28 2285 vha->host_no, fcport->port_name[0], fcport->port_name[1],
d8b45213
AV
2286 fcport->port_name[2], fcport->port_name[3],
2287 fcport->port_name[4], fcport->port_name[5],
2288 fcport->port_name[6], fcport->port_name[7], rval,
a3cbdfad 2289 fcport->fp_speed, mb[0], mb[1]));
d8b45213
AV
2290 } else {
2291 DEBUG2(qla_printk(KERN_INFO, ha,
2292 "iIDMA adjusted to %s GB/s on "
2293 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
a3cbdfad 2294 link_speeds[fcport->fp_speed], fcport->port_name[0],
d8b45213
AV
2295 fcport->port_name[1], fcport->port_name[2],
2296 fcport->port_name[3], fcport->port_name[4],
2297 fcport->port_name[5], fcport->port_name[6],
2298 fcport->port_name[7]));
2299 }
2300}
2301
23be331d 2302static void
e315cd28 2303qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e118
AV
2304{
2305 struct fc_rport_identifiers rport_ids;
bdf79621 2306 struct fc_rport *rport;
e315cd28 2307 struct qla_hw_data *ha = vha->hw;
8482e118 2308
d97994dc
AV
2309 if (fcport->drport)
2310 qla2x00_rport_del(fcport);
8482e118 2311
f8b02a85
AV
2312 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2313 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e118
AV
2314 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2315 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
77d74143 2316 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
e315cd28 2317 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
77d74143
AV
2318 if (!rport) {
2319 qla_printk(KERN_WARNING, ha,
2320 "Unable to allocate fc remote port!\n");
2321 return;
2322 }
e315cd28 2323 spin_lock_irq(fcport->vha->host->host_lock);
19a7b4ae 2324 *((fc_port_t **)rport->dd_data) = fcport;
e315cd28 2325 spin_unlock_irq(fcport->vha->host->host_lock);
d97994dc 2326
ad3e0eda 2327 rport->supported_classes = fcport->supported_classes;
77d74143 2328
8482e118
AV
2329 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
2330 if (fcport->port_type == FCT_INITIATOR)
2331 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2332 if (fcport->port_type == FCT_TARGET)
2333 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
77d74143 2334 fc_remote_port_rolechg(rport, rport_ids.roles);
1da177e4
LT
2335}
2336
23be331d
AB
2337/*
2338 * qla2x00_update_fcport
2339 * Updates device on list.
2340 *
2341 * Input:
2342 * ha = adapter block pointer.
2343 * fcport = port structure pointer.
2344 *
2345 * Return:
2346 * 0 - Success
2347 * BIT_0 - error
2348 *
2349 * Context:
2350 * Kernel context.
2351 */
2352void
e315cd28 2353qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
23be331d 2354{
e315cd28 2355 struct qla_hw_data *ha = vha->hw;
2c3dfe3f 2356
e315cd28 2357 fcport->vha = vha;
23be331d 2358 fcport->login_retry = 0;
e315cd28 2359 fcport->port_login_retry_count = ha->port_down_retry_count *
23be331d 2360 PORT_RETRY_TIME;
e315cd28 2361 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
23be331d
AB
2362 PORT_RETRY_TIME);
2363 fcport->flags &= ~FCF_LOGIN_NEEDED;
2364
e315cd28 2365 qla2x00_iidma_fcport(vha, fcport);
23be331d
AB
2366
2367 atomic_set(&fcport->state, FCS_ONLINE);
2368
e315cd28 2369 qla2x00_reg_remote_port(vha, fcport);
23be331d
AB
2370}
2371
1da177e4
LT
2372/*
2373 * qla2x00_configure_fabric
2374 * Setup SNS devices with loop ID's.
2375 *
2376 * Input:
2377 * ha = adapter block pointer.
2378 *
2379 * Returns:
2380 * 0 = success.
2381 * BIT_0 = error
2382 */
2383static int
e315cd28 2384qla2x00_configure_fabric(scsi_qla_host_t *vha)
1da177e4
LT
2385{
2386 int rval, rval2;
2387 fc_port_t *fcport, *fcptemp;
2388 uint16_t next_loopid;
2389 uint16_t mb[MAILBOX_REGISTER_COUNT];
0107109e 2390 uint16_t loop_id;
1da177e4 2391 LIST_HEAD(new_fcports);
e315cd28
AC
2392 struct qla_hw_data *ha = vha->hw;
2393 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
1da177e4
LT
2394
2395 /* If FL port exists, then SNS is present */
e428924c 2396 if (IS_FWI2_CAPABLE(ha))
0107109e
AV
2397 loop_id = NPH_F_PORT;
2398 else
2399 loop_id = SNS_FL_PORT;
e315cd28 2400 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
1da177e4
LT
2401 if (rval != QLA_SUCCESS) {
2402 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
e315cd28 2403 "Port\n", vha->host_no));
1da177e4 2404
e315cd28 2405 vha->device_flags &= ~SWITCH_FOUND;
1da177e4
LT
2406 return (QLA_SUCCESS);
2407 }
e315cd28 2408 vha->device_flags |= SWITCH_FOUND;
1da177e4
LT
2409
2410 /* Mark devices that need re-synchronization. */
e315cd28 2411 rval2 = qla2x00_device_resync(vha);
1da177e4
LT
2412 if (rval2 == QLA_RSCNS_HANDLED) {
2413 /* No point doing the scan, just continue. */
2414 return (QLA_SUCCESS);
2415 }
2416 do {
cca5335c
AV
2417 /* FDMI support. */
2418 if (ql2xfdmienable &&
e315cd28
AC
2419 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2420 qla2x00_fdmi_register(vha);
cca5335c 2421
1da177e4 2422 /* Ensure we are logged into the SNS. */
e428924c 2423 if (IS_FWI2_CAPABLE(ha))
0107109e
AV
2424 loop_id = NPH_SNS;
2425 else
2426 loop_id = SIMPLE_NAME_SERVER;
e315cd28 2427 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
abbd8870 2428 0xfc, mb, BIT_1 | BIT_0);
1da177e4
LT
2429 if (mb[0] != MBS_COMMAND_COMPLETE) {
2430 DEBUG2(qla_printk(KERN_INFO, ha,
2431 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
0107109e 2432 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
1da177e4
LT
2433 mb[0], mb[1], mb[2], mb[6], mb[7]));
2434 return (QLA_SUCCESS);
2435 }
2436
e315cd28
AC
2437 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2438 if (qla2x00_rft_id(vha)) {
1da177e4
LT
2439 /* EMPTY */
2440 DEBUG2(printk("scsi(%ld): Register FC-4 "
e315cd28 2441 "TYPE failed.\n", vha->host_no));
1da177e4 2442 }
e315cd28 2443 if (qla2x00_rff_id(vha)) {
1da177e4
LT
2444 /* EMPTY */
2445 DEBUG2(printk("scsi(%ld): Register FC-4 "
e315cd28 2446 "Features failed.\n", vha->host_no));
1da177e4 2447 }
e315cd28 2448 if (qla2x00_rnn_id(vha)) {
1da177e4
LT
2449 /* EMPTY */
2450 DEBUG2(printk("scsi(%ld): Register Node Name "
e315cd28
AC
2451 "failed.\n", vha->host_no));
2452 } else if (qla2x00_rsnn_nn(vha)) {
1da177e4
LT
2453 /* EMPTY */
2454 DEBUG2(printk("scsi(%ld): Register Symbolic "
e315cd28 2455 "Node Name failed.\n", vha->host_no));
1da177e4
LT
2456 }
2457 }
2458
e315cd28 2459 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
1da177e4
LT
2460 if (rval != QLA_SUCCESS)
2461 break;
2462
2463 /*
2464 * Logout all previous fabric devices marked lost, except
2465 * tape devices.
2466 */
e315cd28
AC
2467 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2468 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
1da177e4
LT
2469 break;
2470
2471 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2472 continue;
2473
2474 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
e315cd28 2475 qla2x00_mark_device_lost(vha, fcport,
d97994dc 2476 ql2xplogiabsentdevice, 0);
1da177e4
LT
2477 if (fcport->loop_id != FC_NO_LOOP_ID &&
2478 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2479 fcport->port_type != FCT_INITIATOR &&
2480 fcport->port_type != FCT_BROADCAST) {
e315cd28 2481 ha->isp_ops->fabric_logout(vha,
1c7c6357
AV
2482 fcport->loop_id,
2483 fcport->d_id.b.domain,
2484 fcport->d_id.b.area,
2485 fcport->d_id.b.al_pa);
1da177e4
LT
2486 fcport->loop_id = FC_NO_LOOP_ID;
2487 }
2488 }
2489 }
2490
2491 /* Starting free loop ID. */
e315cd28 2492 next_loopid = ha->min_external_loopid;
1da177e4
LT
2493
2494 /*
2495 * Scan through our port list and login entries that need to be
2496 * logged in.
2497 */
e315cd28
AC
2498 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2499 if (atomic_read(&vha->loop_down_timer) ||
2500 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
1da177e4
LT
2501 break;
2502
2503 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2504 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2505 continue;
2506
2507 if (fcport->loop_id == FC_NO_LOOP_ID) {
2508 fcport->loop_id = next_loopid;
d4486fd6 2509 rval = qla2x00_find_new_loop_id(
e315cd28 2510 base_vha, fcport);
1da177e4
LT
2511 if (rval != QLA_SUCCESS) {
2512 /* Ran out of IDs to use */
2513 break;
2514 }
2515 }
1da177e4 2516 /* Login and update database */
e315cd28 2517 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
1da177e4
LT
2518 }
2519
2520 /* Exit if out of loop IDs. */
2521 if (rval != QLA_SUCCESS) {
2522 break;
2523 }
2524
2525 /*
2526 * Login and add the new devices to our port list.
2527 */
2528 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
e315cd28
AC
2529 if (atomic_read(&vha->loop_down_timer) ||
2530 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
1da177e4
LT
2531 break;
2532
2533 /* Find a new loop ID to use. */
2534 fcport->loop_id = next_loopid;
e315cd28 2535 rval = qla2x00_find_new_loop_id(base_vha, fcport);
1da177e4
LT
2536 if (rval != QLA_SUCCESS) {
2537 /* Ran out of IDs to use */
2538 break;
2539 }
2540
bdf79621 2541 /* Login and update database */
e315cd28
AC
2542 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
2543
2544 if (vha->vp_idx) {
2545 fcport->vha = vha;
2546 fcport->vp_idx = vha->vp_idx;
2547 }
2548 list_move_tail(&fcport->list, &vha->vp_fcports);
1da177e4
LT
2549 }
2550 } while (0);
2551
2552 /* Free all new device structures not processed. */
2553 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2554 list_del(&fcport->list);
2555 kfree(fcport);
2556 }
2557
2558 if (rval) {
2559 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
e315cd28 2560 "rval=%d\n", vha->host_no, rval));
1da177e4
LT
2561 }
2562
2563 return (rval);
2564}
2565
2566
2567/*
2568 * qla2x00_find_all_fabric_devs
2569 *
2570 * Input:
2571 * ha = adapter block pointer.
2572 * dev = database device entry pointer.
2573 *
2574 * Returns:
2575 * 0 = success.
2576 *
2577 * Context:
2578 * Kernel context.
2579 */
2580static int
e315cd28
AC
2581qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2582 struct list_head *new_fcports)
1da177e4
LT
2583{
2584 int rval;
2585 uint16_t loop_id;
2586 fc_port_t *fcport, *new_fcport, *fcptemp;
2587 int found;
2588
2589 sw_info_t *swl;
2590 int swl_idx;
2591 int first_dev, last_dev;
2592 port_id_t wrap, nxt_d_id;
e315cd28
AC
2593 struct qla_hw_data *ha = vha->hw;
2594 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
1da177e4
LT
2595
2596 rval = QLA_SUCCESS;
2597
2598 /* Try GID_PT to get device list, else GAN. */
4b89258c 2599 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
bbfbbbc1 2600 if (!swl) {
1da177e4
LT
2601 /*EMPTY*/
2602 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
e315cd28 2603 "on GA_NXT\n", vha->host_no));
1da177e4 2604 } else {
e315cd28 2605 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
1da177e4
LT
2606 kfree(swl);
2607 swl = NULL;
e315cd28 2608 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
1da177e4
LT
2609 kfree(swl);
2610 swl = NULL;
e315cd28 2611 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
1da177e4
LT
2612 kfree(swl);
2613 swl = NULL;
e5896bd5 2614 } else if (ql2xiidmaenable &&
e315cd28
AC
2615 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2616 qla2x00_gpsc(vha, swl);
1da177e4
LT
2617 }
2618 }
2619 swl_idx = 0;
2620
2621 /* Allocate temporary fcport for any new fcports discovered. */
e315cd28 2622 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1da177e4 2623 if (new_fcport == NULL) {
c9475cb0 2624 kfree(swl);
1da177e4
LT
2625 return (QLA_MEMORY_ALLOC_FAILED);
2626 }
2627 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
1da177e4
LT
2628 /* Set start port ID scan at adapter ID. */
2629 first_dev = 1;
2630 last_dev = 0;
2631
2632 /* Starting free loop ID. */
e315cd28
AC
2633 loop_id = ha->min_external_loopid;
2634 for (; loop_id <= ha->max_loop_id; loop_id++) {
2635 if (qla2x00_is_reserved_id(vha, loop_id))
1da177e4
LT
2636 continue;
2637
e315cd28 2638 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
1da177e4
LT
2639 break;
2640
2641 if (swl != NULL) {
2642 if (last_dev) {
2643 wrap.b24 = new_fcport->d_id.b24;
2644 } else {
2645 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2646 memcpy(new_fcport->node_name,
2647 swl[swl_idx].node_name, WWN_SIZE);
2648 memcpy(new_fcport->port_name,
2649 swl[swl_idx].port_name, WWN_SIZE);
d8b45213
AV
2650 memcpy(new_fcport->fabric_port_name,
2651 swl[swl_idx].fabric_port_name, WWN_SIZE);
2652 new_fcport->fp_speed = swl[swl_idx].fp_speed;
1da177e4
LT
2653
2654 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2655 last_dev = 1;
2656 }
2657 swl_idx++;
2658 }
2659 } else {
2660 /* Send GA_NXT to the switch */
e315cd28 2661 rval = qla2x00_ga_nxt(vha, new_fcport);
1da177e4
LT
2662 if (rval != QLA_SUCCESS) {
2663 qla_printk(KERN_WARNING, ha,
2664 "SNS scan failed -- assuming zero-entry "
2665 "result...\n");
2666 list_for_each_entry_safe(fcport, fcptemp,
2667 new_fcports, list) {
2668 list_del(&fcport->list);
2669 kfree(fcport);
2670 }
2671 rval = QLA_SUCCESS;
2672 break;
2673 }
2674 }
2675
2676 /* If wrap on switch device list, exit. */
2677 if (first_dev) {
2678 wrap.b24 = new_fcport->d_id.b24;
2679 first_dev = 0;
2680 } else if (new_fcport->d_id.b24 == wrap.b24) {
2681 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
e315cd28 2682 vha->host_no, new_fcport->d_id.b.domain,
1da177e4
LT
2683 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2684 break;
2685 }
2686
2c3dfe3f 2687 /* Bypass if same physical adapter. */
e315cd28 2688 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
1da177e4
LT
2689 continue;
2690
2c3dfe3f 2691 /* Bypass virtual ports of the same host. */
e315cd28
AC
2692 found = 0;
2693 if (ha->num_vhosts) {
2694 list_for_each_entry(vp, &ha->vp_list, list) {
2695 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2696 found = 1;
2c3dfe3f 2697 break;
e315cd28 2698 }
2c3dfe3f 2699 }
e315cd28 2700 if (found)
2c3dfe3f
SJ
2701 continue;
2702 }
2703
f7d289f6
AV
2704 /* Bypass if same domain and area of adapter. */
2705 if (((new_fcport->d_id.b24 & 0xffff00) ==
e315cd28 2706 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
f7d289f6
AV
2707 ISP_CFG_FL)
2708 continue;
2709
1da177e4
LT
2710 /* Bypass reserved domain fields. */
2711 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2712 continue;
2713
2714 /* Locate matching device in database. */
2715 found = 0;
e315cd28 2716 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1da177e4
LT
2717 if (memcmp(new_fcport->port_name, fcport->port_name,
2718 WWN_SIZE))
2719 continue;
2720
2721 found++;
2722
d8b45213
AV
2723 /* Update port state. */
2724 memcpy(fcport->fabric_port_name,
2725 new_fcport->fabric_port_name, WWN_SIZE);
2726 fcport->fp_speed = new_fcport->fp_speed;
2727
1da177e4
LT
2728 /*
2729 * If address the same and state FCS_ONLINE, nothing
2730 * changed.
2731 */
2732 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2733 atomic_read(&fcport->state) == FCS_ONLINE) {
2734 break;
2735 }
2736
2737 /*
2738 * If device was not a fabric device before.
2739 */
2740 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2741 fcport->d_id.b24 = new_fcport->d_id.b24;
2742 fcport->loop_id = FC_NO_LOOP_ID;
2743 fcport->flags |= (FCF_FABRIC_DEVICE |
2744 FCF_LOGIN_NEEDED);
2745 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2746 break;
2747 }
2748
2749 /*
2750 * Port ID changed or device was marked to be updated;
2751 * Log it out if still logged in and mark it for
2752 * relogin later.
2753 */
2754 fcport->d_id.b24 = new_fcport->d_id.b24;
2755 fcport->flags |= FCF_LOGIN_NEEDED;
2756 if (fcport->loop_id != FC_NO_LOOP_ID &&
2757 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2758 fcport->port_type != FCT_INITIATOR &&
2759 fcport->port_type != FCT_BROADCAST) {
e315cd28 2760 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
1c7c6357
AV
2761 fcport->d_id.b.domain, fcport->d_id.b.area,
2762 fcport->d_id.b.al_pa);
1da177e4
LT
2763 fcport->loop_id = FC_NO_LOOP_ID;
2764 }
2765
2766 break;
2767 }
2768
2769 if (found)
2770 continue;
1da177e4
LT
2771 /* If device was not in our fcports list, then add it. */
2772 list_add_tail(&new_fcport->list, new_fcports);
2773
2774 /* Allocate a new replacement fcport. */
2775 nxt_d_id.b24 = new_fcport->d_id.b24;
e315cd28 2776 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
1da177e4 2777 if (new_fcport == NULL) {
c9475cb0 2778 kfree(swl);
1da177e4
LT
2779 return (QLA_MEMORY_ALLOC_FAILED);
2780 }
2781 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2782 new_fcport->d_id.b24 = nxt_d_id.b24;
2783 }
2784
c9475cb0
JJ
2785 kfree(swl);
2786 kfree(new_fcport);
1da177e4
LT
2787
2788 if (!list_empty(new_fcports))
e315cd28 2789 vha->device_flags |= DFLG_FABRIC_DEVICES;
1da177e4
LT
2790
2791 return (rval);
2792}
2793
2794/*
2795 * qla2x00_find_new_loop_id
2796 * Scan through our port list and find a new usable loop ID.
2797 *
2798 * Input:
2799 * ha: adapter state pointer.
2800 * dev: port structure pointer.
2801 *
2802 * Returns:
2803 * qla2x00 local function return status code.
2804 *
2805 * Context:
2806 * Kernel context.
2807 */
413975a0 2808static int
e315cd28 2809qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
1da177e4
LT
2810{
2811 int rval;
2812 int found;
2813 fc_port_t *fcport;
2814 uint16_t first_loop_id;
e315cd28
AC
2815 struct qla_hw_data *ha = vha->hw;
2816 struct scsi_qla_host *vp;
1da177e4
LT
2817
2818 rval = QLA_SUCCESS;
2819
2820 /* Save starting loop ID. */
2821 first_loop_id = dev->loop_id;
2822
2823 for (;;) {
2824 /* Skip loop ID if already used by adapter. */
e315cd28 2825 if (dev->loop_id == vha->loop_id)
1da177e4 2826 dev->loop_id++;
1da177e4
LT
2827
2828 /* Skip reserved loop IDs. */
e315cd28 2829 while (qla2x00_is_reserved_id(vha, dev->loop_id))
1da177e4 2830 dev->loop_id++;
1da177e4
LT
2831
2832 /* Reset loop ID if passed the end. */
e315cd28 2833 if (dev->loop_id > ha->max_loop_id) {
1da177e4
LT
2834 /* first loop ID. */
2835 dev->loop_id = ha->min_external_loopid;
2836 }
2837
2838 /* Check for loop ID being already in use. */
2839 found = 0;
2840 fcport = NULL;
e315cd28
AC
2841 list_for_each_entry(vp, &ha->vp_list, list) {
2842 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2843 if (fcport->loop_id == dev->loop_id &&
2844 fcport != dev) {
2845 /* ID possibly in use */
2846 found++;
2847 break;
2848 }
1da177e4 2849 }
e315cd28
AC
2850 if (found)
2851 break;
1da177e4
LT
2852 }
2853
2854 /* If not in use then it is free to use. */
2855 if (!found) {
2856 break;
2857 }
2858
2859 /* ID in use. Try next value. */
2860 dev->loop_id++;
2861
2862 /* If wrap around. No free ID to use. */
2863 if (dev->loop_id == first_loop_id) {
2864 dev->loop_id = FC_NO_LOOP_ID;
2865 rval = QLA_FUNCTION_FAILED;
2866 break;
2867 }
2868 }
2869
2870 return (rval);
2871}
2872
2873/*
2874 * qla2x00_device_resync
2875 * Marks devices in the database that needs resynchronization.
2876 *
2877 * Input:
2878 * ha = adapter block pointer.
2879 *
2880 * Context:
2881 * Kernel context.
2882 */
2883static int
e315cd28 2884qla2x00_device_resync(scsi_qla_host_t *vha)
1da177e4
LT
2885{
2886 int rval;
1da177e4
LT
2887 uint32_t mask;
2888 fc_port_t *fcport;
2889 uint32_t rscn_entry;
2890 uint8_t rscn_out_iter;
2891 uint8_t format;
2892 port_id_t d_id;
2893
2894 rval = QLA_RSCNS_HANDLED;
2895
e315cd28
AC
2896 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2897 vha->flags.rscn_queue_overflow) {
1da177e4 2898
e315cd28 2899 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
1da177e4
LT
2900 format = MSB(MSW(rscn_entry));
2901 d_id.b.domain = LSB(MSW(rscn_entry));
2902 d_id.b.area = MSB(LSW(rscn_entry));
2903 d_id.b.al_pa = LSB(LSW(rscn_entry));
2904
2905 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2906 "[%02x/%02x%02x%02x].\n",
e315cd28 2907 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
1da177e4
LT
2908 d_id.b.area, d_id.b.al_pa));
2909
e315cd28
AC
2910 vha->rscn_out_ptr++;
2911 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2912 vha->rscn_out_ptr = 0;
1da177e4
LT
2913
2914 /* Skip duplicate entries. */
e315cd28
AC
2915 for (rscn_out_iter = vha->rscn_out_ptr;
2916 !vha->flags.rscn_queue_overflow &&
2917 rscn_out_iter != vha->rscn_in_ptr;
1da177e4
LT
2918 rscn_out_iter = (rscn_out_iter ==
2919 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2920
e315cd28 2921 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
1da177e4
LT
2922 break;
2923
2924 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
e315cd28 2925 "entry found at [%d].\n", vha->host_no,
1da177e4
LT
2926 rscn_out_iter));
2927
e315cd28 2928 vha->rscn_out_ptr = rscn_out_iter;
1da177e4
LT
2929 }
2930
2931 /* Queue overflow, set switch default case. */
e315cd28 2932 if (vha->flags.rscn_queue_overflow) {
1da177e4 2933 DEBUG(printk("scsi(%ld): device_resync: rscn "
e315cd28 2934 "overflow.\n", vha->host_no));
1da177e4
LT
2935
2936 format = 3;
e315cd28 2937 vha->flags.rscn_queue_overflow = 0;
1da177e4
LT
2938 }
2939
2940 switch (format) {
2941 case 0:
1da177e4
LT
2942 mask = 0xffffff;
2943 break;
2944 case 1:
2945 mask = 0xffff00;
2946 break;
2947 case 2:
2948 mask = 0xff0000;
2949 break;
2950 default:
2951 mask = 0x0;
2952 d_id.b24 = 0;
e315cd28 2953 vha->rscn_out_ptr = vha->rscn_in_ptr;
1da177e4
LT
2954 break;
2955 }
2956
2957 rval = QLA_SUCCESS;
2958
e315cd28 2959 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1da177e4
LT
2960 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2961 (fcport->d_id.b24 & mask) != d_id.b24 ||
2962 fcport->port_type == FCT_BROADCAST)
2963 continue;
2964
2965 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2966 if (format != 3 ||
2967 fcport->port_type != FCT_INITIATOR) {
e315cd28 2968 qla2x00_mark_device_lost(vha, fcport,
d97994dc 2969 0, 0);
1da177e4
LT
2970 }
2971 }
2972 fcport->flags &= ~FCF_FARP_DONE;
2973 }
2974 }
2975 return (rval);
2976}
2977
2978/*
2979 * qla2x00_fabric_dev_login
2980 * Login fabric target device and update FC port database.
2981 *
2982 * Input:
2983 * ha: adapter state pointer.
2984 * fcport: port structure list pointer.
2985 * next_loopid: contains value of a new loop ID that can be used
2986 * by the next login attempt.
2987 *
2988 * Returns:
2989 * qla2x00 local function return status code.
2990 *
2991 * Context:
2992 * Kernel context.
2993 */
2994static int
e315cd28 2995qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1da177e4
LT
2996 uint16_t *next_loopid)
2997{
2998 int rval;
2999 int retry;
0107109e 3000 uint8_t opts;
e315cd28 3001 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
3002
3003 rval = QLA_SUCCESS;
3004 retry = 0;
3005
e315cd28 3006 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
1da177e4 3007 if (rval == QLA_SUCCESS) {
0107109e
AV
3008 /* Send an ADISC to tape devices.*/
3009 opts = 0;
3010 if (fcport->flags & FCF_TAPE_PRESENT)
3011 opts |= BIT_1;
e315cd28 3012 rval = qla2x00_get_port_database(vha, fcport, opts);
1da177e4 3013 if (rval != QLA_SUCCESS) {
e315cd28 3014 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
1c7c6357
AV
3015 fcport->d_id.b.domain, fcport->d_id.b.area,
3016 fcport->d_id.b.al_pa);
e315cd28 3017 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1da177e4 3018 } else {
e315cd28 3019 qla2x00_update_fcport(vha, fcport);
1da177e4
LT
3020 }
3021 }
3022
3023 return (rval);
3024}
3025
3026/*
3027 * qla2x00_fabric_login
3028 * Issue fabric login command.
3029 *
3030 * Input:
3031 * ha = adapter block pointer.
3032 * device = pointer to FC device type structure.
3033 *
3034 * Returns:
3035 * 0 - Login successfully
3036 * 1 - Login failed
3037 * 2 - Initiator device
3038 * 3 - Fatal error
3039 */
3040int
e315cd28 3041qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
1da177e4
LT
3042 uint16_t *next_loopid)
3043{
3044 int rval;
3045 int retry;
3046 uint16_t tmp_loopid;
3047 uint16_t mb[MAILBOX_REGISTER_COUNT];
e315cd28 3048 struct qla_hw_data *ha = vha->hw;
1da177e4
LT
3049
3050 retry = 0;
3051 tmp_loopid = 0;
3052
3053 for (;;) {
3054 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3055 "for port %02x%02x%02x.\n",
e315cd28 3056 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
1da177e4
LT
3057 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3058
3059 /* Login fcport on switch. */
e315cd28 3060 ha->isp_ops->fabric_login(vha, fcport->loop_id,
1da177e4
LT
3061 fcport->d_id.b.domain, fcport->d_id.b.area,
3062 fcport->d_id.b.al_pa, mb, BIT_0);
3063 if (mb[0] == MBS_PORT_ID_USED) {
3064 /*
3065 * Device has another loop ID. The firmware team
0107109e
AV
3066 * recommends the driver perform an implicit login with
3067 * the specified ID again. The ID we just used is save
3068 * here so we return with an ID that can be tried by
3069 * the next login.
1da177e4
LT
3070 */
3071 retry++;
3072 tmp_loopid = fcport->loop_id;
3073 fcport->loop_id = mb[1];
3074
3075 DEBUG(printk("Fabric Login: port in use - next "
3076 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3077 fcport->loop_id, fcport->d_id.b.domain,
3078 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3079
3080 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3081 /*
3082 * Login succeeded.
3083 */
3084 if (retry) {
3085 /* A retry occurred before. */
3086 *next_loopid = tmp_loopid;
3087 } else {
3088 /*
3089 * No retry occurred before. Just increment the
3090 * ID value for next login.
3091 */
3092 *next_loopid = (fcport->loop_id + 1);
3093 }
3094
3095 if (mb[1] & BIT_0) {
3096 fcport->port_type = FCT_INITIATOR;
3097 } else {
3098 fcport->port_type = FCT_TARGET;
3099 if (mb[1] & BIT_1) {
3100 fcport->flags |= FCF_TAPE_PRESENT;
3101 }
3102 }
3103
ad3e0eda
AV
3104 if (mb[10] & BIT_0)
3105 fcport->supported_classes |= FC_COS_CLASS2;
3106 if (mb[10] & BIT_1)
3107 fcport->supported_classes |= FC_COS_CLASS3;
3108
1da177e4
LT
3109 rval = QLA_SUCCESS;
3110 break;
3111 } else if (mb[0] == MBS_LOOP_ID_USED) {
3112 /*
3113 * Loop ID already used, try next loop ID.
3114 */
3115 fcport->loop_id++;
e315cd28 3116 rval = qla2x00_find_new_loop_id(vha, fcport);
1da177e4
LT
3117 if (rval != QLA_SUCCESS) {
3118 /* Ran out of loop IDs to use */
3119 break;
3120 }
3121 } else if (mb[0] == MBS_COMMAND_ERROR) {
3122 /*
3123 * Firmware possibly timed out during login. If NO
3124 * retries are left to do then the device is declared
3125 * dead.
3126 */
3127 *next_loopid = fcport->loop_id;
e315cd28 3128 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
1c7c6357
AV
3129 fcport->d_id.b.domain, fcport->d_id.b.area,
3130 fcport->d_id.b.al_pa);
e315cd28 3131 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1da177e4
LT
3132
3133 rval = 1;
3134 break;
3135 } else {
3136 /*
3137 * unrecoverable / not handled error
3138 */
3139 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
fa2a1ce5 3140 "loop_id=%x jiffies=%lx.\n",
e315cd28 3141 __func__, vha->host_no, mb[0],
1da177e4
LT
3142 fcport->d_id.b.domain, fcport->d_id.b.area,
3143 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3144
3145 *next_loopid = fcport->loop_id;
e315cd28 3146 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
1c7c6357
AV
3147 fcport->d_id.b.domain, fcport->d_id.b.area,
3148 fcport->d_id.b.al_pa);
1da177e4 3149 fcport->loop_id = FC_NO_LOOP_ID;
0eedfcf0 3150 fcport->login_retry = 0;
1da177e4
LT
3151
3152 rval = 3;
3153 break;
3154 }
3155 }
3156
3157 return (rval);
3158}
3159
3160/*
3161 * qla2x00_local_device_login
3162 * Issue local device login command.
3163 *
3164 * Input:
3165 * ha = adapter block pointer.
3166 * loop_id = loop id of device to login to.
3167 *
3168 * Returns (Where's the #define!!!!):
3169 * 0 - Login successfully
3170 * 1 - Login failed
3171 * 3 - Fatal error
3172 */
3173int
e315cd28 3174qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
1da177e4
LT
3175{
3176 int rval;
3177 uint16_t mb[MAILBOX_REGISTER_COUNT];
3178
3179 memset(mb, 0, sizeof(mb));
e315cd28 3180 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
1da177e4
LT
3181 if (rval == QLA_SUCCESS) {
3182 /* Interrogate mailbox registers for any errors */
3183 if (mb[0] == MBS_COMMAND_ERROR)
3184 rval = 1;
3185 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3186 /* device not in PCB table */
3187 rval = 3;
3188 }
3189
3190 return (rval);
3191}
3192
3193/*
3194 * qla2x00_loop_resync
3195 * Resync with fibre channel devices.
3196 *
3197 * Input:
3198 * ha = adapter block pointer.
3199 *
3200 * Returns:
3201 * 0 = success
3202 */
3203int
e315cd28 3204qla2x00_loop_resync(scsi_qla_host_t *vha)
1da177e4 3205{
73208dfd 3206 int rval = QLA_SUCCESS;
1da177e4 3207 uint32_t wait_time;
73208dfd
AC
3208 struct qla_hw_data *ha = vha->hw;
3209 struct req_que *req = ha->req_q_map[0];
3210 struct rsp_que *rsp = ha->rsp_q_map[0];
1da177e4 3211
e315cd28
AC
3212 atomic_set(&vha->loop_state, LOOP_UPDATE);
3213 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3214 if (vha->flags.online) {
3215 if (!(rval = qla2x00_fw_ready(vha))) {
1da177e4
LT
3216 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3217 wait_time = 256;
3218 do {
e315cd28 3219 atomic_set(&vha->loop_state, LOOP_UPDATE);
1da177e4 3220
0107109e 3221 /* Issue a marker after FW becomes ready. */
73208dfd
AC
3222 qla2x00_marker(vha, req, rsp, 0, 0,
3223 MK_SYNC_ALL);
e315cd28 3224 vha->marker_needed = 0;
1da177e4
LT
3225
3226 /* Remap devices on Loop. */
e315cd28 3227 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1da177e4 3228
e315cd28 3229 qla2x00_configure_loop(vha);
1da177e4 3230 wait_time--;
e315cd28
AC
3231 } while (!atomic_read(&vha->loop_down_timer) &&
3232 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3233 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3234 &vha->dpc_flags)));
1da177e4 3235 }
1da177e4
LT
3236 }
3237
e315cd28 3238 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
1da177e4 3239 return (QLA_FUNCTION_FAILED);
1da177e4 3240
e315cd28 3241 if (rval)
1da177e4 3242 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
1da177e4
LT
3243
3244 return (rval);
3245}
3246
d97994dc 3247void
e315cd28 3248qla2x00_update_fcports(scsi_qla_host_t *vha)
d97994dc
AV
3249{
3250 fc_port_t *fcport;
3251
3252 /* Go with deferred removal of rport references. */
e315cd28
AC
3253 list_for_each_entry(fcport, &vha->vp_fcports, list)
3254 if (fcport && fcport->drport &&
c9c5ced9 3255 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
d97994dc
AV
3256 qla2x00_rport_del(fcport);
3257}
3258
1da177e4
LT
3259/*
3260* qla2x00_abort_isp
3261* Resets ISP and aborts all outstanding commands.
3262*
3263* Input:
3264* ha = adapter block pointer.
3265*
3266* Returns:
3267* 0 = success
3268*/
3269int
e315cd28 3270qla2x00_abort_isp(scsi_qla_host_t *vha)
1da177e4 3271{
476e8978 3272 int rval;
1da177e4 3273 uint8_t status = 0;
e315cd28
AC
3274 struct qla_hw_data *ha = vha->hw;
3275 struct scsi_qla_host *vp;
73208dfd 3276 struct req_que *req = ha->req_q_map[0];
1da177e4 3277
e315cd28
AC
3278 if (vha->flags.online) {
3279 vha->flags.online = 0;
3280 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
e5f5f6f7 3281 ha->qla_stats.total_isp_aborts++;
1da177e4
LT
3282
3283 qla_printk(KERN_INFO, ha,
3284 "Performing ISP error recovery - ha= %p.\n", ha);
e315cd28
AC
3285 ha->isp_ops->reset_chip(vha);
3286
3287 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3288 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3289 atomic_set(&vha->loop_state, LOOP_DOWN);
3290 qla2x00_mark_all_devices_lost(vha, 0);
3291 list_for_each_entry(vp, &ha->vp_list, list)
3292 qla2x00_mark_all_devices_lost(vp, 0);
1da177e4 3293 } else {
e315cd28
AC
3294 if (!atomic_read(&vha->loop_down_timer))
3295 atomic_set(&vha->loop_down_timer,
1da177e4
LT
3296 LOOP_DOWN_TIME);
3297 }
3298
1da177e4 3299 /* Requeue all commands in outstanding command list. */
e315cd28 3300 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
1da177e4 3301
73208dfd 3302 ha->isp_ops->get_flash_version(vha, req->ring);
30c47662 3303
e315cd28 3304 ha->isp_ops->nvram_config(vha);
1da177e4 3305
e315cd28
AC
3306 if (!qla2x00_restart_isp(vha)) {
3307 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
1da177e4 3308
e315cd28 3309 if (!atomic_read(&vha->loop_down_timer)) {
1da177e4
LT
3310 /*
3311 * Issue marker command only when we are going
3312 * to start the I/O .
3313 */
e315cd28 3314 vha->marker_needed = 1;
1da177e4
LT
3315 }
3316
e315cd28 3317 vha->flags.online = 1;
1da177e4 3318
fd34f556 3319 ha->isp_ops->enable_intrs(ha);
1da177e4 3320
fa2a1ce5 3321 ha->isp_abort_cnt = 0;
e315cd28 3322 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
476e8978 3323
df613b96
AV
3324 if (ha->fce) {
3325 ha->flags.fce_enabled = 1;
3326 memset(ha->fce, 0,
3327 fce_calc_size(ha->fce_bufs));
e315cd28 3328 rval = qla2x00_enable_fce_trace(vha,
df613b96
AV
3329 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3330 &ha->fce_bufs);
3331 if (rval) {
3332 qla_printk(KERN_WARNING, ha,
3333 "Unable to reinitialize FCE "
3334 "(%d).\n", rval);
3335 ha->flags.fce_enabled = 0;
3336 }
3337 }
436a7b11
AV
3338
3339 if (ha->eft) {
3340 memset(ha->eft, 0, EFT_SIZE);
e315cd28 3341 rval = qla2x00_enable_eft_trace(vha,
436a7b11
AV
3342 ha->eft_dma, EFT_NUM_BUFFERS);
3343 if (rval) {
3344 qla_printk(KERN_WARNING, ha,
3345 "Unable to reinitialize EFT "
3346 "(%d).\n", rval);
3347 }
3348 }
1da177e4 3349 } else { /* failed the ISP abort */
e315cd28
AC
3350 vha->flags.online = 1;
3351 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
1da177e4
LT
3352 if (ha->isp_abort_cnt == 0) {
3353 qla_printk(KERN_WARNING, ha,
3354 "ISP error recovery failed - "
3355 "board disabled\n");
fa2a1ce5 3356 /*
1da177e4
LT
3357 * The next call disables the board
3358 * completely.
3359 */
e315cd28
AC
3360 ha->isp_ops->reset_adapter(vha);
3361 vha->flags.online = 0;
1da177e4 3362 clear_bit(ISP_ABORT_RETRY,
e315cd28 3363 &vha->dpc_flags);
1da177e4
LT
3364 status = 0;
3365 } else { /* schedule another ISP abort */
3366 ha->isp_abort_cnt--;
3367 DEBUG(printk("qla%ld: ISP abort - "
0107109e 3368 "retry remaining %d\n",
e315cd28 3369 vha->host_no, ha->isp_abort_cnt));
1da177e4
LT
3370 status = 1;
3371 }
3372 } else {
3373 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3374 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3375 "- retrying (%d) more times\n",
e315cd28
AC
3376 vha->host_no, ha->isp_abort_cnt));
3377 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
1da177e4
LT
3378 status = 1;
3379 }
3380 }
fa2a1ce5 3381
1da177e4
LT
3382 }
3383
e315cd28
AC
3384 if (!status) {
3385 DEBUG(printk(KERN_INFO
3386 "qla2x00_abort_isp(%ld): succeeded.\n",
3387 vha->host_no));
3388 list_for_each_entry(vp, &ha->vp_list, list) {
3389 if (vp->vp_idx)
3390 qla2x00_vp_abort_isp(vp);
3391 }
3392 } else {
1da177e4
LT
3393 qla_printk(KERN_INFO, ha,
3394 "qla2x00_abort_isp: **** FAILED ****\n");
1da177e4
LT
3395 }
3396
3397 return(status);
3398}
3399
3400/*
3401* qla2x00_restart_isp
3402* restarts the ISP after a reset
3403*
3404* Input:
3405* ha = adapter block pointer.
3406*
3407* Returns:
3408* 0 = success
3409*/
3410static int
e315cd28 3411qla2x00_restart_isp(scsi_qla_host_t *vha)
1da177e4
LT
3412{
3413 uint8_t status = 0;
1da177e4 3414 uint32_t wait_time;
e315cd28 3415 struct qla_hw_data *ha = vha->hw;
73208dfd
AC
3416 struct req_que *req = ha->req_q_map[0];
3417 struct rsp_que *rsp = ha->rsp_q_map[0];
1da177e4
LT
3418
3419 /* If firmware needs to be loaded */
e315cd28
AC
3420 if (qla2x00_isp_firmware(vha)) {
3421 vha->flags.online = 0;
3422 status = ha->isp_ops->chip_diag(vha);
3423 if (!status)
3424 status = qla2x00_setup_chip(vha);
1da177e4
LT
3425 }
3426
e315cd28
AC
3427 if (!status && !(status = qla2x00_init_rings(vha))) {
3428 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
73208dfd
AC
3429 /* Initialize the queues in use */
3430 qla25xx_init_queues(ha);
3431
e315cd28
AC
3432 status = qla2x00_fw_ready(vha);
3433 if (!status) {
1da177e4 3434 DEBUG(printk("%s(): Start configure loop, "
744f11fd 3435 "status = %d\n", __func__, status));
0107109e
AV
3436
3437 /* Issue a marker after FW becomes ready. */
73208dfd 3438 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
0107109e 3439
e315cd28 3440 vha->flags.online = 1;
1da177e4
LT
3441 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3442 wait_time = 256;
3443 do {
e315cd28
AC
3444 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3445 qla2x00_configure_loop(vha);
1da177e4 3446 wait_time--;
e315cd28
AC
3447 } while (!atomic_read(&vha->loop_down_timer) &&
3448 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3449 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3450 &vha->dpc_flags)));
1da177e4
LT
3451 }
3452
3453 /* if no cable then assume it's good */
e315cd28 3454 if ((vha->device_flags & DFLG_NO_CABLE))
1da177e4
LT
3455 status = 0;
3456
3457 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3458 __func__,
744f11fd 3459 status));
1da177e4
LT
3460 }
3461 return (status);
3462}
3463
73208dfd
AC
3464static int
3465qla25xx_init_queues(struct qla_hw_data *ha)
3466{
3467 struct rsp_que *rsp = NULL;
3468 struct req_que *req = NULL;
3469 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3470 int ret = -1;
3471 int i;
3472
3473 for (i = 1; i < ha->max_queues; i++) {
3474 rsp = ha->rsp_q_map[i];
3475 if (rsp) {
3476 rsp->options &= ~BIT_0;
3477 ret = qla25xx_init_rsp_que(base_vha, rsp, rsp->options);
3478 if (ret != QLA_SUCCESS)
3479 DEBUG2_17(printk(KERN_WARNING
3480 "%s Rsp que:%d init failed\n", __func__,
3481 rsp->id));
3482 else
3483 DEBUG2_17(printk(KERN_INFO
3484 "%s Rsp que:%d inited\n", __func__,
3485 rsp->id));
3486 }
3487 req = ha->req_q_map[i];
3488 if (req) {
3489 req->options &= ~BIT_0;
3490 ret = qla25xx_init_req_que(base_vha, req, req->options);
3491 if (ret != QLA_SUCCESS)
3492 DEBUG2_17(printk(KERN_WARNING
3493 "%s Req que:%d init failed\n", __func__,
3494 req->id));
3495 else
3496 DEBUG2_17(printk(KERN_WARNING
3497 "%s Rsp que:%d inited\n", __func__,
3498 req->id));
3499 }
3500 }
3501 return ret;
3502}
3503
1da177e4
LT
3504/*
3505* qla2x00_reset_adapter
3506* Reset adapter.
3507*
3508* Input:
3509* ha = adapter block pointer.
3510*/
abbd8870 3511void
e315cd28 3512qla2x00_reset_adapter(scsi_qla_host_t *vha)
1da177e4
LT
3513{
3514 unsigned long flags = 0;
e315cd28 3515 struct qla_hw_data *ha = vha->hw;
3d71644c 3516 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1da177e4 3517
e315cd28 3518 vha->flags.online = 0;
fd34f556 3519 ha->isp_ops->disable_intrs(ha);
1da177e4 3520
1da177e4
LT
3521 spin_lock_irqsave(&ha->hardware_lock, flags);
3522 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3523 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3524 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3525 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3526 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3527}
0107109e
AV
3528
3529void
e315cd28 3530qla24xx_reset_adapter(scsi_qla_host_t *vha)
0107109e
AV
3531{
3532 unsigned long flags = 0;
e315cd28 3533 struct qla_hw_data *ha = vha->hw;
0107109e
AV
3534 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3535
e315cd28 3536 vha->flags.online = 0;
fd34f556 3537 ha->isp_ops->disable_intrs(ha);
0107109e
AV
3538
3539 spin_lock_irqsave(&ha->hardware_lock, flags);
3540 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3541 RD_REG_DWORD(&reg->hccr);
3542 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3543 RD_REG_DWORD(&reg->hccr);
3544 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3545}
3546
4e08df3f
DM
3547/* On sparc systems, obtain port and node WWN from firmware
3548 * properties.
3549 */
e315cd28
AC
3550static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3551 struct nvram_24xx *nv)
4e08df3f
DM
3552{
3553#ifdef CONFIG_SPARC
e315cd28 3554 struct qla_hw_data *ha = vha->hw;
4e08df3f 3555 struct pci_dev *pdev = ha->pdev;
15576bc8
DM
3556 struct device_node *dp = pci_device_to_OF_node(pdev);
3557 const u8 *val;
4e08df3f
DM
3558 int len;
3559
3560 val = of_get_property(dp, "port-wwn", &len);
3561 if (val && len >= WWN_SIZE)
3562 memcpy(nv->port_name, val, WWN_SIZE);
3563
3564 val = of_get_property(dp, "node-wwn", &len);
3565 if (val && len >= WWN_SIZE)
3566 memcpy(nv->node_name, val, WWN_SIZE);
3567#endif
3568}
3569
0107109e 3570int
e315cd28 3571qla24xx_nvram_config(scsi_qla_host_t *vha)
0107109e 3572{
4e08df3f 3573 int rval;
0107109e
AV
3574 struct init_cb_24xx *icb;
3575 struct nvram_24xx *nv;
3576 uint32_t *dptr;
3577 uint8_t *dptr1, *dptr2;
3578 uint32_t chksum;
3579 uint16_t cnt;
e315cd28 3580 struct qla_hw_data *ha = vha->hw;
0107109e 3581
4e08df3f 3582 rval = QLA_SUCCESS;
0107109e 3583 icb = (struct init_cb_24xx *)ha->init_cb;
281afe19 3584 nv = ha->nvram;
0107109e
AV
3585
3586 /* Determine NVRAM starting address. */
3587 ha->nvram_size = sizeof(struct nvram_24xx);
3588 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6f641790
AV
3589 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3590 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3591 if (PCI_FUNC(ha->pdev->devfn)) {
0107109e 3592 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
6f641790
AV
3593 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3594 }
0107109e 3595
281afe19
SJ
3596 /* Get VPD data into cache */
3597 ha->vpd = ha->nvram + VPD_OFFSET;
e315cd28 3598 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
281afe19
SJ
3599 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3600
3601 /* Get NVRAM data into cache and calculate checksum. */
0107109e 3602 dptr = (uint32_t *)nv;
e315cd28 3603 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
0107109e
AV
3604 ha->nvram_size);
3605 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3606 chksum += le32_to_cpu(*dptr++);
3607
3608 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
281afe19 3609 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
0107109e
AV
3610
3611 /* Bad NVRAM data, set defaults parameters. */
3612 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3613 || nv->id[3] != ' ' ||
3614 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3615 /* Reset NVRAM data. */
3616 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3617 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3618 le16_to_cpu(nv->nvram_version));
4e08df3f
DM
3619 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3620 "invalid -- WWPN) defaults.\n");
3621
3622 /*
3623 * Set default initialization control block.
3624 */
3625 memset(nv, 0, ha->nvram_size);
3626 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3627 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3628 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3629 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3630 nv->exchange_count = __constant_cpu_to_le16(0);
3631 nv->hard_address = __constant_cpu_to_le16(124);
3632 nv->port_name[0] = 0x21;
3633 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3634 nv->port_name[2] = 0x00;
3635 nv->port_name[3] = 0xe0;
3636 nv->port_name[4] = 0x8b;
3637 nv->port_name[5] = 0x1c;
3638 nv->port_name[6] = 0x55;
3639 nv->port_name[7] = 0x86;
3640 nv->node_name[0] = 0x20;
3641 nv->node_name[1] = 0x00;
3642 nv->node_name[2] = 0x00;
3643 nv->node_name[3] = 0xe0;
3644 nv->node_name[4] = 0x8b;
3645 nv->node_name[5] = 0x1c;
3646 nv->node_name[6] = 0x55;
3647 nv->node_name[7] = 0x86;
e315cd28 3648 qla24xx_nvram_wwn_from_ofw(vha, nv);
4e08df3f
DM
3649 nv->login_retry_count = __constant_cpu_to_le16(8);
3650 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3651 nv->login_timeout = __constant_cpu_to_le16(0);
3652 nv->firmware_options_1 =
3653 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3654 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3655 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3656 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3657 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3658 nv->efi_parameters = __constant_cpu_to_le32(0);
3659 nv->reset_delay = 5;
3660 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3661 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3662 nv->link_down_timeout = __constant_cpu_to_le16(30);
3663
3664 rval = 1;
0107109e
AV
3665 }
3666
3667 /* Reset Initialization control block */
e315cd28 3668 memset(icb, 0, ha->init_cb_size);
0107109e
AV
3669
3670 /* Copy 1st segment. */
3671 dptr1 = (uint8_t *)icb;
3672 dptr2 = (uint8_t *)&nv->version;
3673 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3674 while (cnt--)
3675 *dptr1++ = *dptr2++;
3676
3677 icb->login_retry_count = nv->login_retry_count;
3ea66e28 3678 icb->link_down_on_nos = nv->link_down_on_nos;
0107109e
AV
3679
3680 /* Copy 2nd segment. */
3681 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3682 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3683 cnt = (uint8_t *)&icb->reserved_3 -
3684 (uint8_t *)&icb->interrupt_delay_timer;
3685 while (cnt--)
3686 *dptr1++ = *dptr2++;
3687
3688 /*
3689 * Setup driver NVRAM options.
3690 */
e315cd28 3691 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
9bb9fcf2 3692 "QLA2462");
0107109e 3693
5341e868
AV
3694 /* Use alternate WWN? */
3695 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3696 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3697 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3698 }
3699
0107109e 3700 /* Prepare nodename */
fd0e7e4d 3701 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
0107109e
AV
3702 /*
3703 * Firmware will apply the following mask if the nodename was
3704 * not provided.
3705 */
3706 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3707 icb->node_name[0] &= 0xF0;
3708 }
3709
3710 /* Set host adapter parameters. */
3711 ha->flags.disable_risc_code_load = 0;
0c8c39af
AV
3712 ha->flags.enable_lip_reset = 0;
3713 ha->flags.enable_lip_full_login =
3714 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3715 ha->flags.enable_target_reset =
3716 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
0107109e 3717 ha->flags.enable_led_scheme = 0;
d4c760c2 3718 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
0107109e 3719
fd0e7e4d
AV
3720 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3721 (BIT_6 | BIT_5 | BIT_4)) >> 4;
0107109e
AV
3722
3723 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3724 sizeof(ha->fw_seriallink_options24));
3725
3726 /* save HBA serial number */
3727 ha->serial0 = icb->port_name[5];
3728 ha->serial1 = icb->port_name[6];
3729 ha->serial2 = icb->port_name[7];
e315cd28
AC
3730 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3731 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
0107109e 3732
bc8fb3cb
AV
3733 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3734
0107109e
AV
3735 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3736
3737 /* Set minimum login_timeout to 4 seconds. */
3738 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3739 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3740 if (le16_to_cpu(nv->login_timeout) < 4)
3741 nv->login_timeout = __constant_cpu_to_le16(4);
3742 ha->login_timeout = le16_to_cpu(nv->login_timeout);
c6852c4c 3743 icb->login_timeout = nv->login_timeout;
0107109e 3744
00a537b8
AV
3745 /* Set minimum RATOV to 100 tenths of a second. */
3746 ha->r_a_tov = 100;
0107109e
AV
3747
3748 ha->loop_reset_delay = nv->reset_delay;
3749
3750 /* Link Down Timeout = 0:
3751 *
3752 * When Port Down timer expires we will start returning
3753 * I/O's to OS with "DID_NO_CONNECT".
3754 *
3755 * Link Down Timeout != 0:
3756 *
3757 * The driver waits for the link to come up after link down
3758 * before returning I/Os to OS with "DID_NO_CONNECT".
3759 */
3760 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3761 ha->loop_down_abort_time =
3762 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3763 } else {
3764 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3765 ha->loop_down_abort_time =
3766 (LOOP_DOWN_TIME - ha->link_down_timeout);
3767 }
3768
3769 /* Need enough time to try and get the port back. */
3770 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3771 if (qlport_down_retry)
3772 ha->port_down_retry_count = qlport_down_retry;
3773
3774 /* Set login_retry_count */
3775 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3776 if (ha->port_down_retry_count ==
3777 le16_to_cpu(nv->port_down_retry_count) &&
3778 ha->port_down_retry_count > 3)
3779 ha->login_retry_count = ha->port_down_retry_count;
3780 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3781 ha->login_retry_count = ha->port_down_retry_count;
3782 if (ql2xloginretrycount)
3783 ha->login_retry_count = ql2xloginretrycount;
3784
4fdfefe5 3785 /* Enable ZIO. */
e315cd28 3786 if (!vha->flags.init_done) {
4fdfefe5
AV
3787 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3788 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3789 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3790 le16_to_cpu(icb->interrupt_delay_timer): 2;
3791 }
3792 icb->firmware_options_2 &= __constant_cpu_to_le32(
3793 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
e315cd28 3794 vha->flags.process_response_queue = 0;
4fdfefe5 3795 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4a59f71d
AV
3796 ha->zio_mode = QLA_ZIO_MODE_6;
3797
4fdfefe5 3798 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
e315cd28 3799 "(%d us).\n", vha->host_no, ha->zio_mode,
4fdfefe5
AV
3800 ha->zio_timer * 100));
3801 qla_printk(KERN_INFO, ha,
3802 "ZIO mode %d enabled; timer delay (%d us).\n",
3803 ha->zio_mode, ha->zio_timer * 100);
3804
3805 icb->firmware_options_2 |= cpu_to_le32(
3806 (uint32_t)ha->zio_mode);
3807 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
e315cd28 3808 vha->flags.process_response_queue = 1;
4fdfefe5
AV
3809 }
3810
4e08df3f
DM
3811 if (rval) {
3812 DEBUG2_3(printk(KERN_WARNING
e315cd28 3813 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4e08df3f
DM
3814 }
3815 return (rval);
0107109e
AV
3816}
3817
413975a0 3818static int
e315cd28 3819qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
d1c61909 3820{
73208dfd 3821 int rval = QLA_SUCCESS;
d1c61909
AV
3822 int segments, fragment;
3823 uint32_t faddr;
3824 uint32_t *dcode, dlen;
3825 uint32_t risc_addr;
3826 uint32_t risc_size;
3827 uint32_t i;
e315cd28 3828 struct qla_hw_data *ha = vha->hw;
73208dfd 3829 struct req_que *req = ha->req_q_map[0];
d1c61909
AV
3830 rval = QLA_SUCCESS;
3831
3832 segments = FA_RISC_CODE_SEGMENTS;
c00d8994 3833 faddr = ha->flt_region_fw;
73208dfd 3834 dcode = (uint32_t *)req->ring;
d1c61909
AV
3835 *srisc_addr = 0;
3836
3837 /* Validate firmware image by checking version. */
e315cd28 3838 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
d1c61909
AV
3839 for (i = 0; i < 4; i++)
3840 dcode[i] = be32_to_cpu(dcode[i]);
3841 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3842 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3843 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3844 dcode[3] == 0)) {
3845 qla_printk(KERN_WARNING, ha,
3846 "Unable to verify integrity of flash firmware image!\n");
3847 qla_printk(KERN_WARNING, ha,
3848 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3849 dcode[1], dcode[2], dcode[3]);
3850
3851 return QLA_FUNCTION_FAILED;
3852 }
3853
3854 while (segments && rval == QLA_SUCCESS) {
3855 /* Read segment's load information. */
e315cd28 3856 qla24xx_read_flash_data(vha, dcode, faddr, 4);
d1c61909
AV
3857
3858 risc_addr = be32_to_cpu(dcode[2]);
3859 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3860 risc_size = be32_to_cpu(dcode[3]);
3861
3862 fragment = 0;
3863 while (risc_size > 0 && rval == QLA_SUCCESS) {
3864 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3865 if (dlen > risc_size)
3866 dlen = risc_size;
3867
3868 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3869 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
e315cd28 3870 vha->host_no, risc_addr, dlen, faddr));
d1c61909 3871
e315cd28 3872 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
d1c61909
AV
3873 for (i = 0; i < dlen; i++)
3874 dcode[i] = swab32(dcode[i]);
3875
73208dfd 3876 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
d1c61909
AV
3877 dlen);
3878 if (rval) {
3879 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
e315cd28 3880 "segment %d of firmware\n", vha->host_no,
d1c61909
AV
3881 fragment));
3882 qla_printk(KERN_WARNING, ha,
3883 "[ERROR] Failed to load segment %d of "
3884 "firmware\n", fragment);
3885 break;
3886 }
3887
3888 faddr += dlen;
3889 risc_addr += dlen;
3890 risc_size -= dlen;
3891 fragment++;
3892 }
3893
3894 /* Next segment. */
3895 segments--;
3896 }
3897
3898 return rval;
3899}
3900
d1c61909
AV
3901#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3902
0107109e 3903int
e315cd28 3904qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
5433383e
AV
3905{
3906 int rval;
3907 int i, fragment;
3908 uint16_t *wcode, *fwcode;
3909 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3910 struct fw_blob *blob;
e315cd28 3911 struct qla_hw_data *ha = vha->hw;
73208dfd 3912 struct req_que *req = ha->req_q_map[0];
5433383e
AV
3913
3914 /* Load firmware blob. */
e315cd28 3915 blob = qla2x00_request_firmware(vha);
5433383e
AV
3916 if (!blob) {
3917 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
d1c61909
AV
3918 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3919 "from: " QLA_FW_URL ".\n");
5433383e
AV
3920 return QLA_FUNCTION_FAILED;
3921 }
3922
3923 rval = QLA_SUCCESS;
3924
73208dfd 3925 wcode = (uint16_t *)req->ring;
5433383e
AV
3926 *srisc_addr = 0;
3927 fwcode = (uint16_t *)blob->fw->data;
3928 fwclen = 0;
3929
3930 /* Validate firmware image by checking version. */
3931 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3932 qla_printk(KERN_WARNING, ha,
3933 "Unable to verify integrity of firmware image (%Zd)!\n",
3934 blob->fw->size);
3935 goto fail_fw_integrity;
3936 }
3937 for (i = 0; i < 4; i++)
3938 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3939 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3940 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3941 wcode[2] == 0 && wcode[3] == 0)) {
3942 qla_printk(KERN_WARNING, ha,
3943 "Unable to verify integrity of firmware image!\n");
3944 qla_printk(KERN_WARNING, ha,
3945 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3946 wcode[1], wcode[2], wcode[3]);
3947 goto fail_fw_integrity;
3948 }
3949
3950 seg = blob->segs;
3951 while (*seg && rval == QLA_SUCCESS) {
3952 risc_addr = *seg;
3953 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3954 risc_size = be16_to_cpu(fwcode[3]);
3955
3956 /* Validate firmware image size. */
3957 fwclen += risc_size * sizeof(uint16_t);
3958 if (blob->fw->size < fwclen) {
3959 qla_printk(KERN_WARNING, ha,
3960 "Unable to verify integrity of firmware image "
3961 "(%Zd)!\n", blob->fw->size);
3962 goto fail_fw_integrity;
3963 }
3964
3965 fragment = 0;
3966 while (risc_size > 0 && rval == QLA_SUCCESS) {
3967 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3968 if (wlen > risc_size)
3969 wlen = risc_size;
3970
3971 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
e315cd28 3972 "addr %x, number of words 0x%x.\n", vha->host_no,
5433383e
AV
3973 risc_addr, wlen));
3974
3975 for (i = 0; i < wlen; i++)
3976 wcode[i] = swab16(fwcode[i]);
3977
73208dfd 3978 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
5433383e
AV
3979 wlen);
3980 if (rval) {
3981 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
e315cd28 3982 "segment %d of firmware\n", vha->host_no,
5433383e
AV
3983 fragment));
3984 qla_printk(KERN_WARNING, ha,
3985 "[ERROR] Failed to load segment %d of "
3986 "firmware\n", fragment);
3987 break;
3988 }
3989
3990 fwcode += wlen;
3991 risc_addr += wlen;
3992 risc_size -= wlen;
3993 fragment++;
3994 }
3995
3996 /* Next segment. */
3997 seg++;
3998 }
3999 return rval;
4000
4001fail_fw_integrity:
4002 return QLA_FUNCTION_FAILED;
4003}
4004
4005int
e315cd28 4006qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
0107109e
AV
4007{
4008 int rval;
4009 int segments, fragment;
4010 uint32_t *dcode, dlen;
4011 uint32_t risc_addr;
4012 uint32_t risc_size;
4013 uint32_t i;
5433383e 4014 struct fw_blob *blob;
0107109e 4015 uint32_t *fwcode, fwclen;
e315cd28 4016 struct qla_hw_data *ha = vha->hw;
73208dfd 4017 struct req_que *req = ha->req_q_map[0];
0107109e 4018
5433383e 4019 /* Load firmware blob. */
e315cd28 4020 blob = qla2x00_request_firmware(vha);
5433383e
AV
4021 if (!blob) {
4022 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
d1c61909
AV
4023 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4024 "from: " QLA_FW_URL ".\n");
4025
4026 /* Try to load RISC code from flash. */
4027 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
4028 "outdated) firmware from flash.\n");
e315cd28 4029 return qla24xx_load_risc_flash(vha, srisc_addr);
0107109e
AV
4030 }
4031
4032 rval = QLA_SUCCESS;
4033
4034 segments = FA_RISC_CODE_SEGMENTS;
73208dfd 4035 dcode = (uint32_t *)req->ring;
0107109e 4036 *srisc_addr = 0;
5433383e 4037 fwcode = (uint32_t *)blob->fw->data;
0107109e
AV
4038 fwclen = 0;
4039
4040 /* Validate firmware image by checking version. */
5433383e 4041 if (blob->fw->size < 8 * sizeof(uint32_t)) {
0107109e 4042 qla_printk(KERN_WARNING, ha,
5433383e
AV
4043 "Unable to verify integrity of firmware image (%Zd)!\n",
4044 blob->fw->size);
0107109e
AV
4045 goto fail_fw_integrity;
4046 }
4047 for (i = 0; i < 4; i++)
4048 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4049 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4050 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4051 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4052 dcode[3] == 0)) {
4053 qla_printk(KERN_WARNING, ha,
5433383e 4054 "Unable to verify integrity of firmware image!\n");
0107109e
AV
4055 qla_printk(KERN_WARNING, ha,
4056 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4057 dcode[1], dcode[2], dcode[3]);
4058 goto fail_fw_integrity;
4059 }
4060
4061 while (segments && rval == QLA_SUCCESS) {
4062 risc_addr = be32_to_cpu(fwcode[2]);
4063 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4064 risc_size = be32_to_cpu(fwcode[3]);
4065
4066 /* Validate firmware image size. */
4067 fwclen += risc_size * sizeof(uint32_t);
5433383e 4068 if (blob->fw->size < fwclen) {
0107109e 4069 qla_printk(KERN_WARNING, ha,
5433383e
AV
4070 "Unable to verify integrity of firmware image "
4071 "(%Zd)!\n", blob->fw->size);
4072
0107109e
AV
4073 goto fail_fw_integrity;
4074 }
4075
4076 fragment = 0;
4077 while (risc_size > 0 && rval == QLA_SUCCESS) {
4078 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4079 if (dlen > risc_size)
4080 dlen = risc_size;
4081
4082 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
e315cd28 4083 "addr %x, number of dwords 0x%x.\n", vha->host_no,
0107109e
AV
4084 risc_addr, dlen));
4085
4086 for (i = 0; i < dlen; i++)
4087 dcode[i] = swab32(fwcode[i]);
4088
73208dfd 4089 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
590f98e5 4090 dlen);
0107109e
AV
4091 if (rval) {
4092 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
e315cd28 4093 "segment %d of firmware\n", vha->host_no,
0107109e
AV
4094 fragment));
4095 qla_printk(KERN_WARNING, ha,
4096 "[ERROR] Failed to load segment %d of "
4097 "firmware\n", fragment);
4098 break;
4099 }
4100
4101 fwcode += dlen;
4102 risc_addr += dlen;
4103 risc_size -= dlen;
4104 fragment++;
4105 }
4106
4107 /* Next segment. */
4108 segments--;
4109 }
0107109e
AV
4110 return rval;
4111
4112fail_fw_integrity:
0107109e 4113 return QLA_FUNCTION_FAILED;
0107109e 4114}
18c6c127
AV
4115
4116void
e315cd28 4117qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
18c6c127
AV
4118{
4119 int ret, retries;
e315cd28 4120 struct qla_hw_data *ha = vha->hw;
18c6c127 4121
e428924c 4122 if (!IS_FWI2_CAPABLE(ha))
18c6c127 4123 return;
75edf81d
AV
4124 if (!ha->fw_major_version)
4125 return;
18c6c127 4126
e315cd28 4127 ret = qla2x00_stop_firmware(vha);
7c7f1f29
AV
4128 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4129 retries ; retries--) {
e315cd28
AC
4130 ha->isp_ops->reset_chip(vha);
4131 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
18c6c127 4132 continue;
e315cd28 4133 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
18c6c127
AV
4134 continue;
4135 qla_printk(KERN_INFO, ha,
4136 "Attempting retry of stop-firmware command...\n");
e315cd28 4137 ret = qla2x00_stop_firmware(vha);
18c6c127
AV
4138 }
4139}
2c3dfe3f
SJ
4140
4141int
e315cd28 4142qla24xx_configure_vhba(scsi_qla_host_t *vha)
2c3dfe3f
SJ
4143{
4144 int rval = QLA_SUCCESS;
4145 uint16_t mb[MAILBOX_REGISTER_COUNT];
e315cd28
AC
4146 struct qla_hw_data *ha = vha->hw;
4147 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
73208dfd
AC
4148 struct req_que *req = ha->req_q_map[0];
4149 struct rsp_que *rsp = ha->rsp_q_map[0];
2c3dfe3f 4150
e315cd28 4151 if (!vha->vp_idx)
2c3dfe3f
SJ
4152 return -EINVAL;
4153
e315cd28 4154 rval = qla2x00_fw_ready(base_vha);
2c3dfe3f 4155 if (rval == QLA_SUCCESS) {
e315cd28 4156 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
73208dfd 4157 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
2c3dfe3f
SJ
4158 }
4159
e315cd28 4160 vha->flags.management_server_logged_in = 0;
2c3dfe3f
SJ
4161
4162 /* Login to SNS first */
e315cd28 4163 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
2c3dfe3f
SJ
4164 if (mb[0] != MBS_COMMAND_COMPLETE) {
4165 DEBUG15(qla_printk(KERN_INFO, ha,
4166 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4167 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4168 mb[0], mb[1], mb[2], mb[6], mb[7]));
4169 return (QLA_FUNCTION_FAILED);
4170 }
4171
e315cd28
AC
4172 atomic_set(&vha->loop_down_timer, 0);
4173 atomic_set(&vha->loop_state, LOOP_UP);
4174 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4175 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4176 rval = qla2x00_loop_resync(base_vha);
2c3dfe3f
SJ
4177
4178 return rval;
4179}
4d4df193
HK
4180
4181/* 84XX Support **************************************************************/
4182
4183static LIST_HEAD(qla_cs84xx_list);
4184static DEFINE_MUTEX(qla_cs84xx_mutex);
4185
4186static struct qla_chip_state_84xx *
e315cd28 4187qla84xx_get_chip(struct scsi_qla_host *vha)
4d4df193
HK
4188{
4189 struct qla_chip_state_84xx *cs84xx;
e315cd28 4190 struct qla_hw_data *ha = vha->hw;
4d4df193
HK
4191
4192 mutex_lock(&qla_cs84xx_mutex);
4193
4194 /* Find any shared 84xx chip. */
4195 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4196 if (cs84xx->bus == ha->pdev->bus) {
4197 kref_get(&cs84xx->kref);
4198 goto done;
4199 }
4200 }
4201
4202 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4203 if (!cs84xx)
4204 goto done;
4205
4206 kref_init(&cs84xx->kref);
4207 spin_lock_init(&cs84xx->access_lock);
4208 mutex_init(&cs84xx->fw_update_mutex);
4209 cs84xx->bus = ha->pdev->bus;
4210
4211 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4212done:
4213 mutex_unlock(&qla_cs84xx_mutex);
4214 return cs84xx;
4215}
4216
4217static void
4218__qla84xx_chip_release(struct kref *kref)
4219{
4220 struct qla_chip_state_84xx *cs84xx =
4221 container_of(kref, struct qla_chip_state_84xx, kref);
4222
4223 mutex_lock(&qla_cs84xx_mutex);
4224 list_del(&cs84xx->list);
4225 mutex_unlock(&qla_cs84xx_mutex);
4226 kfree(cs84xx);
4227}
4228
4229void
e315cd28 4230qla84xx_put_chip(struct scsi_qla_host *vha)
4d4df193 4231{
e315cd28 4232 struct qla_hw_data *ha = vha->hw;
4d4df193
HK
4233 if (ha->cs84xx)
4234 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4235}
4236
4237static int
e315cd28 4238qla84xx_init_chip(scsi_qla_host_t *vha)
4d4df193
HK
4239{
4240 int rval;
4241 uint16_t status[2];
e315cd28 4242 struct qla_hw_data *ha = vha->hw;
4d4df193
HK
4243
4244 mutex_lock(&ha->cs84xx->fw_update_mutex);
4245
e315cd28 4246 rval = qla84xx_verify_chip(vha, status);
4d4df193
HK
4247
4248 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4249
4250 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4251 QLA_SUCCESS;
4252}