blob: 6038aedc123939292d9b8b7c668d932cf112b858 [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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700259{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700260 uint16_t w;
Andrew Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700263 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700282
Andrew Vasquez737faec2008-10-24 15:13:45 -0700283 pci_disable_rom(ha->pdev);
Andrew Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700514{
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700515 int hw_evt = 0;
Andrew Vasquez01071092005-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 Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700521
Andrew Vasquez01071092005-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 Vasquez01071092005-07-06 10:31:37 -0700549 d2 = RD_REG_DWORD(&reg->ctrl_status);
550 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
551 udelay(5);
552 d2 = RD_REG_DWORD(&reg->ctrl_status);
553 barrier();
554 }
555
556 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
557 RD_REG_DWORD(&reg->hccr);
558
559 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
560 RD_REG_DWORD(&reg->hccr);
561
562 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
563 RD_REG_DWORD(&reg->hccr);
564
565 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
566 for (cnt = 6000000 ; cnt && d2; cnt--) {
567 udelay(5);
568 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
569 barrier();
570 }
571
572 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800573
574 if (IS_NOPOLLING_TYPE(ha))
575 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700576}
577
578/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700579 * qla24xx_reset_chip() - Reset ISP24xx chip.
580 * @ha: HA context
581 *
582 * Returns 0 on success.
583 */
584void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700586{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700588 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700589
590 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800591 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700592}
593
594/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 * qla2x00_chip_diag() - Test chip for proper operation.
596 * @ha: HA context
597 *
598 * Returns 0 on success.
599 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700600int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800601qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602{
603 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800604 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700605 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 unsigned long flags = 0;
607 uint16_t data;
608 uint32_t cnt;
609 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800610 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
612 /* Assume a failed state */
613 rval = QLA_FUNCTION_FAILED;
614
615 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800616 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617
618 spin_lock_irqsave(&ha->hardware_lock, flags);
619
620 /* Reset ISP chip. */
621 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
622
623 /*
624 * We need to have a delay here since the card will not respond while
625 * in reset causing an MCA on some architectures.
626 */
627 udelay(20);
628 data = qla2x00_debounce_register(&reg->ctrl_status);
629 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
630 udelay(5);
631 data = RD_REG_WORD(&reg->ctrl_status);
632 barrier();
633 }
634
635 if (!cnt)
636 goto chip_diag_failed;
637
638 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
639 ha->host_no));
640
641 /* Reset RISC processor. */
642 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
643 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
644
645 /* Workaround for QLA2312 PCI parity error */
646 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
647 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
648 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
649 udelay(5);
650 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700651 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653 } else
654 udelay(10);
655
656 if (!cnt)
657 goto chip_diag_failed;
658
659 /* Check product ID of chip */
660 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
661
662 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
663 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
664 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
665 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
666 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
667 mb[3] != PROD_ID_3) {
668 qla_printk(KERN_WARNING, ha,
669 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
670
671 goto chip_diag_failed;
672 }
673 ha->product_id[0] = mb[1];
674 ha->product_id[1] = mb[2];
675 ha->product_id[2] = mb[3];
676 ha->product_id[3] = mb[4];
677
678 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800679 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
681 else
682 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800683 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684
685 if (IS_QLA2200(ha) &&
686 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
687 /* Limit firmware transfer size with a 2200A */
688 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800691 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 ha->fw_transfer_size = 128;
693 }
694
695 /* Wrap Incoming Mailboxes Test. */
696 spin_unlock_irqrestore(&ha->hardware_lock, flags);
697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800698 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
699 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 if (rval) {
701 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800702 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 qla_printk(KERN_WARNING, ha,
704 "Failed mailbox send register test\n");
705 }
706 else {
707 /* Flag a successful rval */
708 rval = QLA_SUCCESS;
709 }
710 spin_lock_irqsave(&ha->hardware_lock, flags);
711
712chip_diag_failed:
713 if (rval)
714 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800715 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700716
717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
718
719 return (rval);
720}
721
722/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700723 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
724 * @ha: HA context
725 *
726 * Returns 0 on success.
727 */
728int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800729qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700730{
731 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800732 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800733 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -0700734
Andrew Vasquez88c26662005-07-08 17:59:26 -0700735 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800736 qla24xx_reset_risc(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700737
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800738 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez01071092005-07-06 10:31:37 -0700739
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800740 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700741 if (rval) {
742 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800743 vha->host_no));
Andrew Vasquez01071092005-07-06 10:31:37 -0700744 qla_printk(KERN_WARNING, ha,
745 "Failed mailbox send register test\n");
746 } else {
747 /* Flag a successful rval */
748 rval = QLA_SUCCESS;
749 }
750
751 return rval;
752}
753
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700754void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800755qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700756{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700757 int rval;
758 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800759 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800760 dma_addr_t tc_dma;
761 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800762 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800763 struct req_que *req = ha->req_q_map[0];
764 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700765
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700766 if (ha->fw_dump) {
767 qla_printk(KERN_WARNING, ha,
768 "Firmware dump previously allocated.\n");
769 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700770 }
771
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700772 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800773 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700774 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
775 fixed_size = sizeof(struct qla2100_fw_dump);
776 } else if (IS_QLA23XX(ha)) {
777 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
778 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
779 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700780 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700781 fixed_size = IS_QLA25XX(ha) ?
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800782 offsetof(struct qla25xx_fw_dump, ext_mem) :
783 offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700784 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
785 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800786 if (ha->mqenable)
787 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700788
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700789 /* Allocate memory for Fibre Channel Event Buffer. */
790 if (!IS_QLA25XX(ha))
791 goto try_eft;
792
793 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
794 GFP_KERNEL);
795 if (!tc) {
796 qla_printk(KERN_WARNING, ha, "Unable to allocate "
797 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800798 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700799 }
800
801 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700803 ha->fce_mb, &ha->fce_bufs);
804 if (rval) {
805 qla_printk(KERN_WARNING, ha, "Unable to initialize "
806 "FCE (%d).\n", rval);
807 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
808 tc_dma);
809 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800810 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700811 }
812
813 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
814 FCE_SIZE / 1024);
815
816 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
817 ha->flags.fce_enabled = 1;
818 ha->fce_dma = tc_dma;
819 ha->fce = tc;
820try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700821 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800822 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700823 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800824 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700825 qla_printk(KERN_WARNING, ha, "Unable to allocate "
826 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
827 goto cont_alloc;
828 }
829
Andrew Vasquezfc447652008-01-17 09:02:18 -0800830 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700832 if (rval) {
833 qla_printk(KERN_WARNING, ha, "Unable to initialize "
834 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800835 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
836 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700837 goto cont_alloc;
838 }
839
840 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
841 EFT_SIZE / 1024);
842
843 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800844 ha->eft_dma = tc_dma;
845 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700846 }
847cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800848 req_q_size = req->length * sizeof(request_t);
849 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700850
851 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
852 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800853 eft_size;
854 ha->chain_offset = dump_size;
855 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700856
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700857 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700858 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -0700859 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700860 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700861
862 if (ha->eft) {
863 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
864 ha->eft_dma);
865 ha->eft = NULL;
866 ha->eft_dma = 0;
867 }
868 return;
869 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700870 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
871 dump_size / 1024);
872
873 ha->fw_dump_len = dump_size;
874 ha->fw_dump->signature[0] = 'Q';
875 ha->fw_dump->signature[1] = 'L';
876 ha->fw_dump->signature[2] = 'G';
877 ha->fw_dump->signature[3] = 'C';
878 ha->fw_dump->version = __constant_htonl(1);
879
880 ha->fw_dump->fixed_size = htonl(fixed_size);
881 ha->fw_dump->mem_size = htonl(mem_size);
882 ha->fw_dump->req_q_size = htonl(req_q_size);
883 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
884
885 ha->fw_dump->eft_size = htonl(eft_size);
886 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
887 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
888
889 ha->fw_dump->header_size =
890 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -0700891}
892
893/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
895 * @ha: HA context
896 *
897 * Returns 0 on success.
898 */
899static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800900qla2x00_resize_request_q(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901{
902 int rval;
903 uint16_t fw_iocb_cnt = 0;
904 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
905 dma_addr_t request_dma;
906 request_t *request_ring;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800907 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800908 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909
910 /* Valid only on recent ISPs. */
911 if (IS_QLA2100(ha) || IS_QLA2200(ha))
912 return;
913
914 /* Retrieve IOCB counts available to the firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800915 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
916 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700917 if (rval)
918 return;
919 /* No point in continuing if current settings are sufficient. */
920 if (fw_iocb_cnt < 1024)
921 return;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 if (req->length >= request_q_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 return;
924
925 /* Attempt to claim larger area for request queue. */
926 request_ring = dma_alloc_coherent(&ha->pdev->dev,
927 (request_q_length + 1) * sizeof(request_t), &request_dma,
928 GFP_KERNEL);
929 if (request_ring == NULL)
930 return;
931
932 /* Resize successful, report extensions. */
933 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
934 (ha->fw_memory_size + 1) / 1024);
935 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800936 "(%d -> %d)...\n", req->length, request_q_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
938 /* Clear old allocations. */
939 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 (req->length + 1) * sizeof(request_t), req->ring,
941 req->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700942
943 /* Begin using larger queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800944 req->length = request_q_length;
945 req->ring = request_ring;
946 req->dma = request_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
949/**
950 * qla2x00_setup_chip() - Load and start RISC firmware.
951 * @ha: HA context
952 *
953 * Returns 0 on success.
954 */
955static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800956qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957{
Andrew Vasquez01071092005-07-06 10:31:37 -0700958 int rval;
959 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800960 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800961 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
962 unsigned long flags;
963
964 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
965 /* Disable SRAM, Instruction RAM and GP RAM parity. */
966 spin_lock_irqsave(&ha->hardware_lock, flags);
967 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
968 RD_REG_WORD(&reg->hccr);
969 spin_unlock_irqrestore(&ha->hardware_lock, flags);
970 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700971
972 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800973 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -0700974 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800978 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979 if (rval == QLA_SUCCESS) {
980 /* Start firmware execution. */
981 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800984 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 /* Retrieve firmware information. */
986 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800987 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988 &ha->fw_major_version,
989 &ha->fw_minor_version,
990 &ha->fw_subminor_version,
991 &ha->fw_attributes, &ha->fw_memory_size);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700992 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800993 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700994 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700995 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700996 if ((!ha->max_npiv_vports) ||
997 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800998 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700999 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001000 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -07001001 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001002 qla2x00_resize_request_q(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07001003
1004 if (ql2xallocfwdump)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001005 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006 }
1007 } else {
1008 DEBUG2(printk(KERN_INFO
1009 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001010 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011 }
1012 }
1013
Andrew Vasquez3db06522008-01-31 12:33:49 -08001014 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1015 /* Enable proper parity. */
1016 spin_lock_irqsave(&ha->hardware_lock, flags);
1017 if (IS_QLA2300(ha))
1018 /* SRAM parity */
1019 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1020 else
1021 /* SRAM, Instruction RAM and GP RAM parity */
1022 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1023 RD_REG_WORD(&reg->hccr);
1024 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1025 }
1026
Linus Torvalds1da177e2005-04-16 15:20:36 -07001027 if (rval) {
1028 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001029 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031
1032 return (rval);
1033}
1034
1035/**
1036 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1037 * @ha: HA context
1038 *
1039 * Beginning of request ring has initialization control block already built
1040 * by nvram config routine.
1041 *
1042 * Returns 0 on success.
1043 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001044void
1045qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046{
1047 uint16_t cnt;
1048 response_t *pkt;
1049
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001050 pkt = rsp->ring_ptr;
1051 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001052 pkt->signature = RESPONSE_PROCESSED;
1053 pkt++;
1054 }
1055
1056}
1057
1058/**
1059 * qla2x00_update_fw_options() - Read and process firmware options.
1060 * @ha: HA context
1061 *
1062 * Returns 0 on success.
1063 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001064void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001065qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001066{
1067 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001068 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069
1070 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001071 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072
1073 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1074 return;
1075
1076 /* Serial Link options. */
1077 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001078 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1080 sizeof(ha->fw_seriallink_options)));
1081
1082 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1083 if (ha->fw_seriallink_options[3] & BIT_2) {
1084 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1085
1086 /* 1G settings */
1087 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1088 emphasis = (ha->fw_seriallink_options[2] &
1089 (BIT_4 | BIT_3)) >> 3;
1090 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001091 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001092 rx_sens = (ha->fw_seriallink_options[0] &
1093 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1094 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1095 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1096 if (rx_sens == 0x0)
1097 rx_sens = 0x3;
1098 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1099 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1100 ha->fw_options[10] |= BIT_5 |
1101 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1102 (tx_sens & (BIT_1 | BIT_0));
1103
1104 /* 2G settings */
1105 swing = (ha->fw_seriallink_options[2] &
1106 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1107 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1108 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001109 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110 rx_sens = (ha->fw_seriallink_options[1] &
1111 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1112 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1113 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1114 if (rx_sens == 0x0)
1115 rx_sens = 0x3;
1116 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1117 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1118 ha->fw_options[11] |= BIT_5 |
1119 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1120 (tx_sens & (BIT_1 | BIT_0));
1121 }
1122
1123 /* FCP2 options. */
1124 /* Return command IOCBs without waiting for an ABTS to complete. */
1125 ha->fw_options[3] |= BIT_13;
1126
1127 /* LED scheme. */
1128 if (ha->flags.enable_led_scheme)
1129 ha->fw_options[2] |= BIT_12;
1130
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001131 /* Detect ISP6312. */
1132 if (IS_QLA6312(ha))
1133 ha->fw_options[2] |= BIT_13;
1134
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001136 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137}
1138
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001139void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001140qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001141{
1142 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001143 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001144
1145 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001146 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez01071092005-07-06 10:31:37 -07001147 return;
1148
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001149 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001150 le16_to_cpu(ha->fw_seriallink_options24[1]),
1151 le16_to_cpu(ha->fw_seriallink_options24[2]),
1152 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez01071092005-07-06 10:31:37 -07001153 if (rval != QLA_SUCCESS) {
1154 qla_printk(KERN_WARNING, ha,
1155 "Unable to update Serial Link options (%x).\n", rval);
1156 }
1157}
1158
1159void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001160qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001161{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001162 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001163 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001164 struct req_que *req = ha->req_q_map[0];
1165 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001166
1167 /* Setup ring parameters in initialization control block. */
1168 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1169 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001170 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1171 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1172 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1173 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1174 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1175 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001176
1177 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1178 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1179 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1180 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1181 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1182}
1183
Andrew Vasquez01071092005-07-06 10:31:37 -07001184void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001185qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001186{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001187 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001188 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1189 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1190 struct qla_msix_entry *msix;
Andrew Vasquez01071092005-07-06 10:31:37 -07001191 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001192 uint16_t rid = 0;
1193 struct req_que *req = ha->req_q_map[0];
1194 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07001195
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001196/* Setup ring parameters in initialization control block. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001197 icb = (struct init_cb_24xx *)ha->init_cb;
1198 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1199 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001200 icb->request_q_length = cpu_to_le16(req->length);
1201 icb->response_q_length = cpu_to_le16(rsp->length);
1202 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1203 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1204 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1205 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez01071092005-07-06 10:31:37 -07001206
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001207 if (ha->mqenable) {
1208 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1209 icb->rid = __constant_cpu_to_le16(rid);
1210 if (ha->flags.msix_enabled) {
1211 msix = &ha->msix_entries[1];
1212 DEBUG2_17(printk(KERN_INFO
1213 "Reistering vector 0x%x for base que\n", msix->entry));
1214 icb->msix = cpu_to_le16(msix->entry);
1215 }
1216 /* Use alternate PCI bus number */
1217 if (MSB(rid))
1218 icb->firmware_options_2 |=
1219 __constant_cpu_to_le32(BIT_19);
1220 /* Use alternate PCI devfn */
1221 if (LSB(rid))
1222 icb->firmware_options_2 |=
1223 __constant_cpu_to_le32(BIT_18);
1224
1225 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_22);
1226 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
1227 ha->rsp_q_map[0]->options = icb->firmware_options_2;
1228
1229 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1230 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1231 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1232 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1233 } else {
1234 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1235 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1236 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1237 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1238 }
1239 /* PCI posting */
1240 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez01071092005-07-06 10:31:37 -07001241}
1242
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243/**
1244 * qla2x00_init_rings() - Initializes firmware.
1245 * @ha: HA context
1246 *
1247 * Beginning of request ring has initialization control block already built
1248 * by nvram config routine.
1249 *
1250 * Returns 0 on success.
1251 */
1252static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001253qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254{
1255 int rval;
1256 unsigned long flags = 0;
1257 int cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001258 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001259 struct req_que *req = ha->req_q_map[0];
1260 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001261 struct mid_init_cb_24xx *mid_init_cb =
1262 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263
1264 spin_lock_irqsave(&ha->hardware_lock, flags);
1265
1266 /* Clear outstanding commands array. */
1267 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001268 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001270 req->current_outstanding_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001271
1272 /* Clear RSCN queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001273 vha->rscn_in_ptr = 0;
1274 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001275
1276 /* Initialize firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001277 req->ring_ptr = req->ring;
1278 req->ring_index = 0;
1279 req->cnt = req->length;
1280 rsp->ring_ptr = rsp->ring;
1281 rsp->ring_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001282
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 /* Initialize response queue entries */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001284 qla2x00_init_response_q_entries(rsp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001286 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
1288 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1289
1290 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001291 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001292
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001293 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001294
Seokmann Juc48339d2008-01-17 09:02:19 -08001295 if (ha->flags.npiv_supported)
1296 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1297
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001298 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001299
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001300 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001301 if (rval) {
1302 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001303 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304 } else {
1305 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001306 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 }
1308
1309 return (rval);
1310}
1311
1312/**
1313 * qla2x00_fw_ready() - Waits for firmware ready.
1314 * @ha: HA context
1315 *
1316 * Returns 0 on success.
1317 */
1318static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001319qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001320{
1321 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001322 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323 uint16_t min_wait; /* Minimum wait time if loop is down */
1324 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001325 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001326 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001327
1328 rval = QLA_SUCCESS;
1329
1330 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001331 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001332
1333 /*
1334 * Firmware should take at most one RATOV to login, plus 5 seconds for
1335 * our own processing.
1336 */
1337 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1338 wait_time = min_wait;
1339 }
1340
1341 /* Min wait time if loop down */
1342 mtime = jiffies + (min_wait * HZ);
1343
1344 /* wait time before firmware ready */
1345 wtime = jiffies + (wait_time * HZ);
1346
1347 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001348 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1350
1351 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001353
1354 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001355 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001357 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001358 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001360 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1361 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001363 state[2]));
1364 if ((state[2] & FSTATE_LOGGED_IN) &&
1365 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1366 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001367 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001368
1369 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001370 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001371 if (rval != QLA_SUCCESS)
1372 break;
1373
1374 /* Add time taken to initialize. */
1375 cs84xx_time = jiffies - cs84xx_time;
1376 wtime += cs84xx_time;
1377 mtime += cs84xx_time;
1378 DEBUG16(printk("scsi(%ld): Increasing "
1379 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001380 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001381 }
1382 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001383 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001384 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 &ha->login_timeout, &ha->r_a_tov);
1388
1389 rval = QLA_SUCCESS;
1390 break;
1391 }
1392
1393 rval = QLA_FUNCTION_FAILED;
1394
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001395 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001396 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001397 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001398 * other than Wait for Login.
1399 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001400 if (time_after_eq(jiffies, mtime)) {
1401 qla_printk(KERN_INFO, ha,
1402 "Cable is unplugged...\n");
1403
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001404 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405 break;
1406 }
1407 }
1408 } else {
1409 /* Mailbox cmd failed. Timeout on min_wait. */
1410 if (time_after_eq(jiffies, mtime))
1411 break;
1412 }
1413
1414 if (time_after_eq(jiffies, wtime))
1415 break;
1416
1417 /* Delay for a while */
1418 msleep(500);
1419
1420 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001421 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 } while (1);
1423
1424 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001425 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426
1427 if (rval) {
1428 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001429 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001430 }
1431
1432 return (rval);
1433}
1434
1435/*
1436* qla2x00_configure_hba
1437* Setup adapter context.
1438*
1439* Input:
1440* ha = adapter state pointer.
1441*
1442* Returns:
1443* 0 = success
1444*
1445* Context:
1446* Kernel context.
1447*/
1448static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001449qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450{
1451 int rval;
1452 uint16_t loop_id;
1453 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001454 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001455 uint8_t al_pa;
1456 uint8_t area;
1457 uint8_t domain;
1458 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001459 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460
1461 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001462 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001463 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001465 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001466 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1467 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001468 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001469 } else {
1470 qla_printk(KERN_WARNING, ha,
1471 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001472 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001473 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001474 return (rval);
1475 }
1476
1477 if (topo == 4) {
1478 qla_printk(KERN_INFO, ha,
1479 "Cannot get topology - retrying.\n");
1480 return (QLA_FUNCTION_FAILED);
1481 }
1482
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484
1485 /* initialize */
1486 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1487 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001488 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001489
1490 switch (topo) {
1491 case 0:
1492 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001493 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001494 ha->current_topology = ISP_CFG_NL;
1495 strcpy(connect_type, "(Loop)");
1496 break;
1497
1498 case 1:
1499 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001500 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001501 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001502 ha->current_topology = ISP_CFG_FL;
1503 strcpy(connect_type, "(FL_Port)");
1504 break;
1505
1506 case 2:
1507 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001508 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 ha->operating_mode = P2P;
1510 ha->current_topology = ISP_CFG_N;
1511 strcpy(connect_type, "(N_Port-to-N_Port)");
1512 break;
1513
1514 case 3:
1515 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001517 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518 ha->operating_mode = P2P;
1519 ha->current_topology = ISP_CFG_F;
1520 strcpy(connect_type, "(F_Port)");
1521 break;
1522
1523 default:
1524 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1525 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 ha->current_topology = ISP_CFG_NL;
1528 strcpy(connect_type, "(Loop)");
1529 break;
1530 }
1531
1532 /* Save Host port and loop ID. */
1533 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001534 vha->d_id.b.domain = domain;
1535 vha->d_id.b.area = area;
1536 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001538 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539 qla_printk(KERN_INFO, ha,
1540 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001541 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542
1543 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001544 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001545 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001546 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001547 }
1548
1549 return(rval);
1550}
1551
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001552static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001553qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1554 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001555{
1556 char *st, *en;
1557 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001558 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001559
1560 if (memcmp(model, BINZERO, len) != 0) {
1561 strncpy(ha->model_number, model, len);
1562 st = en = ha->model_number;
1563 en += len - 1;
1564 while (en > st) {
1565 if (*en != 0x20 && *en != 0x00)
1566 break;
1567 *en-- = '\0';
1568 }
1569
1570 index = (ha->pdev->subsystem_device & 0xff);
1571 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1572 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001573 strncpy(ha->model_desc,
1574 qla2x00_model_name[index * 2 + 1],
1575 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001576 } else {
1577 index = (ha->pdev->subsystem_device & 0xff);
1578 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1579 index < QLA_MODEL_NAMES) {
1580 strcpy(ha->model_number,
1581 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001582 strncpy(ha->model_desc,
1583 qla2x00_model_name[index * 2 + 1],
1584 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001585 } else {
1586 strcpy(ha->model_number, def);
1587 }
1588 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001589 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001590 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001591 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001592}
1593
David Miller4e08df32007-04-16 12:37:43 -07001594/* On sparc systems, obtain port and node WWN from firmware
1595 * properties.
1596 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001597static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001598{
1599#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001600 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001601 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001602 struct device_node *dp = pci_device_to_OF_node(pdev);
1603 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001604 int len;
1605
1606 val = of_get_property(dp, "port-wwn", &len);
1607 if (val && len >= WWN_SIZE)
1608 memcpy(nv->port_name, val, WWN_SIZE);
1609
1610 val = of_get_property(dp, "node-wwn", &len);
1611 if (val && len >= WWN_SIZE)
1612 memcpy(nv->node_name, val, WWN_SIZE);
1613#endif
1614}
1615
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616/*
1617* NVRAM configuration for ISP 2xxx
1618*
1619* Input:
1620* ha = adapter block pointer.
1621*
1622* Output:
1623* initialization control block in response_ring
1624* host adapters parameters in host adapter block
1625*
1626* Returns:
1627* 0 = success.
1628*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001629int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001630qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631{
David Miller4e08df32007-04-16 12:37:43 -07001632 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07001633 uint8_t chksum = 0;
1634 uint16_t cnt;
1635 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001636 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001637 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001638 nvram_t *nv = ha->nvram;
1639 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001640 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
David Miller4e08df32007-04-16 12:37:43 -07001642 rval = QLA_SUCCESS;
1643
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001645 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001646 ha->nvram_base = 0;
1647 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1648 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1649 ha->nvram_base = 0x80;
1650
1651 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001652 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07001653 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1654 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001655
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001656 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001657 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658
1659 /* Bad NVRAM data, set defaults parameters. */
1660 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1661 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1662 /* Reset NVRAM data. */
1663 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1664 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1665 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001666 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1667 "invalid -- WWPN) defaults.\n");
1668
1669 /*
1670 * Set default initialization control block.
1671 */
1672 memset(nv, 0, ha->nvram_size);
1673 nv->parameter_block_version = ICB_VERSION;
1674
1675 if (IS_QLA23XX(ha)) {
1676 nv->firmware_options[0] = BIT_2 | BIT_1;
1677 nv->firmware_options[1] = BIT_7 | BIT_5;
1678 nv->add_firmware_options[0] = BIT_5;
1679 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1680 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1681 nv->special_options[1] = BIT_7;
1682 } else if (IS_QLA2200(ha)) {
1683 nv->firmware_options[0] = BIT_2 | BIT_1;
1684 nv->firmware_options[1] = BIT_7 | BIT_5;
1685 nv->add_firmware_options[0] = BIT_5;
1686 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1687 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1688 } else if (IS_QLA2100(ha)) {
1689 nv->firmware_options[0] = BIT_3 | BIT_1;
1690 nv->firmware_options[1] = BIT_5;
1691 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1692 }
1693
1694 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1695 nv->execution_throttle = __constant_cpu_to_le16(16);
1696 nv->retry_count = 8;
1697 nv->retry_delay = 1;
1698
1699 nv->port_name[0] = 33;
1700 nv->port_name[3] = 224;
1701 nv->port_name[4] = 139;
1702
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001703 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001704
1705 nv->login_timeout = 4;
1706
1707 /*
1708 * Set default host adapter parameters
1709 */
1710 nv->host_p[1] = BIT_2;
1711 nv->reset_delay = 5;
1712 nv->port_down_retry_count = 8;
1713 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1714 nv->link_down_timeout = 60;
1715
1716 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717 }
1718
1719#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1720 /*
1721 * The SN2 does not provide BIOS emulation which means you can't change
1722 * potentially bogus BIOS settings. Force the use of default settings
1723 * for link rate and frame size. Hope that the rest of the settings
1724 * are valid.
1725 */
1726 if (ia64_platform_is("sn2")) {
1727 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1728 if (IS_QLA23XX(ha))
1729 nv->special_options[1] = BIT_7;
1730 }
1731#endif
1732
1733 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07001734 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735
1736 /*
1737 * Setup driver NVRAM options.
1738 */
1739 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1740 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1741 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1742 nv->firmware_options[1] &= ~BIT_4;
1743
1744 if (IS_QLA23XX(ha)) {
1745 nv->firmware_options[0] |= BIT_2;
1746 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez01071092005-07-06 10:31:37 -07001747 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748
1749 if (IS_QLA2300(ha)) {
1750 if (ha->fb_rev == FPM_2310) {
1751 strcpy(ha->model_number, "QLA2310");
1752 } else {
1753 strcpy(ha->model_number, "QLA2300");
1754 }
1755 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001756 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001757 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 }
1759 } else if (IS_QLA2200(ha)) {
1760 nv->firmware_options[0] |= BIT_2;
1761 /*
1762 * 'Point-to-point preferred, else loop' is not a safe
1763 * connection mode setting.
1764 */
1765 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1766 (BIT_5 | BIT_4)) {
1767 /* Force 'loop preferred, else point-to-point'. */
1768 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1769 nv->add_firmware_options[0] |= BIT_5;
1770 }
1771 strcpy(ha->model_number, "QLA22xx");
1772 } else /*if (IS_QLA2100(ha))*/ {
1773 strcpy(ha->model_number, "QLA2100");
1774 }
1775
1776 /*
1777 * Copy over NVRAM RISC parameter block to initialization control block.
1778 */
1779 dptr1 = (uint8_t *)icb;
1780 dptr2 = (uint8_t *)&nv->parameter_block_version;
1781 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1782 while (cnt--)
1783 *dptr1++ = *dptr2++;
1784
1785 /* Copy 2nd half. */
1786 dptr1 = (uint8_t *)icb->add_firmware_options;
1787 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1788 while (cnt--)
1789 *dptr1++ = *dptr2++;
1790
Andrew Vasquez5341e862006-05-17 15:09:16 -07001791 /* Use alternate WWN? */
1792 if (nv->host_p[1] & BIT_7) {
1793 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1794 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1795 }
1796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 /* Prepare nodename */
1798 if ((icb->firmware_options[1] & BIT_6) == 0) {
1799 /*
1800 * Firmware will apply the following mask if the nodename was
1801 * not provided.
1802 */
1803 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1804 icb->node_name[0] &= 0xF0;
1805 }
1806
1807 /*
1808 * Set host adapter parameters.
1809 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001810 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001811 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1813 /* Always load RISC code on non ISP2[12]00 chips. */
1814 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1815 ha->flags.disable_risc_code_load = 0;
1816 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1817 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1818 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001819 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001820 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001821
1822 ha->operating_mode =
1823 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1824
1825 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1826 sizeof(ha->fw_seriallink_options));
1827
1828 /* save HBA serial number */
1829 ha->serial0 = icb->port_name[5];
1830 ha->serial1 = icb->port_name[6];
1831 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001832 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1833 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834
1835 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1836
1837 ha->retry_count = nv->retry_count;
1838
1839 /* Set minimum login_timeout to 4 seconds. */
1840 if (nv->login_timeout < ql2xlogintimeout)
1841 nv->login_timeout = ql2xlogintimeout;
1842 if (nv->login_timeout < 4)
1843 nv->login_timeout = 4;
1844 ha->login_timeout = nv->login_timeout;
1845 icb->login_timeout = nv->login_timeout;
1846
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001847 /* Set minimum RATOV to 100 tenths of a second. */
1848 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849
Linus Torvalds1da177e2005-04-16 15:20:36 -07001850 ha->loop_reset_delay = nv->reset_delay;
1851
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852 /* Link Down Timeout = 0:
1853 *
1854 * When Port Down timer expires we will start returning
1855 * I/O's to OS with "DID_NO_CONNECT".
1856 *
1857 * Link Down Timeout != 0:
1858 *
1859 * The driver waits for the link to come up after link down
1860 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001861 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862 if (nv->link_down_timeout == 0) {
1863 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001864 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 } else {
1866 ha->link_down_timeout = nv->link_down_timeout;
1867 ha->loop_down_abort_time =
1868 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001869 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001870
Linus Torvalds1da177e2005-04-16 15:20:36 -07001871 /*
1872 * Need enough time to try and get the port back.
1873 */
1874 ha->port_down_retry_count = nv->port_down_retry_count;
1875 if (qlport_down_retry)
1876 ha->port_down_retry_count = qlport_down_retry;
1877 /* Set login_retry_count */
1878 ha->login_retry_count = nv->retry_count;
1879 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1880 ha->port_down_retry_count > 3)
1881 ha->login_retry_count = ha->port_down_retry_count;
1882 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1883 ha->login_retry_count = ha->port_down_retry_count;
1884 if (ql2xloginretrycount)
1885 ha->login_retry_count = ql2xloginretrycount;
1886
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 icb->lun_enables = __constant_cpu_to_le16(0);
1888 icb->command_resource_count = 0;
1889 icb->immediate_notify_resource_count = 0;
1890 icb->timeout = __constant_cpu_to_le16(0);
1891
1892 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1893 /* Enable RIO */
1894 icb->firmware_options[0] &= ~BIT_3;
1895 icb->add_firmware_options[0] &=
1896 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1897 icb->add_firmware_options[0] |= BIT_2;
1898 icb->response_accumulation_timer = 3;
1899 icb->interrupt_delay_timer = 5;
1900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001901 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001902 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001903 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001904 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001905 ha->zio_mode = icb->add_firmware_options[0] &
1906 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1907 ha->zio_timer = icb->interrupt_delay_timer ?
1908 icb->interrupt_delay_timer: 2;
1909 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 icb->add_firmware_options[0] &=
1911 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001912 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001913 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001914 ha->zio_mode = QLA_ZIO_MODE_6;
1915
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001916 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001918 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001920 "ZIO mode %d enabled; timer delay (%d us).\n",
1921 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001922
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001923 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1924 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001925 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001926 }
1927 }
1928
David Miller4e08df32007-04-16 12:37:43 -07001929 if (rval) {
1930 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001932 }
1933 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934}
1935
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001936static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001937qla2x00_rport_del(void *data)
1938{
1939 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001940 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001941
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001942 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001943 rport = fcport->drport;
1944 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001945 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001946 if (rport)
1947 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001948}
1949
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950/**
1951 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1952 * @ha: HA context
1953 * @flags: allocation flags
1954 *
1955 * Returns a pointer to the allocated fcport, or NULL, if none available.
1956 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001957static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001958qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959{
1960 fc_port_t *fcport;
1961
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001962 fcport = kzalloc(sizeof(fc_port_t), flags);
1963 if (!fcport)
1964 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001965
1966 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001967 fcport->vha = vha;
1968 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001969 fcport->port_type = FCT_UNKNOWN;
1970 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1972 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001973 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001974
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001975 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976}
1977
1978/*
1979 * qla2x00_configure_loop
1980 * Updates Fibre Channel Device Database with what is actually on loop.
1981 *
1982 * Input:
1983 * ha = adapter block pointer.
1984 *
1985 * Returns:
1986 * 0 = success.
1987 * 1 = error.
1988 * 2 = database was full and device was not configured.
1989 */
1990static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001991qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992{
1993 int rval;
1994 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996 rval = QLA_SUCCESS;
1997
1998 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001999 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
2000 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002001 if (rval != QLA_SUCCESS) {
2002 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002003 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002004 return (rval);
2005 }
2006 }
2007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012 /*
2013 * If we have both an RSCN and PORT UPDATE pending then handle them
2014 * both at the same time.
2015 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2017 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018
2019 /* Determine what we need to do */
2020 if (ha->current_topology == ISP_CFG_FL &&
2021 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2022
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002023 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024 set_bit(RSCN_UPDATE, &flags);
2025
2026 } else if (ha->current_topology == ISP_CFG_F &&
2027 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2028
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002029 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 set_bit(RSCN_UPDATE, &flags);
2031 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2032
Andrew Vasquez21333b42006-05-17 15:09:56 -07002033 } else if (ha->current_topology == ISP_CFG_N) {
2034 clear_bit(RSCN_UPDATE, &flags);
2035
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002036 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2038
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 set_bit(RSCN_UPDATE, &flags);
2041 set_bit(LOCAL_LOOP_UPDATE, &flags);
2042 }
2043
2044 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002045 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002047 else
2048 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 }
2050
2051 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002054 else
2055 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002056 }
2057
2058 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002059 if (atomic_read(&vha->loop_down_timer) ||
2060 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002061 rval = QLA_FUNCTION_FAILED;
2062 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002063 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002066 }
2067 }
2068
2069 if (rval) {
2070 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002071 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002072 } else {
2073 DEBUG3(printk("%s: exiting normally\n", __func__));
2074 }
2075
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002076 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002077 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002078 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002079 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002080 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002081 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082 }
2083
2084 return (rval);
2085}
2086
2087
2088
2089/*
2090 * qla2x00_configure_local_loop
2091 * Updates Fibre Channel Device Database with local loop devices.
2092 *
2093 * Input:
2094 * ha = adapter block pointer.
2095 *
2096 * Returns:
2097 * 0 = success.
2098 */
2099static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101{
2102 int rval, rval2;
2103 int found_devs;
2104 int found;
2105 fc_port_t *fcport, *new_fcport;
2106
2107 uint16_t index;
2108 uint16_t entries;
2109 char *id_iter;
2110 uint16_t loop_id;
2111 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002112 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
2114 found_devs = 0;
2115 new_fcport = NULL;
2116 entries = MAX_FIBRE_DEVICES;
2117
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002118 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2119 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120
2121 /* Get list of logged in devices. */
2122 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002123 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002124 &entries);
2125 if (rval != QLA_SUCCESS)
2126 goto cleanup_allocation;
2127
2128 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2129 ha->host_no, entries));
2130 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2131 entries * sizeof(struct gid_list_info)));
2132
2133 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002134 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 if (new_fcport == NULL) {
2136 rval = QLA_MEMORY_ALLOC_FAILED;
2137 goto cleanup_allocation;
2138 }
2139 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2140
2141 /*
2142 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2143 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002144 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2146 fcport->port_type != FCT_BROADCAST &&
2147 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2148
2149 DEBUG(printk("scsi(%ld): Marking port lost, "
2150 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002151 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002152
2153 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2154 fcport->flags &= ~FCF_FARP_DONE;
2155 }
2156 }
2157
2158 /* Add devices to port list. */
2159 id_iter = (char *)ha->gid_list;
2160 for (index = 0; index < entries; index++) {
2161 domain = ((struct gid_list_info *)id_iter)->domain;
2162 area = ((struct gid_list_info *)id_iter)->area;
2163 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002164 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 loop_id = (uint16_t)
2166 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002167 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002168 loop_id = le16_to_cpu(
2169 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002170 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171
2172 /* Bypass reserved domain fields. */
2173 if ((domain & 0xf0) == 0xf0)
2174 continue;
2175
2176 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002177 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002178 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002179 continue;
2180
2181 /* Bypass invalid local loop ID. */
2182 if (loop_id > LAST_LOCAL_LOOP_ID)
2183 continue;
2184
2185 /* Fill in member data. */
2186 new_fcport->d_id.b.domain = domain;
2187 new_fcport->d_id.b.area = area;
2188 new_fcport->d_id.b.al_pa = al_pa;
2189 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 new_fcport->vp_idx = vha->vp_idx;
2191 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 if (rval2 != QLA_SUCCESS) {
2193 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2194 "information -- get_port_database=%x, "
2195 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002196 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002197 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198 vha->host_no));
2199 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 continue;
2201 }
2202
2203 /* Check for matching device in port list. */
2204 found = 0;
2205 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002206 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002207 if (memcmp(new_fcport->port_name, fcport->port_name,
2208 WWN_SIZE))
2209 continue;
2210
2211 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2212 FCF_PERSISTENT_BOUND);
2213 fcport->loop_id = new_fcport->loop_id;
2214 fcport->port_type = new_fcport->port_type;
2215 fcport->d_id.b24 = new_fcport->d_id.b24;
2216 memcpy(fcport->node_name, new_fcport->node_name,
2217 WWN_SIZE);
2218
2219 found++;
2220 break;
2221 }
2222
2223 if (!found) {
2224 /* New device, add to fcports list. */
2225 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002226 if (vha->vp_idx) {
2227 new_fcport->vha = vha;
2228 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002229 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002230 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002231
2232 /* Allocate a new replacement fcport. */
2233 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002234 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002235 if (new_fcport == NULL) {
2236 rval = QLA_MEMORY_ALLOC_FAILED;
2237 goto cleanup_allocation;
2238 }
2239 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2240 }
2241
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002242 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002243 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002244
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002245 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002246
2247 found_devs++;
2248 }
2249
2250cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002251 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002252
2253 if (rval != QLA_SUCCESS) {
2254 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002255 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002256 }
2257
2258 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002259 vha->device_flags |= DFLG_LOCAL_DEVICES;
2260 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261 }
2262
2263 return (rval);
2264}
2265
2266static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002268{
2269#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002270 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002271 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002272 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002274
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002275 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002276 return;
2277
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002278 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2279 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002280 return;
2281
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002283 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002284 if (rval != QLA_SUCCESS) {
2285 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2286 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002287 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002288 fcport->port_name[2], fcport->port_name[3],
2289 fcport->port_name[4], fcport->port_name[5],
2290 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002291 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002292 } else {
2293 DEBUG2(qla_printk(KERN_INFO, ha,
2294 "iIDMA adjusted to %s GB/s on "
2295 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002296 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002297 fcport->port_name[1], fcport->port_name[2],
2298 fcport->port_name[3], fcport->port_name[4],
2299 fcport->port_name[5], fcport->port_name[6],
2300 fcport->port_name[7]));
2301 }
2302}
2303
Adrian Bunk23be3312006-11-24 02:46:01 +01002304static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002305qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e112005-04-17 15:04:54 -05002306{
2307 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002308 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002309 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05002310
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002311 if (fcport->drport)
2312 qla2x00_rport_del(fcport);
8482e112005-04-17 15:04:54 -05002313
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002314 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2315 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002316 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2317 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2318 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002320 if (!rport) {
2321 qla_printk(KERN_WARNING, ha,
2322 "Unable to allocate fc remote port!\n");
2323 return;
2324 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002326 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002328
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002329 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002330
2331 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002332 if (fcport->port_type == FCT_INITIATOR)
2333 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2334 if (fcport->port_type == FCT_TARGET)
2335 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002336 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e112005-04-17 15:04:54 -05002337}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338
2339/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002340 * qla2x00_update_fcport
2341 * Updates device on list.
2342 *
2343 * Input:
2344 * ha = adapter block pointer.
2345 * fcport = port structure pointer.
2346 *
2347 * Return:
2348 * 0 - Success
2349 * BIT_0 - error
2350 *
2351 * Context:
2352 * Kernel context.
2353 */
2354void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002355qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002356{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002357 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002358
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002360 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002362 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002363 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002364 PORT_RETRY_TIME);
2365 fcport->flags &= ~FCF_LOGIN_NEEDED;
2366
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002368
2369 atomic_set(&fcport->state, FCS_ONLINE);
2370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002372}
2373
2374/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375 * qla2x00_configure_fabric
2376 * Setup SNS devices with loop ID's.
2377 *
2378 * Input:
2379 * ha = adapter block pointer.
2380 *
2381 * Returns:
2382 * 0 = success.
2383 * BIT_0 = error
2384 */
2385static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387{
2388 int rval, rval2;
2389 fc_port_t *fcport, *fcptemp;
2390 uint16_t next_loopid;
2391 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002392 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 struct qla_hw_data *ha = vha->hw;
2395 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
2397 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002398 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002399 loop_id = NPH_F_PORT;
2400 else
2401 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002403 if (rval != QLA_SUCCESS) {
2404 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002405 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002406
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002407 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 return (QLA_SUCCESS);
2409 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002410 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411
2412 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002413 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 if (rval2 == QLA_RSCNS_HANDLED) {
2415 /* No point doing the scan, just continue. */
2416 return (QLA_SUCCESS);
2417 }
2418 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002419 /* FDMI support. */
2420 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2422 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002423
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002425 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002426 loop_id = NPH_SNS;
2427 else
2428 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002429 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002430 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 if (mb[0] != MBS_COMMAND_COMPLETE) {
2432 DEBUG2(qla_printk(KERN_INFO, ha,
2433 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002434 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 mb[0], mb[1], mb[2], mb[6], mb[7]));
2436 return (QLA_SUCCESS);
2437 }
2438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002439 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2440 if (qla2x00_rft_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 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002445 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002446 /* EMPTY */
2447 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002448 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002449 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002450 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002451 /* EMPTY */
2452 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002453 "failed.\n", vha->host_no));
2454 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 /* EMPTY */
2456 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002458 }
2459 }
2460
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002461 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462 if (rval != QLA_SUCCESS)
2463 break;
2464
2465 /*
2466 * Logout all previous fabric devices marked lost, except
2467 * tape devices.
2468 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002469 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2470 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471 break;
2472
2473 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2474 continue;
2475
2476 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002477 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002478 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002479 if (fcport->loop_id != FC_NO_LOOP_ID &&
2480 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2481 fcport->port_type != FCT_INITIATOR &&
2482 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002484 fcport->loop_id,
2485 fcport->d_id.b.domain,
2486 fcport->d_id.b.area,
2487 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 fcport->loop_id = FC_NO_LOOP_ID;
2489 }
2490 }
2491 }
2492
2493 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002494 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495
2496 /*
2497 * Scan through our port list and login entries that need to be
2498 * logged in.
2499 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002500 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2501 if (atomic_read(&vha->loop_down_timer) ||
2502 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 break;
2504
2505 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2506 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2507 continue;
2508
2509 if (fcport->loop_id == FC_NO_LOOP_ID) {
2510 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002511 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002512 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002513 if (rval != QLA_SUCCESS) {
2514 /* Ran out of IDs to use */
2515 break;
2516 }
2517 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002519 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002520 }
2521
2522 /* Exit if out of loop IDs. */
2523 if (rval != QLA_SUCCESS) {
2524 break;
2525 }
2526
2527 /*
2528 * Login and add the new devices to our port list.
2529 */
2530 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002531 if (atomic_read(&vha->loop_down_timer) ||
2532 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002533 break;
2534
2535 /* Find a new loop ID to use. */
2536 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002537 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002538 if (rval != QLA_SUCCESS) {
2539 /* Ran out of IDs to use */
2540 break;
2541 }
2542
bdf79622005-04-17 15:06:53 -05002543 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002544 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002545
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002546 if (vha->vp_idx) {
2547 fcport->vha = vha;
2548 fcport->vp_idx = vha->vp_idx;
2549 }
2550 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002551 }
2552 } while (0);
2553
2554 /* Free all new device structures not processed. */
2555 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2556 list_del(&fcport->list);
2557 kfree(fcport);
2558 }
2559
2560 if (rval) {
2561 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002562 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 }
2564
2565 return (rval);
2566}
2567
2568
2569/*
2570 * qla2x00_find_all_fabric_devs
2571 *
2572 * Input:
2573 * ha = adapter block pointer.
2574 * dev = database device entry pointer.
2575 *
2576 * Returns:
2577 * 0 = success.
2578 *
2579 * Context:
2580 * Kernel context.
2581 */
2582static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2584 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585{
2586 int rval;
2587 uint16_t loop_id;
2588 fc_port_t *fcport, *new_fcport, *fcptemp;
2589 int found;
2590
2591 sw_info_t *swl;
2592 int swl_idx;
2593 int first_dev, last_dev;
2594 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 struct qla_hw_data *ha = vha->hw;
2596 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597
2598 rval = QLA_SUCCESS;
2599
2600 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002601 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002602 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002603 /*EMPTY*/
2604 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002606 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002607 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 kfree(swl);
2609 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 kfree(swl);
2612 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002614 kfree(swl);
2615 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002616 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002617 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2618 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619 }
2620 }
2621 swl_idx = 0;
2622
2623 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002626 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 return (QLA_MEMORY_ALLOC_FAILED);
2628 }
2629 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002630 /* Set start port ID scan at adapter ID. */
2631 first_dev = 1;
2632 last_dev = 0;
2633
2634 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002635 loop_id = ha->min_external_loopid;
2636 for (; loop_id <= ha->max_loop_id; loop_id++) {
2637 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 continue;
2639
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002640 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641 break;
2642
2643 if (swl != NULL) {
2644 if (last_dev) {
2645 wrap.b24 = new_fcport->d_id.b24;
2646 } else {
2647 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2648 memcpy(new_fcport->node_name,
2649 swl[swl_idx].node_name, WWN_SIZE);
2650 memcpy(new_fcport->port_name,
2651 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002652 memcpy(new_fcport->fabric_port_name,
2653 swl[swl_idx].fabric_port_name, WWN_SIZE);
2654 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655
2656 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2657 last_dev = 1;
2658 }
2659 swl_idx++;
2660 }
2661 } else {
2662 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002663 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002664 if (rval != QLA_SUCCESS) {
2665 qla_printk(KERN_WARNING, ha,
2666 "SNS scan failed -- assuming zero-entry "
2667 "result...\n");
2668 list_for_each_entry_safe(fcport, fcptemp,
2669 new_fcports, list) {
2670 list_del(&fcport->list);
2671 kfree(fcport);
2672 }
2673 rval = QLA_SUCCESS;
2674 break;
2675 }
2676 }
2677
2678 /* If wrap on switch device list, exit. */
2679 if (first_dev) {
2680 wrap.b24 = new_fcport->d_id.b24;
2681 first_dev = 0;
2682 } else if (new_fcport->d_id.b24 == wrap.b24) {
2683 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002684 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2686 break;
2687 }
2688
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002689 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002690 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002691 continue;
2692
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002693 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 found = 0;
2695 if (ha->num_vhosts) {
2696 list_for_each_entry(vp, &ha->vp_list, list) {
2697 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2698 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002699 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002700 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002701 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002702 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002703 continue;
2704 }
2705
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002706 /* Bypass if same domain and area of adapter. */
2707 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002708 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002709 ISP_CFG_FL)
2710 continue;
2711
Linus Torvalds1da177e2005-04-16 15:20:36 -07002712 /* Bypass reserved domain fields. */
2713 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2714 continue;
2715
2716 /* Locate matching device in database. */
2717 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002718 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002719 if (memcmp(new_fcport->port_name, fcport->port_name,
2720 WWN_SIZE))
2721 continue;
2722
2723 found++;
2724
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002725 /* Update port state. */
2726 memcpy(fcport->fabric_port_name,
2727 new_fcport->fabric_port_name, WWN_SIZE);
2728 fcport->fp_speed = new_fcport->fp_speed;
2729
Linus Torvalds1da177e2005-04-16 15:20:36 -07002730 /*
2731 * If address the same and state FCS_ONLINE, nothing
2732 * changed.
2733 */
2734 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2735 atomic_read(&fcport->state) == FCS_ONLINE) {
2736 break;
2737 }
2738
2739 /*
2740 * If device was not a fabric device before.
2741 */
2742 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2743 fcport->d_id.b24 = new_fcport->d_id.b24;
2744 fcport->loop_id = FC_NO_LOOP_ID;
2745 fcport->flags |= (FCF_FABRIC_DEVICE |
2746 FCF_LOGIN_NEEDED);
2747 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2748 break;
2749 }
2750
2751 /*
2752 * Port ID changed or device was marked to be updated;
2753 * Log it out if still logged in and mark it for
2754 * relogin later.
2755 */
2756 fcport->d_id.b24 = new_fcport->d_id.b24;
2757 fcport->flags |= FCF_LOGIN_NEEDED;
2758 if (fcport->loop_id != FC_NO_LOOP_ID &&
2759 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2760 fcport->port_type != FCT_INITIATOR &&
2761 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002762 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002763 fcport->d_id.b.domain, fcport->d_id.b.area,
2764 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002765 fcport->loop_id = FC_NO_LOOP_ID;
2766 }
2767
2768 break;
2769 }
2770
2771 if (found)
2772 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002773 /* If device was not in our fcports list, then add it. */
2774 list_add_tail(&new_fcport->list, new_fcports);
2775
2776 /* Allocate a new replacement fcport. */
2777 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002778 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002779 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002780 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781 return (QLA_MEMORY_ALLOC_FAILED);
2782 }
2783 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2784 new_fcport->d_id.b24 = nxt_d_id.b24;
2785 }
2786
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002787 kfree(swl);
2788 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
2790 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792
2793 return (rval);
2794}
2795
2796/*
2797 * qla2x00_find_new_loop_id
2798 * Scan through our port list and find a new usable loop ID.
2799 *
2800 * Input:
2801 * ha: adapter state pointer.
2802 * dev: port structure pointer.
2803 *
2804 * Returns:
2805 * qla2x00 local function return status code.
2806 *
2807 * Context:
2808 * Kernel context.
2809 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002810static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812{
2813 int rval;
2814 int found;
2815 fc_port_t *fcport;
2816 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002817 struct qla_hw_data *ha = vha->hw;
2818 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819
2820 rval = QLA_SUCCESS;
2821
2822 /* Save starting loop ID. */
2823 first_loop_id = dev->loop_id;
2824
2825 for (;;) {
2826 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002828 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
2830 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002831 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002832 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
2834 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836 /* first loop ID. */
2837 dev->loop_id = ha->min_external_loopid;
2838 }
2839
2840 /* Check for loop ID being already in use. */
2841 found = 0;
2842 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002843 list_for_each_entry(vp, &ha->vp_list, list) {
2844 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2845 if (fcport->loop_id == dev->loop_id &&
2846 fcport != dev) {
2847 /* ID possibly in use */
2848 found++;
2849 break;
2850 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002852 if (found)
2853 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854 }
2855
2856 /* If not in use then it is free to use. */
2857 if (!found) {
2858 break;
2859 }
2860
2861 /* ID in use. Try next value. */
2862 dev->loop_id++;
2863
2864 /* If wrap around. No free ID to use. */
2865 if (dev->loop_id == first_loop_id) {
2866 dev->loop_id = FC_NO_LOOP_ID;
2867 rval = QLA_FUNCTION_FAILED;
2868 break;
2869 }
2870 }
2871
2872 return (rval);
2873}
2874
2875/*
2876 * qla2x00_device_resync
2877 * Marks devices in the database that needs resynchronization.
2878 *
2879 * Input:
2880 * ha = adapter block pointer.
2881 *
2882 * Context:
2883 * Kernel context.
2884 */
2885static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002886qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002887{
2888 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002889 uint32_t mask;
2890 fc_port_t *fcport;
2891 uint32_t rscn_entry;
2892 uint8_t rscn_out_iter;
2893 uint8_t format;
2894 port_id_t d_id;
2895
2896 rval = QLA_RSCNS_HANDLED;
2897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002898 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2899 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 format = MSB(MSW(rscn_entry));
2903 d_id.b.domain = LSB(MSW(rscn_entry));
2904 d_id.b.area = MSB(LSW(rscn_entry));
2905 d_id.b.al_pa = LSB(LSW(rscn_entry));
2906
2907 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2908 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002909 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002910 d_id.b.area, d_id.b.al_pa));
2911
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002912 vha->rscn_out_ptr++;
2913 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2914 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915
2916 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 for (rscn_out_iter = vha->rscn_out_ptr;
2918 !vha->flags.rscn_queue_overflow &&
2919 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 rscn_out_iter = (rscn_out_iter ==
2921 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2922
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002923 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002924 break;
2925
2926 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 rscn_out_iter));
2929
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002930 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931 }
2932
2933 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002936 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002937
2938 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002940 }
2941
2942 switch (format) {
2943 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 mask = 0xffffff;
2945 break;
2946 case 1:
2947 mask = 0xffff00;
2948 break;
2949 case 2:
2950 mask = 0xff0000;
2951 break;
2952 default:
2953 mask = 0x0;
2954 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002955 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 break;
2957 }
2958
2959 rval = QLA_SUCCESS;
2960
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2963 (fcport->d_id.b24 & mask) != d_id.b24 ||
2964 fcport->port_type == FCT_BROADCAST)
2965 continue;
2966
2967 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2968 if (format != 3 ||
2969 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002970 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002971 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002972 }
2973 }
2974 fcport->flags &= ~FCF_FARP_DONE;
2975 }
2976 }
2977 return (rval);
2978}
2979
2980/*
2981 * qla2x00_fabric_dev_login
2982 * Login fabric target device and update FC port database.
2983 *
2984 * Input:
2985 * ha: adapter state pointer.
2986 * fcport: port structure list pointer.
2987 * next_loopid: contains value of a new loop ID that can be used
2988 * by the next login attempt.
2989 *
2990 * Returns:
2991 * qla2x00 local function return status code.
2992 *
2993 * Context:
2994 * Kernel context.
2995 */
2996static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002997qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 uint16_t *next_loopid)
2999{
3000 int rval;
3001 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07003002 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004
3005 rval = QLA_SUCCESS;
3006 retry = 0;
3007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003008 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 if (rval == QLA_SUCCESS) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003010 /* Send an ADISC to tape devices.*/
3011 opts = 0;
3012 if (fcport->flags & FCF_TAPE_PRESENT)
3013 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003017 fcport->d_id.b.domain, fcport->d_id.b.area,
3018 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003019 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003020 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003021 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 }
3023 }
3024
3025 return (rval);
3026}
3027
3028/*
3029 * qla2x00_fabric_login
3030 * Issue fabric login command.
3031 *
3032 * Input:
3033 * ha = adapter block pointer.
3034 * device = pointer to FC device type structure.
3035 *
3036 * Returns:
3037 * 0 - Login successfully
3038 * 1 - Login failed
3039 * 2 - Initiator device
3040 * 3 - Fatal error
3041 */
3042int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003043qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003044 uint16_t *next_loopid)
3045{
3046 int rval;
3047 int retry;
3048 uint16_t tmp_loopid;
3049 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003050 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051
3052 retry = 0;
3053 tmp_loopid = 0;
3054
3055 for (;;) {
3056 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3057 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003058 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3060
3061 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003062 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063 fcport->d_id.b.domain, fcport->d_id.b.area,
3064 fcport->d_id.b.al_pa, mb, BIT_0);
3065 if (mb[0] == MBS_PORT_ID_USED) {
3066 /*
3067 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07003068 * recommends the driver perform an implicit login with
3069 * the specified ID again. The ID we just used is save
3070 * here so we return with an ID that can be tried by
3071 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003072 */
3073 retry++;
3074 tmp_loopid = fcport->loop_id;
3075 fcport->loop_id = mb[1];
3076
3077 DEBUG(printk("Fabric Login: port in use - next "
3078 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3079 fcport->loop_id, fcport->d_id.b.domain,
3080 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3081
3082 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3083 /*
3084 * Login succeeded.
3085 */
3086 if (retry) {
3087 /* A retry occurred before. */
3088 *next_loopid = tmp_loopid;
3089 } else {
3090 /*
3091 * No retry occurred before. Just increment the
3092 * ID value for next login.
3093 */
3094 *next_loopid = (fcport->loop_id + 1);
3095 }
3096
3097 if (mb[1] & BIT_0) {
3098 fcport->port_type = FCT_INITIATOR;
3099 } else {
3100 fcport->port_type = FCT_TARGET;
3101 if (mb[1] & BIT_1) {
3102 fcport->flags |= FCF_TAPE_PRESENT;
3103 }
3104 }
3105
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003106 if (mb[10] & BIT_0)
3107 fcport->supported_classes |= FC_COS_CLASS2;
3108 if (mb[10] & BIT_1)
3109 fcport->supported_classes |= FC_COS_CLASS3;
3110
Linus Torvalds1da177e2005-04-16 15:20:36 -07003111 rval = QLA_SUCCESS;
3112 break;
3113 } else if (mb[0] == MBS_LOOP_ID_USED) {
3114 /*
3115 * Loop ID already used, try next loop ID.
3116 */
3117 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003119 if (rval != QLA_SUCCESS) {
3120 /* Ran out of loop IDs to use */
3121 break;
3122 }
3123 } else if (mb[0] == MBS_COMMAND_ERROR) {
3124 /*
3125 * Firmware possibly timed out during login. If NO
3126 * retries are left to do then the device is declared
3127 * dead.
3128 */
3129 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003130 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003131 fcport->d_id.b.domain, fcport->d_id.b.area,
3132 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003133 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
3135 rval = 1;
3136 break;
3137 } else {
3138 /*
3139 * unrecoverable / not handled error
3140 */
3141 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003142 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003143 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003144 fcport->d_id.b.domain, fcport->d_id.b.area,
3145 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3146
3147 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003148 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003149 fcport->d_id.b.domain, fcport->d_id.b.area,
3150 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003151 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003152 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153
3154 rval = 3;
3155 break;
3156 }
3157 }
3158
3159 return (rval);
3160}
3161
3162/*
3163 * qla2x00_local_device_login
3164 * Issue local device login command.
3165 *
3166 * Input:
3167 * ha = adapter block pointer.
3168 * loop_id = loop id of device to login to.
3169 *
3170 * Returns (Where's the #define!!!!):
3171 * 0 - Login successfully
3172 * 1 - Login failed
3173 * 3 - Fatal error
3174 */
3175int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177{
3178 int rval;
3179 uint16_t mb[MAILBOX_REGISTER_COUNT];
3180
3181 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003182 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003183 if (rval == QLA_SUCCESS) {
3184 /* Interrogate mailbox registers for any errors */
3185 if (mb[0] == MBS_COMMAND_ERROR)
3186 rval = 1;
3187 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3188 /* device not in PCB table */
3189 rval = 3;
3190 }
3191
3192 return (rval);
3193}
3194
3195/*
3196 * qla2x00_loop_resync
3197 * Resync with fibre channel devices.
3198 *
3199 * Input:
3200 * ha = adapter block pointer.
3201 *
3202 * Returns:
3203 * 0 = success
3204 */
3205int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003206qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003208 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 uint32_t wait_time;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003210 struct qla_hw_data *ha = vha->hw;
3211 struct req_que *req = ha->req_q_map[0];
3212 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003214 atomic_set(&vha->loop_state, LOOP_UPDATE);
3215 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3216 if (vha->flags.online) {
3217 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3219 wait_time = 256;
3220 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003221 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003222
Andrew Vasquez01071092005-07-06 10:31:37 -07003223 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003224 qla2x00_marker(vha, req, rsp, 0, 0,
3225 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003226 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227
3228 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003229 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003231 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003233 } while (!atomic_read(&vha->loop_down_timer) &&
3234 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3235 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3236 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 }
3239
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003240 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003243 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
3246 return (rval);
3247}
3248
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003251{
3252 fc_port_t *fcport;
3253
3254 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003255 list_for_each_entry(fcport, &vha->vp_fcports, list)
3256 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003257 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003258 qla2x00_rport_del(fcport);
3259}
3260
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261/*
3262* qla2x00_abort_isp
3263* Resets ISP and aborts all outstanding commands.
3264*
3265* Input:
3266* ha = adapter block pointer.
3267*
3268* Returns:
3269* 0 = success
3270*/
3271int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003274 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003275 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 struct qla_hw_data *ha = vha->hw;
3277 struct scsi_qla_host *vp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003278 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 if (vha->flags.online) {
3281 vha->flags.online = 0;
3282 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003283 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284
3285 qla_printk(KERN_INFO, ha,
3286 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003289 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3290 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3291 atomic_set(&vha->loop_state, LOOP_DOWN);
3292 qla2x00_mark_all_devices_lost(vha, 0);
3293 list_for_each_entry(vp, &ha->vp_list, list)
3294 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003295 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003296 if (!atomic_read(&vha->loop_down_timer))
3297 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 LOOP_DOWN_TIME);
3299 }
3300
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003302 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003303
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003304 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003305
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003306 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003308 if (!qla2x00_restart_isp(vha)) {
3309 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003311 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 /*
3313 * Issue marker command only when we are going
3314 * to start the I/O .
3315 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003316 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003317 }
3318
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003321 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003323 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003324 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003325
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003326 if (ha->fce) {
3327 ha->flags.fce_enabled = 1;
3328 memset(ha->fce, 0,
3329 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003330 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003331 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3332 &ha->fce_bufs);
3333 if (rval) {
3334 qla_printk(KERN_WARNING, ha,
3335 "Unable to reinitialize FCE "
3336 "(%d).\n", rval);
3337 ha->flags.fce_enabled = 0;
3338 }
3339 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003340
3341 if (ha->eft) {
3342 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003343 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003344 ha->eft_dma, EFT_NUM_BUFFERS);
3345 if (rval) {
3346 qla_printk(KERN_WARNING, ha,
3347 "Unable to reinitialize EFT "
3348 "(%d).\n", rval);
3349 }
3350 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003352 vha->flags.online = 1;
3353 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003354 if (ha->isp_abort_cnt == 0) {
3355 qla_printk(KERN_WARNING, ha,
3356 "ISP error recovery failed - "
3357 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003358 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003359 * The next call disables the board
3360 * completely.
3361 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003362 ha->isp_ops->reset_adapter(vha);
3363 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003365 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 status = 0;
3367 } else { /* schedule another ISP abort */
3368 ha->isp_abort_cnt--;
3369 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003370 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003371 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 status = 1;
3373 }
3374 } else {
3375 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3376 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3377 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 vha->host_no, ha->isp_abort_cnt));
3379 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003380 status = 1;
3381 }
3382 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003383
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 }
3385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003386 if (!status) {
3387 DEBUG(printk(KERN_INFO
3388 "qla2x00_abort_isp(%ld): succeeded.\n",
3389 vha->host_no));
3390 list_for_each_entry(vp, &ha->vp_list, list) {
3391 if (vp->vp_idx)
3392 qla2x00_vp_abort_isp(vp);
3393 }
3394 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 qla_printk(KERN_INFO, ha,
3396 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003397 }
3398
3399 return(status);
3400}
3401
3402/*
3403* qla2x00_restart_isp
3404* restarts the ISP after a reset
3405*
3406* Input:
3407* ha = adapter block pointer.
3408*
3409* Returns:
3410* 0 = success
3411*/
3412static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003413qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003414{
3415 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003417 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003418 struct req_que *req = ha->req_q_map[0];
3419 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420
3421 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003422 if (qla2x00_isp_firmware(vha)) {
3423 vha->flags.online = 0;
3424 status = ha->isp_ops->chip_diag(vha);
3425 if (!status)
3426 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 }
3428
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003429 if (!status && !(status = qla2x00_init_rings(vha))) {
3430 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003431 /* Initialize the queues in use */
3432 qla25xx_init_queues(ha);
3433
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003434 status = qla2x00_fw_ready(vha);
3435 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003436 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003437 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07003438
3439 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003440 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez01071092005-07-06 10:31:37 -07003441
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003442 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3444 wait_time = 256;
3445 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3447 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003449 } while (!atomic_read(&vha->loop_down_timer) &&
3450 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3451 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3452 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003453 }
3454
3455 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003456 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 status = 0;
3458
3459 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3460 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003461 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 }
3463 return (status);
3464}
3465
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003466static int
3467qla25xx_init_queues(struct qla_hw_data *ha)
3468{
3469 struct rsp_que *rsp = NULL;
3470 struct req_que *req = NULL;
3471 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3472 int ret = -1;
3473 int i;
3474
3475 for (i = 1; i < ha->max_queues; i++) {
3476 rsp = ha->rsp_q_map[i];
3477 if (rsp) {
3478 rsp->options &= ~BIT_0;
3479 ret = qla25xx_init_rsp_que(base_vha, rsp, rsp->options);
3480 if (ret != QLA_SUCCESS)
3481 DEBUG2_17(printk(KERN_WARNING
3482 "%s Rsp que:%d init failed\n", __func__,
3483 rsp->id));
3484 else
3485 DEBUG2_17(printk(KERN_INFO
3486 "%s Rsp que:%d inited\n", __func__,
3487 rsp->id));
3488 }
3489 req = ha->req_q_map[i];
3490 if (req) {
3491 req->options &= ~BIT_0;
3492 ret = qla25xx_init_req_que(base_vha, req, req->options);
3493 if (ret != QLA_SUCCESS)
3494 DEBUG2_17(printk(KERN_WARNING
3495 "%s Req que:%d init failed\n", __func__,
3496 req->id));
3497 else
3498 DEBUG2_17(printk(KERN_WARNING
3499 "%s Rsp que:%d inited\n", __func__,
3500 req->id));
3501 }
3502 }
3503 return ret;
3504}
3505
Linus Torvalds1da177e2005-04-16 15:20:36 -07003506/*
3507* qla2x00_reset_adapter
3508* Reset adapter.
3509*
3510* Input:
3511* ha = adapter block pointer.
3512*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003513void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003514qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515{
3516 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003517 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003518 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003520 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003521 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522
Linus Torvalds1da177e2005-04-16 15:20:36 -07003523 spin_lock_irqsave(&ha->hardware_lock, flags);
3524 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3525 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3526 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3527 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3528 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3529}
Andrew Vasquez01071092005-07-06 10:31:37 -07003530
3531void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003532qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003533{
3534 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003535 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003536 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3537
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003538 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003539 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003540
3541 spin_lock_irqsave(&ha->hardware_lock, flags);
3542 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3543 RD_REG_DWORD(&reg->hccr);
3544 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3545 RD_REG_DWORD(&reg->hccr);
3546 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3547}
3548
David Miller4e08df32007-04-16 12:37:43 -07003549/* On sparc systems, obtain port and node WWN from firmware
3550 * properties.
3551 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3553 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003554{
3555#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003556 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003557 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003558 struct device_node *dp = pci_device_to_OF_node(pdev);
3559 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003560 int len;
3561
3562 val = of_get_property(dp, "port-wwn", &len);
3563 if (val && len >= WWN_SIZE)
3564 memcpy(nv->port_name, val, WWN_SIZE);
3565
3566 val = of_get_property(dp, "node-wwn", &len);
3567 if (val && len >= WWN_SIZE)
3568 memcpy(nv->node_name, val, WWN_SIZE);
3569#endif
3570}
3571
Andrew Vasquez01071092005-07-06 10:31:37 -07003572int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003573qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003574{
David Miller4e08df32007-04-16 12:37:43 -07003575 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07003576 struct init_cb_24xx *icb;
3577 struct nvram_24xx *nv;
3578 uint32_t *dptr;
3579 uint8_t *dptr1, *dptr2;
3580 uint32_t chksum;
3581 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003582 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003583
David Miller4e08df32007-04-16 12:37:43 -07003584 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07003585 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003586 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07003587
3588 /* Determine NVRAM starting address. */
3589 ha->nvram_size = sizeof(struct nvram_24xx);
3590 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003591 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3592 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3593 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003594 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003595 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3596 }
Andrew Vasquez01071092005-07-06 10:31:37 -07003597
Seokmann Ju281afe12007-07-26 13:43:34 -07003598 /* Get VPD data into cache */
3599 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003600 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003601 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3602
3603 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07003604 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003605 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07003606 ha->nvram_size);
3607 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3608 chksum += le32_to_cpu(*dptr++);
3609
3610 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003611 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07003612
3613 /* Bad NVRAM data, set defaults parameters. */
3614 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3615 || nv->id[3] != ' ' ||
3616 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3617 /* Reset NVRAM data. */
3618 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3619 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3620 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003621 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3622 "invalid -- WWPN) defaults.\n");
3623
3624 /*
3625 * Set default initialization control block.
3626 */
3627 memset(nv, 0, ha->nvram_size);
3628 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3629 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3630 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3631 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3632 nv->exchange_count = __constant_cpu_to_le16(0);
3633 nv->hard_address = __constant_cpu_to_le16(124);
3634 nv->port_name[0] = 0x21;
3635 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3636 nv->port_name[2] = 0x00;
3637 nv->port_name[3] = 0xe0;
3638 nv->port_name[4] = 0x8b;
3639 nv->port_name[5] = 0x1c;
3640 nv->port_name[6] = 0x55;
3641 nv->port_name[7] = 0x86;
3642 nv->node_name[0] = 0x20;
3643 nv->node_name[1] = 0x00;
3644 nv->node_name[2] = 0x00;
3645 nv->node_name[3] = 0xe0;
3646 nv->node_name[4] = 0x8b;
3647 nv->node_name[5] = 0x1c;
3648 nv->node_name[6] = 0x55;
3649 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003650 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003651 nv->login_retry_count = __constant_cpu_to_le16(8);
3652 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3653 nv->login_timeout = __constant_cpu_to_le16(0);
3654 nv->firmware_options_1 =
3655 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3656 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3657 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3658 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3659 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3660 nv->efi_parameters = __constant_cpu_to_le32(0);
3661 nv->reset_delay = 5;
3662 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3663 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3664 nv->link_down_timeout = __constant_cpu_to_le16(30);
3665
3666 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07003667 }
3668
3669 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003670 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003671
3672 /* Copy 1st segment. */
3673 dptr1 = (uint8_t *)icb;
3674 dptr2 = (uint8_t *)&nv->version;
3675 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3676 while (cnt--)
3677 *dptr1++ = *dptr2++;
3678
3679 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003680 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07003681
3682 /* Copy 2nd segment. */
3683 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3684 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3685 cnt = (uint8_t *)&icb->reserved_3 -
3686 (uint8_t *)&icb->interrupt_delay_timer;
3687 while (cnt--)
3688 *dptr1++ = *dptr2++;
3689
3690 /*
3691 * Setup driver NVRAM options.
3692 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003693 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003694 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07003695
Andrew Vasquez5341e862006-05-17 15:09:16 -07003696 /* Use alternate WWN? */
3697 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3698 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3699 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3700 }
3701
Andrew Vasquez01071092005-07-06 10:31:37 -07003702 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003703 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003704 /*
3705 * Firmware will apply the following mask if the nodename was
3706 * not provided.
3707 */
3708 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3709 icb->node_name[0] &= 0xF0;
3710 }
3711
3712 /* Set host adapter parameters. */
3713 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003714 ha->flags.enable_lip_reset = 0;
3715 ha->flags.enable_lip_full_login =
3716 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3717 ha->flags.enable_target_reset =
3718 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003719 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003720 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003721
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003722 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3723 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07003724
3725 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3726 sizeof(ha->fw_seriallink_options24));
3727
3728 /* save HBA serial number */
3729 ha->serial0 = icb->port_name[5];
3730 ha->serial1 = icb->port_name[6];
3731 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003732 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3733 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez01071092005-07-06 10:31:37 -07003734
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003735 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3736
Andrew Vasquez01071092005-07-06 10:31:37 -07003737 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3738
3739 /* Set minimum login_timeout to 4 seconds. */
3740 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3741 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3742 if (le16_to_cpu(nv->login_timeout) < 4)
3743 nv->login_timeout = __constant_cpu_to_le16(4);
3744 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003745 icb->login_timeout = nv->login_timeout;
Andrew Vasquez01071092005-07-06 10:31:37 -07003746
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003747 /* Set minimum RATOV to 100 tenths of a second. */
3748 ha->r_a_tov = 100;
Andrew Vasquez01071092005-07-06 10:31:37 -07003749
3750 ha->loop_reset_delay = nv->reset_delay;
3751
3752 /* Link Down Timeout = 0:
3753 *
3754 * When Port Down timer expires we will start returning
3755 * I/O's to OS with "DID_NO_CONNECT".
3756 *
3757 * Link Down Timeout != 0:
3758 *
3759 * The driver waits for the link to come up after link down
3760 * before returning I/Os to OS with "DID_NO_CONNECT".
3761 */
3762 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3763 ha->loop_down_abort_time =
3764 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3765 } else {
3766 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3767 ha->loop_down_abort_time =
3768 (LOOP_DOWN_TIME - ha->link_down_timeout);
3769 }
3770
3771 /* Need enough time to try and get the port back. */
3772 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3773 if (qlport_down_retry)
3774 ha->port_down_retry_count = qlport_down_retry;
3775
3776 /* Set login_retry_count */
3777 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3778 if (ha->port_down_retry_count ==
3779 le16_to_cpu(nv->port_down_retry_count) &&
3780 ha->port_down_retry_count > 3)
3781 ha->login_retry_count = ha->port_down_retry_count;
3782 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3783 ha->login_retry_count = ha->port_down_retry_count;
3784 if (ql2xloginretrycount)
3785 ha->login_retry_count = ql2xloginretrycount;
3786
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003787 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003788 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003789 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3790 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3791 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3792 le16_to_cpu(icb->interrupt_delay_timer): 2;
3793 }
3794 icb->firmware_options_2 &= __constant_cpu_to_le32(
3795 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003796 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003797 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003798 ha->zio_mode = QLA_ZIO_MODE_6;
3799
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003800 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003801 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003802 ha->zio_timer * 100));
3803 qla_printk(KERN_INFO, ha,
3804 "ZIO mode %d enabled; timer delay (%d us).\n",
3805 ha->zio_mode, ha->zio_timer * 100);
3806
3807 icb->firmware_options_2 |= cpu_to_le32(
3808 (uint32_t)ha->zio_mode);
3809 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003810 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003811 }
3812
David Miller4e08df32007-04-16 12:37:43 -07003813 if (rval) {
3814 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003815 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003816 }
3817 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07003818}
3819
Adrian Bunk413975a2006-06-30 02:33:06 -07003820static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003822{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003823 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003824 int segments, fragment;
3825 uint32_t faddr;
3826 uint32_t *dcode, dlen;
3827 uint32_t risc_addr;
3828 uint32_t risc_size;
3829 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003830 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003831 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003832 rval = QLA_SUCCESS;
3833
3834 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003835 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003836 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003837 *srisc_addr = 0;
3838
3839 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003841 for (i = 0; i < 4; i++)
3842 dcode[i] = be32_to_cpu(dcode[i]);
3843 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3844 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3845 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3846 dcode[3] == 0)) {
3847 qla_printk(KERN_WARNING, ha,
3848 "Unable to verify integrity of flash firmware image!\n");
3849 qla_printk(KERN_WARNING, ha,
3850 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3851 dcode[1], dcode[2], dcode[3]);
3852
3853 return QLA_FUNCTION_FAILED;
3854 }
3855
3856 while (segments && rval == QLA_SUCCESS) {
3857 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003858 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003859
3860 risc_addr = be32_to_cpu(dcode[2]);
3861 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3862 risc_size = be32_to_cpu(dcode[3]);
3863
3864 fragment = 0;
3865 while (risc_size > 0 && rval == QLA_SUCCESS) {
3866 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3867 if (dlen > risc_size)
3868 dlen = risc_size;
3869
3870 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3871 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003872 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003873
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003874 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003875 for (i = 0; i < dlen; i++)
3876 dcode[i] = swab32(dcode[i]);
3877
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003878 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003879 dlen);
3880 if (rval) {
3881 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003882 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003883 fragment));
3884 qla_printk(KERN_WARNING, ha,
3885 "[ERROR] Failed to load segment %d of "
3886 "firmware\n", fragment);
3887 break;
3888 }
3889
3890 faddr += dlen;
3891 risc_addr += dlen;
3892 risc_size -= dlen;
3893 fragment++;
3894 }
3895
3896 /* Next segment. */
3897 segments--;
3898 }
3899
3900 return rval;
3901}
3902
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003903#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3904
Andrew Vasquez01071092005-07-06 10:31:37 -07003905int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003906qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003907{
3908 int rval;
3909 int i, fragment;
3910 uint16_t *wcode, *fwcode;
3911 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3912 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003913 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003914 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003915
3916 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003917 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003918 if (!blob) {
3919 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003920 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3921 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003922 return QLA_FUNCTION_FAILED;
3923 }
3924
3925 rval = QLA_SUCCESS;
3926
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003927 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003928 *srisc_addr = 0;
3929 fwcode = (uint16_t *)blob->fw->data;
3930 fwclen = 0;
3931
3932 /* Validate firmware image by checking version. */
3933 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3934 qla_printk(KERN_WARNING, ha,
3935 "Unable to verify integrity of firmware image (%Zd)!\n",
3936 blob->fw->size);
3937 goto fail_fw_integrity;
3938 }
3939 for (i = 0; i < 4; i++)
3940 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3941 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3942 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3943 wcode[2] == 0 && wcode[3] == 0)) {
3944 qla_printk(KERN_WARNING, ha,
3945 "Unable to verify integrity of firmware image!\n");
3946 qla_printk(KERN_WARNING, ha,
3947 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3948 wcode[1], wcode[2], wcode[3]);
3949 goto fail_fw_integrity;
3950 }
3951
3952 seg = blob->segs;
3953 while (*seg && rval == QLA_SUCCESS) {
3954 risc_addr = *seg;
3955 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3956 risc_size = be16_to_cpu(fwcode[3]);
3957
3958 /* Validate firmware image size. */
3959 fwclen += risc_size * sizeof(uint16_t);
3960 if (blob->fw->size < fwclen) {
3961 qla_printk(KERN_WARNING, ha,
3962 "Unable to verify integrity of firmware image "
3963 "(%Zd)!\n", blob->fw->size);
3964 goto fail_fw_integrity;
3965 }
3966
3967 fragment = 0;
3968 while (risc_size > 0 && rval == QLA_SUCCESS) {
3969 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3970 if (wlen > risc_size)
3971 wlen = risc_size;
3972
3973 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003974 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003975 risc_addr, wlen));
3976
3977 for (i = 0; i < wlen; i++)
3978 wcode[i] = swab16(fwcode[i]);
3979
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003980 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003981 wlen);
3982 if (rval) {
3983 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003984 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003985 fragment));
3986 qla_printk(KERN_WARNING, ha,
3987 "[ERROR] Failed to load segment %d of "
3988 "firmware\n", fragment);
3989 break;
3990 }
3991
3992 fwcode += wlen;
3993 risc_addr += wlen;
3994 risc_size -= wlen;
3995 fragment++;
3996 }
3997
3998 /* Next segment. */
3999 seg++;
4000 }
4001 return rval;
4002
4003fail_fw_integrity:
4004 return QLA_FUNCTION_FAILED;
4005}
4006
4007int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez01071092005-07-06 10:31:37 -07004009{
4010 int rval;
4011 int segments, fragment;
4012 uint32_t *dcode, dlen;
4013 uint32_t risc_addr;
4014 uint32_t risc_size;
4015 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08004016 struct fw_blob *blob;
Andrew Vasquez01071092005-07-06 10:31:37 -07004017 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004018 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004019 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07004020
Andrew Vasquez54333832005-11-09 15:49:04 -08004021 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004022 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004023 if (!blob) {
4024 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004025 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4026 "from: " QLA_FW_URL ".\n");
4027
4028 /* Try to load RISC code from flash. */
4029 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
4030 "outdated) firmware from flash.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004031 return qla24xx_load_risc_flash(vha, srisc_addr);
Andrew Vasquez01071092005-07-06 10:31:37 -07004032 }
4033
4034 rval = QLA_SUCCESS;
4035
4036 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004037 dcode = (uint32_t *)req->ring;
Andrew Vasquez01071092005-07-06 10:31:37 -07004038 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004039 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez01071092005-07-06 10:31:37 -07004040 fwclen = 0;
4041
4042 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004043 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004044 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004045 "Unable to verify integrity of firmware image (%Zd)!\n",
4046 blob->fw->size);
Andrew Vasquez01071092005-07-06 10:31:37 -07004047 goto fail_fw_integrity;
4048 }
4049 for (i = 0; i < 4; i++)
4050 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4051 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4052 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4053 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4054 dcode[3] == 0)) {
4055 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004056 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez01071092005-07-06 10:31:37 -07004057 qla_printk(KERN_WARNING, ha,
4058 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4059 dcode[1], dcode[2], dcode[3]);
4060 goto fail_fw_integrity;
4061 }
4062
4063 while (segments && rval == QLA_SUCCESS) {
4064 risc_addr = be32_to_cpu(fwcode[2]);
4065 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4066 risc_size = be32_to_cpu(fwcode[3]);
4067
4068 /* Validate firmware image size. */
4069 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004070 if (blob->fw->size < fwclen) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004071 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004072 "Unable to verify integrity of firmware image "
4073 "(%Zd)!\n", blob->fw->size);
4074
Andrew Vasquez01071092005-07-06 10:31:37 -07004075 goto fail_fw_integrity;
4076 }
4077
4078 fragment = 0;
4079 while (risc_size > 0 && rval == QLA_SUCCESS) {
4080 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4081 if (dlen > risc_size)
4082 dlen = risc_size;
4083
4084 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004085 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004086 risc_addr, dlen));
4087
4088 for (i = 0; i < dlen; i++)
4089 dcode[i] = swab32(fwcode[i]);
4090
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004091 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004092 dlen);
Andrew Vasquez01071092005-07-06 10:31:37 -07004093 if (rval) {
4094 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004095 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004096 fragment));
4097 qla_printk(KERN_WARNING, ha,
4098 "[ERROR] Failed to load segment %d of "
4099 "firmware\n", fragment);
4100 break;
4101 }
4102
4103 fwcode += dlen;
4104 risc_addr += dlen;
4105 risc_size -= dlen;
4106 fragment++;
4107 }
4108
4109 /* Next segment. */
4110 segments--;
4111 }
Andrew Vasquez01071092005-07-06 10:31:37 -07004112 return rval;
4113
4114fail_fw_integrity:
Andrew Vasquez01071092005-07-06 10:31:37 -07004115 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004116}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004117
4118void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004119qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004120{
4121 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004122 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004123
Andrew Vasqueze4289242007-07-19 15:05:56 -07004124 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004125 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004126 if (!ha->fw_major_version)
4127 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004128
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004129 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004130 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4131 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004132 ha->isp_ops->reset_chip(vha);
4133 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004134 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004135 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004136 continue;
4137 qla_printk(KERN_INFO, ha,
4138 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004139 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004140 }
4141}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004142
4143int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004144qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004145{
4146 int rval = QLA_SUCCESS;
4147 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148 struct qla_hw_data *ha = vha->hw;
4149 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004150 struct req_que *req = ha->req_q_map[0];
4151 struct rsp_que *rsp = ha->rsp_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004152
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004153 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004154 return -EINVAL;
4155
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004156 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004157 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004158 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004159 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004160 }
4161
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004162 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004163
4164 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004165 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004166 if (mb[0] != MBS_COMMAND_COMPLETE) {
4167 DEBUG15(qla_printk(KERN_INFO, ha,
4168 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4169 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4170 mb[0], mb[1], mb[2], mb[6], mb[7]));
4171 return (QLA_FUNCTION_FAILED);
4172 }
4173
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004174 atomic_set(&vha->loop_down_timer, 0);
4175 atomic_set(&vha->loop_state, LOOP_UP);
4176 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4177 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4178 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004179
4180 return rval;
4181}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004182
4183/* 84XX Support **************************************************************/
4184
4185static LIST_HEAD(qla_cs84xx_list);
4186static DEFINE_MUTEX(qla_cs84xx_mutex);
4187
4188static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004189qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004190{
4191 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004192 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004193
4194 mutex_lock(&qla_cs84xx_mutex);
4195
4196 /* Find any shared 84xx chip. */
4197 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4198 if (cs84xx->bus == ha->pdev->bus) {
4199 kref_get(&cs84xx->kref);
4200 goto done;
4201 }
4202 }
4203
4204 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4205 if (!cs84xx)
4206 goto done;
4207
4208 kref_init(&cs84xx->kref);
4209 spin_lock_init(&cs84xx->access_lock);
4210 mutex_init(&cs84xx->fw_update_mutex);
4211 cs84xx->bus = ha->pdev->bus;
4212
4213 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4214done:
4215 mutex_unlock(&qla_cs84xx_mutex);
4216 return cs84xx;
4217}
4218
4219static void
4220__qla84xx_chip_release(struct kref *kref)
4221{
4222 struct qla_chip_state_84xx *cs84xx =
4223 container_of(kref, struct qla_chip_state_84xx, kref);
4224
4225 mutex_lock(&qla_cs84xx_mutex);
4226 list_del(&cs84xx->list);
4227 mutex_unlock(&qla_cs84xx_mutex);
4228 kfree(cs84xx);
4229}
4230
4231void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004232qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004233{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004234 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004235 if (ha->cs84xx)
4236 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4237}
4238
4239static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004240qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004241{
4242 int rval;
4243 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004244 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004245
4246 mutex_lock(&ha->cs84xx->fw_update_mutex);
4247
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004248 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004249
4250 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4251
4252 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4253 QLA_SUCCESS;
4254}