blob: 521d2158d7a9379a3b4492ad0267b2a66b3e3ffb [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);
573}
574
575/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700576 * qla24xx_reset_chip() - Reset ISP24xx chip.
577 * @ha: HA context
578 *
579 * Returns 0 on success.
580 */
581void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800582qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700583{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800584 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700585 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700586
587 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800588 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700589}
590
591/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 * qla2x00_chip_diag() - Test chip for proper operation.
593 * @ha: HA context
594 *
595 * Returns 0 on success.
596 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700597int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800598qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700599{
600 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700602 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603 unsigned long flags = 0;
604 uint16_t data;
605 uint32_t cnt;
606 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800607 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608
609 /* Assume a failed state */
610 rval = QLA_FUNCTION_FAILED;
611
612 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800613 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614
615 spin_lock_irqsave(&ha->hardware_lock, flags);
616
617 /* Reset ISP chip. */
618 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
619
620 /*
621 * We need to have a delay here since the card will not respond while
622 * in reset causing an MCA on some architectures.
623 */
624 udelay(20);
625 data = qla2x00_debounce_register(&reg->ctrl_status);
626 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
627 udelay(5);
628 data = RD_REG_WORD(&reg->ctrl_status);
629 barrier();
630 }
631
632 if (!cnt)
633 goto chip_diag_failed;
634
635 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
636 ha->host_no));
637
638 /* Reset RISC processor. */
639 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
640 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
641
642 /* Workaround for QLA2312 PCI parity error */
643 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
644 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
645 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
646 udelay(5);
647 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700648 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700649 }
650 } else
651 udelay(10);
652
653 if (!cnt)
654 goto chip_diag_failed;
655
656 /* Check product ID of chip */
657 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
658
659 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
660 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
661 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
662 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
663 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
664 mb[3] != PROD_ID_3) {
665 qla_printk(KERN_WARNING, ha,
666 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
667
668 goto chip_diag_failed;
669 }
670 ha->product_id[0] = mb[1];
671 ha->product_id[1] = mb[2];
672 ha->product_id[2] = mb[3];
673 ha->product_id[3] = mb[4];
674
675 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800676 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700677 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
678 else
679 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800680 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
682 if (IS_QLA2200(ha) &&
683 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
684 /* Limit firmware transfer size with a 2200A */
685 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800686 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800688 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 ha->fw_transfer_size = 128;
690 }
691
692 /* Wrap Incoming Mailboxes Test. */
693 spin_unlock_irqrestore(&ha->hardware_lock, flags);
694
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800695 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
696 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700697 if (rval) {
698 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800699 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 qla_printk(KERN_WARNING, ha,
701 "Failed mailbox send register test\n");
702 }
703 else {
704 /* Flag a successful rval */
705 rval = QLA_SUCCESS;
706 }
707 spin_lock_irqsave(&ha->hardware_lock, flags);
708
709chip_diag_failed:
710 if (rval)
711 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800712 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713
714 spin_unlock_irqrestore(&ha->hardware_lock, flags);
715
716 return (rval);
717}
718
719/**
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700720 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
721 * @ha: HA context
722 *
723 * Returns 0 on success.
724 */
725int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800726qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700727{
728 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800729 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800730 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700731
Andrew Vasquez88c26662005-07-08 17:59:26 -0700732 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800733 qla24xx_reset_risc(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700734
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800735 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700736
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800737 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700738 if (rval) {
739 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740 vha->host_no));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700741 qla_printk(KERN_WARNING, ha,
742 "Failed mailbox send register test\n");
743 } else {
744 /* Flag a successful rval */
745 rval = QLA_SUCCESS;
746 }
747
748 return rval;
749}
750
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700751void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800752qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700753{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700754 int rval;
755 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800756 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800757 dma_addr_t tc_dma;
758 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800759 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800760 struct req_que *req = ha->req_q_map[0];
761 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700762
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700763 if (ha->fw_dump) {
764 qla_printk(KERN_WARNING, ha,
765 "Firmware dump previously allocated.\n");
766 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700767 }
768
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700769 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800770 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700771 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
772 fixed_size = sizeof(struct qla2100_fw_dump);
773 } else if (IS_QLA23XX(ha)) {
774 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
775 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
776 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700777 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700778 fixed_size = IS_QLA25XX(ha) ?
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800779 offsetof(struct qla25xx_fw_dump, ext_mem) :
780 offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700781 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
782 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800783 if (ha->mqenable)
784 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700785
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700786 /* Allocate memory for Fibre Channel Event Buffer. */
787 if (!IS_QLA25XX(ha))
788 goto try_eft;
789
790 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
791 GFP_KERNEL);
792 if (!tc) {
793 qla_printk(KERN_WARNING, ha, "Unable to allocate "
794 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800795 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700796 }
797
798 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700800 ha->fce_mb, &ha->fce_bufs);
801 if (rval) {
802 qla_printk(KERN_WARNING, ha, "Unable to initialize "
803 "FCE (%d).\n", rval);
804 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
805 tc_dma);
806 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800807 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700808 }
809
810 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
811 FCE_SIZE / 1024);
812
813 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
814 ha->flags.fce_enabled = 1;
815 ha->fce_dma = tc_dma;
816 ha->fce = tc;
817try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700818 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800819 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700820 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800821 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700822 qla_printk(KERN_WARNING, ha, "Unable to allocate "
823 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
824 goto cont_alloc;
825 }
826
Andrew Vasquezfc447652008-01-17 09:02:18 -0800827 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800828 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700829 if (rval) {
830 qla_printk(KERN_WARNING, ha, "Unable to initialize "
831 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800832 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
833 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700834 goto cont_alloc;
835 }
836
837 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
838 EFT_SIZE / 1024);
839
840 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800841 ha->eft_dma = tc_dma;
842 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700843 }
844cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800845 req_q_size = req->length * sizeof(request_t);
846 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700847
848 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
849 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800850 mq_size + eft_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700851
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700852 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700853 if (!ha->fw_dump) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700854 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700855 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700856
857 if (ha->eft) {
858 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
859 ha->eft_dma);
860 ha->eft = NULL;
861 ha->eft_dma = 0;
862 }
863 return;
864 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700865 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
866 dump_size / 1024);
867
868 ha->fw_dump_len = dump_size;
869 ha->fw_dump->signature[0] = 'Q';
870 ha->fw_dump->signature[1] = 'L';
871 ha->fw_dump->signature[2] = 'G';
872 ha->fw_dump->signature[3] = 'C';
873 ha->fw_dump->version = __constant_htonl(1);
874
875 ha->fw_dump->fixed_size = htonl(fixed_size);
876 ha->fw_dump->mem_size = htonl(mem_size);
877 ha->fw_dump->req_q_size = htonl(req_q_size);
878 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
879
880 ha->fw_dump->eft_size = htonl(eft_size);
881 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
882 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
883
884 ha->fw_dump->header_size =
885 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700886}
887
888/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
890 * @ha: HA context
891 *
892 * Returns 0 on success.
893 */
894static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800895qla2x00_resize_request_q(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896{
897 int rval;
898 uint16_t fw_iocb_cnt = 0;
899 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
900 dma_addr_t request_dma;
901 request_t *request_ring;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800902 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800903 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
905 /* Valid only on recent ISPs. */
906 if (IS_QLA2100(ha) || IS_QLA2200(ha))
907 return;
908
909 /* Retrieve IOCB counts available to the firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800910 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
911 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 if (rval)
913 return;
914 /* No point in continuing if current settings are sufficient. */
915 if (fw_iocb_cnt < 1024)
916 return;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 if (req->length >= request_q_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 return;
919
920 /* Attempt to claim larger area for request queue. */
921 request_ring = dma_alloc_coherent(&ha->pdev->dev,
922 (request_q_length + 1) * sizeof(request_t), &request_dma,
923 GFP_KERNEL);
924 if (request_ring == NULL)
925 return;
926
927 /* Resize successful, report extensions. */
928 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
929 (ha->fw_memory_size + 1) / 1024);
930 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800931 "(%d -> %d)...\n", req->length, request_q_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700932
933 /* Clear old allocations. */
934 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800935 (req->length + 1) * sizeof(request_t), req->ring,
936 req->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 /* Begin using larger queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800939 req->length = request_q_length;
940 req->ring = request_ring;
941 req->dma = request_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942}
943
944/**
945 * qla2x00_setup_chip() - Load and start RISC firmware.
946 * @ha: HA context
947 *
948 * Returns 0 on success.
949 */
950static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800951qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952{
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700953 int rval;
954 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800955 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800956 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
957 unsigned long flags;
958
959 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
960 /* Disable SRAM, Instruction RAM and GP RAM parity. */
961 spin_lock_irqsave(&ha->hardware_lock, flags);
962 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
963 RD_REG_WORD(&reg->hccr);
964 spin_unlock_irqrestore(&ha->hardware_lock, flags);
965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
967 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800968 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez0107109e2005-07-06 10:31:37 -0700969 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700970 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800971 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800973 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 if (rval == QLA_SUCCESS) {
975 /* Start firmware execution. */
976 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800977 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700978
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800979 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700980 /* Retrieve firmware information. */
981 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 &ha->fw_major_version,
984 &ha->fw_minor_version,
985 &ha->fw_subminor_version,
986 &ha->fw_attributes, &ha->fw_memory_size);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700987 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800988 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700989 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700990 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700991 if ((!ha->max_npiv_vports) ||
992 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800993 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700994 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800995 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700996 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800997 qla2x00_resize_request_q(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700998
999 if (ql2xallocfwdump)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001000 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001001 }
1002 } else {
1003 DEBUG2(printk(KERN_INFO
1004 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001005 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007 }
1008
Andrew Vasquez3db06522008-01-31 12:33:49 -08001009 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1010 /* Enable proper parity. */
1011 spin_lock_irqsave(&ha->hardware_lock, flags);
1012 if (IS_QLA2300(ha))
1013 /* SRAM parity */
1014 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1015 else
1016 /* SRAM, Instruction RAM and GP RAM parity */
1017 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1018 RD_REG_WORD(&reg->hccr);
1019 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1020 }
1021
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 if (rval) {
1023 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001024 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001025 }
1026
1027 return (rval);
1028}
1029
1030/**
1031 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1032 * @ha: HA context
1033 *
1034 * Beginning of request ring has initialization control block already built
1035 * by nvram config routine.
1036 *
1037 * Returns 0 on success.
1038 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001039void
1040qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001041{
1042 uint16_t cnt;
1043 response_t *pkt;
1044
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001045 pkt = rsp->ring_ptr;
1046 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001047 pkt->signature = RESPONSE_PROCESSED;
1048 pkt++;
1049 }
1050
1051}
1052
1053/**
1054 * qla2x00_update_fw_options() - Read and process firmware options.
1055 * @ha: HA context
1056 *
1057 * Returns 0 on success.
1058 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001059void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001061{
1062 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001063 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001064
1065 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001066 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001067
1068 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1069 return;
1070
1071 /* Serial Link options. */
1072 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1075 sizeof(ha->fw_seriallink_options)));
1076
1077 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1078 if (ha->fw_seriallink_options[3] & BIT_2) {
1079 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1080
1081 /* 1G settings */
1082 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1083 emphasis = (ha->fw_seriallink_options[2] &
1084 (BIT_4 | BIT_3)) >> 3;
1085 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001086 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001087 rx_sens = (ha->fw_seriallink_options[0] &
1088 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1089 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1090 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1091 if (rx_sens == 0x0)
1092 rx_sens = 0x3;
1093 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1094 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1095 ha->fw_options[10] |= BIT_5 |
1096 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1097 (tx_sens & (BIT_1 | BIT_0));
1098
1099 /* 2G settings */
1100 swing = (ha->fw_seriallink_options[2] &
1101 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1102 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1103 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001104 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001105 rx_sens = (ha->fw_seriallink_options[1] &
1106 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1107 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1108 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1109 if (rx_sens == 0x0)
1110 rx_sens = 0x3;
1111 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1112 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1113 ha->fw_options[11] |= BIT_5 |
1114 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1115 (tx_sens & (BIT_1 | BIT_0));
1116 }
1117
1118 /* FCP2 options. */
1119 /* Return command IOCBs without waiting for an ABTS to complete. */
1120 ha->fw_options[3] |= BIT_13;
1121
1122 /* LED scheme. */
1123 if (ha->flags.enable_led_scheme)
1124 ha->fw_options[2] |= BIT_12;
1125
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001126 /* Detect ISP6312. */
1127 if (IS_QLA6312(ha))
1128 ha->fw_options[2] |= BIT_13;
1129
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001131 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132}
1133
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001134void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001135qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001136{
1137 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001138 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001139
1140 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001141 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001142 return;
1143
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001144 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001145 le16_to_cpu(ha->fw_seriallink_options24[1]),
1146 le16_to_cpu(ha->fw_seriallink_options24[2]),
1147 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001148 if (rval != QLA_SUCCESS) {
1149 qla_printk(KERN_WARNING, ha,
1150 "Unable to update Serial Link options (%x).\n", rval);
1151 }
1152}
1153
1154void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001155qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001156{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001157 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001158 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001159 struct req_que *req = ha->req_q_map[0];
1160 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001161
1162 /* Setup ring parameters in initialization control block. */
1163 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1164 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001165 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1166 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1167 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1168 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1169 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1170 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001171
1172 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1173 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1174 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1175 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1176 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1177}
1178
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001179void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001181{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001182 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001183 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1184 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1185 struct qla_msix_entry *msix;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001186 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001187 uint16_t rid = 0;
1188 struct req_que *req = ha->req_q_map[0];
1189 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001190
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001191/* Setup ring parameters in initialization control block. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001192 icb = (struct init_cb_24xx *)ha->init_cb;
1193 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1194 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001195 icb->request_q_length = cpu_to_le16(req->length);
1196 icb->response_q_length = cpu_to_le16(rsp->length);
1197 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1198 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1199 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1200 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001201
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001202 if (ha->mqenable) {
1203 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1204 icb->rid = __constant_cpu_to_le16(rid);
1205 if (ha->flags.msix_enabled) {
1206 msix = &ha->msix_entries[1];
1207 DEBUG2_17(printk(KERN_INFO
1208 "Reistering vector 0x%x for base que\n", msix->entry));
1209 icb->msix = cpu_to_le16(msix->entry);
1210 }
1211 /* Use alternate PCI bus number */
1212 if (MSB(rid))
1213 icb->firmware_options_2 |=
1214 __constant_cpu_to_le32(BIT_19);
1215 /* Use alternate PCI devfn */
1216 if (LSB(rid))
1217 icb->firmware_options_2 |=
1218 __constant_cpu_to_le32(BIT_18);
1219
1220 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
1221 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1222 ha->rsp_q_map[0]->options = icb->firmware_options_2;
1223
1224 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1225 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1226 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1227 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1228 } else {
1229 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1230 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1231 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1232 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1233 }
1234 /* PCI posting */
1235 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001236}
1237
Linus Torvalds1da177e2005-04-16 15:20:36 -07001238/**
1239 * qla2x00_init_rings() - Initializes firmware.
1240 * @ha: HA context
1241 *
1242 * Beginning of request ring has initialization control block already built
1243 * by nvram config routine.
1244 *
1245 * Returns 0 on success.
1246 */
1247static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001248qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001249{
1250 int rval;
1251 unsigned long flags = 0;
1252 int cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001253 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001254 struct req_que *req = ha->req_q_map[0];
1255 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001256 struct mid_init_cb_24xx *mid_init_cb =
1257 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
1259 spin_lock_irqsave(&ha->hardware_lock, flags);
1260
1261 /* Clear outstanding commands array. */
1262 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001263 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001264
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001265 req->current_outstanding_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266
1267 /* Clear RSCN queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001268 vha->rscn_in_ptr = 0;
1269 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001270
1271 /* Initialize firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001272 req->ring_ptr = req->ring;
1273 req->ring_index = 0;
1274 req->cnt = req->length;
1275 rsp->ring_ptr = rsp->ring;
1276 rsp->ring_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001277
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278 /* Initialize response queue entries */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001279 qla2x00_init_response_q_entries(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
1283 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1284
1285 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001286 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001289
Seokmann Juc48339d2008-01-17 09:02:19 -08001290 if (ha->flags.npiv_supported)
1291 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1292
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001293 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001295 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001296 if (rval) {
1297 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001298 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001299 } else {
1300 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001301 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302 }
1303
1304 return (rval);
1305}
1306
1307/**
1308 * qla2x00_fw_ready() - Waits for firmware ready.
1309 * @ha: HA context
1310 *
1311 * Returns 0 on success.
1312 */
1313static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001314qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001315{
1316 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001317 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001318 uint16_t min_wait; /* Minimum wait time if loop is down */
1319 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001320 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001321 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001322
1323 rval = QLA_SUCCESS;
1324
1325 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001326 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 /*
1329 * Firmware should take at most one RATOV to login, plus 5 seconds for
1330 * our own processing.
1331 */
1332 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1333 wait_time = min_wait;
1334 }
1335
1336 /* Min wait time if loop down */
1337 mtime = jiffies + (min_wait * HZ);
1338
1339 /* wait time before firmware ready */
1340 wtime = jiffies + (wait_time * HZ);
1341
1342 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001343 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001344 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1345
1346 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001347 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001348
1349 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001350 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001351 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001352 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001354 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001355 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1356 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001357 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001358 state[2]));
1359 if ((state[2] & FSTATE_LOGGED_IN) &&
1360 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1361 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001363
1364 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001365 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001366 if (rval != QLA_SUCCESS)
1367 break;
1368
1369 /* Add time taken to initialize. */
1370 cs84xx_time = jiffies - cs84xx_time;
1371 wtime += cs84xx_time;
1372 mtime += cs84xx_time;
1373 DEBUG16(printk("scsi(%ld): Increasing "
1374 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001375 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001376 }
1377 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001379 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001381 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 &ha->login_timeout, &ha->r_a_tov);
1383
1384 rval = QLA_SUCCESS;
1385 break;
1386 }
1387
1388 rval = QLA_FUNCTION_FAILED;
1389
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001390 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001391 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001393 * other than Wait for Login.
1394 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001395 if (time_after_eq(jiffies, mtime)) {
1396 qla_printk(KERN_INFO, ha,
1397 "Cable is unplugged...\n");
1398
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001399 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 break;
1401 }
1402 }
1403 } else {
1404 /* Mailbox cmd failed. Timeout on min_wait. */
1405 if (time_after_eq(jiffies, mtime))
1406 break;
1407 }
1408
1409 if (time_after_eq(jiffies, wtime))
1410 break;
1411
1412 /* Delay for a while */
1413 msleep(500);
1414
1415 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001416 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001417 } while (1);
1418
1419 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001420 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001421
1422 if (rval) {
1423 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001424 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001425 }
1426
1427 return (rval);
1428}
1429
1430/*
1431* qla2x00_configure_hba
1432* Setup adapter context.
1433*
1434* Input:
1435* ha = adapter state pointer.
1436*
1437* Returns:
1438* 0 = success
1439*
1440* Context:
1441* Kernel context.
1442*/
1443static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445{
1446 int rval;
1447 uint16_t loop_id;
1448 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001449 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450 uint8_t al_pa;
1451 uint8_t area;
1452 uint8_t domain;
1453 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455
1456 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001457 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001458 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001460 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001461 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1462 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001463 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001464 } else {
1465 qla_printk(KERN_WARNING, ha,
1466 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001467 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001468 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001469 return (rval);
1470 }
1471
1472 if (topo == 4) {
1473 qla_printk(KERN_INFO, ha,
1474 "Cannot get topology - retrying.\n");
1475 return (QLA_FUNCTION_FAILED);
1476 }
1477
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001478 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001479
1480 /* initialize */
1481 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1482 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001483 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 switch (topo) {
1486 case 0:
1487 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001488 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489 ha->current_topology = ISP_CFG_NL;
1490 strcpy(connect_type, "(Loop)");
1491 break;
1492
1493 case 1:
1494 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001495 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001496 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 ha->current_topology = ISP_CFG_FL;
1498 strcpy(connect_type, "(FL_Port)");
1499 break;
1500
1501 case 2:
1502 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001503 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504 ha->operating_mode = P2P;
1505 ha->current_topology = ISP_CFG_N;
1506 strcpy(connect_type, "(N_Port-to-N_Port)");
1507 break;
1508
1509 case 3:
1510 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001511 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001512 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513 ha->operating_mode = P2P;
1514 ha->current_topology = ISP_CFG_F;
1515 strcpy(connect_type, "(F_Port)");
1516 break;
1517
1518 default:
1519 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1520 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001521 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 ha->current_topology = ISP_CFG_NL;
1523 strcpy(connect_type, "(Loop)");
1524 break;
1525 }
1526
1527 /* Save Host port and loop ID. */
1528 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001529 vha->d_id.b.domain = domain;
1530 vha->d_id.b.area = area;
1531 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001533 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 qla_printk(KERN_INFO, ha,
1535 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001539 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001541 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 }
1543
1544 return(rval);
1545}
1546
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001547static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001548qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1549 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001550{
1551 char *st, *en;
1552 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001554
1555 if (memcmp(model, BINZERO, len) != 0) {
1556 strncpy(ha->model_number, model, len);
1557 st = en = ha->model_number;
1558 en += len - 1;
1559 while (en > st) {
1560 if (*en != 0x20 && *en != 0x00)
1561 break;
1562 *en-- = '\0';
1563 }
1564
1565 index = (ha->pdev->subsystem_device & 0xff);
1566 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1567 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001568 strncpy(ha->model_desc,
1569 qla2x00_model_name[index * 2 + 1],
1570 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001571 } else {
1572 index = (ha->pdev->subsystem_device & 0xff);
1573 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1574 index < QLA_MODEL_NAMES) {
1575 strcpy(ha->model_number,
1576 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001577 strncpy(ha->model_desc,
1578 qla2x00_model_name[index * 2 + 1],
1579 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001580 } else {
1581 strcpy(ha->model_number, def);
1582 }
1583 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001584 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001585 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001586 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001587}
1588
David Miller4e08df32007-04-16 12:37:43 -07001589/* On sparc systems, obtain port and node WWN from firmware
1590 * properties.
1591 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001592static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001593{
1594#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001595 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001596 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001597 struct device_node *dp = pci_device_to_OF_node(pdev);
1598 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001599 int len;
1600
1601 val = of_get_property(dp, "port-wwn", &len);
1602 if (val && len >= WWN_SIZE)
1603 memcpy(nv->port_name, val, WWN_SIZE);
1604
1605 val = of_get_property(dp, "node-wwn", &len);
1606 if (val && len >= WWN_SIZE)
1607 memcpy(nv->node_name, val, WWN_SIZE);
1608#endif
1609}
1610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611/*
1612* NVRAM configuration for ISP 2xxx
1613*
1614* Input:
1615* ha = adapter block pointer.
1616*
1617* Output:
1618* initialization control block in response_ring
1619* host adapters parameters in host adapter block
1620*
1621* Returns:
1622* 0 = success.
1623*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001624int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001625qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626{
David Miller4e08df32007-04-16 12:37:43 -07001627 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001628 uint8_t chksum = 0;
1629 uint16_t cnt;
1630 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001631 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001632 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001633 nvram_t *nv = ha->nvram;
1634 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001635 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001636
David Miller4e08df32007-04-16 12:37:43 -07001637 rval = QLA_SUCCESS;
1638
Linus Torvalds1da177e2005-04-16 15:20:36 -07001639 /* Determine NVRAM starting address. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001640 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641 ha->nvram_base = 0;
1642 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1643 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1644 ha->nvram_base = 0x80;
1645
1646 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001647 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001648 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1649 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001650
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001651 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001652 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001653
1654 /* Bad NVRAM data, set defaults parameters. */
1655 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1656 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1657 /* Reset NVRAM data. */
1658 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1659 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1660 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001661 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1662 "invalid -- WWPN) defaults.\n");
1663
1664 /*
1665 * Set default initialization control block.
1666 */
1667 memset(nv, 0, ha->nvram_size);
1668 nv->parameter_block_version = ICB_VERSION;
1669
1670 if (IS_QLA23XX(ha)) {
1671 nv->firmware_options[0] = BIT_2 | BIT_1;
1672 nv->firmware_options[1] = BIT_7 | BIT_5;
1673 nv->add_firmware_options[0] = BIT_5;
1674 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1675 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1676 nv->special_options[1] = BIT_7;
1677 } else if (IS_QLA2200(ha)) {
1678 nv->firmware_options[0] = BIT_2 | BIT_1;
1679 nv->firmware_options[1] = BIT_7 | BIT_5;
1680 nv->add_firmware_options[0] = BIT_5;
1681 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1682 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1683 } else if (IS_QLA2100(ha)) {
1684 nv->firmware_options[0] = BIT_3 | BIT_1;
1685 nv->firmware_options[1] = BIT_5;
1686 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1687 }
1688
1689 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1690 nv->execution_throttle = __constant_cpu_to_le16(16);
1691 nv->retry_count = 8;
1692 nv->retry_delay = 1;
1693
1694 nv->port_name[0] = 33;
1695 nv->port_name[3] = 224;
1696 nv->port_name[4] = 139;
1697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001698 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001699
1700 nv->login_timeout = 4;
1701
1702 /*
1703 * Set default host adapter parameters
1704 */
1705 nv->host_p[1] = BIT_2;
1706 nv->reset_delay = 5;
1707 nv->port_down_retry_count = 8;
1708 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1709 nv->link_down_timeout = 60;
1710
1711 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712 }
1713
1714#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1715 /*
1716 * The SN2 does not provide BIOS emulation which means you can't change
1717 * potentially bogus BIOS settings. Force the use of default settings
1718 * for link rate and frame size. Hope that the rest of the settings
1719 * are valid.
1720 */
1721 if (ia64_platform_is("sn2")) {
1722 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1723 if (IS_QLA23XX(ha))
1724 nv->special_options[1] = BIT_7;
1725 }
1726#endif
1727
1728 /* Reset Initialization control block */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001729 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
1731 /*
1732 * Setup driver NVRAM options.
1733 */
1734 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1735 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1736 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1737 nv->firmware_options[1] &= ~BIT_4;
1738
1739 if (IS_QLA23XX(ha)) {
1740 nv->firmware_options[0] |= BIT_2;
1741 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07001742 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
1744 if (IS_QLA2300(ha)) {
1745 if (ha->fb_rev == FPM_2310) {
1746 strcpy(ha->model_number, "QLA2310");
1747 } else {
1748 strcpy(ha->model_number, "QLA2300");
1749 }
1750 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001751 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001752 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001753 }
1754 } else if (IS_QLA2200(ha)) {
1755 nv->firmware_options[0] |= BIT_2;
1756 /*
1757 * 'Point-to-point preferred, else loop' is not a safe
1758 * connection mode setting.
1759 */
1760 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1761 (BIT_5 | BIT_4)) {
1762 /* Force 'loop preferred, else point-to-point'. */
1763 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1764 nv->add_firmware_options[0] |= BIT_5;
1765 }
1766 strcpy(ha->model_number, "QLA22xx");
1767 } else /*if (IS_QLA2100(ha))*/ {
1768 strcpy(ha->model_number, "QLA2100");
1769 }
1770
1771 /*
1772 * Copy over NVRAM RISC parameter block to initialization control block.
1773 */
1774 dptr1 = (uint8_t *)icb;
1775 dptr2 = (uint8_t *)&nv->parameter_block_version;
1776 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1777 while (cnt--)
1778 *dptr1++ = *dptr2++;
1779
1780 /* Copy 2nd half. */
1781 dptr1 = (uint8_t *)icb->add_firmware_options;
1782 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1783 while (cnt--)
1784 *dptr1++ = *dptr2++;
1785
Andrew Vasquez5341e862006-05-17 15:09:16 -07001786 /* Use alternate WWN? */
1787 if (nv->host_p[1] & BIT_7) {
1788 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1789 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1790 }
1791
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792 /* Prepare nodename */
1793 if ((icb->firmware_options[1] & BIT_6) == 0) {
1794 /*
1795 * Firmware will apply the following mask if the nodename was
1796 * not provided.
1797 */
1798 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1799 icb->node_name[0] &= 0xF0;
1800 }
1801
1802 /*
1803 * Set host adapter parameters.
1804 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001805 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001806 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1808 /* Always load RISC code on non ISP2[12]00 chips. */
1809 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1810 ha->flags.disable_risc_code_load = 0;
1811 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1812 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1813 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001814 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001815 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
1817 ha->operating_mode =
1818 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1819
1820 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1821 sizeof(ha->fw_seriallink_options));
1822
1823 /* save HBA serial number */
1824 ha->serial0 = icb->port_name[5];
1825 ha->serial1 = icb->port_name[6];
1826 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001827 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1828 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001829
1830 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1831
1832 ha->retry_count = nv->retry_count;
1833
1834 /* Set minimum login_timeout to 4 seconds. */
1835 if (nv->login_timeout < ql2xlogintimeout)
1836 nv->login_timeout = ql2xlogintimeout;
1837 if (nv->login_timeout < 4)
1838 nv->login_timeout = 4;
1839 ha->login_timeout = nv->login_timeout;
1840 icb->login_timeout = nv->login_timeout;
1841
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001842 /* Set minimum RATOV to 100 tenths of a second. */
1843 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844
Linus Torvalds1da177e2005-04-16 15:20:36 -07001845 ha->loop_reset_delay = nv->reset_delay;
1846
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 /* Link Down Timeout = 0:
1848 *
1849 * When Port Down timer expires we will start returning
1850 * I/O's to OS with "DID_NO_CONNECT".
1851 *
1852 * Link Down Timeout != 0:
1853 *
1854 * The driver waits for the link to come up after link down
1855 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001856 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 if (nv->link_down_timeout == 0) {
1858 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001859 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001860 } else {
1861 ha->link_down_timeout = nv->link_down_timeout;
1862 ha->loop_down_abort_time =
1863 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001864 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 /*
1867 * Need enough time to try and get the port back.
1868 */
1869 ha->port_down_retry_count = nv->port_down_retry_count;
1870 if (qlport_down_retry)
1871 ha->port_down_retry_count = qlport_down_retry;
1872 /* Set login_retry_count */
1873 ha->login_retry_count = nv->retry_count;
1874 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1875 ha->port_down_retry_count > 3)
1876 ha->login_retry_count = ha->port_down_retry_count;
1877 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1878 ha->login_retry_count = ha->port_down_retry_count;
1879 if (ql2xloginretrycount)
1880 ha->login_retry_count = ql2xloginretrycount;
1881
Linus Torvalds1da177e2005-04-16 15:20:36 -07001882 icb->lun_enables = __constant_cpu_to_le16(0);
1883 icb->command_resource_count = 0;
1884 icb->immediate_notify_resource_count = 0;
1885 icb->timeout = __constant_cpu_to_le16(0);
1886
1887 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1888 /* Enable RIO */
1889 icb->firmware_options[0] &= ~BIT_3;
1890 icb->add_firmware_options[0] &=
1891 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1892 icb->add_firmware_options[0] |= BIT_2;
1893 icb->response_accumulation_timer = 3;
1894 icb->interrupt_delay_timer = 5;
1895
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001898 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001900 ha->zio_mode = icb->add_firmware_options[0] &
1901 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1902 ha->zio_timer = icb->interrupt_delay_timer ?
1903 icb->interrupt_delay_timer: 2;
1904 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 icb->add_firmware_options[0] &=
1906 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001908 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001909 ha->zio_mode = QLA_ZIO_MODE_6;
1910
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001911 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001912 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001913 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001915 "ZIO mode %d enabled; timer delay (%d us).\n",
1916 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001918 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1919 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001920 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 }
1922 }
1923
David Miller4e08df32007-04-16 12:37:43 -07001924 if (rval) {
1925 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001926 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001927 }
1928 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001929}
1930
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001931static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001932qla2x00_rport_del(void *data)
1933{
1934 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001935 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001936
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001937 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001938 rport = fcport->drport;
1939 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001941 if (rport)
1942 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001943}
1944
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945/**
1946 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1947 * @ha: HA context
1948 * @flags: allocation flags
1949 *
1950 * Returns a pointer to the allocated fcport, or NULL, if none available.
1951 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001952static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
1955 fc_port_t *fcport;
1956
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001957 fcport = kzalloc(sizeof(fc_port_t), flags);
1958 if (!fcport)
1959 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960
1961 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 fcport->vha = vha;
1963 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001964 fcport->port_type = FCT_UNKNOWN;
1965 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1967 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001968 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001970 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971}
1972
1973/*
1974 * qla2x00_configure_loop
1975 * Updates Fibre Channel Device Database with what is actually on loop.
1976 *
1977 * Input:
1978 * ha = adapter block pointer.
1979 *
1980 * Returns:
1981 * 0 = success.
1982 * 1 = error.
1983 * 2 = database was full and device was not configured.
1984 */
1985static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001986qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001987{
1988 int rval;
1989 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001991 rval = QLA_SUCCESS;
1992
1993 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001994 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1995 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 if (rval != QLA_SUCCESS) {
1997 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 return (rval);
2000 }
2001 }
2002
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002005 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006
2007 /*
2008 * If we have both an RSCN and PORT UPDATE pending then handle them
2009 * both at the same time.
2010 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002011 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2012 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013
2014 /* Determine what we need to do */
2015 if (ha->current_topology == ISP_CFG_FL &&
2016 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2017
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002018 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 set_bit(RSCN_UPDATE, &flags);
2020
2021 } else if (ha->current_topology == ISP_CFG_F &&
2022 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002024 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 set_bit(RSCN_UPDATE, &flags);
2026 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2027
Andrew Vasquez21333b42006-05-17 15:09:56 -07002028 } else if (ha->current_topology == ISP_CFG_N) {
2029 clear_bit(RSCN_UPDATE, &flags);
2030
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002031 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2033
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035 set_bit(RSCN_UPDATE, &flags);
2036 set_bit(LOCAL_LOOP_UPDATE, &flags);
2037 }
2038
2039 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002042 else
2043 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002044 }
2045
2046 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002049 else
2050 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 }
2052
2053 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002054 if (atomic_read(&vha->loop_down_timer) ||
2055 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 rval = QLA_FUNCTION_FAILED;
2057 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002058 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002060 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 }
2062 }
2063
2064 if (rval) {
2065 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067 } else {
2068 DEBUG3(printk("%s: exiting normally\n", __func__));
2069 }
2070
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002071 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002072 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002074 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002075 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077 }
2078
2079 return (rval);
2080}
2081
2082
2083
2084/*
2085 * qla2x00_configure_local_loop
2086 * Updates Fibre Channel Device Database with local loop devices.
2087 *
2088 * Input:
2089 * ha = adapter block pointer.
2090 *
2091 * Returns:
2092 * 0 = success.
2093 */
2094static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002095qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
2097 int rval, rval2;
2098 int found_devs;
2099 int found;
2100 fc_port_t *fcport, *new_fcport;
2101
2102 uint16_t index;
2103 uint16_t entries;
2104 char *id_iter;
2105 uint16_t loop_id;
2106 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002107 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002108
2109 found_devs = 0;
2110 new_fcport = NULL;
2111 entries = MAX_FIBRE_DEVICES;
2112
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002113 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2114 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115
2116 /* Get list of logged in devices. */
2117 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002118 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002119 &entries);
2120 if (rval != QLA_SUCCESS)
2121 goto cleanup_allocation;
2122
2123 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2124 ha->host_no, entries));
2125 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2126 entries * sizeof(struct gid_list_info)));
2127
2128 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002129 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002130 if (new_fcport == NULL) {
2131 rval = QLA_MEMORY_ALLOC_FAILED;
2132 goto cleanup_allocation;
2133 }
2134 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2135
2136 /*
2137 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2138 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002139 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002140 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2141 fcport->port_type != FCT_BROADCAST &&
2142 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2143
2144 DEBUG(printk("scsi(%ld): Marking port lost, "
2145 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147
2148 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2149 fcport->flags &= ~FCF_FARP_DONE;
2150 }
2151 }
2152
2153 /* Add devices to port list. */
2154 id_iter = (char *)ha->gid_list;
2155 for (index = 0; index < entries; index++) {
2156 domain = ((struct gid_list_info *)id_iter)->domain;
2157 area = ((struct gid_list_info *)id_iter)->area;
2158 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002159 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002160 loop_id = (uint16_t)
2161 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002162 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163 loop_id = le16_to_cpu(
2164 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002165 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166
2167 /* Bypass reserved domain fields. */
2168 if ((domain & 0xf0) == 0xf0)
2169 continue;
2170
2171 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002172 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 continue;
2175
2176 /* Bypass invalid local loop ID. */
2177 if (loop_id > LAST_LOCAL_LOOP_ID)
2178 continue;
2179
2180 /* Fill in member data. */
2181 new_fcport->d_id.b.domain = domain;
2182 new_fcport->d_id.b.area = area;
2183 new_fcport->d_id.b.al_pa = al_pa;
2184 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002185 new_fcport->vp_idx = vha->vp_idx;
2186 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 if (rval2 != QLA_SUCCESS) {
2188 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2189 "information -- get_port_database=%x, "
2190 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002191 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002192 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193 vha->host_no));
2194 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195 continue;
2196 }
2197
2198 /* Check for matching device in port list. */
2199 found = 0;
2200 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002201 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 if (memcmp(new_fcport->port_name, fcport->port_name,
2203 WWN_SIZE))
2204 continue;
2205
2206 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2207 FCF_PERSISTENT_BOUND);
2208 fcport->loop_id = new_fcport->loop_id;
2209 fcport->port_type = new_fcport->port_type;
2210 fcport->d_id.b24 = new_fcport->d_id.b24;
2211 memcpy(fcport->node_name, new_fcport->node_name,
2212 WWN_SIZE);
2213
2214 found++;
2215 break;
2216 }
2217
2218 if (!found) {
2219 /* New device, add to fcports list. */
2220 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002221 if (vha->vp_idx) {
2222 new_fcport->vha = vha;
2223 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002224 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002225 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002226
2227 /* Allocate a new replacement fcport. */
2228 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230 if (new_fcport == NULL) {
2231 rval = QLA_MEMORY_ALLOC_FAILED;
2232 goto cleanup_allocation;
2233 }
2234 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2235 }
2236
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002237 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002238 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002240 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002241
2242 found_devs++;
2243 }
2244
2245cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002246 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002247
2248 if (rval != QLA_SUCCESS) {
2249 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002250 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002251 }
2252
2253 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002254 vha->device_flags |= DFLG_LOCAL_DEVICES;
2255 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 }
2257
2258 return (rval);
2259}
2260
2261static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002263{
2264#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002265 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002266 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002267 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002268 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002269
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002270 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002271 return;
2272
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002273 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2274 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002275 return;
2276
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002277 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002278 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002279 if (rval != QLA_SUCCESS) {
2280 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2281 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002283 fcport->port_name[2], fcport->port_name[3],
2284 fcport->port_name[4], fcport->port_name[5],
2285 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002286 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002287 } else {
2288 DEBUG2(qla_printk(KERN_INFO, ha,
2289 "iIDMA adjusted to %s GB/s on "
2290 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002291 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002292 fcport->port_name[1], fcport->port_name[2],
2293 fcport->port_name[3], fcport->port_name[4],
2294 fcport->port_name[5], fcport->port_name[6],
2295 fcport->port_name[7]));
2296 }
2297}
2298
Adrian Bunk23be3312006-11-24 02:46:01 +01002299static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002300qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e1182005-04-17 15:04:54 -05002301{
2302 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002303 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05002305
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002306 if (fcport->drport)
2307 qla2x00_rport_del(fcport);
8482e1182005-04-17 15:04:54 -05002308
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002309 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2310 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e1182005-04-17 15:04:54 -05002311 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2312 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2313 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002314 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002315 if (!rport) {
2316 qla_printk(KERN_WARNING, ha,
2317 "Unable to allocate fc remote port!\n");
2318 return;
2319 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002320 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002321 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002322 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002323
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002324 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002325
2326 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e1182005-04-17 15:04:54 -05002327 if (fcport->port_type == FCT_INITIATOR)
2328 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2329 if (fcport->port_type == FCT_TARGET)
2330 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002331 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e1182005-04-17 15:04:54 -05002332}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002333
2334/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002335 * qla2x00_update_fcport
2336 * Updates device on list.
2337 *
2338 * Input:
2339 * ha = adapter block pointer.
2340 * fcport = port structure pointer.
2341 *
2342 * Return:
2343 * 0 - Success
2344 * BIT_0 - error
2345 *
2346 * Context:
2347 * Kernel context.
2348 */
2349void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002351{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002353
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002355 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002356 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002357 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002358 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002359 PORT_RETRY_TIME);
2360 fcport->flags &= ~FCF_LOGIN_NEEDED;
2361
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002362 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002363
2364 atomic_set(&fcport->state, FCS_ONLINE);
2365
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002367}
2368
2369/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370 * qla2x00_configure_fabric
2371 * Setup SNS devices with loop ID's.
2372 *
2373 * Input:
2374 * ha = adapter block pointer.
2375 *
2376 * Returns:
2377 * 0 = success.
2378 * BIT_0 = error
2379 */
2380static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002381qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382{
2383 int rval, rval2;
2384 fc_port_t *fcport, *fcptemp;
2385 uint16_t next_loopid;
2386 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002387 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389 struct qla_hw_data *ha = vha->hw;
2390 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
2392 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002393 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002394 loop_id = NPH_F_PORT;
2395 else
2396 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002397 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398 if (rval != QLA_SUCCESS) {
2399 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002401
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 return (QLA_SUCCESS);
2404 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
2407 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002408 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 if (rval2 == QLA_RSCNS_HANDLED) {
2410 /* No point doing the scan, just continue. */
2411 return (QLA_SUCCESS);
2412 }
2413 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002414 /* FDMI support. */
2415 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2417 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002418
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002420 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002421 loop_id = NPH_SNS;
2422 else
2423 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002424 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002425 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 if (mb[0] != MBS_COMMAND_COMPLETE) {
2427 DEBUG2(qla_printk(KERN_INFO, ha,
2428 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002429 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002430 mb[0], mb[1], mb[2], mb[6], mb[7]));
2431 return (QLA_SUCCESS);
2432 }
2433
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002434 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2435 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 /* EMPTY */
2437 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 /* EMPTY */
2442 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 /* EMPTY */
2447 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 "failed.\n", vha->host_no));
2449 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450 /* EMPTY */
2451 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002452 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002453 }
2454 }
2455
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 if (rval != QLA_SUCCESS)
2458 break;
2459
2460 /*
2461 * Logout all previous fabric devices marked lost, except
2462 * tape devices.
2463 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002464 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2465 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 break;
2467
2468 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2469 continue;
2470
2471 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002472 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002473 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474 if (fcport->loop_id != FC_NO_LOOP_ID &&
2475 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2476 fcport->port_type != FCT_INITIATOR &&
2477 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002478 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002479 fcport->loop_id,
2480 fcport->d_id.b.domain,
2481 fcport->d_id.b.area,
2482 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002483 fcport->loop_id = FC_NO_LOOP_ID;
2484 }
2485 }
2486 }
2487
2488 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002490
2491 /*
2492 * Scan through our port list and login entries that need to be
2493 * logged in.
2494 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2496 if (atomic_read(&vha->loop_down_timer) ||
2497 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 break;
2499
2500 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2501 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2502 continue;
2503
2504 if (fcport->loop_id == FC_NO_LOOP_ID) {
2505 fcport->loop_id = next_loopid;
Seokmann Jud4486fd62008-04-03 13:13:28 -07002506 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002507 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 if (rval != QLA_SUCCESS) {
2509 /* Ran out of IDs to use */
2510 break;
2511 }
2512 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002514 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 }
2516
2517 /* Exit if out of loop IDs. */
2518 if (rval != QLA_SUCCESS) {
2519 break;
2520 }
2521
2522 /*
2523 * Login and add the new devices to our port list.
2524 */
2525 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 if (atomic_read(&vha->loop_down_timer) ||
2527 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528 break;
2529
2530 /* Find a new loop ID to use. */
2531 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002532 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 if (rval != QLA_SUCCESS) {
2534 /* Ran out of IDs to use */
2535 break;
2536 }
2537
bdf79622005-04-17 15:06:53 -05002538 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002539 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002540
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002541 if (vha->vp_idx) {
2542 fcport->vha = vha;
2543 fcport->vp_idx = vha->vp_idx;
2544 }
2545 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002546 }
2547 } while (0);
2548
2549 /* Free all new device structures not processed. */
2550 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2551 list_del(&fcport->list);
2552 kfree(fcport);
2553 }
2554
2555 if (rval) {
2556 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002557 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558 }
2559
2560 return (rval);
2561}
2562
2563
2564/*
2565 * qla2x00_find_all_fabric_devs
2566 *
2567 * Input:
2568 * ha = adapter block pointer.
2569 * dev = database device entry pointer.
2570 *
2571 * Returns:
2572 * 0 = success.
2573 *
2574 * Context:
2575 * Kernel context.
2576 */
2577static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002578qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2579 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580{
2581 int rval;
2582 uint16_t loop_id;
2583 fc_port_t *fcport, *new_fcport, *fcptemp;
2584 int found;
2585
2586 sw_info_t *swl;
2587 int swl_idx;
2588 int first_dev, last_dev;
2589 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002590 struct qla_hw_data *ha = vha->hw;
2591 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592
2593 rval = QLA_SUCCESS;
2594
2595 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002596 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002597 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002598 /*EMPTY*/
2599 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002600 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002602 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 kfree(swl);
2604 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 kfree(swl);
2607 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002608 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 kfree(swl);
2610 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002611 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002612 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2613 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 }
2615 }
2616 swl_idx = 0;
2617
2618 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002619 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002620 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002621 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 return (QLA_MEMORY_ALLOC_FAILED);
2623 }
2624 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 /* Set start port ID scan at adapter ID. */
2626 first_dev = 1;
2627 last_dev = 0;
2628
2629 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002630 loop_id = ha->min_external_loopid;
2631 for (; loop_id <= ha->max_loop_id; loop_id++) {
2632 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 continue;
2634
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002636 break;
2637
2638 if (swl != NULL) {
2639 if (last_dev) {
2640 wrap.b24 = new_fcport->d_id.b24;
2641 } else {
2642 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2643 memcpy(new_fcport->node_name,
2644 swl[swl_idx].node_name, WWN_SIZE);
2645 memcpy(new_fcport->port_name,
2646 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002647 memcpy(new_fcport->fabric_port_name,
2648 swl[swl_idx].fabric_port_name, WWN_SIZE);
2649 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650
2651 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2652 last_dev = 1;
2653 }
2654 swl_idx++;
2655 }
2656 } else {
2657 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 if (rval != QLA_SUCCESS) {
2660 qla_printk(KERN_WARNING, ha,
2661 "SNS scan failed -- assuming zero-entry "
2662 "result...\n");
2663 list_for_each_entry_safe(fcport, fcptemp,
2664 new_fcports, list) {
2665 list_del(&fcport->list);
2666 kfree(fcport);
2667 }
2668 rval = QLA_SUCCESS;
2669 break;
2670 }
2671 }
2672
2673 /* If wrap on switch device list, exit. */
2674 if (first_dev) {
2675 wrap.b24 = new_fcport->d_id.b24;
2676 first_dev = 0;
2677 } else if (new_fcport->d_id.b24 == wrap.b24) {
2678 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002679 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2681 break;
2682 }
2683
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002684 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002685 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 continue;
2687
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002688 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002689 found = 0;
2690 if (ha->num_vhosts) {
2691 list_for_each_entry(vp, &ha->vp_list, list) {
2692 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2693 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002694 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002695 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002696 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002697 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002698 continue;
2699 }
2700
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002701 /* Bypass if same domain and area of adapter. */
2702 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002703 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002704 ISP_CFG_FL)
2705 continue;
2706
Linus Torvalds1da177e2005-04-16 15:20:36 -07002707 /* Bypass reserved domain fields. */
2708 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2709 continue;
2710
2711 /* Locate matching device in database. */
2712 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 if (memcmp(new_fcport->port_name, fcport->port_name,
2715 WWN_SIZE))
2716 continue;
2717
2718 found++;
2719
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002720 /* Update port state. */
2721 memcpy(fcport->fabric_port_name,
2722 new_fcport->fabric_port_name, WWN_SIZE);
2723 fcport->fp_speed = new_fcport->fp_speed;
2724
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725 /*
2726 * If address the same and state FCS_ONLINE, nothing
2727 * changed.
2728 */
2729 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2730 atomic_read(&fcport->state) == FCS_ONLINE) {
2731 break;
2732 }
2733
2734 /*
2735 * If device was not a fabric device before.
2736 */
2737 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2738 fcport->d_id.b24 = new_fcport->d_id.b24;
2739 fcport->loop_id = FC_NO_LOOP_ID;
2740 fcport->flags |= (FCF_FABRIC_DEVICE |
2741 FCF_LOGIN_NEEDED);
2742 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2743 break;
2744 }
2745
2746 /*
2747 * Port ID changed or device was marked to be updated;
2748 * Log it out if still logged in and mark it for
2749 * relogin later.
2750 */
2751 fcport->d_id.b24 = new_fcport->d_id.b24;
2752 fcport->flags |= FCF_LOGIN_NEEDED;
2753 if (fcport->loop_id != FC_NO_LOOP_ID &&
2754 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2755 fcport->port_type != FCT_INITIATOR &&
2756 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002757 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002758 fcport->d_id.b.domain, fcport->d_id.b.area,
2759 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 fcport->loop_id = FC_NO_LOOP_ID;
2761 }
2762
2763 break;
2764 }
2765
2766 if (found)
2767 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 /* If device was not in our fcports list, then add it. */
2769 list_add_tail(&new_fcport->list, new_fcports);
2770
2771 /* Allocate a new replacement fcport. */
2772 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002773 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002775 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776 return (QLA_MEMORY_ALLOC_FAILED);
2777 }
2778 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2779 new_fcport->d_id.b24 = nxt_d_id.b24;
2780 }
2781
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002782 kfree(swl);
2783 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002786 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
2788 return (rval);
2789}
2790
2791/*
2792 * qla2x00_find_new_loop_id
2793 * Scan through our port list and find a new usable loop ID.
2794 *
2795 * Input:
2796 * ha: adapter state pointer.
2797 * dev: port structure pointer.
2798 *
2799 * Returns:
2800 * qla2x00 local function return status code.
2801 *
2802 * Context:
2803 * Kernel context.
2804 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002805static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002806qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807{
2808 int rval;
2809 int found;
2810 fc_port_t *fcport;
2811 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002812 struct qla_hw_data *ha = vha->hw;
2813 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814
2815 rval = QLA_SUCCESS;
2816
2817 /* Save starting loop ID. */
2818 first_loop_id = dev->loop_id;
2819
2820 for (;;) {
2821 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002822 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824
2825 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002826 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002827 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828
2829 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002830 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002831 /* first loop ID. */
2832 dev->loop_id = ha->min_external_loopid;
2833 }
2834
2835 /* Check for loop ID being already in use. */
2836 found = 0;
2837 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002838 list_for_each_entry(vp, &ha->vp_list, list) {
2839 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2840 if (fcport->loop_id == dev->loop_id &&
2841 fcport != dev) {
2842 /* ID possibly in use */
2843 found++;
2844 break;
2845 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002846 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002847 if (found)
2848 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 }
2850
2851 /* If not in use then it is free to use. */
2852 if (!found) {
2853 break;
2854 }
2855
2856 /* ID in use. Try next value. */
2857 dev->loop_id++;
2858
2859 /* If wrap around. No free ID to use. */
2860 if (dev->loop_id == first_loop_id) {
2861 dev->loop_id = FC_NO_LOOP_ID;
2862 rval = QLA_FUNCTION_FAILED;
2863 break;
2864 }
2865 }
2866
2867 return (rval);
2868}
2869
2870/*
2871 * qla2x00_device_resync
2872 * Marks devices in the database that needs resynchronization.
2873 *
2874 * Input:
2875 * ha = adapter block pointer.
2876 *
2877 * Context:
2878 * Kernel context.
2879 */
2880static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002882{
2883 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 uint32_t mask;
2885 fc_port_t *fcport;
2886 uint32_t rscn_entry;
2887 uint8_t rscn_out_iter;
2888 uint8_t format;
2889 port_id_t d_id;
2890
2891 rval = QLA_RSCNS_HANDLED;
2892
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002893 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2894 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002896 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 format = MSB(MSW(rscn_entry));
2898 d_id.b.domain = LSB(MSW(rscn_entry));
2899 d_id.b.area = MSB(LSW(rscn_entry));
2900 d_id.b.al_pa = LSB(LSW(rscn_entry));
2901
2902 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2903 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002904 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 d_id.b.area, d_id.b.al_pa));
2906
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002907 vha->rscn_out_ptr++;
2908 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2909 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910
2911 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002912 for (rscn_out_iter = vha->rscn_out_ptr;
2913 !vha->flags.rscn_queue_overflow &&
2914 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 rscn_out_iter = (rscn_out_iter ==
2916 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2917
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002918 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919 break;
2920
2921 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002922 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 rscn_out_iter));
2924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 }
2927
2928 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002929 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002930 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002931 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002932
2933 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 }
2936
2937 switch (format) {
2938 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 mask = 0xffffff;
2940 break;
2941 case 1:
2942 mask = 0xffff00;
2943 break;
2944 case 2:
2945 mask = 0xff0000;
2946 break;
2947 default:
2948 mask = 0x0;
2949 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002950 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002951 break;
2952 }
2953
2954 rval = QLA_SUCCESS;
2955
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002956 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2958 (fcport->d_id.b24 & mask) != d_id.b24 ||
2959 fcport->port_type == FCT_BROADCAST)
2960 continue;
2961
2962 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2963 if (format != 3 ||
2964 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002965 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002966 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002967 }
2968 }
2969 fcport->flags &= ~FCF_FARP_DONE;
2970 }
2971 }
2972 return (rval);
2973}
2974
2975/*
2976 * qla2x00_fabric_dev_login
2977 * Login fabric target device and update FC port database.
2978 *
2979 * Input:
2980 * ha: adapter state pointer.
2981 * fcport: port structure list pointer.
2982 * next_loopid: contains value of a new loop ID that can be used
2983 * by the next login attempt.
2984 *
2985 * Returns:
2986 * qla2x00 local function return status code.
2987 *
2988 * Context:
2989 * Kernel context.
2990 */
2991static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002992qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 uint16_t *next_loopid)
2994{
2995 int rval;
2996 int retry;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07002997 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002999
3000 rval = QLA_SUCCESS;
3001 retry = 0;
3002
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 if (rval == QLA_SUCCESS) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003005 /* Send an ADISC to tape devices.*/
3006 opts = 0;
3007 if (fcport->flags & FCF_TAPE_PRESENT)
3008 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003009 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003011 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003012 fcport->d_id.b.domain, fcport->d_id.b.area,
3013 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 }
3018 }
3019
3020 return (rval);
3021}
3022
3023/*
3024 * qla2x00_fabric_login
3025 * Issue fabric login command.
3026 *
3027 * Input:
3028 * ha = adapter block pointer.
3029 * device = pointer to FC device type structure.
3030 *
3031 * Returns:
3032 * 0 - Login successfully
3033 * 1 - Login failed
3034 * 2 - Initiator device
3035 * 3 - Fatal error
3036 */
3037int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003038qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003039 uint16_t *next_loopid)
3040{
3041 int rval;
3042 int retry;
3043 uint16_t tmp_loopid;
3044 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003045 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046
3047 retry = 0;
3048 tmp_loopid = 0;
3049
3050 for (;;) {
3051 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3052 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3055
3056 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003057 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058 fcport->d_id.b.domain, fcport->d_id.b.area,
3059 fcport->d_id.b.al_pa, mb, BIT_0);
3060 if (mb[0] == MBS_PORT_ID_USED) {
3061 /*
3062 * Device has another loop ID. The firmware team
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003063 * recommends the driver perform an implicit login with
3064 * the specified ID again. The ID we just used is save
3065 * here so we return with an ID that can be tried by
3066 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 */
3068 retry++;
3069 tmp_loopid = fcport->loop_id;
3070 fcport->loop_id = mb[1];
3071
3072 DEBUG(printk("Fabric Login: port in use - next "
3073 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3074 fcport->loop_id, fcport->d_id.b.domain,
3075 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3076
3077 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3078 /*
3079 * Login succeeded.
3080 */
3081 if (retry) {
3082 /* A retry occurred before. */
3083 *next_loopid = tmp_loopid;
3084 } else {
3085 /*
3086 * No retry occurred before. Just increment the
3087 * ID value for next login.
3088 */
3089 *next_loopid = (fcport->loop_id + 1);
3090 }
3091
3092 if (mb[1] & BIT_0) {
3093 fcport->port_type = FCT_INITIATOR;
3094 } else {
3095 fcport->port_type = FCT_TARGET;
3096 if (mb[1] & BIT_1) {
3097 fcport->flags |= FCF_TAPE_PRESENT;
3098 }
3099 }
3100
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003101 if (mb[10] & BIT_0)
3102 fcport->supported_classes |= FC_COS_CLASS2;
3103 if (mb[10] & BIT_1)
3104 fcport->supported_classes |= FC_COS_CLASS3;
3105
Linus Torvalds1da177e2005-04-16 15:20:36 -07003106 rval = QLA_SUCCESS;
3107 break;
3108 } else if (mb[0] == MBS_LOOP_ID_USED) {
3109 /*
3110 * Loop ID already used, try next loop ID.
3111 */
3112 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003113 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 if (rval != QLA_SUCCESS) {
3115 /* Ran out of loop IDs to use */
3116 break;
3117 }
3118 } else if (mb[0] == MBS_COMMAND_ERROR) {
3119 /*
3120 * Firmware possibly timed out during login. If NO
3121 * retries are left to do then the device is declared
3122 * dead.
3123 */
3124 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003126 fcport->d_id.b.domain, fcport->d_id.b.area,
3127 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003128 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003129
3130 rval = 1;
3131 break;
3132 } else {
3133 /*
3134 * unrecoverable / not handled error
3135 */
3136 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003137 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003138 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 fcport->d_id.b.domain, fcport->d_id.b.area,
3140 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3141
3142 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003144 fcport->d_id.b.domain, fcport->d_id.b.area,
3145 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003146 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003147 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003148
3149 rval = 3;
3150 break;
3151 }
3152 }
3153
3154 return (rval);
3155}
3156
3157/*
3158 * qla2x00_local_device_login
3159 * Issue local device login command.
3160 *
3161 * Input:
3162 * ha = adapter block pointer.
3163 * loop_id = loop id of device to login to.
3164 *
3165 * Returns (Where's the #define!!!!):
3166 * 0 - Login successfully
3167 * 1 - Login failed
3168 * 3 - Fatal error
3169 */
3170int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003171qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003172{
3173 int rval;
3174 uint16_t mb[MAILBOX_REGISTER_COUNT];
3175
3176 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003177 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003178 if (rval == QLA_SUCCESS) {
3179 /* Interrogate mailbox registers for any errors */
3180 if (mb[0] == MBS_COMMAND_ERROR)
3181 rval = 1;
3182 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3183 /* device not in PCB table */
3184 rval = 3;
3185 }
3186
3187 return (rval);
3188}
3189
3190/*
3191 * qla2x00_loop_resync
3192 * Resync with fibre channel devices.
3193 *
3194 * Input:
3195 * ha = adapter block pointer.
3196 *
3197 * Returns:
3198 * 0 = success
3199 */
3200int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003201qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003203 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003205 struct qla_hw_data *ha = vha->hw;
3206 struct req_que *req = ha->req_q_map[0];
3207 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003209 atomic_set(&vha->loop_state, LOOP_UPDATE);
3210 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3211 if (vha->flags.online) {
3212 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3214 wait_time = 256;
3215 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003216 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003218 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003219 qla2x00_marker(vha, req, rsp, 0, 0,
3220 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003221 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
3223 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003226 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003228 } while (!atomic_read(&vha->loop_down_timer) &&
3229 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3230 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3231 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 }
3234
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003235 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
3241 return (rval);
3242}
3243
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003246{
3247 fc_port_t *fcport;
3248
3249 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 list_for_each_entry(fcport, &vha->vp_fcports, list)
3251 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003252 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003253 qla2x00_rport_del(fcport);
3254}
3255
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256/*
3257* qla2x00_abort_isp
3258* Resets ISP and aborts all outstanding commands.
3259*
3260* Input:
3261* ha = adapter block pointer.
3262*
3263* Returns:
3264* 0 = success
3265*/
3266int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003269 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003270 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 struct qla_hw_data *ha = vha->hw;
3272 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003273 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003275 if (vha->flags.online) {
3276 vha->flags.online = 0;
3277 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003278 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
3280 qla_printk(KERN_INFO, ha,
3281 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003282 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003284 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3285 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3286 atomic_set(&vha->loop_state, LOOP_DOWN);
3287 qla2x00_mark_all_devices_lost(vha, 0);
3288 list_for_each_entry(vp, &ha->vp_list, list)
3289 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 if (!atomic_read(&vha->loop_down_timer))
3292 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 LOOP_DOWN_TIME);
3294 }
3295
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003299 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003300
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003303 if (!qla2x00_restart_isp(vha)) {
3304 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307 /*
3308 * Issue marker command only when we are going
3309 * to start the I/O .
3310 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003311 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 }
3313
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003314 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003316 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003318 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003320
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003321 if (ha->fce) {
3322 ha->flags.fce_enabled = 1;
3323 memset(ha->fce, 0,
3324 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003325 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003326 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3327 &ha->fce_bufs);
3328 if (rval) {
3329 qla_printk(KERN_WARNING, ha,
3330 "Unable to reinitialize FCE "
3331 "(%d).\n", rval);
3332 ha->flags.fce_enabled = 0;
3333 }
3334 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003335
3336 if (ha->eft) {
3337 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003338 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003339 ha->eft_dma, EFT_NUM_BUFFERS);
3340 if (rval) {
3341 qla_printk(KERN_WARNING, ha,
3342 "Unable to reinitialize EFT "
3343 "(%d).\n", rval);
3344 }
3345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 vha->flags.online = 1;
3348 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 if (ha->isp_abort_cnt == 0) {
3350 qla_printk(KERN_WARNING, ha,
3351 "ISP error recovery failed - "
3352 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003353 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 * The next call disables the board
3355 * completely.
3356 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003357 ha->isp_ops->reset_adapter(vha);
3358 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003360 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 status = 0;
3362 } else { /* schedule another ISP abort */
3363 ha->isp_abort_cnt--;
3364 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003365 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003366 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 status = 1;
3368 }
3369 } else {
3370 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3371 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3372 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003373 vha->host_no, ha->isp_abort_cnt));
3374 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375 status = 1;
3376 }
3377 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003378
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379 }
3380
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381 if (!status) {
3382 DEBUG(printk(KERN_INFO
3383 "qla2x00_abort_isp(%ld): succeeded.\n",
3384 vha->host_no));
3385 list_for_each_entry(vp, &ha->vp_list, list) {
3386 if (vp->vp_idx)
3387 qla2x00_vp_abort_isp(vp);
3388 }
3389 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003390 qla_printk(KERN_INFO, ha,
3391 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 }
3393
3394 return(status);
3395}
3396
3397/*
3398* qla2x00_restart_isp
3399* restarts the ISP after a reset
3400*
3401* Input:
3402* ha = adapter block pointer.
3403*
3404* Returns:
3405* 0 = success
3406*/
3407static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003408qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409{
3410 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003411 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003412 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003413 struct req_que *req = ha->req_q_map[0];
3414 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415
3416 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417 if (qla2x00_isp_firmware(vha)) {
3418 vha->flags.online = 0;
3419 status = ha->isp_ops->chip_diag(vha);
3420 if (!status)
3421 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 }
3423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 if (!status && !(status = qla2x00_init_rings(vha))) {
3425 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003426 /* Initialize the queues in use */
3427 qla25xx_init_queues(ha);
3428
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429 status = qla2x00_fw_ready(vha);
3430 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003432 "status = %d\n", __func__, status));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003433
3434 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003435 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003436
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003437 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3439 wait_time = 256;
3440 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003441 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3442 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003444 } while (!atomic_read(&vha->loop_down_timer) &&
3445 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3446 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3447 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 }
3449
3450 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003451 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 status = 0;
3453
3454 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3455 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003456 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 }
3458 return (status);
3459}
3460
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003461static int
3462qla25xx_init_queues(struct qla_hw_data *ha)
3463{
3464 struct rsp_que *rsp = NULL;
3465 struct req_que *req = NULL;
3466 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3467 int ret = -1;
3468 int i;
3469
3470 for (i = 1; i < ha->max_queues; i++) {
3471 rsp = ha->rsp_q_map[i];
3472 if (rsp) {
3473 rsp->options &= ~BIT_0;
3474 ret = qla25xx_init_rsp_que(base_vha, rsp, rsp->options);
3475 if (ret != QLA_SUCCESS)
3476 DEBUG2_17(printk(KERN_WARNING
3477 "%s Rsp que:%d init failed\n", __func__,
3478 rsp->id));
3479 else
3480 DEBUG2_17(printk(KERN_INFO
3481 "%s Rsp que:%d inited\n", __func__,
3482 rsp->id));
3483 }
3484 req = ha->req_q_map[i];
3485 if (req) {
3486 req->options &= ~BIT_0;
3487 ret = qla25xx_init_req_que(base_vha, req, req->options);
3488 if (ret != QLA_SUCCESS)
3489 DEBUG2_17(printk(KERN_WARNING
3490 "%s Req que:%d init failed\n", __func__,
3491 req->id));
3492 else
3493 DEBUG2_17(printk(KERN_WARNING
3494 "%s Rsp que:%d inited\n", __func__,
3495 req->id));
3496 }
3497 }
3498 return ret;
3499}
3500
Linus Torvalds1da177e2005-04-16 15:20:36 -07003501/*
3502* qla2x00_reset_adapter
3503* Reset adapter.
3504*
3505* Input:
3506* ha = adapter block pointer.
3507*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003508void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003509qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003510{
3511 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003512 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003513 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003515 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003516 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 spin_lock_irqsave(&ha->hardware_lock, flags);
3519 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3520 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3521 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3522 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3523 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3524}
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003525
3526void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003527qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003528{
3529 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003531 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3532
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003533 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003534 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003535
3536 spin_lock_irqsave(&ha->hardware_lock, flags);
3537 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3538 RD_REG_DWORD(&reg->hccr);
3539 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3540 RD_REG_DWORD(&reg->hccr);
3541 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3542}
3543
David Miller4e08df32007-04-16 12:37:43 -07003544/* On sparc systems, obtain port and node WWN from firmware
3545 * properties.
3546 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003547static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3548 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003549{
3550#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003552 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003553 struct device_node *dp = pci_device_to_OF_node(pdev);
3554 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003555 int len;
3556
3557 val = of_get_property(dp, "port-wwn", &len);
3558 if (val && len >= WWN_SIZE)
3559 memcpy(nv->port_name, val, WWN_SIZE);
3560
3561 val = of_get_property(dp, "node-wwn", &len);
3562 if (val && len >= WWN_SIZE)
3563 memcpy(nv->node_name, val, WWN_SIZE);
3564#endif
3565}
3566
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003567int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003568qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003569{
David Miller4e08df32007-04-16 12:37:43 -07003570 int rval;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003571 struct init_cb_24xx *icb;
3572 struct nvram_24xx *nv;
3573 uint32_t *dptr;
3574 uint8_t *dptr1, *dptr2;
3575 uint32_t chksum;
3576 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003577 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003578
David Miller4e08df32007-04-16 12:37:43 -07003579 rval = QLA_SUCCESS;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003580 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003581 nv = ha->nvram;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003582
3583 /* Determine NVRAM starting address. */
3584 ha->nvram_size = sizeof(struct nvram_24xx);
3585 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003586 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3587 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3588 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003589 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003590 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3591 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003592
Seokmann Ju281afe12007-07-26 13:43:34 -07003593 /* Get VPD data into cache */
3594 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003595 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003596 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3597
3598 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003599 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003601 ha->nvram_size);
3602 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3603 chksum += le32_to_cpu(*dptr++);
3604
3605 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003606 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003607
3608 /* Bad NVRAM data, set defaults parameters. */
3609 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3610 || nv->id[3] != ' ' ||
3611 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3612 /* Reset NVRAM data. */
3613 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3614 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3615 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003616 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3617 "invalid -- WWPN) defaults.\n");
3618
3619 /*
3620 * Set default initialization control block.
3621 */
3622 memset(nv, 0, ha->nvram_size);
3623 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3624 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3625 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3626 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3627 nv->exchange_count = __constant_cpu_to_le16(0);
3628 nv->hard_address = __constant_cpu_to_le16(124);
3629 nv->port_name[0] = 0x21;
3630 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3631 nv->port_name[2] = 0x00;
3632 nv->port_name[3] = 0xe0;
3633 nv->port_name[4] = 0x8b;
3634 nv->port_name[5] = 0x1c;
3635 nv->port_name[6] = 0x55;
3636 nv->port_name[7] = 0x86;
3637 nv->node_name[0] = 0x20;
3638 nv->node_name[1] = 0x00;
3639 nv->node_name[2] = 0x00;
3640 nv->node_name[3] = 0xe0;
3641 nv->node_name[4] = 0x8b;
3642 nv->node_name[5] = 0x1c;
3643 nv->node_name[6] = 0x55;
3644 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003645 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003646 nv->login_retry_count = __constant_cpu_to_le16(8);
3647 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3648 nv->login_timeout = __constant_cpu_to_le16(0);
3649 nv->firmware_options_1 =
3650 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3651 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3652 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3653 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3654 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3655 nv->efi_parameters = __constant_cpu_to_le32(0);
3656 nv->reset_delay = 5;
3657 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3658 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3659 nv->link_down_timeout = __constant_cpu_to_le16(30);
3660
3661 rval = 1;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003662 }
3663
3664 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003665 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003666
3667 /* Copy 1st segment. */
3668 dptr1 = (uint8_t *)icb;
3669 dptr2 = (uint8_t *)&nv->version;
3670 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3671 while (cnt--)
3672 *dptr1++ = *dptr2++;
3673
3674 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003675 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003676
3677 /* Copy 2nd segment. */
3678 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3679 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3680 cnt = (uint8_t *)&icb->reserved_3 -
3681 (uint8_t *)&icb->interrupt_delay_timer;
3682 while (cnt--)
3683 *dptr1++ = *dptr2++;
3684
3685 /*
3686 * Setup driver NVRAM options.
3687 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003688 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003689 "QLA2462");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003690
Andrew Vasquez5341e862006-05-17 15:09:16 -07003691 /* Use alternate WWN? */
3692 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3693 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3694 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3695 }
3696
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003697 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003698 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003699 /*
3700 * Firmware will apply the following mask if the nodename was
3701 * not provided.
3702 */
3703 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3704 icb->node_name[0] &= 0xF0;
3705 }
3706
3707 /* Set host adapter parameters. */
3708 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003709 ha->flags.enable_lip_reset = 0;
3710 ha->flags.enable_lip_full_login =
3711 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3712 ha->flags.enable_target_reset =
3713 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003714 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003715 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003716
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003717 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3718 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003719
3720 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3721 sizeof(ha->fw_seriallink_options24));
3722
3723 /* save HBA serial number */
3724 ha->serial0 = icb->port_name[5];
3725 ha->serial1 = icb->port_name[6];
3726 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003727 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3728 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003729
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003730 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3731
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003732 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3733
3734 /* Set minimum login_timeout to 4 seconds. */
3735 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3736 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3737 if (le16_to_cpu(nv->login_timeout) < 4)
3738 nv->login_timeout = __constant_cpu_to_le16(4);
3739 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003740 icb->login_timeout = nv->login_timeout;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003741
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003742 /* Set minimum RATOV to 100 tenths of a second. */
3743 ha->r_a_tov = 100;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003744
3745 ha->loop_reset_delay = nv->reset_delay;
3746
3747 /* Link Down Timeout = 0:
3748 *
3749 * When Port Down timer expires we will start returning
3750 * I/O's to OS with "DID_NO_CONNECT".
3751 *
3752 * Link Down Timeout != 0:
3753 *
3754 * The driver waits for the link to come up after link down
3755 * before returning I/Os to OS with "DID_NO_CONNECT".
3756 */
3757 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3758 ha->loop_down_abort_time =
3759 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3760 } else {
3761 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3762 ha->loop_down_abort_time =
3763 (LOOP_DOWN_TIME - ha->link_down_timeout);
3764 }
3765
3766 /* Need enough time to try and get the port back. */
3767 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3768 if (qlport_down_retry)
3769 ha->port_down_retry_count = qlport_down_retry;
3770
3771 /* Set login_retry_count */
3772 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3773 if (ha->port_down_retry_count ==
3774 le16_to_cpu(nv->port_down_retry_count) &&
3775 ha->port_down_retry_count > 3)
3776 ha->login_retry_count = ha->port_down_retry_count;
3777 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3778 ha->login_retry_count = ha->port_down_retry_count;
3779 if (ql2xloginretrycount)
3780 ha->login_retry_count = ql2xloginretrycount;
3781
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003782 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003783 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003784 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3785 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3786 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3787 le16_to_cpu(icb->interrupt_delay_timer): 2;
3788 }
3789 icb->firmware_options_2 &= __constant_cpu_to_le32(
3790 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003791 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003792 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003793 ha->zio_mode = QLA_ZIO_MODE_6;
3794
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003795 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003796 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003797 ha->zio_timer * 100));
3798 qla_printk(KERN_INFO, ha,
3799 "ZIO mode %d enabled; timer delay (%d us).\n",
3800 ha->zio_mode, ha->zio_timer * 100);
3801
3802 icb->firmware_options_2 |= cpu_to_le32(
3803 (uint32_t)ha->zio_mode);
3804 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003805 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003806 }
3807
David Miller4e08df32007-04-16 12:37:43 -07003808 if (rval) {
3809 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003810 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003811 }
3812 return (rval);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003813}
3814
Adrian Bunk413975a2006-06-30 02:33:06 -07003815static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003816qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003817{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003818 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003819 int segments, fragment;
3820 uint32_t faddr;
3821 uint32_t *dcode, dlen;
3822 uint32_t risc_addr;
3823 uint32_t risc_size;
3824 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003825 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003826 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003827 rval = QLA_SUCCESS;
3828
3829 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003830 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003831 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003832 *srisc_addr = 0;
3833
3834 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003835 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003836 for (i = 0; i < 4; i++)
3837 dcode[i] = be32_to_cpu(dcode[i]);
3838 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3839 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3840 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3841 dcode[3] == 0)) {
3842 qla_printk(KERN_WARNING, ha,
3843 "Unable to verify integrity of flash firmware image!\n");
3844 qla_printk(KERN_WARNING, ha,
3845 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3846 dcode[1], dcode[2], dcode[3]);
3847
3848 return QLA_FUNCTION_FAILED;
3849 }
3850
3851 while (segments && rval == QLA_SUCCESS) {
3852 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003853 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003854
3855 risc_addr = be32_to_cpu(dcode[2]);
3856 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3857 risc_size = be32_to_cpu(dcode[3]);
3858
3859 fragment = 0;
3860 while (risc_size > 0 && rval == QLA_SUCCESS) {
3861 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3862 if (dlen > risc_size)
3863 dlen = risc_size;
3864
3865 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3866 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003867 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003869 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003870 for (i = 0; i < dlen; i++)
3871 dcode[i] = swab32(dcode[i]);
3872
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003873 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003874 dlen);
3875 if (rval) {
3876 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003877 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003878 fragment));
3879 qla_printk(KERN_WARNING, ha,
3880 "[ERROR] Failed to load segment %d of "
3881 "firmware\n", fragment);
3882 break;
3883 }
3884
3885 faddr += dlen;
3886 risc_addr += dlen;
3887 risc_size -= dlen;
3888 fragment++;
3889 }
3890
3891 /* Next segment. */
3892 segments--;
3893 }
3894
3895 return rval;
3896}
3897
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003898#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3899
Andrew Vasquez0107109e2005-07-06 10:31:37 -07003900int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003901qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003902{
3903 int rval;
3904 int i, fragment;
3905 uint16_t *wcode, *fwcode;
3906 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3907 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003908 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003909 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003910
3911 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003912 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003913 if (!blob) {
3914 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003915 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3916 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003917 return QLA_FUNCTION_FAILED;
3918 }
3919
3920 rval = QLA_SUCCESS;
3921
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003922 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003923 *srisc_addr = 0;
3924 fwcode = (uint16_t *)blob->fw->data;
3925 fwclen = 0;
3926
3927 /* Validate firmware image by checking version. */
3928 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3929 qla_printk(KERN_WARNING, ha,
3930 "Unable to verify integrity of firmware image (%Zd)!\n",
3931 blob->fw->size);
3932 goto fail_fw_integrity;
3933 }
3934 for (i = 0; i < 4; i++)
3935 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3936 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3937 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3938 wcode[2] == 0 && wcode[3] == 0)) {
3939 qla_printk(KERN_WARNING, ha,
3940 "Unable to verify integrity of firmware image!\n");
3941 qla_printk(KERN_WARNING, ha,
3942 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3943 wcode[1], wcode[2], wcode[3]);
3944 goto fail_fw_integrity;
3945 }
3946
3947 seg = blob->segs;
3948 while (*seg && rval == QLA_SUCCESS) {
3949 risc_addr = *seg;
3950 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3951 risc_size = be16_to_cpu(fwcode[3]);
3952
3953 /* Validate firmware image size. */
3954 fwclen += risc_size * sizeof(uint16_t);
3955 if (blob->fw->size < fwclen) {
3956 qla_printk(KERN_WARNING, ha,
3957 "Unable to verify integrity of firmware image "
3958 "(%Zd)!\n", blob->fw->size);
3959 goto fail_fw_integrity;
3960 }
3961
3962 fragment = 0;
3963 while (risc_size > 0 && rval == QLA_SUCCESS) {
3964 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3965 if (wlen > risc_size)
3966 wlen = risc_size;
3967
3968 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003969 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003970 risc_addr, wlen));
3971
3972 for (i = 0; i < wlen; i++)
3973 wcode[i] = swab16(fwcode[i]);
3974
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003975 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003976 wlen);
3977 if (rval) {
3978 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003979 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003980 fragment));
3981 qla_printk(KERN_WARNING, ha,
3982 "[ERROR] Failed to load segment %d of "
3983 "firmware\n", fragment);
3984 break;
3985 }
3986
3987 fwcode += wlen;
3988 risc_addr += wlen;
3989 risc_size -= wlen;
3990 fragment++;
3991 }
3992
3993 /* Next segment. */
3994 seg++;
3995 }
3996 return rval;
3997
3998fail_fw_integrity:
3999 return QLA_FUNCTION_FAILED;
4000}
4001
4002int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004003qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004004{
4005 int rval;
4006 int segments, fragment;
4007 uint32_t *dcode, dlen;
4008 uint32_t risc_addr;
4009 uint32_t risc_size;
4010 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004011 struct fw_blob *blob;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004012 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004013 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004014 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004015
Andrew Vasquez54333832005-11-09 15:49:04 -08004016 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004017 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004018 if (!blob) {
4019 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004020 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4021 "from: " QLA_FW_URL ".\n");
4022
4023 /* Try to load RISC code from flash. */
4024 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
4025 "outdated) firmware from flash.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004026 return qla24xx_load_risc_flash(vha, srisc_addr);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004027 }
4028
4029 rval = QLA_SUCCESS;
4030
4031 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004032 dcode = (uint32_t *)req->ring;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004033 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004034 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004035 fwclen = 0;
4036
4037 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004038 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004039 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004040 "Unable to verify integrity of firmware image (%Zd)!\n",
4041 blob->fw->size);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004042 goto fail_fw_integrity;
4043 }
4044 for (i = 0; i < 4; i++)
4045 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4046 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4047 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4048 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4049 dcode[3] == 0)) {
4050 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004051 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004052 qla_printk(KERN_WARNING, ha,
4053 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4054 dcode[1], dcode[2], dcode[3]);
4055 goto fail_fw_integrity;
4056 }
4057
4058 while (segments && rval == QLA_SUCCESS) {
4059 risc_addr = be32_to_cpu(fwcode[2]);
4060 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4061 risc_size = be32_to_cpu(fwcode[3]);
4062
4063 /* Validate firmware image size. */
4064 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004065 if (blob->fw->size < fwclen) {
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004066 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004067 "Unable to verify integrity of firmware image "
4068 "(%Zd)!\n", blob->fw->size);
4069
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004070 goto fail_fw_integrity;
4071 }
4072
4073 fragment = 0;
4074 while (risc_size > 0 && rval == QLA_SUCCESS) {
4075 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4076 if (dlen > risc_size)
4077 dlen = risc_size;
4078
4079 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004080 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004081 risc_addr, dlen));
4082
4083 for (i = 0; i < dlen; i++)
4084 dcode[i] = swab32(fwcode[i]);
4085
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004086 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004087 dlen);
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004088 if (rval) {
4089 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004090 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004091 fragment));
4092 qla_printk(KERN_WARNING, ha,
4093 "[ERROR] Failed to load segment %d of "
4094 "firmware\n", fragment);
4095 break;
4096 }
4097
4098 fwcode += dlen;
4099 risc_addr += dlen;
4100 risc_size -= dlen;
4101 fragment++;
4102 }
4103
4104 /* Next segment. */
4105 segments--;
4106 }
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004107 return rval;
4108
4109fail_fw_integrity:
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004110 return QLA_FUNCTION_FAILED;
Andrew Vasquez0107109e2005-07-06 10:31:37 -07004111}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004112
4113void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004114qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004115{
4116 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004117 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004118
Andrew Vasqueze4289242007-07-19 15:05:56 -07004119 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004120 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004121 if (!ha->fw_major_version)
4122 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004123
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004124 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004125 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4126 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004127 ha->isp_ops->reset_chip(vha);
4128 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004129 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004130 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004131 continue;
4132 qla_printk(KERN_INFO, ha,
4133 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004134 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004135 }
4136}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004137
4138int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004140{
4141 int rval = QLA_SUCCESS;
4142 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004143 struct qla_hw_data *ha = vha->hw;
4144 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004145 struct req_que *req = ha->req_q_map[0];
4146 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004147
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004149 return -EINVAL;
4150
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004152 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004153 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004154 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004155 }
4156
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004157 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004158
4159 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004161 if (mb[0] != MBS_COMMAND_COMPLETE) {
4162 DEBUG15(qla_printk(KERN_INFO, ha,
4163 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4164 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4165 mb[0], mb[1], mb[2], mb[6], mb[7]));
4166 return (QLA_FUNCTION_FAILED);
4167 }
4168
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004169 atomic_set(&vha->loop_down_timer, 0);
4170 atomic_set(&vha->loop_state, LOOP_UP);
4171 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4172 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4173 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004174
4175 return rval;
4176}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004177
4178/* 84XX Support **************************************************************/
4179
4180static LIST_HEAD(qla_cs84xx_list);
4181static DEFINE_MUTEX(qla_cs84xx_mutex);
4182
4183static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004184qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004185{
4186 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004188
4189 mutex_lock(&qla_cs84xx_mutex);
4190
4191 /* Find any shared 84xx chip. */
4192 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4193 if (cs84xx->bus == ha->pdev->bus) {
4194 kref_get(&cs84xx->kref);
4195 goto done;
4196 }
4197 }
4198
4199 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4200 if (!cs84xx)
4201 goto done;
4202
4203 kref_init(&cs84xx->kref);
4204 spin_lock_init(&cs84xx->access_lock);
4205 mutex_init(&cs84xx->fw_update_mutex);
4206 cs84xx->bus = ha->pdev->bus;
4207
4208 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4209done:
4210 mutex_unlock(&qla_cs84xx_mutex);
4211 return cs84xx;
4212}
4213
4214static void
4215__qla84xx_chip_release(struct kref *kref)
4216{
4217 struct qla_chip_state_84xx *cs84xx =
4218 container_of(kref, struct qla_chip_state_84xx, kref);
4219
4220 mutex_lock(&qla_cs84xx_mutex);
4221 list_del(&cs84xx->list);
4222 mutex_unlock(&qla_cs84xx_mutex);
4223 kfree(cs84xx);
4224}
4225
4226void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004227qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004228{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004229 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004230 if (ha->cs84xx)
4231 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4232}
4233
4234static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004235qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004236{
4237 int rval;
4238 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004239 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004240
4241 mutex_lock(&ha->cs84xx->fw_update_mutex);
4242
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004243 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004244
4245 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4246
4247 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4248 QLA_SUCCESS;
4249}