blob: 36cea2224b3c49f4243c3614a7365d6f9f0df3b2 [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 int qla2x00_setup_chip(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070024static int qla2x00_init_rings(scsi_qla_host_t *);
25static int qla2x00_fw_ready(scsi_qla_host_t *);
26static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070027static int qla2x00_configure_loop(scsi_qla_host_t *);
28static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070029static int qla2x00_configure_fabric(scsi_qla_host_t *);
30static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
31static int qla2x00_device_resync(scsi_qla_host_t *);
32static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
33 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070034
35static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070036
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080037static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070038
Harihara Kadayam4d4df192008-04-03 13:13:26 -070039static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
40static int qla84xx_init_chip(scsi_qla_host_t *);
Anirban Chakraborty73208df2008-12-09 16:45:39 -080041static int qla25xx_init_queues(struct qla_hw_data *);
Harihara Kadayam4d4df192008-04-03 13:13:26 -070042
Linus Torvalds1da177e2005-04-16 15:20:36 -070043/****************************************************************************/
44/* QLogic ISP2x00 Hardware Support Functions. */
45/****************************************************************************/
46
47/*
48* qla2x00_initialize_adapter
49* Initialize board.
50*
51* Input:
52* ha = adapter block pointer.
53*
54* Returns:
55* 0 = success
56*/
57int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080058qla2x00_initialize_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -070059{
60 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080061 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -080062 struct req_que *req = ha->req_q_map[0];
Lalit Chandivade2533cf62009-03-24 09:08:07 -070063
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080065 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -070066 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080067 vha->flags.reset_active = 0;
68 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
69 atomic_set(&vha->loop_state, LOOP_DOWN);
70 vha->device_flags = DFLG_NO_CABLE;
71 vha->dpc_flags = 0;
72 vha->flags.management_server_logged_in = 0;
73 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 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);
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700134 ha->flags.chip_reset_done = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 return (rval);
137}
138
139/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700140 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141 * @ha: HA context
142 *
143 * Returns 0 on success.
144 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700145int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800146qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700148 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700149 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800150 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700151 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700154 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700157 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
159
Andrew Vasquez737faec2008-10-24 15:13:45 -0700160 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700162 /* Get PCI bus information. */
163 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700164 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700165 spin_unlock_irqrestore(&ha->hardware_lock, flags);
166
167 return QLA_SUCCESS;
168}
169
170/**
171 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
172 * @ha: HA context
173 *
174 * Returns 0 on success.
175 */
176int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800177qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700178{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700179 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700180 unsigned long flags = 0;
181 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800182 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700183 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700184
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700185 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700186 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700187
188 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700189 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700190
191 if (IS_QLA2322(ha) || IS_QLA6322(ha))
192 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700193 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700194
195 /*
196 * If this is a 2300 card and not 2312, reset the
197 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
198 * the 2310 also reports itself as a 2300 so we need to get the
199 * fb revision level -- a 6 indicates it really is a 2300 and
200 * not a 2310.
201 */
202 if (IS_QLA2300(ha)) {
203 spin_lock_irqsave(&ha->hardware_lock, flags);
204
205 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700206 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700207 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700208 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700209 break;
210
211 udelay(10);
212 }
213
214 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700215 WRT_REG_WORD(&reg->ctrl_status, 0x20);
216 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700217
218 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700219 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700220
221 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700222 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700223
224 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700225 WRT_REG_WORD(&reg->ctrl_status, 0x0);
226 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700227
228 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700229 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700230 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700231 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700232 break;
233
234 udelay(10);
235 }
236
237 spin_unlock_irqrestore(&ha->hardware_lock, flags);
238 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700239
240 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
241
Andrew Vasquez737faec2008-10-24 15:13:45 -0700242 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700243
244 /* Get PCI bus information. */
245 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700246 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700247 spin_unlock_irqrestore(&ha->hardware_lock, flags);
248
249 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700250}
251
252/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700253 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
254 * @ha: HA context
255 *
256 * Returns 0 on success.
257 */
258int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800259qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700260{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700261 uint16_t w;
Andrew Vasquez01071092005-07-06 10:31:37 -0700262 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800263 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700264 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez01071092005-07-06 10:31:37 -0700265
266 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700267 pci_try_set_mwi(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700268
269 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700270 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez01071092005-07-06 10:31:37 -0700271 w &= ~PCI_COMMAND_INTX_DISABLE;
272 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
273
274 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
275
276 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700277 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
278 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700279
280 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700281 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
282 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700283
Andrew Vasquez737faec2008-10-24 15:13:45 -0700284 pci_disable_rom(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700285
Auke Kok44c10132007-06-08 15:46:36 -0700286 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800287
Andrew Vasquez01071092005-07-06 10:31:37 -0700288 /* Get PCI bus information. */
289 spin_lock_irqsave(&ha->hardware_lock, flags);
290 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
291 spin_unlock_irqrestore(&ha->hardware_lock, flags);
292
293 return QLA_SUCCESS;
294}
295
296/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700297 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
298 * @ha: HA context
299 *
300 * Returns 0 on success.
301 */
302int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800303qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700304{
305 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800306 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700307
308 pci_set_master(ha->pdev);
309 pci_try_set_mwi(ha->pdev);
310
311 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
312 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
313 w &= ~PCI_COMMAND_INTX_DISABLE;
314 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
315
316 /* PCIe -- adjust Maximum Read Request Size (2048). */
317 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
318 pcie_set_readrq(ha->pdev, 2048);
319
Andrew Vasquez737faec2008-10-24 15:13:45 -0700320 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700321
322 ha->chip_revision = ha->pdev->revision;
323
324 return QLA_SUCCESS;
325}
326
327/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 * qla2x00_isp_firmware() - Choose firmware image.
329 * @ha: HA context
330 *
331 * Returns 0 on success.
332 */
333static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800334qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335{
336 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700337 uint16_t loop_id, topo, sw_cap;
338 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800339 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340
341 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700342 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 if (ha->flags.disable_risc_code_load) {
345 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800346 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
348
349 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700351 if (rval == QLA_SUCCESS) {
352 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800353 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700354 &area, &domain, &topo, &sw_cap);
355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 if (rval) {
359 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800360 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 }
362
363 return (rval);
364}
365
366/**
367 * qla2x00_reset_chip() - Reset ISP chip.
368 * @ha: HA context
369 *
370 * Returns 0 on success.
371 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700372void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800373qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374{
375 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800376 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700377 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 uint16_t cmd;
380
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700381 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382
383 spin_lock_irqsave(&ha->hardware_lock, flags);
384
385 /* Turn off master enable */
386 cmd = 0;
387 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
388 cmd &= ~PCI_COMMAND_MASTER;
389 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
390
391 if (!IS_QLA2100(ha)) {
392 /* Pause RISC. */
393 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
394 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
395 for (cnt = 0; cnt < 30000; cnt++) {
396 if ((RD_REG_WORD(&reg->hccr) &
397 HCCR_RISC_PAUSE) != 0)
398 break;
399 udelay(100);
400 }
401 } else {
402 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
403 udelay(10);
404 }
405
406 /* Select FPM registers. */
407 WRT_REG_WORD(&reg->ctrl_status, 0x20);
408 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
409
410 /* FPM Soft Reset. */
411 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
412 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
413
414 /* Toggle Fpm Reset. */
415 if (!IS_QLA2200(ha)) {
416 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
417 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
418 }
419
420 /* Select frame buffer registers. */
421 WRT_REG_WORD(&reg->ctrl_status, 0x10);
422 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
423
424 /* Reset frame buffer FIFOs. */
425 if (IS_QLA2200(ha)) {
426 WRT_FB_CMD_REG(ha, reg, 0xa000);
427 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
428 } else {
429 WRT_FB_CMD_REG(ha, reg, 0x00fc);
430
431 /* Read back fb_cmd until zero or 3 seconds max */
432 for (cnt = 0; cnt < 3000; cnt++) {
433 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
434 break;
435 udelay(100);
436 }
437 }
438
439 /* Select RISC module registers. */
440 WRT_REG_WORD(&reg->ctrl_status, 0);
441 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
442
443 /* Reset RISC processor. */
444 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
445 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
446
447 /* Release RISC processor. */
448 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
449 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
450 }
451
452 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
453 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
454
455 /* Reset ISP chip. */
456 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
457
458 /* Wait for RISC to recover from reset. */
459 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
460 /*
461 * It is necessary to for a delay here since the card doesn't
462 * respond to PCI reads during a reset. On some architectures
463 * this will result in an MCA.
464 */
465 udelay(20);
466 for (cnt = 30000; cnt; cnt--) {
467 if ((RD_REG_WORD(&reg->ctrl_status) &
468 CSR_ISP_SOFT_RESET) == 0)
469 break;
470 udelay(100);
471 }
472 } else
473 udelay(10);
474
475 /* Reset RISC processor. */
476 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
477
478 WRT_REG_WORD(&reg->semaphore, 0);
479
480 /* Release RISC processor. */
481 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
482 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
483
484 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
485 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700486 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489 udelay(100);
490 }
491 } else
492 udelay(100);
493
494 /* Turn on master enable */
495 cmd |= PCI_COMMAND_MASTER;
496 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
497
498 /* Disable RISC pause on FPM parity error. */
499 if (!IS_QLA2100(ha)) {
500 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
501 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
502 }
503
504 spin_unlock_irqrestore(&ha->hardware_lock, flags);
505}
506
507/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700508 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez01071092005-07-06 10:31:37 -0700509 * @ha: HA context
510 *
511 * Returns 0 on success.
512 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700513static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800514qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700515{
516 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 }
545
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800546 /* Wait for soft-reset to complete. */
Andrew Vasquez01071092005-07-06 10:31:37 -0700547 d2 = RD_REG_DWORD(&reg->ctrl_status);
548 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
549 udelay(5);
550 d2 = RD_REG_DWORD(&reg->ctrl_status);
551 barrier();
552 }
553
554 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
555 RD_REG_DWORD(&reg->hccr);
556
557 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
558 RD_REG_DWORD(&reg->hccr);
559
560 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
561 RD_REG_DWORD(&reg->hccr);
562
563 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
564 for (cnt = 6000000 ; cnt && d2; cnt--) {
565 udelay(5);
566 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
567 barrier();
568 }
569
570 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez124f85e2009-01-05 11:18:06 -0800571
572 if (IS_NOPOLLING_TYPE(ha))
573 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700574}
575
576/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700577 * qla24xx_reset_chip() - Reset ISP24xx chip.
578 * @ha: HA context
579 *
580 * Returns 0 on success.
581 */
582void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700584{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800585 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700586 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700587
588 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700590}
591
592/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700593 * qla2x00_chip_diag() - Test chip for proper operation.
594 * @ha: HA context
595 *
596 * Returns 0 on success.
597 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700598int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800599qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600{
601 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800602 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700603 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 unsigned long flags = 0;
605 uint16_t data;
606 uint32_t cnt;
607 uint16_t mb[5];
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800608 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609
610 /* Assume a failed state */
611 rval = QLA_FUNCTION_FAILED;
612
613 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800614 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
616 spin_lock_irqsave(&ha->hardware_lock, flags);
617
618 /* Reset ISP chip. */
619 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
620
621 /*
622 * We need to have a delay here since the card will not respond while
623 * in reset causing an MCA on some architectures.
624 */
625 udelay(20);
626 data = qla2x00_debounce_register(&reg->ctrl_status);
627 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
628 udelay(5);
629 data = RD_REG_WORD(&reg->ctrl_status);
630 barrier();
631 }
632
633 if (!cnt)
634 goto chip_diag_failed;
635
636 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
Andrew Vasquez76403352009-04-06 22:33:39 -0700637 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638
639 /* Reset RISC processor. */
640 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
641 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
642
643 /* Workaround for QLA2312 PCI parity error */
644 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
645 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
646 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
647 udelay(5);
648 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700649 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651 } else
652 udelay(10);
653
654 if (!cnt)
655 goto chip_diag_failed;
656
657 /* Check product ID of chip */
Andrew Vasquez76403352009-04-06 22:33:39 -0700658 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659
660 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
661 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
662 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
663 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
664 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
665 mb[3] != PROD_ID_3) {
666 qla_printk(KERN_WARNING, ha,
667 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
668
669 goto chip_diag_failed;
670 }
671 ha->product_id[0] = mb[1];
672 ha->product_id[1] = mb[2];
673 ha->product_id[2] = mb[3];
674 ha->product_id[3] = mb[4];
675
676 /* Adjust fw RISC transfer size */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800677 if (req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700678 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
679 else
680 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800681 req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682
683 if (IS_QLA2200(ha) &&
684 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
685 /* Limit firmware transfer size with a 2200A */
686 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800687 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700688
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800689 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 ha->fw_transfer_size = 128;
691 }
692
693 /* Wrap Incoming Mailboxes Test. */
694 spin_unlock_irqrestore(&ha->hardware_lock, flags);
695
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800696 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
697 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 if (rval) {
699 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800700 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 qla_printk(KERN_WARNING, ha,
702 "Failed mailbox send register test\n");
703 }
704 else {
705 /* Flag a successful rval */
706 rval = QLA_SUCCESS;
707 }
708 spin_lock_irqsave(&ha->hardware_lock, flags);
709
710chip_diag_failed:
711 if (rval)
712 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800713 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700714
715 spin_unlock_irqrestore(&ha->hardware_lock, flags);
716
717 return (rval);
718}
719
720/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700721 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
722 * @ha: HA context
723 *
724 * Returns 0 on success.
725 */
726int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700728{
729 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800730 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800731 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -0700732
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800733 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez01071092005-07-06 10:31:37 -0700734
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800735 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700736 if (rval) {
737 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 vha->host_no));
Andrew Vasquez01071092005-07-06 10:31:37 -0700739 qla_printk(KERN_WARNING, ha,
740 "Failed mailbox send register test\n");
741 } else {
742 /* Flag a successful rval */
743 rval = QLA_SUCCESS;
744 }
745
746 return rval;
747}
748
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700749void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800750qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700751{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700752 int rval;
753 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800754 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800755 dma_addr_t tc_dma;
756 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800757 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800758 struct req_que *req = ha->req_q_map[0];
759 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700760
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700761 if (ha->fw_dump) {
762 qla_printk(KERN_WARNING, ha,
763 "Firmware dump previously allocated.\n");
764 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700765 }
766
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700767 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800768 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700769 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
770 fixed_size = sizeof(struct qla2100_fw_dump);
771 } else if (IS_QLA23XX(ha)) {
772 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
773 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
774 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700775 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800776 if (IS_QLA81XX(ha))
777 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
778 else if (IS_QLA25XX(ha))
779 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
780 else
781 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700782 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
783 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800784 if (ha->mqenable)
785 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700786 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800787 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700788 goto try_eft;
789
790 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
791 GFP_KERNEL);
792 if (!tc) {
793 qla_printk(KERN_WARNING, ha, "Unable to allocate "
794 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800795 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700796 }
797
798 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800799 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700800 ha->fce_mb, &ha->fce_bufs);
801 if (rval) {
802 qla_printk(KERN_WARNING, ha, "Unable to initialize "
803 "FCE (%d).\n", rval);
804 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
805 tc_dma);
806 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800807 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700808 }
809
810 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
811 FCE_SIZE / 1024);
812
Giridhar Malavali7d9dade2009-03-24 09:07:58 -0700813 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700814 ha->flags.fce_enabled = 1;
815 ha->fce_dma = tc_dma;
816 ha->fce = tc;
817try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700818 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800819 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700820 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800821 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700822 qla_printk(KERN_WARNING, ha, "Unable to allocate "
823 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
824 goto cont_alloc;
825 }
826
Andrew Vasquezfc447652008-01-17 09:02:18 -0800827 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800828 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700829 if (rval) {
830 qla_printk(KERN_WARNING, ha, "Unable to initialize "
831 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800832 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
833 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700834 goto cont_alloc;
835 }
836
837 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
838 EFT_SIZE / 1024);
839
840 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800841 ha->eft_dma = tc_dma;
842 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700843 }
844cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800845 req_q_size = req->length * sizeof(request_t);
846 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700847
848 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700849 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800850 ha->chain_offset = dump_size;
851 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700852
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700853 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700854 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -0700855 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700856 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700857
858 if (ha->eft) {
859 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
860 ha->eft_dma);
861 ha->eft = NULL;
862 ha->eft_dma = 0;
863 }
864 return;
865 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700866 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
867 dump_size / 1024);
868
869 ha->fw_dump_len = dump_size;
870 ha->fw_dump->signature[0] = 'Q';
871 ha->fw_dump->signature[1] = 'L';
872 ha->fw_dump->signature[2] = 'G';
873 ha->fw_dump->signature[3] = 'C';
874 ha->fw_dump->version = __constant_htonl(1);
875
876 ha->fw_dump->fixed_size = htonl(fixed_size);
877 ha->fw_dump->mem_size = htonl(mem_size);
878 ha->fw_dump->req_q_size = htonl(req_q_size);
879 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
880
881 ha->fw_dump->eft_size = htonl(eft_size);
882 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
883 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
884
885 ha->fw_dump->header_size =
886 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -0700887}
888
889/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890 * qla2x00_setup_chip() - Load and start RISC firmware.
891 * @ha: HA context
892 *
893 * Returns 0 on success.
894 */
895static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800896qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700897{
Andrew Vasquez01071092005-07-06 10:31:37 -0700898 int rval;
899 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800900 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800901 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
902 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700903 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800904
905 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
906 /* Disable SRAM, Instruction RAM and GP RAM parity. */
907 spin_lock_irqsave(&ha->hardware_lock, flags);
908 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
909 RD_REG_WORD(&reg->hccr);
910 spin_unlock_irqrestore(&ha->hardware_lock, flags);
911 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912
913 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800914 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -0700915 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800919 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 if (rval == QLA_SUCCESS) {
921 /* Start firmware execution. */
922 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800923 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700927 if (rval == QLA_SUCCESS) {
928 fw_major_version = ha->fw_major_version;
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700929 rval = qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930 &ha->fw_major_version,
931 &ha->fw_minor_version,
932 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800933 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700934 ha->mpi_version, &ha->mpi_capabilities,
935 ha->phy_version);
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700936 if (rval != QLA_SUCCESS)
937 goto failed;
938
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700939 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800940 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700941 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700942 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700943 if ((!ha->max_npiv_vports) ||
944 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800945 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700946 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800947 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700948 }
Andrew Vasquez24a08132009-03-24 09:08:16 -0700949 qla2x00_get_resource_cnts(vha, NULL,
950 &ha->fw_xcb_count, NULL, NULL,
951 &ha->max_npiv_vports);
Andrew Vasquezd743de62009-03-24 09:08:15 -0700952
953 if (!fw_major_version && ql2xallocfwdump)
954 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700955 }
956 } else {
957 DEBUG2(printk(KERN_INFO
958 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800959 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960 }
961 }
962
Andrew Vasquez3db06522008-01-31 12:33:49 -0800963 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
964 /* Enable proper parity. */
965 spin_lock_irqsave(&ha->hardware_lock, flags);
966 if (IS_QLA2300(ha))
967 /* SRAM parity */
968 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
969 else
970 /* SRAM, Instruction RAM and GP RAM parity */
971 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
972 RD_REG_WORD(&reg->hccr);
973 spin_unlock_irqrestore(&ha->hardware_lock, flags);
974 }
975
Joe Carnuccio1d2874d2009-03-24 09:08:06 -0700976 if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
977 uint32_t size;
978
979 rval = qla81xx_fac_get_sector_size(vha, &size);
980 if (rval == QLA_SUCCESS) {
981 ha->flags.fac_supported = 1;
982 ha->fdt_block_size = size << 2;
983 } else {
984 qla_printk(KERN_ERR, ha,
985 "Unsupported FAC firmware (%d.%02d.%02d).\n",
986 ha->fw_major_version, ha->fw_minor_version,
987 ha->fw_subminor_version);
988 }
989 }
Andrew Vasquezca9e9c32009-06-03 09:55:20 -0700990failed:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700991 if (rval) {
992 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800993 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
995
996 return (rval);
997}
998
999/**
1000 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1001 * @ha: HA context
1002 *
1003 * Beginning of request ring has initialization control block already built
1004 * by nvram config routine.
1005 *
1006 * Returns 0 on success.
1007 */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001008void
1009qla2x00_init_response_q_entries(struct rsp_que *rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010{
1011 uint16_t cnt;
1012 response_t *pkt;
1013
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001014 rsp->ring_ptr = rsp->ring;
1015 rsp->ring_index = 0;
1016 rsp->status_srb = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001017 pkt = rsp->ring_ptr;
1018 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 pkt->signature = RESPONSE_PROCESSED;
1020 pkt++;
1021 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022}
1023
1024/**
1025 * qla2x00_update_fw_options() - Read and process firmware options.
1026 * @ha: HA context
1027 *
1028 * Returns 0 on success.
1029 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001030void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001031qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
1033 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001034 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035
1036 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001037 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001038
1039 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1040 return;
1041
1042 /* Serial Link options. */
1043 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001044 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001045 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1046 sizeof(ha->fw_seriallink_options)));
1047
1048 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1049 if (ha->fw_seriallink_options[3] & BIT_2) {
1050 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1051
1052 /* 1G settings */
1053 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1054 emphasis = (ha->fw_seriallink_options[2] &
1055 (BIT_4 | BIT_3)) >> 3;
1056 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001057 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001058 rx_sens = (ha->fw_seriallink_options[0] &
1059 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1060 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1061 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1062 if (rx_sens == 0x0)
1063 rx_sens = 0x3;
1064 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1065 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1066 ha->fw_options[10] |= BIT_5 |
1067 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1068 (tx_sens & (BIT_1 | BIT_0));
1069
1070 /* 2G settings */
1071 swing = (ha->fw_seriallink_options[2] &
1072 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1073 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1074 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001075 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076 rx_sens = (ha->fw_seriallink_options[1] &
1077 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1078 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1079 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1080 if (rx_sens == 0x0)
1081 rx_sens = 0x3;
1082 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1083 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1084 ha->fw_options[11] |= BIT_5 |
1085 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1086 (tx_sens & (BIT_1 | BIT_0));
1087 }
1088
1089 /* FCP2 options. */
1090 /* Return command IOCBs without waiting for an ABTS to complete. */
1091 ha->fw_options[3] |= BIT_13;
1092
1093 /* LED scheme. */
1094 if (ha->flags.enable_led_scheme)
1095 ha->fw_options[2] |= BIT_12;
1096
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001097 /* Detect ISP6312. */
1098 if (IS_QLA6312(ha))
1099 ha->fw_options[2] |= BIT_13;
1100
Linus Torvalds1da177e2005-04-16 15:20:36 -07001101 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001102 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001103}
1104
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001105void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001106qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001107{
1108 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001109 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001110
1111 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001112 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez01071092005-07-06 10:31:37 -07001113 return;
1114
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001115 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001116 le16_to_cpu(ha->fw_seriallink_options24[1]),
1117 le16_to_cpu(ha->fw_seriallink_options24[2]),
1118 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez01071092005-07-06 10:31:37 -07001119 if (rval != QLA_SUCCESS) {
1120 qla_printk(KERN_WARNING, ha,
1121 "Unable to update Serial Link options (%x).\n", rval);
1122 }
1123}
1124
1125void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001126qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001127{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001128 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001129 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001130 struct req_que *req = ha->req_q_map[0];
1131 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001132
1133 /* Setup ring parameters in initialization control block. */
1134 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1135 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001136 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1137 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1138 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1139 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1140 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1141 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001142
1143 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1144 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1145 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1146 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1147 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1148}
1149
Andrew Vasquez01071092005-07-06 10:31:37 -07001150void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001151qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001152{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001153 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001154 device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0);
1155 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
1156 struct qla_msix_entry *msix;
Andrew Vasquez01071092005-07-06 10:31:37 -07001157 struct init_cb_24xx *icb;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001158 uint16_t rid = 0;
1159 struct req_que *req = ha->req_q_map[0];
1160 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07001161
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001162/* Setup ring parameters in initialization control block. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001163 icb = (struct init_cb_24xx *)ha->init_cb;
1164 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1165 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001166 icb->request_q_length = cpu_to_le16(req->length);
1167 icb->response_q_length = cpu_to_le16(rsp->length);
1168 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1169 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1170 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1171 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez01071092005-07-06 10:31:37 -07001172
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001173 if (ha->mqenable) {
1174 icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS);
1175 icb->rid = __constant_cpu_to_le16(rid);
1176 if (ha->flags.msix_enabled) {
1177 msix = &ha->msix_entries[1];
1178 DEBUG2_17(printk(KERN_INFO
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001179 "Registering vector 0x%x for base que\n", msix->entry));
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001180 icb->msix = cpu_to_le16(msix->entry);
1181 }
1182 /* Use alternate PCI bus number */
1183 if (MSB(rid))
1184 icb->firmware_options_2 |=
1185 __constant_cpu_to_le32(BIT_19);
1186 /* Use alternate PCI devfn */
1187 if (LSB(rid))
1188 icb->firmware_options_2 |=
1189 __constant_cpu_to_le32(BIT_18);
1190
Anirban Chakraborty618a7522009-02-08 20:50:11 -08001191 icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001192 icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001193
1194 WRT_REG_DWORD(&reg->isp25mq.req_q_in, 0);
1195 WRT_REG_DWORD(&reg->isp25mq.req_q_out, 0);
1196 WRT_REG_DWORD(&reg->isp25mq.rsp_q_in, 0);
1197 WRT_REG_DWORD(&reg->isp25mq.rsp_q_out, 0);
1198 } else {
1199 WRT_REG_DWORD(&reg->isp24.req_q_in, 0);
1200 WRT_REG_DWORD(&reg->isp24.req_q_out, 0);
1201 WRT_REG_DWORD(&reg->isp24.rsp_q_in, 0);
1202 WRT_REG_DWORD(&reg->isp24.rsp_q_out, 0);
1203 }
1204 /* PCI posting */
1205 RD_REG_DWORD(&ioreg->hccr);
Andrew Vasquez01071092005-07-06 10:31:37 -07001206}
1207
Linus Torvalds1da177e2005-04-16 15:20:36 -07001208/**
1209 * qla2x00_init_rings() - Initializes firmware.
1210 * @ha: HA context
1211 *
1212 * Beginning of request ring has initialization control block already built
1213 * by nvram config routine.
1214 *
1215 * Returns 0 on success.
1216 */
1217static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001218qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001219{
1220 int rval;
1221 unsigned long flags = 0;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001222 int cnt, que;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001223 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001224 struct req_que *req;
1225 struct rsp_que *rsp;
1226 struct scsi_qla_host *vp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001227 struct mid_init_cb_24xx *mid_init_cb =
1228 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 spin_lock_irqsave(&ha->hardware_lock, flags);
1231
1232 /* Clear outstanding commands array. */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001233 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001234 req = ha->req_q_map[que];
1235 if (!req)
1236 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001237 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001238 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001239
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001240 req->current_outstanding_cmd = 1;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001241
1242 /* Initialize firmware. */
1243 req->ring_ptr = req->ring;
1244 req->ring_index = 0;
1245 req->cnt = req->length;
1246 }
1247
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001248 for (que = 0; que < ha->max_rsp_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001249 rsp = ha->rsp_q_map[que];
1250 if (!rsp)
1251 continue;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001252 /* Initialize response queue entries */
1253 qla2x00_init_response_q_entries(rsp);
1254 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001255
1256 /* Clear RSCN queue. */
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001257 list_for_each_entry(vp, &ha->vp_list, list) {
1258 vp->rscn_in_ptr = 0;
1259 vp->rscn_out_ptr = 0;
1260 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001261 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
1263 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1264
1265 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001266 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001268 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001269
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001270 if (ha->flags.npiv_supported) {
1271 if (ha->operating_mode == LOOP)
1272 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
Seokmann Juc48339d2008-01-17 09:02:19 -08001273 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
Lalit Chandivade605aa2b2009-03-05 11:07:01 -08001274 }
1275
Andrew Vasquez24a08132009-03-24 09:08:16 -07001276 if (IS_FWI2_CAPABLE(ha)) {
1277 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
1278 mid_init_cb->init_cb.execution_throttle =
1279 cpu_to_le16(ha->fw_xcb_count);
1280 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001281
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001282 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283 if (rval) {
1284 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001285 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001286 } else {
1287 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001288 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289 }
1290
1291 return (rval);
1292}
1293
1294/**
1295 * qla2x00_fw_ready() - Waits for firmware ready.
1296 * @ha: HA context
1297 *
1298 * Returns 0 on success.
1299 */
1300static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001301qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001302{
1303 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001304 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001305 uint16_t min_wait; /* Minimum wait time if loop is down */
1306 uint16_t wait_time; /* Wait time if loop is coming ready */
Andrew Vasquez656e8912009-06-03 09:55:29 -07001307 uint16_t state[5];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001309
1310 rval = QLA_SUCCESS;
1311
1312 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001313 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314
1315 /*
1316 * Firmware should take at most one RATOV to login, plus 5 seconds for
1317 * our own processing.
1318 */
1319 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1320 wait_time = min_wait;
1321 }
1322
1323 /* Min wait time if loop down */
1324 mtime = jiffies + (min_wait * HZ);
1325
1326 /* wait time before firmware ready */
1327 wtime = jiffies + (wait_time * HZ);
1328
1329 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001330 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001331 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1332
1333 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001334 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001335
1336 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001337 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001339 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001340 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001342 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1343 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001344 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001345 state[2]));
1346 if ((state[2] & FSTATE_LOGGED_IN) &&
1347 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1348 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001349 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001350
1351 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001352 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001353 if (rval != QLA_SUCCESS)
1354 break;
1355
1356 /* Add time taken to initialize. */
1357 cs84xx_time = jiffies - cs84xx_time;
1358 wtime += cs84xx_time;
1359 mtime += cs84xx_time;
1360 DEBUG16(printk("scsi(%ld): Increasing "
1361 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001363 }
1364 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001365 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001366 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001367
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001368 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001369 &ha->login_timeout, &ha->r_a_tov);
1370
1371 rval = QLA_SUCCESS;
1372 break;
1373 }
1374
1375 rval = QLA_FUNCTION_FAILED;
1376
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001377 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001378 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001379 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001380 * other than Wait for Login.
1381 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001382 if (time_after_eq(jiffies, mtime)) {
1383 qla_printk(KERN_INFO, ha,
1384 "Cable is unplugged...\n");
1385
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387 break;
1388 }
1389 }
1390 } else {
1391 /* Mailbox cmd failed. Timeout on min_wait. */
1392 if (time_after_eq(jiffies, mtime))
1393 break;
1394 }
1395
1396 if (time_after_eq(jiffies, wtime))
1397 break;
1398
1399 /* Delay for a while */
1400 msleep(500);
1401
1402 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001403 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001404 } while (1);
1405
Andrew Vasquez656e8912009-06-03 09:55:29 -07001406 DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n",
1407 vha->host_no, state[0], state[1], state[2], state[3], state[4],
1408 jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409
1410 if (rval) {
1411 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001412 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 }
1414
1415 return (rval);
1416}
1417
1418/*
1419* qla2x00_configure_hba
1420* Setup adapter context.
1421*
1422* Input:
1423* ha = adapter state pointer.
1424*
1425* Returns:
1426* 0 = success
1427*
1428* Context:
1429* Kernel context.
1430*/
1431static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001432qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433{
1434 int rval;
1435 uint16_t loop_id;
1436 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001437 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 uint8_t al_pa;
1439 uint8_t area;
1440 uint8_t domain;
1441 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001442 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001443
1444 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001445 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001446 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001448 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001449 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1450 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001451 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001452 } else {
1453 qla_printk(KERN_WARNING, ha,
1454 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001455 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 return (rval);
1458 }
1459
1460 if (topo == 4) {
1461 qla_printk(KERN_INFO, ha,
1462 "Cannot get topology - retrying.\n");
1463 return (QLA_FUNCTION_FAILED);
1464 }
1465
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001466 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467
1468 /* initialize */
1469 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1470 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001471 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001472
1473 switch (topo) {
1474 case 0:
1475 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001476 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001477 ha->current_topology = ISP_CFG_NL;
1478 strcpy(connect_type, "(Loop)");
1479 break;
1480
1481 case 1:
1482 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001483 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001484 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 ha->current_topology = ISP_CFG_FL;
1486 strcpy(connect_type, "(FL_Port)");
1487 break;
1488
1489 case 2:
1490 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001491 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001492 ha->operating_mode = P2P;
1493 ha->current_topology = ISP_CFG_N;
1494 strcpy(connect_type, "(N_Port-to-N_Port)");
1495 break;
1496
1497 case 3:
1498 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001500 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001501 ha->operating_mode = P2P;
1502 ha->current_topology = ISP_CFG_F;
1503 strcpy(connect_type, "(F_Port)");
1504 break;
1505
1506 default:
1507 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1508 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001509 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 ha->current_topology = ISP_CFG_NL;
1511 strcpy(connect_type, "(Loop)");
1512 break;
1513 }
1514
1515 /* Save Host port and loop ID. */
1516 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001517 vha->d_id.b.domain = domain;
1518 vha->d_id.b.area = area;
1519 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001521 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 qla_printk(KERN_INFO, ha,
1523 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001524 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
1526 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001527 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001529 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 }
1531
1532 return(rval);
1533}
1534
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001535static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001536qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1537 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001538{
1539 char *st, *en;
1540 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001541 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez1b91a2e2009-06-03 09:55:15 -07001542 int use_tbl = !IS_QLA25XX(ha) && !IS_QLA81XX(ha);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001543
1544 if (memcmp(model, BINZERO, len) != 0) {
1545 strncpy(ha->model_number, model, len);
1546 st = en = ha->model_number;
1547 en += len - 1;
1548 while (en > st) {
1549 if (*en != 0x20 && *en != 0x00)
1550 break;
1551 *en-- = '\0';
1552 }
1553
1554 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001555 if (use_tbl &&
1556 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001557 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001558 strncpy(ha->model_desc,
1559 qla2x00_model_name[index * 2 + 1],
1560 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001561 } else {
1562 index = (ha->pdev->subsystem_device & 0xff);
Andrew Vasquez7d0dba12009-04-06 22:33:45 -07001563 if (use_tbl &&
1564 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001565 index < QLA_MODEL_NAMES) {
1566 strcpy(ha->model_number,
1567 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001568 strncpy(ha->model_desc,
1569 qla2x00_model_name[index * 2 + 1],
1570 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001571 } else {
1572 strcpy(ha->model_number, def);
1573 }
1574 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001575 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001576 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001577 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001578}
1579
David Miller4e08df32007-04-16 12:37:43 -07001580/* On sparc systems, obtain port and node WWN from firmware
1581 * properties.
1582 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001583static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001584{
1585#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001586 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001587 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001588 struct device_node *dp = pci_device_to_OF_node(pdev);
1589 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001590 int len;
1591
1592 val = of_get_property(dp, "port-wwn", &len);
1593 if (val && len >= WWN_SIZE)
1594 memcpy(nv->port_name, val, WWN_SIZE);
1595
1596 val = of_get_property(dp, "node-wwn", &len);
1597 if (val && len >= WWN_SIZE)
1598 memcpy(nv->node_name, val, WWN_SIZE);
1599#endif
1600}
1601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602/*
1603* NVRAM configuration for ISP 2xxx
1604*
1605* Input:
1606* ha = adapter block pointer.
1607*
1608* Output:
1609* initialization control block in response_ring
1610* host adapters parameters in host adapter block
1611*
1612* Returns:
1613* 0 = success.
1614*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001615int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001617{
David Miller4e08df32007-04-16 12:37:43 -07001618 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07001619 uint8_t chksum = 0;
1620 uint16_t cnt;
1621 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001622 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001623 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001624 nvram_t *nv = ha->nvram;
1625 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001626 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
David Miller4e08df32007-04-16 12:37:43 -07001628 rval = QLA_SUCCESS;
1629
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001631 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001632 ha->nvram_base = 0;
1633 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1634 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1635 ha->nvram_base = 0x80;
1636
1637 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07001639 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1640 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001642 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001643 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644
1645 /* Bad NVRAM data, set defaults parameters. */
1646 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1647 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1648 /* Reset NVRAM data. */
1649 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1650 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1651 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001652 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1653 "invalid -- WWPN) defaults.\n");
1654
1655 /*
1656 * Set default initialization control block.
1657 */
1658 memset(nv, 0, ha->nvram_size);
1659 nv->parameter_block_version = ICB_VERSION;
1660
1661 if (IS_QLA23XX(ha)) {
1662 nv->firmware_options[0] = BIT_2 | BIT_1;
1663 nv->firmware_options[1] = BIT_7 | BIT_5;
1664 nv->add_firmware_options[0] = BIT_5;
1665 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1666 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1667 nv->special_options[1] = BIT_7;
1668 } else if (IS_QLA2200(ha)) {
1669 nv->firmware_options[0] = BIT_2 | BIT_1;
1670 nv->firmware_options[1] = BIT_7 | BIT_5;
1671 nv->add_firmware_options[0] = BIT_5;
1672 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1673 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1674 } else if (IS_QLA2100(ha)) {
1675 nv->firmware_options[0] = BIT_3 | BIT_1;
1676 nv->firmware_options[1] = BIT_5;
1677 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1678 }
1679
1680 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1681 nv->execution_throttle = __constant_cpu_to_le16(16);
1682 nv->retry_count = 8;
1683 nv->retry_delay = 1;
1684
1685 nv->port_name[0] = 33;
1686 nv->port_name[3] = 224;
1687 nv->port_name[4] = 139;
1688
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001689 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001690
1691 nv->login_timeout = 4;
1692
1693 /*
1694 * Set default host adapter parameters
1695 */
1696 nv->host_p[1] = BIT_2;
1697 nv->reset_delay = 5;
1698 nv->port_down_retry_count = 8;
1699 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1700 nv->link_down_timeout = 60;
1701
1702 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001703 }
1704
1705#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1706 /*
1707 * The SN2 does not provide BIOS emulation which means you can't change
1708 * potentially bogus BIOS settings. Force the use of default settings
1709 * for link rate and frame size. Hope that the rest of the settings
1710 * are valid.
1711 */
1712 if (ia64_platform_is("sn2")) {
1713 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1714 if (IS_QLA23XX(ha))
1715 nv->special_options[1] = BIT_7;
1716 }
1717#endif
1718
1719 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07001720 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721
1722 /*
1723 * Setup driver NVRAM options.
1724 */
1725 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1726 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1727 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1728 nv->firmware_options[1] &= ~BIT_4;
1729
1730 if (IS_QLA23XX(ha)) {
1731 nv->firmware_options[0] |= BIT_2;
1732 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez01071092005-07-06 10:31:37 -07001733 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734
1735 if (IS_QLA2300(ha)) {
1736 if (ha->fb_rev == FPM_2310) {
1737 strcpy(ha->model_number, "QLA2310");
1738 } else {
1739 strcpy(ha->model_number, "QLA2300");
1740 }
1741 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001742 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001743 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 }
1745 } else if (IS_QLA2200(ha)) {
1746 nv->firmware_options[0] |= BIT_2;
1747 /*
1748 * 'Point-to-point preferred, else loop' is not a safe
1749 * connection mode setting.
1750 */
1751 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1752 (BIT_5 | BIT_4)) {
1753 /* Force 'loop preferred, else point-to-point'. */
1754 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1755 nv->add_firmware_options[0] |= BIT_5;
1756 }
1757 strcpy(ha->model_number, "QLA22xx");
1758 } else /*if (IS_QLA2100(ha))*/ {
1759 strcpy(ha->model_number, "QLA2100");
1760 }
1761
1762 /*
1763 * Copy over NVRAM RISC parameter block to initialization control block.
1764 */
1765 dptr1 = (uint8_t *)icb;
1766 dptr2 = (uint8_t *)&nv->parameter_block_version;
1767 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1768 while (cnt--)
1769 *dptr1++ = *dptr2++;
1770
1771 /* Copy 2nd half. */
1772 dptr1 = (uint8_t *)icb->add_firmware_options;
1773 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1774 while (cnt--)
1775 *dptr1++ = *dptr2++;
1776
Andrew Vasquez5341e862006-05-17 15:09:16 -07001777 /* Use alternate WWN? */
1778 if (nv->host_p[1] & BIT_7) {
1779 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1780 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1781 }
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783 /* Prepare nodename */
1784 if ((icb->firmware_options[1] & BIT_6) == 0) {
1785 /*
1786 * Firmware will apply the following mask if the nodename was
1787 * not provided.
1788 */
1789 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1790 icb->node_name[0] &= 0xF0;
1791 }
1792
1793 /*
1794 * Set host adapter parameters.
1795 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001796 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001797 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1799 /* Always load RISC code on non ISP2[12]00 chips. */
1800 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1801 ha->flags.disable_risc_code_load = 0;
1802 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1803 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1804 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001805 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001806 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001807
1808 ha->operating_mode =
1809 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1810
1811 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1812 sizeof(ha->fw_seriallink_options));
1813
1814 /* save HBA serial number */
1815 ha->serial0 = icb->port_name[5];
1816 ha->serial1 = icb->port_name[6];
1817 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001818 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1819 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001820
1821 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1822
1823 ha->retry_count = nv->retry_count;
1824
1825 /* Set minimum login_timeout to 4 seconds. */
1826 if (nv->login_timeout < ql2xlogintimeout)
1827 nv->login_timeout = ql2xlogintimeout;
1828 if (nv->login_timeout < 4)
1829 nv->login_timeout = 4;
1830 ha->login_timeout = nv->login_timeout;
1831 icb->login_timeout = nv->login_timeout;
1832
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001833 /* Set minimum RATOV to 100 tenths of a second. */
1834 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001835
Linus Torvalds1da177e2005-04-16 15:20:36 -07001836 ha->loop_reset_delay = nv->reset_delay;
1837
Linus Torvalds1da177e2005-04-16 15:20:36 -07001838 /* Link Down Timeout = 0:
1839 *
1840 * When Port Down timer expires we will start returning
1841 * I/O's to OS with "DID_NO_CONNECT".
1842 *
1843 * Link Down Timeout != 0:
1844 *
1845 * The driver waits for the link to come up after link down
1846 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001847 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001848 if (nv->link_down_timeout == 0) {
1849 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001850 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001851 } else {
1852 ha->link_down_timeout = nv->link_down_timeout;
1853 ha->loop_down_abort_time =
1854 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001855 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001856
Linus Torvalds1da177e2005-04-16 15:20:36 -07001857 /*
1858 * Need enough time to try and get the port back.
1859 */
1860 ha->port_down_retry_count = nv->port_down_retry_count;
1861 if (qlport_down_retry)
1862 ha->port_down_retry_count = qlport_down_retry;
1863 /* Set login_retry_count */
1864 ha->login_retry_count = nv->retry_count;
1865 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1866 ha->port_down_retry_count > 3)
1867 ha->login_retry_count = ha->port_down_retry_count;
1868 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1869 ha->login_retry_count = ha->port_down_retry_count;
1870 if (ql2xloginretrycount)
1871 ha->login_retry_count = ql2xloginretrycount;
1872
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 icb->lun_enables = __constant_cpu_to_le16(0);
1874 icb->command_resource_count = 0;
1875 icb->immediate_notify_resource_count = 0;
1876 icb->timeout = __constant_cpu_to_le16(0);
1877
1878 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1879 /* Enable RIO */
1880 icb->firmware_options[0] &= ~BIT_3;
1881 icb->add_firmware_options[0] &=
1882 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1883 icb->add_firmware_options[0] |= BIT_2;
1884 icb->response_accumulation_timer = 3;
1885 icb->interrupt_delay_timer = 5;
1886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001889 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001890 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001891 ha->zio_mode = icb->add_firmware_options[0] &
1892 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1893 ha->zio_timer = icb->interrupt_delay_timer ?
1894 icb->interrupt_delay_timer: 2;
1895 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 icb->add_firmware_options[0] &=
1897 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001899 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001900 ha->zio_mode = QLA_ZIO_MODE_6;
1901
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001902 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001903 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001904 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001905 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001906 "ZIO mode %d enabled; timer delay (%d us).\n",
1907 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001909 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1910 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001911 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912 }
1913 }
1914
David Miller4e08df32007-04-16 12:37:43 -07001915 if (rval) {
1916 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001917 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001918 }
1919 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920}
1921
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001922static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001923qla2x00_rport_del(void *data)
1924{
1925 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001926 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001928 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001929 rport = fcport->drport;
1930 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001932 if (rport)
1933 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001934}
1935
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936/**
1937 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1938 * @ha: HA context
1939 * @flags: allocation flags
1940 *
1941 * Returns a pointer to the allocated fcport, or NULL, if none available.
1942 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001943static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001944qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001945{
1946 fc_port_t *fcport;
1947
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001948 fcport = kzalloc(sizeof(fc_port_t), flags);
1949 if (!fcport)
1950 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951
1952 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953 fcport->vha = vha;
1954 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955 fcport->port_type = FCT_UNKNOWN;
1956 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001958 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001959
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001960 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961}
1962
1963/*
1964 * qla2x00_configure_loop
1965 * Updates Fibre Channel Device Database with what is actually on loop.
1966 *
1967 * Input:
1968 * ha = adapter block pointer.
1969 *
1970 * Returns:
1971 * 0 = success.
1972 * 1 = error.
1973 * 2 = database was full and device was not configured.
1974 */
1975static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001976qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977{
1978 int rval;
1979 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981 rval = QLA_SUCCESS;
1982
1983 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1985 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 if (rval != QLA_SUCCESS) {
1987 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989 return (rval);
1990 }
1991 }
1992
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001993 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001995 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001996
1997 /*
1998 * If we have both an RSCN and PORT UPDATE pending then handle them
1999 * both at the same time.
2000 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2002 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002003
2004 /* Determine what we need to do */
2005 if (ha->current_topology == ISP_CFG_FL &&
2006 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002008 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 set_bit(RSCN_UPDATE, &flags);
2010
2011 } else if (ha->current_topology == ISP_CFG_F &&
2012 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2013
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 set_bit(RSCN_UPDATE, &flags);
2016 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2017
Andrew Vasquez21333b42006-05-17 15:09:56 -07002018 } else if (ha->current_topology == ISP_CFG_N) {
2019 clear_bit(RSCN_UPDATE, &flags);
2020
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2023
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002024 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025 set_bit(RSCN_UPDATE, &flags);
2026 set_bit(LOCAL_LOOP_UPDATE, &flags);
2027 }
2028
2029 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002032 else
2033 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 }
2035
2036 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002037 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 else
2040 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 }
2042
2043 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 if (atomic_read(&vha->loop_down_timer) ||
2045 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 rval = QLA_FUNCTION_FAILED;
2047 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002051 }
2052 }
2053
2054 if (rval) {
2055 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002056 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057 } else {
2058 DEBUG3(printk("%s: exiting normally\n", __func__));
2059 }
2060
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002061 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002065 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Andrew Vasquezf4658b62009-06-03 09:55:21 -07002067 vha->flags.rscn_queue_overflow = 1;
2068 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002069 }
2070
2071 return (rval);
2072}
2073
2074
2075
2076/*
2077 * qla2x00_configure_local_loop
2078 * Updates Fibre Channel Device Database with local loop devices.
2079 *
2080 * Input:
2081 * ha = adapter block pointer.
2082 *
2083 * Returns:
2084 * 0 = success.
2085 */
2086static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088{
2089 int rval, rval2;
2090 int found_devs;
2091 int found;
2092 fc_port_t *fcport, *new_fcport;
2093
2094 uint16_t index;
2095 uint16_t entries;
2096 char *id_iter;
2097 uint16_t loop_id;
2098 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002099 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002100
2101 found_devs = 0;
2102 new_fcport = NULL;
2103 entries = MAX_FIBRE_DEVICES;
2104
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002105 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2106 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002107
2108 /* Get list of logged in devices. */
2109 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 &entries);
2112 if (rval != QLA_SUCCESS)
2113 goto cleanup_allocation;
2114
2115 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002116 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2118 entries * sizeof(struct gid_list_info)));
2119
2120 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002121 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122 if (new_fcport == NULL) {
2123 rval = QLA_MEMORY_ALLOC_FAILED;
2124 goto cleanup_allocation;
2125 }
2126 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2127
2128 /*
2129 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2130 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002131 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2133 fcport->port_type != FCT_BROADCAST &&
2134 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2135
2136 DEBUG(printk("scsi(%ld): Marking port lost, "
2137 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002139
2140 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 }
2142 }
2143
2144 /* Add devices to port list. */
2145 id_iter = (char *)ha->gid_list;
2146 for (index = 0; index < entries; index++) {
2147 domain = ((struct gid_list_info *)id_iter)->domain;
2148 area = ((struct gid_list_info *)id_iter)->area;
2149 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002150 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151 loop_id = (uint16_t)
2152 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002153 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002154 loop_id = le16_to_cpu(
2155 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002156 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002157
2158 /* Bypass reserved domain fields. */
2159 if ((domain & 0xf0) == 0xf0)
2160 continue;
2161
2162 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002163 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002164 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165 continue;
2166
2167 /* Bypass invalid local loop ID. */
2168 if (loop_id > LAST_LOCAL_LOOP_ID)
2169 continue;
2170
2171 /* Fill in member data. */
2172 new_fcport->d_id.b.domain = domain;
2173 new_fcport->d_id.b.area = area;
2174 new_fcport->d_id.b.al_pa = al_pa;
2175 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002176 new_fcport->vp_idx = vha->vp_idx;
2177 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002178 if (rval2 != QLA_SUCCESS) {
2179 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2180 "information -- get_port_database=%x, "
2181 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002182 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002183 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002184 vha->host_no));
2185 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 continue;
2187 }
2188
2189 /* Check for matching device in port list. */
2190 found = 0;
2191 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002192 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002193 if (memcmp(new_fcport->port_name, fcport->port_name,
2194 WWN_SIZE))
2195 continue;
2196
Shyam Sundarddb9b122009-03-24 09:08:10 -07002197 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 fcport->loop_id = new_fcport->loop_id;
2199 fcport->port_type = new_fcport->port_type;
2200 fcport->d_id.b24 = new_fcport->d_id.b24;
2201 memcpy(fcport->node_name, new_fcport->node_name,
2202 WWN_SIZE);
2203
2204 found++;
2205 break;
2206 }
2207
2208 if (!found) {
2209 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002210 if (vha->vp_idx) {
2211 new_fcport->vha = vha;
2212 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002213 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002214 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002215
2216 /* Allocate a new replacement fcport. */
2217 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002218 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002219 if (new_fcport == NULL) {
2220 rval = QLA_MEMORY_ALLOC_FAILED;
2221 goto cleanup_allocation;
2222 }
2223 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2224 }
2225
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002226 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002227 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002228
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
2231 found_devs++;
2232 }
2233
2234cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002235 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236
2237 if (rval != QLA_SUCCESS) {
2238 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002239 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002240 }
2241
Linus Torvalds1da177e2005-04-16 15:20:36 -07002242 return (rval);
2243}
2244
2245static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002247{
2248#define LS_UNKNOWN 2
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002249 static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" };
2250 char *link_speed;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002251 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002252 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002254
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002255 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002256 return;
2257
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002258 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2259 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002260 return;
2261
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002262 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002263 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002264 if (rval != QLA_SUCCESS) {
2265 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2266 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002268 fcport->port_name[2], fcport->port_name[3],
2269 fcport->port_name[4], fcport->port_name[5],
2270 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002271 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002272 } else {
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002273 link_speed = link_speeds[LS_UNKNOWN];
2274 if (fcport->fp_speed < 5)
2275 link_speed = link_speeds[fcport->fp_speed];
2276 else if (fcport->fp_speed == 0x13)
2277 link_speed = link_speeds[5];
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002278 DEBUG2(qla_printk(KERN_INFO, ha,
2279 "iIDMA adjusted to %s GB/s on "
2280 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasquez9f8fdde2009-06-03 09:55:22 -07002281 link_speed, fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002282 fcport->port_name[1], fcport->port_name[2],
2283 fcport->port_name[3], fcport->port_name[4],
2284 fcport->port_name[5], fcport->port_name[6],
2285 fcport->port_name[7]));
2286 }
2287}
2288
Adrian Bunk23be3312006-11-24 02:46:01 +01002289static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e112005-04-17 15:04:54 -05002291{
2292 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002293 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002294 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05002295
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002296 if (fcport->drport)
2297 qla2x00_rport_del(fcport);
8482e112005-04-17 15:04:54 -05002298
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002299 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2300 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002301 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2302 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2303 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002304 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002305 if (!rport) {
2306 qla_printk(KERN_WARNING, ha,
2307 "Unable to allocate fc remote port!\n");
2308 return;
2309 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002310 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002311 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002312 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002313
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002314 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002315
2316 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002317 if (fcport->port_type == FCT_INITIATOR)
2318 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2319 if (fcport->port_type == FCT_TARGET)
2320 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002321 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e112005-04-17 15:04:54 -05002322}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002323
2324/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002325 * qla2x00_update_fcport
2326 * Updates device on list.
2327 *
2328 * Input:
2329 * ha = adapter block pointer.
2330 * fcport = port structure pointer.
2331 *
2332 * Return:
2333 * 0 - Success
2334 * BIT_0 - error
2335 *
2336 * Context:
2337 * Kernel context.
2338 */
2339void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002340qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002341{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002342 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002343
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002344 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002345 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002346 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002347 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002348 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002349 PORT_RETRY_TIME);
2350 fcport->flags &= ~FCF_LOGIN_NEEDED;
2351
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002353
2354 atomic_set(&fcport->state, FCS_ONLINE);
2355
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002356 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002357}
2358
2359/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 * qla2x00_configure_fabric
2361 * Setup SNS devices with loop ID's.
2362 *
2363 * Input:
2364 * ha = adapter block pointer.
2365 *
2366 * Returns:
2367 * 0 = success.
2368 * BIT_0 = error
2369 */
2370static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372{
2373 int rval, rval2;
2374 fc_port_t *fcport, *fcptemp;
2375 uint16_t next_loopid;
2376 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002377 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002379 struct qla_hw_data *ha = vha->hw;
2380 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381
2382 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002383 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002384 loop_id = NPH_F_PORT;
2385 else
2386 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002387 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 if (rval != QLA_SUCCESS) {
2389 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002390 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002391
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002392 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002393 return (QLA_SUCCESS);
2394 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002395 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002396
2397 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002398 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 if (rval2 == QLA_RSCNS_HANDLED) {
2400 /* No point doing the scan, just continue. */
2401 return (QLA_SUCCESS);
2402 }
2403 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002404 /* FDMI support. */
2405 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002406 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2407 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002408
Linus Torvalds1da177e2005-04-16 15:20:36 -07002409 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002410 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002411 loop_id = NPH_SNS;
2412 else
2413 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002415 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002416 if (mb[0] != MBS_COMMAND_COMPLETE) {
2417 DEBUG2(qla_printk(KERN_INFO, ha,
2418 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002419 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002420 mb[0], mb[1], mb[2], mb[6], mb[7]));
2421 return (QLA_SUCCESS);
2422 }
2423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002424 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2425 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 /* EMPTY */
2427 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002428 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002429 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002430 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 /* EMPTY */
2432 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002434 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002435 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002436 /* EMPTY */
2437 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002438 "failed.\n", vha->host_no));
2439 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002440 /* EMPTY */
2441 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002442 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 }
2444 }
2445
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002446 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002447 if (rval != QLA_SUCCESS)
2448 break;
2449
2450 /*
2451 * Logout all previous fabric devices marked lost, except
2452 * tape devices.
2453 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002454 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2455 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456 break;
2457
2458 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2459 continue;
2460
2461 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002462 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002463 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 if (fcport->loop_id != FC_NO_LOOP_ID &&
2465 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2466 fcport->port_type != FCT_INITIATOR &&
2467 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002469 fcport->loop_id,
2470 fcport->d_id.b.domain,
2471 fcport->d_id.b.area,
2472 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002473 fcport->loop_id = FC_NO_LOOP_ID;
2474 }
2475 }
2476 }
2477
2478 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002479 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480
2481 /*
2482 * Scan through our port list and login entries that need to be
2483 * logged in.
2484 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2486 if (atomic_read(&vha->loop_down_timer) ||
2487 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 break;
2489
2490 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2491 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2492 continue;
2493
2494 if (fcport->loop_id == FC_NO_LOOP_ID) {
2495 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002496 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498 if (rval != QLA_SUCCESS) {
2499 /* Ran out of IDs to use */
2500 break;
2501 }
2502 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002505 }
2506
2507 /* Exit if out of loop IDs. */
2508 if (rval != QLA_SUCCESS) {
2509 break;
2510 }
2511
2512 /*
2513 * Login and add the new devices to our port list.
2514 */
2515 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002516 if (atomic_read(&vha->loop_down_timer) ||
2517 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518 break;
2519
2520 /* Find a new loop ID to use. */
2521 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002522 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002523 if (rval != QLA_SUCCESS) {
2524 /* Ran out of IDs to use */
2525 break;
2526 }
2527
bdf79622005-04-17 15:06:53 -05002528 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002529 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002530
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002531 if (vha->vp_idx) {
2532 fcport->vha = vha;
2533 fcport->vp_idx = vha->vp_idx;
2534 }
2535 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 }
2537 } while (0);
2538
2539 /* Free all new device structures not processed. */
2540 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2541 list_del(&fcport->list);
2542 kfree(fcport);
2543 }
2544
2545 if (rval) {
2546 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548 }
2549
2550 return (rval);
2551}
2552
2553
2554/*
2555 * qla2x00_find_all_fabric_devs
2556 *
2557 * Input:
2558 * ha = adapter block pointer.
2559 * dev = database device entry pointer.
2560 *
2561 * Returns:
2562 * 0 = success.
2563 *
2564 * Context:
2565 * Kernel context.
2566 */
2567static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2569 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570{
2571 int rval;
2572 uint16_t loop_id;
2573 fc_port_t *fcport, *new_fcport, *fcptemp;
2574 int found;
2575
2576 sw_info_t *swl;
2577 int swl_idx;
2578 int first_dev, last_dev;
2579 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002580 struct qla_hw_data *ha = vha->hw;
2581 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002582 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583
2584 rval = QLA_SUCCESS;
2585
2586 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002587 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002588 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 /*EMPTY*/
2590 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002593 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 kfree(swl);
2595 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002596 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597 kfree(swl);
2598 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600 kfree(swl);
2601 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002602 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002603 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2604 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 }
2606 }
2607 swl_idx = 0;
2608
2609 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002610 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002611 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002612 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002613 return (QLA_MEMORY_ALLOC_FAILED);
2614 }
2615 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002616 /* Set start port ID scan at adapter ID. */
2617 first_dev = 1;
2618 last_dev = 0;
2619
2620 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002621 loop_id = ha->min_external_loopid;
2622 for (; loop_id <= ha->max_loop_id; loop_id++) {
2623 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002624 continue;
2625
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002626 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002627 break;
2628
2629 if (swl != NULL) {
2630 if (last_dev) {
2631 wrap.b24 = new_fcport->d_id.b24;
2632 } else {
2633 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2634 memcpy(new_fcport->node_name,
2635 swl[swl_idx].node_name, WWN_SIZE);
2636 memcpy(new_fcport->port_name,
2637 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002638 memcpy(new_fcport->fabric_port_name,
2639 swl[swl_idx].fabric_port_name, WWN_SIZE);
2640 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
2642 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2643 last_dev = 1;
2644 }
2645 swl_idx++;
2646 }
2647 } else {
2648 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002649 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 if (rval != QLA_SUCCESS) {
2651 qla_printk(KERN_WARNING, ha,
2652 "SNS scan failed -- assuming zero-entry "
2653 "result...\n");
2654 list_for_each_entry_safe(fcport, fcptemp,
2655 new_fcports, list) {
2656 list_del(&fcport->list);
2657 kfree(fcport);
2658 }
2659 rval = QLA_SUCCESS;
2660 break;
2661 }
2662 }
2663
2664 /* If wrap on switch device list, exit. */
2665 if (first_dev) {
2666 wrap.b24 = new_fcport->d_id.b24;
2667 first_dev = 0;
2668 } else if (new_fcport->d_id.b24 == wrap.b24) {
2669 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002670 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002671 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2672 break;
2673 }
2674
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002675 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677 continue;
2678
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002679 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002680 found = 0;
2681 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002682 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002683 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2684 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002685 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002686 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002687 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002688 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002689 continue;
2690 }
2691
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002692 /* Bypass if same domain and area of adapter. */
2693 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002694 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002695 ISP_CFG_FL)
2696 continue;
2697
Linus Torvalds1da177e2005-04-16 15:20:36 -07002698 /* Bypass reserved domain fields. */
2699 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2700 continue;
2701
2702 /* Locate matching device in database. */
2703 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002704 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705 if (memcmp(new_fcport->port_name, fcport->port_name,
2706 WWN_SIZE))
2707 continue;
2708
2709 found++;
2710
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002711 /* Update port state. */
2712 memcpy(fcport->fabric_port_name,
2713 new_fcport->fabric_port_name, WWN_SIZE);
2714 fcport->fp_speed = new_fcport->fp_speed;
2715
Linus Torvalds1da177e2005-04-16 15:20:36 -07002716 /*
2717 * If address the same and state FCS_ONLINE, nothing
2718 * changed.
2719 */
2720 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2721 atomic_read(&fcport->state) == FCS_ONLINE) {
2722 break;
2723 }
2724
2725 /*
2726 * If device was not a fabric device before.
2727 */
2728 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2729 fcport->d_id.b24 = new_fcport->d_id.b24;
2730 fcport->loop_id = FC_NO_LOOP_ID;
2731 fcport->flags |= (FCF_FABRIC_DEVICE |
2732 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 break;
2734 }
2735
2736 /*
2737 * Port ID changed or device was marked to be updated;
2738 * Log it out if still logged in and mark it for
2739 * relogin later.
2740 */
2741 fcport->d_id.b24 = new_fcport->d_id.b24;
2742 fcport->flags |= FCF_LOGIN_NEEDED;
2743 if (fcport->loop_id != FC_NO_LOOP_ID &&
2744 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2745 fcport->port_type != FCT_INITIATOR &&
2746 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002747 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002748 fcport->d_id.b.domain, fcport->d_id.b.area,
2749 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 fcport->loop_id = FC_NO_LOOP_ID;
2751 }
2752
2753 break;
2754 }
2755
2756 if (found)
2757 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002758 /* If device was not in our fcports list, then add it. */
2759 list_add_tail(&new_fcport->list, new_fcports);
2760
2761 /* Allocate a new replacement fcport. */
2762 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002763 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002764 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002765 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002766 return (QLA_MEMORY_ALLOC_FAILED);
2767 }
2768 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2769 new_fcport->d_id.b24 = nxt_d_id.b24;
2770 }
2771
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002772 kfree(swl);
2773 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 return (rval);
2776}
2777
2778/*
2779 * qla2x00_find_new_loop_id
2780 * Scan through our port list and find a new usable loop ID.
2781 *
2782 * Input:
2783 * ha: adapter state pointer.
2784 * dev: port structure pointer.
2785 *
2786 * Returns:
2787 * qla2x00 local function return status code.
2788 *
2789 * Context:
2790 * Kernel context.
2791 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002792static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002793qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002794{
2795 int rval;
2796 int found;
2797 fc_port_t *fcport;
2798 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799 struct qla_hw_data *ha = vha->hw;
2800 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002801 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802
2803 rval = QLA_SUCCESS;
2804
2805 /* Save starting loop ID. */
2806 first_loop_id = dev->loop_id;
2807
2808 for (;;) {
2809 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002810 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812
2813 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002814 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816
2817 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002818 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 /* first loop ID. */
2820 dev->loop_id = ha->min_external_loopid;
2821 }
2822
2823 /* Check for loop ID being already in use. */
2824 found = 0;
2825 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002826 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2828 if (fcport->loop_id == dev->loop_id &&
2829 fcport != dev) {
2830 /* ID possibly in use */
2831 found++;
2832 break;
2833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002835 if (found)
2836 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837 }
2838
2839 /* If not in use then it is free to use. */
2840 if (!found) {
2841 break;
2842 }
2843
2844 /* ID in use. Try next value. */
2845 dev->loop_id++;
2846
2847 /* If wrap around. No free ID to use. */
2848 if (dev->loop_id == first_loop_id) {
2849 dev->loop_id = FC_NO_LOOP_ID;
2850 rval = QLA_FUNCTION_FAILED;
2851 break;
2852 }
2853 }
2854
2855 return (rval);
2856}
2857
2858/*
2859 * qla2x00_device_resync
2860 * Marks devices in the database that needs resynchronization.
2861 *
2862 * Input:
2863 * ha = adapter block pointer.
2864 *
2865 * Context:
2866 * Kernel context.
2867 */
2868static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002870{
2871 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 uint32_t mask;
2873 fc_port_t *fcport;
2874 uint32_t rscn_entry;
2875 uint8_t rscn_out_iter;
2876 uint8_t format;
2877 port_id_t d_id;
2878
2879 rval = QLA_RSCNS_HANDLED;
2880
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2882 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002884 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002885 format = MSB(MSW(rscn_entry));
2886 d_id.b.domain = LSB(MSW(rscn_entry));
2887 d_id.b.area = MSB(LSW(rscn_entry));
2888 d_id.b.al_pa = LSB(LSW(rscn_entry));
2889
2890 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2891 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002892 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 d_id.b.area, d_id.b.al_pa));
2894
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895 vha->rscn_out_ptr++;
2896 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2897 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002898
2899 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002900 for (rscn_out_iter = vha->rscn_out_ptr;
2901 !vha->flags.rscn_queue_overflow &&
2902 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 rscn_out_iter = (rscn_out_iter ==
2904 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2905
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002906 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002907 break;
2908
2909 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 rscn_out_iter));
2912
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 }
2915
2916 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002917 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920
2921 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002922 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 }
2924
2925 switch (format) {
2926 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 mask = 0xffffff;
2928 break;
2929 case 1:
2930 mask = 0xffff00;
2931 break;
2932 case 2:
2933 mask = 0xff0000;
2934 break;
2935 default:
2936 mask = 0x0;
2937 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002938 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002939 break;
2940 }
2941
2942 rval = QLA_SUCCESS;
2943
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002944 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2946 (fcport->d_id.b24 & mask) != d_id.b24 ||
2947 fcport->port_type == FCT_BROADCAST)
2948 continue;
2949
2950 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2951 if (format != 3 ||
2952 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002953 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002954 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002955 }
2956 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002957 }
2958 }
2959 return (rval);
2960}
2961
2962/*
2963 * qla2x00_fabric_dev_login
2964 * Login fabric target device and update FC port database.
2965 *
2966 * Input:
2967 * ha: adapter state pointer.
2968 * fcport: port structure list pointer.
2969 * next_loopid: contains value of a new loop ID that can be used
2970 * by the next login attempt.
2971 *
2972 * Returns:
2973 * qla2x00 local function return status code.
2974 *
2975 * Context:
2976 * Kernel context.
2977 */
2978static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002980 uint16_t *next_loopid)
2981{
2982 int rval;
2983 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07002984 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986
2987 rval = QLA_SUCCESS;
2988 retry = 0;
2989
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002990 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002991 if (rval == QLA_SUCCESS) {
Andrew Vasquez01071092005-07-06 10:31:37 -07002992 /* Send an ADISC to tape devices.*/
2993 opts = 0;
2994 if (fcport->flags & FCF_TAPE_PRESENT)
2995 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002996 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002997 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002998 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002999 fcport->d_id.b.domain, fcport->d_id.b.area,
3000 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003001 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003002 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003003 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004 }
3005 }
3006
3007 return (rval);
3008}
3009
3010/*
3011 * qla2x00_fabric_login
3012 * Issue fabric login command.
3013 *
3014 * Input:
3015 * ha = adapter block pointer.
3016 * device = pointer to FC device type structure.
3017 *
3018 * Returns:
3019 * 0 - Login successfully
3020 * 1 - Login failed
3021 * 2 - Initiator device
3022 * 3 - Fatal error
3023 */
3024int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003025qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 uint16_t *next_loopid)
3027{
3028 int rval;
3029 int retry;
3030 uint16_t tmp_loopid;
3031 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033
3034 retry = 0;
3035 tmp_loopid = 0;
3036
3037 for (;;) {
3038 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3039 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003040 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003041 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3042
3043 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003044 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003045 fcport->d_id.b.domain, fcport->d_id.b.area,
3046 fcport->d_id.b.al_pa, mb, BIT_0);
3047 if (mb[0] == MBS_PORT_ID_USED) {
3048 /*
3049 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07003050 * recommends the driver perform an implicit login with
3051 * the specified ID again. The ID we just used is save
3052 * here so we return with an ID that can be tried by
3053 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 */
3055 retry++;
3056 tmp_loopid = fcport->loop_id;
3057 fcport->loop_id = mb[1];
3058
3059 DEBUG(printk("Fabric Login: port in use - next "
3060 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3061 fcport->loop_id, fcport->d_id.b.domain,
3062 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3063
3064 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3065 /*
3066 * Login succeeded.
3067 */
3068 if (retry) {
3069 /* A retry occurred before. */
3070 *next_loopid = tmp_loopid;
3071 } else {
3072 /*
3073 * No retry occurred before. Just increment the
3074 * ID value for next login.
3075 */
3076 *next_loopid = (fcport->loop_id + 1);
3077 }
3078
3079 if (mb[1] & BIT_0) {
3080 fcport->port_type = FCT_INITIATOR;
3081 } else {
3082 fcport->port_type = FCT_TARGET;
3083 if (mb[1] & BIT_1) {
3084 fcport->flags |= FCF_TAPE_PRESENT;
3085 }
3086 }
3087
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003088 if (mb[10] & BIT_0)
3089 fcport->supported_classes |= FC_COS_CLASS2;
3090 if (mb[10] & BIT_1)
3091 fcport->supported_classes |= FC_COS_CLASS3;
3092
Linus Torvalds1da177e2005-04-16 15:20:36 -07003093 rval = QLA_SUCCESS;
3094 break;
3095 } else if (mb[0] == MBS_LOOP_ID_USED) {
3096 /*
3097 * Loop ID already used, try next loop ID.
3098 */
3099 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003100 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 if (rval != QLA_SUCCESS) {
3102 /* Ran out of loop IDs to use */
3103 break;
3104 }
3105 } else if (mb[0] == MBS_COMMAND_ERROR) {
3106 /*
3107 * Firmware possibly timed out during login. If NO
3108 * retries are left to do then the device is declared
3109 * dead.
3110 */
3111 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003112 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003113 fcport->d_id.b.domain, fcport->d_id.b.area,
3114 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003115 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003116
3117 rval = 1;
3118 break;
3119 } else {
3120 /*
3121 * unrecoverable / not handled error
3122 */
3123 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003124 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003125 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003126 fcport->d_id.b.domain, fcport->d_id.b.area,
3127 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
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);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003133 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003134 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135
3136 rval = 3;
3137 break;
3138 }
3139 }
3140
3141 return (rval);
3142}
3143
3144/*
3145 * qla2x00_local_device_login
3146 * Issue local device login command.
3147 *
3148 * Input:
3149 * ha = adapter block pointer.
3150 * loop_id = loop id of device to login to.
3151 *
3152 * Returns (Where's the #define!!!!):
3153 * 0 - Login successfully
3154 * 1 - Login failed
3155 * 3 - Fatal error
3156 */
3157int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003158qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003159{
3160 int rval;
3161 uint16_t mb[MAILBOX_REGISTER_COUNT];
3162
3163 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003164 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003165 if (rval == QLA_SUCCESS) {
3166 /* Interrogate mailbox registers for any errors */
3167 if (mb[0] == MBS_COMMAND_ERROR)
3168 rval = 1;
3169 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3170 /* device not in PCB table */
3171 rval = 3;
3172 }
3173
3174 return (rval);
3175}
3176
3177/*
3178 * qla2x00_loop_resync
3179 * Resync with fibre channel devices.
3180 *
3181 * Input:
3182 * ha = adapter block pointer.
3183 *
3184 * Returns:
3185 * 0 = success
3186 */
3187int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003188qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003190 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191 uint32_t wait_time;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07003192 struct req_que *req;
3193 struct rsp_que *rsp;
3194
3195 if (ql2xmultique_tag)
3196 req = vha->hw->req_q_map[0];
3197 else
3198 req = vha->req;
3199 rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003201 atomic_set(&vha->loop_state, LOOP_UPDATE);
3202 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3203 if (vha->flags.online) {
3204 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3206 wait_time = 256;
3207 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003208 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209
Andrew Vasquez01071092005-07-06 10:31:37 -07003210 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003211 qla2x00_marker(vha, req, rsp, 0, 0,
3212 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003213 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
3215 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003216 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003217
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003218 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003219 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003220 } while (!atomic_read(&vha->loop_down_timer) &&
3221 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3222 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3223 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003224 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003225 }
3226
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003227 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003228 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003230 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003232
3233 return (rval);
3234}
3235
Linus Torvalds1da177e2005-04-16 15:20:36 -07003236void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003237qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003238{
3239 fc_port_t *fcport;
3240
3241 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003242 list_for_each_entry(fcport, &vha->vp_fcports, list)
3243 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003244 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003245 qla2x00_rport_del(fcport);
3246}
3247
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248/*
3249* qla2x00_abort_isp
3250* Resets ISP and aborts all outstanding commands.
3251*
3252* Input:
3253* ha = adapter block pointer.
3254*
3255* Returns:
3256* 0 = success
3257*/
3258int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003259qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003261 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 struct qla_hw_data *ha = vha->hw;
3264 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003265 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003266 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003268 if (vha->flags.online) {
3269 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003270 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003271 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003272 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
3274 qla_printk(KERN_INFO, ha,
3275 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003276 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003278 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3279 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3280 atomic_set(&vha->loop_state, LOOP_DOWN);
3281 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003282 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003283 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003284 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 if (!atomic_read(&vha->loop_down_timer))
3286 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287 LOOP_DOWN_TIME);
3288 }
3289
Linus Torvalds1da177e2005-04-16 15:20:36 -07003290 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003292
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003293 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003294
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003295 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003297 if (!qla2x00_restart_isp(vha)) {
3298 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003300 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301 /*
3302 * Issue marker command only when we are going
3303 * to start the I/O .
3304 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003305 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 }
3307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003308 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003310 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003311
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003312 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003314
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003315 if (ha->fce) {
3316 ha->flags.fce_enabled = 1;
3317 memset(ha->fce, 0,
3318 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003319 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003320 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3321 &ha->fce_bufs);
3322 if (rval) {
3323 qla_printk(KERN_WARNING, ha,
3324 "Unable to reinitialize FCE "
3325 "(%d).\n", rval);
3326 ha->flags.fce_enabled = 0;
3327 }
3328 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003329
3330 if (ha->eft) {
3331 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003332 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003333 ha->eft_dma, EFT_NUM_BUFFERS);
3334 if (rval) {
3335 qla_printk(KERN_WARNING, ha,
3336 "Unable to reinitialize EFT "
3337 "(%d).\n", rval);
3338 }
3339 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003340 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003341 vha->flags.online = 1;
3342 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 if (ha->isp_abort_cnt == 0) {
3344 qla_printk(KERN_WARNING, ha,
3345 "ISP error recovery failed - "
3346 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003347 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 * The next call disables the board
3349 * completely.
3350 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003351 ha->isp_ops->reset_adapter(vha);
3352 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003354 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 status = 0;
3356 } else { /* schedule another ISP abort */
3357 ha->isp_abort_cnt--;
3358 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003359 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003360 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003361 status = 1;
3362 }
3363 } else {
3364 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3365 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3366 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003367 vha->host_no, ha->isp_abort_cnt));
3368 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003369 status = 1;
3370 }
3371 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003372
Linus Torvalds1da177e2005-04-16 15:20:36 -07003373 }
3374
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003375 if (!status) {
3376 DEBUG(printk(KERN_INFO
3377 "qla2x00_abort_isp(%ld): succeeded.\n",
3378 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003379 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003380 if (vp->vp_idx)
3381 qla2x00_vp_abort_isp(vp);
3382 }
3383 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003384 qla_printk(KERN_INFO, ha,
3385 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 }
3387
3388 return(status);
3389}
3390
3391/*
3392* qla2x00_restart_isp
3393* restarts the ISP after a reset
3394*
3395* Input:
3396* ha = adapter block pointer.
3397*
3398* Returns:
3399* 0 = success
3400*/
3401static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003403{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003404 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003406 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003407 struct req_que *req = ha->req_q_map[0];
3408 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409
3410 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003411 if (qla2x00_isp_firmware(vha)) {
3412 vha->flags.online = 0;
3413 status = ha->isp_ops->chip_diag(vha);
3414 if (!status)
3415 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003416 }
3417
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 if (!status && !(status = qla2x00_init_rings(vha))) {
3419 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003420 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003421 /* Initialize the queues in use */
3422 qla25xx_init_queues(ha);
3423
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003424 status = qla2x00_fw_ready(vha);
3425 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003426 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003427 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07003428
3429 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003430 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez01071092005-07-06 10:31:37 -07003431
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003432 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003433 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3434 wait_time = 256;
3435 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3437 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003439 } while (!atomic_read(&vha->loop_down_timer) &&
3440 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3441 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3442 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003443 }
3444
3445 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003446 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003447 status = 0;
3448
3449 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3450 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003451 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 }
3453 return (status);
3454}
3455
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003456static int
3457qla25xx_init_queues(struct qla_hw_data *ha)
3458{
3459 struct rsp_que *rsp = NULL;
3460 struct req_que *req = NULL;
3461 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3462 int ret = -1;
3463 int i;
3464
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003465 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003466 rsp = ha->rsp_q_map[i];
3467 if (rsp) {
3468 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003469 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003470 if (ret != QLA_SUCCESS)
3471 DEBUG2_17(printk(KERN_WARNING
3472 "%s Rsp que:%d init failed\n", __func__,
3473 rsp->id));
3474 else
3475 DEBUG2_17(printk(KERN_INFO
3476 "%s Rsp que:%d inited\n", __func__,
3477 rsp->id));
3478 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003479 }
3480 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003481 req = ha->req_q_map[i];
3482 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003483 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003484 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003485 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003486 if (ret != QLA_SUCCESS)
3487 DEBUG2_17(printk(KERN_WARNING
3488 "%s Req que:%d init failed\n", __func__,
3489 req->id));
3490 else
3491 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003492 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003493 req->id));
3494 }
3495 }
3496 return ret;
3497}
3498
Linus Torvalds1da177e2005-04-16 15:20:36 -07003499/*
3500* qla2x00_reset_adapter
3501* Reset adapter.
3502*
3503* Input:
3504* ha = adapter block pointer.
3505*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003506void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003507qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508{
3509 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003510 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003511 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003513 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003514 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003515
Linus Torvalds1da177e2005-04-16 15:20:36 -07003516 spin_lock_irqsave(&ha->hardware_lock, flags);
3517 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3518 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3519 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3520 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3521 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3522}
Andrew Vasquez01071092005-07-06 10:31:37 -07003523
3524void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003525qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003526{
3527 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003528 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003529 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3530
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003531 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003532 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003533
3534 spin_lock_irqsave(&ha->hardware_lock, flags);
3535 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3536 RD_REG_DWORD(&reg->hccr);
3537 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3538 RD_REG_DWORD(&reg->hccr);
3539 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003540
3541 if (IS_NOPOLLING_TYPE(ha))
3542 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003543}
3544
David Miller4e08df32007-04-16 12:37:43 -07003545/* On sparc systems, obtain port and node WWN from firmware
3546 * properties.
3547 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003548static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3549 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003550{
3551#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003552 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003553 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003554 struct device_node *dp = pci_device_to_OF_node(pdev);
3555 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003556 int len;
3557
3558 val = of_get_property(dp, "port-wwn", &len);
3559 if (val && len >= WWN_SIZE)
3560 memcpy(nv->port_name, val, WWN_SIZE);
3561
3562 val = of_get_property(dp, "node-wwn", &len);
3563 if (val && len >= WWN_SIZE)
3564 memcpy(nv->node_name, val, WWN_SIZE);
3565#endif
3566}
3567
Andrew Vasquez01071092005-07-06 10:31:37 -07003568int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003569qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003570{
David Miller4e08df32007-04-16 12:37:43 -07003571 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07003572 struct init_cb_24xx *icb;
3573 struct nvram_24xx *nv;
3574 uint32_t *dptr;
3575 uint8_t *dptr1, *dptr2;
3576 uint32_t chksum;
3577 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003579
David Miller4e08df32007-04-16 12:37:43 -07003580 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07003581 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003582 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07003583
3584 /* Determine NVRAM starting address. */
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003585 if (ha->flags.port0) {
3586 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
3587 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3588 } else {
Andrew Vasquez01071092005-07-06 10:31:37 -07003589 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003590 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3591 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003592 ha->nvram_size = sizeof(struct nvram_24xx);
3593 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez01071092005-07-06 10:31:37 -07003594
Seokmann Ju281afe12007-07-26 13:43:34 -07003595 /* Get VPD data into cache */
3596 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003597 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003598 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3599
3600 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07003601 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003602 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07003603 ha->nvram_size);
3604 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3605 chksum += le32_to_cpu(*dptr++);
3606
Andrew Vasquez76403352009-04-06 22:33:39 -07003607 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003608 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07003609
3610 /* Bad NVRAM data, set defaults parameters. */
3611 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3612 || nv->id[3] != ' ' ||
3613 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3614 /* Reset NVRAM data. */
3615 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3616 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3617 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003618 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3619 "invalid -- WWPN) defaults.\n");
3620
3621 /*
3622 * Set default initialization control block.
3623 */
3624 memset(nv, 0, ha->nvram_size);
3625 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3626 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3627 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3628 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3629 nv->exchange_count = __constant_cpu_to_le16(0);
3630 nv->hard_address = __constant_cpu_to_le16(124);
3631 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07003632 nv->port_name[1] = 0x00 + ha->port_no;
David Miller4e08df32007-04-16 12:37:43 -07003633 nv->port_name[2] = 0x00;
3634 nv->port_name[3] = 0xe0;
3635 nv->port_name[4] = 0x8b;
3636 nv->port_name[5] = 0x1c;
3637 nv->port_name[6] = 0x55;
3638 nv->port_name[7] = 0x86;
3639 nv->node_name[0] = 0x20;
3640 nv->node_name[1] = 0x00;
3641 nv->node_name[2] = 0x00;
3642 nv->node_name[3] = 0xe0;
3643 nv->node_name[4] = 0x8b;
3644 nv->node_name[5] = 0x1c;
3645 nv->node_name[6] = 0x55;
3646 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003647 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003648 nv->login_retry_count = __constant_cpu_to_le16(8);
3649 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3650 nv->login_timeout = __constant_cpu_to_le16(0);
3651 nv->firmware_options_1 =
3652 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3653 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3654 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3655 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3656 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3657 nv->efi_parameters = __constant_cpu_to_le32(0);
3658 nv->reset_delay = 5;
3659 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3660 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3661 nv->link_down_timeout = __constant_cpu_to_le16(30);
3662
3663 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07003664 }
3665
3666 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003667 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003668
3669 /* Copy 1st segment. */
3670 dptr1 = (uint8_t *)icb;
3671 dptr2 = (uint8_t *)&nv->version;
3672 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3673 while (cnt--)
3674 *dptr1++ = *dptr2++;
3675
3676 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003677 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07003678
3679 /* Copy 2nd segment. */
3680 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3681 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3682 cnt = (uint8_t *)&icb->reserved_3 -
3683 (uint8_t *)&icb->interrupt_delay_timer;
3684 while (cnt--)
3685 *dptr1++ = *dptr2++;
3686
3687 /*
3688 * Setup driver NVRAM options.
3689 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003690 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003691 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07003692
Andrew Vasquez5341e862006-05-17 15:09:16 -07003693 /* Use alternate WWN? */
3694 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3695 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3696 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3697 }
3698
Andrew Vasquez01071092005-07-06 10:31:37 -07003699 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003700 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003701 /*
3702 * Firmware will apply the following mask if the nodename was
3703 * not provided.
3704 */
3705 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3706 icb->node_name[0] &= 0xF0;
3707 }
3708
3709 /* Set host adapter parameters. */
3710 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003711 ha->flags.enable_lip_reset = 0;
3712 ha->flags.enable_lip_full_login =
3713 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3714 ha->flags.enable_target_reset =
3715 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003716 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003717 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003718
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003719 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3720 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07003721
3722 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3723 sizeof(ha->fw_seriallink_options24));
3724
3725 /* save HBA serial number */
3726 ha->serial0 = icb->port_name[5];
3727 ha->serial1 = icb->port_name[6];
3728 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003729 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3730 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez01071092005-07-06 10:31:37 -07003731
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003732 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3733
Andrew Vasquez01071092005-07-06 10:31:37 -07003734 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3735
3736 /* Set minimum login_timeout to 4 seconds. */
3737 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3738 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3739 if (le16_to_cpu(nv->login_timeout) < 4)
3740 nv->login_timeout = __constant_cpu_to_le16(4);
3741 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003742 icb->login_timeout = nv->login_timeout;
Andrew Vasquez01071092005-07-06 10:31:37 -07003743
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003744 /* Set minimum RATOV to 100 tenths of a second. */
3745 ha->r_a_tov = 100;
Andrew Vasquez01071092005-07-06 10:31:37 -07003746
3747 ha->loop_reset_delay = nv->reset_delay;
3748
3749 /* Link Down Timeout = 0:
3750 *
3751 * When Port Down timer expires we will start returning
3752 * I/O's to OS with "DID_NO_CONNECT".
3753 *
3754 * Link Down Timeout != 0:
3755 *
3756 * The driver waits for the link to come up after link down
3757 * before returning I/Os to OS with "DID_NO_CONNECT".
3758 */
3759 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3760 ha->loop_down_abort_time =
3761 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3762 } else {
3763 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3764 ha->loop_down_abort_time =
3765 (LOOP_DOWN_TIME - ha->link_down_timeout);
3766 }
3767
3768 /* Need enough time to try and get the port back. */
3769 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3770 if (qlport_down_retry)
3771 ha->port_down_retry_count = qlport_down_retry;
3772
3773 /* Set login_retry_count */
3774 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3775 if (ha->port_down_retry_count ==
3776 le16_to_cpu(nv->port_down_retry_count) &&
3777 ha->port_down_retry_count > 3)
3778 ha->login_retry_count = ha->port_down_retry_count;
3779 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3780 ha->login_retry_count = ha->port_down_retry_count;
3781 if (ql2xloginretrycount)
3782 ha->login_retry_count = ql2xloginretrycount;
3783
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003784 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003785 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003786 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3787 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3788 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3789 le16_to_cpu(icb->interrupt_delay_timer): 2;
3790 }
3791 icb->firmware_options_2 &= __constant_cpu_to_le32(
3792 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003793 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003794 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003795 ha->zio_mode = QLA_ZIO_MODE_6;
3796
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003797 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003798 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003799 ha->zio_timer * 100));
3800 qla_printk(KERN_INFO, ha,
3801 "ZIO mode %d enabled; timer delay (%d us).\n",
3802 ha->zio_mode, ha->zio_timer * 100);
3803
3804 icb->firmware_options_2 |= cpu_to_le32(
3805 (uint32_t)ha->zio_mode);
3806 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003807 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003808 }
3809
David Miller4e08df32007-04-16 12:37:43 -07003810 if (rval) {
3811 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003812 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003813 }
3814 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07003815}
3816
Adrian Bunk413975a2006-06-30 02:33:06 -07003817static int
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003818qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
3819 uint32_t faddr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003820{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003821 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003822 int segments, fragment;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003823 uint32_t *dcode, dlen;
3824 uint32_t risc_addr;
3825 uint32_t risc_size;
3826 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003827 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003828 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003829
3830 qla_printk(KERN_INFO, ha,
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07003831 "FW: Loading from flash (%x)...\n", faddr);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003832
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003833 rval = QLA_SUCCESS;
3834
3835 segments = FA_RISC_CODE_SEGMENTS;
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
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004007static int
4008qla24xx_load_risc_blob(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
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004028 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004029 }
4030
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004031 qla_printk(KERN_INFO, ha,
4032 "FW: Loading via request-firmware...\n");
4033
Andrew Vasquez01071092005-07-06 10:31:37 -07004034 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
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004118int
4119qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4120{
4121 int rval;
4122
Andrew Vasqueze337d902009-04-06 22:33:49 -07004123 if (ql2xfwloadbin == 1)
4124 return qla81xx_load_risc(vha, srisc_addr);
4125
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004126 /*
4127 * FW Load priority:
4128 * 1) Firmware via request-firmware interface (.bin file).
4129 * 2) Firmware residing in flash.
4130 */
4131 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4132 if (rval == QLA_SUCCESS)
4133 return rval;
4134
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004135 return qla24xx_load_risc_flash(vha, srisc_addr,
4136 vha->hw->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004137}
4138
4139int
4140qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4141{
4142 int rval;
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004143 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004144
Andrew Vasqueze337d902009-04-06 22:33:49 -07004145 if (ql2xfwloadbin == 2)
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004146 goto try_blob_fw;
Andrew Vasqueze337d902009-04-06 22:33:49 -07004147
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004148 /*
4149 * FW Load priority:
4150 * 1) Firmware residing in flash.
4151 * 2) Firmware via request-firmware interface (.bin file).
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004152 * 3) Golden-Firmware residing in flash -- limited operation.
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004153 */
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004154 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004155 if (rval == QLA_SUCCESS)
4156 return rval;
4157
Andrew Vasquezcbc8eb62009-06-03 09:55:17 -07004158try_blob_fw:
4159 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4160 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
4161 return rval;
4162
4163 qla_printk(KERN_ERR, ha,
4164 "FW: Attempting to fallback to golden firmware...\n");
4165 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
4166 if (rval != QLA_SUCCESS)
4167 return rval;
4168
4169 qla_printk(KERN_ERR, ha,
4170 "FW: Please update operational firmware...\n");
4171 ha->flags.running_gold_fw = 1;
4172
4173 return rval;
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004174}
4175
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004176void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004177qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004178{
4179 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004180 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004181
Andrew Vasqueze4289242007-07-19 15:05:56 -07004182 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004183 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004184 if (!ha->fw_major_version)
4185 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004186
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004187 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004188 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
Andrew Vasquezb469a7c2009-04-06 22:33:48 -07004189 ret != QLA_INVALID_COMMAND && retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 ha->isp_ops->reset_chip(vha);
4191 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004192 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004193 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004194 continue;
4195 qla_printk(KERN_INFO, ha,
4196 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004197 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004198 }
4199}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004200
4201int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004202qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004203{
4204 int rval = QLA_SUCCESS;
4205 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004206 struct qla_hw_data *ha = vha->hw;
4207 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004208 struct req_que *req;
4209 struct rsp_que *rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004210
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004211 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004212 return -EINVAL;
4213
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004214 rval = qla2x00_fw_ready(base_vha);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -07004215 if (ql2xmultique_tag)
4216 req = ha->req_q_map[0];
4217 else
4218 req = vha->req;
4219 rsp = req->rsp;
4220
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004221 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004222 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004223 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004224 }
4225
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004226 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004227
4228 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004229 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004230 if (mb[0] != MBS_COMMAND_COMPLETE) {
4231 DEBUG15(qla_printk(KERN_INFO, ha,
4232 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4233 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4234 mb[0], mb[1], mb[2], mb[6], mb[7]));
4235 return (QLA_FUNCTION_FAILED);
4236 }
4237
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004238 atomic_set(&vha->loop_down_timer, 0);
4239 atomic_set(&vha->loop_state, LOOP_UP);
4240 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4241 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4242 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004243
4244 return rval;
4245}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004246
4247/* 84XX Support **************************************************************/
4248
4249static LIST_HEAD(qla_cs84xx_list);
4250static DEFINE_MUTEX(qla_cs84xx_mutex);
4251
4252static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004253qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004254{
4255 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004256 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004257
4258 mutex_lock(&qla_cs84xx_mutex);
4259
4260 /* Find any shared 84xx chip. */
4261 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4262 if (cs84xx->bus == ha->pdev->bus) {
4263 kref_get(&cs84xx->kref);
4264 goto done;
4265 }
4266 }
4267
4268 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4269 if (!cs84xx)
4270 goto done;
4271
4272 kref_init(&cs84xx->kref);
4273 spin_lock_init(&cs84xx->access_lock);
4274 mutex_init(&cs84xx->fw_update_mutex);
4275 cs84xx->bus = ha->pdev->bus;
4276
4277 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4278done:
4279 mutex_unlock(&qla_cs84xx_mutex);
4280 return cs84xx;
4281}
4282
4283static void
4284__qla84xx_chip_release(struct kref *kref)
4285{
4286 struct qla_chip_state_84xx *cs84xx =
4287 container_of(kref, struct qla_chip_state_84xx, kref);
4288
4289 mutex_lock(&qla_cs84xx_mutex);
4290 list_del(&cs84xx->list);
4291 mutex_unlock(&qla_cs84xx_mutex);
4292 kfree(cs84xx);
4293}
4294
4295void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004296qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004297{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004298 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004299 if (ha->cs84xx)
4300 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4301}
4302
4303static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004304qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004305{
4306 int rval;
4307 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004308 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004309
4310 mutex_lock(&ha->cs84xx->fw_update_mutex);
4311
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004312 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004313
4314 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4315
4316 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4317 QLA_SUCCESS;
4318}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004319
4320/* 81XX Support **************************************************************/
4321
4322int
4323qla81xx_nvram_config(scsi_qla_host_t *vha)
4324{
4325 int rval;
4326 struct init_cb_81xx *icb;
4327 struct nvram_81xx *nv;
4328 uint32_t *dptr;
4329 uint8_t *dptr1, *dptr2;
4330 uint32_t chksum;
4331 uint16_t cnt;
4332 struct qla_hw_data *ha = vha->hw;
4333
4334 rval = QLA_SUCCESS;
4335 icb = (struct init_cb_81xx *)ha->init_cb;
4336 nv = ha->nvram;
4337
4338 /* Determine NVRAM starting address. */
4339 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004340 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004341
4342 /* Get VPD data into cache */
4343 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d790382009-03-24 09:08:14 -07004344 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4345 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004346
4347 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d790382009-03-24 09:08:14 -07004348 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004349 ha->nvram_size);
Andrew Vasquez3d790382009-03-24 09:08:14 -07004350 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004351 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4352 chksum += le32_to_cpu(*dptr++);
4353
Andrew Vasquez76403352009-04-06 22:33:39 -07004354 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004355 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4356
4357 /* Bad NVRAM data, set defaults parameters. */
4358 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4359 || nv->id[3] != ' ' ||
4360 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4361 /* Reset NVRAM data. */
4362 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4363 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4364 le16_to_cpu(nv->nvram_version));
4365 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4366 "invalid -- WWPN) defaults.\n");
4367
4368 /*
4369 * Set default initialization control block.
4370 */
4371 memset(nv, 0, ha->nvram_size);
4372 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4373 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4374 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4375 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4376 nv->exchange_count = __constant_cpu_to_le16(0);
4377 nv->port_name[0] = 0x21;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004378 nv->port_name[1] = 0x00 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004379 nv->port_name[2] = 0x00;
4380 nv->port_name[3] = 0xe0;
4381 nv->port_name[4] = 0x8b;
4382 nv->port_name[5] = 0x1c;
4383 nv->port_name[6] = 0x55;
4384 nv->port_name[7] = 0x86;
4385 nv->node_name[0] = 0x20;
4386 nv->node_name[1] = 0x00;
4387 nv->node_name[2] = 0x00;
4388 nv->node_name[3] = 0xe0;
4389 nv->node_name[4] = 0x8b;
4390 nv->node_name[5] = 0x1c;
4391 nv->node_name[6] = 0x55;
4392 nv->node_name[7] = 0x86;
4393 nv->login_retry_count = __constant_cpu_to_le16(8);
4394 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4395 nv->login_timeout = __constant_cpu_to_le16(0);
4396 nv->firmware_options_1 =
4397 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4398 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4399 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4400 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4401 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4402 nv->efi_parameters = __constant_cpu_to_le32(0);
4403 nv->reset_delay = 5;
4404 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4405 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4406 nv->link_down_timeout = __constant_cpu_to_le16(30);
Andrew Vasquezeeebcc92009-06-03 09:55:24 -07004407 nv->enode_mac[0] = 0x00;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004408 nv->enode_mac[1] = 0x02;
4409 nv->enode_mac[2] = 0x03;
4410 nv->enode_mac[3] = 0x04;
4411 nv->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004412 nv->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004413
4414 rval = 1;
4415 }
4416
4417 /* Reset Initialization control block */
4418 memset(icb, 0, sizeof(struct init_cb_81xx));
4419
4420 /* Copy 1st segment. */
4421 dptr1 = (uint8_t *)icb;
4422 dptr2 = (uint8_t *)&nv->version;
4423 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4424 while (cnt--)
4425 *dptr1++ = *dptr2++;
4426
4427 icb->login_retry_count = nv->login_retry_count;
4428
4429 /* Copy 2nd segment. */
4430 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4431 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4432 cnt = (uint8_t *)&icb->reserved_5 -
4433 (uint8_t *)&icb->interrupt_delay_timer;
4434 while (cnt--)
4435 *dptr1++ = *dptr2++;
4436
4437 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4438 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4439 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4440 icb->enode_mac[0] = 0x01;
4441 icb->enode_mac[1] = 0x02;
4442 icb->enode_mac[2] = 0x03;
4443 icb->enode_mac[3] = 0x04;
4444 icb->enode_mac[4] = 0x05;
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07004445 icb->enode_mac[5] = 0x06 + ha->port_no;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004446 }
4447
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004448 /* Use extended-initialization control block. */
4449 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4450
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004451 /*
4452 * Setup driver NVRAM options.
4453 */
4454 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4455 "QLE81XX");
4456
4457 /* Use alternate WWN? */
4458 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4459 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4460 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4461 }
4462
4463 /* Prepare nodename */
4464 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4465 /*
4466 * Firmware will apply the following mask if the nodename was
4467 * not provided.
4468 */
4469 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4470 icb->node_name[0] &= 0xF0;
4471 }
4472
4473 /* Set host adapter parameters. */
4474 ha->flags.disable_risc_code_load = 0;
4475 ha->flags.enable_lip_reset = 0;
4476 ha->flags.enable_lip_full_login =
4477 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4478 ha->flags.enable_target_reset =
4479 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4480 ha->flags.enable_led_scheme = 0;
4481 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4482
4483 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4484 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4485
4486 /* save HBA serial number */
4487 ha->serial0 = icb->port_name[5];
4488 ha->serial1 = icb->port_name[6];
4489 ha->serial2 = icb->port_name[7];
4490 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4491 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4492
4493 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4494
4495 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4496
4497 /* Set minimum login_timeout to 4 seconds. */
4498 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4499 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4500 if (le16_to_cpu(nv->login_timeout) < 4)
4501 nv->login_timeout = __constant_cpu_to_le16(4);
4502 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4503 icb->login_timeout = nv->login_timeout;
4504
4505 /* Set minimum RATOV to 100 tenths of a second. */
4506 ha->r_a_tov = 100;
4507
4508 ha->loop_reset_delay = nv->reset_delay;
4509
4510 /* Link Down Timeout = 0:
4511 *
4512 * When Port Down timer expires we will start returning
4513 * I/O's to OS with "DID_NO_CONNECT".
4514 *
4515 * Link Down Timeout != 0:
4516 *
4517 * The driver waits for the link to come up after link down
4518 * before returning I/Os to OS with "DID_NO_CONNECT".
4519 */
4520 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4521 ha->loop_down_abort_time =
4522 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4523 } else {
4524 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4525 ha->loop_down_abort_time =
4526 (LOOP_DOWN_TIME - ha->link_down_timeout);
4527 }
4528
4529 /* Need enough time to try and get the port back. */
4530 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4531 if (qlport_down_retry)
4532 ha->port_down_retry_count = qlport_down_retry;
4533
4534 /* Set login_retry_count */
4535 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4536 if (ha->port_down_retry_count ==
4537 le16_to_cpu(nv->port_down_retry_count) &&
4538 ha->port_down_retry_count > 3)
4539 ha->login_retry_count = ha->port_down_retry_count;
4540 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4541 ha->login_retry_count = ha->port_down_retry_count;
4542 if (ql2xloginretrycount)
4543 ha->login_retry_count = ql2xloginretrycount;
4544
4545 /* Enable ZIO. */
4546 if (!vha->flags.init_done) {
4547 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4548 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4549 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4550 le16_to_cpu(icb->interrupt_delay_timer): 2;
4551 }
4552 icb->firmware_options_2 &= __constant_cpu_to_le32(
4553 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4554 vha->flags.process_response_queue = 0;
4555 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4556 ha->zio_mode = QLA_ZIO_MODE_6;
4557
4558 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4559 "(%d us).\n", vha->host_no, ha->zio_mode,
4560 ha->zio_timer * 100));
4561 qla_printk(KERN_INFO, ha,
4562 "ZIO mode %d enabled; timer delay (%d us).\n",
4563 ha->zio_mode, ha->zio_timer * 100);
4564
4565 icb->firmware_options_2 |= cpu_to_le32(
4566 (uint32_t)ha->zio_mode);
4567 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4568 vha->flags.process_response_queue = 1;
4569 }
4570
4571 if (rval) {
4572 DEBUG2_3(printk(KERN_WARNING
4573 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4574 }
4575 return (rval);
4576}
4577
4578void
4579qla81xx_update_fw_options(scsi_qla_host_t *ha)
4580{
4581}