blob: 9ad4d0968e5c87b38045c60e08cd6f244aa0ff5b [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
Anirban Chakraborty73208df2008-12-09 16:45:39 -08008#include "qla_gbl.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
10#include <linux/delay.h>
Andrew Vasquez0107109e2005-07-06 10:31:37 -070011#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070012
13#include "qla_devtbl.h"
14
David Miller4e08df32007-04-16 12:37:43 -070015#ifdef CONFIG_SPARC
16#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070017#endif
18
Linus Torvalds1da177e2005-04-16 15:20:36 -070019/*
20* QLogic ISP2x00 Hardware Support Function Prototypes.
21*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070023static void qla2x00_resize_request_q(scsi_qla_host_t *);
24static int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070025static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080042static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070043
Linus Torvalds1da177e2005-04-16 15:20:36 -070044/****************************************************************************/
45/* QLogic ISP2x00 Hardware Support Functions. */
46/****************************************************************************/
47
48/*
49* qla2x00_initialize_adapter
50* Initialize board.
51*
52* Input:
53* ha = adapter block pointer.
54*
55* Returns:
56* 0 = success
57*/
58int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080059qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070060{
61 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080062 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -080063 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080065 vha->flags.online = 0;
66 vha->flags.reset_active = 0;
67 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
68 atomic_set(&vha->loop_state, LOOP_DOWN);
69 vha->device_flags = DFLG_NO_CABLE;
70 vha->dpc_flags = 0;
71 vha->flags.management_server_logged_in = 0;
72 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073 ha->mbx_flags = 0;
74 ha->isp_abort_cnt = 0;
75 ha->beacon_blink_led = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080076 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Anirban Chakraborty73208df2008-12-09 16:45:39 -080078 set_bit(0, ha->req_qid_map);
79 set_bit(0, ha->rsp_qid_map);
80
Andrew Vasquez0107109e2005-07-06 10:31:37 -070081 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080082 rval = ha->isp_ops->pci_config(vha);
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",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080085 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 return (rval);
87 }
88
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080089 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080091 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -070092 if (rval) {
93 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080094 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -070095 return (rval);
96 }
97
Anirban Chakraborty73208df2008-12-09 16:45:39 -080098 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -080099
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800102 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700104 if (ha->flags.disable_serdes) {
105 /* Mask HBA via NVRAM settings? */
106 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
107 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800108 vha->port_name[0], vha->port_name[1],
109 vha->port_name[2], vha->port_name[3],
110 vha->port_name[4], vha->port_name[5],
111 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700112 return QLA_FUNCTION_FAILED;
113 }
114
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
116
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800117 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
118 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800119 if (rval)
120 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800121 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800122 if (rval)
123 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700125 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800126 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700127 if (!ha->cs84xx) {
128 qla_printk(KERN_ERR, ha,
129 "Unable to configure ISP84XX.\n");
130 return QLA_FUNCTION_FAILED;
131 }
132 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800133 rval = qla2x00_init_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 return (rval);
136}
137
138/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700139 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 * @ha: HA context
141 *
142 * Returns 0 on success.
143 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700144int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800145qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700147 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700148 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800149 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700150 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700153 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700156 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
158
Andrew Vasquez737faec2008-10-24 15:13:45 -0700159 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700161 /* Get PCI bus information. */
162 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700163 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700164 spin_unlock_irqrestore(&ha->hardware_lock, flags);
165
166 return QLA_SUCCESS;
167}
168
169/**
170 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
171 * @ha: HA context
172 *
173 * Returns 0 on success.
174 */
175int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800176qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700177{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700178 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700179 unsigned long flags = 0;
180 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800181 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700182 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700183
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700184 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700185 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700186
187 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700188 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700189
190 if (IS_QLA2322(ha) || IS_QLA6322(ha))
191 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700192 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700193
194 /*
195 * If this is a 2300 card and not 2312, reset the
196 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
197 * the 2310 also reports itself as a 2300 so we need to get the
198 * fb revision level -- a 6 indicates it really is a 2300 and
199 * not a 2310.
200 */
201 if (IS_QLA2300(ha)) {
202 spin_lock_irqsave(&ha->hardware_lock, flags);
203
204 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700205 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700206 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700207 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700208 break;
209
210 udelay(10);
211 }
212
213 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700214 WRT_REG_WORD(&reg->ctrl_status, 0x20);
215 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700216
217 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700218 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700219
220 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700221 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700222
223 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700224 WRT_REG_WORD(&reg->ctrl_status, 0x0);
225 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700226
227 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700228 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700229 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700230 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700231 break;
232
233 udelay(10);
234 }
235
236 spin_unlock_irqrestore(&ha->hardware_lock, flags);
237 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700238
239 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
240
Andrew Vasquez737faec2008-10-24 15:13:45 -0700241 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700242
243 /* Get PCI bus information. */
244 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700245 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
247
248 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249}
250
251/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700252 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
253 * @ha: HA context
254 *
255 * Returns 0 on success.
256 */
257int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800258qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700259{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700260 uint16_t w;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700261 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800262 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700263 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700264
265 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700266 pci_try_set_mwi(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700267
268 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700269 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700270 w &= ~PCI_COMMAND_INTX_DISABLE;
271 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
272
273 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
274
275 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700276 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
277 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700278
279 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700280 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
281 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700282
Andrew Vasquez737faec2008-10-24 15:13:45 -0700283 pci_disable_rom(ha->pdev);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700284
Auke Kok44c10132007-06-08 15:46:36 -0700285 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800286
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700287 /* Get PCI bus information. */
288 spin_lock_irqsave(&ha->hardware_lock, flags);
289 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
291
292 return QLA_SUCCESS;
293}
294
295/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700296 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
297 * @ha: HA context
298 *
299 * Returns 0 on success.
300 */
301int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800302qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700303{
304 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800305 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700306
307 pci_set_master(ha->pdev);
308 pci_try_set_mwi(ha->pdev);
309
310 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
311 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
312 w &= ~PCI_COMMAND_INTX_DISABLE;
313 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
314
315 /* PCIe -- adjust Maximum Read Request Size (2048). */
316 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
317 pcie_set_readrq(ha->pdev, 2048);
318
Andrew Vasquez737faec2008-10-24 15:13:45 -0700319 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700320
321 ha->chip_revision = ha->pdev->revision;
322
323 return QLA_SUCCESS;
324}
325
326/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 * qla2x00_isp_firmware() - Choose firmware image.
328 * @ha: HA context
329 *
330 * Returns 0 on success.
331 */
332static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800333qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334{
335 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700336 uint16_t loop_id, topo, sw_cap;
337 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800338 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339
340 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700341 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 if (ha->flags.disable_risc_code_load) {
344 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800345 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
347
348 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800349 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700350 if (rval == QLA_SUCCESS) {
351 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800352 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700353 &area, &domain, &topo, &sw_cap);
354 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
357 if (rval) {
358 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800359 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 }
361
362 return (rval);
363}
364
365/**
366 * qla2x00_reset_chip() - Reset ISP chip.
367 * @ha: HA context
368 *
369 * Returns 0 on success.
370 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700371void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800372qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
374 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800375 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700376 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 uint16_t cmd;
379
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700380 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381
382 spin_lock_irqsave(&ha->hardware_lock, flags);
383
384 /* Turn off master enable */
385 cmd = 0;
386 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
387 cmd &= ~PCI_COMMAND_MASTER;
388 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
389
390 if (!IS_QLA2100(ha)) {
391 /* Pause RISC. */
392 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
393 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
394 for (cnt = 0; cnt < 30000; cnt++) {
395 if ((RD_REG_WORD(&reg->hccr) &
396 HCCR_RISC_PAUSE) != 0)
397 break;
398 udelay(100);
399 }
400 } else {
401 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
402 udelay(10);
403 }
404
405 /* Select FPM registers. */
406 WRT_REG_WORD(&reg->ctrl_status, 0x20);
407 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
408
409 /* FPM Soft Reset. */
410 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
411 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
412
413 /* Toggle Fpm Reset. */
414 if (!IS_QLA2200(ha)) {
415 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
416 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
417 }
418
419 /* Select frame buffer registers. */
420 WRT_REG_WORD(&reg->ctrl_status, 0x10);
421 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
422
423 /* Reset frame buffer FIFOs. */
424 if (IS_QLA2200(ha)) {
425 WRT_FB_CMD_REG(ha, reg, 0xa000);
426 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
427 } else {
428 WRT_FB_CMD_REG(ha, reg, 0x00fc);
429
430 /* Read back fb_cmd until zero or 3 seconds max */
431 for (cnt = 0; cnt < 3000; cnt++) {
432 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
433 break;
434 udelay(100);
435 }
436 }
437
438 /* Select RISC module registers. */
439 WRT_REG_WORD(&reg->ctrl_status, 0);
440 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
441
442 /* Reset RISC processor. */
443 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
444 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
445
446 /* Release RISC processor. */
447 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
448 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
449 }
450
451 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
452 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
453
454 /* Reset ISP chip. */
455 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
456
457 /* Wait for RISC to recover from reset. */
458 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
459 /*
460 * It is necessary to for a delay here since the card doesn't
461 * respond to PCI reads during a reset. On some architectures
462 * this will result in an MCA.
463 */
464 udelay(20);
465 for (cnt = 30000; cnt; cnt--) {
466 if ((RD_REG_WORD(&reg->ctrl_status) &
467 CSR_ISP_SOFT_RESET) == 0)
468 break;
469 udelay(100);
470 }
471 } else
472 udelay(10);
473
474 /* Reset RISC processor. */
475 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
476
477 WRT_REG_WORD(&reg->semaphore, 0);
478
479 /* Release RISC processor. */
480 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
481 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
482
483 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
484 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700485 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
488 udelay(100);
489 }
490 } else
491 udelay(100);
492
493 /* Turn on master enable */
494 cmd |= PCI_COMMAND_MASTER;
495 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
496
497 /* Disable RISC pause on FPM parity error. */
498 if (!IS_QLA2100(ha)) {
499 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
500 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
501 }
502
503 spin_unlock_irqrestore(&ha->hardware_lock, flags);
504}
505
506/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700507 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700508 * @ha: HA context
509 *
510 * Returns 0 on success.
511 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700512static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700514{
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700515 int hw_evt = 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700516 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700518 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
519 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800520 uint16_t wd;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700521
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700522 spin_lock_irqsave(&ha->hardware_lock, flags);
523
524 /* Reset RISC. */
525 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
526 for (cnt = 0; cnt < 30000; cnt++) {
527 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
528 break;
529
530 udelay(10);
531 }
532
533 WRT_REG_DWORD(&reg->ctrl_status,
534 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800535 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700536
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800537 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700538 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700539 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
540 for (cnt = 10000 ; cnt && d2; cnt--) {
541 udelay(5);
542 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
543 barrier();
544 }
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700545 if (cnt == 0)
546 hw_evt = 1;
Andrew Vasquez88c26662005-07-08 17:59:26 -0700547
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800548 /* Wait for soft-reset to complete. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700549 d2 = RD_REG_DWORD(&reg->ctrl_status);
550 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
551 udelay(5);
552 d2 = RD_REG_DWORD(&reg->ctrl_status);
553 barrier();
554 }
555
556 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
557 RD_REG_DWORD(&reg->hccr);
558
559 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
560 RD_REG_DWORD(&reg->hccr);
561
562 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
563 RD_REG_DWORD(&reg->hccr);
564
565 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
566 for (cnt = 6000000 ; cnt && d2; cnt--) {
567 udelay(5);
568 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
569 barrier();
570 }
571
572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800573
574 if (IS_NOPOLLING_TYPE(ha))
575 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700576}
577
578/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700579 * qla24xx_reset_chip() - Reset ISP24xx chip.
580 * @ha: HA context
581 *
582 * Returns 0 on success.
583 */
584void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700586{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700588 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700589
590 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700592}
593
594/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 * qla2x00_chip_diag() - Test chip for proper operation.
596 * @ha: HA context
597 *
598 * Returns 0 on success.
599 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700600int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800604 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700605 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 unsigned long flags = 0;
607 uint16_t data;
608 uint32_t cnt;
609 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800610 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 /* Assume a failed state */
613 rval = QLA_FUNCTION_FAILED;
614
615 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800616 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 spin_lock_irqsave(&ha->hardware_lock, flags);
619
620 /* Reset ISP chip. */
621 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
622
623 /*
624 * We need to have a delay here since the card will not respond while
625 * in reset causing an MCA on some architectures.
626 */
627 udelay(20);
628 data = qla2x00_debounce_register(&reg->ctrl_status);
629 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
630 udelay(5);
631 data = RD_REG_WORD(&reg->ctrl_status);
632 barrier();
633 }
634
635 if (!cnt)
636 goto chip_diag_failed;
637
638 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
639 ha->host_no));
640
641 /* Reset RISC processor. */
642 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
643 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
644
645 /* Workaround for QLA2312 PCI parity error */
646 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
647 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
648 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
649 udelay(5);
650 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700651 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653 } else
654 udelay(10);
655
656 if (!cnt)
657 goto chip_diag_failed;
658
659 /* Check product ID of chip */
660 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
661
662 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
663 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
664 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
665 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
666 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
667 mb[3] != PROD_ID_3) {
668 qla_printk(KERN_WARNING, ha,
669 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
670
671 goto chip_diag_failed;
672 }
673 ha->product_id[0] = mb[1];
674 ha->product_id[1] = mb[2];
675 ha->product_id[2] = mb[3];
676 ha->product_id[3] = mb[4];
677
678 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800679 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
681 else
682 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800683 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
685 if (IS_QLA2200(ha) &&
686 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
687 /* Limit firmware transfer size with a 2200A */
688 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800691 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 ha->fw_transfer_size = 128;
693 }
694
695 /* Wrap Incoming Mailboxes Test. */
696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
699 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 if (rval) {
701 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800702 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 qla_printk(KERN_WARNING, ha,
704 "Failed mailbox send register test\n");
705 }
706 else {
707 /* Flag a successful rval */
708 rval = QLA_SUCCESS;
709 }
710 spin_lock_irqsave(&ha->hardware_lock, flags);
711
712chip_diag_failed:
713 if (rval)
714 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800715 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
718
719 return (rval);
720}
721
722/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700723 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
724 * @ha: HA context
725 *
726 * Returns 0 on success.
727 */
728int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800729qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700730{
731 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800732 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800733 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700734
Andrew Vasquez88c26662005-07-08 17:59:26 -0700735 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800736 qla24xx_reset_risc(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700737
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800738 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700741 if (rval) {
742 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800743 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700744 qla_printk(KERN_WARNING, ha,
745 "Failed mailbox send register test\n");
746 } else {
747 /* Flag a successful rval */
748 rval = QLA_SUCCESS;
749 }
750
751 return rval;
752}
753
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700754void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700756{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700757 int rval;
758 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800759 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800760 dma_addr_t tc_dma;
761 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800762 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800763 struct req_que *req = ha->req_q_map[0];
764 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700765
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700766 if (ha->fw_dump) {
767 qla_printk(KERN_WARNING, ha,
768 "Firmware dump previously allocated.\n");
769 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700770 }
771
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700772 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800773 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700774 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
775 fixed_size = sizeof(struct qla2100_fw_dump);
776 } else if (IS_QLA23XX(ha)) {
777 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
778 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
779 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700780 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800781 if (IS_QLA81XX(ha))
782 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
783 else if (IS_QLA25XX(ha))
784 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
785 else
786 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700787 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
788 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800789 if (ha->mqenable)
790 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700791
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700792 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800793 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700794 goto try_eft;
795
796 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
797 GFP_KERNEL);
798 if (!tc) {
799 qla_printk(KERN_WARNING, ha, "Unable to allocate "
800 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800801 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700802 }
803
804 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800805 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700806 ha->fce_mb, &ha->fce_bufs);
807 if (rval) {
808 qla_printk(KERN_WARNING, ha, "Unable to initialize "
809 "FCE (%d).\n", rval);
810 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
811 tc_dma);
812 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800813 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700814 }
815
816 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
817 FCE_SIZE / 1024);
818
819 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
820 ha->flags.fce_enabled = 1;
821 ha->fce_dma = tc_dma;
822 ha->fce = tc;
823try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700824 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800825 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700826 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800827 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700828 qla_printk(KERN_WARNING, ha, "Unable to allocate "
829 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
830 goto cont_alloc;
831 }
832
Andrew Vasquezfc447652008-01-17 09:02:18 -0800833 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800834 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700835 if (rval) {
836 qla_printk(KERN_WARNING, ha, "Unable to initialize "
837 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800838 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
839 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700840 goto cont_alloc;
841 }
842
843 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
844 EFT_SIZE / 1024);
845
846 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800847 ha->eft_dma = tc_dma;
848 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700849 }
850cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800851 req_q_size = req->length * sizeof(request_t);
852 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700853
854 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
855 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800856 eft_size;
857 ha->chain_offset = dump_size;
858 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700859
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700860 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700861 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700862 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700863 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700864
865 if (ha->eft) {
866 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
867 ha->eft_dma);
868 ha->eft = NULL;
869 ha->eft_dma = 0;
870 }
871 return;
872 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700873 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
874 dump_size / 1024);
875
876 ha->fw_dump_len = dump_size;
877 ha->fw_dump->signature[0] = 'Q';
878 ha->fw_dump->signature[1] = 'L';
879 ha->fw_dump->signature[2] = 'G';
880 ha->fw_dump->signature[3] = 'C';
881 ha->fw_dump->version = __constant_htonl(1);
882
883 ha->fw_dump->fixed_size = htonl(fixed_size);
884 ha->fw_dump->mem_size = htonl(mem_size);
885 ha->fw_dump->req_q_size = htonl(req_q_size);
886 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
887
888 ha->fw_dump->eft_size = htonl(eft_size);
889 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
890 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
891
892 ha->fw_dump->header_size =
893 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700894}
895
896/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
898 * @ha: HA context
899 *
900 * Returns 0 on success.
901 */
902static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903qla2x00_resize_request_q(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904{
905 int rval;
906 uint16_t fw_iocb_cnt = 0;
907 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
908 dma_addr_t request_dma;
909 request_t *request_ring;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800910 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800911 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 /* Valid only on recent ISPs. */
914 if (IS_QLA2100(ha) || IS_QLA2200(ha))
915 return;
916
917 /* Retrieve IOCB counts available to the firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800918 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
919 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (rval)
921 return;
922 /* No point in continuing if current settings are sufficient. */
923 if (fw_iocb_cnt < 1024)
924 return;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 if (req->length >= request_q_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 return;
927
928 /* Attempt to claim larger area for request queue. */
929 request_ring = dma_alloc_coherent(&ha->pdev->dev,
930 (request_q_length + 1) * sizeof(request_t), &request_dma,
931 GFP_KERNEL);
932 if (request_ring == NULL)
933 return;
934
935 /* Resize successful, report extensions. */
936 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
937 (ha->fw_memory_size + 1) / 1024);
938 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 "(%d -> %d)...\n", req->length, request_q_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940
941 /* Clear old allocations. */
942 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800943 (req->length + 1) * sizeof(request_t), req->ring,
944 req->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945
946 /* Begin using larger queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800947 req->length = request_q_length;
948 req->ring = request_ring;
949 req->dma = request_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950}
951
952/**
953 * qla2x00_setup_chip() - Load and start RISC firmware.
954 * @ha: HA context
955 *
956 * Returns 0 on success.
957 */
958static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800959qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700961 int rval;
962 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800963 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800964 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
965 unsigned long flags;
966
967 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
968 /* Disable SRAM, Instruction RAM and GP RAM parity. */
969 spin_lock_irqsave(&ha->hardware_lock, flags);
970 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
971 RD_REG_WORD(&reg->hccr);
972 spin_unlock_irqrestore(&ha->hardware_lock, flags);
973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700977 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800979 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800981 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982 if (rval == QLA_SUCCESS) {
983 /* Start firmware execution. */
984 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800985 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800987 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 /* Retrieve firmware information. */
989 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800990 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 &ha->fw_major_version,
992 &ha->fw_minor_version,
993 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800994 &ha->fw_attributes, &ha->fw_memory_size,
995 ha->mpi_version, &ha->mpi_capabilities);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700996 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800997 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700998 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700999 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001000 if ((!ha->max_npiv_vports) ||
1001 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001002 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001003 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001004 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001005 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001006 qla2x00_resize_request_q(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001007
1008 if (ql2xallocfwdump)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001009 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 }
1011 } else {
1012 DEBUG2(printk(KERN_INFO
1013 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001014 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001015 }
1016 }
1017
Andrew Vasquez3db06522008-01-31 12:33:49 -08001018 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1019 /* Enable proper parity. */
1020 spin_lock_irqsave(&ha->hardware_lock, flags);
1021 if (IS_QLA2300(ha))
1022 /* SRAM parity */
1023 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1024 else
1025 /* SRAM, Instruction RAM and GP RAM parity */
1026 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1027 RD_REG_WORD(&reg->hccr);
1028 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1029 }
1030
Linus Torvalds1da177e2005-04-16 15:20:36 -07001031 if (rval) {
1032 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001033 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 }
1035
1036 return (rval);
1037}
1038
1039/**
1040 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1041 * @ha: HA context
1042 *
1043 * Beginning of request ring has initialization control block already built
1044 * by nvram config routine.
1045 *
1046 * Returns 0 on success.
1047 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001048void
1049qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050{
1051 uint16_t cnt;
1052 response_t *pkt;
1053
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001054 pkt = rsp->ring_ptr;
1055 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056 pkt->signature = RESPONSE_PROCESSED;
1057 pkt++;
1058 }
1059
1060}
1061
1062/**
1063 * qla2x00_update_fw_options() - Read and process firmware options.
1064 * @ha: HA context
1065 *
1066 * Returns 0 on success.
1067 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001068void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001069qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070{
1071 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001072 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073
1074 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1078 return;
1079
1080 /* Serial Link options. */
1081 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001082 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001083 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1084 sizeof(ha->fw_seriallink_options)));
1085
1086 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1087 if (ha->fw_seriallink_options[3] & BIT_2) {
1088 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1089
1090 /* 1G settings */
1091 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1092 emphasis = (ha->fw_seriallink_options[2] &
1093 (BIT_4 | BIT_3)) >> 3;
1094 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001095 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096 rx_sens = (ha->fw_seriallink_options[0] &
1097 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1098 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1099 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1100 if (rx_sens == 0x0)
1101 rx_sens = 0x3;
1102 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1103 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1104 ha->fw_options[10] |= BIT_5 |
1105 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1106 (tx_sens & (BIT_1 | BIT_0));
1107
1108 /* 2G settings */
1109 swing = (ha->fw_seriallink_options[2] &
1110 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1111 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1112 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001113 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001114 rx_sens = (ha->fw_seriallink_options[1] &
1115 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1116 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1117 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1118 if (rx_sens == 0x0)
1119 rx_sens = 0x3;
1120 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1121 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1122 ha->fw_options[11] |= BIT_5 |
1123 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1124 (tx_sens & (BIT_1 | BIT_0));
1125 }
1126
1127 /* FCP2 options. */
1128 /* Return command IOCBs without waiting for an ABTS to complete. */
1129 ha->fw_options[3] |= BIT_13;
1130
1131 /* LED scheme. */
1132 if (ha->flags.enable_led_scheme)
1133 ha->fw_options[2] |= BIT_12;
1134
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001135 /* Detect ISP6312. */
1136 if (IS_QLA6312(ha))
1137 ha->fw_options[2] |= BIT_13;
1138
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001140 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001141}
1142
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001143void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001145{
1146 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001147 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001148
1149 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001150 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001151 return;
1152
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001153 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001154 le16_to_cpu(ha->fw_seriallink_options24[1]),
1155 le16_to_cpu(ha->fw_seriallink_options24[2]),
1156 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001157 if (rval != QLA_SUCCESS) {
1158 qla_printk(KERN_WARNING, ha,
1159 "Unable to update Serial Link options (%x).\n", rval);
1160 }
1161}
1162
1163void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001164qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001165{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001166 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001167 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001168 struct req_que *req = ha->req_q_map[0];
1169 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001170
1171 /* Setup ring parameters in initialization control block. */
1172 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1173 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001174 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1175 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1176 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1177 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1178 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1179 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001180
1181 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1182 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1183 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1184 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1185 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1186}
1187
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001188void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001189qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001190{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001191 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001192 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1193 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1194 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001195 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001196 uint16_t rid = 0;
1197 struct req_que *req = ha->req_q_map[0];
1198 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001199
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001200/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001201 icb = (struct init_cb_24xx *)ha->init_cb;
1202 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1203 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001204 icb->request_q_length = cpu_to_le16(req->length);
1205 icb->response_q_length = cpu_to_le16(rsp->length);
1206 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1207 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1208 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1209 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001210
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001211 if (ha->mqenable) {
1212 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1213 icb->rid = __constant_cpu_to_le16(rid);
1214 if (ha->flags.msix_enabled) {
1215 msix = &ha->msix_entries[1];
1216 DEBUG2_17(printk(KERN_INFO
1217 "Reistering vector 0x%x for base que\n", msix->entry));
1218 icb->msix = cpu_to_le16(msix->entry);
1219 }
1220 /* Use alternate PCI bus number */
1221 if (MSB(rid))
1222 icb->firmware_options_2 |=
1223 __constant_cpu_to_le32(BIT_19);
1224 /* Use alternate PCI devfn */
1225 if (LSB(rid))
1226 icb->firmware_options_2 |=
1227 __constant_cpu_to_le32(BIT_18);
1228
1229 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
1230 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1231 ha->rsp_q_map[0]->options = icb->firmware_options_2;
1232
1233 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1234 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1235 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1236 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1237 } else {
1238 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1239 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1240 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1241 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1242 }
1243 /* PCI posting */
1244 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001245}
1246
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247/**
1248 * qla2x00_init_rings() - Initializes firmware.
1249 * @ha: HA context
1250 *
1251 * Beginning of request ring has initialization control block already built
1252 * by nvram config routine.
1253 *
1254 * Returns 0 on success.
1255 */
1256static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001257qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258{
1259 int rval;
1260 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001261 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001262 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001263 struct req_que *req;
1264 struct rsp_que *rsp;
1265 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001266 struct mid_init_cb_24xx *mid_init_cb =
1267 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001268
1269 spin_lock_irqsave(&ha->hardware_lock, flags);
1270
1271 /* Clear outstanding commands array. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001272 for (que = 0; que < ha->max_queues; que++) {
1273 req = ha->req_q_map[que];
1274 if (!req)
1275 continue;
1276 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1277 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001279 req->current_outstanding_cmd = 0;
1280
1281 /* Initialize firmware. */
1282 req->ring_ptr = req->ring;
1283 req->ring_index = 0;
1284 req->cnt = req->length;
1285 }
1286
1287 for (que = 0; que < ha->max_queues; que++) {
1288 rsp = ha->rsp_q_map[que];
1289 if (!rsp)
1290 continue;
1291 rsp->ring_ptr = rsp->ring;
1292 rsp->ring_index = 0;
1293
1294 /* Initialize response queue entries */
1295 qla2x00_init_response_q_entries(rsp);
1296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297
1298 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001299 list_for_each_entry(vp, &ha->vp_list, list) {
1300 vp->rscn_in_ptr = 0;
1301 vp->rscn_out_ptr = 0;
1302 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001303 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
1305 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1306
1307 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001310 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001311
Seokmann Juc48339d2008-01-17 09:02:19 -08001312 if (ha->flags.npiv_supported)
1313 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1314
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001315 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001316
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001317 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 if (rval) {
1319 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001320 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001321 } else {
1322 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001323 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 }
1325
1326 return (rval);
1327}
1328
1329/**
1330 * qla2x00_fw_ready() - Waits for firmware ready.
1331 * @ha: HA context
1332 *
1333 * Returns 0 on success.
1334 */
1335static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001336qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001337{
1338 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001339 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 uint16_t min_wait; /* Minimum wait time if loop is down */
1341 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001342 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344
1345 rval = QLA_SUCCESS;
1346
1347 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001348 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349
1350 /*
1351 * Firmware should take at most one RATOV to login, plus 5 seconds for
1352 * our own processing.
1353 */
1354 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1355 wait_time = min_wait;
1356 }
1357
1358 /* Min wait time if loop down */
1359 mtime = jiffies + (min_wait * HZ);
1360
1361 /* wait time before firmware ready */
1362 wtime = jiffies + (wait_time * HZ);
1363
1364 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001366 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1367
1368 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001369 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001370
1371 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001372 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001373 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001374 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001375 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001377 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1378 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001379 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001380 state[2]));
1381 if ((state[2] & FSTATE_LOGGED_IN) &&
1382 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1383 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001384 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001385
1386 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001387 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001388 if (rval != QLA_SUCCESS)
1389 break;
1390
1391 /* Add time taken to initialize. */
1392 cs84xx_time = jiffies - cs84xx_time;
1393 wtime += cs84xx_time;
1394 mtime += cs84xx_time;
1395 DEBUG16(printk("scsi(%ld): Increasing "
1396 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001397 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001398 }
1399 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001401 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001403 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 &ha->login_timeout, &ha->r_a_tov);
1405
1406 rval = QLA_SUCCESS;
1407 break;
1408 }
1409
1410 rval = QLA_FUNCTION_FAILED;
1411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001412 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001413 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001414 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001415 * other than Wait for Login.
1416 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 if (time_after_eq(jiffies, mtime)) {
1418 qla_printk(KERN_INFO, ha,
1419 "Cable is unplugged...\n");
1420
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001421 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 break;
1423 }
1424 }
1425 } else {
1426 /* Mailbox cmd failed. Timeout on min_wait. */
1427 if (time_after_eq(jiffies, mtime))
1428 break;
1429 }
1430
1431 if (time_after_eq(jiffies, wtime))
1432 break;
1433
1434 /* Delay for a while */
1435 msleep(500);
1436
1437 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001438 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001439 } while (1);
1440
1441 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001442 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
1444 if (rval) {
1445 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001446 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 }
1448
1449 return (rval);
1450}
1451
1452/*
1453* qla2x00_configure_hba
1454* Setup adapter context.
1455*
1456* Input:
1457* ha = adapter state pointer.
1458*
1459* Returns:
1460* 0 = success
1461*
1462* Context:
1463* Kernel context.
1464*/
1465static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001466qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467{
1468 int rval;
1469 uint16_t loop_id;
1470 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001471 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472 uint8_t al_pa;
1473 uint8_t area;
1474 uint8_t domain;
1475 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001476 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477
1478 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001479 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001480 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001482 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001483 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1484 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001486 } else {
1487 qla_printk(KERN_WARNING, ha,
1488 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001489 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 return (rval);
1492 }
1493
1494 if (topo == 4) {
1495 qla_printk(KERN_INFO, ha,
1496 "Cannot get topology - retrying.\n");
1497 return (QLA_FUNCTION_FAILED);
1498 }
1499
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001500 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501
1502 /* initialize */
1503 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1504 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001505 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001506
1507 switch (topo) {
1508 case 0:
1509 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001510 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 ha->current_topology = ISP_CFG_NL;
1512 strcpy(connect_type, "(Loop)");
1513 break;
1514
1515 case 1:
1516 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001517 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001518 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 ha->current_topology = ISP_CFG_FL;
1520 strcpy(connect_type, "(FL_Port)");
1521 break;
1522
1523 case 2:
1524 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001525 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 ha->operating_mode = P2P;
1527 ha->current_topology = ISP_CFG_N;
1528 strcpy(connect_type, "(N_Port-to-N_Port)");
1529 break;
1530
1531 case 3:
1532 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001533 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001534 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 ha->operating_mode = P2P;
1536 ha->current_topology = ISP_CFG_F;
1537 strcpy(connect_type, "(F_Port)");
1538 break;
1539
1540 default:
1541 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1542 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001543 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 ha->current_topology = ISP_CFG_NL;
1545 strcpy(connect_type, "(Loop)");
1546 break;
1547 }
1548
1549 /* Save Host port and loop ID. */
1550 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001551 vha->d_id.b.domain = domain;
1552 vha->d_id.b.area = area;
1553 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001555 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 qla_printk(KERN_INFO, ha,
1557 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001558 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001559
1560 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001561 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001563 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 }
1565
1566 return(rval);
1567}
1568
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001569static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001570qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1571 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001572{
1573 char *st, *en;
1574 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001575 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001576
1577 if (memcmp(model, BINZERO, len) != 0) {
1578 strncpy(ha->model_number, model, len);
1579 st = en = ha->model_number;
1580 en += len - 1;
1581 while (en > st) {
1582 if (*en != 0x20 && *en != 0x00)
1583 break;
1584 *en-- = '\0';
1585 }
1586
1587 index = (ha->pdev->subsystem_device & 0xff);
1588 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1589 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001590 strncpy(ha->model_desc,
1591 qla2x00_model_name[index * 2 + 1],
1592 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001593 } else {
1594 index = (ha->pdev->subsystem_device & 0xff);
1595 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1596 index < QLA_MODEL_NAMES) {
1597 strcpy(ha->model_number,
1598 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001599 strncpy(ha->model_desc,
1600 qla2x00_model_name[index * 2 + 1],
1601 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001602 } else {
1603 strcpy(ha->model_number, def);
1604 }
1605 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001606 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001607 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001608 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001609}
1610
David Miller4e08df32007-04-16 12:37:43 -07001611/* On sparc systems, obtain port and node WWN from firmware
1612 * properties.
1613 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001614static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001615{
1616#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001617 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001618 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001619 struct device_node *dp = pci_device_to_OF_node(pdev);
1620 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001621 int len;
1622
1623 val = of_get_property(dp, "port-wwn", &len);
1624 if (val && len >= WWN_SIZE)
1625 memcpy(nv->port_name, val, WWN_SIZE);
1626
1627 val = of_get_property(dp, "node-wwn", &len);
1628 if (val && len >= WWN_SIZE)
1629 memcpy(nv->node_name, val, WWN_SIZE);
1630#endif
1631}
1632
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633/*
1634* NVRAM configuration for ISP 2xxx
1635*
1636* Input:
1637* ha = adapter block pointer.
1638*
1639* Output:
1640* initialization control block in response_ring
1641* host adapters parameters in host adapter block
1642*
1643* Returns:
1644* 0 = success.
1645*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001646int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001647qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648{
David Miller4e08df32007-04-16 12:37:43 -07001649 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001650 uint8_t chksum = 0;
1651 uint16_t cnt;
1652 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001653 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001654 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001655 nvram_t *nv = ha->nvram;
1656 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001657 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
David Miller4e08df32007-04-16 12:37:43 -07001659 rval = QLA_SUCCESS;
1660
Linus Torvalds1da177e2005-04-16 15:20:36 -07001661 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001662 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 ha->nvram_base = 0;
1664 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1665 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1666 ha->nvram_base = 0x80;
1667
1668 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001669 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001670 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1671 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001673 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001674 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001675
1676 /* Bad NVRAM data, set defaults parameters. */
1677 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1678 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1679 /* Reset NVRAM data. */
1680 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1681 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1682 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001683 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1684 "invalid -- WWPN) defaults.\n");
1685
1686 /*
1687 * Set default initialization control block.
1688 */
1689 memset(nv, 0, ha->nvram_size);
1690 nv->parameter_block_version = ICB_VERSION;
1691
1692 if (IS_QLA23XX(ha)) {
1693 nv->firmware_options[0] = BIT_2 | BIT_1;
1694 nv->firmware_options[1] = BIT_7 | BIT_5;
1695 nv->add_firmware_options[0] = BIT_5;
1696 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1697 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1698 nv->special_options[1] = BIT_7;
1699 } else if (IS_QLA2200(ha)) {
1700 nv->firmware_options[0] = BIT_2 | BIT_1;
1701 nv->firmware_options[1] = BIT_7 | BIT_5;
1702 nv->add_firmware_options[0] = BIT_5;
1703 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1704 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1705 } else if (IS_QLA2100(ha)) {
1706 nv->firmware_options[0] = BIT_3 | BIT_1;
1707 nv->firmware_options[1] = BIT_5;
1708 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1709 }
1710
1711 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1712 nv->execution_throttle = __constant_cpu_to_le16(16);
1713 nv->retry_count = 8;
1714 nv->retry_delay = 1;
1715
1716 nv->port_name[0] = 33;
1717 nv->port_name[3] = 224;
1718 nv->port_name[4] = 139;
1719
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001720 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001721
1722 nv->login_timeout = 4;
1723
1724 /*
1725 * Set default host adapter parameters
1726 */
1727 nv->host_p[1] = BIT_2;
1728 nv->reset_delay = 5;
1729 nv->port_down_retry_count = 8;
1730 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1731 nv->link_down_timeout = 60;
1732
1733 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 }
1735
1736#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1737 /*
1738 * The SN2 does not provide BIOS emulation which means you can't change
1739 * potentially bogus BIOS settings. Force the use of default settings
1740 * for link rate and frame size. Hope that the rest of the settings
1741 * are valid.
1742 */
1743 if (ia64_platform_is("sn2")) {
1744 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1745 if (IS_QLA23XX(ha))
1746 nv->special_options[1] = BIT_7;
1747 }
1748#endif
1749
1750 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001751 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001752
1753 /*
1754 * Setup driver NVRAM options.
1755 */
1756 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1757 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1758 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1759 nv->firmware_options[1] &= ~BIT_4;
1760
1761 if (IS_QLA23XX(ha)) {
1762 nv->firmware_options[0] |= BIT_2;
1763 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001764 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
1766 if (IS_QLA2300(ha)) {
1767 if (ha->fb_rev == FPM_2310) {
1768 strcpy(ha->model_number, "QLA2310");
1769 } else {
1770 strcpy(ha->model_number, "QLA2300");
1771 }
1772 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001773 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001774 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001775 }
1776 } else if (IS_QLA2200(ha)) {
1777 nv->firmware_options[0] |= BIT_2;
1778 /*
1779 * 'Point-to-point preferred, else loop' is not a safe
1780 * connection mode setting.
1781 */
1782 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1783 (BIT_5 | BIT_4)) {
1784 /* Force 'loop preferred, else point-to-point'. */
1785 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1786 nv->add_firmware_options[0] |= BIT_5;
1787 }
1788 strcpy(ha->model_number, "QLA22xx");
1789 } else /*if (IS_QLA2100(ha))*/ {
1790 strcpy(ha->model_number, "QLA2100");
1791 }
1792
1793 /*
1794 * Copy over NVRAM RISC parameter block to initialization control block.
1795 */
1796 dptr1 = (uint8_t *)icb;
1797 dptr2 = (uint8_t *)&nv->parameter_block_version;
1798 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1799 while (cnt--)
1800 *dptr1++ = *dptr2++;
1801
1802 /* Copy 2nd half. */
1803 dptr1 = (uint8_t *)icb->add_firmware_options;
1804 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1805 while (cnt--)
1806 *dptr1++ = *dptr2++;
1807
Andrew Vasquez5341e862006-05-17 15:09:16 -07001808 /* Use alternate WWN? */
1809 if (nv->host_p[1] & BIT_7) {
1810 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1811 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1812 }
1813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 /* Prepare nodename */
1815 if ((icb->firmware_options[1] & BIT_6) == 0) {
1816 /*
1817 * Firmware will apply the following mask if the nodename was
1818 * not provided.
1819 */
1820 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1821 icb->node_name[0] &= 0xF0;
1822 }
1823
1824 /*
1825 * Set host adapter parameters.
1826 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001827 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001828 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1830 /* Always load RISC code on non ISP2[12]00 chips. */
1831 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1832 ha->flags.disable_risc_code_load = 0;
1833 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1834 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1835 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001836 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001837 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838
1839 ha->operating_mode =
1840 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1841
1842 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1843 sizeof(ha->fw_seriallink_options));
1844
1845 /* save HBA serial number */
1846 ha->serial0 = icb->port_name[5];
1847 ha->serial1 = icb->port_name[6];
1848 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001849 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1850 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851
1852 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1853
1854 ha->retry_count = nv->retry_count;
1855
1856 /* Set minimum login_timeout to 4 seconds. */
1857 if (nv->login_timeout < ql2xlogintimeout)
1858 nv->login_timeout = ql2xlogintimeout;
1859 if (nv->login_timeout < 4)
1860 nv->login_timeout = 4;
1861 ha->login_timeout = nv->login_timeout;
1862 icb->login_timeout = nv->login_timeout;
1863
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001864 /* Set minimum RATOV to 100 tenths of a second. */
1865 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867 ha->loop_reset_delay = nv->reset_delay;
1868
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 /* Link Down Timeout = 0:
1870 *
1871 * When Port Down timer expires we will start returning
1872 * I/O's to OS with "DID_NO_CONNECT".
1873 *
1874 * Link Down Timeout != 0:
1875 *
1876 * The driver waits for the link to come up after link down
1877 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001878 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001879 if (nv->link_down_timeout == 0) {
1880 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001881 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 } else {
1883 ha->link_down_timeout = nv->link_down_timeout;
1884 ha->loop_down_abort_time =
1885 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 /*
1889 * Need enough time to try and get the port back.
1890 */
1891 ha->port_down_retry_count = nv->port_down_retry_count;
1892 if (qlport_down_retry)
1893 ha->port_down_retry_count = qlport_down_retry;
1894 /* Set login_retry_count */
1895 ha->login_retry_count = nv->retry_count;
1896 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1897 ha->port_down_retry_count > 3)
1898 ha->login_retry_count = ha->port_down_retry_count;
1899 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1900 ha->login_retry_count = ha->port_down_retry_count;
1901 if (ql2xloginretrycount)
1902 ha->login_retry_count = ql2xloginretrycount;
1903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 icb->lun_enables = __constant_cpu_to_le16(0);
1905 icb->command_resource_count = 0;
1906 icb->immediate_notify_resource_count = 0;
1907 icb->timeout = __constant_cpu_to_le16(0);
1908
1909 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1910 /* Enable RIO */
1911 icb->firmware_options[0] &= ~BIT_3;
1912 icb->add_firmware_options[0] &=
1913 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1914 icb->add_firmware_options[0] |= BIT_2;
1915 icb->response_accumulation_timer = 3;
1916 icb->interrupt_delay_timer = 5;
1917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001918 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001920 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001921 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001922 ha->zio_mode = icb->add_firmware_options[0] &
1923 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1924 ha->zio_timer = icb->interrupt_delay_timer ?
1925 icb->interrupt_delay_timer: 2;
1926 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927 icb->add_firmware_options[0] &=
1928 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001930 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001931 ha->zio_mode = QLA_ZIO_MODE_6;
1932
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001933 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001934 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001935 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001937 "ZIO mode %d enabled; timer delay (%d us).\n",
1938 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001940 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1941 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943 }
1944 }
1945
David Miller4e08df32007-04-16 12:37:43 -07001946 if (rval) {
1947 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001948 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001949 }
1950 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951}
1952
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001953static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001954qla2x00_rport_del(void *data)
1955{
1956 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001957 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001958
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001959 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001960 rport = fcport->drport;
1961 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001963 if (rport)
1964 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001965}
1966
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967/**
1968 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1969 * @ha: HA context
1970 * @flags: allocation flags
1971 *
1972 * Returns a pointer to the allocated fcport, or NULL, if none available.
1973 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001974static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001975qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976{
1977 fc_port_t *fcport;
1978
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001979 fcport = kzalloc(sizeof(fc_port_t), flags);
1980 if (!fcport)
1981 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982
1983 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 fcport->vha = vha;
1985 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 fcport->port_type = FCT_UNKNOWN;
1987 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1989 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001990 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001992 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993}
1994
1995/*
1996 * qla2x00_configure_loop
1997 * Updates Fibre Channel Device Database with what is actually on loop.
1998 *
1999 * Input:
2000 * ha = adapter block pointer.
2001 *
2002 * Returns:
2003 * 0 = success.
2004 * 1 = error.
2005 * 2 = database was full and device was not configured.
2006 */
2007static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009{
2010 int rval;
2011 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002012 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013 rval = QLA_SUCCESS;
2014
2015 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2017 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 if (rval != QLA_SUCCESS) {
2019 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 return (rval);
2022 }
2023 }
2024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028
2029 /*
2030 * If we have both an RSCN and PORT UPDATE pending then handle them
2031 * both at the same time.
2032 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2034 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
2036 /* Determine what we need to do */
2037 if (ha->current_topology == ISP_CFG_FL &&
2038 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 set_bit(RSCN_UPDATE, &flags);
2042
2043 } else if (ha->current_topology == ISP_CFG_F &&
2044 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 set_bit(RSCN_UPDATE, &flags);
2048 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2049
Andrew Vasquez21333b42006-05-17 15:09:56 -07002050 } else if (ha->current_topology == ISP_CFG_N) {
2051 clear_bit(RSCN_UPDATE, &flags);
2052
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002056 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 set_bit(RSCN_UPDATE, &flags);
2058 set_bit(LOCAL_LOOP_UPDATE, &flags);
2059 }
2060
2061 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064 else
2065 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 }
2067
2068 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002069 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002070 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002071 else
2072 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 }
2074
2075 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 if (atomic_read(&vha->loop_down_timer) ||
2077 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 rval = QLA_FUNCTION_FAILED;
2079 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002080 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002081
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002083 }
2084 }
2085
2086 if (rval) {
2087 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002088 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 } else {
2090 DEBUG3(printk("%s: exiting normally\n", __func__));
2091 }
2092
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002093 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002097 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 }
2100
2101 return (rval);
2102}
2103
2104
2105
2106/*
2107 * qla2x00_configure_local_loop
2108 * Updates Fibre Channel Device Database with local loop devices.
2109 *
2110 * Input:
2111 * ha = adapter block pointer.
2112 *
2113 * Returns:
2114 * 0 = success.
2115 */
2116static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002117qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118{
2119 int rval, rval2;
2120 int found_devs;
2121 int found;
2122 fc_port_t *fcport, *new_fcport;
2123
2124 uint16_t index;
2125 uint16_t entries;
2126 char *id_iter;
2127 uint16_t loop_id;
2128 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002129 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130
2131 found_devs = 0;
2132 new_fcport = NULL;
2133 entries = MAX_FIBRE_DEVICES;
2134
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2136 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137
2138 /* Get list of logged in devices. */
2139 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002140 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 &entries);
2142 if (rval != QLA_SUCCESS)
2143 goto cleanup_allocation;
2144
2145 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2146 ha->host_no, entries));
2147 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2148 entries * sizeof(struct gid_list_info)));
2149
2150 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002151 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152 if (new_fcport == NULL) {
2153 rval = QLA_MEMORY_ALLOC_FAILED;
2154 goto cleanup_allocation;
2155 }
2156 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2157
2158 /*
2159 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2160 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002161 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002162 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2163 fcport->port_type != FCT_BROADCAST &&
2164 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2165
2166 DEBUG(printk("scsi(%ld): Marking port lost, "
2167 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002168 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002169
2170 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2171 fcport->flags &= ~FCF_FARP_DONE;
2172 }
2173 }
2174
2175 /* Add devices to port list. */
2176 id_iter = (char *)ha->gid_list;
2177 for (index = 0; index < entries; index++) {
2178 domain = ((struct gid_list_info *)id_iter)->domain;
2179 area = ((struct gid_list_info *)id_iter)->area;
2180 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002181 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 loop_id = (uint16_t)
2183 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002184 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 loop_id = le16_to_cpu(
2186 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002187 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188
2189 /* Bypass reserved domain fields. */
2190 if ((domain & 0xf0) == 0xf0)
2191 continue;
2192
2193 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002194 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002195 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002196 continue;
2197
2198 /* Bypass invalid local loop ID. */
2199 if (loop_id > LAST_LOCAL_LOOP_ID)
2200 continue;
2201
2202 /* Fill in member data. */
2203 new_fcport->d_id.b.domain = domain;
2204 new_fcport->d_id.b.area = area;
2205 new_fcport->d_id.b.al_pa = al_pa;
2206 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002207 new_fcport->vp_idx = vha->vp_idx;
2208 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209 if (rval2 != QLA_SUCCESS) {
2210 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2211 "information -- get_port_database=%x, "
2212 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002213 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002214 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002215 vha->host_no));
2216 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002217 continue;
2218 }
2219
2220 /* Check for matching device in port list. */
2221 found = 0;
2222 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002223 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224 if (memcmp(new_fcport->port_name, fcport->port_name,
2225 WWN_SIZE))
2226 continue;
2227
2228 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2229 FCF_PERSISTENT_BOUND);
2230 fcport->loop_id = new_fcport->loop_id;
2231 fcport->port_type = new_fcport->port_type;
2232 fcport->d_id.b24 = new_fcport->d_id.b24;
2233 memcpy(fcport->node_name, new_fcport->node_name,
2234 WWN_SIZE);
2235
2236 found++;
2237 break;
2238 }
2239
2240 if (!found) {
2241 /* New device, add to fcports list. */
2242 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002243 if (vha->vp_idx) {
2244 new_fcport->vha = vha;
2245 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002246 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002247 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002248
2249 /* Allocate a new replacement fcport. */
2250 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002251 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252 if (new_fcport == NULL) {
2253 rval = QLA_MEMORY_ALLOC_FAILED;
2254 goto cleanup_allocation;
2255 }
2256 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2257 }
2258
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002259 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002260 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002263
2264 found_devs++;
2265 }
2266
2267cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002268 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
2270 if (rval != QLA_SUCCESS) {
2271 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002272 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002273 }
2274
2275 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002276 vha->device_flags |= DFLG_LOCAL_DEVICES;
2277 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002278 }
2279
2280 return (rval);
2281}
2282
2283static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002284qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002285{
2286#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002287 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002288 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002289 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002291
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002292 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002293 return;
2294
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002295 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2296 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002297 return;
2298
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002299 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002300 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002301 if (rval != QLA_SUCCESS) {
2302 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2303 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002305 fcport->port_name[2], fcport->port_name[3],
2306 fcport->port_name[4], fcport->port_name[5],
2307 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002308 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002309 } else {
2310 DEBUG2(qla_printk(KERN_INFO, ha,
2311 "iIDMA adjusted to %s GB/s on "
2312 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002313 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002314 fcport->port_name[1], fcport->port_name[2],
2315 fcport->port_name[3], fcport->port_name[4],
2316 fcport->port_name[5], fcport->port_name[6],
2317 fcport->port_name[7]));
2318 }
2319}
2320
Adrian Bunk23be3312006-11-24 02:46:01 +01002321static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002322qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002323{
2324 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002325 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002326 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002327
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002328 if (fcport->drport)
2329 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002330
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002331 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2332 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002333 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2334 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2335 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002337 if (!rport) {
2338 qla_printk(KERN_WARNING, ha,
2339 "Unable to allocate fc remote port!\n");
2340 return;
2341 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002343 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002344 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002345
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002346 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002347
2348 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002349 if (fcport->port_type == FCT_INITIATOR)
2350 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2351 if (fcport->port_type == FCT_TARGET)
2352 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002353 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002354}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
2356/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002357 * qla2x00_update_fcport
2358 * Updates device on list.
2359 *
2360 * Input:
2361 * ha = adapter block pointer.
2362 * fcport = port structure pointer.
2363 *
2364 * Return:
2365 * 0 - Success
2366 * BIT_0 - error
2367 *
2368 * Context:
2369 * Kernel context.
2370 */
2371void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002372qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002373{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002374 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002375
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002376 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002377 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002379 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002380 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002381 PORT_RETRY_TIME);
2382 fcport->flags &= ~FCF_LOGIN_NEEDED;
2383
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002385
2386 atomic_set(&fcport->state, FCS_ONLINE);
2387
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002388 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002389}
2390
2391/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002392 * qla2x00_configure_fabric
2393 * Setup SNS devices with loop ID's.
2394 *
2395 * Input:
2396 * ha = adapter block pointer.
2397 *
2398 * Returns:
2399 * 0 = success.
2400 * BIT_0 = error
2401 */
2402static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404{
2405 int rval, rval2;
2406 fc_port_t *fcport, *fcptemp;
2407 uint16_t next_loopid;
2408 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002409 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002411 struct qla_hw_data *ha = vha->hw;
2412 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413
2414 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002415 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002416 loop_id = NPH_F_PORT;
2417 else
2418 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002419 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 if (rval != QLA_SUCCESS) {
2421 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002422 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002424 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425 return (QLA_SUCCESS);
2426 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002427 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428
2429 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002430 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 if (rval2 == QLA_RSCNS_HANDLED) {
2432 /* No point doing the scan, just continue. */
2433 return (QLA_SUCCESS);
2434 }
2435 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002436 /* FDMI support. */
2437 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2439 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002442 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002443 loop_id = NPH_SNS;
2444 else
2445 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002447 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448 if (mb[0] != MBS_COMMAND_COMPLETE) {
2449 DEBUG2(qla_printk(KERN_INFO, ha,
2450 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002451 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 mb[0], mb[1], mb[2], mb[6], mb[7]));
2453 return (QLA_SUCCESS);
2454 }
2455
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2457 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 /* EMPTY */
2459 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002460 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463 /* EMPTY */
2464 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002465 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002467 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468 /* EMPTY */
2469 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002470 "failed.\n", vha->host_no));
2471 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 /* EMPTY */
2473 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002474 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 }
2476 }
2477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002478 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 if (rval != QLA_SUCCESS)
2480 break;
2481
2482 /*
2483 * Logout all previous fabric devices marked lost, except
2484 * tape devices.
2485 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002486 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2487 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 break;
2489
2490 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2491 continue;
2492
2493 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002494 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002495 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 if (fcport->loop_id != FC_NO_LOOP_ID &&
2497 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2498 fcport->port_type != FCT_INITIATOR &&
2499 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002501 fcport->loop_id,
2502 fcport->d_id.b.domain,
2503 fcport->d_id.b.area,
2504 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 fcport->loop_id = FC_NO_LOOP_ID;
2506 }
2507 }
2508 }
2509
2510 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002511 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002512
2513 /*
2514 * Scan through our port list and login entries that need to be
2515 * logged in.
2516 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2518 if (atomic_read(&vha->loop_down_timer) ||
2519 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 break;
2521
2522 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2523 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2524 continue;
2525
2526 if (fcport->loop_id == FC_NO_LOOP_ID) {
2527 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002528 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002530 if (rval != QLA_SUCCESS) {
2531 /* Ran out of IDs to use */
2532 break;
2533 }
2534 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002535 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002536 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002537 }
2538
2539 /* Exit if out of loop IDs. */
2540 if (rval != QLA_SUCCESS) {
2541 break;
2542 }
2543
2544 /*
2545 * Login and add the new devices to our port list.
2546 */
2547 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002548 if (atomic_read(&vha->loop_down_timer) ||
2549 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002550 break;
2551
2552 /* Find a new loop ID to use. */
2553 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002554 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002555 if (rval != QLA_SUCCESS) {
2556 /* Ran out of IDs to use */
2557 break;
2558 }
2559
bdf79622005-04-17 15:06:53 -05002560 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002561 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002562
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002563 if (vha->vp_idx) {
2564 fcport->vha = vha;
2565 fcport->vp_idx = vha->vp_idx;
2566 }
2567 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568 }
2569 } while (0);
2570
2571 /* Free all new device structures not processed. */
2572 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2573 list_del(&fcport->list);
2574 kfree(fcport);
2575 }
2576
2577 if (rval) {
2578 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 }
2581
2582 return (rval);
2583}
2584
2585
2586/*
2587 * qla2x00_find_all_fabric_devs
2588 *
2589 * Input:
2590 * ha = adapter block pointer.
2591 * dev = database device entry pointer.
2592 *
2593 * Returns:
2594 * 0 = success.
2595 *
2596 * Context:
2597 * Kernel context.
2598 */
2599static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2601 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602{
2603 int rval;
2604 uint16_t loop_id;
2605 fc_port_t *fcport, *new_fcport, *fcptemp;
2606 int found;
2607
2608 sw_info_t *swl;
2609 int swl_idx;
2610 int first_dev, last_dev;
2611 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 struct qla_hw_data *ha = vha->hw;
2613 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614
2615 rval = QLA_SUCCESS;
2616
2617 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002618 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002619 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 /*EMPTY*/
2621 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 kfree(swl);
2626 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 kfree(swl);
2629 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631 kfree(swl);
2632 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002633 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2635 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 }
2637 }
2638 swl_idx = 0;
2639
2640 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002642 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002643 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002644 return (QLA_MEMORY_ALLOC_FAILED);
2645 }
2646 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002647 /* Set start port ID scan at adapter ID. */
2648 first_dev = 1;
2649 last_dev = 0;
2650
2651 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002652 loop_id = ha->min_external_loopid;
2653 for (; loop_id <= ha->max_loop_id; loop_id++) {
2654 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 continue;
2656
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002657 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 break;
2659
2660 if (swl != NULL) {
2661 if (last_dev) {
2662 wrap.b24 = new_fcport->d_id.b24;
2663 } else {
2664 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2665 memcpy(new_fcport->node_name,
2666 swl[swl_idx].node_name, WWN_SIZE);
2667 memcpy(new_fcport->port_name,
2668 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002669 memcpy(new_fcport->fabric_port_name,
2670 swl[swl_idx].fabric_port_name, WWN_SIZE);
2671 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672
2673 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2674 last_dev = 1;
2675 }
2676 swl_idx++;
2677 }
2678 } else {
2679 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 if (rval != QLA_SUCCESS) {
2682 qla_printk(KERN_WARNING, ha,
2683 "SNS scan failed -- assuming zero-entry "
2684 "result...\n");
2685 list_for_each_entry_safe(fcport, fcptemp,
2686 new_fcports, list) {
2687 list_del(&fcport->list);
2688 kfree(fcport);
2689 }
2690 rval = QLA_SUCCESS;
2691 break;
2692 }
2693 }
2694
2695 /* If wrap on switch device list, exit. */
2696 if (first_dev) {
2697 wrap.b24 = new_fcport->d_id.b24;
2698 first_dev = 0;
2699 } else if (new_fcport->d_id.b24 == wrap.b24) {
2700 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002701 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002702 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2703 break;
2704 }
2705
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002706 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002707 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002708 continue;
2709
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002710 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002711 found = 0;
2712 if (ha->num_vhosts) {
2713 list_for_each_entry(vp, &ha->vp_list, list) {
2714 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2715 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002716 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002718 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002719 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002720 continue;
2721 }
2722
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002723 /* Bypass if same domain and area of adapter. */
2724 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002726 ISP_CFG_FL)
2727 continue;
2728
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 /* Bypass reserved domain fields. */
2730 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2731 continue;
2732
2733 /* Locate matching device in database. */
2734 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002735 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 if (memcmp(new_fcport->port_name, fcport->port_name,
2737 WWN_SIZE))
2738 continue;
2739
2740 found++;
2741
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002742 /* Update port state. */
2743 memcpy(fcport->fabric_port_name,
2744 new_fcport->fabric_port_name, WWN_SIZE);
2745 fcport->fp_speed = new_fcport->fp_speed;
2746
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 /*
2748 * If address the same and state FCS_ONLINE, nothing
2749 * changed.
2750 */
2751 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2752 atomic_read(&fcport->state) == FCS_ONLINE) {
2753 break;
2754 }
2755
2756 /*
2757 * If device was not a fabric device before.
2758 */
2759 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2760 fcport->d_id.b24 = new_fcport->d_id.b24;
2761 fcport->loop_id = FC_NO_LOOP_ID;
2762 fcport->flags |= (FCF_FABRIC_DEVICE |
2763 FCF_LOGIN_NEEDED);
2764 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2765 break;
2766 }
2767
2768 /*
2769 * Port ID changed or device was marked to be updated;
2770 * Log it out if still logged in and mark it for
2771 * relogin later.
2772 */
2773 fcport->d_id.b24 = new_fcport->d_id.b24;
2774 fcport->flags |= FCF_LOGIN_NEEDED;
2775 if (fcport->loop_id != FC_NO_LOOP_ID &&
2776 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2777 fcport->port_type != FCT_INITIATOR &&
2778 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002780 fcport->d_id.b.domain, fcport->d_id.b.area,
2781 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 fcport->loop_id = FC_NO_LOOP_ID;
2783 }
2784
2785 break;
2786 }
2787
2788 if (found)
2789 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790 /* If device was not in our fcports list, then add it. */
2791 list_add_tail(&new_fcport->list, new_fcports);
2792
2793 /* Allocate a new replacement fcport. */
2794 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002797 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002798 return (QLA_MEMORY_ALLOC_FAILED);
2799 }
2800 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2801 new_fcport->d_id.b24 = nxt_d_id.b24;
2802 }
2803
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002804 kfree(swl);
2805 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
2807 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002808 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002809
2810 return (rval);
2811}
2812
2813/*
2814 * qla2x00_find_new_loop_id
2815 * Scan through our port list and find a new usable loop ID.
2816 *
2817 * Input:
2818 * ha: adapter state pointer.
2819 * dev: port structure pointer.
2820 *
2821 * Returns:
2822 * qla2x00 local function return status code.
2823 *
2824 * Context:
2825 * Kernel context.
2826 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002827static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002828qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829{
2830 int rval;
2831 int found;
2832 fc_port_t *fcport;
2833 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834 struct qla_hw_data *ha = vha->hw;
2835 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836
2837 rval = QLA_SUCCESS;
2838
2839 /* Save starting loop ID. */
2840 first_loop_id = dev->loop_id;
2841
2842 for (;;) {
2843 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846
2847 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002850
2851 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 /* first loop ID. */
2854 dev->loop_id = ha->min_external_loopid;
2855 }
2856
2857 /* Check for loop ID being already in use. */
2858 found = 0;
2859 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 list_for_each_entry(vp, &ha->vp_list, list) {
2861 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2862 if (fcport->loop_id == dev->loop_id &&
2863 fcport != dev) {
2864 /* ID possibly in use */
2865 found++;
2866 break;
2867 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002868 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 if (found)
2870 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871 }
2872
2873 /* If not in use then it is free to use. */
2874 if (!found) {
2875 break;
2876 }
2877
2878 /* ID in use. Try next value. */
2879 dev->loop_id++;
2880
2881 /* If wrap around. No free ID to use. */
2882 if (dev->loop_id == first_loop_id) {
2883 dev->loop_id = FC_NO_LOOP_ID;
2884 rval = QLA_FUNCTION_FAILED;
2885 break;
2886 }
2887 }
2888
2889 return (rval);
2890}
2891
2892/*
2893 * qla2x00_device_resync
2894 * Marks devices in the database that needs resynchronization.
2895 *
2896 * Input:
2897 * ha = adapter block pointer.
2898 *
2899 * Context:
2900 * Kernel context.
2901 */
2902static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904{
2905 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 uint32_t mask;
2907 fc_port_t *fcport;
2908 uint32_t rscn_entry;
2909 uint8_t rscn_out_iter;
2910 uint8_t format;
2911 port_id_t d_id;
2912
2913 rval = QLA_RSCNS_HANDLED;
2914
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002915 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2916 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 format = MSB(MSW(rscn_entry));
2920 d_id.b.domain = LSB(MSW(rscn_entry));
2921 d_id.b.area = MSB(LSW(rscn_entry));
2922 d_id.b.al_pa = LSB(LSW(rscn_entry));
2923
2924 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2925 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 d_id.b.area, d_id.b.al_pa));
2928
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 vha->rscn_out_ptr++;
2930 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2931 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 for (rscn_out_iter = vha->rscn_out_ptr;
2935 !vha->flags.rscn_queue_overflow &&
2936 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937 rscn_out_iter = (rscn_out_iter ==
2938 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2939
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002940 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 break;
2942
2943 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002944 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 rscn_out_iter));
2946
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002947 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 }
2949
2950 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002952 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002954
2955 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002956 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 }
2958
2959 switch (format) {
2960 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002961 mask = 0xffffff;
2962 break;
2963 case 1:
2964 mask = 0xffff00;
2965 break;
2966 case 2:
2967 mask = 0xff0000;
2968 break;
2969 default:
2970 mask = 0x0;
2971 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 break;
2974 }
2975
2976 rval = QLA_SUCCESS;
2977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2980 (fcport->d_id.b24 & mask) != d_id.b24 ||
2981 fcport->port_type == FCT_BROADCAST)
2982 continue;
2983
2984 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2985 if (format != 3 ||
2986 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002988 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 }
2990 }
2991 fcport->flags &= ~FCF_FARP_DONE;
2992 }
2993 }
2994 return (rval);
2995}
2996
2997/*
2998 * qla2x00_fabric_dev_login
2999 * Login fabric target device and update FC port database.
3000 *
3001 * Input:
3002 * ha: adapter state pointer.
3003 * fcport: port structure list pointer.
3004 * next_loopid: contains value of a new loop ID that can be used
3005 * by the next login attempt.
3006 *
3007 * Returns:
3008 * qla2x00 local function return status code.
3009 *
3010 * Context:
3011 * Kernel context.
3012 */
3013static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 uint16_t *next_loopid)
3016{
3017 int rval;
3018 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003019 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
3022 rval = QLA_SUCCESS;
3023 retry = 0;
3024
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003027 /* Send an ADISC to tape devices.*/
3028 opts = 0;
3029 if (fcport->flags & FCF_TAPE_PRESENT)
3030 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003031 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003033 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003034 fcport->d_id.b.domain, fcport->d_id.b.area,
3035 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003037 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 }
3040 }
3041
3042 return (rval);
3043}
3044
3045/*
3046 * qla2x00_fabric_login
3047 * Issue fabric login command.
3048 *
3049 * Input:
3050 * ha = adapter block pointer.
3051 * device = pointer to FC device type structure.
3052 *
3053 * Returns:
3054 * 0 - Login successfully
3055 * 1 - Login failed
3056 * 2 - Initiator device
3057 * 3 - Fatal error
3058 */
3059int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003060qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003061 uint16_t *next_loopid)
3062{
3063 int rval;
3064 int retry;
3065 uint16_t tmp_loopid;
3066 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068
3069 retry = 0;
3070 tmp_loopid = 0;
3071
3072 for (;;) {
3073 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3074 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003075 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3077
3078 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080 fcport->d_id.b.domain, fcport->d_id.b.area,
3081 fcport->d_id.b.al_pa, mb, BIT_0);
3082 if (mb[0] == MBS_PORT_ID_USED) {
3083 /*
3084 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003085 * recommends the driver perform an implicit login with
3086 * the specified ID again. The ID we just used is save
3087 * here so we return with an ID that can be tried by
3088 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 */
3090 retry++;
3091 tmp_loopid = fcport->loop_id;
3092 fcport->loop_id = mb[1];
3093
3094 DEBUG(printk("Fabric Login: port in use - next "
3095 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3096 fcport->loop_id, fcport->d_id.b.domain,
3097 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3098
3099 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3100 /*
3101 * Login succeeded.
3102 */
3103 if (retry) {
3104 /* A retry occurred before. */
3105 *next_loopid = tmp_loopid;
3106 } else {
3107 /*
3108 * No retry occurred before. Just increment the
3109 * ID value for next login.
3110 */
3111 *next_loopid = (fcport->loop_id + 1);
3112 }
3113
3114 if (mb[1] & BIT_0) {
3115 fcport->port_type = FCT_INITIATOR;
3116 } else {
3117 fcport->port_type = FCT_TARGET;
3118 if (mb[1] & BIT_1) {
3119 fcport->flags |= FCF_TAPE_PRESENT;
3120 }
3121 }
3122
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003123 if (mb[10] & BIT_0)
3124 fcport->supported_classes |= FC_COS_CLASS2;
3125 if (mb[10] & BIT_1)
3126 fcport->supported_classes |= FC_COS_CLASS3;
3127
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128 rval = QLA_SUCCESS;
3129 break;
3130 } else if (mb[0] == MBS_LOOP_ID_USED) {
3131 /*
3132 * Loop ID already used, try next loop ID.
3133 */
3134 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003135 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 if (rval != QLA_SUCCESS) {
3137 /* Ran out of loop IDs to use */
3138 break;
3139 }
3140 } else if (mb[0] == MBS_COMMAND_ERROR) {
3141 /*
3142 * Firmware possibly timed out during login. If NO
3143 * retries are left to do then the device is declared
3144 * dead.
3145 */
3146 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003147 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003148 fcport->d_id.b.domain, fcport->d_id.b.area,
3149 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151
3152 rval = 1;
3153 break;
3154 } else {
3155 /*
3156 * unrecoverable / not handled error
3157 */
3158 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003159 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003160 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003161 fcport->d_id.b.domain, fcport->d_id.b.area,
3162 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3163
3164 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003165 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003166 fcport->d_id.b.domain, fcport->d_id.b.area,
3167 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003168 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003169 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003170
3171 rval = 3;
3172 break;
3173 }
3174 }
3175
3176 return (rval);
3177}
3178
3179/*
3180 * qla2x00_local_device_login
3181 * Issue local device login command.
3182 *
3183 * Input:
3184 * ha = adapter block pointer.
3185 * loop_id = loop id of device to login to.
3186 *
3187 * Returns (Where's the #define!!!!):
3188 * 0 - Login successfully
3189 * 1 - Login failed
3190 * 3 - Fatal error
3191 */
3192int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194{
3195 int rval;
3196 uint16_t mb[MAILBOX_REGISTER_COUNT];
3197
3198 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003199 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 if (rval == QLA_SUCCESS) {
3201 /* Interrogate mailbox registers for any errors */
3202 if (mb[0] == MBS_COMMAND_ERROR)
3203 rval = 1;
3204 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3205 /* device not in PCB table */
3206 rval = 3;
3207 }
3208
3209 return (rval);
3210}
3211
3212/*
3213 * qla2x00_loop_resync
3214 * Resync with fibre channel devices.
3215 *
3216 * Input:
3217 * ha = adapter block pointer.
3218 *
3219 * Returns:
3220 * 0 = success
3221 */
3222int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003223qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003225 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003227 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003228 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
3229 struct rsp_que *rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 atomic_set(&vha->loop_state, LOOP_UPDATE);
3232 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3233 if (vha->flags.online) {
3234 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3236 wait_time = 256;
3237 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003240 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003241 qla2x00_marker(vha, req, rsp, 0, 0,
3242 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003243 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244
3245 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003248 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 } while (!atomic_read(&vha->loop_down_timer) &&
3251 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3252 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3253 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 }
3256
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262
3263 return (rval);
3264}
3265
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003268{
3269 fc_port_t *fcport;
3270
3271 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272 list_for_each_entry(fcport, &vha->vp_fcports, list)
3273 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003274 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003275 qla2x00_rport_del(fcport);
3276}
3277
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278/*
3279* qla2x00_abort_isp
3280* Resets ISP and aborts all outstanding commands.
3281*
3282* Input:
3283* ha = adapter block pointer.
3284*
3285* Returns:
3286* 0 = success
3287*/
3288int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003291 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003293 struct qla_hw_data *ha = vha->hw;
3294 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003295 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 if (vha->flags.online) {
3298 vha->flags.online = 0;
3299 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003300 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
3302 qla_printk(KERN_INFO, ha,
3303 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003304 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3307 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3308 atomic_set(&vha->loop_state, LOOP_DOWN);
3309 qla2x00_mark_all_devices_lost(vha, 0);
3310 list_for_each_entry(vp, &ha->vp_list, list)
3311 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313 if (!atomic_read(&vha->loop_down_timer))
3314 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 LOOP_DOWN_TIME);
3316 }
3317
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003321 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 if (!qla2x00_restart_isp(vha)) {
3326 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329 /*
3330 * Issue marker command only when we are going
3331 * to start the I/O .
3332 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003333 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003334 }
3335
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003338 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003339
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003340 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003342
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003343 if (ha->fce) {
3344 ha->flags.fce_enabled = 1;
3345 memset(ha->fce, 0,
3346 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003348 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3349 &ha->fce_bufs);
3350 if (rval) {
3351 qla_printk(KERN_WARNING, ha,
3352 "Unable to reinitialize FCE "
3353 "(%d).\n", rval);
3354 ha->flags.fce_enabled = 0;
3355 }
3356 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003357
3358 if (ha->eft) {
3359 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003360 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003361 ha->eft_dma, EFT_NUM_BUFFERS);
3362 if (rval) {
3363 qla_printk(KERN_WARNING, ha,
3364 "Unable to reinitialize EFT "
3365 "(%d).\n", rval);
3366 }
3367 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 vha->flags.online = 1;
3370 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003371 if (ha->isp_abort_cnt == 0) {
3372 qla_printk(KERN_WARNING, ha,
3373 "ISP error recovery failed - "
3374 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003375 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003376 * The next call disables the board
3377 * completely.
3378 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003379 ha->isp_ops->reset_adapter(vha);
3380 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003381 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003382 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 status = 0;
3384 } else { /* schedule another ISP abort */
3385 ha->isp_abort_cnt--;
3386 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003387 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 status = 1;
3390 }
3391 } else {
3392 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3393 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3394 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003395 vha->host_no, ha->isp_abort_cnt));
3396 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 status = 1;
3398 }
3399 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003400
Linus Torvalds1da177e2005-04-16 15:20:36 -07003401 }
3402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003403 if (!status) {
3404 DEBUG(printk(KERN_INFO
3405 "qla2x00_abort_isp(%ld): succeeded.\n",
3406 vha->host_no));
3407 list_for_each_entry(vp, &ha->vp_list, list) {
3408 if (vp->vp_idx)
3409 qla2x00_vp_abort_isp(vp);
3410 }
3411 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003412 qla_printk(KERN_INFO, ha,
3413 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414 }
3415
3416 return(status);
3417}
3418
3419/*
3420* qla2x00_restart_isp
3421* restarts the ISP after a reset
3422*
3423* Input:
3424* ha = adapter block pointer.
3425*
3426* Returns:
3427* 0 = success
3428*/
3429static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431{
3432 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003434 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003435 struct req_que *req = ha->req_q_map[0];
3436 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003437
3438 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439 if (qla2x00_isp_firmware(vha)) {
3440 vha->flags.online = 0;
3441 status = ha->isp_ops->chip_diag(vha);
3442 if (!status)
3443 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003444 }
3445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 if (!status && !(status = qla2x00_init_rings(vha))) {
3447 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003448 /* Initialize the queues in use */
3449 qla25xx_init_queues(ha);
3450
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003451 status = qla2x00_fw_ready(vha);
3452 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003454 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003455
3456 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003457 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003458
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003459 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003460 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3461 wait_time = 256;
3462 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003463 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3464 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003465 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003466 } while (!atomic_read(&vha->loop_down_timer) &&
3467 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3468 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3469 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003470 }
3471
3472 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003473 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 status = 0;
3475
3476 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3477 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003478 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 }
3480 return (status);
3481}
3482
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003483static int
3484qla25xx_init_queues(struct qla_hw_data *ha)
3485{
3486 struct rsp_que *rsp = NULL;
3487 struct req_que *req = NULL;
3488 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3489 int ret = -1;
3490 int i;
3491
3492 for (i = 1; i < ha->max_queues; i++) {
3493 rsp = ha->rsp_q_map[i];
3494 if (rsp) {
3495 rsp->options &= ~BIT_0;
3496 ret = qla25xx_init_rsp_que(base_vha, rsp, rsp->options);
3497 if (ret != QLA_SUCCESS)
3498 DEBUG2_17(printk(KERN_WARNING
3499 "%s Rsp que:%d init failed\n", __func__,
3500 rsp->id));
3501 else
3502 DEBUG2_17(printk(KERN_INFO
3503 "%s Rsp que:%d inited\n", __func__,
3504 rsp->id));
3505 }
3506 req = ha->req_q_map[i];
3507 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003508 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003509 req->options &= ~BIT_0;
3510 ret = qla25xx_init_req_que(base_vha, req, req->options);
3511 if (ret != QLA_SUCCESS)
3512 DEBUG2_17(printk(KERN_WARNING
3513 "%s Req que:%d init failed\n", __func__,
3514 req->id));
3515 else
3516 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003517 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003518 req->id));
3519 }
3520 }
3521 return ret;
3522}
3523
Linus Torvalds1da177e2005-04-16 15:20:36 -07003524/*
3525* qla2x00_reset_adapter
3526* Reset adapter.
3527*
3528* Input:
3529* ha = adapter block pointer.
3530*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003531void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533{
3534 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003535 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003536 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003539 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541 spin_lock_irqsave(&ha->hardware_lock, flags);
3542 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3543 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3544 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3545 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3546 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3547}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003548
3549void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003550qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003551{
3552 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003553 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003554 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3555
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003557 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003558
3559 spin_lock_irqsave(&ha->hardware_lock, flags);
3560 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3561 RD_REG_DWORD(&reg->hccr);
3562 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3563 RD_REG_DWORD(&reg->hccr);
3564 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3565}
3566
David Miller4e08df32007-04-16 12:37:43 -07003567/* On sparc systems, obtain port and node WWN from firmware
3568 * properties.
3569 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003570static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3571 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003572{
3573#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003574 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003575 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003576 struct device_node *dp = pci_device_to_OF_node(pdev);
3577 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003578 int len;
3579
3580 val = of_get_property(dp, "port-wwn", &len);
3581 if (val && len >= WWN_SIZE)
3582 memcpy(nv->port_name, val, WWN_SIZE);
3583
3584 val = of_get_property(dp, "node-wwn", &len);
3585 if (val && len >= WWN_SIZE)
3586 memcpy(nv->node_name, val, WWN_SIZE);
3587#endif
3588}
3589
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003590int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003591qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003592{
David Miller4e08df32007-04-16 12:37:43 -07003593 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003594 struct init_cb_24xx *icb;
3595 struct nvram_24xx *nv;
3596 uint32_t *dptr;
3597 uint8_t *dptr1, *dptr2;
3598 uint32_t chksum;
3599 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003601
David Miller4e08df32007-04-16 12:37:43 -07003602 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003603 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003604 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003605
3606 /* Determine NVRAM starting address. */
3607 ha->nvram_size = sizeof(struct nvram_24xx);
3608 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003609 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3610 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3611 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003612 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003613 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3614 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003615
Seokmann Ju281afe12007-07-26 13:43:34 -07003616 /* Get VPD data into cache */
3617 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003618 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003619 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3620
3621 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003622 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003623 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003624 ha->nvram_size);
3625 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3626 chksum += le32_to_cpu(*dptr++);
3627
3628 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003629 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003630
3631 /* Bad NVRAM data, set defaults parameters. */
3632 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3633 || nv->id[3] != ' ' ||
3634 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3635 /* Reset NVRAM data. */
3636 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3637 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3638 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003639 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3640 "invalid -- WWPN) defaults.\n");
3641
3642 /*
3643 * Set default initialization control block.
3644 */
3645 memset(nv, 0, ha->nvram_size);
3646 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3647 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3648 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3649 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3650 nv->exchange_count = __constant_cpu_to_le16(0);
3651 nv->hard_address = __constant_cpu_to_le16(124);
3652 nv->port_name[0] = 0x21;
3653 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3654 nv->port_name[2] = 0x00;
3655 nv->port_name[3] = 0xe0;
3656 nv->port_name[4] = 0x8b;
3657 nv->port_name[5] = 0x1c;
3658 nv->port_name[6] = 0x55;
3659 nv->port_name[7] = 0x86;
3660 nv->node_name[0] = 0x20;
3661 nv->node_name[1] = 0x00;
3662 nv->node_name[2] = 0x00;
3663 nv->node_name[3] = 0xe0;
3664 nv->node_name[4] = 0x8b;
3665 nv->node_name[5] = 0x1c;
3666 nv->node_name[6] = 0x55;
3667 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003668 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003669 nv->login_retry_count = __constant_cpu_to_le16(8);
3670 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3671 nv->login_timeout = __constant_cpu_to_le16(0);
3672 nv->firmware_options_1 =
3673 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3674 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3675 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3676 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3677 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3678 nv->efi_parameters = __constant_cpu_to_le32(0);
3679 nv->reset_delay = 5;
3680 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3681 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3682 nv->link_down_timeout = __constant_cpu_to_le16(30);
3683
3684 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003685 }
3686
3687 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003689
3690 /* Copy 1st segment. */
3691 dptr1 = (uint8_t *)icb;
3692 dptr2 = (uint8_t *)&nv->version;
3693 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3694 while (cnt--)
3695 *dptr1++ = *dptr2++;
3696
3697 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003698 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003699
3700 /* Copy 2nd segment. */
3701 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3702 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3703 cnt = (uint8_t *)&icb->reserved_3 -
3704 (uint8_t *)&icb->interrupt_delay_timer;
3705 while (cnt--)
3706 *dptr1++ = *dptr2++;
3707
3708 /*
3709 * Setup driver NVRAM options.
3710 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003711 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003712 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003713
Andrew Vasquez5341e862006-05-17 15:09:16 -07003714 /* Use alternate WWN? */
3715 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3716 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3717 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3718 }
3719
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003720 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003721 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003722 /*
3723 * Firmware will apply the following mask if the nodename was
3724 * not provided.
3725 */
3726 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3727 icb->node_name[0] &= 0xF0;
3728 }
3729
3730 /* Set host adapter parameters. */
3731 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003732 ha->flags.enable_lip_reset = 0;
3733 ha->flags.enable_lip_full_login =
3734 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3735 ha->flags.enable_target_reset =
3736 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003737 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003738 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003739
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003740 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3741 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003742
3743 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3744 sizeof(ha->fw_seriallink_options24));
3745
3746 /* save HBA serial number */
3747 ha->serial0 = icb->port_name[5];
3748 ha->serial1 = icb->port_name[6];
3749 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003750 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3751 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003752
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003753 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3754
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003755 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3756
3757 /* Set minimum login_timeout to 4 seconds. */
3758 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3759 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3760 if (le16_to_cpu(nv->login_timeout) < 4)
3761 nv->login_timeout = __constant_cpu_to_le16(4);
3762 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003763 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003764
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003765 /* Set minimum RATOV to 100 tenths of a second. */
3766 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003767
3768 ha->loop_reset_delay = nv->reset_delay;
3769
3770 /* Link Down Timeout = 0:
3771 *
3772 * When Port Down timer expires we will start returning
3773 * I/O's to OS with "DID_NO_CONNECT".
3774 *
3775 * Link Down Timeout != 0:
3776 *
3777 * The driver waits for the link to come up after link down
3778 * before returning I/Os to OS with "DID_NO_CONNECT".
3779 */
3780 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3781 ha->loop_down_abort_time =
3782 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3783 } else {
3784 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3785 ha->loop_down_abort_time =
3786 (LOOP_DOWN_TIME - ha->link_down_timeout);
3787 }
3788
3789 /* Need enough time to try and get the port back. */
3790 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3791 if (qlport_down_retry)
3792 ha->port_down_retry_count = qlport_down_retry;
3793
3794 /* Set login_retry_count */
3795 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3796 if (ha->port_down_retry_count ==
3797 le16_to_cpu(nv->port_down_retry_count) &&
3798 ha->port_down_retry_count > 3)
3799 ha->login_retry_count = ha->port_down_retry_count;
3800 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3801 ha->login_retry_count = ha->port_down_retry_count;
3802 if (ql2xloginretrycount)
3803 ha->login_retry_count = ql2xloginretrycount;
3804
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003805 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003806 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003807 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3808 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3809 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3810 le16_to_cpu(icb->interrupt_delay_timer): 2;
3811 }
3812 icb->firmware_options_2 &= __constant_cpu_to_le32(
3813 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003814 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003815 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003816 ha->zio_mode = QLA_ZIO_MODE_6;
3817
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003818 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003819 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003820 ha->zio_timer * 100));
3821 qla_printk(KERN_INFO, ha,
3822 "ZIO mode %d enabled; timer delay (%d us).\n",
3823 ha->zio_mode, ha->zio_timer * 100);
3824
3825 icb->firmware_options_2 |= cpu_to_le32(
3826 (uint32_t)ha->zio_mode);
3827 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003829 }
3830
David Miller4e08df32007-04-16 12:37:43 -07003831 if (rval) {
3832 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003833 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003834 }
3835 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003836}
3837
Adrian Bunk413975a2006-06-30 02:33:06 -07003838static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003839qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003840{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003841 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003842 int segments, fragment;
3843 uint32_t faddr;
3844 uint32_t *dcode, dlen;
3845 uint32_t risc_addr;
3846 uint32_t risc_size;
3847 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003848 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003849 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003850 rval = QLA_SUCCESS;
3851
3852 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003853 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003854 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003855 *srisc_addr = 0;
3856
3857 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003859 for (i = 0; i < 4; i++)
3860 dcode[i] = be32_to_cpu(dcode[i]);
3861 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3862 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3863 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3864 dcode[3] == 0)) {
3865 qla_printk(KERN_WARNING, ha,
3866 "Unable to verify integrity of flash firmware image!\n");
3867 qla_printk(KERN_WARNING, ha,
3868 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3869 dcode[1], dcode[2], dcode[3]);
3870
3871 return QLA_FUNCTION_FAILED;
3872 }
3873
3874 while (segments && rval == QLA_SUCCESS) {
3875 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003876 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003877
3878 risc_addr = be32_to_cpu(dcode[2]);
3879 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3880 risc_size = be32_to_cpu(dcode[3]);
3881
3882 fragment = 0;
3883 while (risc_size > 0 && rval == QLA_SUCCESS) {
3884 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3885 if (dlen > risc_size)
3886 dlen = risc_size;
3887
3888 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3889 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003890 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003891
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003892 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003893 for (i = 0; i < dlen; i++)
3894 dcode[i] = swab32(dcode[i]);
3895
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003896 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003897 dlen);
3898 if (rval) {
3899 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003900 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003901 fragment));
3902 qla_printk(KERN_WARNING, ha,
3903 "[ERROR] Failed to load segment %d of "
3904 "firmware\n", fragment);
3905 break;
3906 }
3907
3908 faddr += dlen;
3909 risc_addr += dlen;
3910 risc_size -= dlen;
3911 fragment++;
3912 }
3913
3914 /* Next segment. */
3915 segments--;
3916 }
3917
3918 return rval;
3919}
3920
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003921#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3922
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003923int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003924qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003925{
3926 int rval;
3927 int i, fragment;
3928 uint16_t *wcode, *fwcode;
3929 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3930 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003931 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003932 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003933
3934 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003936 if (!blob) {
3937 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003938 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3939 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003940 return QLA_FUNCTION_FAILED;
3941 }
3942
3943 rval = QLA_SUCCESS;
3944
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003945 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003946 *srisc_addr = 0;
3947 fwcode = (uint16_t *)blob->fw->data;
3948 fwclen = 0;
3949
3950 /* Validate firmware image by checking version. */
3951 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3952 qla_printk(KERN_WARNING, ha,
3953 "Unable to verify integrity of firmware image (%Zd)!\n",
3954 blob->fw->size);
3955 goto fail_fw_integrity;
3956 }
3957 for (i = 0; i < 4; i++)
3958 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3959 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3960 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3961 wcode[2] == 0 && wcode[3] == 0)) {
3962 qla_printk(KERN_WARNING, ha,
3963 "Unable to verify integrity of firmware image!\n");
3964 qla_printk(KERN_WARNING, ha,
3965 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3966 wcode[1], wcode[2], wcode[3]);
3967 goto fail_fw_integrity;
3968 }
3969
3970 seg = blob->segs;
3971 while (*seg && rval == QLA_SUCCESS) {
3972 risc_addr = *seg;
3973 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3974 risc_size = be16_to_cpu(fwcode[3]);
3975
3976 /* Validate firmware image size. */
3977 fwclen += risc_size * sizeof(uint16_t);
3978 if (blob->fw->size < fwclen) {
3979 qla_printk(KERN_WARNING, ha,
3980 "Unable to verify integrity of firmware image "
3981 "(%Zd)!\n", blob->fw->size);
3982 goto fail_fw_integrity;
3983 }
3984
3985 fragment = 0;
3986 while (risc_size > 0 && rval == QLA_SUCCESS) {
3987 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3988 if (wlen > risc_size)
3989 wlen = risc_size;
3990
3991 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003992 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003993 risc_addr, wlen));
3994
3995 for (i = 0; i < wlen; i++)
3996 wcode[i] = swab16(fwcode[i]);
3997
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003998 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003999 wlen);
4000 if (rval) {
4001 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004002 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004003 fragment));
4004 qla_printk(KERN_WARNING, ha,
4005 "[ERROR] Failed to load segment %d of "
4006 "firmware\n", fragment);
4007 break;
4008 }
4009
4010 fwcode += wlen;
4011 risc_addr += wlen;
4012 risc_size -= wlen;
4013 fragment++;
4014 }
4015
4016 /* Next segment. */
4017 seg++;
4018 }
4019 return rval;
4020
4021fail_fw_integrity:
4022 return QLA_FUNCTION_FAILED;
4023}
4024
4025int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004027{
4028 int rval;
4029 int segments, fragment;
4030 uint32_t *dcode, dlen;
4031 uint32_t risc_addr;
4032 uint32_t risc_size;
4033 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004034 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004035 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004036 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004037 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004038
Andrew Vasquez54333832005-11-09 15:49:04 -08004039 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004040 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004041 if (!blob) {
4042 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004043 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4044 "from: " QLA_FW_URL ".\n");
4045
4046 /* Try to load RISC code from flash. */
4047 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
4048 "outdated) firmware from flash.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004049 return qla24xx_load_risc_flash(vha, srisc_addr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004050 }
4051
4052 rval = QLA_SUCCESS;
4053
4054 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004055 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004056 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004057 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004058 fwclen = 0;
4059
4060 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004061 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004062 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004063 "Unable to verify integrity of firmware image (%Zd)!\n",
4064 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004065 goto fail_fw_integrity;
4066 }
4067 for (i = 0; i < 4; i++)
4068 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4069 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4070 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4071 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4072 dcode[3] == 0)) {
4073 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004074 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004075 qla_printk(KERN_WARNING, ha,
4076 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4077 dcode[1], dcode[2], dcode[3]);
4078 goto fail_fw_integrity;
4079 }
4080
4081 while (segments && rval == QLA_SUCCESS) {
4082 risc_addr = be32_to_cpu(fwcode[2]);
4083 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4084 risc_size = be32_to_cpu(fwcode[3]);
4085
4086 /* Validate firmware image size. */
4087 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004088 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004089 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004090 "Unable to verify integrity of firmware image "
4091 "(%Zd)!\n", blob->fw->size);
4092
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004093 goto fail_fw_integrity;
4094 }
4095
4096 fragment = 0;
4097 while (risc_size > 0 && rval == QLA_SUCCESS) {
4098 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4099 if (dlen > risc_size)
4100 dlen = risc_size;
4101
4102 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004103 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004104 risc_addr, dlen));
4105
4106 for (i = 0; i < dlen; i++)
4107 dcode[i] = swab32(fwcode[i]);
4108
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004109 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004110 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004111 if (rval) {
4112 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004113 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004114 fragment));
4115 qla_printk(KERN_WARNING, ha,
4116 "[ERROR] Failed to load segment %d of "
4117 "firmware\n", fragment);
4118 break;
4119 }
4120
4121 fwcode += dlen;
4122 risc_addr += dlen;
4123 risc_size -= dlen;
4124 fragment++;
4125 }
4126
4127 /* Next segment. */
4128 segments--;
4129 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004130 return rval;
4131
4132fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004133 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004134}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004135
4136void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004137qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004138{
4139 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004140 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004141
Andrew Vasqueze4289242007-07-19 15:05:56 -07004142 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004143 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004144 if (!ha->fw_major_version)
4145 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004146
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004147 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004148 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4149 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004150 ha->isp_ops->reset_chip(vha);
4151 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004152 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004153 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004154 continue;
4155 qla_printk(KERN_INFO, ha,
4156 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004157 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004158 }
4159}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004160
4161int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004162qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004163{
4164 int rval = QLA_SUCCESS;
4165 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004166 struct qla_hw_data *ha = vha->hw;
4167 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004168 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
4169 struct rsp_que *rsp = req->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004170
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004171 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004172 return -EINVAL;
4173
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004174 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004175 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004176 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004177 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004178 }
4179
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004180 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004181
4182 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004183 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004184 if (mb[0] != MBS_COMMAND_COMPLETE) {
4185 DEBUG15(qla_printk(KERN_INFO, ha,
4186 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4187 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4188 mb[0], mb[1], mb[2], mb[6], mb[7]));
4189 return (QLA_FUNCTION_FAILED);
4190 }
4191
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004192 atomic_set(&vha->loop_down_timer, 0);
4193 atomic_set(&vha->loop_state, LOOP_UP);
4194 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4195 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4196 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004197
4198 return rval;
4199}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004200
4201/* 84XX Support **************************************************************/
4202
4203static LIST_HEAD(qla_cs84xx_list);
4204static DEFINE_MUTEX(qla_cs84xx_mutex);
4205
4206static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004207qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004208{
4209 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004210 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004211
4212 mutex_lock(&qla_cs84xx_mutex);
4213
4214 /* Find any shared 84xx chip. */
4215 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4216 if (cs84xx->bus == ha->pdev->bus) {
4217 kref_get(&cs84xx->kref);
4218 goto done;
4219 }
4220 }
4221
4222 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4223 if (!cs84xx)
4224 goto done;
4225
4226 kref_init(&cs84xx->kref);
4227 spin_lock_init(&cs84xx->access_lock);
4228 mutex_init(&cs84xx->fw_update_mutex);
4229 cs84xx->bus = ha->pdev->bus;
4230
4231 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4232done:
4233 mutex_unlock(&qla_cs84xx_mutex);
4234 return cs84xx;
4235}
4236
4237static void
4238__qla84xx_chip_release(struct kref *kref)
4239{
4240 struct qla_chip_state_84xx *cs84xx =
4241 container_of(kref, struct qla_chip_state_84xx, kref);
4242
4243 mutex_lock(&qla_cs84xx_mutex);
4244 list_del(&cs84xx->list);
4245 mutex_unlock(&qla_cs84xx_mutex);
4246 kfree(cs84xx);
4247}
4248
4249void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004250qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004252 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004253 if (ha->cs84xx)
4254 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4255}
4256
4257static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004258qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004259{
4260 int rval;
4261 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004262 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004263
4264 mutex_lock(&ha->cs84xx->fw_update_mutex);
4265
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004266 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004267
4268 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4269
4270 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4271 QLA_SUCCESS;
4272}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004273
4274/* 81XX Support **************************************************************/
4275
4276int
4277qla81xx_nvram_config(scsi_qla_host_t *vha)
4278{
4279 int rval;
4280 struct init_cb_81xx *icb;
4281 struct nvram_81xx *nv;
4282 uint32_t *dptr;
4283 uint8_t *dptr1, *dptr2;
4284 uint32_t chksum;
4285 uint16_t cnt;
4286 struct qla_hw_data *ha = vha->hw;
4287
4288 rval = QLA_SUCCESS;
4289 icb = (struct init_cb_81xx *)ha->init_cb;
4290 nv = ha->nvram;
4291
4292 /* Determine NVRAM starting address. */
4293 ha->nvram_size = sizeof(struct nvram_81xx);
4294 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4295 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4296 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4297 if (PCI_FUNC(ha->pdev->devfn) & 1) {
4298 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4299 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4300 }
4301
4302 /* Get VPD data into cache */
4303 ha->vpd = ha->nvram + VPD_OFFSET;
4304 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4305 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4306
4307 /* Get NVRAM data into cache and calculate checksum. */
4308 dptr = (uint32_t *)nv;
4309 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4310 ha->nvram_size);
4311 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4312 chksum += le32_to_cpu(*dptr++);
4313
4314 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4315 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4316
4317 /* Bad NVRAM data, set defaults parameters. */
4318 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4319 || nv->id[3] != ' ' ||
4320 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4321 /* Reset NVRAM data. */
4322 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4323 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4324 le16_to_cpu(nv->nvram_version));
4325 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4326 "invalid -- WWPN) defaults.\n");
4327
4328 /*
4329 * Set default initialization control block.
4330 */
4331 memset(nv, 0, ha->nvram_size);
4332 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4333 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4334 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4335 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4336 nv->exchange_count = __constant_cpu_to_le16(0);
4337 nv->port_name[0] = 0x21;
4338 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4339 nv->port_name[2] = 0x00;
4340 nv->port_name[3] = 0xe0;
4341 nv->port_name[4] = 0x8b;
4342 nv->port_name[5] = 0x1c;
4343 nv->port_name[6] = 0x55;
4344 nv->port_name[7] = 0x86;
4345 nv->node_name[0] = 0x20;
4346 nv->node_name[1] = 0x00;
4347 nv->node_name[2] = 0x00;
4348 nv->node_name[3] = 0xe0;
4349 nv->node_name[4] = 0x8b;
4350 nv->node_name[5] = 0x1c;
4351 nv->node_name[6] = 0x55;
4352 nv->node_name[7] = 0x86;
4353 nv->login_retry_count = __constant_cpu_to_le16(8);
4354 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4355 nv->login_timeout = __constant_cpu_to_le16(0);
4356 nv->firmware_options_1 =
4357 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4358 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4359 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4360 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4361 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4362 nv->efi_parameters = __constant_cpu_to_le32(0);
4363 nv->reset_delay = 5;
4364 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4365 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4366 nv->link_down_timeout = __constant_cpu_to_le16(30);
4367 nv->enode_mac[0] = 0x01;
4368 nv->enode_mac[1] = 0x02;
4369 nv->enode_mac[2] = 0x03;
4370 nv->enode_mac[3] = 0x04;
4371 nv->enode_mac[4] = 0x05;
4372 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4373
4374 rval = 1;
4375 }
4376
4377 /* Reset Initialization control block */
4378 memset(icb, 0, sizeof(struct init_cb_81xx));
4379
4380 /* Copy 1st segment. */
4381 dptr1 = (uint8_t *)icb;
4382 dptr2 = (uint8_t *)&nv->version;
4383 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4384 while (cnt--)
4385 *dptr1++ = *dptr2++;
4386
4387 icb->login_retry_count = nv->login_retry_count;
4388
4389 /* Copy 2nd segment. */
4390 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4391 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4392 cnt = (uint8_t *)&icb->reserved_5 -
4393 (uint8_t *)&icb->interrupt_delay_timer;
4394 while (cnt--)
4395 *dptr1++ = *dptr2++;
4396
4397 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4398 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4399 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4400 icb->enode_mac[0] = 0x01;
4401 icb->enode_mac[1] = 0x02;
4402 icb->enode_mac[2] = 0x03;
4403 icb->enode_mac[3] = 0x04;
4404 icb->enode_mac[4] = 0x05;
4405 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4406 }
4407
4408 /*
4409 * Setup driver NVRAM options.
4410 */
4411 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4412 "QLE81XX");
4413
4414 /* Use alternate WWN? */
4415 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4416 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4417 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4418 }
4419
4420 /* Prepare nodename */
4421 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4422 /*
4423 * Firmware will apply the following mask if the nodename was
4424 * not provided.
4425 */
4426 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4427 icb->node_name[0] &= 0xF0;
4428 }
4429
4430 /* Set host adapter parameters. */
4431 ha->flags.disable_risc_code_load = 0;
4432 ha->flags.enable_lip_reset = 0;
4433 ha->flags.enable_lip_full_login =
4434 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4435 ha->flags.enable_target_reset =
4436 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4437 ha->flags.enable_led_scheme = 0;
4438 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4439
4440 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4441 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4442
4443 /* save HBA serial number */
4444 ha->serial0 = icb->port_name[5];
4445 ha->serial1 = icb->port_name[6];
4446 ha->serial2 = icb->port_name[7];
4447 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4448 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4449
4450 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4451
4452 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4453
4454 /* Set minimum login_timeout to 4 seconds. */
4455 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4456 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4457 if (le16_to_cpu(nv->login_timeout) < 4)
4458 nv->login_timeout = __constant_cpu_to_le16(4);
4459 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4460 icb->login_timeout = nv->login_timeout;
4461
4462 /* Set minimum RATOV to 100 tenths of a second. */
4463 ha->r_a_tov = 100;
4464
4465 ha->loop_reset_delay = nv->reset_delay;
4466
4467 /* Link Down Timeout = 0:
4468 *
4469 * When Port Down timer expires we will start returning
4470 * I/O's to OS with "DID_NO_CONNECT".
4471 *
4472 * Link Down Timeout != 0:
4473 *
4474 * The driver waits for the link to come up after link down
4475 * before returning I/Os to OS with "DID_NO_CONNECT".
4476 */
4477 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4478 ha->loop_down_abort_time =
4479 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4480 } else {
4481 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4482 ha->loop_down_abort_time =
4483 (LOOP_DOWN_TIME - ha->link_down_timeout);
4484 }
4485
4486 /* Need enough time to try and get the port back. */
4487 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4488 if (qlport_down_retry)
4489 ha->port_down_retry_count = qlport_down_retry;
4490
4491 /* Set login_retry_count */
4492 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4493 if (ha->port_down_retry_count ==
4494 le16_to_cpu(nv->port_down_retry_count) &&
4495 ha->port_down_retry_count > 3)
4496 ha->login_retry_count = ha->port_down_retry_count;
4497 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4498 ha->login_retry_count = ha->port_down_retry_count;
4499 if (ql2xloginretrycount)
4500 ha->login_retry_count = ql2xloginretrycount;
4501
4502 /* Enable ZIO. */
4503 if (!vha->flags.init_done) {
4504 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4505 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4506 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4507 le16_to_cpu(icb->interrupt_delay_timer): 2;
4508 }
4509 icb->firmware_options_2 &= __constant_cpu_to_le32(
4510 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4511 vha->flags.process_response_queue = 0;
4512 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4513 ha->zio_mode = QLA_ZIO_MODE_6;
4514
4515 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4516 "(%d us).\n", vha->host_no, ha->zio_mode,
4517 ha->zio_timer * 100));
4518 qla_printk(KERN_INFO, ha,
4519 "ZIO mode %d enabled; timer delay (%d us).\n",
4520 ha->zio_mode, ha->zio_timer * 100);
4521
4522 icb->firmware_options_2 |= cpu_to_le32(
4523 (uint32_t)ha->zio_mode);
4524 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4525 vha->flags.process_response_queue = 1;
4526 }
4527
4528 if (rval) {
4529 DEBUG2_3(printk(KERN_WARNING
4530 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4531 }
4532 return (rval);
4533}
4534
4535void
4536qla81xx_update_fw_options(scsi_qla_host_t *ha)
4537{
4538}