blob: a8a0f138bc260bc985dee06dbdb93ba1ce6fb261 [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
Giridhar Malavali7d9dade2009-03-24 09:07:58 -0700819 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700820 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;
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700966 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800967
968 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
969 /* Disable SRAM, Instruction RAM and GP RAM parity. */
970 spin_lock_irqsave(&ha->hardware_lock, flags);
971 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
972 RD_REG_WORD(&reg->hccr);
973 spin_unlock_irqrestore(&ha->hardware_lock, flags);
974 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975
976 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800977 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700978 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700981
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 if (rval == QLA_SUCCESS) {
984 /* Start firmware execution. */
985 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800986 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700990 if (rval == QLA_SUCCESS) {
991 fw_major_version = ha->fw_major_version;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800992 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700993 &ha->fw_major_version,
994 &ha->fw_minor_version,
995 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800996 &ha->fw_attributes, &ha->fw_memory_size,
997 ha->mpi_version, &ha->mpi_capabilities);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700998 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800999 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -07001000 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001001 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001002 if ((!ha->max_npiv_vports) ||
1003 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001004 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001005 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001006 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001007 }
Andrew Vasquezdda772e2009-03-24 09:08:00 -07001008 if (!fw_major_version) {
1009 qla2x00_resize_request_q(vha);
1010 if (ql2xallocfwdump)
1011 qla2x00_alloc_fw_dump(vha);
1012 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013 }
1014 } else {
1015 DEBUG2(printk(KERN_INFO
1016 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001017 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001018 }
1019 }
1020
Andrew Vasquez3db06522008-01-31 12:33:49 -08001021 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1022 /* Enable proper parity. */
1023 spin_lock_irqsave(&ha->hardware_lock, flags);
1024 if (IS_QLA2300(ha))
1025 /* SRAM parity */
1026 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1027 else
1028 /* SRAM, Instruction RAM and GP RAM parity */
1029 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1030 RD_REG_WORD(&reg->hccr);
1031 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1032 }
1033
Linus Torvalds1da177e2005-04-16 15:20:36 -07001034 if (rval) {
1035 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001036 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 }
1038
1039 return (rval);
1040}
1041
1042/**
1043 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1044 * @ha: HA context
1045 *
1046 * Beginning of request ring has initialization control block already built
1047 * by nvram config routine.
1048 *
1049 * Returns 0 on success.
1050 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001051void
1052qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001053{
1054 uint16_t cnt;
1055 response_t *pkt;
1056
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001057 pkt = rsp->ring_ptr;
1058 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059 pkt->signature = RESPONSE_PROCESSED;
1060 pkt++;
1061 }
1062
1063}
1064
1065/**
1066 * qla2x00_update_fw_options() - Read and process firmware options.
1067 * @ha: HA context
1068 *
1069 * Returns 0 on success.
1070 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001071void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001072qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001073{
1074 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001075 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076
1077 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
1080 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1081 return;
1082
1083 /* Serial Link options. */
1084 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001085 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001086 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1087 sizeof(ha->fw_seriallink_options)));
1088
1089 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1090 if (ha->fw_seriallink_options[3] & BIT_2) {
1091 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1092
1093 /* 1G settings */
1094 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1095 emphasis = (ha->fw_seriallink_options[2] &
1096 (BIT_4 | BIT_3)) >> 3;
1097 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001098 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099 rx_sens = (ha->fw_seriallink_options[0] &
1100 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1101 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1102 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1103 if (rx_sens == 0x0)
1104 rx_sens = 0x3;
1105 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1106 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1107 ha->fw_options[10] |= BIT_5 |
1108 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1109 (tx_sens & (BIT_1 | BIT_0));
1110
1111 /* 2G settings */
1112 swing = (ha->fw_seriallink_options[2] &
1113 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1114 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1115 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001116 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001117 rx_sens = (ha->fw_seriallink_options[1] &
1118 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1119 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1120 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1121 if (rx_sens == 0x0)
1122 rx_sens = 0x3;
1123 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1124 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1125 ha->fw_options[11] |= BIT_5 |
1126 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1127 (tx_sens & (BIT_1 | BIT_0));
1128 }
1129
1130 /* FCP2 options. */
1131 /* Return command IOCBs without waiting for an ABTS to complete. */
1132 ha->fw_options[3] |= BIT_13;
1133
1134 /* LED scheme. */
1135 if (ha->flags.enable_led_scheme)
1136 ha->fw_options[2] |= BIT_12;
1137
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001138 /* Detect ISP6312. */
1139 if (IS_QLA6312(ha))
1140 ha->fw_options[2] |= BIT_13;
1141
Linus Torvalds1da177e2005-04-16 15:20:36 -07001142 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001143 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001144}
1145
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001146void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001147qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001148{
1149 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001150 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001151
1152 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001153 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001154 return;
1155
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001156 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001157 le16_to_cpu(ha->fw_seriallink_options24[1]),
1158 le16_to_cpu(ha->fw_seriallink_options24[2]),
1159 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001160 if (rval != QLA_SUCCESS) {
1161 qla_printk(KERN_WARNING, ha,
1162 "Unable to update Serial Link options (%x).\n", rval);
1163 }
1164}
1165
1166void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001167qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001168{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001169 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001170 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001171 struct req_que *req = ha->req_q_map[0];
1172 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001173
1174 /* Setup ring parameters in initialization control block. */
1175 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1176 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001177 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1178 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1179 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1180 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1181 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1182 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001183
1184 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1185 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1186 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1187 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1188 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1189}
1190
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001191void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001192qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001193{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001194 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001195 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1196 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1197 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001198 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001199 uint16_t rid = 0;
1200 struct req_que *req = ha->req_q_map[0];
1201 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001202
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001203/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001204 icb = (struct init_cb_24xx *)ha->init_cb;
1205 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1206 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001207 icb->request_q_length = cpu_to_le16(req->length);
1208 icb->response_q_length = cpu_to_le16(rsp->length);
1209 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1210 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1211 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1212 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001213
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001214 if (ha->mqenable) {
1215 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1216 icb->rid = __constant_cpu_to_le16(rid);
1217 if (ha->flags.msix_enabled) {
1218 msix = &ha->msix_entries[1];
1219 DEBUG2_17(printk(KERN_INFO
1220 "Reistering vector 0x%x for base que\n", msix->entry));
1221 icb->msix = cpu_to_le16(msix->entry);
1222 }
1223 /* Use alternate PCI bus number */
1224 if (MSB(rid))
1225 icb->firmware_options_2 |=
1226 __constant_cpu_to_le32(BIT_19);
1227 /* Use alternate PCI devfn */
1228 if (LSB(rid))
1229 icb->firmware_options_2 |=
1230 __constant_cpu_to_le32(BIT_18);
1231
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001232 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001233 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001234
1235 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1236 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1237 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1238 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1239 } else {
1240 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1241 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1242 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1243 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1244 }
1245 /* PCI posting */
1246 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001247}
1248
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249/**
1250 * qla2x00_init_rings() - Initializes firmware.
1251 * @ha: HA context
1252 *
1253 * Beginning of request ring has initialization control block already built
1254 * by nvram config routine.
1255 *
1256 * Returns 0 on success.
1257 */
1258static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001259qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001260{
1261 int rval;
1262 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001263 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001264 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001265 struct req_que *req;
1266 struct rsp_que *rsp;
1267 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001268 struct mid_init_cb_24xx *mid_init_cb =
1269 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271 spin_lock_irqsave(&ha->hardware_lock, flags);
1272
1273 /* Clear outstanding commands array. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001274 for (que = 0; que < ha->max_queues; que++) {
1275 req = ha->req_q_map[que];
1276 if (!req)
1277 continue;
1278 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
1279 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001281 req->current_outstanding_cmd = 0;
1282
1283 /* Initialize firmware. */
1284 req->ring_ptr = req->ring;
1285 req->ring_index = 0;
1286 req->cnt = req->length;
1287 }
1288
1289 for (que = 0; que < ha->max_queues; que++) {
1290 rsp = ha->rsp_q_map[que];
1291 if (!rsp)
1292 continue;
1293 rsp->ring_ptr = rsp->ring;
1294 rsp->ring_index = 0;
1295
1296 /* Initialize response queue entries */
1297 qla2x00_init_response_q_entries(rsp);
1298 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299
1300 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001301 list_for_each_entry(vp, &ha->vp_list, list) {
1302 vp->rscn_in_ptr = 0;
1303 vp->rscn_out_ptr = 0;
1304 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001305 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001306
1307 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1308
1309 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001310 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001312 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001313
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001314 if (ha->flags.npiv_supported) {
1315 if (ha->operating_mode == LOOP)
1316 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001317 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001318 }
1319
Seokmann Juc48339d2008-01-17 09:02:19 -08001320
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001321 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001323 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001324 if (rval) {
1325 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327 } else {
1328 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001329 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001330 }
1331
1332 return (rval);
1333}
1334
1335/**
1336 * qla2x00_fw_ready() - Waits for firmware ready.
1337 * @ha: HA context
1338 *
1339 * Returns 0 on success.
1340 */
1341static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001342qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343{
1344 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001345 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346 uint16_t min_wait; /* Minimum wait time if loop is down */
1347 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001348 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001349 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001350
1351 rval = QLA_SUCCESS;
1352
1353 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001354 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355
1356 /*
1357 * Firmware should take at most one RATOV to login, plus 5 seconds for
1358 * our own processing.
1359 */
1360 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1361 wait_time = min_wait;
1362 }
1363
1364 /* Min wait time if loop down */
1365 mtime = jiffies + (min_wait * HZ);
1366
1367 /* wait time before firmware ready */
1368 wtime = jiffies + (wait_time * HZ);
1369
1370 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001371 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001372 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1373
1374 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001375 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376
1377 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001378 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001380 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001381 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001383 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1384 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001385 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001386 state[2]));
1387 if ((state[2] & FSTATE_LOGGED_IN) &&
1388 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1389 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001390 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001391
1392 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001393 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001394 if (rval != QLA_SUCCESS)
1395 break;
1396
1397 /* Add time taken to initialize. */
1398 cs84xx_time = jiffies - cs84xx_time;
1399 wtime += cs84xx_time;
1400 mtime += cs84xx_time;
1401 DEBUG16(printk("scsi(%ld): Increasing "
1402 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001403 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001404 }
1405 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001406 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001407 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001409 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001410 &ha->login_timeout, &ha->r_a_tov);
1411
1412 rval = QLA_SUCCESS;
1413 break;
1414 }
1415
1416 rval = QLA_FUNCTION_FAILED;
1417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001418 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001419 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001420 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001421 * other than Wait for Login.
1422 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001423 if (time_after_eq(jiffies, mtime)) {
1424 qla_printk(KERN_INFO, ha,
1425 "Cable is unplugged...\n");
1426
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001427 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 break;
1429 }
1430 }
1431 } else {
1432 /* Mailbox cmd failed. Timeout on min_wait. */
1433 if (time_after_eq(jiffies, mtime))
1434 break;
1435 }
1436
1437 if (time_after_eq(jiffies, wtime))
1438 break;
1439
1440 /* Delay for a while */
1441 msleep(500);
1442
1443 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445 } while (1);
1446
1447 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001449
1450 if (rval) {
1451 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001452 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001453 }
1454
1455 return (rval);
1456}
1457
1458/*
1459* qla2x00_configure_hba
1460* Setup adapter context.
1461*
1462* Input:
1463* ha = adapter state pointer.
1464*
1465* Returns:
1466* 0 = success
1467*
1468* Context:
1469* Kernel context.
1470*/
1471static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001473{
1474 int rval;
1475 uint16_t loop_id;
1476 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001477 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478 uint8_t al_pa;
1479 uint8_t area;
1480 uint8_t domain;
1481 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001482 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
1484 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001485 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001486 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001487 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001488 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001489 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1490 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001492 } else {
1493 qla_printk(KERN_WARNING, ha,
1494 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001495 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001496 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 return (rval);
1498 }
1499
1500 if (topo == 4) {
1501 qla_printk(KERN_INFO, ha,
1502 "Cannot get topology - retrying.\n");
1503 return (QLA_FUNCTION_FAILED);
1504 }
1505
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001506 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001507
1508 /* initialize */
1509 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1510 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001511 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
1513 switch (topo) {
1514 case 0:
1515 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517 ha->current_topology = ISP_CFG_NL;
1518 strcpy(connect_type, "(Loop)");
1519 break;
1520
1521 case 1:
1522 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001524 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525 ha->current_topology = ISP_CFG_FL;
1526 strcpy(connect_type, "(FL_Port)");
1527 break;
1528
1529 case 2:
1530 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001531 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532 ha->operating_mode = P2P;
1533 ha->current_topology = ISP_CFG_N;
1534 strcpy(connect_type, "(N_Port-to-N_Port)");
1535 break;
1536
1537 case 3:
1538 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001540 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 ha->operating_mode = P2P;
1542 ha->current_topology = ISP_CFG_F;
1543 strcpy(connect_type, "(F_Port)");
1544 break;
1545
1546 default:
1547 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1548 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001549 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 ha->current_topology = ISP_CFG_NL;
1551 strcpy(connect_type, "(Loop)");
1552 break;
1553 }
1554
1555 /* Save Host port and loop ID. */
1556 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001557 vha->d_id.b.domain = domain;
1558 vha->d_id.b.area = area;
1559 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001561 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001562 qla_printk(KERN_INFO, ha,
1563 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001564 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001565
1566 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001567 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001569 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 }
1571
1572 return(rval);
1573}
1574
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001575static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1577 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001578{
1579 char *st, *en;
1580 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001581 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001582
1583 if (memcmp(model, BINZERO, len) != 0) {
1584 strncpy(ha->model_number, model, len);
1585 st = en = ha->model_number;
1586 en += len - 1;
1587 while (en > st) {
1588 if (*en != 0x20 && *en != 0x00)
1589 break;
1590 *en-- = '\0';
1591 }
1592
1593 index = (ha->pdev->subsystem_device & 0xff);
1594 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1595 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001596 strncpy(ha->model_desc,
1597 qla2x00_model_name[index * 2 + 1],
1598 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001599 } else {
1600 index = (ha->pdev->subsystem_device & 0xff);
1601 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1602 index < QLA_MODEL_NAMES) {
1603 strcpy(ha->model_number,
1604 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001605 strncpy(ha->model_desc,
1606 qla2x00_model_name[index * 2 + 1],
1607 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001608 } else {
1609 strcpy(ha->model_number, def);
1610 }
1611 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001612 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001613 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001614 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001615}
1616
David Miller4e08df32007-04-16 12:37:43 -07001617/* On sparc systems, obtain port and node WWN from firmware
1618 * properties.
1619 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001620static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001621{
1622#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001623 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001624 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001625 struct device_node *dp = pci_device_to_OF_node(pdev);
1626 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001627 int len;
1628
1629 val = of_get_property(dp, "port-wwn", &len);
1630 if (val && len >= WWN_SIZE)
1631 memcpy(nv->port_name, val, WWN_SIZE);
1632
1633 val = of_get_property(dp, "node-wwn", &len);
1634 if (val && len >= WWN_SIZE)
1635 memcpy(nv->node_name, val, WWN_SIZE);
1636#endif
1637}
1638
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639/*
1640* NVRAM configuration for ISP 2xxx
1641*
1642* Input:
1643* ha = adapter block pointer.
1644*
1645* Output:
1646* initialization control block in response_ring
1647* host adapters parameters in host adapter block
1648*
1649* Returns:
1650* 0 = success.
1651*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001652int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001653qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654{
David Miller4e08df32007-04-16 12:37:43 -07001655 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001656 uint8_t chksum = 0;
1657 uint16_t cnt;
1658 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001659 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001660 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001661 nvram_t *nv = ha->nvram;
1662 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001663 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664
David Miller4e08df32007-04-16 12:37:43 -07001665 rval = QLA_SUCCESS;
1666
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001668 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001669 ha->nvram_base = 0;
1670 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1671 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1672 ha->nvram_base = 0x80;
1673
1674 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001675 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001676 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1677 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001678
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001679 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001680 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681
1682 /* Bad NVRAM data, set defaults parameters. */
1683 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1684 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1685 /* Reset NVRAM data. */
1686 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1687 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1688 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001689 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1690 "invalid -- WWPN) defaults.\n");
1691
1692 /*
1693 * Set default initialization control block.
1694 */
1695 memset(nv, 0, ha->nvram_size);
1696 nv->parameter_block_version = ICB_VERSION;
1697
1698 if (IS_QLA23XX(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(2048);
1704 nv->special_options[1] = BIT_7;
1705 } else if (IS_QLA2200(ha)) {
1706 nv->firmware_options[0] = BIT_2 | BIT_1;
1707 nv->firmware_options[1] = BIT_7 | BIT_5;
1708 nv->add_firmware_options[0] = BIT_5;
1709 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1710 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1711 } else if (IS_QLA2100(ha)) {
1712 nv->firmware_options[0] = BIT_3 | BIT_1;
1713 nv->firmware_options[1] = BIT_5;
1714 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1715 }
1716
1717 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1718 nv->execution_throttle = __constant_cpu_to_le16(16);
1719 nv->retry_count = 8;
1720 nv->retry_delay = 1;
1721
1722 nv->port_name[0] = 33;
1723 nv->port_name[3] = 224;
1724 nv->port_name[4] = 139;
1725
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001726 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001727
1728 nv->login_timeout = 4;
1729
1730 /*
1731 * Set default host adapter parameters
1732 */
1733 nv->host_p[1] = BIT_2;
1734 nv->reset_delay = 5;
1735 nv->port_down_retry_count = 8;
1736 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1737 nv->link_down_timeout = 60;
1738
1739 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 }
1741
1742#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1743 /*
1744 * The SN2 does not provide BIOS emulation which means you can't change
1745 * potentially bogus BIOS settings. Force the use of default settings
1746 * for link rate and frame size. Hope that the rest of the settings
1747 * are valid.
1748 */
1749 if (ia64_platform_is("sn2")) {
1750 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1751 if (IS_QLA23XX(ha))
1752 nv->special_options[1] = BIT_7;
1753 }
1754#endif
1755
1756 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001757 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758
1759 /*
1760 * Setup driver NVRAM options.
1761 */
1762 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1763 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1764 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1765 nv->firmware_options[1] &= ~BIT_4;
1766
1767 if (IS_QLA23XX(ha)) {
1768 nv->firmware_options[0] |= BIT_2;
1769 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001770 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
1772 if (IS_QLA2300(ha)) {
1773 if (ha->fb_rev == FPM_2310) {
1774 strcpy(ha->model_number, "QLA2310");
1775 } else {
1776 strcpy(ha->model_number, "QLA2300");
1777 }
1778 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001779 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001780 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781 }
1782 } else if (IS_QLA2200(ha)) {
1783 nv->firmware_options[0] |= BIT_2;
1784 /*
1785 * 'Point-to-point preferred, else loop' is not a safe
1786 * connection mode setting.
1787 */
1788 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1789 (BIT_5 | BIT_4)) {
1790 /* Force 'loop preferred, else point-to-point'. */
1791 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1792 nv->add_firmware_options[0] |= BIT_5;
1793 }
1794 strcpy(ha->model_number, "QLA22xx");
1795 } else /*if (IS_QLA2100(ha))*/ {
1796 strcpy(ha->model_number, "QLA2100");
1797 }
1798
1799 /*
1800 * Copy over NVRAM RISC parameter block to initialization control block.
1801 */
1802 dptr1 = (uint8_t *)icb;
1803 dptr2 = (uint8_t *)&nv->parameter_block_version;
1804 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1805 while (cnt--)
1806 *dptr1++ = *dptr2++;
1807
1808 /* Copy 2nd half. */
1809 dptr1 = (uint8_t *)icb->add_firmware_options;
1810 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1811 while (cnt--)
1812 *dptr1++ = *dptr2++;
1813
Andrew Vasquez5341e862006-05-17 15:09:16 -07001814 /* Use alternate WWN? */
1815 if (nv->host_p[1] & BIT_7) {
1816 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1817 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1818 }
1819
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820 /* Prepare nodename */
1821 if ((icb->firmware_options[1] & BIT_6) == 0) {
1822 /*
1823 * Firmware will apply the following mask if the nodename was
1824 * not provided.
1825 */
1826 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1827 icb->node_name[0] &= 0xF0;
1828 }
1829
1830 /*
1831 * Set host adapter parameters.
1832 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001833 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001834 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1836 /* Always load RISC code on non ISP2[12]00 chips. */
1837 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1838 ha->flags.disable_risc_code_load = 0;
1839 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1840 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1841 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001842 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001843 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
1845 ha->operating_mode =
1846 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1847
1848 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1849 sizeof(ha->fw_seriallink_options));
1850
1851 /* save HBA serial number */
1852 ha->serial0 = icb->port_name[5];
1853 ha->serial1 = icb->port_name[6];
1854 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001855 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1856 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857
1858 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1859
1860 ha->retry_count = nv->retry_count;
1861
1862 /* Set minimum login_timeout to 4 seconds. */
1863 if (nv->login_timeout < ql2xlogintimeout)
1864 nv->login_timeout = ql2xlogintimeout;
1865 if (nv->login_timeout < 4)
1866 nv->login_timeout = 4;
1867 ha->login_timeout = nv->login_timeout;
1868 icb->login_timeout = nv->login_timeout;
1869
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001870 /* Set minimum RATOV to 100 tenths of a second. */
1871 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 ha->loop_reset_delay = nv->reset_delay;
1874
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 /* Link Down Timeout = 0:
1876 *
1877 * When Port Down timer expires we will start returning
1878 * I/O's to OS with "DID_NO_CONNECT".
1879 *
1880 * Link Down Timeout != 0:
1881 *
1882 * The driver waits for the link to come up after link down
1883 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001884 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001885 if (nv->link_down_timeout == 0) {
1886 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001887 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 } else {
1889 ha->link_down_timeout = nv->link_down_timeout;
1890 ha->loop_down_abort_time =
1891 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001892 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001893
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 /*
1895 * Need enough time to try and get the port back.
1896 */
1897 ha->port_down_retry_count = nv->port_down_retry_count;
1898 if (qlport_down_retry)
1899 ha->port_down_retry_count = qlport_down_retry;
1900 /* Set login_retry_count */
1901 ha->login_retry_count = nv->retry_count;
1902 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1903 ha->port_down_retry_count > 3)
1904 ha->login_retry_count = ha->port_down_retry_count;
1905 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1906 ha->login_retry_count = ha->port_down_retry_count;
1907 if (ql2xloginretrycount)
1908 ha->login_retry_count = ql2xloginretrycount;
1909
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 icb->lun_enables = __constant_cpu_to_le16(0);
1911 icb->command_resource_count = 0;
1912 icb->immediate_notify_resource_count = 0;
1913 icb->timeout = __constant_cpu_to_le16(0);
1914
1915 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1916 /* Enable RIO */
1917 icb->firmware_options[0] &= ~BIT_3;
1918 icb->add_firmware_options[0] &=
1919 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1920 icb->add_firmware_options[0] |= BIT_2;
1921 icb->response_accumulation_timer = 3;
1922 icb->interrupt_delay_timer = 5;
1923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001924 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001926 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001928 ha->zio_mode = icb->add_firmware_options[0] &
1929 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1930 ha->zio_timer = icb->interrupt_delay_timer ?
1931 icb->interrupt_delay_timer: 2;
1932 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 icb->add_firmware_options[0] &=
1934 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001935 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001936 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001937 ha->zio_mode = QLA_ZIO_MODE_6;
1938
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001939 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001941 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001943 "ZIO mode %d enabled; timer delay (%d us).\n",
1944 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001946 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1947 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001948 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001949 }
1950 }
1951
David Miller4e08df32007-04-16 12:37:43 -07001952 if (rval) {
1953 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001955 }
1956 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957}
1958
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001959static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001960qla2x00_rport_del(void *data)
1961{
1962 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001963 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001964
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001965 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001966 rport = fcport->drport;
1967 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001968 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001969 if (rport)
1970 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001971}
1972
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973/**
1974 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1975 * @ha: HA context
1976 * @flags: allocation flags
1977 *
1978 * Returns a pointer to the allocated fcport, or NULL, if none available.
1979 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001980static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001981qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982{
1983 fc_port_t *fcport;
1984
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001985 fcport = kzalloc(sizeof(fc_port_t), flags);
1986 if (!fcport)
1987 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001988
1989 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 fcport->vha = vha;
1991 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 fcport->port_type = FCT_UNKNOWN;
1993 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1995 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001996 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001997
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001998 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999}
2000
2001/*
2002 * qla2x00_configure_loop
2003 * Updates Fibre Channel Device Database with what is actually on loop.
2004 *
2005 * Input:
2006 * ha = adapter block pointer.
2007 *
2008 * Returns:
2009 * 0 = success.
2010 * 1 = error.
2011 * 2 = database was full and device was not configured.
2012 */
2013static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015{
2016 int rval;
2017 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002018 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 rval = QLA_SUCCESS;
2020
2021 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002022 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2023 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 if (rval != QLA_SUCCESS) {
2025 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 return (rval);
2028 }
2029 }
2030
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034
2035 /*
2036 * If we have both an RSCN and PORT UPDATE pending then handle them
2037 * both at the same time.
2038 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2040 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
2042 /* Determine what we need to do */
2043 if (ha->current_topology == ISP_CFG_FL &&
2044 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 set_bit(RSCN_UPDATE, &flags);
2048
2049 } else if (ha->current_topology == ISP_CFG_F &&
2050 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2051
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 set_bit(RSCN_UPDATE, &flags);
2054 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2055
Andrew Vasquez21333b42006-05-17 15:09:56 -07002056 } else if (ha->current_topology == ISP_CFG_N) {
2057 clear_bit(RSCN_UPDATE, &flags);
2058
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2061
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 set_bit(RSCN_UPDATE, &flags);
2064 set_bit(LOCAL_LOOP_UPDATE, &flags);
2065 }
2066
2067 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002068 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
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_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 }
2073
2074 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002075 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002077 else
2078 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002079 }
2080
2081 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 if (atomic_read(&vha->loop_down_timer) ||
2083 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 rval = QLA_FUNCTION_FAILED;
2085 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002086 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002088 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002089 }
2090 }
2091
2092 if (rval) {
2093 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095 } else {
2096 DEBUG3(printk("%s: exiting normally\n", __func__));
2097 }
2098
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002099 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002103 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 }
2106
2107 return (rval);
2108}
2109
2110
2111
2112/*
2113 * qla2x00_configure_local_loop
2114 * Updates Fibre Channel Device Database with local loop devices.
2115 *
2116 * Input:
2117 * ha = adapter block pointer.
2118 *
2119 * Returns:
2120 * 0 = success.
2121 */
2122static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002123qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124{
2125 int rval, rval2;
2126 int found_devs;
2127 int found;
2128 fc_port_t *fcport, *new_fcport;
2129
2130 uint16_t index;
2131 uint16_t entries;
2132 char *id_iter;
2133 uint16_t loop_id;
2134 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002135 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136
2137 found_devs = 0;
2138 new_fcport = NULL;
2139 entries = MAX_FIBRE_DEVICES;
2140
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002141 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2142 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143
2144 /* Get list of logged in devices. */
2145 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147 &entries);
2148 if (rval != QLA_SUCCESS)
2149 goto cleanup_allocation;
2150
2151 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2152 ha->host_no, entries));
2153 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2154 entries * sizeof(struct gid_list_info)));
2155
2156 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158 if (new_fcport == NULL) {
2159 rval = QLA_MEMORY_ALLOC_FAILED;
2160 goto cleanup_allocation;
2161 }
2162 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2163
2164 /*
2165 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2166 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002167 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2169 fcport->port_type != FCT_BROADCAST &&
2170 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2171
2172 DEBUG(printk("scsi(%ld): Marking port lost, "
2173 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002174 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175
2176 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2177 fcport->flags &= ~FCF_FARP_DONE;
2178 }
2179 }
2180
2181 /* Add devices to port list. */
2182 id_iter = (char *)ha->gid_list;
2183 for (index = 0; index < entries; index++) {
2184 domain = ((struct gid_list_info *)id_iter)->domain;
2185 area = ((struct gid_list_info *)id_iter)->area;
2186 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002187 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188 loop_id = (uint16_t)
2189 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002190 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002191 loop_id = le16_to_cpu(
2192 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002193 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002194
2195 /* Bypass reserved domain fields. */
2196 if ((domain & 0xf0) == 0xf0)
2197 continue;
2198
2199 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002200 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002201 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 continue;
2203
2204 /* Bypass invalid local loop ID. */
2205 if (loop_id > LAST_LOCAL_LOOP_ID)
2206 continue;
2207
2208 /* Fill in member data. */
2209 new_fcport->d_id.b.domain = domain;
2210 new_fcport->d_id.b.area = area;
2211 new_fcport->d_id.b.al_pa = al_pa;
2212 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002213 new_fcport->vp_idx = vha->vp_idx;
2214 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215 if (rval2 != QLA_SUCCESS) {
2216 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2217 "information -- get_port_database=%x, "
2218 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002219 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002220 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002221 vha->host_no));
2222 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002223 continue;
2224 }
2225
2226 /* Check for matching device in port list. */
2227 found = 0;
2228 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 if (memcmp(new_fcport->port_name, fcport->port_name,
2231 WWN_SIZE))
2232 continue;
2233
2234 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2235 FCF_PERSISTENT_BOUND);
2236 fcport->loop_id = new_fcport->loop_id;
2237 fcport->port_type = new_fcport->port_type;
2238 fcport->d_id.b24 = new_fcport->d_id.b24;
2239 memcpy(fcport->node_name, new_fcport->node_name,
2240 WWN_SIZE);
2241
2242 found++;
2243 break;
2244 }
2245
2246 if (!found) {
2247 /* New device, add to fcports list. */
2248 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002249 if (vha->vp_idx) {
2250 new_fcport->vha = vha;
2251 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002252 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002254
2255 /* Allocate a new replacement fcport. */
2256 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002257 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002258 if (new_fcport == NULL) {
2259 rval = QLA_MEMORY_ALLOC_FAILED;
2260 goto cleanup_allocation;
2261 }
2262 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2263 }
2264
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002265 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002266 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002269
2270 found_devs++;
2271 }
2272
2273cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002274 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
2276 if (rval != QLA_SUCCESS) {
2277 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002278 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002279 }
2280
2281 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 vha->device_flags |= DFLG_LOCAL_DEVICES;
2283 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002284 }
2285
2286 return (rval);
2287}
2288
2289static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002291{
2292#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002293 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002294 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002295 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002296 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002297
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002298 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002299 return;
2300
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002301 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2302 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002303 return;
2304
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002305 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002306 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002307 if (rval != QLA_SUCCESS) {
2308 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2309 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002310 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002311 fcport->port_name[2], fcport->port_name[3],
2312 fcport->port_name[4], fcport->port_name[5],
2313 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002314 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002315 } else {
2316 DEBUG2(qla_printk(KERN_INFO, ha,
2317 "iIDMA adjusted to %s GB/s on "
2318 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002319 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002320 fcport->port_name[1], fcport->port_name[2],
2321 fcport->port_name[3], fcport->port_name[4],
2322 fcport->port_name[5], fcport->port_name[6],
2323 fcport->port_name[7]));
2324 }
2325}
2326
Adrian Bunk23be3312006-11-24 02:46:01 +01002327static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002328qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002329{
2330 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002331 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002333
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002334 if (fcport->drport)
2335 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002336
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002337 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2338 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002339 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2340 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2341 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002343 if (!rport) {
2344 qla_printk(KERN_WARNING, ha,
2345 "Unable to allocate fc remote port!\n");
2346 return;
2347 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002348 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002349 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002351
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002352 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002353
2354 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002355 if (fcport->port_type == FCT_INITIATOR)
2356 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2357 if (fcport->port_type == FCT_TARGET)
2358 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002359 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002360}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002361
2362/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002363 * qla2x00_update_fcport
2364 * Updates device on list.
2365 *
2366 * Input:
2367 * ha = adapter block pointer.
2368 * fcport = port structure pointer.
2369 *
2370 * Return:
2371 * 0 - Success
2372 * BIT_0 - error
2373 *
2374 * Context:
2375 * Kernel context.
2376 */
2377void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002379{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002380 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002381
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002382 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002383 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002384 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002385 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002387 PORT_RETRY_TIME);
2388 fcport->flags &= ~FCF_LOGIN_NEEDED;
2389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002391
2392 atomic_set(&fcport->state, FCS_ONLINE);
2393
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002395}
2396
2397/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 * qla2x00_configure_fabric
2399 * Setup SNS devices with loop ID's.
2400 *
2401 * Input:
2402 * ha = adapter block pointer.
2403 *
2404 * Returns:
2405 * 0 = success.
2406 * BIT_0 = error
2407 */
2408static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410{
2411 int rval, rval2;
2412 fc_port_t *fcport, *fcptemp;
2413 uint16_t next_loopid;
2414 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002415 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417 struct qla_hw_data *ha = vha->hw;
2418 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419
2420 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002421 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002422 loop_id = NPH_F_PORT;
2423 else
2424 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002425 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 if (rval != QLA_SUCCESS) {
2427 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002428 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002430 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 return (QLA_SUCCESS);
2432 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434
2435 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002436 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002437 if (rval2 == QLA_RSCNS_HANDLED) {
2438 /* No point doing the scan, just continue. */
2439 return (QLA_SUCCESS);
2440 }
2441 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002442 /* FDMI support. */
2443 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002444 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2445 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002446
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002448 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002449 loop_id = NPH_SNS;
2450 else
2451 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002452 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002453 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454 if (mb[0] != MBS_COMMAND_COMPLETE) {
2455 DEBUG2(qla_printk(KERN_INFO, ha,
2456 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002457 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 mb[0], mb[1], mb[2], mb[6], mb[7]));
2459 return (QLA_SUCCESS);
2460 }
2461
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2463 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 /* EMPTY */
2465 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002469 /* EMPTY */
2470 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002471 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 /* EMPTY */
2475 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 "failed.\n", vha->host_no));
2477 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 /* EMPTY */
2479 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002480 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002481 }
2482 }
2483
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002484 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002485 if (rval != QLA_SUCCESS)
2486 break;
2487
2488 /*
2489 * Logout all previous fabric devices marked lost, except
2490 * tape devices.
2491 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2493 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 break;
2495
2496 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2497 continue;
2498
2499 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002501 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 if (fcport->loop_id != FC_NO_LOOP_ID &&
2503 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2504 fcport->port_type != FCT_INITIATOR &&
2505 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002506 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002507 fcport->loop_id,
2508 fcport->d_id.b.domain,
2509 fcport->d_id.b.area,
2510 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 fcport->loop_id = FC_NO_LOOP_ID;
2512 }
2513 }
2514 }
2515
2516 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
2519 /*
2520 * Scan through our port list and login entries that need to be
2521 * logged in.
2522 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002523 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2524 if (atomic_read(&vha->loop_down_timer) ||
2525 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002526 break;
2527
2528 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2529 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2530 continue;
2531
2532 if (fcport->loop_id == FC_NO_LOOP_ID) {
2533 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002534 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 if (rval != QLA_SUCCESS) {
2537 /* Ran out of IDs to use */
2538 break;
2539 }
2540 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002541 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002542 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002543 }
2544
2545 /* Exit if out of loop IDs. */
2546 if (rval != QLA_SUCCESS) {
2547 break;
2548 }
2549
2550 /*
2551 * Login and add the new devices to our port list.
2552 */
2553 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002554 if (atomic_read(&vha->loop_down_timer) ||
2555 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002556 break;
2557
2558 /* Find a new loop ID to use. */
2559 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002560 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561 if (rval != QLA_SUCCESS) {
2562 /* Ran out of IDs to use */
2563 break;
2564 }
2565
bdf79622005-04-17 15:06:53 -05002566 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002567 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 if (vha->vp_idx) {
2570 fcport->vha = vha;
2571 fcport->vp_idx = vha->vp_idx;
2572 }
2573 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002574 }
2575 } while (0);
2576
2577 /* Free all new device structures not processed. */
2578 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2579 list_del(&fcport->list);
2580 kfree(fcport);
2581 }
2582
2583 if (rval) {
2584 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002585 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002586 }
2587
2588 return (rval);
2589}
2590
2591
2592/*
2593 * qla2x00_find_all_fabric_devs
2594 *
2595 * Input:
2596 * ha = adapter block pointer.
2597 * dev = database device entry pointer.
2598 *
2599 * Returns:
2600 * 0 = success.
2601 *
2602 * Context:
2603 * Kernel context.
2604 */
2605static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002606qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2607 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608{
2609 int rval;
2610 uint16_t loop_id;
2611 fc_port_t *fcport, *new_fcport, *fcptemp;
2612 int found;
2613
2614 sw_info_t *swl;
2615 int swl_idx;
2616 int first_dev, last_dev;
2617 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002618 struct qla_hw_data *ha = vha->hw;
2619 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002620 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621
2622 rval = QLA_SUCCESS;
2623
2624 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002625 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002626 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 /*EMPTY*/
2628 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002631 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632 kfree(swl);
2633 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 kfree(swl);
2636 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 kfree(swl);
2639 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002640 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002641 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2642 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 }
2644 }
2645 swl_idx = 0;
2646
2647 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002650 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 return (QLA_MEMORY_ALLOC_FAILED);
2652 }
2653 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 /* Set start port ID scan at adapter ID. */
2655 first_dev = 1;
2656 last_dev = 0;
2657
2658 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002659 loop_id = ha->min_external_loopid;
2660 for (; loop_id <= ha->max_loop_id; loop_id++) {
2661 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662 continue;
2663
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 break;
2666
2667 if (swl != NULL) {
2668 if (last_dev) {
2669 wrap.b24 = new_fcport->d_id.b24;
2670 } else {
2671 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2672 memcpy(new_fcport->node_name,
2673 swl[swl_idx].node_name, WWN_SIZE);
2674 memcpy(new_fcport->port_name,
2675 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002676 memcpy(new_fcport->fabric_port_name,
2677 swl[swl_idx].fabric_port_name, WWN_SIZE);
2678 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679
2680 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2681 last_dev = 1;
2682 }
2683 swl_idx++;
2684 }
2685 } else {
2686 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002687 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002688 if (rval != QLA_SUCCESS) {
2689 qla_printk(KERN_WARNING, ha,
2690 "SNS scan failed -- assuming zero-entry "
2691 "result...\n");
2692 list_for_each_entry_safe(fcport, fcptemp,
2693 new_fcports, list) {
2694 list_del(&fcport->list);
2695 kfree(fcport);
2696 }
2697 rval = QLA_SUCCESS;
2698 break;
2699 }
2700 }
2701
2702 /* If wrap on switch device list, exit. */
2703 if (first_dev) {
2704 wrap.b24 = new_fcport->d_id.b24;
2705 first_dev = 0;
2706 } else if (new_fcport->d_id.b24 == wrap.b24) {
2707 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2710 break;
2711 }
2712
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002713 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002714 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 continue;
2716
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002717 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002718 found = 0;
2719 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002720 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002721 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2722 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002723 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002724 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002725 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002726 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002727 continue;
2728 }
2729
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002730 /* Bypass if same domain and area of adapter. */
2731 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002733 ISP_CFG_FL)
2734 continue;
2735
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736 /* Bypass reserved domain fields. */
2737 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2738 continue;
2739
2740 /* Locate matching device in database. */
2741 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002742 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 if (memcmp(new_fcport->port_name, fcport->port_name,
2744 WWN_SIZE))
2745 continue;
2746
2747 found++;
2748
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002749 /* Update port state. */
2750 memcpy(fcport->fabric_port_name,
2751 new_fcport->fabric_port_name, WWN_SIZE);
2752 fcport->fp_speed = new_fcport->fp_speed;
2753
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 /*
2755 * If address the same and state FCS_ONLINE, nothing
2756 * changed.
2757 */
2758 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2759 atomic_read(&fcport->state) == FCS_ONLINE) {
2760 break;
2761 }
2762
2763 /*
2764 * If device was not a fabric device before.
2765 */
2766 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2767 fcport->d_id.b24 = new_fcport->d_id.b24;
2768 fcport->loop_id = FC_NO_LOOP_ID;
2769 fcport->flags |= (FCF_FABRIC_DEVICE |
2770 FCF_LOGIN_NEEDED);
2771 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2772 break;
2773 }
2774
2775 /*
2776 * Port ID changed or device was marked to be updated;
2777 * Log it out if still logged in and mark it for
2778 * relogin later.
2779 */
2780 fcport->d_id.b24 = new_fcport->d_id.b24;
2781 fcport->flags |= FCF_LOGIN_NEEDED;
2782 if (fcport->loop_id != FC_NO_LOOP_ID &&
2783 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2784 fcport->port_type != FCT_INITIATOR &&
2785 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002786 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002787 fcport->d_id.b.domain, fcport->d_id.b.area,
2788 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789 fcport->loop_id = FC_NO_LOOP_ID;
2790 }
2791
2792 break;
2793 }
2794
2795 if (found)
2796 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797 /* If device was not in our fcports list, then add it. */
2798 list_add_tail(&new_fcport->list, new_fcports);
2799
2800 /* Allocate a new replacement fcport. */
2801 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002804 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002805 return (QLA_MEMORY_ALLOC_FAILED);
2806 }
2807 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2808 new_fcport->d_id.b24 = nxt_d_id.b24;
2809 }
2810
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002811 kfree(swl);
2812 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813
2814 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816
2817 return (rval);
2818}
2819
2820/*
2821 * qla2x00_find_new_loop_id
2822 * Scan through our port list and find a new usable loop ID.
2823 *
2824 * Input:
2825 * ha: adapter state pointer.
2826 * dev: port structure pointer.
2827 *
2828 * Returns:
2829 * qla2x00 local function return status code.
2830 *
2831 * Context:
2832 * Kernel context.
2833 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002834static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836{
2837 int rval;
2838 int found;
2839 fc_port_t *fcport;
2840 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002841 struct qla_hw_data *ha = vha->hw;
2842 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002843 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002844
2845 rval = QLA_SUCCESS;
2846
2847 /* Save starting loop ID. */
2848 first_loop_id = dev->loop_id;
2849
2850 for (;;) {
2851 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
2855 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002857 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858
2859 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 /* first loop ID. */
2862 dev->loop_id = ha->min_external_loopid;
2863 }
2864
2865 /* Check for loop ID being already in use. */
2866 found = 0;
2867 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002868 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2870 if (fcport->loop_id == dev->loop_id &&
2871 fcport != dev) {
2872 /* ID possibly in use */
2873 found++;
2874 break;
2875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002877 if (found)
2878 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879 }
2880
2881 /* If not in use then it is free to use. */
2882 if (!found) {
2883 break;
2884 }
2885
2886 /* ID in use. Try next value. */
2887 dev->loop_id++;
2888
2889 /* If wrap around. No free ID to use. */
2890 if (dev->loop_id == first_loop_id) {
2891 dev->loop_id = FC_NO_LOOP_ID;
2892 rval = QLA_FUNCTION_FAILED;
2893 break;
2894 }
2895 }
2896
2897 return (rval);
2898}
2899
2900/*
2901 * qla2x00_device_resync
2902 * Marks devices in the database that needs resynchronization.
2903 *
2904 * Input:
2905 * ha = adapter block pointer.
2906 *
2907 * Context:
2908 * Kernel context.
2909 */
2910static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002911qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002912{
2913 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 uint32_t mask;
2915 fc_port_t *fcport;
2916 uint32_t rscn_entry;
2917 uint8_t rscn_out_iter;
2918 uint8_t format;
2919 port_id_t d_id;
2920
2921 rval = QLA_RSCNS_HANDLED;
2922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2924 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 format = MSB(MSW(rscn_entry));
2928 d_id.b.domain = LSB(MSW(rscn_entry));
2929 d_id.b.area = MSB(LSW(rscn_entry));
2930 d_id.b.al_pa = LSB(LSW(rscn_entry));
2931
2932 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2933 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 d_id.b.area, d_id.b.al_pa));
2936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002937 vha->rscn_out_ptr++;
2938 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2939 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940
2941 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002942 for (rscn_out_iter = vha->rscn_out_ptr;
2943 !vha->flags.rscn_queue_overflow &&
2944 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 rscn_out_iter = (rscn_out_iter ==
2946 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2947
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002948 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002949 break;
2950
2951 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002952 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 rscn_out_iter));
2954
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 }
2957
2958 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002959 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002960 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962
2963 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002964 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002965 }
2966
2967 switch (format) {
2968 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002969 mask = 0xffffff;
2970 break;
2971 case 1:
2972 mask = 0xffff00;
2973 break;
2974 case 2:
2975 mask = 0xff0000;
2976 break;
2977 default:
2978 mask = 0x0;
2979 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 break;
2982 }
2983
2984 rval = QLA_SUCCESS;
2985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002986 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002987 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2988 (fcport->d_id.b24 & mask) != d_id.b24 ||
2989 fcport->port_type == FCT_BROADCAST)
2990 continue;
2991
2992 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2993 if (format != 3 ||
2994 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002995 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002996 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 }
2998 }
2999 fcport->flags &= ~FCF_FARP_DONE;
3000 }
3001 }
3002 return (rval);
3003}
3004
3005/*
3006 * qla2x00_fabric_dev_login
3007 * Login fabric target device and update FC port database.
3008 *
3009 * Input:
3010 * ha: adapter state pointer.
3011 * fcport: port structure list pointer.
3012 * next_loopid: contains value of a new loop ID that can be used
3013 * by the next login attempt.
3014 *
3015 * Returns:
3016 * qla2x00 local function return status code.
3017 *
3018 * Context:
3019 * Kernel context.
3020 */
3021static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 uint16_t *next_loopid)
3024{
3025 int rval;
3026 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003027 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029
3030 rval = QLA_SUCCESS;
3031 retry = 0;
3032
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003033 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003034 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003035 /* Send an ADISC to tape devices.*/
3036 opts = 0;
3037 if (fcport->flags & FCF_TAPE_PRESENT)
3038 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003039 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003041 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003042 fcport->d_id.b.domain, fcport->d_id.b.area,
3043 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003046 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047 }
3048 }
3049
3050 return (rval);
3051}
3052
3053/*
3054 * qla2x00_fabric_login
3055 * Issue fabric login command.
3056 *
3057 * Input:
3058 * ha = adapter block pointer.
3059 * device = pointer to FC device type structure.
3060 *
3061 * Returns:
3062 * 0 - Login successfully
3063 * 1 - Login failed
3064 * 2 - Initiator device
3065 * 3 - Fatal error
3066 */
3067int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003068qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 uint16_t *next_loopid)
3070{
3071 int rval;
3072 int retry;
3073 uint16_t tmp_loopid;
3074 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003075 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
3077 retry = 0;
3078 tmp_loopid = 0;
3079
3080 for (;;) {
3081 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3082 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003083 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3085
3086 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003087 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 fcport->d_id.b.domain, fcport->d_id.b.area,
3089 fcport->d_id.b.al_pa, mb, BIT_0);
3090 if (mb[0] == MBS_PORT_ID_USED) {
3091 /*
3092 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003093 * recommends the driver perform an implicit login with
3094 * the specified ID again. The ID we just used is save
3095 * here so we return with an ID that can be tried by
3096 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003097 */
3098 retry++;
3099 tmp_loopid = fcport->loop_id;
3100 fcport->loop_id = mb[1];
3101
3102 DEBUG(printk("Fabric Login: port in use - next "
3103 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3104 fcport->loop_id, fcport->d_id.b.domain,
3105 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3106
3107 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3108 /*
3109 * Login succeeded.
3110 */
3111 if (retry) {
3112 /* A retry occurred before. */
3113 *next_loopid = tmp_loopid;
3114 } else {
3115 /*
3116 * No retry occurred before. Just increment the
3117 * ID value for next login.
3118 */
3119 *next_loopid = (fcport->loop_id + 1);
3120 }
3121
3122 if (mb[1] & BIT_0) {
3123 fcport->port_type = FCT_INITIATOR;
3124 } else {
3125 fcport->port_type = FCT_TARGET;
3126 if (mb[1] & BIT_1) {
3127 fcport->flags |= FCF_TAPE_PRESENT;
3128 }
3129 }
3130
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003131 if (mb[10] & BIT_0)
3132 fcport->supported_classes |= FC_COS_CLASS2;
3133 if (mb[10] & BIT_1)
3134 fcport->supported_classes |= FC_COS_CLASS3;
3135
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 rval = QLA_SUCCESS;
3137 break;
3138 } else if (mb[0] == MBS_LOOP_ID_USED) {
3139 /*
3140 * Loop ID already used, try next loop ID.
3141 */
3142 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 if (rval != QLA_SUCCESS) {
3145 /* Ran out of loop IDs to use */
3146 break;
3147 }
3148 } else if (mb[0] == MBS_COMMAND_ERROR) {
3149 /*
3150 * Firmware possibly timed out during login. If NO
3151 * retries are left to do then the device is declared
3152 * dead.
3153 */
3154 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003155 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003156 fcport->d_id.b.domain, fcport->d_id.b.area,
3157 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159
3160 rval = 1;
3161 break;
3162 } else {
3163 /*
3164 * unrecoverable / not handled error
3165 */
3166 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003167 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003168 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 fcport->d_id.b.domain, fcport->d_id.b.area,
3170 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3171
3172 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003173 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003174 fcport->d_id.b.domain, fcport->d_id.b.area,
3175 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003176 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003177 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178
3179 rval = 3;
3180 break;
3181 }
3182 }
3183
3184 return (rval);
3185}
3186
3187/*
3188 * qla2x00_local_device_login
3189 * Issue local device login command.
3190 *
3191 * Input:
3192 * ha = adapter block pointer.
3193 * loop_id = loop id of device to login to.
3194 *
3195 * Returns (Where's the #define!!!!):
3196 * 0 - Login successfully
3197 * 1 - Login failed
3198 * 3 - Fatal error
3199 */
3200int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003201qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202{
3203 int rval;
3204 uint16_t mb[MAILBOX_REGISTER_COUNT];
3205
3206 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003207 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 if (rval == QLA_SUCCESS) {
3209 /* Interrogate mailbox registers for any errors */
3210 if (mb[0] == MBS_COMMAND_ERROR)
3211 rval = 1;
3212 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3213 /* device not in PCB table */
3214 rval = 3;
3215 }
3216
3217 return (rval);
3218}
3219
3220/*
3221 * qla2x00_loop_resync
3222 * Resync with fibre channel devices.
3223 *
3224 * Input:
3225 * ha = adapter block pointer.
3226 *
3227 * Returns:
3228 * 0 = success
3229 */
3230int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003233 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003235 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003236 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
3237 struct rsp_que *rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003239 atomic_set(&vha->loop_state, LOOP_UPDATE);
3240 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3241 if (vha->flags.online) {
3242 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003243 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3244 wait_time = 256;
3245 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003246 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003247
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003248 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003249 qla2x00_marker(vha, req, rsp, 0, 0,
3250 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003251 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003252
3253 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003254 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003256 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003257 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003258 } while (!atomic_read(&vha->loop_down_timer) &&
3259 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3260 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3261 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 }
3264
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003265 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270
3271 return (rval);
3272}
3273
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003276{
3277 fc_port_t *fcport;
3278
3279 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 list_for_each_entry(fcport, &vha->vp_fcports, list)
3281 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003282 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003283 qla2x00_rport_del(fcport);
3284}
3285
Linus Torvalds1da177e2005-04-16 15:20:36 -07003286/*
3287* qla2x00_abort_isp
3288* Resets ISP and aborts all outstanding commands.
3289*
3290* Input:
3291* ha = adapter block pointer.
3292*
3293* Returns:
3294* 0 = success
3295*/
3296int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003299 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 struct qla_hw_data *ha = vha->hw;
3302 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003303 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003304 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 if (vha->flags.online) {
3307 vha->flags.online = 0;
3308 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003309 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
3311 qla_printk(KERN_INFO, ha,
3312 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003315 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3316 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3317 atomic_set(&vha->loop_state, LOOP_DOWN);
3318 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003319 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003320 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003322 if (!atomic_read(&vha->loop_down_timer))
3323 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 LOOP_DOWN_TIME);
3325 }
3326
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003328 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003329
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003330 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003331
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003332 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003334 if (!qla2x00_restart_isp(vha)) {
3335 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003336
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003337 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 /*
3339 * Issue marker command only when we are going
3340 * to start the I/O .
3341 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 }
3344
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003345 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003347 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003349 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003350 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003351
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003352 if (ha->fce) {
3353 ha->flags.fce_enabled = 1;
3354 memset(ha->fce, 0,
3355 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003356 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003357 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3358 &ha->fce_bufs);
3359 if (rval) {
3360 qla_printk(KERN_WARNING, ha,
3361 "Unable to reinitialize FCE "
3362 "(%d).\n", rval);
3363 ha->flags.fce_enabled = 0;
3364 }
3365 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003366
3367 if (ha->eft) {
3368 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003369 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003370 ha->eft_dma, EFT_NUM_BUFFERS);
3371 if (rval) {
3372 qla_printk(KERN_WARNING, ha,
3373 "Unable to reinitialize EFT "
3374 "(%d).\n", rval);
3375 }
3376 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 vha->flags.online = 1;
3379 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 if (ha->isp_abort_cnt == 0) {
3381 qla_printk(KERN_WARNING, ha,
3382 "ISP error recovery failed - "
3383 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003384 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385 * The next call disables the board
3386 * completely.
3387 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 ha->isp_ops->reset_adapter(vha);
3389 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003391 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 status = 0;
3393 } else { /* schedule another ISP abort */
3394 ha->isp_abort_cnt--;
3395 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003396 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003397 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 status = 1;
3399 }
3400 } else {
3401 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3402 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3403 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003404 vha->host_no, ha->isp_abort_cnt));
3405 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 status = 1;
3407 }
3408 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003409
Linus Torvalds1da177e2005-04-16 15:20:36 -07003410 }
3411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003412 if (!status) {
3413 DEBUG(printk(KERN_INFO
3414 "qla2x00_abort_isp(%ld): succeeded.\n",
3415 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003416 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417 if (vp->vp_idx)
3418 qla2x00_vp_abort_isp(vp);
3419 }
3420 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 qla_printk(KERN_INFO, ha,
3422 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003423 }
3424
3425 return(status);
3426}
3427
3428/*
3429* qla2x00_restart_isp
3430* restarts the ISP after a reset
3431*
3432* Input:
3433* ha = adapter block pointer.
3434*
3435* Returns:
3436* 0 = success
3437*/
3438static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003440{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003441 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003442 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003443 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003444 struct req_que *req = ha->req_q_map[0];
3445 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448 if (qla2x00_isp_firmware(vha)) {
3449 vha->flags.online = 0;
3450 status = ha->isp_ops->chip_diag(vha);
3451 if (!status)
3452 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 }
3454
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003455 if (!status && !(status = qla2x00_init_rings(vha))) {
3456 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003457 /* Initialize the queues in use */
3458 qla25xx_init_queues(ha);
3459
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003460 status = qla2x00_fw_ready(vha);
3461 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003463 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003464
3465 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003466 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003469 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3470 wait_time = 256;
3471 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3473 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003475 } while (!atomic_read(&vha->loop_down_timer) &&
3476 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3477 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3478 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479 }
3480
3481 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003482 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003483 status = 0;
3484
3485 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3486 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003487 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003488 }
3489 return (status);
3490}
3491
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003492static int
3493qla25xx_init_queues(struct qla_hw_data *ha)
3494{
3495 struct rsp_que *rsp = NULL;
3496 struct req_que *req = NULL;
3497 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3498 int ret = -1;
3499 int i;
3500
3501 for (i = 1; i < ha->max_queues; i++) {
3502 rsp = ha->rsp_q_map[i];
3503 if (rsp) {
3504 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003505 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003506 if (ret != QLA_SUCCESS)
3507 DEBUG2_17(printk(KERN_WARNING
3508 "%s Rsp que:%d init failed\n", __func__,
3509 rsp->id));
3510 else
3511 DEBUG2_17(printk(KERN_INFO
3512 "%s Rsp que:%d inited\n", __func__,
3513 rsp->id));
3514 }
3515 req = ha->req_q_map[i];
3516 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003517 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003518 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003519 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003520 if (ret != QLA_SUCCESS)
3521 DEBUG2_17(printk(KERN_WARNING
3522 "%s Req que:%d init failed\n", __func__,
3523 req->id));
3524 else
3525 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003526 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003527 req->id));
3528 }
3529 }
3530 return ret;
3531}
3532
Linus Torvalds1da177e2005-04-16 15:20:36 -07003533/*
3534* qla2x00_reset_adapter
3535* Reset adapter.
3536*
3537* Input:
3538* ha = adapter block pointer.
3539*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003540void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003541qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003542{
3543 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003544 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003545 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003546
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003548 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003549
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550 spin_lock_irqsave(&ha->hardware_lock, flags);
3551 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3552 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3553 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3554 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3555 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3556}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003557
3558void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003559qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003560{
3561 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003562 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003563 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3564
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003565 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003566 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003567
3568 spin_lock_irqsave(&ha->hardware_lock, flags);
3569 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3570 RD_REG_DWORD(&reg->hccr);
3571 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3572 RD_REG_DWORD(&reg->hccr);
3573 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003574
3575 if (IS_NOPOLLING_TYPE(ha))
3576 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003577}
3578
David Miller4e08df32007-04-16 12:37:43 -07003579/* On sparc systems, obtain port and node WWN from firmware
3580 * properties.
3581 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3583 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003584{
3585#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003586 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003587 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003588 struct device_node *dp = pci_device_to_OF_node(pdev);
3589 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003590 int len;
3591
3592 val = of_get_property(dp, "port-wwn", &len);
3593 if (val && len >= WWN_SIZE)
3594 memcpy(nv->port_name, val, WWN_SIZE);
3595
3596 val = of_get_property(dp, "node-wwn", &len);
3597 if (val && len >= WWN_SIZE)
3598 memcpy(nv->node_name, val, WWN_SIZE);
3599#endif
3600}
3601
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003602int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003603qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003604{
David Miller4e08df32007-04-16 12:37:43 -07003605 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003606 struct init_cb_24xx *icb;
3607 struct nvram_24xx *nv;
3608 uint32_t *dptr;
3609 uint8_t *dptr1, *dptr2;
3610 uint32_t chksum;
3611 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003612 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003613
David Miller4e08df32007-04-16 12:37:43 -07003614 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003615 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003616 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003617
3618 /* Determine NVRAM starting address. */
3619 ha->nvram_size = sizeof(struct nvram_24xx);
3620 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003621 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3622 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3623 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003624 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003625 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3626 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003627
Seokmann Ju281afe12007-07-26 13:43:34 -07003628 /* Get VPD data into cache */
3629 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003630 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003631 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3632
3633 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003634 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003635 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003636 ha->nvram_size);
3637 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3638 chksum += le32_to_cpu(*dptr++);
3639
3640 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003641 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003642
3643 /* Bad NVRAM data, set defaults parameters. */
3644 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3645 || nv->id[3] != ' ' ||
3646 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3647 /* Reset NVRAM data. */
3648 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3649 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3650 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003651 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3652 "invalid -- WWPN) defaults.\n");
3653
3654 /*
3655 * Set default initialization control block.
3656 */
3657 memset(nv, 0, ha->nvram_size);
3658 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3659 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3660 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3661 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3662 nv->exchange_count = __constant_cpu_to_le16(0);
3663 nv->hard_address = __constant_cpu_to_le16(124);
3664 nv->port_name[0] = 0x21;
3665 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3666 nv->port_name[2] = 0x00;
3667 nv->port_name[3] = 0xe0;
3668 nv->port_name[4] = 0x8b;
3669 nv->port_name[5] = 0x1c;
3670 nv->port_name[6] = 0x55;
3671 nv->port_name[7] = 0x86;
3672 nv->node_name[0] = 0x20;
3673 nv->node_name[1] = 0x00;
3674 nv->node_name[2] = 0x00;
3675 nv->node_name[3] = 0xe0;
3676 nv->node_name[4] = 0x8b;
3677 nv->node_name[5] = 0x1c;
3678 nv->node_name[6] = 0x55;
3679 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003680 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003681 nv->login_retry_count = __constant_cpu_to_le16(8);
3682 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3683 nv->login_timeout = __constant_cpu_to_le16(0);
3684 nv->firmware_options_1 =
3685 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3686 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3687 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3688 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3689 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3690 nv->efi_parameters = __constant_cpu_to_le32(0);
3691 nv->reset_delay = 5;
3692 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3693 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3694 nv->link_down_timeout = __constant_cpu_to_le16(30);
3695
3696 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003697 }
3698
3699 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003700 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003701
3702 /* Copy 1st segment. */
3703 dptr1 = (uint8_t *)icb;
3704 dptr2 = (uint8_t *)&nv->version;
3705 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3706 while (cnt--)
3707 *dptr1++ = *dptr2++;
3708
3709 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003710 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003711
3712 /* Copy 2nd segment. */
3713 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3714 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3715 cnt = (uint8_t *)&icb->reserved_3 -
3716 (uint8_t *)&icb->interrupt_delay_timer;
3717 while (cnt--)
3718 *dptr1++ = *dptr2++;
3719
3720 /*
3721 * Setup driver NVRAM options.
3722 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003723 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003724 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003725
Andrew Vasquez5341e862006-05-17 15:09:16 -07003726 /* Use alternate WWN? */
3727 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3728 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3729 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3730 }
3731
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003732 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003733 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003734 /*
3735 * Firmware will apply the following mask if the nodename was
3736 * not provided.
3737 */
3738 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3739 icb->node_name[0] &= 0xF0;
3740 }
3741
3742 /* Set host adapter parameters. */
3743 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003744 ha->flags.enable_lip_reset = 0;
3745 ha->flags.enable_lip_full_login =
3746 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3747 ha->flags.enable_target_reset =
3748 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003749 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003750 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003751
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003752 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3753 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003754
3755 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3756 sizeof(ha->fw_seriallink_options24));
3757
3758 /* save HBA serial number */
3759 ha->serial0 = icb->port_name[5];
3760 ha->serial1 = icb->port_name[6];
3761 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003762 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3763 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003764
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003765 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3766
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003767 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3768
3769 /* Set minimum login_timeout to 4 seconds. */
3770 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3771 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3772 if (le16_to_cpu(nv->login_timeout) < 4)
3773 nv->login_timeout = __constant_cpu_to_le16(4);
3774 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003775 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003776
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003777 /* Set minimum RATOV to 100 tenths of a second. */
3778 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003779
3780 ha->loop_reset_delay = nv->reset_delay;
3781
3782 /* Link Down Timeout = 0:
3783 *
3784 * When Port Down timer expires we will start returning
3785 * I/O's to OS with "DID_NO_CONNECT".
3786 *
3787 * Link Down Timeout != 0:
3788 *
3789 * The driver waits for the link to come up after link down
3790 * before returning I/Os to OS with "DID_NO_CONNECT".
3791 */
3792 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3793 ha->loop_down_abort_time =
3794 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3795 } else {
3796 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3797 ha->loop_down_abort_time =
3798 (LOOP_DOWN_TIME - ha->link_down_timeout);
3799 }
3800
3801 /* Need enough time to try and get the port back. */
3802 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3803 if (qlport_down_retry)
3804 ha->port_down_retry_count = qlport_down_retry;
3805
3806 /* Set login_retry_count */
3807 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3808 if (ha->port_down_retry_count ==
3809 le16_to_cpu(nv->port_down_retry_count) &&
3810 ha->port_down_retry_count > 3)
3811 ha->login_retry_count = ha->port_down_retry_count;
3812 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3813 ha->login_retry_count = ha->port_down_retry_count;
3814 if (ql2xloginretrycount)
3815 ha->login_retry_count = ql2xloginretrycount;
3816
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003817 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003818 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003819 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3820 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3821 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3822 le16_to_cpu(icb->interrupt_delay_timer): 2;
3823 }
3824 icb->firmware_options_2 &= __constant_cpu_to_le32(
3825 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003826 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003827 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003828 ha->zio_mode = QLA_ZIO_MODE_6;
3829
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003830 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003831 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003832 ha->zio_timer * 100));
3833 qla_printk(KERN_INFO, ha,
3834 "ZIO mode %d enabled; timer delay (%d us).\n",
3835 ha->zio_mode, ha->zio_timer * 100);
3836
3837 icb->firmware_options_2 |= cpu_to_le32(
3838 (uint32_t)ha->zio_mode);
3839 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003841 }
3842
David Miller4e08df32007-04-16 12:37:43 -07003843 if (rval) {
3844 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003845 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003846 }
3847 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003848}
3849
Adrian Bunk413975a2006-06-30 02:33:06 -07003850static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003851qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003852{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003853 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003854 int segments, fragment;
3855 uint32_t faddr;
3856 uint32_t *dcode, dlen;
3857 uint32_t risc_addr;
3858 uint32_t risc_size;
3859 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003860 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003861 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003862
3863 qla_printk(KERN_INFO, ha,
3864 "FW: Loading from flash (%x)...\n", ha->flt_region_fw);
3865
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003866 rval = QLA_SUCCESS;
3867
3868 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003869 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003870 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003871 *srisc_addr = 0;
3872
3873 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003874 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003875 for (i = 0; i < 4; i++)
3876 dcode[i] = be32_to_cpu(dcode[i]);
3877 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3878 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3879 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3880 dcode[3] == 0)) {
3881 qla_printk(KERN_WARNING, ha,
3882 "Unable to verify integrity of flash firmware image!\n");
3883 qla_printk(KERN_WARNING, ha,
3884 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3885 dcode[1], dcode[2], dcode[3]);
3886
3887 return QLA_FUNCTION_FAILED;
3888 }
3889
3890 while (segments && rval == QLA_SUCCESS) {
3891 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003892 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003893
3894 risc_addr = be32_to_cpu(dcode[2]);
3895 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3896 risc_size = be32_to_cpu(dcode[3]);
3897
3898 fragment = 0;
3899 while (risc_size > 0 && rval == QLA_SUCCESS) {
3900 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3901 if (dlen > risc_size)
3902 dlen = risc_size;
3903
3904 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3905 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003906 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003907
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003909 for (i = 0; i < dlen; i++)
3910 dcode[i] = swab32(dcode[i]);
3911
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003912 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003913 dlen);
3914 if (rval) {
3915 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003916 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003917 fragment));
3918 qla_printk(KERN_WARNING, ha,
3919 "[ERROR] Failed to load segment %d of "
3920 "firmware\n", fragment);
3921 break;
3922 }
3923
3924 faddr += dlen;
3925 risc_addr += dlen;
3926 risc_size -= dlen;
3927 fragment++;
3928 }
3929
3930 /* Next segment. */
3931 segments--;
3932 }
3933
3934 return rval;
3935}
3936
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003937#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3938
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003939int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003940qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003941{
3942 int rval;
3943 int i, fragment;
3944 uint16_t *wcode, *fwcode;
3945 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3946 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003947 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003948 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003949
3950 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003951 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003952 if (!blob) {
3953 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003954 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3955 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003956 return QLA_FUNCTION_FAILED;
3957 }
3958
3959 rval = QLA_SUCCESS;
3960
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003961 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003962 *srisc_addr = 0;
3963 fwcode = (uint16_t *)blob->fw->data;
3964 fwclen = 0;
3965
3966 /* Validate firmware image by checking version. */
3967 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3968 qla_printk(KERN_WARNING, ha,
3969 "Unable to verify integrity of firmware image (%Zd)!\n",
3970 blob->fw->size);
3971 goto fail_fw_integrity;
3972 }
3973 for (i = 0; i < 4; i++)
3974 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3975 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3976 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3977 wcode[2] == 0 && wcode[3] == 0)) {
3978 qla_printk(KERN_WARNING, ha,
3979 "Unable to verify integrity of firmware image!\n");
3980 qla_printk(KERN_WARNING, ha,
3981 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3982 wcode[1], wcode[2], wcode[3]);
3983 goto fail_fw_integrity;
3984 }
3985
3986 seg = blob->segs;
3987 while (*seg && rval == QLA_SUCCESS) {
3988 risc_addr = *seg;
3989 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3990 risc_size = be16_to_cpu(fwcode[3]);
3991
3992 /* Validate firmware image size. */
3993 fwclen += risc_size * sizeof(uint16_t);
3994 if (blob->fw->size < fwclen) {
3995 qla_printk(KERN_WARNING, ha,
3996 "Unable to verify integrity of firmware image "
3997 "(%Zd)!\n", blob->fw->size);
3998 goto fail_fw_integrity;
3999 }
4000
4001 fragment = 0;
4002 while (risc_size > 0 && rval == QLA_SUCCESS) {
4003 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
4004 if (wlen > risc_size)
4005 wlen = risc_size;
4006
4007 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004009 risc_addr, wlen));
4010
4011 for (i = 0; i < wlen; i++)
4012 wcode[i] = swab16(fwcode[i]);
4013
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004014 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08004015 wlen);
4016 if (rval) {
4017 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004018 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08004019 fragment));
4020 qla_printk(KERN_WARNING, ha,
4021 "[ERROR] Failed to load segment %d of "
4022 "firmware\n", fragment);
4023 break;
4024 }
4025
4026 fwcode += wlen;
4027 risc_addr += wlen;
4028 risc_size -= wlen;
4029 fragment++;
4030 }
4031
4032 /* Next segment. */
4033 seg++;
4034 }
4035 return rval;
4036
4037fail_fw_integrity:
4038 return QLA_FUNCTION_FAILED;
4039}
4040
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004041static int
4042qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004043{
4044 int rval;
4045 int segments, fragment;
4046 uint32_t *dcode, dlen;
4047 uint32_t risc_addr;
4048 uint32_t risc_size;
4049 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004050 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004051 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004052 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004053 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004054
Andrew Vasquez54333832005-11-09 15:49:04 -08004055 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004056 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004057 if (!blob) {
4058 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004059 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4060 "from: " QLA_FW_URL ".\n");
4061
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004062 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004063 }
4064
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004065 qla_printk(KERN_INFO, ha,
4066 "FW: Loading via request-firmware...\n");
4067
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004068 rval = QLA_SUCCESS;
4069
4070 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004071 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004072 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004073 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004074 fwclen = 0;
4075
4076 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004077 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004078 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004079 "Unable to verify integrity of firmware image (%Zd)!\n",
4080 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004081 goto fail_fw_integrity;
4082 }
4083 for (i = 0; i < 4; i++)
4084 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4085 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4086 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4087 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4088 dcode[3] == 0)) {
4089 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004090 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004091 qla_printk(KERN_WARNING, ha,
4092 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4093 dcode[1], dcode[2], dcode[3]);
4094 goto fail_fw_integrity;
4095 }
4096
4097 while (segments && rval == QLA_SUCCESS) {
4098 risc_addr = be32_to_cpu(fwcode[2]);
4099 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4100 risc_size = be32_to_cpu(fwcode[3]);
4101
4102 /* Validate firmware image size. */
4103 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004104 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004105 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004106 "Unable to verify integrity of firmware image "
4107 "(%Zd)!\n", blob->fw->size);
4108
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004109 goto fail_fw_integrity;
4110 }
4111
4112 fragment = 0;
4113 while (risc_size > 0 && rval == QLA_SUCCESS) {
4114 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4115 if (dlen > risc_size)
4116 dlen = risc_size;
4117
4118 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004120 risc_addr, dlen));
4121
4122 for (i = 0; i < dlen; i++)
4123 dcode[i] = swab32(fwcode[i]);
4124
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004125 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004126 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004127 if (rval) {
4128 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004129 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004130 fragment));
4131 qla_printk(KERN_WARNING, ha,
4132 "[ERROR] Failed to load segment %d of "
4133 "firmware\n", fragment);
4134 break;
4135 }
4136
4137 fwcode += dlen;
4138 risc_addr += dlen;
4139 risc_size -= dlen;
4140 fragment++;
4141 }
4142
4143 /* Next segment. */
4144 segments--;
4145 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004146 return rval;
4147
4148fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004149 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004150}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004151
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004152int
4153qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4154{
4155 int rval;
4156
4157 /*
4158 * FW Load priority:
4159 * 1) Firmware via request-firmware interface (.bin file).
4160 * 2) Firmware residing in flash.
4161 */
4162 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4163 if (rval == QLA_SUCCESS)
4164 return rval;
4165
4166 return qla24xx_load_risc_flash(vha, srisc_addr);
4167}
4168
4169int
4170qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4171{
4172 int rval;
4173
4174 /*
4175 * FW Load priority:
4176 * 1) Firmware residing in flash.
4177 * 2) Firmware via request-firmware interface (.bin file).
4178 */
4179 rval = qla24xx_load_risc_flash(vha, srisc_addr);
4180 if (rval == QLA_SUCCESS)
4181 return rval;
4182
4183 return qla24xx_load_risc_blob(vha, srisc_addr);
4184}
4185
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004186void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004188{
4189 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004191
Andrew Vasqueze4289242007-07-19 15:05:56 -07004192 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004193 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004194 if (!ha->fw_major_version)
4195 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004196
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004197 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004198 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4199 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004200 ha->isp_ops->reset_chip(vha);
4201 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004202 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004203 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004204 continue;
4205 qla_printk(KERN_INFO, ha,
4206 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004207 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004208 }
4209}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004210
4211int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004212qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004213{
4214 int rval = QLA_SUCCESS;
4215 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004216 struct qla_hw_data *ha = vha->hw;
4217 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004218 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
4219 struct rsp_que *rsp = req->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004220
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004221 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004222 return -EINVAL;
4223
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004224 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004225 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004226 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004227 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004228 }
4229
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004230 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004231
4232 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004233 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004234 if (mb[0] != MBS_COMMAND_COMPLETE) {
4235 DEBUG15(qla_printk(KERN_INFO, ha,
4236 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4237 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4238 mb[0], mb[1], mb[2], mb[6], mb[7]));
4239 return (QLA_FUNCTION_FAILED);
4240 }
4241
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004242 atomic_set(&vha->loop_down_timer, 0);
4243 atomic_set(&vha->loop_state, LOOP_UP);
4244 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4245 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4246 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004247
4248 return rval;
4249}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004250
4251/* 84XX Support **************************************************************/
4252
4253static LIST_HEAD(qla_cs84xx_list);
4254static DEFINE_MUTEX(qla_cs84xx_mutex);
4255
4256static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004257qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004258{
4259 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004260 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004261
4262 mutex_lock(&qla_cs84xx_mutex);
4263
4264 /* Find any shared 84xx chip. */
4265 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4266 if (cs84xx->bus == ha->pdev->bus) {
4267 kref_get(&cs84xx->kref);
4268 goto done;
4269 }
4270 }
4271
4272 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4273 if (!cs84xx)
4274 goto done;
4275
4276 kref_init(&cs84xx->kref);
4277 spin_lock_init(&cs84xx->access_lock);
4278 mutex_init(&cs84xx->fw_update_mutex);
4279 cs84xx->bus = ha->pdev->bus;
4280
4281 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4282done:
4283 mutex_unlock(&qla_cs84xx_mutex);
4284 return cs84xx;
4285}
4286
4287static void
4288__qla84xx_chip_release(struct kref *kref)
4289{
4290 struct qla_chip_state_84xx *cs84xx =
4291 container_of(kref, struct qla_chip_state_84xx, kref);
4292
4293 mutex_lock(&qla_cs84xx_mutex);
4294 list_del(&cs84xx->list);
4295 mutex_unlock(&qla_cs84xx_mutex);
4296 kfree(cs84xx);
4297}
4298
4299void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004300qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004301{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004302 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004303 if (ha->cs84xx)
4304 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4305}
4306
4307static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004308qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004309{
4310 int rval;
4311 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004312 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004313
4314 mutex_lock(&ha->cs84xx->fw_update_mutex);
4315
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004316 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004317
4318 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4319
4320 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4321 QLA_SUCCESS;
4322}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004323
4324/* 81XX Support **************************************************************/
4325
4326int
4327qla81xx_nvram_config(scsi_qla_host_t *vha)
4328{
4329 int rval;
4330 struct init_cb_81xx *icb;
4331 struct nvram_81xx *nv;
4332 uint32_t *dptr;
4333 uint8_t *dptr1, *dptr2;
4334 uint32_t chksum;
4335 uint16_t cnt;
4336 struct qla_hw_data *ha = vha->hw;
4337
4338 rval = QLA_SUCCESS;
4339 icb = (struct init_cb_81xx *)ha->init_cb;
4340 nv = ha->nvram;
4341
4342 /* Determine NVRAM starting address. */
4343 ha->nvram_size = sizeof(struct nvram_81xx);
4344 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
4345 ha->vpd_size = FA_NVRAM_VPD_SIZE;
4346 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
4347 if (PCI_FUNC(ha->pdev->devfn) & 1) {
4348 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
4349 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
4350 }
4351
4352 /* Get VPD data into cache */
4353 ha->vpd = ha->nvram + VPD_OFFSET;
4354 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
4355 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
4356
4357 /* Get NVRAM data into cache and calculate checksum. */
4358 dptr = (uint32_t *)nv;
4359 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
4360 ha->nvram_size);
4361 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4362 chksum += le32_to_cpu(*dptr++);
4363
4364 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
4365 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4366
4367 /* Bad NVRAM data, set defaults parameters. */
4368 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4369 || nv->id[3] != ' ' ||
4370 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4371 /* Reset NVRAM data. */
4372 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4373 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4374 le16_to_cpu(nv->nvram_version));
4375 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4376 "invalid -- WWPN) defaults.\n");
4377
4378 /*
4379 * Set default initialization control block.
4380 */
4381 memset(nv, 0, ha->nvram_size);
4382 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4383 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4384 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4385 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4386 nv->exchange_count = __constant_cpu_to_le16(0);
4387 nv->port_name[0] = 0x21;
4388 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4389 nv->port_name[2] = 0x00;
4390 nv->port_name[3] = 0xe0;
4391 nv->port_name[4] = 0x8b;
4392 nv->port_name[5] = 0x1c;
4393 nv->port_name[6] = 0x55;
4394 nv->port_name[7] = 0x86;
4395 nv->node_name[0] = 0x20;
4396 nv->node_name[1] = 0x00;
4397 nv->node_name[2] = 0x00;
4398 nv->node_name[3] = 0xe0;
4399 nv->node_name[4] = 0x8b;
4400 nv->node_name[5] = 0x1c;
4401 nv->node_name[6] = 0x55;
4402 nv->node_name[7] = 0x86;
4403 nv->login_retry_count = __constant_cpu_to_le16(8);
4404 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4405 nv->login_timeout = __constant_cpu_to_le16(0);
4406 nv->firmware_options_1 =
4407 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4408 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4409 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4410 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4411 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4412 nv->efi_parameters = __constant_cpu_to_le32(0);
4413 nv->reset_delay = 5;
4414 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4415 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4416 nv->link_down_timeout = __constant_cpu_to_le16(30);
4417 nv->enode_mac[0] = 0x01;
4418 nv->enode_mac[1] = 0x02;
4419 nv->enode_mac[2] = 0x03;
4420 nv->enode_mac[3] = 0x04;
4421 nv->enode_mac[4] = 0x05;
4422 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4423
4424 rval = 1;
4425 }
4426
4427 /* Reset Initialization control block */
4428 memset(icb, 0, sizeof(struct init_cb_81xx));
4429
4430 /* Copy 1st segment. */
4431 dptr1 = (uint8_t *)icb;
4432 dptr2 = (uint8_t *)&nv->version;
4433 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4434 while (cnt--)
4435 *dptr1++ = *dptr2++;
4436
4437 icb->login_retry_count = nv->login_retry_count;
4438
4439 /* Copy 2nd segment. */
4440 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4441 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4442 cnt = (uint8_t *)&icb->reserved_5 -
4443 (uint8_t *)&icb->interrupt_delay_timer;
4444 while (cnt--)
4445 *dptr1++ = *dptr2++;
4446
4447 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4448 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4449 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4450 icb->enode_mac[0] = 0x01;
4451 icb->enode_mac[1] = 0x02;
4452 icb->enode_mac[2] = 0x03;
4453 icb->enode_mac[3] = 0x04;
4454 icb->enode_mac[4] = 0x05;
4455 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4456 }
4457
4458 /*
4459 * Setup driver NVRAM options.
4460 */
4461 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4462 "QLE81XX");
4463
4464 /* Use alternate WWN? */
4465 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4466 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4467 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4468 }
4469
4470 /* Prepare nodename */
4471 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4472 /*
4473 * Firmware will apply the following mask if the nodename was
4474 * not provided.
4475 */
4476 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4477 icb->node_name[0] &= 0xF0;
4478 }
4479
4480 /* Set host adapter parameters. */
4481 ha->flags.disable_risc_code_load = 0;
4482 ha->flags.enable_lip_reset = 0;
4483 ha->flags.enable_lip_full_login =
4484 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4485 ha->flags.enable_target_reset =
4486 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4487 ha->flags.enable_led_scheme = 0;
4488 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4489
4490 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4491 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4492
4493 /* save HBA serial number */
4494 ha->serial0 = icb->port_name[5];
4495 ha->serial1 = icb->port_name[6];
4496 ha->serial2 = icb->port_name[7];
4497 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4498 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4499
4500 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4501
4502 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4503
4504 /* Set minimum login_timeout to 4 seconds. */
4505 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4506 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4507 if (le16_to_cpu(nv->login_timeout) < 4)
4508 nv->login_timeout = __constant_cpu_to_le16(4);
4509 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4510 icb->login_timeout = nv->login_timeout;
4511
4512 /* Set minimum RATOV to 100 tenths of a second. */
4513 ha->r_a_tov = 100;
4514
4515 ha->loop_reset_delay = nv->reset_delay;
4516
4517 /* Link Down Timeout = 0:
4518 *
4519 * When Port Down timer expires we will start returning
4520 * I/O's to OS with "DID_NO_CONNECT".
4521 *
4522 * Link Down Timeout != 0:
4523 *
4524 * The driver waits for the link to come up after link down
4525 * before returning I/Os to OS with "DID_NO_CONNECT".
4526 */
4527 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4528 ha->loop_down_abort_time =
4529 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4530 } else {
4531 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4532 ha->loop_down_abort_time =
4533 (LOOP_DOWN_TIME - ha->link_down_timeout);
4534 }
4535
4536 /* Need enough time to try and get the port back. */
4537 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4538 if (qlport_down_retry)
4539 ha->port_down_retry_count = qlport_down_retry;
4540
4541 /* Set login_retry_count */
4542 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4543 if (ha->port_down_retry_count ==
4544 le16_to_cpu(nv->port_down_retry_count) &&
4545 ha->port_down_retry_count > 3)
4546 ha->login_retry_count = ha->port_down_retry_count;
4547 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4548 ha->login_retry_count = ha->port_down_retry_count;
4549 if (ql2xloginretrycount)
4550 ha->login_retry_count = ql2xloginretrycount;
4551
4552 /* Enable ZIO. */
4553 if (!vha->flags.init_done) {
4554 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4555 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4556 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4557 le16_to_cpu(icb->interrupt_delay_timer): 2;
4558 }
4559 icb->firmware_options_2 &= __constant_cpu_to_le32(
4560 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4561 vha->flags.process_response_queue = 0;
4562 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4563 ha->zio_mode = QLA_ZIO_MODE_6;
4564
4565 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4566 "(%d us).\n", vha->host_no, ha->zio_mode,
4567 ha->zio_timer * 100));
4568 qla_printk(KERN_INFO, ha,
4569 "ZIO mode %d enabled; timer delay (%d us).\n",
4570 ha->zio_mode, ha->zio_timer * 100);
4571
4572 icb->firmware_options_2 |= cpu_to_le32(
4573 (uint32_t)ha->zio_mode);
4574 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4575 vha->flags.process_response_queue = 1;
4576 }
4577
4578 if (rval) {
4579 DEBUG2_3(printk(KERN_WARNING
4580 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4581 }
4582 return (rval);
4583}
4584
4585void
4586qla81xx_update_fw_options(scsi_qla_host_t *ha)
4587{
4588}