blob: 986501759ad4910fa6b93c7db75d355001c47ad8 [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
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001229 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001230 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001231
1232 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1233 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1234 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1235 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1236 } else {
1237 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1238 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1239 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1240 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1241 }
1242 /* PCI posting */
1243 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001244}
1245
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246/**
1247 * qla2x00_init_rings() - Initializes firmware.
1248 * @ha: HA context
1249 *
1250 * Beginning of request ring has initialization control block already built
1251 * by nvram config routine.
1252 *
1253 * Returns 0 on success.
1254 */
1255static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001256qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257{
1258 int rval;
1259 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001260 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001261 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001262 struct req_que *req;
1263 struct rsp_que *rsp;
1264 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001265 struct mid_init_cb_24xx *mid_init_cb =
1266 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
1268 spin_lock_irqsave(&ha->hardware_lock, flags);
1269
1270 /* Clear outstanding commands array. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001271 for (que = 0; que < ha->max_queues; que++) {
1272 req = ha->req_q_map[que];
1273 if (!req)
1274 continue;
1275 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1276 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001278 req->current_outstanding_cmd = 0;
1279
1280 /* Initialize firmware. */
1281 req->ring_ptr = req->ring;
1282 req->ring_index = 0;
1283 req->cnt = req->length;
1284 }
1285
1286 for (que = 0; que < ha->max_queues; que++) {
1287 rsp = ha->rsp_q_map[que];
1288 if (!rsp)
1289 continue;
1290 rsp->ring_ptr = rsp->ring;
1291 rsp->ring_index = 0;
1292
1293 /* Initialize response queue entries */
1294 qla2x00_init_response_q_entries(rsp);
1295 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296
1297 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001298 list_for_each_entry(vp, &ha->vp_list, list) {
1299 vp->rscn_in_ptr = 0;
1300 vp->rscn_out_ptr = 0;
1301 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001302 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303
1304 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1305
1306 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001307 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001308
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001309 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001310
Seokmann Juc48339d2008-01-17 09:02:19 -08001311 if (ha->flags.npiv_supported)
1312 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1313
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001314 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001315
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001316 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 if (rval) {
1318 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001319 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320 } else {
1321 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001322 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 }
1324
1325 return (rval);
1326}
1327
1328/**
1329 * qla2x00_fw_ready() - Waits for firmware ready.
1330 * @ha: HA context
1331 *
1332 * Returns 0 on success.
1333 */
1334static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001335qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336{
1337 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001338 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001339 uint16_t min_wait; /* Minimum wait time if loop is down */
1340 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001341 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001342 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
1344 rval = QLA_SUCCESS;
1345
1346 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001347 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349 /*
1350 * Firmware should take at most one RATOV to login, plus 5 seconds for
1351 * our own processing.
1352 */
1353 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1354 wait_time = min_wait;
1355 }
1356
1357 /* Min wait time if loop down */
1358 mtime = jiffies + (min_wait * HZ);
1359
1360 /* wait time before firmware ready */
1361 wtime = jiffies + (wait_time * HZ);
1362
1363 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001364 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1366
1367 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001368 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369
1370 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001371 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001373 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001374 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001375 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001376 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1377 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001378 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001379 state[2]));
1380 if ((state[2] & FSTATE_LOGGED_IN) &&
1381 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1382 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001383 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001384
1385 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001387 if (rval != QLA_SUCCESS)
1388 break;
1389
1390 /* Add time taken to initialize. */
1391 cs84xx_time = jiffies - cs84xx_time;
1392 wtime += cs84xx_time;
1393 mtime += cs84xx_time;
1394 DEBUG16(printk("scsi(%ld): Increasing "
1395 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001396 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001397 }
1398 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001399 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001400 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001402 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 &ha->login_timeout, &ha->r_a_tov);
1404
1405 rval = QLA_SUCCESS;
1406 break;
1407 }
1408
1409 rval = QLA_FUNCTION_FAILED;
1410
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001411 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001412 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001414 * other than Wait for Login.
1415 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001416 if (time_after_eq(jiffies, mtime)) {
1417 qla_printk(KERN_INFO, ha,
1418 "Cable is unplugged...\n");
1419
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001420 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421 break;
1422 }
1423 }
1424 } else {
1425 /* Mailbox cmd failed. Timeout on min_wait. */
1426 if (time_after_eq(jiffies, mtime))
1427 break;
1428 }
1429
1430 if (time_after_eq(jiffies, wtime))
1431 break;
1432
1433 /* Delay for a while */
1434 msleep(500);
1435
1436 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001437 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 } while (1);
1439
1440 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001441 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
1443 if (rval) {
1444 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001445 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 }
1447
1448 return (rval);
1449}
1450
1451/*
1452* qla2x00_configure_hba
1453* Setup adapter context.
1454*
1455* Input:
1456* ha = adapter state pointer.
1457*
1458* Returns:
1459* 0 = success
1460*
1461* Context:
1462* Kernel context.
1463*/
1464static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001465qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466{
1467 int rval;
1468 uint16_t loop_id;
1469 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001470 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471 uint8_t al_pa;
1472 uint8_t area;
1473 uint8_t domain;
1474 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476
1477 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001479 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001480 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001481 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001482 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1483 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001484 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001485 } else {
1486 qla_printk(KERN_WARNING, ha,
1487 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001488 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001489 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 return (rval);
1491 }
1492
1493 if (topo == 4) {
1494 qla_printk(KERN_INFO, ha,
1495 "Cannot get topology - retrying.\n");
1496 return (QLA_FUNCTION_FAILED);
1497 }
1498
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501 /* initialize */
1502 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1503 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001504 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505
1506 switch (topo) {
1507 case 0:
1508 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001509 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 ha->current_topology = ISP_CFG_NL;
1511 strcpy(connect_type, "(Loop)");
1512 break;
1513
1514 case 1:
1515 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001517 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 ha->current_topology = ISP_CFG_FL;
1519 strcpy(connect_type, "(FL_Port)");
1520 break;
1521
1522 case 2:
1523 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 ha->operating_mode = P2P;
1526 ha->current_topology = ISP_CFG_N;
1527 strcpy(connect_type, "(N_Port-to-N_Port)");
1528 break;
1529
1530 case 3:
1531 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001532 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001533 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 ha->operating_mode = P2P;
1535 ha->current_topology = ISP_CFG_F;
1536 strcpy(connect_type, "(F_Port)");
1537 break;
1538
1539 default:
1540 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1541 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001542 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001543 ha->current_topology = ISP_CFG_NL;
1544 strcpy(connect_type, "(Loop)");
1545 break;
1546 }
1547
1548 /* Save Host port and loop ID. */
1549 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001550 vha->d_id.b.domain = domain;
1551 vha->d_id.b.area = area;
1552 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001554 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 qla_printk(KERN_INFO, ha,
1556 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001557 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001560 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001561 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001562 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 }
1564
1565 return(rval);
1566}
1567
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001568static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001569qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1570 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001571{
1572 char *st, *en;
1573 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001574 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001575
1576 if (memcmp(model, BINZERO, len) != 0) {
1577 strncpy(ha->model_number, model, len);
1578 st = en = ha->model_number;
1579 en += len - 1;
1580 while (en > st) {
1581 if (*en != 0x20 && *en != 0x00)
1582 break;
1583 *en-- = '\0';
1584 }
1585
1586 index = (ha->pdev->subsystem_device & 0xff);
1587 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1588 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001589 strncpy(ha->model_desc,
1590 qla2x00_model_name[index * 2 + 1],
1591 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001592 } else {
1593 index = (ha->pdev->subsystem_device & 0xff);
1594 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1595 index < QLA_MODEL_NAMES) {
1596 strcpy(ha->model_number,
1597 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001598 strncpy(ha->model_desc,
1599 qla2x00_model_name[index * 2 + 1],
1600 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001601 } else {
1602 strcpy(ha->model_number, def);
1603 }
1604 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001605 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001606 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001607 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001608}
1609
David Miller4e08df32007-04-16 12:37:43 -07001610/* On sparc systems, obtain port and node WWN from firmware
1611 * properties.
1612 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001614{
1615#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001617 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001618 struct device_node *dp = pci_device_to_OF_node(pdev);
1619 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001620 int len;
1621
1622 val = of_get_property(dp, "port-wwn", &len);
1623 if (val && len >= WWN_SIZE)
1624 memcpy(nv->port_name, val, WWN_SIZE);
1625
1626 val = of_get_property(dp, "node-wwn", &len);
1627 if (val && len >= WWN_SIZE)
1628 memcpy(nv->node_name, val, WWN_SIZE);
1629#endif
1630}
1631
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632/*
1633* NVRAM configuration for ISP 2xxx
1634*
1635* Input:
1636* ha = adapter block pointer.
1637*
1638* Output:
1639* initialization control block in response_ring
1640* host adapters parameters in host adapter block
1641*
1642* Returns:
1643* 0 = success.
1644*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001645int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001646qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001647{
David Miller4e08df32007-04-16 12:37:43 -07001648 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001649 uint8_t chksum = 0;
1650 uint16_t cnt;
1651 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001653 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001654 nvram_t *nv = ha->nvram;
1655 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001656 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001657
David Miller4e08df32007-04-16 12:37:43 -07001658 rval = QLA_SUCCESS;
1659
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001661 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662 ha->nvram_base = 0;
1663 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1664 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1665 ha->nvram_base = 0x80;
1666
1667 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001668 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001669 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1670 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001671
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001672 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001673 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674
1675 /* Bad NVRAM data, set defaults parameters. */
1676 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1677 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1678 /* Reset NVRAM data. */
1679 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1680 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1681 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001682 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1683 "invalid -- WWPN) defaults.\n");
1684
1685 /*
1686 * Set default initialization control block.
1687 */
1688 memset(nv, 0, ha->nvram_size);
1689 nv->parameter_block_version = ICB_VERSION;
1690
1691 if (IS_QLA23XX(ha)) {
1692 nv->firmware_options[0] = BIT_2 | BIT_1;
1693 nv->firmware_options[1] = BIT_7 | BIT_5;
1694 nv->add_firmware_options[0] = BIT_5;
1695 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1696 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1697 nv->special_options[1] = BIT_7;
1698 } else if (IS_QLA2200(ha)) {
1699 nv->firmware_options[0] = BIT_2 | BIT_1;
1700 nv->firmware_options[1] = BIT_7 | BIT_5;
1701 nv->add_firmware_options[0] = BIT_5;
1702 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1703 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1704 } else if (IS_QLA2100(ha)) {
1705 nv->firmware_options[0] = BIT_3 | BIT_1;
1706 nv->firmware_options[1] = BIT_5;
1707 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1708 }
1709
1710 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1711 nv->execution_throttle = __constant_cpu_to_le16(16);
1712 nv->retry_count = 8;
1713 nv->retry_delay = 1;
1714
1715 nv->port_name[0] = 33;
1716 nv->port_name[3] = 224;
1717 nv->port_name[4] = 139;
1718
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001719 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001720
1721 nv->login_timeout = 4;
1722
1723 /*
1724 * Set default host adapter parameters
1725 */
1726 nv->host_p[1] = BIT_2;
1727 nv->reset_delay = 5;
1728 nv->port_down_retry_count = 8;
1729 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1730 nv->link_down_timeout = 60;
1731
1732 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 }
1734
1735#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1736 /*
1737 * The SN2 does not provide BIOS emulation which means you can't change
1738 * potentially bogus BIOS settings. Force the use of default settings
1739 * for link rate and frame size. Hope that the rest of the settings
1740 * are valid.
1741 */
1742 if (ia64_platform_is("sn2")) {
1743 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1744 if (IS_QLA23XX(ha))
1745 nv->special_options[1] = BIT_7;
1746 }
1747#endif
1748
1749 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001750 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001751
1752 /*
1753 * Setup driver NVRAM options.
1754 */
1755 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1756 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1757 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1758 nv->firmware_options[1] &= ~BIT_4;
1759
1760 if (IS_QLA23XX(ha)) {
1761 nv->firmware_options[0] |= BIT_2;
1762 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001763 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001764
1765 if (IS_QLA2300(ha)) {
1766 if (ha->fb_rev == FPM_2310) {
1767 strcpy(ha->model_number, "QLA2310");
1768 } else {
1769 strcpy(ha->model_number, "QLA2300");
1770 }
1771 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001772 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001773 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 }
1775 } else if (IS_QLA2200(ha)) {
1776 nv->firmware_options[0] |= BIT_2;
1777 /*
1778 * 'Point-to-point preferred, else loop' is not a safe
1779 * connection mode setting.
1780 */
1781 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1782 (BIT_5 | BIT_4)) {
1783 /* Force 'loop preferred, else point-to-point'. */
1784 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1785 nv->add_firmware_options[0] |= BIT_5;
1786 }
1787 strcpy(ha->model_number, "QLA22xx");
1788 } else /*if (IS_QLA2100(ha))*/ {
1789 strcpy(ha->model_number, "QLA2100");
1790 }
1791
1792 /*
1793 * Copy over NVRAM RISC parameter block to initialization control block.
1794 */
1795 dptr1 = (uint8_t *)icb;
1796 dptr2 = (uint8_t *)&nv->parameter_block_version;
1797 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1798 while (cnt--)
1799 *dptr1++ = *dptr2++;
1800
1801 /* Copy 2nd half. */
1802 dptr1 = (uint8_t *)icb->add_firmware_options;
1803 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1804 while (cnt--)
1805 *dptr1++ = *dptr2++;
1806
Andrew Vasquez5341e862006-05-17 15:09:16 -07001807 /* Use alternate WWN? */
1808 if (nv->host_p[1] & BIT_7) {
1809 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1810 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1811 }
1812
Linus Torvalds1da177e2005-04-16 15:20:36 -07001813 /* Prepare nodename */
1814 if ((icb->firmware_options[1] & BIT_6) == 0) {
1815 /*
1816 * Firmware will apply the following mask if the nodename was
1817 * not provided.
1818 */
1819 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1820 icb->node_name[0] &= 0xF0;
1821 }
1822
1823 /*
1824 * Set host adapter parameters.
1825 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001826 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001827 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001828 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1829 /* Always load RISC code on non ISP2[12]00 chips. */
1830 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1831 ha->flags.disable_risc_code_load = 0;
1832 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1833 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1834 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001835 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001836 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001837
1838 ha->operating_mode =
1839 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1840
1841 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1842 sizeof(ha->fw_seriallink_options));
1843
1844 /* save HBA serial number */
1845 ha->serial0 = icb->port_name[5];
1846 ha->serial1 = icb->port_name[6];
1847 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001848 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1849 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850
1851 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1852
1853 ha->retry_count = nv->retry_count;
1854
1855 /* Set minimum login_timeout to 4 seconds. */
1856 if (nv->login_timeout < ql2xlogintimeout)
1857 nv->login_timeout = ql2xlogintimeout;
1858 if (nv->login_timeout < 4)
1859 nv->login_timeout = 4;
1860 ha->login_timeout = nv->login_timeout;
1861 icb->login_timeout = nv->login_timeout;
1862
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001863 /* Set minimum RATOV to 100 tenths of a second. */
1864 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 ha->loop_reset_delay = nv->reset_delay;
1867
Linus Torvalds1da177e2005-04-16 15:20:36 -07001868 /* Link Down Timeout = 0:
1869 *
1870 * When Port Down timer expires we will start returning
1871 * I/O's to OS with "DID_NO_CONNECT".
1872 *
1873 * Link Down Timeout != 0:
1874 *
1875 * The driver waits for the link to come up after link down
1876 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001877 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878 if (nv->link_down_timeout == 0) {
1879 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001880 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 } else {
1882 ha->link_down_timeout = nv->link_down_timeout;
1883 ha->loop_down_abort_time =
1884 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 /*
1888 * Need enough time to try and get the port back.
1889 */
1890 ha->port_down_retry_count = nv->port_down_retry_count;
1891 if (qlport_down_retry)
1892 ha->port_down_retry_count = qlport_down_retry;
1893 /* Set login_retry_count */
1894 ha->login_retry_count = nv->retry_count;
1895 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1896 ha->port_down_retry_count > 3)
1897 ha->login_retry_count = ha->port_down_retry_count;
1898 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1899 ha->login_retry_count = ha->port_down_retry_count;
1900 if (ql2xloginretrycount)
1901 ha->login_retry_count = ql2xloginretrycount;
1902
Linus Torvalds1da177e2005-04-16 15:20:36 -07001903 icb->lun_enables = __constant_cpu_to_le16(0);
1904 icb->command_resource_count = 0;
1905 icb->immediate_notify_resource_count = 0;
1906 icb->timeout = __constant_cpu_to_le16(0);
1907
1908 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1909 /* Enable RIO */
1910 icb->firmware_options[0] &= ~BIT_3;
1911 icb->add_firmware_options[0] &=
1912 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1913 icb->add_firmware_options[0] |= BIT_2;
1914 icb->response_accumulation_timer = 3;
1915 icb->interrupt_delay_timer = 5;
1916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001919 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001920 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001921 ha->zio_mode = icb->add_firmware_options[0] &
1922 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1923 ha->zio_timer = icb->interrupt_delay_timer ?
1924 icb->interrupt_delay_timer: 2;
1925 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 icb->add_firmware_options[0] &=
1927 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001929 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001930 ha->zio_mode = QLA_ZIO_MODE_6;
1931
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001932 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001933 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001934 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001936 "ZIO mode %d enabled; timer delay (%d us).\n",
1937 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001939 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1940 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001941 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 }
1943 }
1944
David Miller4e08df32007-04-16 12:37:43 -07001945 if (rval) {
1946 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001947 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001948 }
1949 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950}
1951
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001952static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001953qla2x00_rport_del(void *data)
1954{
1955 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001956 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001957
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001958 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001959 rport = fcport->drport;
1960 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001961 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001962 if (rport)
1963 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001964}
1965
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966/**
1967 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1968 * @ha: HA context
1969 * @flags: allocation flags
1970 *
1971 * Returns a pointer to the allocated fcport, or NULL, if none available.
1972 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001973static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001974qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001975{
1976 fc_port_t *fcport;
1977
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001978 fcport = kzalloc(sizeof(fc_port_t), flags);
1979 if (!fcport)
1980 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
1982 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983 fcport->vha = vha;
1984 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 fcport->port_type = FCT_UNKNOWN;
1986 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1988 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001989 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001991 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992}
1993
1994/*
1995 * qla2x00_configure_loop
1996 * Updates Fibre Channel Device Database with what is actually on loop.
1997 *
1998 * Input:
1999 * ha = adapter block pointer.
2000 *
2001 * Returns:
2002 * 0 = success.
2003 * 1 = error.
2004 * 2 = database was full and device was not configured.
2005 */
2006static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008{
2009 int rval;
2010 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 rval = QLA_SUCCESS;
2013
2014 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2016 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 if (rval != QLA_SUCCESS) {
2018 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002019 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 return (rval);
2021 }
2022 }
2023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002024 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027
2028 /*
2029 * If we have both an RSCN and PORT UPDATE pending then handle them
2030 * both at the same time.
2031 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002032 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2033 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035 /* Determine what we need to do */
2036 if (ha->current_topology == ISP_CFG_FL &&
2037 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2038
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 set_bit(RSCN_UPDATE, &flags);
2041
2042 } else if (ha->current_topology == ISP_CFG_F &&
2043 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002045 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 set_bit(RSCN_UPDATE, &flags);
2047 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2048
Andrew Vasquez21333b42006-05-17 15:09:56 -07002049 } else if (ha->current_topology == ISP_CFG_N) {
2050 clear_bit(RSCN_UPDATE, &flags);
2051
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2054
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002055 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 set_bit(RSCN_UPDATE, &flags);
2057 set_bit(LOCAL_LOOP_UPDATE, &flags);
2058 }
2059
2060 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002061 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 else
2064 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065 }
2066
2067 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002068 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002070 else
2071 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 }
2073
2074 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 if (atomic_read(&vha->loop_down_timer) ||
2076 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 rval = QLA_FUNCTION_FAILED;
2078 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002081 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 }
2083 }
2084
2085 if (rval) {
2086 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 } else {
2089 DEBUG3(printk("%s: exiting normally\n", __func__));
2090 }
2091
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002092 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002093 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002095 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002096 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002097 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002098 }
2099
2100 return (rval);
2101}
2102
2103
2104
2105/*
2106 * qla2x00_configure_local_loop
2107 * Updates Fibre Channel Device Database with local loop devices.
2108 *
2109 * Input:
2110 * ha = adapter block pointer.
2111 *
2112 * Returns:
2113 * 0 = success.
2114 */
2115static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002116qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117{
2118 int rval, rval2;
2119 int found_devs;
2120 int found;
2121 fc_port_t *fcport, *new_fcport;
2122
2123 uint16_t index;
2124 uint16_t entries;
2125 char *id_iter;
2126 uint16_t loop_id;
2127 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002128 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129
2130 found_devs = 0;
2131 new_fcport = NULL;
2132 entries = MAX_FIBRE_DEVICES;
2133
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002134 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2135 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
2137 /* Get list of logged in devices. */
2138 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002139 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 &entries);
2141 if (rval != QLA_SUCCESS)
2142 goto cleanup_allocation;
2143
2144 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2145 ha->host_no, entries));
2146 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2147 entries * sizeof(struct gid_list_info)));
2148
2149 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002150 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 if (new_fcport == NULL) {
2152 rval = QLA_MEMORY_ALLOC_FAILED;
2153 goto cleanup_allocation;
2154 }
2155 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2156
2157 /*
2158 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2159 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2162 fcport->port_type != FCT_BROADCAST &&
2163 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2164
2165 DEBUG(printk("scsi(%ld): Marking port lost, "
2166 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168
2169 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2170 fcport->flags &= ~FCF_FARP_DONE;
2171 }
2172 }
2173
2174 /* Add devices to port list. */
2175 id_iter = (char *)ha->gid_list;
2176 for (index = 0; index < entries; index++) {
2177 domain = ((struct gid_list_info *)id_iter)->domain;
2178 area = ((struct gid_list_info *)id_iter)->area;
2179 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002180 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002181 loop_id = (uint16_t)
2182 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002183 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002184 loop_id = le16_to_cpu(
2185 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002186 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187
2188 /* Bypass reserved domain fields. */
2189 if ((domain & 0xf0) == 0xf0)
2190 continue;
2191
2192 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002193 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 continue;
2196
2197 /* Bypass invalid local loop ID. */
2198 if (loop_id > LAST_LOCAL_LOOP_ID)
2199 continue;
2200
2201 /* Fill in member data. */
2202 new_fcport->d_id.b.domain = domain;
2203 new_fcport->d_id.b.area = area;
2204 new_fcport->d_id.b.al_pa = al_pa;
2205 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002206 new_fcport->vp_idx = vha->vp_idx;
2207 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002208 if (rval2 != QLA_SUCCESS) {
2209 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2210 "information -- get_port_database=%x, "
2211 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002213 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 vha->host_no));
2215 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216 continue;
2217 }
2218
2219 /* Check for matching device in port list. */
2220 found = 0;
2221 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002222 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 if (memcmp(new_fcport->port_name, fcport->port_name,
2224 WWN_SIZE))
2225 continue;
2226
2227 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2228 FCF_PERSISTENT_BOUND);
2229 fcport->loop_id = new_fcport->loop_id;
2230 fcport->port_type = new_fcport->port_type;
2231 fcport->d_id.b24 = new_fcport->d_id.b24;
2232 memcpy(fcport->node_name, new_fcport->node_name,
2233 WWN_SIZE);
2234
2235 found++;
2236 break;
2237 }
2238
2239 if (!found) {
2240 /* New device, add to fcports list. */
2241 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002242 if (vha->vp_idx) {
2243 new_fcport->vha = vha;
2244 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002245 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
2248 /* Allocate a new replacement fcport. */
2249 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 if (new_fcport == NULL) {
2252 rval = QLA_MEMORY_ALLOC_FAILED;
2253 goto cleanup_allocation;
2254 }
2255 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2256 }
2257
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002258 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002259 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002260
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002261 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002262
2263 found_devs++;
2264 }
2265
2266cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002267 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002268
2269 if (rval != QLA_SUCCESS) {
2270 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002271 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002272 }
2273
2274 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002275 vha->device_flags |= DFLG_LOCAL_DEVICES;
2276 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002277 }
2278
2279 return (rval);
2280}
2281
2282static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002283qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002284{
2285#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002286 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002287 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002288 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002289 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002290
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002291 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002292 return;
2293
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002294 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2295 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002296 return;
2297
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002298 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002299 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002300 if (rval != QLA_SUCCESS) {
2301 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2302 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002304 fcport->port_name[2], fcport->port_name[3],
2305 fcport->port_name[4], fcport->port_name[5],
2306 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002307 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002308 } else {
2309 DEBUG2(qla_printk(KERN_INFO, ha,
2310 "iIDMA adjusted to %s GB/s on "
2311 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002312 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002313 fcport->port_name[1], fcport->port_name[2],
2314 fcport->port_name[3], fcport->port_name[4],
2315 fcport->port_name[5], fcport->port_name[6],
2316 fcport->port_name[7]));
2317 }
2318}
2319
Adrian Bunk23be3312006-11-24 02:46:01 +01002320static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002322{
2323 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002324 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002326
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002327 if (fcport->drport)
2328 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002329
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002330 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2331 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002332 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2333 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2334 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002336 if (!rport) {
2337 qla_printk(KERN_WARNING, ha,
2338 "Unable to allocate fc remote port!\n");
2339 return;
2340 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002341 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002342 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002343 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002344
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002345 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002346
2347 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002348 if (fcport->port_type == FCT_INITIATOR)
2349 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2350 if (fcport->port_type == FCT_TARGET)
2351 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002352 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002353}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002354
2355/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002356 * qla2x00_update_fcport
2357 * Updates device on list.
2358 *
2359 * Input:
2360 * ha = adapter block pointer.
2361 * fcport = port structure pointer.
2362 *
2363 * Return:
2364 * 0 - Success
2365 * BIT_0 - error
2366 *
2367 * Context:
2368 * Kernel context.
2369 */
2370void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002372{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002374
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002375 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002376 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002378 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002379 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002380 PORT_RETRY_TIME);
2381 fcport->flags &= ~FCF_LOGIN_NEEDED;
2382
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002384
2385 atomic_set(&fcport->state, FCS_ONLINE);
2386
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002388}
2389
2390/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391 * qla2x00_configure_fabric
2392 * Setup SNS devices with loop ID's.
2393 *
2394 * Input:
2395 * ha = adapter block pointer.
2396 *
2397 * Returns:
2398 * 0 = success.
2399 * BIT_0 = error
2400 */
2401static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403{
2404 int rval, rval2;
2405 fc_port_t *fcport, *fcptemp;
2406 uint16_t next_loopid;
2407 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002408 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 struct qla_hw_data *ha = vha->hw;
2411 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412
2413 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002414 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002415 loop_id = NPH_F_PORT;
2416 else
2417 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 if (rval != QLA_SUCCESS) {
2420 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002423 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 return (QLA_SUCCESS);
2425 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002426 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002427
2428 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002429 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 if (rval2 == QLA_RSCNS_HANDLED) {
2431 /* No point doing the scan, just continue. */
2432 return (QLA_SUCCESS);
2433 }
2434 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002435 /* FDMI support. */
2436 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2438 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002439
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002441 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002442 loop_id = NPH_SNS;
2443 else
2444 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002446 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 if (mb[0] != MBS_COMMAND_COMPLETE) {
2448 DEBUG2(qla_printk(KERN_INFO, ha,
2449 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002450 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 mb[0], mb[1], mb[2], mb[6], mb[7]));
2452 return (QLA_SUCCESS);
2453 }
2454
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002455 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2456 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 /* EMPTY */
2458 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002459 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002460 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 /* EMPTY */
2463 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002464 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 /* EMPTY */
2468 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 "failed.\n", vha->host_no));
2470 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 /* EMPTY */
2472 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 }
2475 }
2476
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 if (rval != QLA_SUCCESS)
2479 break;
2480
2481 /*
2482 * Logout all previous fabric devices marked lost, except
2483 * tape devices.
2484 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2486 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002487 break;
2488
2489 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2490 continue;
2491
2492 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002494 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 if (fcport->loop_id != FC_NO_LOOP_ID &&
2496 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2497 fcport->port_type != FCT_INITIATOR &&
2498 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002499 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002500 fcport->loop_id,
2501 fcport->d_id.b.domain,
2502 fcport->d_id.b.area,
2503 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002504 fcport->loop_id = FC_NO_LOOP_ID;
2505 }
2506 }
2507 }
2508
2509 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
2512 /*
2513 * Scan through our port list and login entries that need to be
2514 * logged in.
2515 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2517 if (atomic_read(&vha->loop_down_timer) ||
2518 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002519 break;
2520
2521 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2522 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2523 continue;
2524
2525 if (fcport->loop_id == FC_NO_LOOP_ID) {
2526 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002527 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002528 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529 if (rval != QLA_SUCCESS) {
2530 /* Ran out of IDs to use */
2531 break;
2532 }
2533 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 }
2537
2538 /* Exit if out of loop IDs. */
2539 if (rval != QLA_SUCCESS) {
2540 break;
2541 }
2542
2543 /*
2544 * Login and add the new devices to our port list.
2545 */
2546 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547 if (atomic_read(&vha->loop_down_timer) ||
2548 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549 break;
2550
2551 /* Find a new loop ID to use. */
2552 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002553 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002554 if (rval != QLA_SUCCESS) {
2555 /* Ran out of IDs to use */
2556 break;
2557 }
2558
bdf79622005-04-17 15:06:53 -05002559 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002561
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562 if (vha->vp_idx) {
2563 fcport->vha = vha;
2564 fcport->vp_idx = vha->vp_idx;
2565 }
2566 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 }
2568 } while (0);
2569
2570 /* Free all new device structures not processed. */
2571 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2572 list_del(&fcport->list);
2573 kfree(fcport);
2574 }
2575
2576 if (rval) {
2577 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002579 }
2580
2581 return (rval);
2582}
2583
2584
2585/*
2586 * qla2x00_find_all_fabric_devs
2587 *
2588 * Input:
2589 * ha = adapter block pointer.
2590 * dev = database device entry pointer.
2591 *
2592 * Returns:
2593 * 0 = success.
2594 *
2595 * Context:
2596 * Kernel context.
2597 */
2598static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2600 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601{
2602 int rval;
2603 uint16_t loop_id;
2604 fc_port_t *fcport, *new_fcport, *fcptemp;
2605 int found;
2606
2607 sw_info_t *swl;
2608 int swl_idx;
2609 int first_dev, last_dev;
2610 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002611 struct qla_hw_data *ha = vha->hw;
2612 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613
2614 rval = QLA_SUCCESS;
2615
2616 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002617 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002618 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 /*EMPTY*/
2620 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002623 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 kfree(swl);
2625 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002626 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 kfree(swl);
2628 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 kfree(swl);
2631 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002632 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002633 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2634 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 }
2636 }
2637 swl_idx = 0;
2638
2639 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002642 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 return (QLA_MEMORY_ALLOC_FAILED);
2644 }
2645 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 /* Set start port ID scan at adapter ID. */
2647 first_dev = 1;
2648 last_dev = 0;
2649
2650 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002651 loop_id = ha->min_external_loopid;
2652 for (; loop_id <= ha->max_loop_id; loop_id++) {
2653 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 continue;
2655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002656 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002657 break;
2658
2659 if (swl != NULL) {
2660 if (last_dev) {
2661 wrap.b24 = new_fcport->d_id.b24;
2662 } else {
2663 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2664 memcpy(new_fcport->node_name,
2665 swl[swl_idx].node_name, WWN_SIZE);
2666 memcpy(new_fcport->port_name,
2667 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002668 memcpy(new_fcport->fabric_port_name,
2669 swl[swl_idx].fabric_port_name, WWN_SIZE);
2670 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671
2672 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2673 last_dev = 1;
2674 }
2675 swl_idx++;
2676 }
2677 } else {
2678 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 if (rval != QLA_SUCCESS) {
2681 qla_printk(KERN_WARNING, ha,
2682 "SNS scan failed -- assuming zero-entry "
2683 "result...\n");
2684 list_for_each_entry_safe(fcport, fcptemp,
2685 new_fcports, list) {
2686 list_del(&fcport->list);
2687 kfree(fcport);
2688 }
2689 rval = QLA_SUCCESS;
2690 break;
2691 }
2692 }
2693
2694 /* If wrap on switch device list, exit. */
2695 if (first_dev) {
2696 wrap.b24 = new_fcport->d_id.b24;
2697 first_dev = 0;
2698 } else if (new_fcport->d_id.b24 == wrap.b24) {
2699 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2702 break;
2703 }
2704
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002705 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002706 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 continue;
2708
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002709 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002710 found = 0;
2711 if (ha->num_vhosts) {
2712 list_for_each_entry(vp, &ha->vp_list, list) {
2713 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2714 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002715 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002717 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002718 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002719 continue;
2720 }
2721
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002722 /* Bypass if same domain and area of adapter. */
2723 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002725 ISP_CFG_FL)
2726 continue;
2727
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728 /* Bypass reserved domain fields. */
2729 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2730 continue;
2731
2732 /* Locate matching device in database. */
2733 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735 if (memcmp(new_fcport->port_name, fcport->port_name,
2736 WWN_SIZE))
2737 continue;
2738
2739 found++;
2740
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002741 /* Update port state. */
2742 memcpy(fcport->fabric_port_name,
2743 new_fcport->fabric_port_name, WWN_SIZE);
2744 fcport->fp_speed = new_fcport->fp_speed;
2745
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 /*
2747 * If address the same and state FCS_ONLINE, nothing
2748 * changed.
2749 */
2750 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2751 atomic_read(&fcport->state) == FCS_ONLINE) {
2752 break;
2753 }
2754
2755 /*
2756 * If device was not a fabric device before.
2757 */
2758 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2759 fcport->d_id.b24 = new_fcport->d_id.b24;
2760 fcport->loop_id = FC_NO_LOOP_ID;
2761 fcport->flags |= (FCF_FABRIC_DEVICE |
2762 FCF_LOGIN_NEEDED);
2763 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2764 break;
2765 }
2766
2767 /*
2768 * Port ID changed or device was marked to be updated;
2769 * Log it out if still logged in and mark it for
2770 * relogin later.
2771 */
2772 fcport->d_id.b24 = new_fcport->d_id.b24;
2773 fcport->flags |= FCF_LOGIN_NEEDED;
2774 if (fcport->loop_id != FC_NO_LOOP_ID &&
2775 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2776 fcport->port_type != FCT_INITIATOR &&
2777 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002779 fcport->d_id.b.domain, fcport->d_id.b.area,
2780 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 fcport->loop_id = FC_NO_LOOP_ID;
2782 }
2783
2784 break;
2785 }
2786
2787 if (found)
2788 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 /* If device was not in our fcports list, then add it. */
2790 list_add_tail(&new_fcport->list, new_fcports);
2791
2792 /* Allocate a new replacement fcport. */
2793 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002794 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002795 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002796 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 return (QLA_MEMORY_ALLOC_FAILED);
2798 }
2799 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2800 new_fcport->d_id.b24 = nxt_d_id.b24;
2801 }
2802
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002803 kfree(swl);
2804 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805
2806 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002808
2809 return (rval);
2810}
2811
2812/*
2813 * qla2x00_find_new_loop_id
2814 * Scan through our port list and find a new usable loop ID.
2815 *
2816 * Input:
2817 * ha: adapter state pointer.
2818 * dev: port structure pointer.
2819 *
2820 * Returns:
2821 * qla2x00 local function return status code.
2822 *
2823 * Context:
2824 * Kernel context.
2825 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002826static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828{
2829 int rval;
2830 int found;
2831 fc_port_t *fcport;
2832 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002833 struct qla_hw_data *ha = vha->hw;
2834 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002835
2836 rval = QLA_SUCCESS;
2837
2838 /* Save starting loop ID. */
2839 first_loop_id = dev->loop_id;
2840
2841 for (;;) {
2842 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845
2846 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002848 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849
2850 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002851 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002852 /* first loop ID. */
2853 dev->loop_id = ha->min_external_loopid;
2854 }
2855
2856 /* Check for loop ID being already in use. */
2857 found = 0;
2858 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002859 list_for_each_entry(vp, &ha->vp_list, list) {
2860 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2861 if (fcport->loop_id == dev->loop_id &&
2862 fcport != dev) {
2863 /* ID possibly in use */
2864 found++;
2865 break;
2866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002867 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002868 if (found)
2869 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870 }
2871
2872 /* If not in use then it is free to use. */
2873 if (!found) {
2874 break;
2875 }
2876
2877 /* ID in use. Try next value. */
2878 dev->loop_id++;
2879
2880 /* If wrap around. No free ID to use. */
2881 if (dev->loop_id == first_loop_id) {
2882 dev->loop_id = FC_NO_LOOP_ID;
2883 rval = QLA_FUNCTION_FAILED;
2884 break;
2885 }
2886 }
2887
2888 return (rval);
2889}
2890
2891/*
2892 * qla2x00_device_resync
2893 * Marks devices in the database that needs resynchronization.
2894 *
2895 * Input:
2896 * ha = adapter block pointer.
2897 *
2898 * Context:
2899 * Kernel context.
2900 */
2901static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002902qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903{
2904 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 uint32_t mask;
2906 fc_port_t *fcport;
2907 uint32_t rscn_entry;
2908 uint8_t rscn_out_iter;
2909 uint8_t format;
2910 port_id_t d_id;
2911
2912 rval = QLA_RSCNS_HANDLED;
2913
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002914 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2915 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 format = MSB(MSW(rscn_entry));
2919 d_id.b.domain = LSB(MSW(rscn_entry));
2920 d_id.b.area = MSB(LSW(rscn_entry));
2921 d_id.b.al_pa = LSB(LSW(rscn_entry));
2922
2923 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2924 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 d_id.b.area, d_id.b.al_pa));
2927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002928 vha->rscn_out_ptr++;
2929 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2930 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931
2932 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002933 for (rscn_out_iter = vha->rscn_out_ptr;
2934 !vha->flags.rscn_queue_overflow &&
2935 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 rscn_out_iter = (rscn_out_iter ==
2937 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 break;
2941
2942 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002943 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 rscn_out_iter));
2945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002946 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002947 }
2948
2949 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002952 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953
2954 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 }
2957
2958 switch (format) {
2959 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 mask = 0xffffff;
2961 break;
2962 case 1:
2963 mask = 0xffff00;
2964 break;
2965 case 2:
2966 mask = 0xff0000;
2967 break;
2968 default:
2969 mask = 0x0;
2970 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002971 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 break;
2973 }
2974
2975 rval = QLA_SUCCESS;
2976
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002977 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002978 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2979 (fcport->d_id.b24 & mask) != d_id.b24 ||
2980 fcport->port_type == FCT_BROADCAST)
2981 continue;
2982
2983 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2984 if (format != 3 ||
2985 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002986 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002987 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 }
2989 }
2990 fcport->flags &= ~FCF_FARP_DONE;
2991 }
2992 }
2993 return (rval);
2994}
2995
2996/*
2997 * qla2x00_fabric_dev_login
2998 * Login fabric target device and update FC port database.
2999 *
3000 * Input:
3001 * ha: adapter state pointer.
3002 * fcport: port structure list pointer.
3003 * next_loopid: contains value of a new loop ID that can be used
3004 * by the next login attempt.
3005 *
3006 * Returns:
3007 * qla2x00 local function return status code.
3008 *
3009 * Context:
3010 * Kernel context.
3011 */
3012static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 uint16_t *next_loopid)
3015{
3016 int rval;
3017 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003018 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020
3021 rval = QLA_SUCCESS;
3022 retry = 0;
3023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003024 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003026 /* Send an ADISC to tape devices.*/
3027 opts = 0;
3028 if (fcport->flags & FCF_TAPE_PRESENT)
3029 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003030 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003031 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003033 fcport->d_id.b.domain, fcport->d_id.b.area,
3034 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003035 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003037 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 }
3039 }
3040
3041 return (rval);
3042}
3043
3044/*
3045 * qla2x00_fabric_login
3046 * Issue fabric login command.
3047 *
3048 * Input:
3049 * ha = adapter block pointer.
3050 * device = pointer to FC device type structure.
3051 *
3052 * Returns:
3053 * 0 - Login successfully
3054 * 1 - Login failed
3055 * 2 - Initiator device
3056 * 3 - Fatal error
3057 */
3058int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003059qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003060 uint16_t *next_loopid)
3061{
3062 int rval;
3063 int retry;
3064 uint16_t tmp_loopid;
3065 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003066 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067
3068 retry = 0;
3069 tmp_loopid = 0;
3070
3071 for (;;) {
3072 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3073 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003074 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3076
3077 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003078 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 fcport->d_id.b.domain, fcport->d_id.b.area,
3080 fcport->d_id.b.al_pa, mb, BIT_0);
3081 if (mb[0] == MBS_PORT_ID_USED) {
3082 /*
3083 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003084 * recommends the driver perform an implicit login with
3085 * the specified ID again. The ID we just used is save
3086 * here so we return with an ID that can be tried by
3087 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 */
3089 retry++;
3090 tmp_loopid = fcport->loop_id;
3091 fcport->loop_id = mb[1];
3092
3093 DEBUG(printk("Fabric Login: port in use - next "
3094 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3095 fcport->loop_id, fcport->d_id.b.domain,
3096 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3097
3098 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3099 /*
3100 * Login succeeded.
3101 */
3102 if (retry) {
3103 /* A retry occurred before. */
3104 *next_loopid = tmp_loopid;
3105 } else {
3106 /*
3107 * No retry occurred before. Just increment the
3108 * ID value for next login.
3109 */
3110 *next_loopid = (fcport->loop_id + 1);
3111 }
3112
3113 if (mb[1] & BIT_0) {
3114 fcport->port_type = FCT_INITIATOR;
3115 } else {
3116 fcport->port_type = FCT_TARGET;
3117 if (mb[1] & BIT_1) {
3118 fcport->flags |= FCF_TAPE_PRESENT;
3119 }
3120 }
3121
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003122 if (mb[10] & BIT_0)
3123 fcport->supported_classes |= FC_COS_CLASS2;
3124 if (mb[10] & BIT_1)
3125 fcport->supported_classes |= FC_COS_CLASS3;
3126
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 rval = QLA_SUCCESS;
3128 break;
3129 } else if (mb[0] == MBS_LOOP_ID_USED) {
3130 /*
3131 * Loop ID already used, try next loop ID.
3132 */
3133 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003134 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135 if (rval != QLA_SUCCESS) {
3136 /* Ran out of loop IDs to use */
3137 break;
3138 }
3139 } else if (mb[0] == MBS_COMMAND_ERROR) {
3140 /*
3141 * Firmware possibly timed out during login. If NO
3142 * retries are left to do then the device is declared
3143 * dead.
3144 */
3145 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003147 fcport->d_id.b.domain, fcport->d_id.b.area,
3148 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003149 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003150
3151 rval = 1;
3152 break;
3153 } else {
3154 /*
3155 * unrecoverable / not handled error
3156 */
3157 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003158 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003159 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 fcport->d_id.b.domain, fcport->d_id.b.area,
3161 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3162
3163 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003165 fcport->d_id.b.domain, fcport->d_id.b.area,
3166 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003167 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003168 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169
3170 rval = 3;
3171 break;
3172 }
3173 }
3174
3175 return (rval);
3176}
3177
3178/*
3179 * qla2x00_local_device_login
3180 * Issue local device login command.
3181 *
3182 * Input:
3183 * ha = adapter block pointer.
3184 * loop_id = loop id of device to login to.
3185 *
3186 * Returns (Where's the #define!!!!):
3187 * 0 - Login successfully
3188 * 1 - Login failed
3189 * 3 - Fatal error
3190 */
3191int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003193{
3194 int rval;
3195 uint16_t mb[MAILBOX_REGISTER_COUNT];
3196
3197 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 if (rval == QLA_SUCCESS) {
3200 /* Interrogate mailbox registers for any errors */
3201 if (mb[0] == MBS_COMMAND_ERROR)
3202 rval = 1;
3203 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3204 /* device not in PCB table */
3205 rval = 3;
3206 }
3207
3208 return (rval);
3209}
3210
3211/*
3212 * qla2x00_loop_resync
3213 * Resync with fibre channel devices.
3214 *
3215 * Input:
3216 * ha = adapter block pointer.
3217 *
3218 * Returns:
3219 * 0 = success
3220 */
3221int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003222qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003224 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003226 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003227 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
3228 struct rsp_que *rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230 atomic_set(&vha->loop_state, LOOP_UPDATE);
3231 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3232 if (vha->flags.online) {
3233 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3235 wait_time = 256;
3236 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003239 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003240 qla2x00_marker(vha, req, rsp, 0, 0,
3241 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243
3244 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003247 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003249 } while (!atomic_read(&vha->loop_down_timer) &&
3250 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3251 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3252 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003254 }
3255
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261
3262 return (rval);
3263}
3264
Linus Torvalds1da177e2005-04-16 15:20:36 -07003265void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003266qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003267{
3268 fc_port_t *fcport;
3269
3270 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 list_for_each_entry(fcport, &vha->vp_fcports, list)
3272 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003273 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003274 qla2x00_rport_del(fcport);
3275}
3276
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277/*
3278* qla2x00_abort_isp
3279* Resets ISP and aborts all outstanding commands.
3280*
3281* Input:
3282* ha = adapter block pointer.
3283*
3284* Returns:
3285* 0 = success
3286*/
3287int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003288qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003289{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003290 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003292 struct qla_hw_data *ha = vha->hw;
3293 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003294 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003296 if (vha->flags.online) {
3297 vha->flags.online = 0;
3298 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003299 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300
3301 qla_printk(KERN_INFO, ha,
3302 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3306 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3307 atomic_set(&vha->loop_state, LOOP_DOWN);
3308 qla2x00_mark_all_devices_lost(vha, 0);
3309 list_for_each_entry(vp, &ha->vp_list, list)
3310 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003312 if (!atomic_read(&vha->loop_down_timer))
3313 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314 LOOP_DOWN_TIME);
3315 }
3316
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003318 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003320 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003321
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003323
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003324 if (!qla2x00_restart_isp(vha)) {
3325 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003326
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003327 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 /*
3329 * Issue marker command only when we are going
3330 * to start the I/O .
3331 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003332 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 }
3334
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003335 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003337 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003339 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003340 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003341
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003342 if (ha->fce) {
3343 ha->flags.fce_enabled = 1;
3344 memset(ha->fce, 0,
3345 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003346 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003347 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3348 &ha->fce_bufs);
3349 if (rval) {
3350 qla_printk(KERN_WARNING, ha,
3351 "Unable to reinitialize FCE "
3352 "(%d).\n", rval);
3353 ha->flags.fce_enabled = 0;
3354 }
3355 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003356
3357 if (ha->eft) {
3358 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003359 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003360 ha->eft_dma, EFT_NUM_BUFFERS);
3361 if (rval) {
3362 qla_printk(KERN_WARNING, ha,
3363 "Unable to reinitialize EFT "
3364 "(%d).\n", rval);
3365 }
3366 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003368 vha->flags.online = 1;
3369 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 if (ha->isp_abort_cnt == 0) {
3371 qla_printk(KERN_WARNING, ha,
3372 "ISP error recovery failed - "
3373 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003374 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 * The next call disables the board
3376 * completely.
3377 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 ha->isp_ops->reset_adapter(vha);
3379 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003382 status = 0;
3383 } else { /* schedule another ISP abort */
3384 ha->isp_abort_cnt--;
3385 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003386 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003387 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003388 status = 1;
3389 }
3390 } else {
3391 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3392 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3393 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003394 vha->host_no, ha->isp_abort_cnt));
3395 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003396 status = 1;
3397 }
3398 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003399
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 }
3401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 if (!status) {
3403 DEBUG(printk(KERN_INFO
3404 "qla2x00_abort_isp(%ld): succeeded.\n",
3405 vha->host_no));
3406 list_for_each_entry(vp, &ha->vp_list, list) {
3407 if (vp->vp_idx)
3408 qla2x00_vp_abort_isp(vp);
3409 }
3410 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 qla_printk(KERN_INFO, ha,
3412 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 }
3414
3415 return(status);
3416}
3417
3418/*
3419* qla2x00_restart_isp
3420* restarts the ISP after a reset
3421*
3422* Input:
3423* ha = adapter block pointer.
3424*
3425* Returns:
3426* 0 = success
3427*/
3428static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003430{
3431 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003432 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003434 struct req_que *req = ha->req_q_map[0];
3435 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436
3437 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003438 if (qla2x00_isp_firmware(vha)) {
3439 vha->flags.online = 0;
3440 status = ha->isp_ops->chip_diag(vha);
3441 if (!status)
3442 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 }
3444
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003445 if (!status && !(status = qla2x00_init_rings(vha))) {
3446 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003447 /* Initialize the queues in use */
3448 qla25xx_init_queues(ha);
3449
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003450 status = qla2x00_fw_ready(vha);
3451 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003453 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003454
3455 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003456 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003457
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003458 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003459 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3460 wait_time = 256;
3461 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003462 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3463 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003464 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003465 } while (!atomic_read(&vha->loop_down_timer) &&
3466 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3467 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3468 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 }
3470
3471 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 status = 0;
3474
3475 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3476 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003477 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003478 }
3479 return (status);
3480}
3481
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003482static int
3483qla25xx_init_queues(struct qla_hw_data *ha)
3484{
3485 struct rsp_que *rsp = NULL;
3486 struct req_que *req = NULL;
3487 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3488 int ret = -1;
3489 int i;
3490
3491 for (i = 1; i < ha->max_queues; i++) {
3492 rsp = ha->rsp_q_map[i];
3493 if (rsp) {
3494 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003495 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003496 if (ret != QLA_SUCCESS)
3497 DEBUG2_17(printk(KERN_WARNING
3498 "%s Rsp que:%d init failed\n", __func__,
3499 rsp->id));
3500 else
3501 DEBUG2_17(printk(KERN_INFO
3502 "%s Rsp que:%d inited\n", __func__,
3503 rsp->id));
3504 }
3505 req = ha->req_q_map[i];
3506 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003507 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003508 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003509 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003510 if (ret != QLA_SUCCESS)
3511 DEBUG2_17(printk(KERN_WARNING
3512 "%s Req que:%d init failed\n", __func__,
3513 req->id));
3514 else
3515 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003516 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003517 req->id));
3518 }
3519 }
3520 return ret;
3521}
3522
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523/*
3524* qla2x00_reset_adapter
3525* Reset adapter.
3526*
3527* Input:
3528* ha = adapter block pointer.
3529*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003530void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003532{
3533 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003534 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003535 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003537 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003538 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003539
Linus Torvalds1da177e2005-04-16 15:20:36 -07003540 spin_lock_irqsave(&ha->hardware_lock, flags);
3541 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3542 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3543 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3544 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3545 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3546}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003547
3548void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003549qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003550{
3551 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003553 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3554
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003555 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003556 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003557
3558 spin_lock_irqsave(&ha->hardware_lock, flags);
3559 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3560 RD_REG_DWORD(&reg->hccr);
3561 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3562 RD_REG_DWORD(&reg->hccr);
3563 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003564
3565 if (IS_NOPOLLING_TYPE(ha))
3566 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003567}
3568
David Miller4e08df32007-04-16 12:37:43 -07003569/* On sparc systems, obtain port and node WWN from firmware
3570 * properties.
3571 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003572static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3573 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003574{
3575#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003576 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003577 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003578 struct device_node *dp = pci_device_to_OF_node(pdev);
3579 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003580 int len;
3581
3582 val = of_get_property(dp, "port-wwn", &len);
3583 if (val && len >= WWN_SIZE)
3584 memcpy(nv->port_name, val, WWN_SIZE);
3585
3586 val = of_get_property(dp, "node-wwn", &len);
3587 if (val && len >= WWN_SIZE)
3588 memcpy(nv->node_name, val, WWN_SIZE);
3589#endif
3590}
3591
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003592int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003593qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003594{
David Miller4e08df32007-04-16 12:37:43 -07003595 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003596 struct init_cb_24xx *icb;
3597 struct nvram_24xx *nv;
3598 uint32_t *dptr;
3599 uint8_t *dptr1, *dptr2;
3600 uint32_t chksum;
3601 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003603
David Miller4e08df32007-04-16 12:37:43 -07003604 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003605 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003606 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003607
3608 /* Determine NVRAM starting address. */
3609 ha->nvram_size = sizeof(struct nvram_24xx);
3610 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003611 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3612 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3613 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003614 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003615 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3616 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003617
Seokmann Ju281afe12007-07-26 13:43:34 -07003618 /* Get VPD data into cache */
3619 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003620 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003621 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3622
3623 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003624 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003625 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003626 ha->nvram_size);
3627 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3628 chksum += le32_to_cpu(*dptr++);
3629
3630 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003631 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003632
3633 /* Bad NVRAM data, set defaults parameters. */
3634 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3635 || nv->id[3] != ' ' ||
3636 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3637 /* Reset NVRAM data. */
3638 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3639 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3640 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003641 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3642 "invalid -- WWPN) defaults.\n");
3643
3644 /*
3645 * Set default initialization control block.
3646 */
3647 memset(nv, 0, ha->nvram_size);
3648 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3649 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3650 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3651 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3652 nv->exchange_count = __constant_cpu_to_le16(0);
3653 nv->hard_address = __constant_cpu_to_le16(124);
3654 nv->port_name[0] = 0x21;
3655 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3656 nv->port_name[2] = 0x00;
3657 nv->port_name[3] = 0xe0;
3658 nv->port_name[4] = 0x8b;
3659 nv->port_name[5] = 0x1c;
3660 nv->port_name[6] = 0x55;
3661 nv->port_name[7] = 0x86;
3662 nv->node_name[0] = 0x20;
3663 nv->node_name[1] = 0x00;
3664 nv->node_name[2] = 0x00;
3665 nv->node_name[3] = 0xe0;
3666 nv->node_name[4] = 0x8b;
3667 nv->node_name[5] = 0x1c;
3668 nv->node_name[6] = 0x55;
3669 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003670 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003671 nv->login_retry_count = __constant_cpu_to_le16(8);
3672 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3673 nv->login_timeout = __constant_cpu_to_le16(0);
3674 nv->firmware_options_1 =
3675 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3676 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3677 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3678 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3679 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3680 nv->efi_parameters = __constant_cpu_to_le32(0);
3681 nv->reset_delay = 5;
3682 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3683 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3684 nv->link_down_timeout = __constant_cpu_to_le16(30);
3685
3686 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003687 }
3688
3689 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003690 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003691
3692 /* Copy 1st segment. */
3693 dptr1 = (uint8_t *)icb;
3694 dptr2 = (uint8_t *)&nv->version;
3695 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3696 while (cnt--)
3697 *dptr1++ = *dptr2++;
3698
3699 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003700 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003701
3702 /* Copy 2nd segment. */
3703 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3704 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3705 cnt = (uint8_t *)&icb->reserved_3 -
3706 (uint8_t *)&icb->interrupt_delay_timer;
3707 while (cnt--)
3708 *dptr1++ = *dptr2++;
3709
3710 /*
3711 * Setup driver NVRAM options.
3712 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003713 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003714 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003715
Andrew Vasquez5341e862006-05-17 15:09:16 -07003716 /* Use alternate WWN? */
3717 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3718 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3719 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3720 }
3721
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003722 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003723 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003724 /*
3725 * Firmware will apply the following mask if the nodename was
3726 * not provided.
3727 */
3728 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3729 icb->node_name[0] &= 0xF0;
3730 }
3731
3732 /* Set host adapter parameters. */
3733 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003734 ha->flags.enable_lip_reset = 0;
3735 ha->flags.enable_lip_full_login =
3736 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3737 ha->flags.enable_target_reset =
3738 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003739 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003740 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003741
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003742 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3743 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003744
3745 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3746 sizeof(ha->fw_seriallink_options24));
3747
3748 /* save HBA serial number */
3749 ha->serial0 = icb->port_name[5];
3750 ha->serial1 = icb->port_name[6];
3751 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003752 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3753 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003754
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003755 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3756
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003757 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3758
3759 /* Set minimum login_timeout to 4 seconds. */
3760 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3761 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3762 if (le16_to_cpu(nv->login_timeout) < 4)
3763 nv->login_timeout = __constant_cpu_to_le16(4);
3764 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003765 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003766
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003767 /* Set minimum RATOV to 100 tenths of a second. */
3768 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003769
3770 ha->loop_reset_delay = nv->reset_delay;
3771
3772 /* Link Down Timeout = 0:
3773 *
3774 * When Port Down timer expires we will start returning
3775 * I/O's to OS with "DID_NO_CONNECT".
3776 *
3777 * Link Down Timeout != 0:
3778 *
3779 * The driver waits for the link to come up after link down
3780 * before returning I/Os to OS with "DID_NO_CONNECT".
3781 */
3782 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3783 ha->loop_down_abort_time =
3784 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3785 } else {
3786 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3787 ha->loop_down_abort_time =
3788 (LOOP_DOWN_TIME - ha->link_down_timeout);
3789 }
3790
3791 /* Need enough time to try and get the port back. */
3792 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3793 if (qlport_down_retry)
3794 ha->port_down_retry_count = qlport_down_retry;
3795
3796 /* Set login_retry_count */
3797 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3798 if (ha->port_down_retry_count ==
3799 le16_to_cpu(nv->port_down_retry_count) &&
3800 ha->port_down_retry_count > 3)
3801 ha->login_retry_count = ha->port_down_retry_count;
3802 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3803 ha->login_retry_count = ha->port_down_retry_count;
3804 if (ql2xloginretrycount)
3805 ha->login_retry_count = ql2xloginretrycount;
3806
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003807 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003809 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3810 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3811 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3812 le16_to_cpu(icb->interrupt_delay_timer): 2;
3813 }
3814 icb->firmware_options_2 &= __constant_cpu_to_le32(
3815 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003817 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003818 ha->zio_mode = QLA_ZIO_MODE_6;
3819
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003820 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003822 ha->zio_timer * 100));
3823 qla_printk(KERN_INFO, ha,
3824 "ZIO mode %d enabled; timer delay (%d us).\n",
3825 ha->zio_mode, ha->zio_timer * 100);
3826
3827 icb->firmware_options_2 |= cpu_to_le32(
3828 (uint32_t)ha->zio_mode);
3829 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003831 }
3832
David Miller4e08df32007-04-16 12:37:43 -07003833 if (rval) {
3834 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003836 }
3837 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003838}
3839
Adrian Bunk413975a2006-06-30 02:33:06 -07003840static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003842{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003843 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003844 int segments, fragment;
3845 uint32_t faddr;
3846 uint32_t *dcode, dlen;
3847 uint32_t risc_addr;
3848 uint32_t risc_size;
3849 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003850 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003851 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003852
3853 qla_printk(KERN_INFO, ha,
3854 "FW: Loading from flash (%x)...\n", ha->flt_region_fw);
3855
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003856 rval = QLA_SUCCESS;
3857
3858 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003859 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003860 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003861 *srisc_addr = 0;
3862
3863 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003864 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003865 for (i = 0; i < 4; i++)
3866 dcode[i] = be32_to_cpu(dcode[i]);
3867 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3868 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3869 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3870 dcode[3] == 0)) {
3871 qla_printk(KERN_WARNING, ha,
3872 "Unable to verify integrity of flash firmware image!\n");
3873 qla_printk(KERN_WARNING, ha,
3874 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3875 dcode[1], dcode[2], dcode[3]);
3876
3877 return QLA_FUNCTION_FAILED;
3878 }
3879
3880 while (segments && rval == QLA_SUCCESS) {
3881 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003883
3884 risc_addr = be32_to_cpu(dcode[2]);
3885 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3886 risc_size = be32_to_cpu(dcode[3]);
3887
3888 fragment = 0;
3889 while (risc_size > 0 && rval == QLA_SUCCESS) {
3890 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3891 if (dlen > risc_size)
3892 dlen = risc_size;
3893
3894 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3895 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003896 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003898 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003899 for (i = 0; i < dlen; i++)
3900 dcode[i] = swab32(dcode[i]);
3901
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003902 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003903 dlen);
3904 if (rval) {
3905 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003906 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003907 fragment));
3908 qla_printk(KERN_WARNING, ha,
3909 "[ERROR] Failed to load segment %d of "
3910 "firmware\n", fragment);
3911 break;
3912 }
3913
3914 faddr += dlen;
3915 risc_addr += dlen;
3916 risc_size -= dlen;
3917 fragment++;
3918 }
3919
3920 /* Next segment. */
3921 segments--;
3922 }
3923
3924 return rval;
3925}
3926
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003927#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3928
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003929int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003930qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003931{
3932 int rval;
3933 int i, fragment;
3934 uint16_t *wcode, *fwcode;
3935 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3936 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003937 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003938 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003939
3940 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003941 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003942 if (!blob) {
3943 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003944 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3945 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003946 return QLA_FUNCTION_FAILED;
3947 }
3948
3949 rval = QLA_SUCCESS;
3950
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003951 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003952 *srisc_addr = 0;
3953 fwcode = (uint16_t *)blob->fw->data;
3954 fwclen = 0;
3955
3956 /* Validate firmware image by checking version. */
3957 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3958 qla_printk(KERN_WARNING, ha,
3959 "Unable to verify integrity of firmware image (%Zd)!\n",
3960 blob->fw->size);
3961 goto fail_fw_integrity;
3962 }
3963 for (i = 0; i < 4; i++)
3964 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3965 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3966 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3967 wcode[2] == 0 && wcode[3] == 0)) {
3968 qla_printk(KERN_WARNING, ha,
3969 "Unable to verify integrity of firmware image!\n");
3970 qla_printk(KERN_WARNING, ha,
3971 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3972 wcode[1], wcode[2], wcode[3]);
3973 goto fail_fw_integrity;
3974 }
3975
3976 seg = blob->segs;
3977 while (*seg && rval == QLA_SUCCESS) {
3978 risc_addr = *seg;
3979 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3980 risc_size = be16_to_cpu(fwcode[3]);
3981
3982 /* Validate firmware image size. */
3983 fwclen += risc_size * sizeof(uint16_t);
3984 if (blob->fw->size < fwclen) {
3985 qla_printk(KERN_WARNING, ha,
3986 "Unable to verify integrity of firmware image "
3987 "(%Zd)!\n", blob->fw->size);
3988 goto fail_fw_integrity;
3989 }
3990
3991 fragment = 0;
3992 while (risc_size > 0 && rval == QLA_SUCCESS) {
3993 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3994 if (wlen > risc_size)
3995 wlen = risc_size;
3996
3997 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003998 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003999 risc_addr, wlen));
4000
4001 for (i = 0; i < wlen; i++)
4002 wcode[i] = swab16(fwcode[i]);
4003
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004004 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004005 wlen);
4006 if (rval) {
4007 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004009 fragment));
4010 qla_printk(KERN_WARNING, ha,
4011 "[ERROR] Failed to load segment %d of "
4012 "firmware\n", fragment);
4013 break;
4014 }
4015
4016 fwcode += wlen;
4017 risc_addr += wlen;
4018 risc_size -= wlen;
4019 fragment++;
4020 }
4021
4022 /* Next segment. */
4023 seg++;
4024 }
4025 return rval;
4026
4027fail_fw_integrity:
4028 return QLA_FUNCTION_FAILED;
4029}
4030
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004031static int
4032qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004033{
4034 int rval;
4035 int segments, fragment;
4036 uint32_t *dcode, dlen;
4037 uint32_t risc_addr;
4038 uint32_t risc_size;
4039 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004040 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004041 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004042 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004043 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004044
Andrew Vasquez54333832005-11-09 15:49:04 -08004045 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004046 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004047 if (!blob) {
4048 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004049 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4050 "from: " QLA_FW_URL ".\n");
4051
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004052 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004053 }
4054
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004055 qla_printk(KERN_INFO, ha,
4056 "FW: Loading via request-firmware...\n");
4057
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004058 rval = QLA_SUCCESS;
4059
4060 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004061 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004062 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004063 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004064 fwclen = 0;
4065
4066 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004067 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004068 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004069 "Unable to verify integrity of firmware image (%Zd)!\n",
4070 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004071 goto fail_fw_integrity;
4072 }
4073 for (i = 0; i < 4; i++)
4074 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4075 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4076 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4077 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4078 dcode[3] == 0)) {
4079 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004080 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004081 qla_printk(KERN_WARNING, ha,
4082 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4083 dcode[1], dcode[2], dcode[3]);
4084 goto fail_fw_integrity;
4085 }
4086
4087 while (segments && rval == QLA_SUCCESS) {
4088 risc_addr = be32_to_cpu(fwcode[2]);
4089 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4090 risc_size = be32_to_cpu(fwcode[3]);
4091
4092 /* Validate firmware image size. */
4093 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004094 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004095 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004096 "Unable to verify integrity of firmware image "
4097 "(%Zd)!\n", blob->fw->size);
4098
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004099 goto fail_fw_integrity;
4100 }
4101
4102 fragment = 0;
4103 while (risc_size > 0 && rval == QLA_SUCCESS) {
4104 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4105 if (dlen > risc_size)
4106 dlen = risc_size;
4107
4108 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004109 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004110 risc_addr, dlen));
4111
4112 for (i = 0; i < dlen; i++)
4113 dcode[i] = swab32(fwcode[i]);
4114
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004115 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004116 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004117 if (rval) {
4118 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004120 fragment));
4121 qla_printk(KERN_WARNING, ha,
4122 "[ERROR] Failed to load segment %d of "
4123 "firmware\n", fragment);
4124 break;
4125 }
4126
4127 fwcode += dlen;
4128 risc_addr += dlen;
4129 risc_size -= dlen;
4130 fragment++;
4131 }
4132
4133 /* Next segment. */
4134 segments--;
4135 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004136 return rval;
4137
4138fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004139 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004140}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004141
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004142int
4143qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4144{
4145 int rval;
4146
4147 /*
4148 * FW Load priority:
4149 * 1) Firmware via request-firmware interface (.bin file).
4150 * 2) Firmware residing in flash.
4151 */
4152 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4153 if (rval == QLA_SUCCESS)
4154 return rval;
4155
4156 return qla24xx_load_risc_flash(vha, srisc_addr);
4157}
4158
4159int
4160qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4161{
4162 int rval;
4163
4164 /*
4165 * FW Load priority:
4166 * 1) Firmware residing in flash.
4167 * 2) Firmware via request-firmware interface (.bin file).
4168 */
4169 rval = qla24xx_load_risc_flash(vha, srisc_addr);
4170 if (rval == QLA_SUCCESS)
4171 return rval;
4172
4173 return qla24xx_load_risc_blob(vha, srisc_addr);
4174}
4175
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004176void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004177qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004178{
4179 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004180 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004181
Andrew Vasqueze4289242007-07-19 15:05:56 -07004182 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004183 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004184 if (!ha->fw_major_version)
4185 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004186
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004188 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4189 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 ha->isp_ops->reset_chip(vha);
4191 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004192 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004194 continue;
4195 qla_printk(KERN_INFO, ha,
4196 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004197 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004198 }
4199}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004200
4201int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004202qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004203{
4204 int rval = QLA_SUCCESS;
4205 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004206 struct qla_hw_data *ha = vha->hw;
4207 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004208 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
4209 struct rsp_que *rsp = req->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004210
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004211 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004212 return -EINVAL;
4213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004214 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004215 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004216 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004217 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004218 }
4219
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004220 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004221
4222 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004223 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004224 if (mb[0] != MBS_COMMAND_COMPLETE) {
4225 DEBUG15(qla_printk(KERN_INFO, ha,
4226 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4227 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4228 mb[0], mb[1], mb[2], mb[6], mb[7]));
4229 return (QLA_FUNCTION_FAILED);
4230 }
4231
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232 atomic_set(&vha->loop_down_timer, 0);
4233 atomic_set(&vha->loop_state, LOOP_UP);
4234 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4235 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4236 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004237
4238 return rval;
4239}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004240
4241/* 84XX Support **************************************************************/
4242
4243static LIST_HEAD(qla_cs84xx_list);
4244static DEFINE_MUTEX(qla_cs84xx_mutex);
4245
4246static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004247qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004248{
4249 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004250 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251
4252 mutex_lock(&qla_cs84xx_mutex);
4253
4254 /* Find any shared 84xx chip. */
4255 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4256 if (cs84xx->bus == ha->pdev->bus) {
4257 kref_get(&cs84xx->kref);
4258 goto done;
4259 }
4260 }
4261
4262 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4263 if (!cs84xx)
4264 goto done;
4265
4266 kref_init(&cs84xx->kref);
4267 spin_lock_init(&cs84xx->access_lock);
4268 mutex_init(&cs84xx->fw_update_mutex);
4269 cs84xx->bus = ha->pdev->bus;
4270
4271 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4272done:
4273 mutex_unlock(&qla_cs84xx_mutex);
4274 return cs84xx;
4275}
4276
4277static void
4278__qla84xx_chip_release(struct kref *kref)
4279{
4280 struct qla_chip_state_84xx *cs84xx =
4281 container_of(kref, struct qla_chip_state_84xx, kref);
4282
4283 mutex_lock(&qla_cs84xx_mutex);
4284 list_del(&cs84xx->list);
4285 mutex_unlock(&qla_cs84xx_mutex);
4286 kfree(cs84xx);
4287}
4288
4289void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004290qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004291{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004292 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004293 if (ha->cs84xx)
4294 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4295}
4296
4297static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004298qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004299{
4300 int rval;
4301 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004302 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004303
4304 mutex_lock(&ha->cs84xx->fw_update_mutex);
4305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004306 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004307
4308 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4309
4310 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4311 QLA_SUCCESS;
4312}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004313
4314/* 81XX Support **************************************************************/
4315
4316int
4317qla81xx_nvram_config(scsi_qla_host_t *vha)
4318{
4319 int rval;
4320 struct init_cb_81xx *icb;
4321 struct nvram_81xx *nv;
4322 uint32_t *dptr;
4323 uint8_t *dptr1, *dptr2;
4324 uint32_t chksum;
4325 uint16_t cnt;
4326 struct qla_hw_data *ha = vha->hw;
4327
4328 rval = QLA_SUCCESS;
4329 icb = (struct init_cb_81xx *)ha->init_cb;
4330 nv = ha->nvram;
4331
4332 /* Determine NVRAM starting address. */
4333 ha->nvram_size = sizeof(struct nvram_81xx);
4334 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4335 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4336 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4337 if (PCI_FUNC(ha->pdev->devfn) & 1) {
4338 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4339 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4340 }
4341
4342 /* Get VPD data into cache */
4343 ha->vpd = ha->nvram + VPD_OFFSET;
4344 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4345 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4346
4347 /* Get NVRAM data into cache and calculate checksum. */
4348 dptr = (uint32_t *)nv;
4349 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4350 ha->nvram_size);
4351 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4352 chksum += le32_to_cpu(*dptr++);
4353
4354 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4355 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4356
4357 /* Bad NVRAM data, set defaults parameters. */
4358 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4359 || nv->id[3] != ' ' ||
4360 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4361 /* Reset NVRAM data. */
4362 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4363 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4364 le16_to_cpu(nv->nvram_version));
4365 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4366 "invalid -- WWPN) defaults.\n");
4367
4368 /*
4369 * Set default initialization control block.
4370 */
4371 memset(nv, 0, ha->nvram_size);
4372 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4373 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4374 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4375 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4376 nv->exchange_count = __constant_cpu_to_le16(0);
4377 nv->port_name[0] = 0x21;
4378 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4379 nv->port_name[2] = 0x00;
4380 nv->port_name[3] = 0xe0;
4381 nv->port_name[4] = 0x8b;
4382 nv->port_name[5] = 0x1c;
4383 nv->port_name[6] = 0x55;
4384 nv->port_name[7] = 0x86;
4385 nv->node_name[0] = 0x20;
4386 nv->node_name[1] = 0x00;
4387 nv->node_name[2] = 0x00;
4388 nv->node_name[3] = 0xe0;
4389 nv->node_name[4] = 0x8b;
4390 nv->node_name[5] = 0x1c;
4391 nv->node_name[6] = 0x55;
4392 nv->node_name[7] = 0x86;
4393 nv->login_retry_count = __constant_cpu_to_le16(8);
4394 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4395 nv->login_timeout = __constant_cpu_to_le16(0);
4396 nv->firmware_options_1 =
4397 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4398 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4399 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4400 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4401 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4402 nv->efi_parameters = __constant_cpu_to_le32(0);
4403 nv->reset_delay = 5;
4404 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4405 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4406 nv->link_down_timeout = __constant_cpu_to_le16(30);
4407 nv->enode_mac[0] = 0x01;
4408 nv->enode_mac[1] = 0x02;
4409 nv->enode_mac[2] = 0x03;
4410 nv->enode_mac[3] = 0x04;
4411 nv->enode_mac[4] = 0x05;
4412 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4413
4414 rval = 1;
4415 }
4416
4417 /* Reset Initialization control block */
4418 memset(icb, 0, sizeof(struct init_cb_81xx));
4419
4420 /* Copy 1st segment. */
4421 dptr1 = (uint8_t *)icb;
4422 dptr2 = (uint8_t *)&nv->version;
4423 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4424 while (cnt--)
4425 *dptr1++ = *dptr2++;
4426
4427 icb->login_retry_count = nv->login_retry_count;
4428
4429 /* Copy 2nd segment. */
4430 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4431 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4432 cnt = (uint8_t *)&icb->reserved_5 -
4433 (uint8_t *)&icb->interrupt_delay_timer;
4434 while (cnt--)
4435 *dptr1++ = *dptr2++;
4436
4437 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4438 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4439 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4440 icb->enode_mac[0] = 0x01;
4441 icb->enode_mac[1] = 0x02;
4442 icb->enode_mac[2] = 0x03;
4443 icb->enode_mac[3] = 0x04;
4444 icb->enode_mac[4] = 0x05;
4445 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4446 }
4447
4448 /*
4449 * Setup driver NVRAM options.
4450 */
4451 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4452 "QLE81XX");
4453
4454 /* Use alternate WWN? */
4455 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4456 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4457 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4458 }
4459
4460 /* Prepare nodename */
4461 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4462 /*
4463 * Firmware will apply the following mask if the nodename was
4464 * not provided.
4465 */
4466 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4467 icb->node_name[0] &= 0xF0;
4468 }
4469
4470 /* Set host adapter parameters. */
4471 ha->flags.disable_risc_code_load = 0;
4472 ha->flags.enable_lip_reset = 0;
4473 ha->flags.enable_lip_full_login =
4474 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4475 ha->flags.enable_target_reset =
4476 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4477 ha->flags.enable_led_scheme = 0;
4478 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4479
4480 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4481 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4482
4483 /* save HBA serial number */
4484 ha->serial0 = icb->port_name[5];
4485 ha->serial1 = icb->port_name[6];
4486 ha->serial2 = icb->port_name[7];
4487 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4488 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4489
4490 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4491
4492 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4493
4494 /* Set minimum login_timeout to 4 seconds. */
4495 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4496 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4497 if (le16_to_cpu(nv->login_timeout) < 4)
4498 nv->login_timeout = __constant_cpu_to_le16(4);
4499 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4500 icb->login_timeout = nv->login_timeout;
4501
4502 /* Set minimum RATOV to 100 tenths of a second. */
4503 ha->r_a_tov = 100;
4504
4505 ha->loop_reset_delay = nv->reset_delay;
4506
4507 /* Link Down Timeout = 0:
4508 *
4509 * When Port Down timer expires we will start returning
4510 * I/O's to OS with "DID_NO_CONNECT".
4511 *
4512 * Link Down Timeout != 0:
4513 *
4514 * The driver waits for the link to come up after link down
4515 * before returning I/Os to OS with "DID_NO_CONNECT".
4516 */
4517 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4518 ha->loop_down_abort_time =
4519 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4520 } else {
4521 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4522 ha->loop_down_abort_time =
4523 (LOOP_DOWN_TIME - ha->link_down_timeout);
4524 }
4525
4526 /* Need enough time to try and get the port back. */
4527 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4528 if (qlport_down_retry)
4529 ha->port_down_retry_count = qlport_down_retry;
4530
4531 /* Set login_retry_count */
4532 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4533 if (ha->port_down_retry_count ==
4534 le16_to_cpu(nv->port_down_retry_count) &&
4535 ha->port_down_retry_count > 3)
4536 ha->login_retry_count = ha->port_down_retry_count;
4537 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4538 ha->login_retry_count = ha->port_down_retry_count;
4539 if (ql2xloginretrycount)
4540 ha->login_retry_count = ql2xloginretrycount;
4541
4542 /* Enable ZIO. */
4543 if (!vha->flags.init_done) {
4544 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4545 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4546 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4547 le16_to_cpu(icb->interrupt_delay_timer): 2;
4548 }
4549 icb->firmware_options_2 &= __constant_cpu_to_le32(
4550 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4551 vha->flags.process_response_queue = 0;
4552 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4553 ha->zio_mode = QLA_ZIO_MODE_6;
4554
4555 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4556 "(%d us).\n", vha->host_no, ha->zio_mode,
4557 ha->zio_timer * 100));
4558 qla_printk(KERN_INFO, ha,
4559 "ZIO mode %d enabled; timer delay (%d us).\n",
4560 ha->zio_mode, ha->zio_timer * 100);
4561
4562 icb->firmware_options_2 |= cpu_to_le32(
4563 (uint32_t)ha->zio_mode);
4564 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4565 vha->flags.process_response_queue = 1;
4566 }
4567
4568 if (rval) {
4569 DEBUG2_3(printk(KERN_WARNING
4570 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4571 }
4572 return (rval);
4573}
4574
4575void
4576qla81xx_update_fw_options(scsi_qla_host_t *ha)
4577{
4578}