blob: da2cce011520a6179d695b16f02a986836efb910 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2005 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/delay.h>
Andrew Vasquez01071092005-07-06 10:31:37 -070010#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12#include "qla_devtbl.h"
13
David Miller4e08df32007-04-16 12:37:43 -070014#ifdef CONFIG_SPARC
15#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070016#endif
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/* XXX(hch): this is ugly, but we don't want to pull in exioctl.h */
19#ifndef EXT_IS_LUN_BIT_SET
20#define EXT_IS_LUN_BIT_SET(P,L) \
21 (((P)->mask[L/8] & (0x80 >> (L%8)))?1:0)
22#define EXT_SET_LUN_BIT(P,L) \
23 ((P)->mask[L/8] |= (0x80 >> (L%8)))
24#endif
25
26/*
27* QLogic ISP2x00 Hardware Support Function Prototypes.
28*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static void qla2x00_resize_request_q(scsi_qla_host_t *);
31static int qla2x00_setup_chip(scsi_qla_host_t *);
32static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
33static int qla2x00_init_rings(scsi_qla_host_t *);
34static int qla2x00_fw_ready(scsi_qla_host_t *);
35static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036static int qla2x00_configure_loop(scsi_qla_host_t *);
37static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070038static int qla2x00_configure_fabric(scsi_qla_host_t *);
39static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
40static int qla2x00_device_resync(scsi_qla_host_t *);
41static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
42 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070043
44static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070045
Adrian Bunk413975a2006-06-30 02:33:06 -070046static int qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev);
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048/****************************************************************************/
49/* QLogic ISP2x00 Hardware Support Functions. */
50/****************************************************************************/
51
52/*
53* qla2x00_initialize_adapter
54* Initialize board.
55*
56* Input:
57* ha = adapter block pointer.
58*
59* Returns:
60* 0 = success
61*/
62int
63qla2x00_initialize_adapter(scsi_qla_host_t *ha)
64{
65 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -070066
67 /* Clear adapter flags. */
68 ha->flags.online = 0;
69 ha->flags.reset_active = 0;
70 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
71 atomic_set(&ha->loop_state, LOOP_DOWN);
Andrew Vasquez26032212007-01-29 10:22:23 -080072 ha->device_flags = DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 ha->dpc_flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 ha->flags.management_server_logged_in = 0;
75 ha->marker_needed = 0;
76 ha->mbx_flags = 0;
77 ha->isp_abort_cnt = 0;
78 ha->beacon_blink_led = 0;
Andrew Vasquezcca53352005-08-26 19:08:30 -070079 set_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070080
Andrew Vasquez01071092005-07-06 10:31:37 -070081 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Andrew Vasquezfd34f552007-07-19 15:06:00 -070082 rval = ha->isp_ops->pci_config(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -080084 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 ha->host_no));
86 return (rval);
87 }
88
Andrew Vasquezfd34f552007-07-19 15:06:00 -070089 ha->isp_ops->reset_chip(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Andrew Vasquezfd34f552007-07-19 15:06:00 -070091 ha->isp_ops->get_flash_version(ha, ha->request_ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -080092
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez01071092005-07-06 10:31:37 -070094
Andrew Vasquezfd34f552007-07-19 15:06:00 -070095 ha->isp_ops->nvram_config(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
Andrew Vasquezd4c760c2006-06-23 16:10:39 -070097 if (ha->flags.disable_serdes) {
98 /* Mask HBA via NVRAM settings? */
99 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
100 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
101 ha->port_name[0], ha->port_name[1],
102 ha->port_name[2], ha->port_name[3],
103 ha->port_name[4], ha->port_name[5],
104 ha->port_name[6], ha->port_name[7]);
105 return QLA_FUNCTION_FAILED;
106 }
107
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
109
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800110 if (qla2x00_isp_firmware(ha) != QLA_SUCCESS) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700111 rval = ha->isp_ops->chip_diag(ha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800112 if (rval)
113 return (rval);
114 rval = qla2x00_setup_chip(ha);
115 if (rval)
116 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117 }
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800118 rval = qla2x00_init_rings(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119
120 return (rval);
121}
122
123/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700124 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 * @ha: HA context
126 *
127 * Returns 0 on success.
128 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700129int
130qla2100_pci_config(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700132 uint16_t w;
Adam Kropelin27b2f672005-09-16 19:28:20 -0700133 uint32_t d;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700134 unsigned long flags;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700135 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700138 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700141 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
143
144 /* Reset expansion ROM address decode enable */
Adam Kropelin27b2f672005-09-16 19:28:20 -0700145 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
146 d &= ~PCI_ROM_ADDRESS_ENABLE;
147 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700149 /* Get PCI bus information. */
150 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700151 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700152 spin_unlock_irqrestore(&ha->hardware_lock, flags);
153
154 return QLA_SUCCESS;
155}
156
157/**
158 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
159 * @ha: HA context
160 *
161 * Returns 0 on success.
162 */
163int
164qla2300_pci_config(scsi_qla_host_t *ha)
165{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700166 uint16_t w;
Adam Kropelin27b2f672005-09-16 19:28:20 -0700167 uint32_t d;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700168 unsigned long flags = 0;
169 uint32_t cnt;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700170 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700171
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700172 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700173 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700174
175 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700176 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700177
178 if (IS_QLA2322(ha) || IS_QLA6322(ha))
179 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700180 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700181
182 /*
183 * If this is a 2300 card and not 2312, reset the
184 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
185 * the 2310 also reports itself as a 2300 so we need to get the
186 * fb revision level -- a 6 indicates it really is a 2300 and
187 * not a 2310.
188 */
189 if (IS_QLA2300(ha)) {
190 spin_lock_irqsave(&ha->hardware_lock, flags);
191
192 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700193 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700194 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700195 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700196 break;
197
198 udelay(10);
199 }
200
201 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700202 WRT_REG_WORD(&reg->ctrl_status, 0x20);
203 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700204
205 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700206 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700207
208 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700209 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700210
211 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700212 WRT_REG_WORD(&reg->ctrl_status, 0x0);
213 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700214
215 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700216 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700217 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700218 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700219 break;
220
221 udelay(10);
222 }
223
224 spin_unlock_irqrestore(&ha->hardware_lock, flags);
225 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700226
227 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
228
229 /* Reset expansion ROM address decode enable */
Adam Kropelin27b2f672005-09-16 19:28:20 -0700230 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
231 d &= ~PCI_ROM_ADDRESS_ENABLE;
232 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700233
234 /* Get PCI bus information. */
235 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700236 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
238
239 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240}
241
242/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700243 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
244 * @ha: HA context
245 *
246 * Returns 0 on success.
247 */
248int
249qla24xx_pci_config(scsi_qla_host_t *ha)
250{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700251 uint16_t w;
Adam Kropelin27b2f672005-09-16 19:28:20 -0700252 uint32_t d;
Andrew Vasquez01071092005-07-06 10:31:37 -0700253 unsigned long flags = 0;
254 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez01071092005-07-06 10:31:37 -0700255
256 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700257 pci_try_set_mwi(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700258
259 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700260 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez01071092005-07-06 10:31:37 -0700261 w &= ~PCI_COMMAND_INTX_DISABLE;
262 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
263
264 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
265
266 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700267 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
268 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700269
270 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700271 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
272 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700273
274 /* Reset expansion ROM address decode enable */
Adam Kropelin27b2f672005-09-16 19:28:20 -0700275 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
276 d &= ~PCI_ROM_ADDRESS_ENABLE;
277 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
Andrew Vasquez01071092005-07-06 10:31:37 -0700278
Auke Kok44c10132007-06-08 15:46:36 -0700279 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800280
Andrew Vasquez01071092005-07-06 10:31:37 -0700281 /* Get PCI bus information. */
282 spin_lock_irqsave(&ha->hardware_lock, flags);
283 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
284 spin_unlock_irqrestore(&ha->hardware_lock, flags);
285
286 return QLA_SUCCESS;
287}
288
289/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700290 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
291 * @ha: HA context
292 *
293 * Returns 0 on success.
294 */
295int
296qla25xx_pci_config(scsi_qla_host_t *ha)
297{
298 uint16_t w;
299 uint32_t d;
300
301 pci_set_master(ha->pdev);
302 pci_try_set_mwi(ha->pdev);
303
304 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
305 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
306 w &= ~PCI_COMMAND_INTX_DISABLE;
307 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
308
309 /* PCIe -- adjust Maximum Read Request Size (2048). */
310 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
311 pcie_set_readrq(ha->pdev, 2048);
312
313 /* Reset expansion ROM address decode enable */
314 pci_read_config_dword(ha->pdev, PCI_ROM_ADDRESS, &d);
315 d &= ~PCI_ROM_ADDRESS_ENABLE;
316 pci_write_config_dword(ha->pdev, PCI_ROM_ADDRESS, d);
317
318 ha->chip_revision = ha->pdev->revision;
319
320 return QLA_SUCCESS;
321}
322
323/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 * qla2x00_isp_firmware() - Choose firmware image.
325 * @ha: HA context
326 *
327 * Returns 0 on success.
328 */
329static int
330qla2x00_isp_firmware(scsi_qla_host_t *ha)
331{
332 int rval;
333
334 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700335 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 if (ha->flags.disable_risc_code_load) {
338 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
339 ha->host_no));
340 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
341
342 /* Verify checksum of loaded RISC code. */
Andrew Vasquez441d1072006-05-17 15:09:34 -0700343 rval = qla2x00_verify_checksum(ha, ha->fw_srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 }
345
346 if (rval) {
347 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
348 ha->host_no));
349 }
350
351 return (rval);
352}
353
354/**
355 * qla2x00_reset_chip() - Reset ISP chip.
356 * @ha: HA context
357 *
358 * Returns 0 on success.
359 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700360void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700361qla2x00_reset_chip(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362{
363 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700364 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 uint16_t cmd;
367
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700368 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700369
370 spin_lock_irqsave(&ha->hardware_lock, flags);
371
372 /* Turn off master enable */
373 cmd = 0;
374 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
375 cmd &= ~PCI_COMMAND_MASTER;
376 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
377
378 if (!IS_QLA2100(ha)) {
379 /* Pause RISC. */
380 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
381 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
382 for (cnt = 0; cnt < 30000; cnt++) {
383 if ((RD_REG_WORD(&reg->hccr) &
384 HCCR_RISC_PAUSE) != 0)
385 break;
386 udelay(100);
387 }
388 } else {
389 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
390 udelay(10);
391 }
392
393 /* Select FPM registers. */
394 WRT_REG_WORD(&reg->ctrl_status, 0x20);
395 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
396
397 /* FPM Soft Reset. */
398 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
399 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
400
401 /* Toggle Fpm Reset. */
402 if (!IS_QLA2200(ha)) {
403 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
404 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
405 }
406
407 /* Select frame buffer registers. */
408 WRT_REG_WORD(&reg->ctrl_status, 0x10);
409 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
410
411 /* Reset frame buffer FIFOs. */
412 if (IS_QLA2200(ha)) {
413 WRT_FB_CMD_REG(ha, reg, 0xa000);
414 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
415 } else {
416 WRT_FB_CMD_REG(ha, reg, 0x00fc);
417
418 /* Read back fb_cmd until zero or 3 seconds max */
419 for (cnt = 0; cnt < 3000; cnt++) {
420 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
421 break;
422 udelay(100);
423 }
424 }
425
426 /* Select RISC module registers. */
427 WRT_REG_WORD(&reg->ctrl_status, 0);
428 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
429
430 /* Reset RISC processor. */
431 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
432 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
433
434 /* Release RISC processor. */
435 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
436 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
437 }
438
439 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
440 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
441
442 /* Reset ISP chip. */
443 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
444
445 /* Wait for RISC to recover from reset. */
446 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
447 /*
448 * It is necessary to for a delay here since the card doesn't
449 * respond to PCI reads during a reset. On some architectures
450 * this will result in an MCA.
451 */
452 udelay(20);
453 for (cnt = 30000; cnt; cnt--) {
454 if ((RD_REG_WORD(&reg->ctrl_status) &
455 CSR_ISP_SOFT_RESET) == 0)
456 break;
457 udelay(100);
458 }
459 } else
460 udelay(10);
461
462 /* Reset RISC processor. */
463 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
464
465 WRT_REG_WORD(&reg->semaphore, 0);
466
467 /* Release RISC processor. */
468 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
469 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
470
471 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
472 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700473 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700475
476 udelay(100);
477 }
478 } else
479 udelay(100);
480
481 /* Turn on master enable */
482 cmd |= PCI_COMMAND_MASTER;
483 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
484
485 /* Disable RISC pause on FPM parity error. */
486 if (!IS_QLA2100(ha)) {
487 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
488 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
489 }
490
491 spin_unlock_irqrestore(&ha->hardware_lock, flags);
492}
493
494/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700495 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez01071092005-07-06 10:31:37 -0700496 * @ha: HA context
497 *
498 * Returns 0 on success.
499 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700500static inline void
501qla24xx_reset_risc(scsi_qla_host_t *ha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700502{
503 unsigned long flags = 0;
504 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
505 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800506 uint16_t wd;
Andrew Vasquez01071092005-07-06 10:31:37 -0700507
Andrew Vasquez01071092005-07-06 10:31:37 -0700508 spin_lock_irqsave(&ha->hardware_lock, flags);
509
510 /* Reset RISC. */
511 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
512 for (cnt = 0; cnt < 30000; cnt++) {
513 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
514 break;
515
516 udelay(10);
517 }
518
519 WRT_REG_DWORD(&reg->ctrl_status,
520 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800521 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700522
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800523 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700524 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700525 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
526 for (cnt = 10000 ; cnt && d2; cnt--) {
527 udelay(5);
528 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
529 barrier();
530 }
531
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800532 /* Wait for soft-reset to complete. */
Andrew Vasquez01071092005-07-06 10:31:37 -0700533 d2 = RD_REG_DWORD(&reg->ctrl_status);
534 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
535 udelay(5);
536 d2 = RD_REG_DWORD(&reg->ctrl_status);
537 barrier();
538 }
539
540 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
541 RD_REG_DWORD(&reg->hccr);
542
543 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
544 RD_REG_DWORD(&reg->hccr);
545
546 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
547 RD_REG_DWORD(&reg->hccr);
548
549 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
550 for (cnt = 6000000 ; cnt && d2; cnt--) {
551 udelay(5);
552 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
553 barrier();
554 }
555
556 spin_unlock_irqrestore(&ha->hardware_lock, flags);
557}
558
559/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700560 * qla24xx_reset_chip() - Reset ISP24xx chip.
561 * @ha: HA context
562 *
563 * Returns 0 on success.
564 */
565void
566qla24xx_reset_chip(scsi_qla_host_t *ha)
567{
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700568 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700569
570 /* Perform RISC reset. */
571 qla24xx_reset_risc(ha);
572}
573
574/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 * qla2x00_chip_diag() - Test chip for proper operation.
576 * @ha: HA context
577 *
578 * Returns 0 on success.
579 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700580int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581qla2x00_chip_diag(scsi_qla_host_t *ha)
582{
583 int rval;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700584 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 unsigned long flags = 0;
586 uint16_t data;
587 uint32_t cnt;
588 uint16_t mb[5];
589
590 /* Assume a failed state */
591 rval = QLA_FUNCTION_FAILED;
592
593 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
594 ha->host_no, (u_long)&reg->flash_address));
595
596 spin_lock_irqsave(&ha->hardware_lock, flags);
597
598 /* Reset ISP chip. */
599 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
600
601 /*
602 * We need to have a delay here since the card will not respond while
603 * in reset causing an MCA on some architectures.
604 */
605 udelay(20);
606 data = qla2x00_debounce_register(&reg->ctrl_status);
607 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
608 udelay(5);
609 data = RD_REG_WORD(&reg->ctrl_status);
610 barrier();
611 }
612
613 if (!cnt)
614 goto chip_diag_failed;
615
616 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
617 ha->host_no));
618
619 /* Reset RISC processor. */
620 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
621 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
622
623 /* Workaround for QLA2312 PCI parity error */
624 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
625 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
626 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
627 udelay(5);
628 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700629 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 }
631 } else
632 udelay(10);
633
634 if (!cnt)
635 goto chip_diag_failed;
636
637 /* Check product ID of chip */
638 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
639
640 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
641 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
642 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
643 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
644 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
645 mb[3] != PROD_ID_3) {
646 qla_printk(KERN_WARNING, ha,
647 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
648
649 goto chip_diag_failed;
650 }
651 ha->product_id[0] = mb[1];
652 ha->product_id[1] = mb[2];
653 ha->product_id[2] = mb[3];
654 ha->product_id[3] = mb[4];
655
656 /* Adjust fw RISC transfer size */
657 if (ha->request_q_length > 1024)
658 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
659 else
660 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
661 ha->request_q_length;
662
663 if (IS_QLA2200(ha) &&
664 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
665 /* Limit firmware transfer size with a 2200A */
666 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
667 ha->host_no));
668
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800669 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 ha->fw_transfer_size = 128;
671 }
672
673 /* Wrap Incoming Mailboxes Test. */
674 spin_unlock_irqrestore(&ha->hardware_lock, flags);
675
676 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", ha->host_no));
677 rval = qla2x00_mbx_reg_test(ha);
678 if (rval) {
679 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
680 ha->host_no));
681 qla_printk(KERN_WARNING, ha,
682 "Failed mailbox send register test\n");
683 }
684 else {
685 /* Flag a successful rval */
686 rval = QLA_SUCCESS;
687 }
688 spin_lock_irqsave(&ha->hardware_lock, flags);
689
690chip_diag_failed:
691 if (rval)
692 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
693 "****\n", ha->host_no));
694
695 spin_unlock_irqrestore(&ha->hardware_lock, flags);
696
697 return (rval);
698}
699
700/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700701 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
702 * @ha: HA context
703 *
704 * Returns 0 on success.
705 */
706int
707qla24xx_chip_diag(scsi_qla_host_t *ha)
708{
709 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -0700710
Andrew Vasquez88c26662005-07-08 17:59:26 -0700711 /* Perform RISC reset. */
712 qla24xx_reset_risc(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700713
714 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
715
716 rval = qla2x00_mbx_reg_test(ha);
717 if (rval) {
718 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
719 ha->host_no));
720 qla_printk(KERN_WARNING, ha,
721 "Failed mailbox send register test\n");
722 } else {
723 /* Flag a successful rval */
724 rval = QLA_SUCCESS;
725 }
726
727 return rval;
728}
729
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700730void
Andrew Vasquez01071092005-07-06 10:31:37 -0700731qla2x00_alloc_fw_dump(scsi_qla_host_t *ha)
732{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700733 int rval;
734 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
735 eft_size;
736 dma_addr_t eft_dma;
737 void *eft;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700738
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700739 if (ha->fw_dump) {
740 qla_printk(KERN_WARNING, ha,
741 "Firmware dump previously allocated.\n");
742 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700743 }
744
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700745 ha->fw_dumped = 0;
746 fixed_size = mem_size = eft_size = 0;
747 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
748 fixed_size = sizeof(struct qla2100_fw_dump);
749 } else if (IS_QLA23XX(ha)) {
750 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
751 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
752 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700753 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700754 fixed_size = IS_QLA25XX(ha) ?
755 offsetof(struct qla25xx_fw_dump, ext_mem):
756 offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700757 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
758 sizeof(uint32_t);
759
760 /* Allocate memory for Extended Trace Buffer. */
761 eft = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &eft_dma,
762 GFP_KERNEL);
763 if (!eft) {
764 qla_printk(KERN_WARNING, ha, "Unable to allocate "
765 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
766 goto cont_alloc;
767 }
768
Andrew Vasquez00b6bd22008-01-17 09:02:16 -0800769 rval = qla2x00_enable_eft_trace(ha, eft_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700770 if (rval) {
771 qla_printk(KERN_WARNING, ha, "Unable to initialize "
772 "EFT (%d).\n", rval);
773 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
774 eft_dma);
775 goto cont_alloc;
776 }
777
778 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
779 EFT_SIZE / 1024);
780
781 eft_size = EFT_SIZE;
782 memset(eft, 0, eft_size);
783 ha->eft_dma = eft_dma;
784 ha->eft = eft;
785 }
786cont_alloc:
787 req_q_size = ha->request_q_length * sizeof(request_t);
788 rsp_q_size = ha->response_q_length * sizeof(response_t);
789
790 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
791 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
792 eft_size;
793
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700794 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700795 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -0700796 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700797 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700798
799 if (ha->eft) {
800 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
801 ha->eft_dma);
802 ha->eft = NULL;
803 ha->eft_dma = 0;
804 }
805 return;
806 }
807
808 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
809 dump_size / 1024);
810
811 ha->fw_dump_len = dump_size;
812 ha->fw_dump->signature[0] = 'Q';
813 ha->fw_dump->signature[1] = 'L';
814 ha->fw_dump->signature[2] = 'G';
815 ha->fw_dump->signature[3] = 'C';
816 ha->fw_dump->version = __constant_htonl(1);
817
818 ha->fw_dump->fixed_size = htonl(fixed_size);
819 ha->fw_dump->mem_size = htonl(mem_size);
820 ha->fw_dump->req_q_size = htonl(req_q_size);
821 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
822
823 ha->fw_dump->eft_size = htonl(eft_size);
824 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
825 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
826
827 ha->fw_dump->header_size =
828 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -0700829}
830
831/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700832 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
833 * @ha: HA context
834 *
835 * Returns 0 on success.
836 */
837static void
838qla2x00_resize_request_q(scsi_qla_host_t *ha)
839{
840 int rval;
841 uint16_t fw_iocb_cnt = 0;
842 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
843 dma_addr_t request_dma;
844 request_t *request_ring;
845
846 /* Valid only on recent ISPs. */
847 if (IS_QLA2100(ha) || IS_QLA2200(ha))
848 return;
849
850 /* Retrieve IOCB counts available to the firmware. */
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700851 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt,
852 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 if (rval)
854 return;
855 /* No point in continuing if current settings are sufficient. */
856 if (fw_iocb_cnt < 1024)
857 return;
858 if (ha->request_q_length >= request_q_length)
859 return;
860
861 /* Attempt to claim larger area for request queue. */
862 request_ring = dma_alloc_coherent(&ha->pdev->dev,
863 (request_q_length + 1) * sizeof(request_t), &request_dma,
864 GFP_KERNEL);
865 if (request_ring == NULL)
866 return;
867
868 /* Resize successful, report extensions. */
869 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
870 (ha->fw_memory_size + 1) / 1024);
871 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
872 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
873
874 /* Clear old allocations. */
875 dma_free_coherent(&ha->pdev->dev,
876 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
877 ha->request_dma);
878
879 /* Begin using larger queue. */
880 ha->request_q_length = request_q_length;
881 ha->request_ring = request_ring;
882 ha->request_dma = request_dma;
883}
884
885/**
886 * qla2x00_setup_chip() - Load and start RISC firmware.
887 * @ha: HA context
888 *
889 * Returns 0 on success.
890 */
891static int
892qla2x00_setup_chip(scsi_qla_host_t *ha)
893{
Andrew Vasquez01071092005-07-06 10:31:37 -0700894 int rval;
895 uint32_t srisc_address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
897 /* Load firmware sequences */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700898 rval = ha->isp_ops->load_risc(ha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -0700899 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
901 "code.\n", ha->host_no));
902
Andrew Vasquez01071092005-07-06 10:31:37 -0700903 rval = qla2x00_verify_checksum(ha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904 if (rval == QLA_SUCCESS) {
905 /* Start firmware execution. */
906 DEBUG(printk("scsi(%ld): Checksum OK, start "
907 "firmware.\n", ha->host_no));
908
Andrew Vasquez01071092005-07-06 10:31:37 -0700909 rval = qla2x00_execute_fw(ha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700910 /* Retrieve firmware information. */
911 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
912 qla2x00_get_fw_version(ha,
913 &ha->fw_major_version,
914 &ha->fw_minor_version,
915 &ha->fw_subminor_version,
916 &ha->fw_attributes, &ha->fw_memory_size);
917 qla2x00_resize_request_q(ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700918 ha->flags.npiv_supported = 0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700919 if ((IS_QLA24XX(ha) || IS_QLA25XX(ha)) &&
920 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700921 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700922 if ((!ha->max_npiv_vports) ||
923 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800924 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700925 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800926 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700927 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700928
929 if (ql2xallocfwdump)
930 qla2x00_alloc_fw_dump(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
932 } else {
933 DEBUG2(printk(KERN_INFO
934 "scsi(%ld): ISP Firmware failed checksum.\n",
935 ha->host_no));
936 }
937 }
938
939 if (rval) {
940 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
941 ha->host_no));
942 }
943
944 return (rval);
945}
946
947/**
948 * qla2x00_init_response_q_entries() - Initializes response queue entries.
949 * @ha: HA context
950 *
951 * Beginning of request ring has initialization control block already built
952 * by nvram config routine.
953 *
954 * Returns 0 on success.
955 */
956static void
957qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
958{
959 uint16_t cnt;
960 response_t *pkt;
961
962 pkt = ha->response_ring_ptr;
963 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
964 pkt->signature = RESPONSE_PROCESSED;
965 pkt++;
966 }
967
968}
969
970/**
971 * qla2x00_update_fw_options() - Read and process firmware options.
972 * @ha: HA context
973 *
974 * Returns 0 on success.
975 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700976void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977qla2x00_update_fw_options(scsi_qla_host_t *ha)
978{
979 uint16_t swing, emphasis, tx_sens, rx_sens;
980
981 memset(ha->fw_options, 0, sizeof(ha->fw_options));
982 qla2x00_get_fw_options(ha, ha->fw_options);
983
984 if (IS_QLA2100(ha) || IS_QLA2200(ha))
985 return;
986
987 /* Serial Link options. */
988 DEBUG3(printk("scsi(%ld): Serial link options:\n",
989 ha->host_no));
990 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
991 sizeof(ha->fw_seriallink_options)));
992
993 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
994 if (ha->fw_seriallink_options[3] & BIT_2) {
995 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
996
997 /* 1G settings */
998 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
999 emphasis = (ha->fw_seriallink_options[2] &
1000 (BIT_4 | BIT_3)) >> 3;
1001 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001002 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003 rx_sens = (ha->fw_seriallink_options[0] &
1004 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1005 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1006 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1007 if (rx_sens == 0x0)
1008 rx_sens = 0x3;
1009 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1010 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1011 ha->fw_options[10] |= BIT_5 |
1012 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1013 (tx_sens & (BIT_1 | BIT_0));
1014
1015 /* 2G settings */
1016 swing = (ha->fw_seriallink_options[2] &
1017 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1018 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1019 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001020 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001021 rx_sens = (ha->fw_seriallink_options[1] &
1022 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1023 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1024 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1025 if (rx_sens == 0x0)
1026 rx_sens = 0x3;
1027 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1028 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1029 ha->fw_options[11] |= BIT_5 |
1030 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1031 (tx_sens & (BIT_1 | BIT_0));
1032 }
1033
1034 /* FCP2 options. */
1035 /* Return command IOCBs without waiting for an ABTS to complete. */
1036 ha->fw_options[3] |= BIT_13;
1037
1038 /* LED scheme. */
1039 if (ha->flags.enable_led_scheme)
1040 ha->fw_options[2] |= BIT_12;
1041
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001042 /* Detect ISP6312. */
1043 if (IS_QLA6312(ha))
1044 ha->fw_options[2] |= BIT_13;
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 /* Update firmware options. */
1047 qla2x00_set_fw_options(ha, ha->fw_options);
1048}
1049
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001050void
Andrew Vasquez01071092005-07-06 10:31:37 -07001051qla24xx_update_fw_options(scsi_qla_host_t *ha)
1052{
1053 int rval;
1054
1055 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001056 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez01071092005-07-06 10:31:37 -07001057 return;
1058
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001059 rval = qla2x00_set_serdes_params(ha,
1060 le16_to_cpu(ha->fw_seriallink_options24[1]),
1061 le16_to_cpu(ha->fw_seriallink_options24[2]),
1062 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez01071092005-07-06 10:31:37 -07001063 if (rval != QLA_SUCCESS) {
1064 qla_printk(KERN_WARNING, ha,
1065 "Unable to update Serial Link options (%x).\n", rval);
1066 }
1067}
1068
1069void
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001070qla2x00_config_rings(struct scsi_qla_host *ha)
1071{
Andrew Vasquez3d716442005-07-06 10:30:26 -07001072 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001073
1074 /* Setup ring parameters in initialization control block. */
1075 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1076 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1077 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1078 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1079 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1080 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1081 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1082 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1083
1084 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1085 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1086 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1087 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1088 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1089}
1090
Andrew Vasquez01071092005-07-06 10:31:37 -07001091void
1092qla24xx_config_rings(struct scsi_qla_host *ha)
1093{
1094 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1095 struct init_cb_24xx *icb;
1096
1097 /* Setup ring parameters in initialization control block. */
1098 icb = (struct init_cb_24xx *)ha->init_cb;
1099 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1100 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1101 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1102 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1103 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1104 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1105 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1106 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1107
1108 WRT_REG_DWORD(&reg->req_q_in, 0);
1109 WRT_REG_DWORD(&reg->req_q_out, 0);
1110 WRT_REG_DWORD(&reg->rsp_q_in, 0);
1111 WRT_REG_DWORD(&reg->rsp_q_out, 0);
1112 RD_REG_DWORD(&reg->rsp_q_out);
1113}
1114
Linus Torvalds1da177e2005-04-16 15:20:36 -07001115/**
1116 * qla2x00_init_rings() - Initializes firmware.
1117 * @ha: HA context
1118 *
1119 * Beginning of request ring has initialization control block already built
1120 * by nvram config routine.
1121 *
1122 * Returns 0 on success.
1123 */
1124static int
1125qla2x00_init_rings(scsi_qla_host_t *ha)
1126{
1127 int rval;
1128 unsigned long flags = 0;
1129 int cnt;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001130 struct mid_init_cb_24xx *mid_init_cb =
1131 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
1133 spin_lock_irqsave(&ha->hardware_lock, flags);
1134
1135 /* Clear outstanding commands array. */
1136 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1137 ha->outstanding_cmds[cnt] = NULL;
1138
1139 ha->current_outstanding_cmd = 0;
1140
1141 /* Clear RSCN queue. */
1142 ha->rscn_in_ptr = 0;
1143 ha->rscn_out_ptr = 0;
1144
1145 /* Initialize firmware. */
1146 ha->request_ring_ptr = ha->request_ring;
1147 ha->req_ring_index = 0;
1148 ha->req_q_cnt = ha->request_q_length;
1149 ha->response_ring_ptr = ha->response_ring;
1150 ha->rsp_ring_index = 0;
1151
Linus Torvalds1da177e2005-04-16 15:20:36 -07001152 /* Initialize response queue entries */
1153 qla2x00_init_response_q_entries(ha);
1154
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001155 ha->isp_ops->config_rings(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001156
1157 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1158
1159 /* Update any ISP specific firmware options before initialization. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001160 ha->isp_ops->update_fw_options(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001161
1162 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001163
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001164 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1165 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001166
Andrew Vasquez01071092005-07-06 10:31:37 -07001167 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 if (rval) {
1169 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1170 ha->host_no));
1171 } else {
1172 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1173 ha->host_no));
1174 }
1175
1176 return (rval);
1177}
1178
1179/**
1180 * qla2x00_fw_ready() - Waits for firmware ready.
1181 * @ha: HA context
1182 *
1183 * Returns 0 on success.
1184 */
1185static int
1186qla2x00_fw_ready(scsi_qla_host_t *ha)
1187{
1188 int rval;
1189 unsigned long wtime, mtime;
1190 uint16_t min_wait; /* Minimum wait time if loop is down */
1191 uint16_t wait_time; /* Wait time if loop is coming ready */
1192 uint16_t fw_state;
1193
1194 rval = QLA_SUCCESS;
1195
1196 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001197 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001198
1199 /*
1200 * Firmware should take at most one RATOV to login, plus 5 seconds for
1201 * our own processing.
1202 */
1203 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1204 wait_time = min_wait;
1205 }
1206
1207 /* Min wait time if loop down */
1208 mtime = jiffies + (min_wait * HZ);
1209
1210 /* wait time before firmware ready */
1211 wtime = jiffies + (wait_time * HZ);
1212
1213 /* Wait for ISP to finish LIP */
1214 if (!ha->flags.init_done)
1215 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1216
1217 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1218 ha->host_no));
1219
1220 do {
1221 rval = qla2x00_get_firmware_state(ha, &fw_state);
1222 if (rval == QLA_SUCCESS) {
1223 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1224 ha->device_flags &= ~DFLG_NO_CABLE;
1225 }
1226 if (fw_state == FSTATE_READY) {
1227 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1228 ha->host_no));
1229
1230 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1231 &ha->login_timeout, &ha->r_a_tov);
1232
1233 rval = QLA_SUCCESS;
1234 break;
1235 }
1236
1237 rval = QLA_FUNCTION_FAILED;
1238
1239 if (atomic_read(&ha->loop_down_timer) &&
Andrew Vasquez7d7abc72006-06-23 16:11:17 -07001240 fw_state != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001242 * other than Wait for Login.
1243 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001244 if (time_after_eq(jiffies, mtime)) {
1245 qla_printk(KERN_INFO, ha,
1246 "Cable is unplugged...\n");
1247
1248 ha->device_flags |= DFLG_NO_CABLE;
1249 break;
1250 }
1251 }
1252 } else {
1253 /* Mailbox cmd failed. Timeout on min_wait. */
1254 if (time_after_eq(jiffies, mtime))
1255 break;
1256 }
1257
1258 if (time_after_eq(jiffies, wtime))
1259 break;
1260
1261 /* Delay for a while */
1262 msleep(500);
1263
1264 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1265 ha->host_no, fw_state, jiffies));
1266 } while (1);
1267
1268 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1269 ha->host_no, fw_state, jiffies));
1270
1271 if (rval) {
1272 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1273 ha->host_no));
1274 }
1275
1276 return (rval);
1277}
1278
1279/*
1280* qla2x00_configure_hba
1281* Setup adapter context.
1282*
1283* Input:
1284* ha = adapter state pointer.
1285*
1286* Returns:
1287* 0 = success
1288*
1289* Context:
1290* Kernel context.
1291*/
1292static int
1293qla2x00_configure_hba(scsi_qla_host_t *ha)
1294{
1295 int rval;
1296 uint16_t loop_id;
1297 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001298 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 uint8_t al_pa;
1300 uint8_t area;
1301 uint8_t domain;
1302 char connect_type[22];
1303
1304 /* Get host addresses. */
1305 rval = qla2x00_get_adapter_id(ha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001306 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 if (rval != QLA_SUCCESS) {
Andrew Vasquez23443b12005-12-06 10:57:06 -08001308 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001309 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1310 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1311 __func__, ha->host_no));
1312 } else {
1313 qla_printk(KERN_WARNING, ha,
1314 "ERROR -- Unable to get host loop ID.\n");
1315 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1316 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 return (rval);
1318 }
1319
1320 if (topo == 4) {
1321 qla_printk(KERN_INFO, ha,
1322 "Cannot get topology - retrying.\n");
1323 return (QLA_FUNCTION_FAILED);
1324 }
1325
1326 ha->loop_id = loop_id;
1327
1328 /* initialize */
1329 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1330 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001331 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 switch (topo) {
1334 case 0:
1335 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1336 ha->host_no));
1337 ha->current_topology = ISP_CFG_NL;
1338 strcpy(connect_type, "(Loop)");
1339 break;
1340
1341 case 1:
1342 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1343 ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001344 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 ha->current_topology = ISP_CFG_FL;
1346 strcpy(connect_type, "(FL_Port)");
1347 break;
1348
1349 case 2:
1350 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1351 ha->host_no));
1352 ha->operating_mode = P2P;
1353 ha->current_topology = ISP_CFG_N;
1354 strcpy(connect_type, "(N_Port-to-N_Port)");
1355 break;
1356
1357 case 3:
1358 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1359 ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001360 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001361 ha->operating_mode = P2P;
1362 ha->current_topology = ISP_CFG_F;
1363 strcpy(connect_type, "(F_Port)");
1364 break;
1365
1366 default:
1367 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1368 "Using NL.\n",
1369 ha->host_no, topo));
1370 ha->current_topology = ISP_CFG_NL;
1371 strcpy(connect_type, "(Loop)");
1372 break;
1373 }
1374
1375 /* Save Host port and loop ID. */
1376 /* byte order - Big Endian */
1377 ha->d_id.b.domain = domain;
1378 ha->d_id.b.area = area;
1379 ha->d_id.b.al_pa = al_pa;
1380
1381 if (!ha->flags.init_done)
1382 qla_printk(KERN_INFO, ha,
1383 "Topology - %s, Host Loop address 0x%x\n",
1384 connect_type, ha->loop_id);
1385
1386 if (rval) {
1387 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1388 } else {
1389 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1390 }
1391
1392 return(rval);
1393}
1394
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001395static inline void
1396qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1397{
1398 char *st, *en;
1399 uint16_t index;
1400
1401 if (memcmp(model, BINZERO, len) != 0) {
1402 strncpy(ha->model_number, model, len);
1403 st = en = ha->model_number;
1404 en += len - 1;
1405 while (en > st) {
1406 if (*en != 0x20 && *en != 0x00)
1407 break;
1408 *en-- = '\0';
1409 }
1410
1411 index = (ha->pdev->subsystem_device & 0xff);
1412 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1413 index < QLA_MODEL_NAMES)
1414 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1415 } else {
1416 index = (ha->pdev->subsystem_device & 0xff);
1417 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1418 index < QLA_MODEL_NAMES) {
1419 strcpy(ha->model_number,
1420 qla2x00_model_name[index * 2]);
1421 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1422 } else {
1423 strcpy(ha->model_number, def);
1424 }
1425 }
1426}
1427
David Miller4e08df32007-04-16 12:37:43 -07001428/* On sparc systems, obtain port and node WWN from firmware
1429 * properties.
1430 */
1431static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1432{
1433#ifdef CONFIG_SPARC
1434 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001435 struct device_node *dp = pci_device_to_OF_node(pdev);
1436 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001437 int len;
1438
1439 val = of_get_property(dp, "port-wwn", &len);
1440 if (val && len >= WWN_SIZE)
1441 memcpy(nv->port_name, val, WWN_SIZE);
1442
1443 val = of_get_property(dp, "node-wwn", &len);
1444 if (val && len >= WWN_SIZE)
1445 memcpy(nv->node_name, val, WWN_SIZE);
1446#endif
1447}
1448
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449/*
1450* NVRAM configuration for ISP 2xxx
1451*
1452* Input:
1453* ha = adapter block pointer.
1454*
1455* Output:
1456* initialization control block in response_ring
1457* host adapters parameters in host adapter block
1458*
1459* Returns:
1460* 0 = success.
1461*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001462int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001463qla2x00_nvram_config(scsi_qla_host_t *ha)
1464{
David Miller4e08df32007-04-16 12:37:43 -07001465 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07001466 uint8_t chksum = 0;
1467 uint16_t cnt;
1468 uint8_t *dptr1, *dptr2;
1469 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001470 nvram_t *nv = ha->nvram;
1471 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001472 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473
David Miller4e08df32007-04-16 12:37:43 -07001474 rval = QLA_SUCCESS;
1475
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001477 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 ha->nvram_base = 0;
1479 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1480 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1481 ha->nvram_base = 0x80;
1482
1483 /* Get NVRAM data and calculate checksum. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001484 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07001485 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1486 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487
1488 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001489 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490
1491 /* Bad NVRAM data, set defaults parameters. */
1492 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1493 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1494 /* Reset NVRAM data. */
1495 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1496 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1497 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001498 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1499 "invalid -- WWPN) defaults.\n");
1500
1501 /*
1502 * Set default initialization control block.
1503 */
1504 memset(nv, 0, ha->nvram_size);
1505 nv->parameter_block_version = ICB_VERSION;
1506
1507 if (IS_QLA23XX(ha)) {
1508 nv->firmware_options[0] = BIT_2 | BIT_1;
1509 nv->firmware_options[1] = BIT_7 | BIT_5;
1510 nv->add_firmware_options[0] = BIT_5;
1511 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1512 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1513 nv->special_options[1] = BIT_7;
1514 } else if (IS_QLA2200(ha)) {
1515 nv->firmware_options[0] = BIT_2 | BIT_1;
1516 nv->firmware_options[1] = BIT_7 | BIT_5;
1517 nv->add_firmware_options[0] = BIT_5;
1518 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1519 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1520 } else if (IS_QLA2100(ha)) {
1521 nv->firmware_options[0] = BIT_3 | BIT_1;
1522 nv->firmware_options[1] = BIT_5;
1523 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1524 }
1525
1526 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1527 nv->execution_throttle = __constant_cpu_to_le16(16);
1528 nv->retry_count = 8;
1529 nv->retry_delay = 1;
1530
1531 nv->port_name[0] = 33;
1532 nv->port_name[3] = 224;
1533 nv->port_name[4] = 139;
1534
1535 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1536
1537 nv->login_timeout = 4;
1538
1539 /*
1540 * Set default host adapter parameters
1541 */
1542 nv->host_p[1] = BIT_2;
1543 nv->reset_delay = 5;
1544 nv->port_down_retry_count = 8;
1545 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1546 nv->link_down_timeout = 60;
1547
1548 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 }
1550
1551#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1552 /*
1553 * The SN2 does not provide BIOS emulation which means you can't change
1554 * potentially bogus BIOS settings. Force the use of default settings
1555 * for link rate and frame size. Hope that the rest of the settings
1556 * are valid.
1557 */
1558 if (ia64_platform_is("sn2")) {
1559 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1560 if (IS_QLA23XX(ha))
1561 nv->special_options[1] = BIT_7;
1562 }
1563#endif
1564
1565 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07001566 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 /*
1569 * Setup driver NVRAM options.
1570 */
1571 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1572 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1573 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1574 nv->firmware_options[1] &= ~BIT_4;
1575
1576 if (IS_QLA23XX(ha)) {
1577 nv->firmware_options[0] |= BIT_2;
1578 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez01071092005-07-06 10:31:37 -07001579 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001580
1581 if (IS_QLA2300(ha)) {
1582 if (ha->fb_rev == FPM_2310) {
1583 strcpy(ha->model_number, "QLA2310");
1584 } else {
1585 strcpy(ha->model_number, "QLA2300");
1586 }
1587 } else {
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001588 qla2x00_set_model_info(ha, nv->model_number,
1589 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 }
1591 } else if (IS_QLA2200(ha)) {
1592 nv->firmware_options[0] |= BIT_2;
1593 /*
1594 * 'Point-to-point preferred, else loop' is not a safe
1595 * connection mode setting.
1596 */
1597 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1598 (BIT_5 | BIT_4)) {
1599 /* Force 'loop preferred, else point-to-point'. */
1600 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1601 nv->add_firmware_options[0] |= BIT_5;
1602 }
1603 strcpy(ha->model_number, "QLA22xx");
1604 } else /*if (IS_QLA2100(ha))*/ {
1605 strcpy(ha->model_number, "QLA2100");
1606 }
1607
1608 /*
1609 * Copy over NVRAM RISC parameter block to initialization control block.
1610 */
1611 dptr1 = (uint8_t *)icb;
1612 dptr2 = (uint8_t *)&nv->parameter_block_version;
1613 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1614 while (cnt--)
1615 *dptr1++ = *dptr2++;
1616
1617 /* Copy 2nd half. */
1618 dptr1 = (uint8_t *)icb->add_firmware_options;
1619 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1620 while (cnt--)
1621 *dptr1++ = *dptr2++;
1622
Andrew Vasquez5341e862006-05-17 15:09:16 -07001623 /* Use alternate WWN? */
1624 if (nv->host_p[1] & BIT_7) {
1625 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1626 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1627 }
1628
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 /* Prepare nodename */
1630 if ((icb->firmware_options[1] & BIT_6) == 0) {
1631 /*
1632 * Firmware will apply the following mask if the nodename was
1633 * not provided.
1634 */
1635 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1636 icb->node_name[0] &= 0xF0;
1637 }
1638
1639 /*
1640 * Set host adapter parameters.
1641 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001642 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001643 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1645 /* Always load RISC code on non ISP2[12]00 chips. */
1646 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1647 ha->flags.disable_risc_code_load = 0;
1648 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1649 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1650 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001651 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001652 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 ha->operating_mode =
1655 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1656
1657 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1658 sizeof(ha->fw_seriallink_options));
1659
1660 /* save HBA serial number */
1661 ha->serial0 = icb->port_name[5];
1662 ha->serial1 = icb->port_name[6];
1663 ha->serial2 = icb->port_name[7];
Andrew Vasquez3d716442005-07-06 10:30:26 -07001664 ha->node_name = icb->node_name;
1665 ha->port_name = icb->port_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001666
1667 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1668
1669 ha->retry_count = nv->retry_count;
1670
1671 /* Set minimum login_timeout to 4 seconds. */
1672 if (nv->login_timeout < ql2xlogintimeout)
1673 nv->login_timeout = ql2xlogintimeout;
1674 if (nv->login_timeout < 4)
1675 nv->login_timeout = 4;
1676 ha->login_timeout = nv->login_timeout;
1677 icb->login_timeout = nv->login_timeout;
1678
1679 /* Set minimum RATOV to 200 tenths of a second. */
1680 ha->r_a_tov = 200;
1681
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 ha->loop_reset_delay = nv->reset_delay;
1683
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684 /* Link Down Timeout = 0:
1685 *
1686 * When Port Down timer expires we will start returning
1687 * I/O's to OS with "DID_NO_CONNECT".
1688 *
1689 * Link Down Timeout != 0:
1690 *
1691 * The driver waits for the link to come up after link down
1692 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001693 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001694 if (nv->link_down_timeout == 0) {
1695 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001696 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697 } else {
1698 ha->link_down_timeout = nv->link_down_timeout;
1699 ha->loop_down_abort_time =
1700 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001701 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001702
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 /*
1704 * Need enough time to try and get the port back.
1705 */
1706 ha->port_down_retry_count = nv->port_down_retry_count;
1707 if (qlport_down_retry)
1708 ha->port_down_retry_count = qlport_down_retry;
1709 /* Set login_retry_count */
1710 ha->login_retry_count = nv->retry_count;
1711 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1712 ha->port_down_retry_count > 3)
1713 ha->login_retry_count = ha->port_down_retry_count;
1714 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1715 ha->login_retry_count = ha->port_down_retry_count;
1716 if (ql2xloginretrycount)
1717 ha->login_retry_count = ql2xloginretrycount;
1718
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 icb->lun_enables = __constant_cpu_to_le16(0);
1720 icb->command_resource_count = 0;
1721 icb->immediate_notify_resource_count = 0;
1722 icb->timeout = __constant_cpu_to_le16(0);
1723
1724 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1725 /* Enable RIO */
1726 icb->firmware_options[0] &= ~BIT_3;
1727 icb->add_firmware_options[0] &=
1728 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1729 icb->add_firmware_options[0] |= BIT_2;
1730 icb->response_accumulation_timer = 3;
1731 icb->interrupt_delay_timer = 5;
1732
1733 ha->flags.process_response_queue = 1;
1734 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001735 /* Enable ZIO. */
1736 if (!ha->flags.init_done) {
1737 ha->zio_mode = icb->add_firmware_options[0] &
1738 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1739 ha->zio_timer = icb->interrupt_delay_timer ?
1740 icb->interrupt_delay_timer: 2;
1741 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 icb->add_firmware_options[0] &=
1743 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001744 ha->flags.process_response_queue = 0;
1745 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001746 ha->zio_mode = QLA_ZIO_MODE_6;
1747
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001748 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1749 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1750 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001752 "ZIO mode %d enabled; timer delay (%d us).\n",
1753 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001754
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001755 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1756 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001757 ha->flags.process_response_queue = 1;
1758 }
1759 }
1760
David Miller4e08df32007-04-16 12:37:43 -07001761 if (rval) {
1762 DEBUG2_3(printk(KERN_WARNING
1763 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1764 }
1765 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001766}
1767
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001768static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001769qla2x00_rport_del(void *data)
1770{
1771 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001772 struct fc_rport *rport;
1773 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001774
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001775 spin_lock_irqsave(&fcport->rport_lock, flags);
1776 rport = fcport->drport;
1777 fcport->drport = NULL;
1778 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1779 if (rport)
1780 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001781}
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783/**
1784 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1785 * @ha: HA context
1786 * @flags: allocation flags
1787 *
1788 * Returns a pointer to the allocated fcport, or NULL, if none available.
1789 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001790static fc_port_t *
Al Viroc53033f2005-10-21 03:22:08 -04001791qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792{
1793 fc_port_t *fcport;
1794
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001795 fcport = kzalloc(sizeof(fc_port_t), flags);
1796 if (!fcport)
1797 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798
1799 /* Setup fcport template structure. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800 fcport->ha = ha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001801 fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 fcport->port_type = FCT_UNKNOWN;
1803 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001804 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1805 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001806 fcport->supported_classes = FC_COS_UNSPECIFIED;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001807 spin_lock_init(&fcport->rport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001809 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810}
1811
1812/*
1813 * qla2x00_configure_loop
1814 * Updates Fibre Channel Device Database with what is actually on loop.
1815 *
1816 * Input:
1817 * ha = adapter block pointer.
1818 *
1819 * Returns:
1820 * 0 = success.
1821 * 1 = error.
1822 * 2 = database was full and device was not configured.
1823 */
1824static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001825qla2x00_configure_loop(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001826{
1827 int rval;
1828 unsigned long flags, save_flags;
1829
1830 rval = QLA_SUCCESS;
1831
1832 /* Get Initiator ID */
1833 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1834 rval = qla2x00_configure_hba(ha);
1835 if (rval != QLA_SUCCESS) {
1836 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1837 ha->host_no));
1838 return (rval);
1839 }
1840 }
1841
1842 save_flags = flags = ha->dpc_flags;
1843 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1844 ha->host_no, flags));
1845
1846 /*
1847 * If we have both an RSCN and PORT UPDATE pending then handle them
1848 * both at the same time.
1849 */
1850 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1851 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
1853 /* Determine what we need to do */
1854 if (ha->current_topology == ISP_CFG_FL &&
1855 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1856
1857 ha->flags.rscn_queue_overflow = 1;
1858 set_bit(RSCN_UPDATE, &flags);
1859
1860 } else if (ha->current_topology == ISP_CFG_F &&
1861 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1862
1863 ha->flags.rscn_queue_overflow = 1;
1864 set_bit(RSCN_UPDATE, &flags);
1865 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1866
Andrew Vasquez21333b42006-05-17 15:09:56 -07001867 } else if (ha->current_topology == ISP_CFG_N) {
1868 clear_bit(RSCN_UPDATE, &flags);
1869
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870 } else if (!ha->flags.online ||
1871 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1872
1873 ha->flags.rscn_queue_overflow = 1;
1874 set_bit(RSCN_UPDATE, &flags);
1875 set_bit(LOCAL_LOOP_UPDATE, &flags);
1876 }
1877
1878 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1879 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1880 rval = QLA_FUNCTION_FAILED;
1881 } else {
1882 rval = qla2x00_configure_local_loop(ha);
1883 }
1884 }
1885
1886 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Andrew Vasquez23443b12005-12-06 10:57:06 -08001887 if (LOOP_TRANSITION(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 rval = QLA_FUNCTION_FAILED;
1889 } else {
1890 rval = qla2x00_configure_fabric(ha);
1891 }
1892 }
1893
1894 if (rval == QLA_SUCCESS) {
1895 if (atomic_read(&ha->loop_down_timer) ||
1896 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1897 rval = QLA_FUNCTION_FAILED;
1898 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 atomic_set(&ha->loop_state, LOOP_READY);
1900
1901 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1902 }
1903 }
1904
1905 if (rval) {
1906 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1907 __func__, ha->host_no));
1908 } else {
1909 DEBUG3(printk("%s: exiting normally\n", __func__));
1910 }
1911
1912 /* Restore state if a resync event occured during processing */
1913 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1914 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1915 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1916 if (test_bit(RSCN_UPDATE, &save_flags))
1917 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1918 }
1919
1920 return (rval);
1921}
1922
1923
1924
1925/*
1926 * qla2x00_configure_local_loop
1927 * Updates Fibre Channel Device Database with local loop devices.
1928 *
1929 * Input:
1930 * ha = adapter block pointer.
1931 *
1932 * Returns:
1933 * 0 = success.
1934 */
1935static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001936qla2x00_configure_local_loop(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001937{
1938 int rval, rval2;
1939 int found_devs;
1940 int found;
1941 fc_port_t *fcport, *new_fcport;
1942
1943 uint16_t index;
1944 uint16_t entries;
1945 char *id_iter;
1946 uint16_t loop_id;
1947 uint8_t domain, area, al_pa;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001948 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949
1950 found_devs = 0;
1951 new_fcport = NULL;
1952 entries = MAX_FIBRE_DEVICES;
1953
1954 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1955 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1956
1957 /* Get list of logged in devices. */
1958 memset(ha->gid_list, 0, GID_LIST_SIZE);
1959 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1960 &entries);
1961 if (rval != QLA_SUCCESS)
1962 goto cleanup_allocation;
1963
1964 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1965 ha->host_no, entries));
1966 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1967 entries * sizeof(struct gid_list_info)));
1968
1969 /* Allocate temporary fcport for any new fcports discovered. */
1970 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1971 if (new_fcport == NULL) {
1972 rval = QLA_MEMORY_ALLOC_FAILED;
1973 goto cleanup_allocation;
1974 }
1975 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1976
1977 /*
1978 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1979 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001980 list_for_each_entry(fcport, &pha->fcports, list) {
1981 if (fcport->vp_idx != ha->vp_idx)
1982 continue;
1983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1985 fcport->port_type != FCT_BROADCAST &&
1986 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1987
1988 DEBUG(printk("scsi(%ld): Marking port lost, "
1989 "loop_id=0x%04x\n",
1990 ha->host_no, fcport->loop_id));
1991
1992 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1993 fcport->flags &= ~FCF_FARP_DONE;
1994 }
1995 }
1996
1997 /* Add devices to port list. */
1998 id_iter = (char *)ha->gid_list;
1999 for (index = 0; index < entries; index++) {
2000 domain = ((struct gid_list_info *)id_iter)->domain;
2001 area = ((struct gid_list_info *)id_iter)->area;
2002 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002003 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 loop_id = (uint16_t)
2005 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002006 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 loop_id = le16_to_cpu(
2008 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002009 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010
2011 /* Bypass reserved domain fields. */
2012 if ((domain & 0xf0) == 0xf0)
2013 continue;
2014
2015 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002016 if (area && domain &&
2017 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 continue;
2019
2020 /* Bypass invalid local loop ID. */
2021 if (loop_id > LAST_LOCAL_LOOP_ID)
2022 continue;
2023
2024 /* Fill in member data. */
2025 new_fcport->d_id.b.domain = domain;
2026 new_fcport->d_id.b.area = area;
2027 new_fcport->d_id.b.al_pa = al_pa;
2028 new_fcport->loop_id = loop_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002029 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2031 if (rval2 != QLA_SUCCESS) {
2032 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2033 "information -- get_port_database=%x, "
2034 "loop_id=0x%04x\n",
2035 ha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002036 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2037 ha->host_no));
2038 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002039 continue;
2040 }
2041
2042 /* Check for matching device in port list. */
2043 found = 0;
2044 fcport = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002045 list_for_each_entry(fcport, &pha->fcports, list) {
2046 if (fcport->vp_idx != ha->vp_idx)
2047 continue;
2048
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 if (memcmp(new_fcport->port_name, fcport->port_name,
2050 WWN_SIZE))
2051 continue;
2052
2053 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2054 FCF_PERSISTENT_BOUND);
2055 fcport->loop_id = new_fcport->loop_id;
2056 fcport->port_type = new_fcport->port_type;
2057 fcport->d_id.b24 = new_fcport->d_id.b24;
2058 memcpy(fcport->node_name, new_fcport->node_name,
2059 WWN_SIZE);
2060
2061 found++;
2062 break;
2063 }
2064
2065 if (!found) {
2066 /* New device, add to fcports list. */
2067 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002068 if (ha->parent) {
2069 new_fcport->ha = ha;
2070 new_fcport->vp_idx = ha->vp_idx;
2071 list_add_tail(&new_fcport->vp_fcport,
2072 &ha->vp_fcports);
2073 }
2074 list_add_tail(&new_fcport->list, &pha->fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075
2076 /* Allocate a new replacement fcport. */
2077 fcport = new_fcport;
2078 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2079 if (new_fcport == NULL) {
2080 rval = QLA_MEMORY_ALLOC_FAILED;
2081 goto cleanup_allocation;
2082 }
2083 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2084 }
2085
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002086 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002087 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002088
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 qla2x00_update_fcport(ha, fcport);
2090
2091 found_devs++;
2092 }
2093
2094cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002095 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096
2097 if (rval != QLA_SUCCESS) {
2098 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2099 "rval=%x\n", ha->host_no, rval));
2100 }
2101
2102 if (found_devs) {
2103 ha->device_flags |= DFLG_LOCAL_DEVICES;
2104 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2105 }
2106
2107 return (rval);
2108}
2109
2110static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002111qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002112{
2113 fc_port_t *fcport;
2114
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002115 qla2x00_mark_all_devices_lost(ha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 list_for_each_entry(fcport, &ha->fcports, list) {
2117 if (fcport->port_type != FCT_TARGET)
2118 continue;
2119
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002120 qla2x00_update_fcport(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002121 }
2122}
2123
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002124static void
2125qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2126{
2127#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002128 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002129 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002130 uint16_t mb[6];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002131
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002132 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002133 return;
2134
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002135 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2136 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002137 return;
2138
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002139 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, fcport->fp_speed,
2140 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002141 if (rval != QLA_SUCCESS) {
2142 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2143 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2144 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2145 fcport->port_name[2], fcport->port_name[3],
2146 fcport->port_name[4], fcport->port_name[5],
2147 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002148 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002149 } else {
2150 DEBUG2(qla_printk(KERN_INFO, ha,
2151 "iIDMA adjusted to %s GB/s on "
2152 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002153 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002154 fcport->port_name[1], fcport->port_name[2],
2155 fcport->port_name[3], fcport->port_name[4],
2156 fcport->port_name[5], fcport->port_name[6],
2157 fcport->port_name[7]));
2158 }
2159}
2160
Adrian Bunk23be3312006-11-24 02:46:01 +01002161static void
8482e112005-04-17 15:04:54 -05002162qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2163{
2164 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002165 struct fc_rport *rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002166 unsigned long flags;
8482e112005-04-17 15:04:54 -05002167
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002168 if (fcport->drport)
2169 qla2x00_rport_del(fcport);
2170 if (fcport->rport)
2171 return;
8482e112005-04-17 15:04:54 -05002172
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002173 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2174 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002175 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2176 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2177 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002178 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002179 if (!rport) {
2180 qla_printk(KERN_WARNING, ha,
2181 "Unable to allocate fc remote port!\n");
2182 return;
2183 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002184 spin_lock_irqsave(&fcport->rport_lock, flags);
2185 fcport->rport = rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002186 *((fc_port_t **)rport->dd_data) = fcport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002187 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2188
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002189 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002190
2191 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002192 if (fcport->port_type == FCT_INITIATOR)
2193 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2194 if (fcport->port_type == FCT_TARGET)
2195 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002196 fc_remote_port_rolechg(rport, rport_ids.roles);
bdf79622005-04-17 15:06:53 -05002197
Andrew Vasquezcc4731f2005-07-06 10:32:37 -07002198 if (rport->scsi_target_id != -1 &&
2199 rport->scsi_target_id < ha->host->max_id)
bdf79622005-04-17 15:06:53 -05002200 fcport->os_target_id = rport->scsi_target_id;
8482e112005-04-17 15:04:54 -05002201}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202
2203/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002204 * qla2x00_update_fcport
2205 * Updates device on list.
2206 *
2207 * Input:
2208 * ha = adapter block pointer.
2209 * fcport = port structure pointer.
2210 *
2211 * Return:
2212 * 0 - Success
2213 * BIT_0 - error
2214 *
2215 * Context:
2216 * Kernel context.
2217 */
2218void
2219qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2220{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002221 scsi_qla_host_t *pha = to_qla_parent(ha);
2222
Adrian Bunk23be3312006-11-24 02:46:01 +01002223 fcport->ha = ha;
2224 fcport->login_retry = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002225 fcport->port_login_retry_count = pha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002226 PORT_RETRY_TIME;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002227 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002228 PORT_RETRY_TIME);
2229 fcport->flags &= ~FCF_LOGIN_NEEDED;
2230
2231 qla2x00_iidma_fcport(ha, fcport);
2232
2233 atomic_set(&fcport->state, FCS_ONLINE);
2234
2235 qla2x00_reg_remote_port(ha, fcport);
2236}
2237
2238/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002239 * qla2x00_configure_fabric
2240 * Setup SNS devices with loop ID's.
2241 *
2242 * Input:
2243 * ha = adapter block pointer.
2244 *
2245 * Returns:
2246 * 0 = success.
2247 * BIT_0 = error
2248 */
2249static int
2250qla2x00_configure_fabric(scsi_qla_host_t *ha)
2251{
2252 int rval, rval2;
2253 fc_port_t *fcport, *fcptemp;
2254 uint16_t next_loopid;
2255 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002256 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002257 LIST_HEAD(new_fcports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002258 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259
2260 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002261 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002262 loop_id = NPH_F_PORT;
2263 else
2264 loop_id = SNS_FL_PORT;
Andrew Vasquez90991c82006-10-02 12:00:46 -07002265 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266 if (rval != QLA_SUCCESS) {
2267 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2268 "Port\n", ha->host_no));
2269
2270 ha->device_flags &= ~SWITCH_FOUND;
2271 return (QLA_SUCCESS);
2272 }
Andrew Vasquez90991c82006-10-02 12:00:46 -07002273 ha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002274
2275 /* Mark devices that need re-synchronization. */
2276 rval2 = qla2x00_device_resync(ha);
2277 if (rval2 == QLA_RSCNS_HANDLED) {
2278 /* No point doing the scan, just continue. */
2279 return (QLA_SUCCESS);
2280 }
2281 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002282 /* FDMI support. */
2283 if (ql2xfdmienable &&
2284 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2285 qla2x00_fdmi_register(ha);
2286
Linus Torvalds1da177e2005-04-16 15:20:36 -07002287 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002288 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002289 loop_id = NPH_SNS;
2290 else
2291 loop_id = SIMPLE_NAME_SERVER;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002292 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002293 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002294 if (mb[0] != MBS_COMMAND_COMPLETE) {
2295 DEBUG2(qla_printk(KERN_INFO, ha,
2296 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002297 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002298 mb[0], mb[1], mb[2], mb[6], mb[7]));
2299 return (QLA_SUCCESS);
2300 }
2301
2302 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2303 if (qla2x00_rft_id(ha)) {
2304 /* EMPTY */
2305 DEBUG2(printk("scsi(%ld): Register FC-4 "
2306 "TYPE failed.\n", ha->host_no));
2307 }
2308 if (qla2x00_rff_id(ha)) {
2309 /* EMPTY */
2310 DEBUG2(printk("scsi(%ld): Register FC-4 "
2311 "Features failed.\n", ha->host_no));
2312 }
2313 if (qla2x00_rnn_id(ha)) {
2314 /* EMPTY */
2315 DEBUG2(printk("scsi(%ld): Register Node Name "
2316 "failed.\n", ha->host_no));
2317 } else if (qla2x00_rsnn_nn(ha)) {
2318 /* EMPTY */
2319 DEBUG2(printk("scsi(%ld): Register Symbolic "
2320 "Node Name failed.\n", ha->host_no));
2321 }
2322 }
2323
2324 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2325 if (rval != QLA_SUCCESS)
2326 break;
2327
2328 /*
2329 * Logout all previous fabric devices marked lost, except
2330 * tape devices.
2331 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002332 list_for_each_entry(fcport, &pha->fcports, list) {
2333 if (fcport->vp_idx !=ha->vp_idx)
2334 continue;
2335
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2337 break;
2338
2339 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2340 continue;
2341
2342 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2343 qla2x00_mark_device_lost(ha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002344 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002345 if (fcport->loop_id != FC_NO_LOOP_ID &&
2346 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2347 fcport->port_type != FCT_INITIATOR &&
2348 fcport->port_type != FCT_BROADCAST) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002349 ha->isp_ops->fabric_logout(ha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002350 fcport->loop_id,
2351 fcport->d_id.b.domain,
2352 fcport->d_id.b.area,
2353 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354 fcport->loop_id = FC_NO_LOOP_ID;
2355 }
2356 }
2357 }
2358
2359 /* Starting free loop ID. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002360 next_loopid = pha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
2362 /*
2363 * Scan through our port list and login entries that need to be
2364 * logged in.
2365 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002366 list_for_each_entry(fcport, &pha->fcports, list) {
2367 if (fcport->vp_idx != ha->vp_idx)
2368 continue;
2369
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 if (atomic_read(&ha->loop_down_timer) ||
2371 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2372 break;
2373
2374 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2375 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2376 continue;
2377
2378 if (fcport->loop_id == FC_NO_LOOP_ID) {
2379 fcport->loop_id = next_loopid;
2380 rval = qla2x00_find_new_loop_id(ha, fcport);
2381 if (rval != QLA_SUCCESS) {
2382 /* Ran out of IDs to use */
2383 break;
2384 }
2385 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002386 /* Login and update database */
2387 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2388 }
2389
2390 /* Exit if out of loop IDs. */
2391 if (rval != QLA_SUCCESS) {
2392 break;
2393 }
2394
2395 /*
2396 * Login and add the new devices to our port list.
2397 */
2398 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2399 if (atomic_read(&ha->loop_down_timer) ||
2400 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2401 break;
2402
2403 /* Find a new loop ID to use. */
2404 fcport->loop_id = next_loopid;
2405 rval = qla2x00_find_new_loop_id(ha, fcport);
2406 if (rval != QLA_SUCCESS) {
2407 /* Ran out of IDs to use */
2408 break;
2409 }
2410
bdf79622005-04-17 15:06:53 -05002411 /* Login and update database */
2412 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002413
2414 if (ha->parent) {
2415 fcport->ha = ha;
2416 fcport->vp_idx = ha->vp_idx;
2417 list_add_tail(&fcport->vp_fcport,
2418 &ha->vp_fcports);
2419 list_move_tail(&fcport->list,
2420 &ha->parent->fcports);
2421 } else
2422 list_move_tail(&fcport->list, &ha->fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423 }
2424 } while (0);
2425
2426 /* Free all new device structures not processed. */
2427 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2428 list_del(&fcport->list);
2429 kfree(fcport);
2430 }
2431
2432 if (rval) {
2433 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2434 "rval=%d\n", ha->host_no, rval));
2435 }
2436
2437 return (rval);
2438}
2439
2440
2441/*
2442 * qla2x00_find_all_fabric_devs
2443 *
2444 * Input:
2445 * ha = adapter block pointer.
2446 * dev = database device entry pointer.
2447 *
2448 * Returns:
2449 * 0 = success.
2450 *
2451 * Context:
2452 * Kernel context.
2453 */
2454static int
2455qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2456{
2457 int rval;
2458 uint16_t loop_id;
2459 fc_port_t *fcport, *new_fcport, *fcptemp;
2460 int found;
2461
2462 sw_info_t *swl;
2463 int swl_idx;
2464 int first_dev, last_dev;
2465 port_id_t wrap, nxt_d_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002466 int vp_index;
2467 int empty_vp_index;
2468 int found_vp;
2469 scsi_qla_host_t *vha;
2470 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
2472 rval = QLA_SUCCESS;
2473
2474 /* Try GID_PT to get device list, else GAN. */
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002475 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_ATOMIC);
2476 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 /*EMPTY*/
2478 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2479 "on GA_NXT\n", ha->host_no));
2480 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2482 kfree(swl);
2483 swl = NULL;
2484 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2485 kfree(swl);
2486 swl = NULL;
2487 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2488 kfree(swl);
2489 swl = NULL;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002490 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2491 qla2x00_gpsc(ha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 }
2493 }
2494 swl_idx = 0;
2495
2496 /* Allocate temporary fcport for any new fcports discovered. */
2497 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2498 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002499 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002500 return (QLA_MEMORY_ALLOC_FAILED);
2501 }
2502 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002503 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 /* Set start port ID scan at adapter ID. */
2505 first_dev = 1;
2506 last_dev = 0;
2507
2508 /* Starting free loop ID. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002509 loop_id = pha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002510 for (; loop_id <= ha->last_loop_id; loop_id++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07002511 if (qla2x00_is_reserved_id(ha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512 continue;
2513
Andrew Vasquez23443b12005-12-06 10:57:06 -08002514 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 break;
2516
2517 if (swl != NULL) {
2518 if (last_dev) {
2519 wrap.b24 = new_fcport->d_id.b24;
2520 } else {
2521 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2522 memcpy(new_fcport->node_name,
2523 swl[swl_idx].node_name, WWN_SIZE);
2524 memcpy(new_fcport->port_name,
2525 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002526 memcpy(new_fcport->fabric_port_name,
2527 swl[swl_idx].fabric_port_name, WWN_SIZE);
2528 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529
2530 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2531 last_dev = 1;
2532 }
2533 swl_idx++;
2534 }
2535 } else {
2536 /* Send GA_NXT to the switch */
2537 rval = qla2x00_ga_nxt(ha, new_fcport);
2538 if (rval != QLA_SUCCESS) {
2539 qla_printk(KERN_WARNING, ha,
2540 "SNS scan failed -- assuming zero-entry "
2541 "result...\n");
2542 list_for_each_entry_safe(fcport, fcptemp,
2543 new_fcports, list) {
2544 list_del(&fcport->list);
2545 kfree(fcport);
2546 }
2547 rval = QLA_SUCCESS;
2548 break;
2549 }
2550 }
2551
2552 /* If wrap on switch device list, exit. */
2553 if (first_dev) {
2554 wrap.b24 = new_fcport->d_id.b24;
2555 first_dev = 0;
2556 } else if (new_fcport->d_id.b24 == wrap.b24) {
2557 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2558 ha->host_no, new_fcport->d_id.b.domain,
2559 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2560 break;
2561 }
2562
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002563 /* Bypass if same physical adapter. */
2564 if (new_fcport->d_id.b24 == pha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 continue;
2566
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002567 /* Bypass virtual ports of the same host. */
2568 if (pha->num_vhosts) {
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002569 for_each_mapped_vp_idx(pha, vp_index) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002570 empty_vp_index = 1;
2571 found_vp = 0;
2572 list_for_each_entry(vha, &pha->vp_list,
2573 vp_list) {
2574 if (vp_index == vha->vp_idx) {
2575 empty_vp_index = 0;
2576 found_vp = 1;
2577 break;
2578 }
2579 }
2580
2581 if (empty_vp_index)
2582 continue;
2583
2584 if (found_vp &&
2585 new_fcport->d_id.b24 == vha->d_id.b24)
2586 break;
2587 }
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002588
2589 if (vp_index <= pha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002590 continue;
2591 }
2592
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002593 /* Bypass if same domain and area of adapter. */
2594 if (((new_fcport->d_id.b24 & 0xffff00) ==
2595 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2596 ISP_CFG_FL)
2597 continue;
2598
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 /* Bypass reserved domain fields. */
2600 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2601 continue;
2602
2603 /* Locate matching device in database. */
2604 found = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002605 list_for_each_entry(fcport, &pha->fcports, list) {
2606 if (new_fcport->vp_idx != fcport->vp_idx)
2607 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 if (memcmp(new_fcport->port_name, fcport->port_name,
2609 WWN_SIZE))
2610 continue;
2611
2612 found++;
2613
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002614 /* Update port state. */
2615 memcpy(fcport->fabric_port_name,
2616 new_fcport->fabric_port_name, WWN_SIZE);
2617 fcport->fp_speed = new_fcport->fp_speed;
2618
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 /*
2620 * If address the same and state FCS_ONLINE, nothing
2621 * changed.
2622 */
2623 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2624 atomic_read(&fcport->state) == FCS_ONLINE) {
2625 break;
2626 }
2627
2628 /*
2629 * If device was not a fabric device before.
2630 */
2631 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2632 fcport->d_id.b24 = new_fcport->d_id.b24;
2633 fcport->loop_id = FC_NO_LOOP_ID;
2634 fcport->flags |= (FCF_FABRIC_DEVICE |
2635 FCF_LOGIN_NEEDED);
2636 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2637 break;
2638 }
2639
2640 /*
2641 * Port ID changed or device was marked to be updated;
2642 * Log it out if still logged in and mark it for
2643 * relogin later.
2644 */
2645 fcport->d_id.b24 = new_fcport->d_id.b24;
2646 fcport->flags |= FCF_LOGIN_NEEDED;
2647 if (fcport->loop_id != FC_NO_LOOP_ID &&
2648 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2649 fcport->port_type != FCT_INITIATOR &&
2650 fcport->port_type != FCT_BROADCAST) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002651 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002652 fcport->d_id.b.domain, fcport->d_id.b.area,
2653 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 fcport->loop_id = FC_NO_LOOP_ID;
2655 }
2656
2657 break;
2658 }
2659
2660 if (found)
2661 continue;
2662
2663 /* If device was not in our fcports list, then add it. */
2664 list_add_tail(&new_fcport->list, new_fcports);
2665
2666 /* Allocate a new replacement fcport. */
2667 nxt_d_id.b24 = new_fcport->d_id.b24;
2668 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2669 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002670 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 return (QLA_MEMORY_ALLOC_FAILED);
2672 }
2673 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2674 new_fcport->d_id.b24 = nxt_d_id.b24;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002675 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 }
2677
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002678 kfree(swl);
2679 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680
2681 if (!list_empty(new_fcports))
2682 ha->device_flags |= DFLG_FABRIC_DEVICES;
2683
2684 return (rval);
2685}
2686
2687/*
2688 * qla2x00_find_new_loop_id
2689 * Scan through our port list and find a new usable loop ID.
2690 *
2691 * Input:
2692 * ha: adapter state pointer.
2693 * dev: port structure pointer.
2694 *
2695 * Returns:
2696 * qla2x00 local function return status code.
2697 *
2698 * Context:
2699 * Kernel context.
2700 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002701static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2703{
2704 int rval;
2705 int found;
2706 fc_port_t *fcport;
2707 uint16_t first_loop_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002708 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
2710 rval = QLA_SUCCESS;
2711
2712 /* Save starting loop ID. */
2713 first_loop_id = dev->loop_id;
2714
2715 for (;;) {
2716 /* Skip loop ID if already used by adapter. */
2717 if (dev->loop_id == ha->loop_id) {
2718 dev->loop_id++;
2719 }
2720
2721 /* Skip reserved loop IDs. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002722 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 dev->loop_id++;
2724 }
2725
2726 /* Reset loop ID if passed the end. */
2727 if (dev->loop_id > ha->last_loop_id) {
2728 /* first loop ID. */
2729 dev->loop_id = ha->min_external_loopid;
2730 }
2731
2732 /* Check for loop ID being already in use. */
2733 found = 0;
2734 fcport = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002735 list_for_each_entry(fcport, &pha->fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2737 /* ID possibly in use */
2738 found++;
2739 break;
2740 }
2741 }
2742
2743 /* If not in use then it is free to use. */
2744 if (!found) {
2745 break;
2746 }
2747
2748 /* ID in use. Try next value. */
2749 dev->loop_id++;
2750
2751 /* If wrap around. No free ID to use. */
2752 if (dev->loop_id == first_loop_id) {
2753 dev->loop_id = FC_NO_LOOP_ID;
2754 rval = QLA_FUNCTION_FAILED;
2755 break;
2756 }
2757 }
2758
2759 return (rval);
2760}
2761
2762/*
2763 * qla2x00_device_resync
2764 * Marks devices in the database that needs resynchronization.
2765 *
2766 * Input:
2767 * ha = adapter block pointer.
2768 *
2769 * Context:
2770 * Kernel context.
2771 */
2772static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002773qla2x00_device_resync(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774{
2775 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 uint32_t mask;
2777 fc_port_t *fcport;
2778 uint32_t rscn_entry;
2779 uint8_t rscn_out_iter;
2780 uint8_t format;
2781 port_id_t d_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002782 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 rval = QLA_RSCNS_HANDLED;
2785
2786 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2787 ha->flags.rscn_queue_overflow) {
2788
2789 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2790 format = MSB(MSW(rscn_entry));
2791 d_id.b.domain = LSB(MSW(rscn_entry));
2792 d_id.b.area = MSB(LSW(rscn_entry));
2793 d_id.b.al_pa = LSB(LSW(rscn_entry));
2794
2795 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2796 "[%02x/%02x%02x%02x].\n",
2797 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2798 d_id.b.area, d_id.b.al_pa));
2799
2800 ha->rscn_out_ptr++;
2801 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2802 ha->rscn_out_ptr = 0;
2803
2804 /* Skip duplicate entries. */
2805 for (rscn_out_iter = ha->rscn_out_ptr;
2806 !ha->flags.rscn_queue_overflow &&
2807 rscn_out_iter != ha->rscn_in_ptr;
2808 rscn_out_iter = (rscn_out_iter ==
2809 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2810
2811 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2812 break;
2813
2814 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2815 "entry found at [%d].\n", ha->host_no,
2816 rscn_out_iter));
2817
2818 ha->rscn_out_ptr = rscn_out_iter;
2819 }
2820
2821 /* Queue overflow, set switch default case. */
2822 if (ha->flags.rscn_queue_overflow) {
2823 DEBUG(printk("scsi(%ld): device_resync: rscn "
2824 "overflow.\n", ha->host_no));
2825
2826 format = 3;
2827 ha->flags.rscn_queue_overflow = 0;
2828 }
2829
2830 switch (format) {
2831 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 mask = 0xffffff;
2833 break;
2834 case 1:
2835 mask = 0xffff00;
2836 break;
2837 case 2:
2838 mask = 0xff0000;
2839 break;
2840 default:
2841 mask = 0x0;
2842 d_id.b24 = 0;
2843 ha->rscn_out_ptr = ha->rscn_in_ptr;
2844 break;
2845 }
2846
2847 rval = QLA_SUCCESS;
2848
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002849 list_for_each_entry(fcport, &pha->fcports, list) {
2850 if (fcport->vp_idx != ha->vp_idx)
2851 continue;
2852
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2854 (fcport->d_id.b24 & mask) != d_id.b24 ||
2855 fcport->port_type == FCT_BROADCAST)
2856 continue;
2857
2858 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2859 if (format != 3 ||
2860 fcport->port_type != FCT_INITIATOR) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002861 qla2x00_mark_device_lost(ha, fcport,
2862 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002863 }
2864 }
2865 fcport->flags &= ~FCF_FARP_DONE;
2866 }
2867 }
2868 return (rval);
2869}
2870
2871/*
2872 * qla2x00_fabric_dev_login
2873 * Login fabric target device and update FC port database.
2874 *
2875 * Input:
2876 * ha: adapter state pointer.
2877 * fcport: port structure list pointer.
2878 * next_loopid: contains value of a new loop ID that can be used
2879 * by the next login attempt.
2880 *
2881 * Returns:
2882 * qla2x00 local function return status code.
2883 *
2884 * Context:
2885 * Kernel context.
2886 */
2887static int
2888qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2889 uint16_t *next_loopid)
2890{
2891 int rval;
2892 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07002893 uint8_t opts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894
2895 rval = QLA_SUCCESS;
2896 retry = 0;
2897
2898 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2899 if (rval == QLA_SUCCESS) {
Andrew Vasquez01071092005-07-06 10:31:37 -07002900 /* Send an ADISC to tape devices.*/
2901 opts = 0;
2902 if (fcport->flags & FCF_TAPE_PRESENT)
2903 opts |= BIT_1;
2904 rval = qla2x00_get_port_database(ha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 if (rval != QLA_SUCCESS) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002906 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002907 fcport->d_id.b.domain, fcport->d_id.b.area,
2908 fcport->d_id.b.al_pa);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002909 qla2x00_mark_device_lost(ha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 } else {
2911 qla2x00_update_fcport(ha, fcport);
2912 }
2913 }
2914
2915 return (rval);
2916}
2917
2918/*
2919 * qla2x00_fabric_login
2920 * Issue fabric login command.
2921 *
2922 * Input:
2923 * ha = adapter block pointer.
2924 * device = pointer to FC device type structure.
2925 *
2926 * Returns:
2927 * 0 - Login successfully
2928 * 1 - Login failed
2929 * 2 - Initiator device
2930 * 3 - Fatal error
2931 */
2932int
2933qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2934 uint16_t *next_loopid)
2935{
2936 int rval;
2937 int retry;
2938 uint16_t tmp_loopid;
2939 uint16_t mb[MAILBOX_REGISTER_COUNT];
2940
2941 retry = 0;
2942 tmp_loopid = 0;
2943
2944 for (;;) {
2945 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2946 "for port %02x%02x%02x.\n",
2947 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2948 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2949
2950 /* Login fcport on switch. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002951 ha->isp_ops->fabric_login(ha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 fcport->d_id.b.domain, fcport->d_id.b.area,
2953 fcport->d_id.b.al_pa, mb, BIT_0);
2954 if (mb[0] == MBS_PORT_ID_USED) {
2955 /*
2956 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07002957 * recommends the driver perform an implicit login with
2958 * the specified ID again. The ID we just used is save
2959 * here so we return with an ID that can be tried by
2960 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 */
2962 retry++;
2963 tmp_loopid = fcport->loop_id;
2964 fcport->loop_id = mb[1];
2965
2966 DEBUG(printk("Fabric Login: port in use - next "
2967 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2968 fcport->loop_id, fcport->d_id.b.domain,
2969 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2970
2971 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2972 /*
2973 * Login succeeded.
2974 */
2975 if (retry) {
2976 /* A retry occurred before. */
2977 *next_loopid = tmp_loopid;
2978 } else {
2979 /*
2980 * No retry occurred before. Just increment the
2981 * ID value for next login.
2982 */
2983 *next_loopid = (fcport->loop_id + 1);
2984 }
2985
2986 if (mb[1] & BIT_0) {
2987 fcport->port_type = FCT_INITIATOR;
2988 } else {
2989 fcport->port_type = FCT_TARGET;
2990 if (mb[1] & BIT_1) {
2991 fcport->flags |= FCF_TAPE_PRESENT;
2992 }
2993 }
2994
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002995 if (mb[10] & BIT_0)
2996 fcport->supported_classes |= FC_COS_CLASS2;
2997 if (mb[10] & BIT_1)
2998 fcport->supported_classes |= FC_COS_CLASS3;
2999
Linus Torvalds1da177e2005-04-16 15:20:36 -07003000 rval = QLA_SUCCESS;
3001 break;
3002 } else if (mb[0] == MBS_LOOP_ID_USED) {
3003 /*
3004 * Loop ID already used, try next loop ID.
3005 */
3006 fcport->loop_id++;
3007 rval = qla2x00_find_new_loop_id(ha, fcport);
3008 if (rval != QLA_SUCCESS) {
3009 /* Ran out of loop IDs to use */
3010 break;
3011 }
3012 } else if (mb[0] == MBS_COMMAND_ERROR) {
3013 /*
3014 * Firmware possibly timed out during login. If NO
3015 * retries are left to do then the device is declared
3016 * dead.
3017 */
3018 *next_loopid = fcport->loop_id;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003019 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003020 fcport->d_id.b.domain, fcport->d_id.b.area,
3021 fcport->d_id.b.al_pa);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003022 qla2x00_mark_device_lost(ha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023
3024 rval = 1;
3025 break;
3026 } else {
3027 /*
3028 * unrecoverable / not handled error
3029 */
3030 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003031 "loop_id=%x jiffies=%lx.\n",
3032 __func__, ha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 fcport->d_id.b.domain, fcport->d_id.b.area,
3034 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3035
3036 *next_loopid = fcport->loop_id;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003037 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003038 fcport->d_id.b.domain, fcport->d_id.b.area,
3039 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003041 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042
3043 rval = 3;
3044 break;
3045 }
3046 }
3047
3048 return (rval);
3049}
3050
3051/*
3052 * qla2x00_local_device_login
3053 * Issue local device login command.
3054 *
3055 * Input:
3056 * ha = adapter block pointer.
3057 * loop_id = loop id of device to login to.
3058 *
3059 * Returns (Where's the #define!!!!):
3060 * 0 - Login successfully
3061 * 1 - Login failed
3062 * 3 - Fatal error
3063 */
3064int
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08003065qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066{
3067 int rval;
3068 uint16_t mb[MAILBOX_REGISTER_COUNT];
3069
3070 memset(mb, 0, sizeof(mb));
andrew.vasquez@qlogic.com9a52a572006-03-09 14:27:44 -08003071 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 if (rval == QLA_SUCCESS) {
3073 /* Interrogate mailbox registers for any errors */
3074 if (mb[0] == MBS_COMMAND_ERROR)
3075 rval = 1;
3076 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3077 /* device not in PCB table */
3078 rval = 3;
3079 }
3080
3081 return (rval);
3082}
3083
3084/*
3085 * qla2x00_loop_resync
3086 * Resync with fibre channel devices.
3087 *
3088 * Input:
3089 * ha = adapter block pointer.
3090 *
3091 * Returns:
3092 * 0 = success
3093 */
3094int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003095qla2x00_loop_resync(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096{
3097 int rval;
3098 uint32_t wait_time;
3099
3100 rval = QLA_SUCCESS;
3101
3102 atomic_set(&ha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003103 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3104 if (ha->flags.online) {
3105 if (!(rval = qla2x00_fw_ready(ha))) {
3106 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3107 wait_time = 256;
3108 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003109 atomic_set(&ha->loop_state, LOOP_UPDATE);
3110
Andrew Vasquez01071092005-07-06 10:31:37 -07003111 /* Issue a marker after FW becomes ready. */
3112 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3113 ha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114
3115 /* Remap devices on Loop. */
3116 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3117
3118 qla2x00_configure_loop(ha);
3119 wait_time--;
3120 } while (!atomic_read(&ha->loop_down_timer) &&
3121 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3122 wait_time &&
3123 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125 }
3126
3127 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3128 return (QLA_FUNCTION_FAILED);
3129 }
3130
3131 if (rval) {
3132 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3133 }
3134
3135 return (rval);
3136}
3137
Linus Torvalds1da177e2005-04-16 15:20:36 -07003138void
3139qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3140{
3141 int rescan_done;
3142 fc_port_t *fcport;
3143
3144 rescan_done = 0;
3145 list_for_each_entry(fcport, &ha->fcports, list) {
3146 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3147 continue;
3148
3149 qla2x00_update_fcport(ha, fcport);
3150 fcport->flags &= ~FCF_RESCAN_NEEDED;
3151
3152 rescan_done = 1;
3153 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003154 qla2x00_probe_for_all_luns(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003155}
3156
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003157void
3158qla2x00_update_fcports(scsi_qla_host_t *ha)
3159{
3160 fc_port_t *fcport;
3161
3162 /* Go with deferred removal of rport references. */
3163 list_for_each_entry(fcport, &ha->fcports, list)
3164 if (fcport->drport)
3165 qla2x00_rport_del(fcport);
3166}
3167
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168/*
3169* qla2x00_abort_isp
3170* Resets ISP and aborts all outstanding commands.
3171*
3172* Input:
3173* ha = adapter block pointer.
3174*
3175* Returns:
3176* 0 = success
3177*/
3178int
3179qla2x00_abort_isp(scsi_qla_host_t *ha)
3180{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003181 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182 unsigned long flags = 0;
3183 uint16_t cnt;
3184 srb_t *sp;
3185 uint8_t status = 0;
3186
3187 if (ha->flags.online) {
3188 ha->flags.online = 0;
3189 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003190
3191 qla_printk(KERN_INFO, ha,
3192 "Performing ISP error recovery - ha= %p.\n", ha);
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003193 ha->isp_ops->reset_chip(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194
3195 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3196 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3197 atomic_set(&ha->loop_state, LOOP_DOWN);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003198 qla2x00_mark_all_devices_lost(ha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 } else {
3200 if (!atomic_read(&ha->loop_down_timer))
3201 atomic_set(&ha->loop_down_timer,
3202 LOOP_DOWN_TIME);
3203 }
3204
3205 spin_lock_irqsave(&ha->hardware_lock, flags);
3206 /* Requeue all commands in outstanding command list. */
3207 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3208 sp = ha->outstanding_cmds[cnt];
3209 if (sp) {
3210 ha->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 sp->flags = 0;
f4f051e2005-04-17 15:02:26 -05003212 sp->cmd->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 sp->cmd->host_scribble = (unsigned char *)NULL;
f4f051e2005-04-17 15:02:26 -05003214 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 }
3216 }
3217 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3218
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003219 ha->isp_ops->get_flash_version(ha, ha->request_ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003220
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003221 ha->isp_ops->nvram_config(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
3223 if (!qla2x00_restart_isp(ha)) {
3224 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3225
3226 if (!atomic_read(&ha->loop_down_timer)) {
3227 /*
3228 * Issue marker command only when we are going
3229 * to start the I/O .
3230 */
3231 ha->marker_needed = 1;
3232 }
3233
3234 ha->flags.online = 1;
3235
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003236 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003238 ha->isp_abort_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003240
3241 if (ha->eft) {
Andrew Vasquez00b6bd22008-01-17 09:02:16 -08003242 rval = qla2x00_enable_eft_trace(ha,
Andrew Vasquez476e8972006-08-23 14:54:55 -07003243 ha->eft_dma, EFT_NUM_BUFFERS);
3244 if (rval) {
3245 qla_printk(KERN_WARNING, ha,
3246 "Unable to reinitialize EFT "
3247 "(%d).\n", rval);
3248 }
3249 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 } else { /* failed the ISP abort */
3251 ha->flags.online = 1;
3252 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3253 if (ha->isp_abort_cnt == 0) {
3254 qla_printk(KERN_WARNING, ha,
3255 "ISP error recovery failed - "
3256 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003257 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 * The next call disables the board
3259 * completely.
3260 */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003261 ha->isp_ops->reset_adapter(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 ha->flags.online = 0;
3263 clear_bit(ISP_ABORT_RETRY,
3264 &ha->dpc_flags);
3265 status = 0;
3266 } else { /* schedule another ISP abort */
3267 ha->isp_abort_cnt--;
3268 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003269 "retry remaining %d\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003270 ha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271 status = 1;
3272 }
3273 } else {
3274 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3275 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3276 "- retrying (%d) more times\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003277 ha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3279 status = 1;
3280 }
3281 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003282
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 }
3284
3285 if (status) {
3286 qla_printk(KERN_INFO, ha,
3287 "qla2x00_abort_isp: **** FAILED ****\n");
3288 } else {
3289 DEBUG(printk(KERN_INFO
3290 "qla2x00_abort_isp(%ld): exiting.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003291 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 }
3293
3294 return(status);
3295}
3296
3297/*
3298* qla2x00_restart_isp
3299* restarts the ISP after a reset
3300*
3301* Input:
3302* ha = adapter block pointer.
3303*
3304* Returns:
3305* 0 = success
3306*/
3307static int
3308qla2x00_restart_isp(scsi_qla_host_t *ha)
3309{
3310 uint8_t status = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003311 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 unsigned long flags = 0;
3313 uint32_t wait_time;
3314
3315 /* If firmware needs to be loaded */
3316 if (qla2x00_isp_firmware(ha)) {
3317 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003318 if (!(status = ha->isp_ops->chip_diag(ha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3320 status = qla2x00_setup_chip(ha);
3321 goto done;
3322 }
3323
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 spin_lock_irqsave(&ha->hardware_lock, flags);
3325
Andrew Vasquez8fef6962007-08-12 18:22:53 -07003326 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
3327 !IS_QLA25XX(ha)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003328 /*
3329 * Disable SRAM, Instruction RAM and GP RAM
3330 * parity.
3331 */
3332 WRT_REG_WORD(&reg->hccr,
3333 (HCCR_ENABLE_PARITY + 0x0));
3334 RD_REG_WORD(&reg->hccr);
3335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336
3337 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003338
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339 status = qla2x00_setup_chip(ha);
3340
3341 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003342
Andrew Vasquez8fef6962007-08-12 18:22:53 -07003343 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
3344 !IS_QLA25XX(ha)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003345 /* Enable proper parity */
3346 if (IS_QLA2300(ha))
3347 /* SRAM parity */
3348 WRT_REG_WORD(&reg->hccr,
3349 (HCCR_ENABLE_PARITY + 0x1));
3350 else
3351 /*
3352 * SRAM, Instruction RAM and GP RAM
3353 * parity.
3354 */
3355 WRT_REG_WORD(&reg->hccr,
3356 (HCCR_ENABLE_PARITY + 0x7));
3357 RD_REG_WORD(&reg->hccr);
3358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359
3360 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3361 }
3362 }
3363
3364 done:
3365 if (!status && !(status = qla2x00_init_rings(ha))) {
3366 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3367 if (!(status = qla2x00_fw_ready(ha))) {
3368 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003369 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07003370
3371 /* Issue a marker after FW becomes ready. */
3372 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3373
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374 ha->flags.online = 1;
3375 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3376 wait_time = 256;
3377 do {
3378 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3379 qla2x00_configure_loop(ha);
3380 wait_time--;
3381 } while (!atomic_read(&ha->loop_down_timer) &&
3382 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3383 wait_time &&
3384 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3385 }
3386
3387 /* if no cable then assume it's good */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003388 if ((ha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 status = 0;
3390
3391 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3392 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003393 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003394 }
3395 return (status);
3396}
3397
3398/*
3399* qla2x00_reset_adapter
3400* Reset adapter.
3401*
3402* Input:
3403* ha = adapter block pointer.
3404*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003405void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406qla2x00_reset_adapter(scsi_qla_host_t *ha)
3407{
3408 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003409 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410
3411 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003412 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 spin_lock_irqsave(&ha->hardware_lock, flags);
3415 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3416 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3417 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3418 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3419 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3420}
Andrew Vasquez01071092005-07-06 10:31:37 -07003421
3422void
3423qla24xx_reset_adapter(scsi_qla_host_t *ha)
3424{
3425 unsigned long flags = 0;
3426 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3427
3428 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003429 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003430
3431 spin_lock_irqsave(&ha->hardware_lock, flags);
3432 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3433 RD_REG_DWORD(&reg->hccr);
3434 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3435 RD_REG_DWORD(&reg->hccr);
3436 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3437}
3438
David Miller4e08df32007-04-16 12:37:43 -07003439/* On sparc systems, obtain port and node WWN from firmware
3440 * properties.
3441 */
3442static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3443{
3444#ifdef CONFIG_SPARC
3445 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003446 struct device_node *dp = pci_device_to_OF_node(pdev);
3447 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003448 int len;
3449
3450 val = of_get_property(dp, "port-wwn", &len);
3451 if (val && len >= WWN_SIZE)
3452 memcpy(nv->port_name, val, WWN_SIZE);
3453
3454 val = of_get_property(dp, "node-wwn", &len);
3455 if (val && len >= WWN_SIZE)
3456 memcpy(nv->node_name, val, WWN_SIZE);
3457#endif
3458}
3459
Andrew Vasquez01071092005-07-06 10:31:37 -07003460int
3461qla24xx_nvram_config(scsi_qla_host_t *ha)
3462{
David Miller4e08df32007-04-16 12:37:43 -07003463 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07003464 struct init_cb_24xx *icb;
3465 struct nvram_24xx *nv;
3466 uint32_t *dptr;
3467 uint8_t *dptr1, *dptr2;
3468 uint32_t chksum;
3469 uint16_t cnt;
3470
David Miller4e08df32007-04-16 12:37:43 -07003471 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07003472 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003473 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07003474
3475 /* Determine NVRAM starting address. */
3476 ha->nvram_size = sizeof(struct nvram_24xx);
3477 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003478 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3479 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3480 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003481 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003482 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3483 }
Andrew Vasquez01071092005-07-06 10:31:37 -07003484
Seokmann Ju281afe12007-07-26 13:43:34 -07003485 /* Get VPD data into cache */
3486 ha->vpd = ha->nvram + VPD_OFFSET;
3487 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd,
3488 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3489
3490 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07003491 dptr = (uint32_t *)nv;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003492 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07003493 ha->nvram_size);
3494 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3495 chksum += le32_to_cpu(*dptr++);
3496
3497 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003498 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07003499
3500 /* Bad NVRAM data, set defaults parameters. */
3501 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3502 || nv->id[3] != ' ' ||
3503 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3504 /* Reset NVRAM data. */
3505 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3506 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3507 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003508 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3509 "invalid -- WWPN) defaults.\n");
3510
3511 /*
3512 * Set default initialization control block.
3513 */
3514 memset(nv, 0, ha->nvram_size);
3515 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3516 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3517 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3518 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3519 nv->exchange_count = __constant_cpu_to_le16(0);
3520 nv->hard_address = __constant_cpu_to_le16(124);
3521 nv->port_name[0] = 0x21;
3522 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3523 nv->port_name[2] = 0x00;
3524 nv->port_name[3] = 0xe0;
3525 nv->port_name[4] = 0x8b;
3526 nv->port_name[5] = 0x1c;
3527 nv->port_name[6] = 0x55;
3528 nv->port_name[7] = 0x86;
3529 nv->node_name[0] = 0x20;
3530 nv->node_name[1] = 0x00;
3531 nv->node_name[2] = 0x00;
3532 nv->node_name[3] = 0xe0;
3533 nv->node_name[4] = 0x8b;
3534 nv->node_name[5] = 0x1c;
3535 nv->node_name[6] = 0x55;
3536 nv->node_name[7] = 0x86;
3537 qla24xx_nvram_wwn_from_ofw(ha, nv);
3538 nv->login_retry_count = __constant_cpu_to_le16(8);
3539 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3540 nv->login_timeout = __constant_cpu_to_le16(0);
3541 nv->firmware_options_1 =
3542 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3543 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3544 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3545 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3546 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3547 nv->efi_parameters = __constant_cpu_to_le32(0);
3548 nv->reset_delay = 5;
3549 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3550 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3551 nv->link_down_timeout = __constant_cpu_to_le16(30);
3552
3553 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07003554 }
3555
3556 /* Reset Initialization control block */
3557 memset(icb, 0, sizeof(struct init_cb_24xx));
3558
3559 /* Copy 1st segment. */
3560 dptr1 = (uint8_t *)icb;
3561 dptr2 = (uint8_t *)&nv->version;
3562 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3563 while (cnt--)
3564 *dptr1++ = *dptr2++;
3565
3566 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003567 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07003568
3569 /* Copy 2nd segment. */
3570 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3571 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3572 cnt = (uint8_t *)&icb->reserved_3 -
3573 (uint8_t *)&icb->interrupt_delay_timer;
3574 while (cnt--)
3575 *dptr1++ = *dptr2++;
3576
3577 /*
3578 * Setup driver NVRAM options.
3579 */
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003580 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3581 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07003582
Andrew Vasquez5341e862006-05-17 15:09:16 -07003583 /* Use alternate WWN? */
3584 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3585 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3586 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3587 }
3588
Andrew Vasquez01071092005-07-06 10:31:37 -07003589 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003590 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003591 /*
3592 * Firmware will apply the following mask if the nodename was
3593 * not provided.
3594 */
3595 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3596 icb->node_name[0] &= 0xF0;
3597 }
3598
3599 /* Set host adapter parameters. */
3600 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003601 ha->flags.enable_lip_reset = 0;
3602 ha->flags.enable_lip_full_login =
3603 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3604 ha->flags.enable_target_reset =
3605 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003606 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003607 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003608
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003609 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3610 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07003611
3612 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3613 sizeof(ha->fw_seriallink_options24));
3614
3615 /* save HBA serial number */
3616 ha->serial0 = icb->port_name[5];
3617 ha->serial1 = icb->port_name[6];
3618 ha->serial2 = icb->port_name[7];
3619 ha->node_name = icb->node_name;
3620 ha->port_name = icb->port_name;
3621
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003622 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3623
Andrew Vasquez01071092005-07-06 10:31:37 -07003624 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3625
3626 /* Set minimum login_timeout to 4 seconds. */
3627 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3628 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3629 if (le16_to_cpu(nv->login_timeout) < 4)
3630 nv->login_timeout = __constant_cpu_to_le16(4);
3631 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3632 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3633
3634 /* Set minimum RATOV to 200 tenths of a second. */
3635 ha->r_a_tov = 200;
3636
3637 ha->loop_reset_delay = nv->reset_delay;
3638
3639 /* Link Down Timeout = 0:
3640 *
3641 * When Port Down timer expires we will start returning
3642 * I/O's to OS with "DID_NO_CONNECT".
3643 *
3644 * Link Down Timeout != 0:
3645 *
3646 * The driver waits for the link to come up after link down
3647 * before returning I/Os to OS with "DID_NO_CONNECT".
3648 */
3649 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3650 ha->loop_down_abort_time =
3651 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3652 } else {
3653 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3654 ha->loop_down_abort_time =
3655 (LOOP_DOWN_TIME - ha->link_down_timeout);
3656 }
3657
3658 /* Need enough time to try and get the port back. */
3659 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3660 if (qlport_down_retry)
3661 ha->port_down_retry_count = qlport_down_retry;
3662
3663 /* Set login_retry_count */
3664 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3665 if (ha->port_down_retry_count ==
3666 le16_to_cpu(nv->port_down_retry_count) &&
3667 ha->port_down_retry_count > 3)
3668 ha->login_retry_count = ha->port_down_retry_count;
3669 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3670 ha->login_retry_count = ha->port_down_retry_count;
3671 if (ql2xloginretrycount)
3672 ha->login_retry_count = ql2xloginretrycount;
3673
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003674 /* Enable ZIO. */
3675 if (!ha->flags.init_done) {
3676 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3677 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3678 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3679 le16_to_cpu(icb->interrupt_delay_timer): 2;
3680 }
3681 icb->firmware_options_2 &= __constant_cpu_to_le32(
3682 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3683 ha->flags.process_response_queue = 0;
3684 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003685 ha->zio_mode = QLA_ZIO_MODE_6;
3686
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003687 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3688 "(%d us).\n", ha->host_no, ha->zio_mode,
3689 ha->zio_timer * 100));
3690 qla_printk(KERN_INFO, ha,
3691 "ZIO mode %d enabled; timer delay (%d us).\n",
3692 ha->zio_mode, ha->zio_timer * 100);
3693
3694 icb->firmware_options_2 |= cpu_to_le32(
3695 (uint32_t)ha->zio_mode);
3696 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3697 ha->flags.process_response_queue = 1;
3698 }
3699
David Miller4e08df32007-04-16 12:37:43 -07003700 if (rval) {
3701 DEBUG2_3(printk(KERN_WARNING
3702 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3703 }
3704 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07003705}
3706
Adrian Bunk413975a2006-06-30 02:33:06 -07003707static int
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003708qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3709{
3710 int rval;
3711 int segments, fragment;
3712 uint32_t faddr;
3713 uint32_t *dcode, dlen;
3714 uint32_t risc_addr;
3715 uint32_t risc_size;
3716 uint32_t i;
3717
3718 rval = QLA_SUCCESS;
3719
3720 segments = FA_RISC_CODE_SEGMENTS;
3721 faddr = FA_RISC_CODE_ADDR;
3722 dcode = (uint32_t *)ha->request_ring;
3723 *srisc_addr = 0;
3724
3725 /* Validate firmware image by checking version. */
3726 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3727 for (i = 0; i < 4; i++)
3728 dcode[i] = be32_to_cpu(dcode[i]);
3729 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3730 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3731 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3732 dcode[3] == 0)) {
3733 qla_printk(KERN_WARNING, ha,
3734 "Unable to verify integrity of flash firmware image!\n");
3735 qla_printk(KERN_WARNING, ha,
3736 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3737 dcode[1], dcode[2], dcode[3]);
3738
3739 return QLA_FUNCTION_FAILED;
3740 }
3741
3742 while (segments && rval == QLA_SUCCESS) {
3743 /* Read segment's load information. */
3744 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3745
3746 risc_addr = be32_to_cpu(dcode[2]);
3747 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3748 risc_size = be32_to_cpu(dcode[3]);
3749
3750 fragment = 0;
3751 while (risc_size > 0 && rval == QLA_SUCCESS) {
3752 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3753 if (dlen > risc_size)
3754 dlen = risc_size;
3755
3756 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3757 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3758 ha->host_no, risc_addr, dlen, faddr));
3759
3760 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3761 for (i = 0; i < dlen; i++)
3762 dcode[i] = swab32(dcode[i]);
3763
3764 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3765 dlen);
3766 if (rval) {
3767 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3768 "segment %d of firmware\n", ha->host_no,
3769 fragment));
3770 qla_printk(KERN_WARNING, ha,
3771 "[ERROR] Failed to load segment %d of "
3772 "firmware\n", fragment);
3773 break;
3774 }
3775
3776 faddr += dlen;
3777 risc_addr += dlen;
3778 risc_size -= dlen;
3779 fragment++;
3780 }
3781
3782 /* Next segment. */
3783 segments--;
3784 }
3785
3786 return rval;
3787}
3788
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003789#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3790
Andrew Vasquez01071092005-07-06 10:31:37 -07003791int
Andrew Vasquez54333832005-11-09 15:49:04 -08003792qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3793{
3794 int rval;
3795 int i, fragment;
3796 uint16_t *wcode, *fwcode;
3797 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3798 struct fw_blob *blob;
3799
3800 /* Load firmware blob. */
3801 blob = qla2x00_request_firmware(ha);
3802 if (!blob) {
3803 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003804 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3805 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003806 return QLA_FUNCTION_FAILED;
3807 }
3808
3809 rval = QLA_SUCCESS;
3810
3811 wcode = (uint16_t *)ha->request_ring;
3812 *srisc_addr = 0;
3813 fwcode = (uint16_t *)blob->fw->data;
3814 fwclen = 0;
3815
3816 /* Validate firmware image by checking version. */
3817 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3818 qla_printk(KERN_WARNING, ha,
3819 "Unable to verify integrity of firmware image (%Zd)!\n",
3820 blob->fw->size);
3821 goto fail_fw_integrity;
3822 }
3823 for (i = 0; i < 4; i++)
3824 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3825 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3826 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3827 wcode[2] == 0 && wcode[3] == 0)) {
3828 qla_printk(KERN_WARNING, ha,
3829 "Unable to verify integrity of firmware image!\n");
3830 qla_printk(KERN_WARNING, ha,
3831 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3832 wcode[1], wcode[2], wcode[3]);
3833 goto fail_fw_integrity;
3834 }
3835
3836 seg = blob->segs;
3837 while (*seg && rval == QLA_SUCCESS) {
3838 risc_addr = *seg;
3839 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3840 risc_size = be16_to_cpu(fwcode[3]);
3841
3842 /* Validate firmware image size. */
3843 fwclen += risc_size * sizeof(uint16_t);
3844 if (blob->fw->size < fwclen) {
3845 qla_printk(KERN_WARNING, ha,
3846 "Unable to verify integrity of firmware image "
3847 "(%Zd)!\n", blob->fw->size);
3848 goto fail_fw_integrity;
3849 }
3850
3851 fragment = 0;
3852 while (risc_size > 0 && rval == QLA_SUCCESS) {
3853 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3854 if (wlen > risc_size)
3855 wlen = risc_size;
3856
3857 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3858 "addr %x, number of words 0x%x.\n", ha->host_no,
3859 risc_addr, wlen));
3860
3861 for (i = 0; i < wlen; i++)
3862 wcode[i] = swab16(fwcode[i]);
3863
3864 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3865 wlen);
3866 if (rval) {
3867 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3868 "segment %d of firmware\n", ha->host_no,
3869 fragment));
3870 qla_printk(KERN_WARNING, ha,
3871 "[ERROR] Failed to load segment %d of "
3872 "firmware\n", fragment);
3873 break;
3874 }
3875
3876 fwcode += wlen;
3877 risc_addr += wlen;
3878 risc_size -= wlen;
3879 fragment++;
3880 }
3881
3882 /* Next segment. */
3883 seg++;
3884 }
3885 return rval;
3886
3887fail_fw_integrity:
3888 return QLA_FUNCTION_FAILED;
3889}
3890
3891int
3892qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
Andrew Vasquez01071092005-07-06 10:31:37 -07003893{
3894 int rval;
3895 int segments, fragment;
3896 uint32_t *dcode, dlen;
3897 uint32_t risc_addr;
3898 uint32_t risc_size;
3899 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08003900 struct fw_blob *blob;
Andrew Vasquez01071092005-07-06 10:31:37 -07003901 uint32_t *fwcode, fwclen;
3902
Andrew Vasquez54333832005-11-09 15:49:04 -08003903 /* Load firmware blob. */
3904 blob = qla2x00_request_firmware(ha);
3905 if (!blob) {
3906 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003907 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3908 "from: " QLA_FW_URL ".\n");
3909
3910 /* Try to load RISC code from flash. */
3911 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3912 "outdated) firmware from flash.\n");
3913 return qla24xx_load_risc_flash(ha, srisc_addr);
Andrew Vasquez01071092005-07-06 10:31:37 -07003914 }
3915
3916 rval = QLA_SUCCESS;
3917
3918 segments = FA_RISC_CODE_SEGMENTS;
3919 dcode = (uint32_t *)ha->request_ring;
3920 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08003921 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez01071092005-07-06 10:31:37 -07003922 fwclen = 0;
3923
3924 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08003925 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003926 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003927 "Unable to verify integrity of firmware image (%Zd)!\n",
3928 blob->fw->size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003929 goto fail_fw_integrity;
3930 }
3931 for (i = 0; i < 4; i++)
3932 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3933 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3934 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3935 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3936 dcode[3] == 0)) {
3937 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003938 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez01071092005-07-06 10:31:37 -07003939 qla_printk(KERN_WARNING, ha,
3940 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3941 dcode[1], dcode[2], dcode[3]);
3942 goto fail_fw_integrity;
3943 }
3944
3945 while (segments && rval == QLA_SUCCESS) {
3946 risc_addr = be32_to_cpu(fwcode[2]);
3947 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3948 risc_size = be32_to_cpu(fwcode[3]);
3949
3950 /* Validate firmware image size. */
3951 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08003952 if (blob->fw->size < fwclen) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003953 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003954 "Unable to verify integrity of firmware image "
3955 "(%Zd)!\n", blob->fw->size);
3956
Andrew Vasquez01071092005-07-06 10:31:37 -07003957 goto fail_fw_integrity;
3958 }
3959
3960 fragment = 0;
3961 while (risc_size > 0 && rval == QLA_SUCCESS) {
3962 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3963 if (dlen > risc_size)
3964 dlen = risc_size;
3965
3966 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3967 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3968 risc_addr, dlen));
3969
3970 for (i = 0; i < dlen; i++)
3971 dcode[i] = swab32(fwcode[i]);
3972
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08003973 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3974 dlen);
Andrew Vasquez01071092005-07-06 10:31:37 -07003975 if (rval) {
3976 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3977 "segment %d of firmware\n", ha->host_no,
3978 fragment));
3979 qla_printk(KERN_WARNING, ha,
3980 "[ERROR] Failed to load segment %d of "
3981 "firmware\n", fragment);
3982 break;
3983 }
3984
3985 fwcode += dlen;
3986 risc_addr += dlen;
3987 risc_size -= dlen;
3988 fragment++;
3989 }
3990
3991 /* Next segment. */
3992 segments--;
3993 }
Andrew Vasquez01071092005-07-06 10:31:37 -07003994 return rval;
3995
3996fail_fw_integrity:
Andrew Vasquez01071092005-07-06 10:31:37 -07003997 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07003998}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07003999
4000void
4001qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
4002{
4003 int ret, retries;
4004
Andrew Vasqueze4289242007-07-19 15:05:56 -07004005 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004006 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004007 if (!ha->fw_major_version)
4008 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004009
4010 ret = qla2x00_stop_firmware(ha);
4011 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
4012 qla2x00_reset_chip(ha);
4013 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
4014 continue;
4015 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4016 continue;
4017 qla_printk(KERN_INFO, ha,
4018 "Attempting retry of stop-firmware command...\n");
4019 ret = qla2x00_stop_firmware(ha);
4020 }
4021}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004022
4023int
4024qla24xx_configure_vhba(scsi_qla_host_t *ha)
4025{
4026 int rval = QLA_SUCCESS;
4027 uint16_t mb[MAILBOX_REGISTER_COUNT];
4028
4029 if (!ha->parent)
4030 return -EINVAL;
4031
4032 rval = qla2x00_fw_ready(ha);
4033 if (rval == QLA_SUCCESS) {
4034 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4035 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
4036 }
4037
4038 ha->flags.management_server_logged_in = 0;
4039
4040 /* Login to SNS first */
4041 qla24xx_login_fabric(ha, NPH_SNS, 0xff, 0xff, 0xfc,
4042 mb, BIT_1);
4043 if (mb[0] != MBS_COMMAND_COMPLETE) {
4044 DEBUG15(qla_printk(KERN_INFO, ha,
4045 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4046 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4047 mb[0], mb[1], mb[2], mb[6], mb[7]));
4048 return (QLA_FUNCTION_FAILED);
4049 }
4050
4051 atomic_set(&ha->loop_down_timer, 0);
4052 atomic_set(&ha->loop_state, LOOP_UP);
4053 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4054 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4055 rval = qla2x00_loop_resync(ha);
4056
4057 return rval;
4058}