blob: 03444d6e4d2684117ae21215e0712ffb52482239 [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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-07-06 10:31:37 -0700253 unsigned long flags = 0;
254 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-07-06 10:31:37 -0700507
Andrew Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-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 Vasquez0107109e2005-07-06 10:31:37 -0700710
Andrew Vasquez88c26662005-07-08 17:59:26 -0700711 /* Perform RISC reset. */
712 qla24xx_reset_risc(ha);
Andrew Vasquez0107109e2005-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 Vasquez0107109e2005-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
769 rval = qla2x00_trace_control(ha, TC_ENABLE, eft_dma,
770 EFT_NUM_BUFFERS);
771 if (rval) {
772 qla_printk(KERN_WARNING, ha, "Unable to initialize "
773 "EFT (%d).\n", rval);
774 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, eft,
775 eft_dma);
776 goto cont_alloc;
777 }
778
779 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
780 EFT_SIZE / 1024);
781
782 eft_size = EFT_SIZE;
783 memset(eft, 0, eft_size);
784 ha->eft_dma = eft_dma;
785 ha->eft = eft;
786 }
787cont_alloc:
788 req_q_size = ha->request_q_length * sizeof(request_t);
789 rsp_q_size = ha->response_q_length * sizeof(response_t);
790
791 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
792 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
793 eft_size;
794
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700795 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700796 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700797 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700798 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700799
800 if (ha->eft) {
801 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
802 ha->eft_dma);
803 ha->eft = NULL;
804 ha->eft_dma = 0;
805 }
806 return;
807 }
808
809 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
810 dump_size / 1024);
811
812 ha->fw_dump_len = dump_size;
813 ha->fw_dump->signature[0] = 'Q';
814 ha->fw_dump->signature[1] = 'L';
815 ha->fw_dump->signature[2] = 'G';
816 ha->fw_dump->signature[3] = 'C';
817 ha->fw_dump->version = __constant_htonl(1);
818
819 ha->fw_dump->fixed_size = htonl(fixed_size);
820 ha->fw_dump->mem_size = htonl(mem_size);
821 ha->fw_dump->req_q_size = htonl(req_q_size);
822 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
823
824 ha->fw_dump->eft_size = htonl(eft_size);
825 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
826 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
827
828 ha->fw_dump->header_size =
829 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700830}
831
832/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
834 * @ha: HA context
835 *
836 * Returns 0 on success.
837 */
838static void
839qla2x00_resize_request_q(scsi_qla_host_t *ha)
840{
841 int rval;
842 uint16_t fw_iocb_cnt = 0;
843 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
844 dma_addr_t request_dma;
845 request_t *request_ring;
846
847 /* Valid only on recent ISPs. */
848 if (IS_QLA2100(ha) || IS_QLA2200(ha))
849 return;
850
851 /* Retrieve IOCB counts available to the firmware. */
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700852 rval = qla2x00_get_resource_cnts(ha, NULL, NULL, NULL, &fw_iocb_cnt,
853 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854 if (rval)
855 return;
856 /* No point in continuing if current settings are sufficient. */
857 if (fw_iocb_cnt < 1024)
858 return;
859 if (ha->request_q_length >= request_q_length)
860 return;
861
862 /* Attempt to claim larger area for request queue. */
863 request_ring = dma_alloc_coherent(&ha->pdev->dev,
864 (request_q_length + 1) * sizeof(request_t), &request_dma,
865 GFP_KERNEL);
866 if (request_ring == NULL)
867 return;
868
869 /* Resize successful, report extensions. */
870 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
871 (ha->fw_memory_size + 1) / 1024);
872 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
873 "(%d -> %d)...\n", ha->request_q_length, request_q_length);
874
875 /* Clear old allocations. */
876 dma_free_coherent(&ha->pdev->dev,
877 (ha->request_q_length + 1) * sizeof(request_t), ha->request_ring,
878 ha->request_dma);
879
880 /* Begin using larger queue. */
881 ha->request_q_length = request_q_length;
882 ha->request_ring = request_ring;
883 ha->request_dma = request_dma;
884}
885
886/**
887 * qla2x00_setup_chip() - Load and start RISC firmware.
888 * @ha: HA context
889 *
890 * Returns 0 on success.
891 */
892static int
893qla2x00_setup_chip(scsi_qla_host_t *ha)
894{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700895 int rval;
896 uint32_t srisc_address = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897
898 /* Load firmware sequences */
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700899 rval = ha->isp_ops->load_risc(ha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700900 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
902 "code.\n", ha->host_no));
903
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700904 rval = qla2x00_verify_checksum(ha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700905 if (rval == QLA_SUCCESS) {
906 /* Start firmware execution. */
907 DEBUG(printk("scsi(%ld): Checksum OK, start "
908 "firmware.\n", ha->host_no));
909
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700910 rval = qla2x00_execute_fw(ha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700911 /* Retrieve firmware information. */
912 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
913 qla2x00_get_fw_version(ha,
914 &ha->fw_major_version,
915 &ha->fw_minor_version,
916 &ha->fw_subminor_version,
917 &ha->fw_attributes, &ha->fw_memory_size);
918 qla2x00_resize_request_q(ha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700919 ha->flags.npiv_supported = 0;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700920 if ((IS_QLA24XX(ha) || IS_QLA25XX(ha)) &&
921 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700922 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700923 if ((!ha->max_npiv_vports) ||
924 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800925 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700926 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800927 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700928 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700929
930 if (ql2xallocfwdump)
931 qla2x00_alloc_fw_dump(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932 }
933 } else {
934 DEBUG2(printk(KERN_INFO
935 "scsi(%ld): ISP Firmware failed checksum.\n",
936 ha->host_no));
937 }
938 }
939
940 if (rval) {
941 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
942 ha->host_no));
943 }
944
945 return (rval);
946}
947
948/**
949 * qla2x00_init_response_q_entries() - Initializes response queue entries.
950 * @ha: HA context
951 *
952 * Beginning of request ring has initialization control block already built
953 * by nvram config routine.
954 *
955 * Returns 0 on success.
956 */
957static void
958qla2x00_init_response_q_entries(scsi_qla_host_t *ha)
959{
960 uint16_t cnt;
961 response_t *pkt;
962
963 pkt = ha->response_ring_ptr;
964 for (cnt = 0; cnt < ha->response_q_length; cnt++) {
965 pkt->signature = RESPONSE_PROCESSED;
966 pkt++;
967 }
968
969}
970
971/**
972 * qla2x00_update_fw_options() - Read and process firmware options.
973 * @ha: HA context
974 *
975 * Returns 0 on success.
976 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700977void
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978qla2x00_update_fw_options(scsi_qla_host_t *ha)
979{
980 uint16_t swing, emphasis, tx_sens, rx_sens;
981
982 memset(ha->fw_options, 0, sizeof(ha->fw_options));
983 qla2x00_get_fw_options(ha, ha->fw_options);
984
985 if (IS_QLA2100(ha) || IS_QLA2200(ha))
986 return;
987
988 /* Serial Link options. */
989 DEBUG3(printk("scsi(%ld): Serial link options:\n",
990 ha->host_no));
991 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
992 sizeof(ha->fw_seriallink_options)));
993
994 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
995 if (ha->fw_seriallink_options[3] & BIT_2) {
996 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
997
998 /* 1G settings */
999 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1000 emphasis = (ha->fw_seriallink_options[2] &
1001 (BIT_4 | BIT_3)) >> 3;
1002 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001003 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001004 rx_sens = (ha->fw_seriallink_options[0] &
1005 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1006 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1007 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1008 if (rx_sens == 0x0)
1009 rx_sens = 0x3;
1010 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1011 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1012 ha->fw_options[10] |= BIT_5 |
1013 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1014 (tx_sens & (BIT_1 | BIT_0));
1015
1016 /* 2G settings */
1017 swing = (ha->fw_seriallink_options[2] &
1018 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1019 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1020 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001021 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 rx_sens = (ha->fw_seriallink_options[1] &
1023 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1024 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1025 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1026 if (rx_sens == 0x0)
1027 rx_sens = 0x3;
1028 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1029 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1030 ha->fw_options[11] |= BIT_5 |
1031 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1032 (tx_sens & (BIT_1 | BIT_0));
1033 }
1034
1035 /* FCP2 options. */
1036 /* Return command IOCBs without waiting for an ABTS to complete. */
1037 ha->fw_options[3] |= BIT_13;
1038
1039 /* LED scheme. */
1040 if (ha->flags.enable_led_scheme)
1041 ha->fw_options[2] |= BIT_12;
1042
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001043 /* Detect ISP6312. */
1044 if (IS_QLA6312(ha))
1045 ha->fw_options[2] |= BIT_13;
1046
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 /* Update firmware options. */
1048 qla2x00_set_fw_options(ha, ha->fw_options);
1049}
1050
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001051void
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001052qla24xx_update_fw_options(scsi_qla_host_t *ha)
1053{
1054 int rval;
1055
1056 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001057 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001058 return;
1059
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001060 rval = qla2x00_set_serdes_params(ha,
1061 le16_to_cpu(ha->fw_seriallink_options24[1]),
1062 le16_to_cpu(ha->fw_seriallink_options24[2]),
1063 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001064 if (rval != QLA_SUCCESS) {
1065 qla_printk(KERN_WARNING, ha,
1066 "Unable to update Serial Link options (%x).\n", rval);
1067 }
1068}
1069
1070void
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001071qla2x00_config_rings(struct scsi_qla_host *ha)
1072{
Andrew Vasquez3d716442005-07-06 10:30:26 -07001073 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001074
1075 /* Setup ring parameters in initialization control block. */
1076 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1077 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
1078 ha->init_cb->request_q_length = cpu_to_le16(ha->request_q_length);
1079 ha->init_cb->response_q_length = cpu_to_le16(ha->response_q_length);
1080 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1081 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1082 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1083 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1084
1085 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1086 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1087 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1088 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1089 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1090}
1091
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001092void
1093qla24xx_config_rings(struct scsi_qla_host *ha)
1094{
1095 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1096 struct init_cb_24xx *icb;
1097
1098 /* Setup ring parameters in initialization control block. */
1099 icb = (struct init_cb_24xx *)ha->init_cb;
1100 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1101 icb->response_q_inpointer = __constant_cpu_to_le16(0);
1102 icb->request_q_length = cpu_to_le16(ha->request_q_length);
1103 icb->response_q_length = cpu_to_le16(ha->response_q_length);
1104 icb->request_q_address[0] = cpu_to_le32(LSD(ha->request_dma));
1105 icb->request_q_address[1] = cpu_to_le32(MSD(ha->request_dma));
1106 icb->response_q_address[0] = cpu_to_le32(LSD(ha->response_dma));
1107 icb->response_q_address[1] = cpu_to_le32(MSD(ha->response_dma));
1108
1109 WRT_REG_DWORD(&reg->req_q_in, 0);
1110 WRT_REG_DWORD(&reg->req_q_out, 0);
1111 WRT_REG_DWORD(&reg->rsp_q_in, 0);
1112 WRT_REG_DWORD(&reg->rsp_q_out, 0);
1113 RD_REG_DWORD(&reg->rsp_q_out);
1114}
1115
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116/**
1117 * qla2x00_init_rings() - Initializes firmware.
1118 * @ha: HA context
1119 *
1120 * Beginning of request ring has initialization control block already built
1121 * by nvram config routine.
1122 *
1123 * Returns 0 on success.
1124 */
1125static int
1126qla2x00_init_rings(scsi_qla_host_t *ha)
1127{
1128 int rval;
1129 unsigned long flags = 0;
1130 int cnt;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001131 struct mid_init_cb_24xx *mid_init_cb =
1132 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133
1134 spin_lock_irqsave(&ha->hardware_lock, flags);
1135
1136 /* Clear outstanding commands array. */
1137 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1138 ha->outstanding_cmds[cnt] = NULL;
1139
1140 ha->current_outstanding_cmd = 0;
1141
1142 /* Clear RSCN queue. */
1143 ha->rscn_in_ptr = 0;
1144 ha->rscn_out_ptr = 0;
1145
1146 /* Initialize firmware. */
1147 ha->request_ring_ptr = ha->request_ring;
1148 ha->req_ring_index = 0;
1149 ha->req_q_cnt = ha->request_q_length;
1150 ha->response_ring_ptr = ha->response_ring;
1151 ha->rsp_ring_index = 0;
1152
Linus Torvalds1da177e2005-04-16 15:20:36 -07001153 /* Initialize response queue entries */
1154 qla2x00_init_response_q_entries(ha);
1155
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001156 ha->isp_ops->config_rings(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001157
1158 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1159
1160 /* Update any ISP specific firmware options before initialization. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001161 ha->isp_ops->update_fw_options(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001162
1163 DEBUG(printk("scsi(%ld): Issue init firmware.\n", ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001164
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001165 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1166 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001167
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001168 rval = qla2x00_init_firmware(ha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 if (rval) {
1170 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
1171 ha->host_no));
1172 } else {
1173 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
1174 ha->host_no));
1175 }
1176
1177 return (rval);
1178}
1179
1180/**
1181 * qla2x00_fw_ready() - Waits for firmware ready.
1182 * @ha: HA context
1183 *
1184 * Returns 0 on success.
1185 */
1186static int
1187qla2x00_fw_ready(scsi_qla_host_t *ha)
1188{
1189 int rval;
1190 unsigned long wtime, mtime;
1191 uint16_t min_wait; /* Minimum wait time if loop is down */
1192 uint16_t wait_time; /* Wait time if loop is coming ready */
1193 uint16_t fw_state;
1194
1195 rval = QLA_SUCCESS;
1196
1197 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001198 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
1200 /*
1201 * Firmware should take at most one RATOV to login, plus 5 seconds for
1202 * our own processing.
1203 */
1204 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1205 wait_time = min_wait;
1206 }
1207
1208 /* Min wait time if loop down */
1209 mtime = jiffies + (min_wait * HZ);
1210
1211 /* wait time before firmware ready */
1212 wtime = jiffies + (wait_time * HZ);
1213
1214 /* Wait for ISP to finish LIP */
1215 if (!ha->flags.init_done)
1216 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1217
1218 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
1219 ha->host_no));
1220
1221 do {
1222 rval = qla2x00_get_firmware_state(ha, &fw_state);
1223 if (rval == QLA_SUCCESS) {
1224 if (fw_state < FSTATE_LOSS_OF_SYNC) {
1225 ha->device_flags &= ~DFLG_NO_CABLE;
1226 }
1227 if (fw_state == FSTATE_READY) {
1228 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
1229 ha->host_no));
1230
1231 qla2x00_get_retry_cnt(ha, &ha->retry_count,
1232 &ha->login_timeout, &ha->r_a_tov);
1233
1234 rval = QLA_SUCCESS;
1235 break;
1236 }
1237
1238 rval = QLA_FUNCTION_FAILED;
1239
1240 if (atomic_read(&ha->loop_down_timer) &&
Andrew Vasquez7d7abc72006-06-23 16:11:17 -07001241 fw_state != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001242 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001243 * other than Wait for Login.
1244 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245 if (time_after_eq(jiffies, mtime)) {
1246 qla_printk(KERN_INFO, ha,
1247 "Cable is unplugged...\n");
1248
1249 ha->device_flags |= DFLG_NO_CABLE;
1250 break;
1251 }
1252 }
1253 } else {
1254 /* Mailbox cmd failed. Timeout on min_wait. */
1255 if (time_after_eq(jiffies, mtime))
1256 break;
1257 }
1258
1259 if (time_after_eq(jiffies, wtime))
1260 break;
1261
1262 /* Delay for a while */
1263 msleep(500);
1264
1265 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1266 ha->host_no, fw_state, jiffies));
1267 } while (1);
1268
1269 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
1270 ha->host_no, fw_state, jiffies));
1271
1272 if (rval) {
1273 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
1274 ha->host_no));
1275 }
1276
1277 return (rval);
1278}
1279
1280/*
1281* qla2x00_configure_hba
1282* Setup adapter context.
1283*
1284* Input:
1285* ha = adapter state pointer.
1286*
1287* Returns:
1288* 0 = success
1289*
1290* Context:
1291* Kernel context.
1292*/
1293static int
1294qla2x00_configure_hba(scsi_qla_host_t *ha)
1295{
1296 int rval;
1297 uint16_t loop_id;
1298 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001299 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300 uint8_t al_pa;
1301 uint8_t area;
1302 uint8_t domain;
1303 char connect_type[22];
1304
1305 /* Get host addresses. */
1306 rval = qla2x00_get_adapter_id(ha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001307 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308 if (rval != QLA_SUCCESS) {
Andrew Vasquez23443b12005-12-06 10:57:06 -08001309 if (LOOP_TRANSITION(ha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001310 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1311 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
1312 __func__, ha->host_no));
1313 } else {
1314 qla_printk(KERN_WARNING, ha,
1315 "ERROR -- Unable to get host loop ID.\n");
1316 set_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
1317 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 return (rval);
1319 }
1320
1321 if (topo == 4) {
1322 qla_printk(KERN_INFO, ha,
1323 "Cannot get topology - retrying.\n");
1324 return (QLA_FUNCTION_FAILED);
1325 }
1326
1327 ha->loop_id = loop_id;
1328
1329 /* initialize */
1330 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1331 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001332 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001333
1334 switch (topo) {
1335 case 0:
1336 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
1337 ha->host_no));
1338 ha->current_topology = ISP_CFG_NL;
1339 strcpy(connect_type, "(Loop)");
1340 break;
1341
1342 case 1:
1343 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
1344 ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001345 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 ha->current_topology = ISP_CFG_FL;
1347 strcpy(connect_type, "(FL_Port)");
1348 break;
1349
1350 case 2:
1351 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
1352 ha->host_no));
1353 ha->operating_mode = P2P;
1354 ha->current_topology = ISP_CFG_N;
1355 strcpy(connect_type, "(N_Port-to-N_Port)");
1356 break;
1357
1358 case 3:
1359 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
1360 ha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001361 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001362 ha->operating_mode = P2P;
1363 ha->current_topology = ISP_CFG_F;
1364 strcpy(connect_type, "(F_Port)");
1365 break;
1366
1367 default:
1368 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1369 "Using NL.\n",
1370 ha->host_no, topo));
1371 ha->current_topology = ISP_CFG_NL;
1372 strcpy(connect_type, "(Loop)");
1373 break;
1374 }
1375
1376 /* Save Host port and loop ID. */
1377 /* byte order - Big Endian */
1378 ha->d_id.b.domain = domain;
1379 ha->d_id.b.area = area;
1380 ha->d_id.b.al_pa = al_pa;
1381
1382 if (!ha->flags.init_done)
1383 qla_printk(KERN_INFO, ha,
1384 "Topology - %s, Host Loop address 0x%x\n",
1385 connect_type, ha->loop_id);
1386
1387 if (rval) {
1388 DEBUG2_3(printk("scsi(%ld): FAILED.\n", ha->host_no));
1389 } else {
1390 DEBUG3(printk("scsi(%ld): exiting normally.\n", ha->host_no));
1391 }
1392
1393 return(rval);
1394}
1395
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001396static inline void
1397qla2x00_set_model_info(scsi_qla_host_t *ha, uint8_t *model, size_t len, char *def)
1398{
1399 char *st, *en;
1400 uint16_t index;
1401
1402 if (memcmp(model, BINZERO, len) != 0) {
1403 strncpy(ha->model_number, model, len);
1404 st = en = ha->model_number;
1405 en += len - 1;
1406 while (en > st) {
1407 if (*en != 0x20 && *en != 0x00)
1408 break;
1409 *en-- = '\0';
1410 }
1411
1412 index = (ha->pdev->subsystem_device & 0xff);
1413 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1414 index < QLA_MODEL_NAMES)
1415 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1416 } else {
1417 index = (ha->pdev->subsystem_device & 0xff);
1418 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1419 index < QLA_MODEL_NAMES) {
1420 strcpy(ha->model_number,
1421 qla2x00_model_name[index * 2]);
1422 ha->model_desc = qla2x00_model_name[index * 2 + 1];
1423 } else {
1424 strcpy(ha->model_number, def);
1425 }
1426 }
1427}
1428
David Miller4e08df32007-04-16 12:37:43 -07001429/* On sparc systems, obtain port and node WWN from firmware
1430 * properties.
1431 */
1432static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, nvram_t *nv)
1433{
1434#ifdef CONFIG_SPARC
1435 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001436 struct device_node *dp = pci_device_to_OF_node(pdev);
1437 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001438 int len;
1439
1440 val = of_get_property(dp, "port-wwn", &len);
1441 if (val && len >= WWN_SIZE)
1442 memcpy(nv->port_name, val, WWN_SIZE);
1443
1444 val = of_get_property(dp, "node-wwn", &len);
1445 if (val && len >= WWN_SIZE)
1446 memcpy(nv->node_name, val, WWN_SIZE);
1447#endif
1448}
1449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450/*
1451* NVRAM configuration for ISP 2xxx
1452*
1453* Input:
1454* ha = adapter block pointer.
1455*
1456* Output:
1457* initialization control block in response_ring
1458* host adapters parameters in host adapter block
1459*
1460* Returns:
1461* 0 = success.
1462*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001463int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464qla2x00_nvram_config(scsi_qla_host_t *ha)
1465{
David Miller4e08df32007-04-16 12:37:43 -07001466 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001467 uint8_t chksum = 0;
1468 uint16_t cnt;
1469 uint8_t *dptr1, *dptr2;
1470 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001471 nvram_t *nv = ha->nvram;
1472 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001473 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474
David Miller4e08df32007-04-16 12:37:43 -07001475 rval = QLA_SUCCESS;
1476
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001478 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479 ha->nvram_base = 0;
1480 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1481 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1482 ha->nvram_base = 0x80;
1483
1484 /* Get NVRAM data and calculate checksum. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001485 ha->isp_ops->read_nvram(ha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001486 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1487 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001488
1489 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001490 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491
1492 /* Bad NVRAM data, set defaults parameters. */
1493 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1494 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1495 /* Reset NVRAM data. */
1496 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1497 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1498 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001499 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1500 "invalid -- WWPN) defaults.\n");
1501
1502 /*
1503 * Set default initialization control block.
1504 */
1505 memset(nv, 0, ha->nvram_size);
1506 nv->parameter_block_version = ICB_VERSION;
1507
1508 if (IS_QLA23XX(ha)) {
1509 nv->firmware_options[0] = BIT_2 | BIT_1;
1510 nv->firmware_options[1] = BIT_7 | BIT_5;
1511 nv->add_firmware_options[0] = BIT_5;
1512 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1513 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1514 nv->special_options[1] = BIT_7;
1515 } else if (IS_QLA2200(ha)) {
1516 nv->firmware_options[0] = BIT_2 | BIT_1;
1517 nv->firmware_options[1] = BIT_7 | BIT_5;
1518 nv->add_firmware_options[0] = BIT_5;
1519 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1520 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1521 } else if (IS_QLA2100(ha)) {
1522 nv->firmware_options[0] = BIT_3 | BIT_1;
1523 nv->firmware_options[1] = BIT_5;
1524 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1525 }
1526
1527 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1528 nv->execution_throttle = __constant_cpu_to_le16(16);
1529 nv->retry_count = 8;
1530 nv->retry_delay = 1;
1531
1532 nv->port_name[0] = 33;
1533 nv->port_name[3] = 224;
1534 nv->port_name[4] = 139;
1535
1536 qla2xxx_nvram_wwn_from_ofw(ha, nv);
1537
1538 nv->login_timeout = 4;
1539
1540 /*
1541 * Set default host adapter parameters
1542 */
1543 nv->host_p[1] = BIT_2;
1544 nv->reset_delay = 5;
1545 nv->port_down_retry_count = 8;
1546 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1547 nv->link_down_timeout = 60;
1548
1549 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 }
1551
1552#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1553 /*
1554 * The SN2 does not provide BIOS emulation which means you can't change
1555 * potentially bogus BIOS settings. Force the use of default settings
1556 * for link rate and frame size. Hope that the rest of the settings
1557 * are valid.
1558 */
1559 if (ia64_platform_is("sn2")) {
1560 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1561 if (IS_QLA23XX(ha))
1562 nv->special_options[1] = BIT_7;
1563 }
1564#endif
1565
1566 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001567 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 /*
1570 * Setup driver NVRAM options.
1571 */
1572 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1573 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1574 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1575 nv->firmware_options[1] &= ~BIT_4;
1576
1577 if (IS_QLA23XX(ha)) {
1578 nv->firmware_options[0] |= BIT_2;
1579 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001580 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581
1582 if (IS_QLA2300(ha)) {
1583 if (ha->fb_rev == FPM_2310) {
1584 strcpy(ha->model_number, "QLA2310");
1585 } else {
1586 strcpy(ha->model_number, "QLA2300");
1587 }
1588 } else {
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001589 qla2x00_set_model_info(ha, nv->model_number,
1590 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591 }
1592 } else if (IS_QLA2200(ha)) {
1593 nv->firmware_options[0] |= BIT_2;
1594 /*
1595 * 'Point-to-point preferred, else loop' is not a safe
1596 * connection mode setting.
1597 */
1598 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1599 (BIT_5 | BIT_4)) {
1600 /* Force 'loop preferred, else point-to-point'. */
1601 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1602 nv->add_firmware_options[0] |= BIT_5;
1603 }
1604 strcpy(ha->model_number, "QLA22xx");
1605 } else /*if (IS_QLA2100(ha))*/ {
1606 strcpy(ha->model_number, "QLA2100");
1607 }
1608
1609 /*
1610 * Copy over NVRAM RISC parameter block to initialization control block.
1611 */
1612 dptr1 = (uint8_t *)icb;
1613 dptr2 = (uint8_t *)&nv->parameter_block_version;
1614 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1615 while (cnt--)
1616 *dptr1++ = *dptr2++;
1617
1618 /* Copy 2nd half. */
1619 dptr1 = (uint8_t *)icb->add_firmware_options;
1620 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1621 while (cnt--)
1622 *dptr1++ = *dptr2++;
1623
Andrew Vasquez5341e862006-05-17 15:09:16 -07001624 /* Use alternate WWN? */
1625 if (nv->host_p[1] & BIT_7) {
1626 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1627 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1628 }
1629
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 /* Prepare nodename */
1631 if ((icb->firmware_options[1] & BIT_6) == 0) {
1632 /*
1633 * Firmware will apply the following mask if the nodename was
1634 * not provided.
1635 */
1636 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1637 icb->node_name[0] &= 0xF0;
1638 }
1639
1640 /*
1641 * Set host adapter parameters.
1642 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001643 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001644 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001645 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1646 /* Always load RISC code on non ISP2[12]00 chips. */
1647 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1648 ha->flags.disable_risc_code_load = 0;
1649 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1650 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1651 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001652 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001653 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654
1655 ha->operating_mode =
1656 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1657
1658 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1659 sizeof(ha->fw_seriallink_options));
1660
1661 /* save HBA serial number */
1662 ha->serial0 = icb->port_name[5];
1663 ha->serial1 = icb->port_name[6];
1664 ha->serial2 = icb->port_name[7];
Andrew Vasquez3d716442005-07-06 10:30:26 -07001665 ha->node_name = icb->node_name;
1666 ha->port_name = icb->port_name;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667
1668 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1669
1670 ha->retry_count = nv->retry_count;
1671
1672 /* Set minimum login_timeout to 4 seconds. */
1673 if (nv->login_timeout < ql2xlogintimeout)
1674 nv->login_timeout = ql2xlogintimeout;
1675 if (nv->login_timeout < 4)
1676 nv->login_timeout = 4;
1677 ha->login_timeout = nv->login_timeout;
1678 icb->login_timeout = nv->login_timeout;
1679
1680 /* Set minimum RATOV to 200 tenths of a second. */
1681 ha->r_a_tov = 200;
1682
Linus Torvalds1da177e2005-04-16 15:20:36 -07001683 ha->loop_reset_delay = nv->reset_delay;
1684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 /* Link Down Timeout = 0:
1686 *
1687 * When Port Down timer expires we will start returning
1688 * I/O's to OS with "DID_NO_CONNECT".
1689 *
1690 * Link Down Timeout != 0:
1691 *
1692 * The driver waits for the link to come up after link down
1693 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001694 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001695 if (nv->link_down_timeout == 0) {
1696 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001697 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 } else {
1699 ha->link_down_timeout = nv->link_down_timeout;
1700 ha->loop_down_abort_time =
1701 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001702 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704 /*
1705 * Need enough time to try and get the port back.
1706 */
1707 ha->port_down_retry_count = nv->port_down_retry_count;
1708 if (qlport_down_retry)
1709 ha->port_down_retry_count = qlport_down_retry;
1710 /* Set login_retry_count */
1711 ha->login_retry_count = nv->retry_count;
1712 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1713 ha->port_down_retry_count > 3)
1714 ha->login_retry_count = ha->port_down_retry_count;
1715 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1716 ha->login_retry_count = ha->port_down_retry_count;
1717 if (ql2xloginretrycount)
1718 ha->login_retry_count = ql2xloginretrycount;
1719
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 icb->lun_enables = __constant_cpu_to_le16(0);
1721 icb->command_resource_count = 0;
1722 icb->immediate_notify_resource_count = 0;
1723 icb->timeout = __constant_cpu_to_le16(0);
1724
1725 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1726 /* Enable RIO */
1727 icb->firmware_options[0] &= ~BIT_3;
1728 icb->add_firmware_options[0] &=
1729 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1730 icb->add_firmware_options[0] |= BIT_2;
1731 icb->response_accumulation_timer = 3;
1732 icb->interrupt_delay_timer = 5;
1733
1734 ha->flags.process_response_queue = 1;
1735 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001736 /* Enable ZIO. */
1737 if (!ha->flags.init_done) {
1738 ha->zio_mode = icb->add_firmware_options[0] &
1739 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1740 ha->zio_timer = icb->interrupt_delay_timer ?
1741 icb->interrupt_delay_timer: 2;
1742 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743 icb->add_firmware_options[0] &=
1744 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001745 ha->flags.process_response_queue = 0;
1746 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001747 ha->zio_mode = QLA_ZIO_MODE_6;
1748
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001749 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
1750 "delay (%d us).\n", ha->host_no, ha->zio_mode,
1751 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001753 "ZIO mode %d enabled; timer delay (%d us).\n",
1754 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001755
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001756 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1757 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 ha->flags.process_response_queue = 1;
1759 }
1760 }
1761
David Miller4e08df32007-04-16 12:37:43 -07001762 if (rval) {
1763 DEBUG2_3(printk(KERN_WARNING
1764 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
1765 }
1766 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001767}
1768
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001769static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001770qla2x00_rport_del(void *data)
1771{
1772 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001773 struct fc_rport *rport;
1774 unsigned long flags;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001775
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001776 spin_lock_irqsave(&fcport->rport_lock, flags);
1777 rport = fcport->drport;
1778 fcport->drport = NULL;
1779 spin_unlock_irqrestore(&fcport->rport_lock, flags);
1780 if (rport)
1781 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001782}
1783
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784/**
1785 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1786 * @ha: HA context
1787 * @flags: allocation flags
1788 *
1789 * Returns a pointer to the allocated fcport, or NULL, if none available.
1790 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001791static fc_port_t *
Al Viroc53033f2005-10-21 03:22:08 -04001792qla2x00_alloc_fcport(scsi_qla_host_t *ha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793{
1794 fc_port_t *fcport;
1795
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001796 fcport = kzalloc(sizeof(fc_port_t), flags);
1797 if (!fcport)
1798 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799
1800 /* Setup fcport template structure. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801 fcport->ha = ha;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001802 fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803 fcport->port_type = FCT_UNKNOWN;
1804 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1806 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001807 fcport->supported_classes = FC_COS_UNSPECIFIED;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001808 spin_lock_init(&fcport->rport_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001809
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001810 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811}
1812
1813/*
1814 * qla2x00_configure_loop
1815 * Updates Fibre Channel Device Database with what is actually on loop.
1816 *
1817 * Input:
1818 * ha = adapter block pointer.
1819 *
1820 * Returns:
1821 * 0 = success.
1822 * 1 = error.
1823 * 2 = database was full and device was not configured.
1824 */
1825static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001826qla2x00_configure_loop(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827{
1828 int rval;
1829 unsigned long flags, save_flags;
1830
1831 rval = QLA_SUCCESS;
1832
1833 /* Get Initiator ID */
1834 if (test_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags)) {
1835 rval = qla2x00_configure_hba(ha);
1836 if (rval != QLA_SUCCESS) {
1837 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
1838 ha->host_no));
1839 return (rval);
1840 }
1841 }
1842
1843 save_flags = flags = ha->dpc_flags;
1844 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
1845 ha->host_no, flags));
1846
1847 /*
1848 * If we have both an RSCN and PORT UPDATE pending then handle them
1849 * both at the same time.
1850 */
1851 clear_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1852 clear_bit(RSCN_UPDATE, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853
1854 /* Determine what we need to do */
1855 if (ha->current_topology == ISP_CFG_FL &&
1856 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1857
1858 ha->flags.rscn_queue_overflow = 1;
1859 set_bit(RSCN_UPDATE, &flags);
1860
1861 } else if (ha->current_topology == ISP_CFG_F &&
1862 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1863
1864 ha->flags.rscn_queue_overflow = 1;
1865 set_bit(RSCN_UPDATE, &flags);
1866 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1867
Andrew Vasquez21333b42006-05-17 15:09:56 -07001868 } else if (ha->current_topology == ISP_CFG_N) {
1869 clear_bit(RSCN_UPDATE, &flags);
1870
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 } else if (!ha->flags.online ||
1872 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
1873
1874 ha->flags.rscn_queue_overflow = 1;
1875 set_bit(RSCN_UPDATE, &flags);
1876 set_bit(LOCAL_LOOP_UPDATE, &flags);
1877 }
1878
1879 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
1880 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1881 rval = QLA_FUNCTION_FAILED;
1882 } else {
1883 rval = qla2x00_configure_local_loop(ha);
1884 }
1885 }
1886
1887 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Andrew Vasquez23443b12005-12-06 10:57:06 -08001888 if (LOOP_TRANSITION(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889 rval = QLA_FUNCTION_FAILED;
1890 } else {
1891 rval = qla2x00_configure_fabric(ha);
1892 }
1893 }
1894
1895 if (rval == QLA_SUCCESS) {
1896 if (atomic_read(&ha->loop_down_timer) ||
1897 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1898 rval = QLA_FUNCTION_FAILED;
1899 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001900 atomic_set(&ha->loop_state, LOOP_READY);
1901
1902 DEBUG(printk("scsi(%ld): LOOP READY\n", ha->host_no));
1903 }
1904 }
1905
1906 if (rval) {
1907 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
1908 __func__, ha->host_no));
1909 } else {
1910 DEBUG3(printk("%s: exiting normally\n", __func__));
1911 }
1912
1913 /* Restore state if a resync event occured during processing */
1914 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)) {
1915 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
1916 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
1917 if (test_bit(RSCN_UPDATE, &save_flags))
1918 set_bit(RSCN_UPDATE, &ha->dpc_flags);
1919 }
1920
1921 return (rval);
1922}
1923
1924
1925
1926/*
1927 * qla2x00_configure_local_loop
1928 * Updates Fibre Channel Device Database with local loop devices.
1929 *
1930 * Input:
1931 * ha = adapter block pointer.
1932 *
1933 * Returns:
1934 * 0 = success.
1935 */
1936static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001937qla2x00_configure_local_loop(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938{
1939 int rval, rval2;
1940 int found_devs;
1941 int found;
1942 fc_port_t *fcport, *new_fcport;
1943
1944 uint16_t index;
1945 uint16_t entries;
1946 char *id_iter;
1947 uint16_t loop_id;
1948 uint8_t domain, area, al_pa;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001949 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950
1951 found_devs = 0;
1952 new_fcport = NULL;
1953 entries = MAX_FIBRE_DEVICES;
1954
1955 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", ha->host_no));
1956 DEBUG3(qla2x00_get_fcal_position_map(ha, NULL));
1957
1958 /* Get list of logged in devices. */
1959 memset(ha->gid_list, 0, GID_LIST_SIZE);
1960 rval = qla2x00_get_id_list(ha, ha->gid_list, ha->gid_list_dma,
1961 &entries);
1962 if (rval != QLA_SUCCESS)
1963 goto cleanup_allocation;
1964
1965 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
1966 ha->host_no, entries));
1967 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
1968 entries * sizeof(struct gid_list_info)));
1969
1970 /* Allocate temporary fcport for any new fcports discovered. */
1971 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
1972 if (new_fcport == NULL) {
1973 rval = QLA_MEMORY_ALLOC_FAILED;
1974 goto cleanup_allocation;
1975 }
1976 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
1977
1978 /*
1979 * Mark local devices that were present with FCF_DEVICE_LOST for now.
1980 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001981 list_for_each_entry(fcport, &pha->fcports, list) {
1982 if (fcport->vp_idx != ha->vp_idx)
1983 continue;
1984
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 if (atomic_read(&fcport->state) == FCS_ONLINE &&
1986 fcport->port_type != FCT_BROADCAST &&
1987 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
1988
1989 DEBUG(printk("scsi(%ld): Marking port lost, "
1990 "loop_id=0x%04x\n",
1991 ha->host_no, fcport->loop_id));
1992
1993 atomic_set(&fcport->state, FCS_DEVICE_LOST);
1994 fcport->flags &= ~FCF_FARP_DONE;
1995 }
1996 }
1997
1998 /* Add devices to port list. */
1999 id_iter = (char *)ha->gid_list;
2000 for (index = 0; index < entries; index++) {
2001 domain = ((struct gid_list_info *)id_iter)->domain;
2002 area = ((struct gid_list_info *)id_iter)->area;
2003 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002004 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 loop_id = (uint16_t)
2006 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002007 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 loop_id = le16_to_cpu(
2009 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002010 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012 /* Bypass reserved domain fields. */
2013 if ((domain & 0xf0) == 0xf0)
2014 continue;
2015
2016 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002017 if (area && domain &&
2018 (area != ha->d_id.b.area || domain != ha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 continue;
2020
2021 /* Bypass invalid local loop ID. */
2022 if (loop_id > LAST_LOCAL_LOOP_ID)
2023 continue;
2024
2025 /* Fill in member data. */
2026 new_fcport->d_id.b.domain = domain;
2027 new_fcport->d_id.b.area = area;
2028 new_fcport->d_id.b.al_pa = al_pa;
2029 new_fcport->loop_id = loop_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002030 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 rval2 = qla2x00_get_port_database(ha, new_fcport, 0);
2032 if (rval2 != QLA_SUCCESS) {
2033 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2034 "information -- get_port_database=%x, "
2035 "loop_id=0x%04x\n",
2036 ha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002037 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
2038 ha->host_no));
2039 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 continue;
2041 }
2042
2043 /* Check for matching device in port list. */
2044 found = 0;
2045 fcport = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002046 list_for_each_entry(fcport, &pha->fcports, list) {
2047 if (fcport->vp_idx != ha->vp_idx)
2048 continue;
2049
Linus Torvalds1da177e2005-04-16 15:20:36 -07002050 if (memcmp(new_fcport->port_name, fcport->port_name,
2051 WWN_SIZE))
2052 continue;
2053
2054 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2055 FCF_PERSISTENT_BOUND);
2056 fcport->loop_id = new_fcport->loop_id;
2057 fcport->port_type = new_fcport->port_type;
2058 fcport->d_id.b24 = new_fcport->d_id.b24;
2059 memcpy(fcport->node_name, new_fcport->node_name,
2060 WWN_SIZE);
2061
2062 found++;
2063 break;
2064 }
2065
2066 if (!found) {
2067 /* New device, add to fcports list. */
2068 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002069 if (ha->parent) {
2070 new_fcport->ha = ha;
2071 new_fcport->vp_idx = ha->vp_idx;
2072 list_add_tail(&new_fcport->vp_fcport,
2073 &ha->vp_fcports);
2074 }
2075 list_add_tail(&new_fcport->list, &pha->fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 /* Allocate a new replacement fcport. */
2078 fcport = new_fcport;
2079 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2080 if (new_fcport == NULL) {
2081 rval = QLA_MEMORY_ALLOC_FAILED;
2082 goto cleanup_allocation;
2083 }
2084 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2085 }
2086
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002087 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002088 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002089
Linus Torvalds1da177e2005-04-16 15:20:36 -07002090 qla2x00_update_fcport(ha, fcport);
2091
2092 found_devs++;
2093 }
2094
2095cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002096 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097
2098 if (rval != QLA_SUCCESS) {
2099 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
2100 "rval=%x\n", ha->host_no, rval));
2101 }
2102
2103 if (found_devs) {
2104 ha->device_flags |= DFLG_LOCAL_DEVICES;
2105 ha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
2106 }
2107
2108 return (rval);
2109}
2110
2111static void
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002112qla2x00_probe_for_all_luns(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113{
2114 fc_port_t *fcport;
2115
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002116 qla2x00_mark_all_devices_lost(ha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 list_for_each_entry(fcport, &ha->fcports, list) {
2118 if (fcport->port_type != FCT_TARGET)
2119 continue;
2120
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002121 qla2x00_update_fcport(ha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 }
2123}
2124
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002125static void
2126qla2x00_iidma_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2127{
2128#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002129 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002130 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002131 uint16_t mb[6];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002132
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002133 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002134 return;
2135
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002136 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2137 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002138 return;
2139
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002140 rval = qla2x00_set_idma_speed(ha, fcport->loop_id, fcport->fp_speed,
2141 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002142 if (rval != QLA_SUCCESS) {
2143 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2144 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
2145 ha->host_no, fcport->port_name[0], fcport->port_name[1],
2146 fcport->port_name[2], fcport->port_name[3],
2147 fcport->port_name[4], fcport->port_name[5],
2148 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002149 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002150 } else {
2151 DEBUG2(qla_printk(KERN_INFO, ha,
2152 "iIDMA adjusted to %s GB/s on "
2153 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002154 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002155 fcport->port_name[1], fcport->port_name[2],
2156 fcport->port_name[3], fcport->port_name[4],
2157 fcport->port_name[5], fcport->port_name[6],
2158 fcport->port_name[7]));
2159 }
2160}
2161
Adrian Bunk23be3312006-11-24 02:46:01 +01002162static void
8482e1182005-04-17 15:04:54 -05002163qla2x00_reg_remote_port(scsi_qla_host_t *ha, fc_port_t *fcport)
2164{
2165 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002166 struct fc_rport *rport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002167 unsigned long flags;
8482e1182005-04-17 15:04:54 -05002168
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002169 if (fcport->drport)
2170 qla2x00_rport_del(fcport);
2171 if (fcport->rport)
2172 return;
8482e1182005-04-17 15:04:54 -05002173
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002174 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2175 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002176 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2177 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2178 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002179 rport = fc_remote_port_add(ha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002180 if (!rport) {
2181 qla_printk(KERN_WARNING, ha,
2182 "Unable to allocate fc remote port!\n");
2183 return;
2184 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002185 spin_lock_irqsave(&fcport->rport_lock, flags);
2186 fcport->rport = rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002187 *((fc_port_t **)rport->dd_data) = fcport;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002188 spin_unlock_irqrestore(&fcport->rport_lock, flags);
2189
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002190 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002191
2192 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002193 if (fcport->port_type == FCT_INITIATOR)
2194 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2195 if (fcport->port_type == FCT_TARGET)
2196 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002197 fc_remote_port_rolechg(rport, rport_ids.roles);
bdf79622005-04-17 15:06:53 -05002198
Andrew Vasquezcc4731f2005-07-06 10:32:37 -07002199 if (rport->scsi_target_id != -1 &&
2200 rport->scsi_target_id < ha->host->max_id)
bdf79622005-04-17 15:06:53 -05002201 fcport->os_target_id = rport->scsi_target_id;
8482e1182005-04-17 15:04:54 -05002202}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203
2204/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002205 * qla2x00_update_fcport
2206 * Updates device on list.
2207 *
2208 * Input:
2209 * ha = adapter block pointer.
2210 * fcport = port structure pointer.
2211 *
2212 * Return:
2213 * 0 - Success
2214 * BIT_0 - error
2215 *
2216 * Context:
2217 * Kernel context.
2218 */
2219void
2220qla2x00_update_fcport(scsi_qla_host_t *ha, fc_port_t *fcport)
2221{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002222 scsi_qla_host_t *pha = to_qla_parent(ha);
2223
Adrian Bunk23be3312006-11-24 02:46:01 +01002224 fcport->ha = ha;
2225 fcport->login_retry = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002226 fcport->port_login_retry_count = pha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002227 PORT_RETRY_TIME;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002228 atomic_set(&fcport->port_down_timer, pha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002229 PORT_RETRY_TIME);
2230 fcport->flags &= ~FCF_LOGIN_NEEDED;
2231
2232 qla2x00_iidma_fcport(ha, fcport);
2233
2234 atomic_set(&fcport->state, FCS_ONLINE);
2235
2236 qla2x00_reg_remote_port(ha, fcport);
2237}
2238
2239/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 * qla2x00_configure_fabric
2241 * Setup SNS devices with loop ID's.
2242 *
2243 * Input:
2244 * ha = adapter block pointer.
2245 *
2246 * Returns:
2247 * 0 = success.
2248 * BIT_0 = error
2249 */
2250static int
2251qla2x00_configure_fabric(scsi_qla_host_t *ha)
2252{
2253 int rval, rval2;
2254 fc_port_t *fcport, *fcptemp;
2255 uint16_t next_loopid;
2256 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002257 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 LIST_HEAD(new_fcports);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002259 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002260
2261 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002262 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002263 loop_id = NPH_F_PORT;
2264 else
2265 loop_id = SNS_FL_PORT;
Andrew Vasquez90991c82006-10-02 12:00:46 -07002266 rval = qla2x00_get_port_name(ha, loop_id, ha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002267 if (rval != QLA_SUCCESS) {
2268 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
2269 "Port\n", ha->host_no));
2270
2271 ha->device_flags &= ~SWITCH_FOUND;
2272 return (QLA_SUCCESS);
2273 }
Andrew Vasquez90991c82006-10-02 12:00:46 -07002274 ha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 /* Mark devices that need re-synchronization. */
2277 rval2 = qla2x00_device_resync(ha);
2278 if (rval2 == QLA_RSCNS_HANDLED) {
2279 /* No point doing the scan, just continue. */
2280 return (QLA_SUCCESS);
2281 }
2282 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002283 /* FDMI support. */
2284 if (ql2xfdmienable &&
2285 test_and_clear_bit(REGISTER_FDMI_NEEDED, &ha->dpc_flags))
2286 qla2x00_fdmi_register(ha);
2287
Linus Torvalds1da177e2005-04-16 15:20:36 -07002288 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002289 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002290 loop_id = NPH_SNS;
2291 else
2292 loop_id = SIMPLE_NAME_SERVER;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002293 ha->isp_ops->fabric_login(ha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002294 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002295 if (mb[0] != MBS_COMMAND_COMPLETE) {
2296 DEBUG2(qla_printk(KERN_INFO, ha,
2297 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002298 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002299 mb[0], mb[1], mb[2], mb[6], mb[7]));
2300 return (QLA_SUCCESS);
2301 }
2302
2303 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags)) {
2304 if (qla2x00_rft_id(ha)) {
2305 /* EMPTY */
2306 DEBUG2(printk("scsi(%ld): Register FC-4 "
2307 "TYPE failed.\n", ha->host_no));
2308 }
2309 if (qla2x00_rff_id(ha)) {
2310 /* EMPTY */
2311 DEBUG2(printk("scsi(%ld): Register FC-4 "
2312 "Features failed.\n", ha->host_no));
2313 }
2314 if (qla2x00_rnn_id(ha)) {
2315 /* EMPTY */
2316 DEBUG2(printk("scsi(%ld): Register Node Name "
2317 "failed.\n", ha->host_no));
2318 } else if (qla2x00_rsnn_nn(ha)) {
2319 /* EMPTY */
2320 DEBUG2(printk("scsi(%ld): Register Symbolic "
2321 "Node Name failed.\n", ha->host_no));
2322 }
2323 }
2324
2325 rval = qla2x00_find_all_fabric_devs(ha, &new_fcports);
2326 if (rval != QLA_SUCCESS)
2327 break;
2328
2329 /*
2330 * Logout all previous fabric devices marked lost, except
2331 * tape devices.
2332 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002333 list_for_each_entry(fcport, &pha->fcports, list) {
2334 if (fcport->vp_idx !=ha->vp_idx)
2335 continue;
2336
Linus Torvalds1da177e2005-04-16 15:20:36 -07002337 if (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2338 break;
2339
2340 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2341 continue;
2342
2343 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2344 qla2x00_mark_device_lost(ha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002345 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002346 if (fcport->loop_id != FC_NO_LOOP_ID &&
2347 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2348 fcport->port_type != FCT_INITIATOR &&
2349 fcport->port_type != FCT_BROADCAST) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002350 ha->isp_ops->fabric_logout(ha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002351 fcport->loop_id,
2352 fcport->d_id.b.domain,
2353 fcport->d_id.b.area,
2354 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355 fcport->loop_id = FC_NO_LOOP_ID;
2356 }
2357 }
2358 }
2359
2360 /* Starting free loop ID. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002361 next_loopid = pha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
2363 /*
2364 * Scan through our port list and login entries that need to be
2365 * logged in.
2366 */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002367 list_for_each_entry(fcport, &pha->fcports, list) {
2368 if (fcport->vp_idx != ha->vp_idx)
2369 continue;
2370
Linus Torvalds1da177e2005-04-16 15:20:36 -07002371 if (atomic_read(&ha->loop_down_timer) ||
2372 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2373 break;
2374
2375 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2376 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2377 continue;
2378
2379 if (fcport->loop_id == FC_NO_LOOP_ID) {
2380 fcport->loop_id = next_loopid;
2381 rval = qla2x00_find_new_loop_id(ha, fcport);
2382 if (rval != QLA_SUCCESS) {
2383 /* Ran out of IDs to use */
2384 break;
2385 }
2386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 /* Login and update database */
2388 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
2389 }
2390
2391 /* Exit if out of loop IDs. */
2392 if (rval != QLA_SUCCESS) {
2393 break;
2394 }
2395
2396 /*
2397 * Login and add the new devices to our port list.
2398 */
2399 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2400 if (atomic_read(&ha->loop_down_timer) ||
2401 test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags))
2402 break;
2403
2404 /* Find a new loop ID to use. */
2405 fcport->loop_id = next_loopid;
2406 rval = qla2x00_find_new_loop_id(ha, fcport);
2407 if (rval != QLA_SUCCESS) {
2408 /* Ran out of IDs to use */
2409 break;
2410 }
2411
bdf79622005-04-17 15:06:53 -05002412 /* Login and update database */
2413 qla2x00_fabric_dev_login(ha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002414
2415 if (ha->parent) {
2416 fcport->ha = ha;
2417 fcport->vp_idx = ha->vp_idx;
2418 list_add_tail(&fcport->vp_fcport,
2419 &ha->vp_fcports);
2420 list_move_tail(&fcport->list,
2421 &ha->parent->fcports);
2422 } else
2423 list_move_tail(&fcport->list, &ha->fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 }
2425 } while (0);
2426
2427 /* Free all new device structures not processed. */
2428 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2429 list_del(&fcport->list);
2430 kfree(fcport);
2431 }
2432
2433 if (rval) {
2434 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
2435 "rval=%d\n", ha->host_no, rval));
2436 }
2437
2438 return (rval);
2439}
2440
2441
2442/*
2443 * qla2x00_find_all_fabric_devs
2444 *
2445 * Input:
2446 * ha = adapter block pointer.
2447 * dev = database device entry pointer.
2448 *
2449 * Returns:
2450 * 0 = success.
2451 *
2452 * Context:
2453 * Kernel context.
2454 */
2455static int
2456qla2x00_find_all_fabric_devs(scsi_qla_host_t *ha, struct list_head *new_fcports)
2457{
2458 int rval;
2459 uint16_t loop_id;
2460 fc_port_t *fcport, *new_fcport, *fcptemp;
2461 int found;
2462
2463 sw_info_t *swl;
2464 int swl_idx;
2465 int first_dev, last_dev;
2466 port_id_t wrap, nxt_d_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002467 int vp_index;
2468 int empty_vp_index;
2469 int found_vp;
2470 scsi_qla_host_t *vha;
2471 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
2473 rval = QLA_SUCCESS;
2474
2475 /* Try GID_PT to get device list, else GAN. */
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002476 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_ATOMIC);
2477 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 /*EMPTY*/
2479 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
2480 "on GA_NXT\n", ha->host_no));
2481 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 if (qla2x00_gid_pt(ha, swl) != QLA_SUCCESS) {
2483 kfree(swl);
2484 swl = NULL;
2485 } else if (qla2x00_gpn_id(ha, swl) != QLA_SUCCESS) {
2486 kfree(swl);
2487 swl = NULL;
2488 } else if (qla2x00_gnn_id(ha, swl) != QLA_SUCCESS) {
2489 kfree(swl);
2490 swl = NULL;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002491 } else if (qla2x00_gfpn_id(ha, swl) == QLA_SUCCESS) {
2492 qla2x00_gpsc(ha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 }
2494 }
2495 swl_idx = 0;
2496
2497 /* Allocate temporary fcport for any new fcports discovered. */
2498 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2499 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002500 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002501 return (QLA_MEMORY_ALLOC_FAILED);
2502 }
2503 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002504 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 /* Set start port ID scan at adapter ID. */
2506 first_dev = 1;
2507 last_dev = 0;
2508
2509 /* Starting free loop ID. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002510 loop_id = pha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 for (; loop_id <= ha->last_loop_id; loop_id++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -07002512 if (qla2x00_is_reserved_id(ha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 continue;
2514
Andrew Vasquez23443b12005-12-06 10:57:06 -08002515 if (atomic_read(&ha->loop_down_timer) || LOOP_TRANSITION(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002516 break;
2517
2518 if (swl != NULL) {
2519 if (last_dev) {
2520 wrap.b24 = new_fcport->d_id.b24;
2521 } else {
2522 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2523 memcpy(new_fcport->node_name,
2524 swl[swl_idx].node_name, WWN_SIZE);
2525 memcpy(new_fcport->port_name,
2526 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002527 memcpy(new_fcport->fabric_port_name,
2528 swl[swl_idx].fabric_port_name, WWN_SIZE);
2529 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530
2531 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2532 last_dev = 1;
2533 }
2534 swl_idx++;
2535 }
2536 } else {
2537 /* Send GA_NXT to the switch */
2538 rval = qla2x00_ga_nxt(ha, new_fcport);
2539 if (rval != QLA_SUCCESS) {
2540 qla_printk(KERN_WARNING, ha,
2541 "SNS scan failed -- assuming zero-entry "
2542 "result...\n");
2543 list_for_each_entry_safe(fcport, fcptemp,
2544 new_fcports, list) {
2545 list_del(&fcport->list);
2546 kfree(fcport);
2547 }
2548 rval = QLA_SUCCESS;
2549 break;
2550 }
2551 }
2552
2553 /* If wrap on switch device list, exit. */
2554 if (first_dev) {
2555 wrap.b24 = new_fcport->d_id.b24;
2556 first_dev = 0;
2557 } else if (new_fcport->d_id.b24 == wrap.b24) {
2558 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
2559 ha->host_no, new_fcport->d_id.b.domain,
2560 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2561 break;
2562 }
2563
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002564 /* Bypass if same physical adapter. */
2565 if (new_fcport->d_id.b24 == pha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566 continue;
2567
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002568 /* Bypass virtual ports of the same host. */
2569 if (pha->num_vhosts) {
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002570 for_each_mapped_vp_idx(pha, vp_index) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002571 empty_vp_index = 1;
2572 found_vp = 0;
2573 list_for_each_entry(vha, &pha->vp_list,
2574 vp_list) {
2575 if (vp_index == vha->vp_idx) {
2576 empty_vp_index = 0;
2577 found_vp = 1;
2578 break;
2579 }
2580 }
2581
2582 if (empty_vp_index)
2583 continue;
2584
2585 if (found_vp &&
2586 new_fcport->d_id.b24 == vha->d_id.b24)
2587 break;
2588 }
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08002589
2590 if (vp_index <= pha->max_npiv_vports)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002591 continue;
2592 }
2593
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002594 /* Bypass if same domain and area of adapter. */
2595 if (((new_fcport->d_id.b24 & 0xffff00) ==
2596 (ha->d_id.b24 & 0xffff00)) && ha->current_topology ==
2597 ISP_CFG_FL)
2598 continue;
2599
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 /* Bypass reserved domain fields. */
2601 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2602 continue;
2603
2604 /* Locate matching device in database. */
2605 found = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002606 list_for_each_entry(fcport, &pha->fcports, list) {
2607 if (new_fcport->vp_idx != fcport->vp_idx)
2608 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 if (memcmp(new_fcport->port_name, fcport->port_name,
2610 WWN_SIZE))
2611 continue;
2612
2613 found++;
2614
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002615 /* Update port state. */
2616 memcpy(fcport->fabric_port_name,
2617 new_fcport->fabric_port_name, WWN_SIZE);
2618 fcport->fp_speed = new_fcport->fp_speed;
2619
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 /*
2621 * If address the same and state FCS_ONLINE, nothing
2622 * changed.
2623 */
2624 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2625 atomic_read(&fcport->state) == FCS_ONLINE) {
2626 break;
2627 }
2628
2629 /*
2630 * If device was not a fabric device before.
2631 */
2632 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2633 fcport->d_id.b24 = new_fcport->d_id.b24;
2634 fcport->loop_id = FC_NO_LOOP_ID;
2635 fcport->flags |= (FCF_FABRIC_DEVICE |
2636 FCF_LOGIN_NEEDED);
2637 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2638 break;
2639 }
2640
2641 /*
2642 * Port ID changed or device was marked to be updated;
2643 * Log it out if still logged in and mark it for
2644 * relogin later.
2645 */
2646 fcport->d_id.b24 = new_fcport->d_id.b24;
2647 fcport->flags |= FCF_LOGIN_NEEDED;
2648 if (fcport->loop_id != FC_NO_LOOP_ID &&
2649 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2650 fcport->port_type != FCT_INITIATOR &&
2651 fcport->port_type != FCT_BROADCAST) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002652 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002653 fcport->d_id.b.domain, fcport->d_id.b.area,
2654 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 fcport->loop_id = FC_NO_LOOP_ID;
2656 }
2657
2658 break;
2659 }
2660
2661 if (found)
2662 continue;
2663
2664 /* If device was not in our fcports list, then add it. */
2665 list_add_tail(&new_fcport->list, new_fcports);
2666
2667 /* Allocate a new replacement fcport. */
2668 nxt_d_id.b24 = new_fcport->d_id.b24;
2669 new_fcport = qla2x00_alloc_fcport(ha, GFP_KERNEL);
2670 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002671 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672 return (QLA_MEMORY_ALLOC_FAILED);
2673 }
2674 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2675 new_fcport->d_id.b24 = nxt_d_id.b24;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002676 new_fcport->vp_idx = ha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 }
2678
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002679 kfree(swl);
2680 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681
2682 if (!list_empty(new_fcports))
2683 ha->device_flags |= DFLG_FABRIC_DEVICES;
2684
2685 return (rval);
2686}
2687
2688/*
2689 * qla2x00_find_new_loop_id
2690 * Scan through our port list and find a new usable loop ID.
2691 *
2692 * Input:
2693 * ha: adapter state pointer.
2694 * dev: port structure pointer.
2695 *
2696 * Returns:
2697 * qla2x00 local function return status code.
2698 *
2699 * Context:
2700 * Kernel context.
2701 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002702static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07002703qla2x00_find_new_loop_id(scsi_qla_host_t *ha, fc_port_t *dev)
2704{
2705 int rval;
2706 int found;
2707 fc_port_t *fcport;
2708 uint16_t first_loop_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002709 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
2711 rval = QLA_SUCCESS;
2712
2713 /* Save starting loop ID. */
2714 first_loop_id = dev->loop_id;
2715
2716 for (;;) {
2717 /* Skip loop ID if already used by adapter. */
2718 if (dev->loop_id == ha->loop_id) {
2719 dev->loop_id++;
2720 }
2721
2722 /* Skip reserved loop IDs. */
Andrew Vasquez3d716442005-07-06 10:30:26 -07002723 while (qla2x00_is_reserved_id(ha, dev->loop_id)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002724 dev->loop_id++;
2725 }
2726
2727 /* Reset loop ID if passed the end. */
2728 if (dev->loop_id > ha->last_loop_id) {
2729 /* first loop ID. */
2730 dev->loop_id = ha->min_external_loopid;
2731 }
2732
2733 /* Check for loop ID being already in use. */
2734 found = 0;
2735 fcport = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002736 list_for_each_entry(fcport, &pha->fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 if (fcport->loop_id == dev->loop_id && fcport != dev) {
2738 /* ID possibly in use */
2739 found++;
2740 break;
2741 }
2742 }
2743
2744 /* If not in use then it is free to use. */
2745 if (!found) {
2746 break;
2747 }
2748
2749 /* ID in use. Try next value. */
2750 dev->loop_id++;
2751
2752 /* If wrap around. No free ID to use. */
2753 if (dev->loop_id == first_loop_id) {
2754 dev->loop_id = FC_NO_LOOP_ID;
2755 rval = QLA_FUNCTION_FAILED;
2756 break;
2757 }
2758 }
2759
2760 return (rval);
2761}
2762
2763/*
2764 * qla2x00_device_resync
2765 * Marks devices in the database that needs resynchronization.
2766 *
2767 * Input:
2768 * ha = adapter block pointer.
2769 *
2770 * Context:
2771 * Kernel context.
2772 */
2773static int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002774qla2x00_device_resync(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775{
2776 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 uint32_t mask;
2778 fc_port_t *fcport;
2779 uint32_t rscn_entry;
2780 uint8_t rscn_out_iter;
2781 uint8_t format;
2782 port_id_t d_id;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002783 scsi_qla_host_t *pha = to_qla_parent(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 rval = QLA_RSCNS_HANDLED;
2786
2787 while (ha->rscn_out_ptr != ha->rscn_in_ptr ||
2788 ha->flags.rscn_queue_overflow) {
2789
2790 rscn_entry = ha->rscn_queue[ha->rscn_out_ptr];
2791 format = MSB(MSW(rscn_entry));
2792 d_id.b.domain = LSB(MSW(rscn_entry));
2793 d_id.b.area = MSB(LSW(rscn_entry));
2794 d_id.b.al_pa = LSB(LSW(rscn_entry));
2795
2796 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2797 "[%02x/%02x%02x%02x].\n",
2798 ha->host_no, ha->rscn_out_ptr, format, d_id.b.domain,
2799 d_id.b.area, d_id.b.al_pa));
2800
2801 ha->rscn_out_ptr++;
2802 if (ha->rscn_out_ptr == MAX_RSCN_COUNT)
2803 ha->rscn_out_ptr = 0;
2804
2805 /* Skip duplicate entries. */
2806 for (rscn_out_iter = ha->rscn_out_ptr;
2807 !ha->flags.rscn_queue_overflow &&
2808 rscn_out_iter != ha->rscn_in_ptr;
2809 rscn_out_iter = (rscn_out_iter ==
2810 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2811
2812 if (rscn_entry != ha->rscn_queue[rscn_out_iter])
2813 break;
2814
2815 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
2816 "entry found at [%d].\n", ha->host_no,
2817 rscn_out_iter));
2818
2819 ha->rscn_out_ptr = rscn_out_iter;
2820 }
2821
2822 /* Queue overflow, set switch default case. */
2823 if (ha->flags.rscn_queue_overflow) {
2824 DEBUG(printk("scsi(%ld): device_resync: rscn "
2825 "overflow.\n", ha->host_no));
2826
2827 format = 3;
2828 ha->flags.rscn_queue_overflow = 0;
2829 }
2830
2831 switch (format) {
2832 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833 mask = 0xffffff;
2834 break;
2835 case 1:
2836 mask = 0xffff00;
2837 break;
2838 case 2:
2839 mask = 0xff0000;
2840 break;
2841 default:
2842 mask = 0x0;
2843 d_id.b24 = 0;
2844 ha->rscn_out_ptr = ha->rscn_in_ptr;
2845 break;
2846 }
2847
2848 rval = QLA_SUCCESS;
2849
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002850 list_for_each_entry(fcport, &pha->fcports, list) {
2851 if (fcport->vp_idx != ha->vp_idx)
2852 continue;
2853
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2855 (fcport->d_id.b24 & mask) != d_id.b24 ||
2856 fcport->port_type == FCT_BROADCAST)
2857 continue;
2858
2859 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2860 if (format != 3 ||
2861 fcport->port_type != FCT_INITIATOR) {
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002862 qla2x00_mark_device_lost(ha, fcport,
2863 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864 }
2865 }
2866 fcport->flags &= ~FCF_FARP_DONE;
2867 }
2868 }
2869 return (rval);
2870}
2871
2872/*
2873 * qla2x00_fabric_dev_login
2874 * Login fabric target device and update FC port database.
2875 *
2876 * Input:
2877 * ha: adapter state pointer.
2878 * fcport: port structure list pointer.
2879 * next_loopid: contains value of a new loop ID that can be used
2880 * by the next login attempt.
2881 *
2882 * Returns:
2883 * qla2x00 local function return status code.
2884 *
2885 * Context:
2886 * Kernel context.
2887 */
2888static int
2889qla2x00_fabric_dev_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2890 uint16_t *next_loopid)
2891{
2892 int rval;
2893 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002894 uint8_t opts;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
2896 rval = QLA_SUCCESS;
2897 retry = 0;
2898
2899 rval = qla2x00_fabric_login(ha, fcport, next_loopid);
2900 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002901 /* Send an ADISC to tape devices.*/
2902 opts = 0;
2903 if (fcport->flags & FCF_TAPE_PRESENT)
2904 opts |= BIT_1;
2905 rval = qla2x00_get_port_database(ha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 if (rval != QLA_SUCCESS) {
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002907 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002908 fcport->d_id.b.domain, fcport->d_id.b.area,
2909 fcport->d_id.b.al_pa);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002910 qla2x00_mark_device_lost(ha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 } else {
2912 qla2x00_update_fcport(ha, fcport);
2913 }
2914 }
2915
2916 return (rval);
2917}
2918
2919/*
2920 * qla2x00_fabric_login
2921 * Issue fabric login command.
2922 *
2923 * Input:
2924 * ha = adapter block pointer.
2925 * device = pointer to FC device type structure.
2926 *
2927 * Returns:
2928 * 0 - Login successfully
2929 * 1 - Login failed
2930 * 2 - Initiator device
2931 * 3 - Fatal error
2932 */
2933int
2934qla2x00_fabric_login(scsi_qla_host_t *ha, fc_port_t *fcport,
2935 uint16_t *next_loopid)
2936{
2937 int rval;
2938 int retry;
2939 uint16_t tmp_loopid;
2940 uint16_t mb[MAILBOX_REGISTER_COUNT];
2941
2942 retry = 0;
2943 tmp_loopid = 0;
2944
2945 for (;;) {
2946 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
2947 "for port %02x%02x%02x.\n",
2948 ha->host_no, fcport->loop_id, fcport->d_id.b.domain,
2949 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2950
2951 /* Login fcport on switch. */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002952 ha->isp_ops->fabric_login(ha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 fcport->d_id.b.domain, fcport->d_id.b.area,
2954 fcport->d_id.b.al_pa, mb, BIT_0);
2955 if (mb[0] == MBS_PORT_ID_USED) {
2956 /*
2957 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002958 * recommends the driver perform an implicit login with
2959 * the specified ID again. The ID we just used is save
2960 * here so we return with an ID that can be tried by
2961 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 */
2963 retry++;
2964 tmp_loopid = fcport->loop_id;
2965 fcport->loop_id = mb[1];
2966
2967 DEBUG(printk("Fabric Login: port in use - next "
2968 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
2969 fcport->loop_id, fcport->d_id.b.domain,
2970 fcport->d_id.b.area, fcport->d_id.b.al_pa));
2971
2972 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
2973 /*
2974 * Login succeeded.
2975 */
2976 if (retry) {
2977 /* A retry occurred before. */
2978 *next_loopid = tmp_loopid;
2979 } else {
2980 /*
2981 * No retry occurred before. Just increment the
2982 * ID value for next login.
2983 */
2984 *next_loopid = (fcport->loop_id + 1);
2985 }
2986
2987 if (mb[1] & BIT_0) {
2988 fcport->port_type = FCT_INITIATOR;
2989 } else {
2990 fcport->port_type = FCT_TARGET;
2991 if (mb[1] & BIT_1) {
2992 fcport->flags |= FCF_TAPE_PRESENT;
2993 }
2994 }
2995
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002996 if (mb[10] & BIT_0)
2997 fcport->supported_classes |= FC_COS_CLASS2;
2998 if (mb[10] & BIT_1)
2999 fcport->supported_classes |= FC_COS_CLASS3;
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 rval = QLA_SUCCESS;
3002 break;
3003 } else if (mb[0] == MBS_LOOP_ID_USED) {
3004 /*
3005 * Loop ID already used, try next loop ID.
3006 */
3007 fcport->loop_id++;
3008 rval = qla2x00_find_new_loop_id(ha, fcport);
3009 if (rval != QLA_SUCCESS) {
3010 /* Ran out of loop IDs to use */
3011 break;
3012 }
3013 } else if (mb[0] == MBS_COMMAND_ERROR) {
3014 /*
3015 * Firmware possibly timed out during login. If NO
3016 * retries are left to do then the device is declared
3017 * dead.
3018 */
3019 *next_loopid = fcport->loop_id;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003020 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003021 fcport->d_id.b.domain, fcport->d_id.b.area,
3022 fcport->d_id.b.al_pa);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003023 qla2x00_mark_device_lost(ha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003024
3025 rval = 1;
3026 break;
3027 } else {
3028 /*
3029 * unrecoverable / not handled error
3030 */
3031 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003032 "loop_id=%x jiffies=%lx.\n",
3033 __func__, ha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 fcport->d_id.b.domain, fcport->d_id.b.area,
3035 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3036
3037 *next_loopid = fcport->loop_id;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003038 ha->isp_ops->fabric_logout(ha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003039 fcport->d_id.b.domain, fcport->d_id.b.area,
3040 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003042 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003043
3044 rval = 3;
3045 break;
3046 }
3047 }
3048
3049 return (rval);
3050}
3051
3052/*
3053 * qla2x00_local_device_login
3054 * Issue local device login command.
3055 *
3056 * Input:
3057 * ha = adapter block pointer.
3058 * loop_id = loop id of device to login to.
3059 *
3060 * Returns (Where's the #define!!!!):
3061 * 0 - Login successfully
3062 * 1 - Login failed
3063 * 3 - Fatal error
3064 */
3065int
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08003066qla2x00_local_device_login(scsi_qla_host_t *ha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067{
3068 int rval;
3069 uint16_t mb[MAILBOX_REGISTER_COUNT];
3070
3071 memset(mb, 0, sizeof(mb));
andrew.vasquez@qlogic.com9a52a57c2006-03-09 14:27:44 -08003072 rval = qla2x00_login_local_device(ha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 if (rval == QLA_SUCCESS) {
3074 /* Interrogate mailbox registers for any errors */
3075 if (mb[0] == MBS_COMMAND_ERROR)
3076 rval = 1;
3077 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3078 /* device not in PCB table */
3079 rval = 3;
3080 }
3081
3082 return (rval);
3083}
3084
3085/*
3086 * qla2x00_loop_resync
3087 * Resync with fibre channel devices.
3088 *
3089 * Input:
3090 * ha = adapter block pointer.
3091 *
3092 * Returns:
3093 * 0 = success
3094 */
3095int
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003096qla2x00_loop_resync(scsi_qla_host_t *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097{
3098 int rval;
3099 uint32_t wait_time;
3100
3101 rval = QLA_SUCCESS;
3102
3103 atomic_set(&ha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3105 if (ha->flags.online) {
3106 if (!(rval = qla2x00_fw_ready(ha))) {
3107 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3108 wait_time = 256;
3109 do {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003110 atomic_set(&ha->loop_state, LOOP_UPDATE);
3111
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003112 /* Issue a marker after FW becomes ready. */
3113 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3114 ha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115
3116 /* Remap devices on Loop. */
3117 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3118
3119 qla2x00_configure_loop(ha);
3120 wait_time--;
3121 } while (!atomic_read(&ha->loop_down_timer) &&
3122 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3123 wait_time &&
3124 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3125 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 }
3127
3128 if (test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) {
3129 return (QLA_FUNCTION_FAILED);
3130 }
3131
3132 if (rval) {
3133 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
3134 }
3135
3136 return (rval);
3137}
3138
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139void
3140qla2x00_rescan_fcports(scsi_qla_host_t *ha)
3141{
3142 int rescan_done;
3143 fc_port_t *fcport;
3144
3145 rescan_done = 0;
3146 list_for_each_entry(fcport, &ha->fcports, list) {
3147 if ((fcport->flags & FCF_RESCAN_NEEDED) == 0)
3148 continue;
3149
3150 qla2x00_update_fcport(ha, fcport);
3151 fcport->flags &= ~FCF_RESCAN_NEEDED;
3152
3153 rescan_done = 1;
3154 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003155 qla2x00_probe_for_all_luns(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156}
3157
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003158void
3159qla2x00_update_fcports(scsi_qla_host_t *ha)
3160{
3161 fc_port_t *fcport;
3162
3163 /* Go with deferred removal of rport references. */
3164 list_for_each_entry(fcport, &ha->fcports, list)
3165 if (fcport->drport)
3166 qla2x00_rport_del(fcport);
3167}
3168
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169/*
3170* qla2x00_abort_isp
3171* Resets ISP and aborts all outstanding commands.
3172*
3173* Input:
3174* ha = adapter block pointer.
3175*
3176* Returns:
3177* 0 = success
3178*/
3179int
3180qla2x00_abort_isp(scsi_qla_host_t *ha)
3181{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003182 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 unsigned long flags = 0;
3184 uint16_t cnt;
3185 srb_t *sp;
3186 uint8_t status = 0;
3187
3188 if (ha->flags.online) {
3189 ha->flags.online = 0;
3190 clear_bit(ISP_ABORT_NEEDED, &ha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191
3192 qla_printk(KERN_INFO, ha,
3193 "Performing ISP error recovery - ha= %p.\n", ha);
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003194 ha->isp_ops->reset_chip(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003195
3196 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
3197 if (atomic_read(&ha->loop_state) != LOOP_DOWN) {
3198 atomic_set(&ha->loop_state, LOOP_DOWN);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003199 qla2x00_mark_all_devices_lost(ha, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 } else {
3201 if (!atomic_read(&ha->loop_down_timer))
3202 atomic_set(&ha->loop_down_timer,
3203 LOOP_DOWN_TIME);
3204 }
3205
3206 spin_lock_irqsave(&ha->hardware_lock, flags);
3207 /* Requeue all commands in outstanding command list. */
3208 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
3209 sp = ha->outstanding_cmds[cnt];
3210 if (sp) {
3211 ha->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003212 sp->flags = 0;
f4f051e2005-04-17 15:02:26 -05003213 sp->cmd->result = DID_RESET << 16;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214 sp->cmd->host_scribble = (unsigned char *)NULL;
f4f051e2005-04-17 15:02:26 -05003215 qla2x00_sp_compl(ha, sp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003216 }
3217 }
3218 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3219
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003220 ha->isp_ops->get_flash_version(ha, ha->request_ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003221
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003222 ha->isp_ops->nvram_config(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223
3224 if (!qla2x00_restart_isp(ha)) {
3225 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3226
3227 if (!atomic_read(&ha->loop_down_timer)) {
3228 /*
3229 * Issue marker command only when we are going
3230 * to start the I/O .
3231 */
3232 ha->marker_needed = 1;
3233 }
3234
3235 ha->flags.online = 1;
3236
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003237 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003239 ha->isp_abort_cnt = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240 clear_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003241
3242 if (ha->eft) {
3243 rval = qla2x00_trace_control(ha, TC_ENABLE,
3244 ha->eft_dma, EFT_NUM_BUFFERS);
3245 if (rval) {
3246 qla_printk(KERN_WARNING, ha,
3247 "Unable to reinitialize EFT "
3248 "(%d).\n", rval);
3249 }
3250 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251 } else { /* failed the ISP abort */
3252 ha->flags.online = 1;
3253 if (test_bit(ISP_ABORT_RETRY, &ha->dpc_flags)) {
3254 if (ha->isp_abort_cnt == 0) {
3255 qla_printk(KERN_WARNING, ha,
3256 "ISP error recovery failed - "
3257 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003258 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 * The next call disables the board
3260 * completely.
3261 */
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003262 ha->isp_ops->reset_adapter(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 ha->flags.online = 0;
3264 clear_bit(ISP_ABORT_RETRY,
3265 &ha->dpc_flags);
3266 status = 0;
3267 } else { /* schedule another ISP abort */
3268 ha->isp_abort_cnt--;
3269 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003270 "retry remaining %d\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003271 ha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 status = 1;
3273 }
3274 } else {
3275 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3276 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3277 "- retrying (%d) more times\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003278 ha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279 set_bit(ISP_ABORT_RETRY, &ha->dpc_flags);
3280 status = 1;
3281 }
3282 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003283
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 }
3285
3286 if (status) {
3287 qla_printk(KERN_INFO, ha,
3288 "qla2x00_abort_isp: **** FAILED ****\n");
3289 } else {
3290 DEBUG(printk(KERN_INFO
3291 "qla2x00_abort_isp(%ld): exiting.\n",
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003292 ha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 }
3294
3295 return(status);
3296}
3297
3298/*
3299* qla2x00_restart_isp
3300* restarts the ISP after a reset
3301*
3302* Input:
3303* ha = adapter block pointer.
3304*
3305* Returns:
3306* 0 = success
3307*/
3308static int
3309qla2x00_restart_isp(scsi_qla_host_t *ha)
3310{
3311 uint8_t status = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003312 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 unsigned long flags = 0;
3314 uint32_t wait_time;
3315
3316 /* If firmware needs to be loaded */
3317 if (qla2x00_isp_firmware(ha)) {
3318 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003319 if (!(status = ha->isp_ops->chip_diag(ha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3321 status = qla2x00_setup_chip(ha);
3322 goto done;
3323 }
3324
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 spin_lock_irqsave(&ha->hardware_lock, flags);
3326
Andrew Vasquez8fef6962007-08-12 18:22:53 -07003327 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
3328 !IS_QLA25XX(ha)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003329 /*
3330 * Disable SRAM, Instruction RAM and GP RAM
3331 * parity.
3332 */
3333 WRT_REG_WORD(&reg->hccr,
3334 (HCCR_ENABLE_PARITY + 0x0));
3335 RD_REG_WORD(&reg->hccr);
3336 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
3338 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003339
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 status = qla2x00_setup_chip(ha);
3341
3342 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003343
Andrew Vasquez8fef6962007-08-12 18:22:53 -07003344 if (!IS_QLA24XX(ha) && !IS_QLA54XX(ha) &&
3345 !IS_QLA25XX(ha)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003346 /* Enable proper parity */
3347 if (IS_QLA2300(ha))
3348 /* SRAM parity */
3349 WRT_REG_WORD(&reg->hccr,
3350 (HCCR_ENABLE_PARITY + 0x1));
3351 else
3352 /*
3353 * SRAM, Instruction RAM and GP RAM
3354 * parity.
3355 */
3356 WRT_REG_WORD(&reg->hccr,
3357 (HCCR_ENABLE_PARITY + 0x7));
3358 RD_REG_WORD(&reg->hccr);
3359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360
3361 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3362 }
3363 }
3364
3365 done:
3366 if (!status && !(status = qla2x00_init_rings(ha))) {
3367 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
3368 if (!(status = qla2x00_fw_ready(ha))) {
3369 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003370 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003371
3372 /* Issue a marker after FW becomes ready. */
3373 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
3374
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 ha->flags.online = 1;
3376 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3377 wait_time = 256;
3378 do {
3379 clear_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
3380 qla2x00_configure_loop(ha);
3381 wait_time--;
3382 } while (!atomic_read(&ha->loop_down_timer) &&
3383 !(test_bit(ISP_ABORT_NEEDED, &ha->dpc_flags)) &&
3384 wait_time &&
3385 (test_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags)));
3386 }
3387
3388 /* if no cable then assume it's good */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003389 if ((ha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 status = 0;
3391
3392 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3393 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003394 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 }
3396 return (status);
3397}
3398
3399/*
3400* qla2x00_reset_adapter
3401* Reset adapter.
3402*
3403* Input:
3404* ha = adapter block pointer.
3405*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003406void
Linus Torvalds1da177e2005-04-16 15:20:36 -07003407qla2x00_reset_adapter(scsi_qla_host_t *ha)
3408{
3409 unsigned long flags = 0;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003410 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411
3412 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003413 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 spin_lock_irqsave(&ha->hardware_lock, flags);
3416 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3417 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3418 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3419 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3420 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3421}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003422
3423void
3424qla24xx_reset_adapter(scsi_qla_host_t *ha)
3425{
3426 unsigned long flags = 0;
3427 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3428
3429 ha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003430 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003431
3432 spin_lock_irqsave(&ha->hardware_lock, flags);
3433 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3434 RD_REG_DWORD(&reg->hccr);
3435 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3436 RD_REG_DWORD(&reg->hccr);
3437 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3438}
3439
David Miller4e08df32007-04-16 12:37:43 -07003440/* On sparc systems, obtain port and node WWN from firmware
3441 * properties.
3442 */
3443static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *ha, struct nvram_24xx *nv)
3444{
3445#ifdef CONFIG_SPARC
3446 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003447 struct device_node *dp = pci_device_to_OF_node(pdev);
3448 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003449 int len;
3450
3451 val = of_get_property(dp, "port-wwn", &len);
3452 if (val && len >= WWN_SIZE)
3453 memcpy(nv->port_name, val, WWN_SIZE);
3454
3455 val = of_get_property(dp, "node-wwn", &len);
3456 if (val && len >= WWN_SIZE)
3457 memcpy(nv->node_name, val, WWN_SIZE);
3458#endif
3459}
3460
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003461int
3462qla24xx_nvram_config(scsi_qla_host_t *ha)
3463{
David Miller4e08df32007-04-16 12:37:43 -07003464 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003465 struct init_cb_24xx *icb;
3466 struct nvram_24xx *nv;
3467 uint32_t *dptr;
3468 uint8_t *dptr1, *dptr2;
3469 uint32_t chksum;
3470 uint16_t cnt;
3471
David Miller4e08df32007-04-16 12:37:43 -07003472 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003473 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003474 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003475
3476 /* Determine NVRAM starting address. */
3477 ha->nvram_size = sizeof(struct nvram_24xx);
3478 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003479 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3480 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3481 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003482 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003483 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3484 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003485
Seokmann Ju281afe12007-07-26 13:43:34 -07003486 /* Get VPD data into cache */
3487 ha->vpd = ha->nvram + VPD_OFFSET;
3488 ha->isp_ops->read_nvram(ha, (uint8_t *)ha->vpd,
3489 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3490
3491 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003492 dptr = (uint32_t *)nv;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003493 ha->isp_ops->read_nvram(ha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003494 ha->nvram_size);
3495 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3496 chksum += le32_to_cpu(*dptr++);
3497
3498 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003499 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003500
3501 /* Bad NVRAM data, set defaults parameters. */
3502 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3503 || nv->id[3] != ' ' ||
3504 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3505 /* Reset NVRAM data. */
3506 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3507 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3508 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003509 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3510 "invalid -- WWPN) defaults.\n");
3511
3512 /*
3513 * Set default initialization control block.
3514 */
3515 memset(nv, 0, ha->nvram_size);
3516 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3517 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3518 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3519 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3520 nv->exchange_count = __constant_cpu_to_le16(0);
3521 nv->hard_address = __constant_cpu_to_le16(124);
3522 nv->port_name[0] = 0x21;
3523 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3524 nv->port_name[2] = 0x00;
3525 nv->port_name[3] = 0xe0;
3526 nv->port_name[4] = 0x8b;
3527 nv->port_name[5] = 0x1c;
3528 nv->port_name[6] = 0x55;
3529 nv->port_name[7] = 0x86;
3530 nv->node_name[0] = 0x20;
3531 nv->node_name[1] = 0x00;
3532 nv->node_name[2] = 0x00;
3533 nv->node_name[3] = 0xe0;
3534 nv->node_name[4] = 0x8b;
3535 nv->node_name[5] = 0x1c;
3536 nv->node_name[6] = 0x55;
3537 nv->node_name[7] = 0x86;
3538 qla24xx_nvram_wwn_from_ofw(ha, nv);
3539 nv->login_retry_count = __constant_cpu_to_le16(8);
3540 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3541 nv->login_timeout = __constant_cpu_to_le16(0);
3542 nv->firmware_options_1 =
3543 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3544 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3545 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3546 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3547 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3548 nv->efi_parameters = __constant_cpu_to_le32(0);
3549 nv->reset_delay = 5;
3550 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3551 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3552 nv->link_down_timeout = __constant_cpu_to_le16(30);
3553
3554 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003555 }
3556
3557 /* Reset Initialization control block */
3558 memset(icb, 0, sizeof(struct init_cb_24xx));
3559
3560 /* Copy 1st segment. */
3561 dptr1 = (uint8_t *)icb;
3562 dptr2 = (uint8_t *)&nv->version;
3563 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3564 while (cnt--)
3565 *dptr1++ = *dptr2++;
3566
3567 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003568 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003569
3570 /* Copy 2nd segment. */
3571 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3572 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3573 cnt = (uint8_t *)&icb->reserved_3 -
3574 (uint8_t *)&icb->interrupt_delay_timer;
3575 while (cnt--)
3576 *dptr1++ = *dptr2++;
3577
3578 /*
3579 * Setup driver NVRAM options.
3580 */
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003581 qla2x00_set_model_info(ha, nv->model_name, sizeof(nv->model_name),
3582 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003583
Andrew Vasquez5341e862006-05-17 15:09:16 -07003584 /* Use alternate WWN? */
3585 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3586 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3587 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3588 }
3589
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003590 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003591 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003592 /*
3593 * Firmware will apply the following mask if the nodename was
3594 * not provided.
3595 */
3596 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3597 icb->node_name[0] &= 0xF0;
3598 }
3599
3600 /* Set host adapter parameters. */
3601 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003602 ha->flags.enable_lip_reset = 0;
3603 ha->flags.enable_lip_full_login =
3604 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3605 ha->flags.enable_target_reset =
3606 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003607 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003608 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003609
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003610 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3611 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003612
3613 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3614 sizeof(ha->fw_seriallink_options24));
3615
3616 /* save HBA serial number */
3617 ha->serial0 = icb->port_name[5];
3618 ha->serial1 = icb->port_name[6];
3619 ha->serial2 = icb->port_name[7];
3620 ha->node_name = icb->node_name;
3621 ha->port_name = icb->port_name;
3622
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003623 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3624
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003625 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3626
3627 /* Set minimum login_timeout to 4 seconds. */
3628 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3629 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3630 if (le16_to_cpu(nv->login_timeout) < 4)
3631 nv->login_timeout = __constant_cpu_to_le16(4);
3632 ha->login_timeout = le16_to_cpu(nv->login_timeout);
3633 icb->login_timeout = cpu_to_le16(nv->login_timeout);
3634
3635 /* Set minimum RATOV to 200 tenths of a second. */
3636 ha->r_a_tov = 200;
3637
3638 ha->loop_reset_delay = nv->reset_delay;
3639
3640 /* Link Down Timeout = 0:
3641 *
3642 * When Port Down timer expires we will start returning
3643 * I/O's to OS with "DID_NO_CONNECT".
3644 *
3645 * Link Down Timeout != 0:
3646 *
3647 * The driver waits for the link to come up after link down
3648 * before returning I/Os to OS with "DID_NO_CONNECT".
3649 */
3650 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3651 ha->loop_down_abort_time =
3652 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3653 } else {
3654 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3655 ha->loop_down_abort_time =
3656 (LOOP_DOWN_TIME - ha->link_down_timeout);
3657 }
3658
3659 /* Need enough time to try and get the port back. */
3660 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3661 if (qlport_down_retry)
3662 ha->port_down_retry_count = qlport_down_retry;
3663
3664 /* Set login_retry_count */
3665 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3666 if (ha->port_down_retry_count ==
3667 le16_to_cpu(nv->port_down_retry_count) &&
3668 ha->port_down_retry_count > 3)
3669 ha->login_retry_count = ha->port_down_retry_count;
3670 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3671 ha->login_retry_count = ha->port_down_retry_count;
3672 if (ql2xloginretrycount)
3673 ha->login_retry_count = ql2xloginretrycount;
3674
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003675 /* Enable ZIO. */
3676 if (!ha->flags.init_done) {
3677 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3678 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3679 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3680 le16_to_cpu(icb->interrupt_delay_timer): 2;
3681 }
3682 icb->firmware_options_2 &= __constant_cpu_to_le32(
3683 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
3684 ha->flags.process_response_queue = 0;
3685 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003686 ha->zio_mode = QLA_ZIO_MODE_6;
3687
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003688 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
3689 "(%d us).\n", ha->host_no, ha->zio_mode,
3690 ha->zio_timer * 100));
3691 qla_printk(KERN_INFO, ha,
3692 "ZIO mode %d enabled; timer delay (%d us).\n",
3693 ha->zio_mode, ha->zio_timer * 100);
3694
3695 icb->firmware_options_2 |= cpu_to_le32(
3696 (uint32_t)ha->zio_mode);
3697 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
3698 ha->flags.process_response_queue = 1;
3699 }
3700
David Miller4e08df32007-04-16 12:37:43 -07003701 if (rval) {
3702 DEBUG2_3(printk(KERN_WARNING
3703 "scsi(%ld): NVRAM configuration failed!\n", ha->host_no));
3704 }
3705 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003706}
3707
Adrian Bunk413975a2006-06-30 02:33:06 -07003708static int
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003709qla24xx_load_risc_flash(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3710{
3711 int rval;
3712 int segments, fragment;
3713 uint32_t faddr;
3714 uint32_t *dcode, dlen;
3715 uint32_t risc_addr;
3716 uint32_t risc_size;
3717 uint32_t i;
3718
3719 rval = QLA_SUCCESS;
3720
3721 segments = FA_RISC_CODE_SEGMENTS;
3722 faddr = FA_RISC_CODE_ADDR;
3723 dcode = (uint32_t *)ha->request_ring;
3724 *srisc_addr = 0;
3725
3726 /* Validate firmware image by checking version. */
3727 qla24xx_read_flash_data(ha, dcode, faddr + 4, 4);
3728 for (i = 0; i < 4; i++)
3729 dcode[i] = be32_to_cpu(dcode[i]);
3730 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3731 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3732 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3733 dcode[3] == 0)) {
3734 qla_printk(KERN_WARNING, ha,
3735 "Unable to verify integrity of flash firmware image!\n");
3736 qla_printk(KERN_WARNING, ha,
3737 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3738 dcode[1], dcode[2], dcode[3]);
3739
3740 return QLA_FUNCTION_FAILED;
3741 }
3742
3743 while (segments && rval == QLA_SUCCESS) {
3744 /* Read segment's load information. */
3745 qla24xx_read_flash_data(ha, dcode, faddr, 4);
3746
3747 risc_addr = be32_to_cpu(dcode[2]);
3748 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3749 risc_size = be32_to_cpu(dcode[3]);
3750
3751 fragment = 0;
3752 while (risc_size > 0 && rval == QLA_SUCCESS) {
3753 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3754 if (dlen > risc_size)
3755 dlen = risc_size;
3756
3757 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3758 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
3759 ha->host_no, risc_addr, dlen, faddr));
3760
3761 qla24xx_read_flash_data(ha, dcode, faddr, dlen);
3762 for (i = 0; i < dlen; i++)
3763 dcode[i] = swab32(dcode[i]);
3764
3765 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3766 dlen);
3767 if (rval) {
3768 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3769 "segment %d of firmware\n", ha->host_no,
3770 fragment));
3771 qla_printk(KERN_WARNING, ha,
3772 "[ERROR] Failed to load segment %d of "
3773 "firmware\n", fragment);
3774 break;
3775 }
3776
3777 faddr += dlen;
3778 risc_addr += dlen;
3779 risc_size -= dlen;
3780 fragment++;
3781 }
3782
3783 /* Next segment. */
3784 segments--;
3785 }
3786
3787 return rval;
3788}
3789
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003790#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3791
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003792int
Andrew Vasquez54333832005-11-09 15:49:04 -08003793qla2x00_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
3794{
3795 int rval;
3796 int i, fragment;
3797 uint16_t *wcode, *fwcode;
3798 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3799 struct fw_blob *blob;
3800
3801 /* Load firmware blob. */
3802 blob = qla2x00_request_firmware(ha);
3803 if (!blob) {
3804 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003805 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3806 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003807 return QLA_FUNCTION_FAILED;
3808 }
3809
3810 rval = QLA_SUCCESS;
3811
3812 wcode = (uint16_t *)ha->request_ring;
3813 *srisc_addr = 0;
3814 fwcode = (uint16_t *)blob->fw->data;
3815 fwclen = 0;
3816
3817 /* Validate firmware image by checking version. */
3818 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3819 qla_printk(KERN_WARNING, ha,
3820 "Unable to verify integrity of firmware image (%Zd)!\n",
3821 blob->fw->size);
3822 goto fail_fw_integrity;
3823 }
3824 for (i = 0; i < 4; i++)
3825 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3826 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3827 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3828 wcode[2] == 0 && wcode[3] == 0)) {
3829 qla_printk(KERN_WARNING, ha,
3830 "Unable to verify integrity of firmware image!\n");
3831 qla_printk(KERN_WARNING, ha,
3832 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3833 wcode[1], wcode[2], wcode[3]);
3834 goto fail_fw_integrity;
3835 }
3836
3837 seg = blob->segs;
3838 while (*seg && rval == QLA_SUCCESS) {
3839 risc_addr = *seg;
3840 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3841 risc_size = be16_to_cpu(fwcode[3]);
3842
3843 /* Validate firmware image size. */
3844 fwclen += risc_size * sizeof(uint16_t);
3845 if (blob->fw->size < fwclen) {
3846 qla_printk(KERN_WARNING, ha,
3847 "Unable to verify integrity of firmware image "
3848 "(%Zd)!\n", blob->fw->size);
3849 goto fail_fw_integrity;
3850 }
3851
3852 fragment = 0;
3853 while (risc_size > 0 && rval == QLA_SUCCESS) {
3854 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3855 if (wlen > risc_size)
3856 wlen = risc_size;
3857
3858 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3859 "addr %x, number of words 0x%x.\n", ha->host_no,
3860 risc_addr, wlen));
3861
3862 for (i = 0; i < wlen; i++)
3863 wcode[i] = swab16(fwcode[i]);
3864
3865 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3866 wlen);
3867 if (rval) {
3868 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3869 "segment %d of firmware\n", ha->host_no,
3870 fragment));
3871 qla_printk(KERN_WARNING, ha,
3872 "[ERROR] Failed to load segment %d of "
3873 "firmware\n", fragment);
3874 break;
3875 }
3876
3877 fwcode += wlen;
3878 risc_addr += wlen;
3879 risc_size -= wlen;
3880 fragment++;
3881 }
3882
3883 /* Next segment. */
3884 seg++;
3885 }
3886 return rval;
3887
3888fail_fw_integrity:
3889 return QLA_FUNCTION_FAILED;
3890}
3891
3892int
3893qla24xx_load_risc(scsi_qla_host_t *ha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003894{
3895 int rval;
3896 int segments, fragment;
3897 uint32_t *dcode, dlen;
3898 uint32_t risc_addr;
3899 uint32_t risc_size;
3900 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08003901 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003902 uint32_t *fwcode, fwclen;
3903
Andrew Vasquez54333832005-11-09 15:49:04 -08003904 /* Load firmware blob. */
3905 blob = qla2x00_request_firmware(ha);
3906 if (!blob) {
3907 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003908 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3909 "from: " QLA_FW_URL ".\n");
3910
3911 /* Try to load RISC code from flash. */
3912 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3913 "outdated) firmware from flash.\n");
3914 return qla24xx_load_risc_flash(ha, srisc_addr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003915 }
3916
3917 rval = QLA_SUCCESS;
3918
3919 segments = FA_RISC_CODE_SEGMENTS;
3920 dcode = (uint32_t *)ha->request_ring;
3921 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08003922 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003923 fwclen = 0;
3924
3925 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08003926 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003927 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003928 "Unable to verify integrity of firmware image (%Zd)!\n",
3929 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003930 goto fail_fw_integrity;
3931 }
3932 for (i = 0; i < 4; i++)
3933 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3934 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3935 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3936 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3937 dcode[3] == 0)) {
3938 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003939 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003940 qla_printk(KERN_WARNING, ha,
3941 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3942 dcode[1], dcode[2], dcode[3]);
3943 goto fail_fw_integrity;
3944 }
3945
3946 while (segments && rval == QLA_SUCCESS) {
3947 risc_addr = be32_to_cpu(fwcode[2]);
3948 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3949 risc_size = be32_to_cpu(fwcode[3]);
3950
3951 /* Validate firmware image size. */
3952 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08003953 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003954 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003955 "Unable to verify integrity of firmware image "
3956 "(%Zd)!\n", blob->fw->size);
3957
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003958 goto fail_fw_integrity;
3959 }
3960
3961 fragment = 0;
3962 while (risc_size > 0 && rval == QLA_SUCCESS) {
3963 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3964 if (dlen > risc_size)
3965 dlen = risc_size;
3966
3967 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3968 "addr %x, number of dwords 0x%x.\n", ha->host_no,
3969 risc_addr, dlen));
3970
3971 for (i = 0; i < dlen; i++)
3972 dcode[i] = swab32(fwcode[i]);
3973
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08003974 rval = qla2x00_load_ram(ha, ha->request_dma, risc_addr,
3975 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003976 if (rval) {
3977 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
3978 "segment %d of firmware\n", ha->host_no,
3979 fragment));
3980 qla_printk(KERN_WARNING, ha,
3981 "[ERROR] Failed to load segment %d of "
3982 "firmware\n", fragment);
3983 break;
3984 }
3985
3986 fwcode += dlen;
3987 risc_addr += dlen;
3988 risc_size -= dlen;
3989 fragment++;
3990 }
3991
3992 /* Next segment. */
3993 segments--;
3994 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003995 return rval;
3996
3997fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003998 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003999}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004000
4001void
4002qla2x00_try_to_stop_firmware(scsi_qla_host_t *ha)
4003{
4004 int ret, retries;
4005
Andrew Vasqueze4289242007-07-19 15:05:56 -07004006 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004007 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004008 if (!ha->fw_major_version)
4009 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004010
4011 ret = qla2x00_stop_firmware(ha);
4012 for (retries = 5; ret != QLA_SUCCESS && retries ; retries--) {
4013 qla2x00_reset_chip(ha);
4014 if (qla2x00_chip_diag(ha) != QLA_SUCCESS)
4015 continue;
4016 if (qla2x00_setup_chip(ha) != QLA_SUCCESS)
4017 continue;
4018 qla_printk(KERN_INFO, ha,
4019 "Attempting retry of stop-firmware command...\n");
4020 ret = qla2x00_stop_firmware(ha);
4021 }
4022}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004023
4024int
4025qla24xx_configure_vhba(scsi_qla_host_t *ha)
4026{
4027 int rval = QLA_SUCCESS;
4028 uint16_t mb[MAILBOX_REGISTER_COUNT];
4029
4030 if (!ha->parent)
4031 return -EINVAL;
4032
4033 rval = qla2x00_fw_ready(ha);
4034 if (rval == QLA_SUCCESS) {
4035 clear_bit(RESET_MARKER_NEEDED, &ha->dpc_flags);
4036 qla2x00_marker(ha, 0, 0, MK_SYNC_ALL);
4037 }
4038
4039 ha->flags.management_server_logged_in = 0;
4040
4041 /* Login to SNS first */
4042 qla24xx_login_fabric(ha, NPH_SNS, 0xff, 0xff, 0xfc,
4043 mb, BIT_1);
4044 if (mb[0] != MBS_COMMAND_COMPLETE) {
4045 DEBUG15(qla_printk(KERN_INFO, ha,
4046 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4047 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4048 mb[0], mb[1], mb[2], mb[6], mb[7]));
4049 return (QLA_FUNCTION_FAILED);
4050 }
4051
4052 atomic_set(&ha->loop_down_timer, 0);
4053 atomic_set(&ha->loop_state, LOOP_UP);
4054 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
4055 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
4056 rval = qla2x00_loop_resync(ha);
4057
4058 return rval;
4059}