blob: 059909c9f29beae4d0c517a98c8e902bcd97e0e0 [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
Andrew Vasquez88c26662005-07-08 17:59:26 -0700733 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 qla24xx_reset_risc(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700735
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800736 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
Andrew Vasquez01071092005-07-06 10:31:37 -0700737
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700739 if (rval) {
740 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800741 vha->host_no));
Andrew Vasquez01071092005-07-06 10:31:37 -0700742 qla_printk(KERN_WARNING, ha,
743 "Failed mailbox send register test\n");
744 } else {
745 /* Flag a successful rval */
746 rval = QLA_SUCCESS;
747 }
748
749 return rval;
750}
751
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700752void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800753qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700754{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700755 int rval;
756 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800757 eft_size, fce_size, mq_size;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800758 dma_addr_t tc_dma;
759 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800760 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800761 struct req_que *req = ha->req_q_map[0];
762 struct rsp_que *rsp = ha->rsp_q_map[0];
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700763
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700764 if (ha->fw_dump) {
765 qla_printk(KERN_WARNING, ha,
766 "Firmware dump previously allocated.\n");
767 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700768 }
769
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700770 ha->fw_dumped = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800771 fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700772 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
773 fixed_size = sizeof(struct qla2100_fw_dump);
774 } else if (IS_QLA23XX(ha)) {
775 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
776 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
777 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700778 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800779 if (IS_QLA81XX(ha))
780 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
781 else if (IS_QLA25XX(ha))
782 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
783 else
784 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700785 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
786 sizeof(uint32_t);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800787 if (ha->mqenable)
788 mq_size = sizeof(struct qla2xxx_mq_chain);
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700789 /* Allocate memory for Fibre Channel Event Buffer. */
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800790 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha))
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700791 goto try_eft;
792
793 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
794 GFP_KERNEL);
795 if (!tc) {
796 qla_printk(KERN_WARNING, ha, "Unable to allocate "
797 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800798 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700799 }
800
801 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800802 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700803 ha->fce_mb, &ha->fce_bufs);
804 if (rval) {
805 qla_printk(KERN_WARNING, ha, "Unable to initialize "
806 "FCE (%d).\n", rval);
807 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
808 tc_dma);
809 ha->flags.fce_enabled = 0;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800810 goto try_eft;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700811 }
812
813 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
814 FCE_SIZE / 1024);
815
Giridhar Malavali7d9dade2009-03-24 09:07:58 -0700816 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700817 ha->flags.fce_enabled = 1;
818 ha->fce_dma = tc_dma;
819 ha->fce = tc;
820try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700821 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800822 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700823 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800824 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700825 qla_printk(KERN_WARNING, ha, "Unable to allocate "
826 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
827 goto cont_alloc;
828 }
829
Andrew Vasquezfc447652008-01-17 09:02:18 -0800830 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700832 if (rval) {
833 qla_printk(KERN_WARNING, ha, "Unable to initialize "
834 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800835 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
836 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700837 goto cont_alloc;
838 }
839
840 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
841 EFT_SIZE / 1024);
842
843 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800844 ha->eft_dma = tc_dma;
845 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700846 }
847cont_alloc:
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800848 req_q_size = req->length * sizeof(request_t);
849 rsp_q_size = rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700850
851 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700852 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
Andrew Vasquezbb99de62009-01-05 11:18:08 -0800853 ha->chain_offset = dump_size;
854 dump_size += mq_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700855
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700856 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700857 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -0700858 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700859 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700860
861 if (ha->eft) {
862 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
863 ha->eft_dma);
864 ha->eft = NULL;
865 ha->eft_dma = 0;
866 }
867 return;
868 }
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700869 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
870 dump_size / 1024);
871
872 ha->fw_dump_len = dump_size;
873 ha->fw_dump->signature[0] = 'Q';
874 ha->fw_dump->signature[1] = 'L';
875 ha->fw_dump->signature[2] = 'G';
876 ha->fw_dump->signature[3] = 'C';
877 ha->fw_dump->version = __constant_htonl(1);
878
879 ha->fw_dump->fixed_size = htonl(fixed_size);
880 ha->fw_dump->mem_size = htonl(mem_size);
881 ha->fw_dump->req_q_size = htonl(req_q_size);
882 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
883
884 ha->fw_dump->eft_size = htonl(eft_size);
885 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
886 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
887
888 ha->fw_dump->header_size =
889 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -0700890}
891
892/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700893 * qla2x00_setup_chip() - Load and start RISC firmware.
894 * @ha: HA context
895 *
896 * Returns 0 on success.
897 */
898static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800899qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700900{
Andrew Vasquez01071092005-07-06 10:31:37 -0700901 int rval;
902 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800904 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
905 unsigned long flags;
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700906 uint16_t fw_major_version;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800907
908 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
909 /* Disable SRAM, Instruction RAM and GP RAM parity. */
910 spin_lock_irqsave(&ha->hardware_lock, flags);
911 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
912 RD_REG_WORD(&reg->hccr);
913 spin_unlock_irqrestore(&ha->hardware_lock, flags);
914 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700915
916 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -0700918 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800920 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 if (rval == QLA_SUCCESS) {
924 /* Start firmware execution. */
925 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800926 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700927
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800928 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 /* Retrieve firmware information. */
Andrew Vasquezdda772e2009-03-24 09:08:00 -0700930 if (rval == QLA_SUCCESS) {
931 fw_major_version = ha->fw_major_version;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800932 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 &ha->fw_major_version,
934 &ha->fw_minor_version,
935 &ha->fw_subminor_version,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800936 &ha->fw_attributes, &ha->fw_memory_size,
Andrew Vasquez55a96152009-03-24 09:08:03 -0700937 ha->mpi_version, &ha->mpi_capabilities,
938 ha->phy_version);
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 }
990
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 */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001307 uint16_t state[3];
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
1406 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001407 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408
1409 if (rval) {
1410 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001411 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001412 }
1413
1414 return (rval);
1415}
1416
1417/*
1418* qla2x00_configure_hba
1419* Setup adapter context.
1420*
1421* Input:
1422* ha = adapter state pointer.
1423*
1424* Returns:
1425* 0 = success
1426*
1427* Context:
1428* Kernel context.
1429*/
1430static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001431qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432{
1433 int rval;
1434 uint16_t loop_id;
1435 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001436 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001437 uint8_t al_pa;
1438 uint8_t area;
1439 uint8_t domain;
1440 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001441 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
1443 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001444 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001445 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001447 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001448 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1449 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001450 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001451 } else {
1452 qla_printk(KERN_WARNING, ha,
1453 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001454 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001455 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 return (rval);
1457 }
1458
1459 if (topo == 4) {
1460 qla_printk(KERN_INFO, ha,
1461 "Cannot get topology - retrying.\n");
1462 return (QLA_FUNCTION_FAILED);
1463 }
1464
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001465 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001466
1467 /* initialize */
1468 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1469 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001470 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001471
1472 switch (topo) {
1473 case 0:
1474 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001475 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 ha->current_topology = ISP_CFG_NL;
1477 strcpy(connect_type, "(Loop)");
1478 break;
1479
1480 case 1:
1481 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001482 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001483 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 ha->current_topology = ISP_CFG_FL;
1485 strcpy(connect_type, "(FL_Port)");
1486 break;
1487
1488 case 2:
1489 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001490 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 ha->operating_mode = P2P;
1492 ha->current_topology = ISP_CFG_N;
1493 strcpy(connect_type, "(N_Port-to-N_Port)");
1494 break;
1495
1496 case 3:
1497 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001499 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500 ha->operating_mode = P2P;
1501 ha->current_topology = ISP_CFG_F;
1502 strcpy(connect_type, "(F_Port)");
1503 break;
1504
1505 default:
1506 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1507 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001508 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001509 ha->current_topology = ISP_CFG_NL;
1510 strcpy(connect_type, "(Loop)");
1511 break;
1512 }
1513
1514 /* Save Host port and loop ID. */
1515 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516 vha->d_id.b.domain = domain;
1517 vha->d_id.b.area = area;
1518 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001520 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 qla_printk(KERN_INFO, ha,
1522 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001523 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001524
1525 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001526 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001528 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001529 }
1530
1531 return(rval);
1532}
1533
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001534static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001535qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1536 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001537{
1538 char *st, *en;
1539 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001540 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001541
1542 if (memcmp(model, BINZERO, len) != 0) {
1543 strncpy(ha->model_number, model, len);
1544 st = en = ha->model_number;
1545 en += len - 1;
1546 while (en > st) {
1547 if (*en != 0x20 && *en != 0x00)
1548 break;
1549 *en-- = '\0';
1550 }
1551
1552 index = (ha->pdev->subsystem_device & 0xff);
1553 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1554 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001555 strncpy(ha->model_desc,
1556 qla2x00_model_name[index * 2 + 1],
1557 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001558 } else {
1559 index = (ha->pdev->subsystem_device & 0xff);
1560 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1561 index < QLA_MODEL_NAMES) {
1562 strcpy(ha->model_number,
1563 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001564 strncpy(ha->model_desc,
1565 qla2x00_model_name[index * 2 + 1],
1566 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001567 } else {
1568 strcpy(ha->model_number, def);
1569 }
1570 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001571 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001572 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001573 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001574}
1575
David Miller4e08df32007-04-16 12:37:43 -07001576/* On sparc systems, obtain port and node WWN from firmware
1577 * properties.
1578 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001579static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001580{
1581#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001582 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001583 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001584 struct device_node *dp = pci_device_to_OF_node(pdev);
1585 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001586 int len;
1587
1588 val = of_get_property(dp, "port-wwn", &len);
1589 if (val && len >= WWN_SIZE)
1590 memcpy(nv->port_name, val, WWN_SIZE);
1591
1592 val = of_get_property(dp, "node-wwn", &len);
1593 if (val && len >= WWN_SIZE)
1594 memcpy(nv->node_name, val, WWN_SIZE);
1595#endif
1596}
1597
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598/*
1599* NVRAM configuration for ISP 2xxx
1600*
1601* Input:
1602* ha = adapter block pointer.
1603*
1604* Output:
1605* initialization control block in response_ring
1606* host adapters parameters in host adapter block
1607*
1608* Returns:
1609* 0 = success.
1610*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001611int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001612qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613{
David Miller4e08df32007-04-16 12:37:43 -07001614 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07001615 uint8_t chksum = 0;
1616 uint16_t cnt;
1617 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001618 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001619 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001620 nvram_t *nv = ha->nvram;
1621 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001622 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623
David Miller4e08df32007-04-16 12:37:43 -07001624 rval = QLA_SUCCESS;
1625
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001627 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001628 ha->nvram_base = 0;
1629 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1630 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1631 ha->nvram_base = 0x80;
1632
1633 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001634 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07001635 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1636 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001639 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001640
1641 /* Bad NVRAM data, set defaults parameters. */
1642 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1643 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1644 /* Reset NVRAM data. */
1645 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1646 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1647 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001648 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1649 "invalid -- WWPN) defaults.\n");
1650
1651 /*
1652 * Set default initialization control block.
1653 */
1654 memset(nv, 0, ha->nvram_size);
1655 nv->parameter_block_version = ICB_VERSION;
1656
1657 if (IS_QLA23XX(ha)) {
1658 nv->firmware_options[0] = BIT_2 | BIT_1;
1659 nv->firmware_options[1] = BIT_7 | BIT_5;
1660 nv->add_firmware_options[0] = BIT_5;
1661 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1662 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1663 nv->special_options[1] = BIT_7;
1664 } else if (IS_QLA2200(ha)) {
1665 nv->firmware_options[0] = BIT_2 | BIT_1;
1666 nv->firmware_options[1] = BIT_7 | BIT_5;
1667 nv->add_firmware_options[0] = BIT_5;
1668 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1669 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1670 } else if (IS_QLA2100(ha)) {
1671 nv->firmware_options[0] = BIT_3 | BIT_1;
1672 nv->firmware_options[1] = BIT_5;
1673 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1674 }
1675
1676 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1677 nv->execution_throttle = __constant_cpu_to_le16(16);
1678 nv->retry_count = 8;
1679 nv->retry_delay = 1;
1680
1681 nv->port_name[0] = 33;
1682 nv->port_name[3] = 224;
1683 nv->port_name[4] = 139;
1684
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001685 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001686
1687 nv->login_timeout = 4;
1688
1689 /*
1690 * Set default host adapter parameters
1691 */
1692 nv->host_p[1] = BIT_2;
1693 nv->reset_delay = 5;
1694 nv->port_down_retry_count = 8;
1695 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1696 nv->link_down_timeout = 60;
1697
1698 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001699 }
1700
1701#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1702 /*
1703 * The SN2 does not provide BIOS emulation which means you can't change
1704 * potentially bogus BIOS settings. Force the use of default settings
1705 * for link rate and frame size. Hope that the rest of the settings
1706 * are valid.
1707 */
1708 if (ia64_platform_is("sn2")) {
1709 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1710 if (IS_QLA23XX(ha))
1711 nv->special_options[1] = BIT_7;
1712 }
1713#endif
1714
1715 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07001716 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717
1718 /*
1719 * Setup driver NVRAM options.
1720 */
1721 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1722 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1723 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1724 nv->firmware_options[1] &= ~BIT_4;
1725
1726 if (IS_QLA23XX(ha)) {
1727 nv->firmware_options[0] |= BIT_2;
1728 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez01071092005-07-06 10:31:37 -07001729 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001730
1731 if (IS_QLA2300(ha)) {
1732 if (ha->fb_rev == FPM_2310) {
1733 strcpy(ha->model_number, "QLA2310");
1734 } else {
1735 strcpy(ha->model_number, "QLA2300");
1736 }
1737 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001738 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001739 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001740 }
1741 } else if (IS_QLA2200(ha)) {
1742 nv->firmware_options[0] |= BIT_2;
1743 /*
1744 * 'Point-to-point preferred, else loop' is not a safe
1745 * connection mode setting.
1746 */
1747 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1748 (BIT_5 | BIT_4)) {
1749 /* Force 'loop preferred, else point-to-point'. */
1750 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1751 nv->add_firmware_options[0] |= BIT_5;
1752 }
1753 strcpy(ha->model_number, "QLA22xx");
1754 } else /*if (IS_QLA2100(ha))*/ {
1755 strcpy(ha->model_number, "QLA2100");
1756 }
1757
1758 /*
1759 * Copy over NVRAM RISC parameter block to initialization control block.
1760 */
1761 dptr1 = (uint8_t *)icb;
1762 dptr2 = (uint8_t *)&nv->parameter_block_version;
1763 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1764 while (cnt--)
1765 *dptr1++ = *dptr2++;
1766
1767 /* Copy 2nd half. */
1768 dptr1 = (uint8_t *)icb->add_firmware_options;
1769 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1770 while (cnt--)
1771 *dptr1++ = *dptr2++;
1772
Andrew Vasquez5341e862006-05-17 15:09:16 -07001773 /* Use alternate WWN? */
1774 if (nv->host_p[1] & BIT_7) {
1775 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1776 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1777 }
1778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779 /* Prepare nodename */
1780 if ((icb->firmware_options[1] & BIT_6) == 0) {
1781 /*
1782 * Firmware will apply the following mask if the nodename was
1783 * not provided.
1784 */
1785 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1786 icb->node_name[0] &= 0xF0;
1787 }
1788
1789 /*
1790 * Set host adapter parameters.
1791 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001792 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001793 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001794 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1795 /* Always load RISC code on non ISP2[12]00 chips. */
1796 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1797 ha->flags.disable_risc_code_load = 0;
1798 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1799 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1800 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001801 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001802 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001803
1804 ha->operating_mode =
1805 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1806
1807 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1808 sizeof(ha->fw_seriallink_options));
1809
1810 /* save HBA serial number */
1811 ha->serial0 = icb->port_name[5];
1812 ha->serial1 = icb->port_name[6];
1813 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001814 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1815 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001816
1817 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1818
1819 ha->retry_count = nv->retry_count;
1820
1821 /* Set minimum login_timeout to 4 seconds. */
1822 if (nv->login_timeout < ql2xlogintimeout)
1823 nv->login_timeout = ql2xlogintimeout;
1824 if (nv->login_timeout < 4)
1825 nv->login_timeout = 4;
1826 ha->login_timeout = nv->login_timeout;
1827 icb->login_timeout = nv->login_timeout;
1828
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001829 /* Set minimum RATOV to 100 tenths of a second. */
1830 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001831
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832 ha->loop_reset_delay = nv->reset_delay;
1833
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 /* Link Down Timeout = 0:
1835 *
1836 * When Port Down timer expires we will start returning
1837 * I/O's to OS with "DID_NO_CONNECT".
1838 *
1839 * Link Down Timeout != 0:
1840 *
1841 * The driver waits for the link to come up after link down
1842 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001843 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 if (nv->link_down_timeout == 0) {
1845 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001846 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001847 } else {
1848 ha->link_down_timeout = nv->link_down_timeout;
1849 ha->loop_down_abort_time =
1850 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001851 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001852
Linus Torvalds1da177e2005-04-16 15:20:36 -07001853 /*
1854 * Need enough time to try and get the port back.
1855 */
1856 ha->port_down_retry_count = nv->port_down_retry_count;
1857 if (qlport_down_retry)
1858 ha->port_down_retry_count = qlport_down_retry;
1859 /* Set login_retry_count */
1860 ha->login_retry_count = nv->retry_count;
1861 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1862 ha->port_down_retry_count > 3)
1863 ha->login_retry_count = ha->port_down_retry_count;
1864 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1865 ha->login_retry_count = ha->port_down_retry_count;
1866 if (ql2xloginretrycount)
1867 ha->login_retry_count = ql2xloginretrycount;
1868
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869 icb->lun_enables = __constant_cpu_to_le16(0);
1870 icb->command_resource_count = 0;
1871 icb->immediate_notify_resource_count = 0;
1872 icb->timeout = __constant_cpu_to_le16(0);
1873
1874 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1875 /* Enable RIO */
1876 icb->firmware_options[0] &= ~BIT_3;
1877 icb->add_firmware_options[0] &=
1878 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1879 icb->add_firmware_options[0] |= BIT_2;
1880 icb->response_accumulation_timer = 3;
1881 icb->interrupt_delay_timer = 5;
1882
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001883 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001885 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001886 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001887 ha->zio_mode = icb->add_firmware_options[0] &
1888 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1889 ha->zio_timer = icb->interrupt_delay_timer ?
1890 icb->interrupt_delay_timer: 2;
1891 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001892 icb->add_firmware_options[0] &=
1893 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001894 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001895 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001896 ha->zio_mode = QLA_ZIO_MODE_6;
1897
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001898 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001899 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001900 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001902 "ZIO mode %d enabled; timer delay (%d us).\n",
1903 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001905 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1906 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001908 }
1909 }
1910
David Miller4e08df32007-04-16 12:37:43 -07001911 if (rval) {
1912 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001913 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001914 }
1915 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001916}
1917
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001918static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001919qla2x00_rport_del(void *data)
1920{
1921 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001922 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001923
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001924 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001925 rport = fcport->drport;
1926 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001927 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001928 if (rport)
1929 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001930}
1931
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932/**
1933 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1934 * @ha: HA context
1935 * @flags: allocation flags
1936 *
1937 * Returns a pointer to the allocated fcport, or NULL, if none available.
1938 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001939static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001940qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001941{
1942 fc_port_t *fcport;
1943
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001944 fcport = kzalloc(sizeof(fc_port_t), flags);
1945 if (!fcport)
1946 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
1948 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001949 fcport->vha = vha;
1950 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001951 fcport->port_type = FCT_UNKNOWN;
1952 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953 atomic_set(&fcport->state, FCS_UNCONFIGURED);
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001954 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001956 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957}
1958
1959/*
1960 * qla2x00_configure_loop
1961 * Updates Fibre Channel Device Database with what is actually on loop.
1962 *
1963 * Input:
1964 * ha = adapter block pointer.
1965 *
1966 * Returns:
1967 * 0 = success.
1968 * 1 = error.
1969 * 2 = database was full and device was not configured.
1970 */
1971static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001972qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973{
1974 int rval;
1975 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001976 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001977 rval = QLA_SUCCESS;
1978
1979 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1981 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001982 if (rval != QLA_SUCCESS) {
1983 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001984 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001985 return (rval);
1986 }
1987 }
1988
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001989 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001990 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001991 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992
1993 /*
1994 * If we have both an RSCN and PORT UPDATE pending then handle them
1995 * both at the same time.
1996 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001997 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1998 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999
2000 /* Determine what we need to do */
2001 if (ha->current_topology == ISP_CFG_FL &&
2002 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005 set_bit(RSCN_UPDATE, &flags);
2006
2007 } else if (ha->current_topology == ISP_CFG_F &&
2008 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
2009
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002010 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 set_bit(RSCN_UPDATE, &flags);
2012 clear_bit(LOCAL_LOOP_UPDATE, &flags);
2013
Andrew Vasquez21333b42006-05-17 15:09:56 -07002014 } else if (ha->current_topology == ISP_CFG_N) {
2015 clear_bit(RSCN_UPDATE, &flags);
2016
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002017 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2019
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002020 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002021 set_bit(RSCN_UPDATE, &flags);
2022 set_bit(LOCAL_LOOP_UPDATE, &flags);
2023 }
2024
2025 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002026 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002027 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002028 else
2029 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 }
2031
2032 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002035 else
2036 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002037 }
2038
2039 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002040 if (atomic_read(&vha->loop_down_timer) ||
2041 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042 rval = QLA_FUNCTION_FAILED;
2043 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002044 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002046 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002047 }
2048 }
2049
2050 if (rval) {
2051 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002052 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053 } else {
2054 DEBUG3(printk("%s: exiting normally\n", __func__));
2055 }
2056
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002057 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002058 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002060 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002061 if (test_bit(RSCN_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002062 set_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002063 }
2064
2065 return (rval);
2066}
2067
2068
2069
2070/*
2071 * qla2x00_configure_local_loop
2072 * Updates Fibre Channel Device Database with local loop devices.
2073 *
2074 * Input:
2075 * ha = adapter block pointer.
2076 *
2077 * Returns:
2078 * 0 = success.
2079 */
2080static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002081qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002082{
2083 int rval, rval2;
2084 int found_devs;
2085 int found;
2086 fc_port_t *fcport, *new_fcport;
2087
2088 uint16_t index;
2089 uint16_t entries;
2090 char *id_iter;
2091 uint16_t loop_id;
2092 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002093 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094
2095 found_devs = 0;
2096 new_fcport = NULL;
2097 entries = MAX_FIBRE_DEVICES;
2098
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002099 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2100 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
2102 /* Get list of logged in devices. */
2103 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002104 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002105 &entries);
2106 if (rval != QLA_SUCCESS)
2107 goto cleanup_allocation;
2108
2109 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
Andrew Vasquez76403352009-04-06 22:33:39 -07002110 vha->host_no, entries));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002111 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2112 entries * sizeof(struct gid_list_info)));
2113
2114 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002115 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116 if (new_fcport == NULL) {
2117 rval = QLA_MEMORY_ALLOC_FAILED;
2118 goto cleanup_allocation;
2119 }
2120 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2121
2122 /*
2123 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2124 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002125 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2127 fcport->port_type != FCT_BROADCAST &&
2128 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2129
2130 DEBUG(printk("scsi(%ld): Marking port lost, "
2131 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002132 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
2134 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135 }
2136 }
2137
2138 /* Add devices to port list. */
2139 id_iter = (char *)ha->gid_list;
2140 for (index = 0; index < entries; index++) {
2141 domain = ((struct gid_list_info *)id_iter)->domain;
2142 area = ((struct gid_list_info *)id_iter)->area;
2143 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002144 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002145 loop_id = (uint16_t)
2146 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002147 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002148 loop_id = le16_to_cpu(
2149 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002150 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151
2152 /* Bypass reserved domain fields. */
2153 if ((domain & 0xf0) == 0xf0)
2154 continue;
2155
2156 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002157 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002159 continue;
2160
2161 /* Bypass invalid local loop ID. */
2162 if (loop_id > LAST_LOCAL_LOOP_ID)
2163 continue;
2164
2165 /* Fill in member data. */
2166 new_fcport->d_id.b.domain = domain;
2167 new_fcport->d_id.b.area = area;
2168 new_fcport->d_id.b.al_pa = al_pa;
2169 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 new_fcport->vp_idx = vha->vp_idx;
2171 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172 if (rval2 != QLA_SUCCESS) {
2173 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2174 "information -- get_port_database=%x, "
2175 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002176 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002177 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002178 vha->host_no));
2179 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002180 continue;
2181 }
2182
2183 /* Check for matching device in port list. */
2184 found = 0;
2185 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002186 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002187 if (memcmp(new_fcport->port_name, fcport->port_name,
2188 WWN_SIZE))
2189 continue;
2190
Shyam Sundarddb9b122009-03-24 09:08:10 -07002191 fcport->flags &= ~FCF_FABRIC_DEVICE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002192 fcport->loop_id = new_fcport->loop_id;
2193 fcport->port_type = new_fcport->port_type;
2194 fcport->d_id.b24 = new_fcport->d_id.b24;
2195 memcpy(fcport->node_name, new_fcport->node_name,
2196 WWN_SIZE);
2197
2198 found++;
2199 break;
2200 }
2201
2202 if (!found) {
2203 /* New device, add to fcports list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002204 if (vha->vp_idx) {
2205 new_fcport->vha = vha;
2206 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002207 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002208 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002209
2210 /* Allocate a new replacement fcport. */
2211 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002212 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213 if (new_fcport == NULL) {
2214 rval = QLA_MEMORY_ALLOC_FAILED;
2215 goto cleanup_allocation;
2216 }
2217 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2218 }
2219
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002220 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002221 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002222
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002223 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002224
2225 found_devs++;
2226 }
2227
2228cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002229 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002230
2231 if (rval != QLA_SUCCESS) {
2232 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002233 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 }
2235
Linus Torvalds1da177e2005-04-16 15:20:36 -07002236 return (rval);
2237}
2238
2239static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002240qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002241{
2242#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002243 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002244 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002245 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002247
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002248 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002249 return;
2250
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002251 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2252 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002253 return;
2254
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002255 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002256 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002257 if (rval != QLA_SUCCESS) {
2258 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2259 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002260 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002261 fcport->port_name[2], fcport->port_name[3],
2262 fcport->port_name[4], fcport->port_name[5],
2263 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002264 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002265 } else {
2266 DEBUG2(qla_printk(KERN_INFO, ha,
2267 "iIDMA adjusted to %s GB/s on "
2268 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002269 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002270 fcport->port_name[1], fcport->port_name[2],
2271 fcport->port_name[3], fcport->port_name[4],
2272 fcport->port_name[5], fcport->port_name[6],
2273 fcport->port_name[7]));
2274 }
2275}
2276
Adrian Bunk23be3312006-11-24 02:46:01 +01002277static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002278qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e112005-04-17 15:04:54 -05002279{
2280 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002281 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002282 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05002283
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002284 if (fcport->drport)
2285 qla2x00_rport_del(fcport);
8482e112005-04-17 15:04:54 -05002286
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002287 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2288 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002289 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2290 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2291 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002293 if (!rport) {
2294 qla_printk(KERN_WARNING, ha,
2295 "Unable to allocate fc remote port!\n");
2296 return;
2297 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002298 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002299 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002300 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002301
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002302 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002303
2304 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002305 if (fcport->port_type == FCT_INITIATOR)
2306 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2307 if (fcport->port_type == FCT_TARGET)
2308 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002309 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e112005-04-17 15:04:54 -05002310}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002311
2312/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002313 * qla2x00_update_fcport
2314 * Updates device on list.
2315 *
2316 * Input:
2317 * ha = adapter block pointer.
2318 * fcport = port structure pointer.
2319 *
2320 * Return:
2321 * 0 - Success
2322 * BIT_0 - error
2323 *
2324 * Context:
2325 * Kernel context.
2326 */
2327void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002328qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002329{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002330 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002331
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002332 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002333 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002334 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002335 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002336 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002337 PORT_RETRY_TIME);
2338 fcport->flags &= ~FCF_LOGIN_NEEDED;
2339
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002340 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002341
2342 atomic_set(&fcport->state, FCS_ONLINE);
2343
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002344 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002345}
2346
2347/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002348 * qla2x00_configure_fabric
2349 * Setup SNS devices with loop ID's.
2350 *
2351 * Input:
2352 * ha = adapter block pointer.
2353 *
2354 * Returns:
2355 * 0 = success.
2356 * BIT_0 = error
2357 */
2358static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002359qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360{
2361 int rval, rval2;
2362 fc_port_t *fcport, *fcptemp;
2363 uint16_t next_loopid;
2364 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002365 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002367 struct qla_hw_data *ha = vha->hw;
2368 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002369
2370 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002371 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002372 loop_id = NPH_F_PORT;
2373 else
2374 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002375 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376 if (rval != QLA_SUCCESS) {
2377 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002380 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002381 return (QLA_SUCCESS);
2382 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002383 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384
2385 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002386 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002387 if (rval2 == QLA_RSCNS_HANDLED) {
2388 /* No point doing the scan, just continue. */
2389 return (QLA_SUCCESS);
2390 }
2391 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002392 /* FDMI support. */
2393 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002394 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2395 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002396
Linus Torvalds1da177e2005-04-16 15:20:36 -07002397 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002398 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002399 loop_id = NPH_SNS;
2400 else
2401 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002402 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002403 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 if (mb[0] != MBS_COMMAND_COMPLETE) {
2405 DEBUG2(qla_printk(KERN_INFO, ha,
2406 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002407 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 mb[0], mb[1], mb[2], mb[6], mb[7]));
2409 return (QLA_SUCCESS);
2410 }
2411
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2413 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002414 /* EMPTY */
2415 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002416 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002418 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 /* EMPTY */
2420 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002423 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002424 /* EMPTY */
2425 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002426 "failed.\n", vha->host_no));
2427 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002428 /* EMPTY */
2429 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002430 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002431 }
2432 }
2433
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002434 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 if (rval != QLA_SUCCESS)
2436 break;
2437
2438 /*
2439 * Logout all previous fabric devices marked lost, except
2440 * tape devices.
2441 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002442 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2443 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444 break;
2445
2446 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2447 continue;
2448
2449 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002450 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002451 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 if (fcport->loop_id != FC_NO_LOOP_ID &&
2453 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2454 fcport->port_type != FCT_INITIATOR &&
2455 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002456 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002457 fcport->loop_id,
2458 fcport->d_id.b.domain,
2459 fcport->d_id.b.area,
2460 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 fcport->loop_id = FC_NO_LOOP_ID;
2462 }
2463 }
2464 }
2465
2466 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002467 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
2469 /*
2470 * Scan through our port list and login entries that need to be
2471 * logged in.
2472 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002473 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2474 if (atomic_read(&vha->loop_down_timer) ||
2475 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002476 break;
2477
2478 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2479 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2480 continue;
2481
2482 if (fcport->loop_id == FC_NO_LOOP_ID) {
2483 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002484 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002486 if (rval != QLA_SUCCESS) {
2487 /* Ran out of IDs to use */
2488 break;
2489 }
2490 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002492 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002493 }
2494
2495 /* Exit if out of loop IDs. */
2496 if (rval != QLA_SUCCESS) {
2497 break;
2498 }
2499
2500 /*
2501 * Login and add the new devices to our port list.
2502 */
2503 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 if (atomic_read(&vha->loop_down_timer) ||
2505 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002506 break;
2507
2508 /* Find a new loop ID to use. */
2509 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 if (rval != QLA_SUCCESS) {
2512 /* Ran out of IDs to use */
2513 break;
2514 }
2515
bdf79622005-04-17 15:06:53 -05002516 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002517 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002518
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002519 if (vha->vp_idx) {
2520 fcport->vha = vha;
2521 fcport->vp_idx = vha->vp_idx;
2522 }
2523 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002524 }
2525 } while (0);
2526
2527 /* Free all new device structures not processed. */
2528 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2529 list_del(&fcport->list);
2530 kfree(fcport);
2531 }
2532
2533 if (rval) {
2534 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002535 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002536 }
2537
2538 return (rval);
2539}
2540
2541
2542/*
2543 * qla2x00_find_all_fabric_devs
2544 *
2545 * Input:
2546 * ha = adapter block pointer.
2547 * dev = database device entry pointer.
2548 *
2549 * Returns:
2550 * 0 = success.
2551 *
2552 * Context:
2553 * Kernel context.
2554 */
2555static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002556qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2557 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002558{
2559 int rval;
2560 uint16_t loop_id;
2561 fc_port_t *fcport, *new_fcport, *fcptemp;
2562 int found;
2563
2564 sw_info_t *swl;
2565 int swl_idx;
2566 int first_dev, last_dev;
2567 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002568 struct qla_hw_data *ha = vha->hw;
2569 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002570 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571
2572 rval = QLA_SUCCESS;
2573
2574 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002575 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002576 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 /*EMPTY*/
2578 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002579 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002582 kfree(swl);
2583 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002584 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 kfree(swl);
2586 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002587 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588 kfree(swl);
2589 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002590 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002591 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2592 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593 }
2594 }
2595 swl_idx = 0;
2596
2597 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002598 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002599 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002600 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002601 return (QLA_MEMORY_ALLOC_FAILED);
2602 }
2603 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002604 /* Set start port ID scan at adapter ID. */
2605 first_dev = 1;
2606 last_dev = 0;
2607
2608 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002609 loop_id = ha->min_external_loopid;
2610 for (; loop_id <= ha->max_loop_id; loop_id++) {
2611 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002612 continue;
2613
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002615 break;
2616
2617 if (swl != NULL) {
2618 if (last_dev) {
2619 wrap.b24 = new_fcport->d_id.b24;
2620 } else {
2621 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2622 memcpy(new_fcport->node_name,
2623 swl[swl_idx].node_name, WWN_SIZE);
2624 memcpy(new_fcport->port_name,
2625 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002626 memcpy(new_fcport->fabric_port_name,
2627 swl[swl_idx].fabric_port_name, WWN_SIZE);
2628 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629
2630 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2631 last_dev = 1;
2632 }
2633 swl_idx++;
2634 }
2635 } else {
2636 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002638 if (rval != QLA_SUCCESS) {
2639 qla_printk(KERN_WARNING, ha,
2640 "SNS scan failed -- assuming zero-entry "
2641 "result...\n");
2642 list_for_each_entry_safe(fcport, fcptemp,
2643 new_fcports, list) {
2644 list_del(&fcport->list);
2645 kfree(fcport);
2646 }
2647 rval = QLA_SUCCESS;
2648 break;
2649 }
2650 }
2651
2652 /* If wrap on switch device list, exit. */
2653 if (first_dev) {
2654 wrap.b24 = new_fcport->d_id.b24;
2655 first_dev = 0;
2656 } else if (new_fcport->d_id.b24 == wrap.b24) {
2657 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2660 break;
2661 }
2662
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002663 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 continue;
2666
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002667 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002668 found = 0;
2669 if (ha->num_vhosts) {
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002670 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002671 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2672 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002673 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002675 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002677 continue;
2678 }
2679
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002680 /* Bypass if same domain and area of adapter. */
2681 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002683 ISP_CFG_FL)
2684 continue;
2685
Linus Torvalds1da177e2005-04-16 15:20:36 -07002686 /* Bypass reserved domain fields. */
2687 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2688 continue;
2689
2690 /* Locate matching device in database. */
2691 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002692 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002693 if (memcmp(new_fcport->port_name, fcport->port_name,
2694 WWN_SIZE))
2695 continue;
2696
2697 found++;
2698
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002699 /* Update port state. */
2700 memcpy(fcport->fabric_port_name,
2701 new_fcport->fabric_port_name, WWN_SIZE);
2702 fcport->fp_speed = new_fcport->fp_speed;
2703
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 /*
2705 * If address the same and state FCS_ONLINE, nothing
2706 * changed.
2707 */
2708 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2709 atomic_read(&fcport->state) == FCS_ONLINE) {
2710 break;
2711 }
2712
2713 /*
2714 * If device was not a fabric device before.
2715 */
2716 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2717 fcport->d_id.b24 = new_fcport->d_id.b24;
2718 fcport->loop_id = FC_NO_LOOP_ID;
2719 fcport->flags |= (FCF_FABRIC_DEVICE |
2720 FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 break;
2722 }
2723
2724 /*
2725 * Port ID changed or device was marked to be updated;
2726 * Log it out if still logged in and mark it for
2727 * relogin later.
2728 */
2729 fcport->d_id.b24 = new_fcport->d_id.b24;
2730 fcport->flags |= FCF_LOGIN_NEEDED;
2731 if (fcport->loop_id != FC_NO_LOOP_ID &&
2732 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2733 fcport->port_type != FCT_INITIATOR &&
2734 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002735 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002736 fcport->d_id.b.domain, fcport->d_id.b.area,
2737 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738 fcport->loop_id = FC_NO_LOOP_ID;
2739 }
2740
2741 break;
2742 }
2743
2744 if (found)
2745 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 /* If device was not in our fcports list, then add it. */
2747 list_add_tail(&new_fcport->list, new_fcports);
2748
2749 /* Allocate a new replacement fcport. */
2750 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002753 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 return (QLA_MEMORY_ALLOC_FAILED);
2755 }
2756 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2757 new_fcport->d_id.b24 = nxt_d_id.b24;
2758 }
2759
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002760 kfree(swl);
2761 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002762
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 return (rval);
2764}
2765
2766/*
2767 * qla2x00_find_new_loop_id
2768 * Scan through our port list and find a new usable loop ID.
2769 *
2770 * Input:
2771 * ha: adapter state pointer.
2772 * dev: port structure pointer.
2773 *
2774 * Returns:
2775 * qla2x00 local function return status code.
2776 *
2777 * Context:
2778 * Kernel context.
2779 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002780static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782{
2783 int rval;
2784 int found;
2785 fc_port_t *fcport;
2786 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002787 struct qla_hw_data *ha = vha->hw;
2788 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002789 struct scsi_qla_host *tvp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002790
2791 rval = QLA_SUCCESS;
2792
2793 /* Save starting loop ID. */
2794 first_loop_id = dev->loop_id;
2795
2796 for (;;) {
2797 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800
2801 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002802 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002803 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804
2805 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002806 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002807 /* first loop ID. */
2808 dev->loop_id = ha->min_external_loopid;
2809 }
2810
2811 /* Check for loop ID being already in use. */
2812 found = 0;
2813 fcport = NULL;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08002814 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2816 if (fcport->loop_id == dev->loop_id &&
2817 fcport != dev) {
2818 /* ID possibly in use */
2819 found++;
2820 break;
2821 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823 if (found)
2824 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002825 }
2826
2827 /* If not in use then it is free to use. */
2828 if (!found) {
2829 break;
2830 }
2831
2832 /* ID in use. Try next value. */
2833 dev->loop_id++;
2834
2835 /* If wrap around. No free ID to use. */
2836 if (dev->loop_id == first_loop_id) {
2837 dev->loop_id = FC_NO_LOOP_ID;
2838 rval = QLA_FUNCTION_FAILED;
2839 break;
2840 }
2841 }
2842
2843 return (rval);
2844}
2845
2846/*
2847 * qla2x00_device_resync
2848 * Marks devices in the database that needs resynchronization.
2849 *
2850 * Input:
2851 * ha = adapter block pointer.
2852 *
2853 * Context:
2854 * Kernel context.
2855 */
2856static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002857qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002858{
2859 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002860 uint32_t mask;
2861 fc_port_t *fcport;
2862 uint32_t rscn_entry;
2863 uint8_t rscn_out_iter;
2864 uint8_t format;
2865 port_id_t d_id;
2866
2867 rval = QLA_RSCNS_HANDLED;
2868
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002869 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2870 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002871
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002872 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002873 format = MSB(MSW(rscn_entry));
2874 d_id.b.domain = LSB(MSW(rscn_entry));
2875 d_id.b.area = MSB(LSW(rscn_entry));
2876 d_id.b.al_pa = LSB(LSW(rscn_entry));
2877
2878 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2879 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002880 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 d_id.b.area, d_id.b.al_pa));
2882
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002883 vha->rscn_out_ptr++;
2884 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2885 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886
2887 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002888 for (rscn_out_iter = vha->rscn_out_ptr;
2889 !vha->flags.rscn_queue_overflow &&
2890 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891 rscn_out_iter = (rscn_out_iter ==
2892 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 break;
2896
2897 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002898 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 rscn_out_iter));
2900
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002901 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002902 }
2903
2904 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002905 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002906 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002907 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908
2909 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002910 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 }
2912
2913 switch (format) {
2914 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002915 mask = 0xffffff;
2916 break;
2917 case 1:
2918 mask = 0xffff00;
2919 break;
2920 case 2:
2921 mask = 0xff0000;
2922 break;
2923 default:
2924 mask = 0x0;
2925 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002926 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002927 break;
2928 }
2929
2930 rval = QLA_SUCCESS;
2931
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002932 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2934 (fcport->d_id.b24 & mask) != d_id.b24 ||
2935 fcport->port_type == FCT_BROADCAST)
2936 continue;
2937
2938 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2939 if (format != 3 ||
2940 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002941 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002942 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 }
2944 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 }
2946 }
2947 return (rval);
2948}
2949
2950/*
2951 * qla2x00_fabric_dev_login
2952 * Login fabric target device and update FC port database.
2953 *
2954 * Input:
2955 * ha: adapter state pointer.
2956 * fcport: port structure list pointer.
2957 * next_loopid: contains value of a new loop ID that can be used
2958 * by the next login attempt.
2959 *
2960 * Returns:
2961 * qla2x00 local function return status code.
2962 *
2963 * Context:
2964 * Kernel context.
2965 */
2966static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968 uint16_t *next_loopid)
2969{
2970 int rval;
2971 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07002972 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002973 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974
2975 rval = QLA_SUCCESS;
2976 retry = 0;
2977
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if (rval == QLA_SUCCESS) {
Andrew Vasquez01071092005-07-06 10:31:37 -07002980 /* Send an ADISC to tape devices.*/
2981 opts = 0;
2982 if (fcport->flags & FCF_TAPE_PRESENT)
2983 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002984 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002985 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002986 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002987 fcport->d_id.b.domain, fcport->d_id.b.area,
2988 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002989 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002990 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992 }
2993 }
2994
2995 return (rval);
2996}
2997
2998/*
2999 * qla2x00_fabric_login
3000 * Issue fabric login command.
3001 *
3002 * Input:
3003 * ha = adapter block pointer.
3004 * device = pointer to FC device type structure.
3005 *
3006 * Returns:
3007 * 0 - Login successfully
3008 * 1 - Login failed
3009 * 2 - Initiator device
3010 * 3 - Fatal error
3011 */
3012int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003013qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 uint16_t *next_loopid)
3015{
3016 int rval;
3017 int retry;
3018 uint16_t tmp_loopid;
3019 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003020 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003021
3022 retry = 0;
3023 tmp_loopid = 0;
3024
3025 for (;;) {
3026 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3027 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003028 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003029 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3030
3031 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003032 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003033 fcport->d_id.b.domain, fcport->d_id.b.area,
3034 fcport->d_id.b.al_pa, mb, BIT_0);
3035 if (mb[0] == MBS_PORT_ID_USED) {
3036 /*
3037 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07003038 * recommends the driver perform an implicit login with
3039 * the specified ID again. The ID we just used is save
3040 * here so we return with an ID that can be tried by
3041 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 */
3043 retry++;
3044 tmp_loopid = fcport->loop_id;
3045 fcport->loop_id = mb[1];
3046
3047 DEBUG(printk("Fabric Login: port in use - next "
3048 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3049 fcport->loop_id, fcport->d_id.b.domain,
3050 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3051
3052 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3053 /*
3054 * Login succeeded.
3055 */
3056 if (retry) {
3057 /* A retry occurred before. */
3058 *next_loopid = tmp_loopid;
3059 } else {
3060 /*
3061 * No retry occurred before. Just increment the
3062 * ID value for next login.
3063 */
3064 *next_loopid = (fcport->loop_id + 1);
3065 }
3066
3067 if (mb[1] & BIT_0) {
3068 fcport->port_type = FCT_INITIATOR;
3069 } else {
3070 fcport->port_type = FCT_TARGET;
3071 if (mb[1] & BIT_1) {
3072 fcport->flags |= FCF_TAPE_PRESENT;
3073 }
3074 }
3075
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003076 if (mb[10] & BIT_0)
3077 fcport->supported_classes |= FC_COS_CLASS2;
3078 if (mb[10] & BIT_1)
3079 fcport->supported_classes |= FC_COS_CLASS3;
3080
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081 rval = QLA_SUCCESS;
3082 break;
3083 } else if (mb[0] == MBS_LOOP_ID_USED) {
3084 /*
3085 * Loop ID already used, try next loop ID.
3086 */
3087 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003088 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003089 if (rval != QLA_SUCCESS) {
3090 /* Ran out of loop IDs to use */
3091 break;
3092 }
3093 } else if (mb[0] == MBS_COMMAND_ERROR) {
3094 /*
3095 * Firmware possibly timed out during login. If NO
3096 * retries are left to do then the device is declared
3097 * dead.
3098 */
3099 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003100 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003101 fcport->d_id.b.domain, fcport->d_id.b.area,
3102 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003103 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003104
3105 rval = 1;
3106 break;
3107 } else {
3108 /*
3109 * unrecoverable / not handled error
3110 */
3111 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003112 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003113 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003114 fcport->d_id.b.domain, fcport->d_id.b.area,
3115 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3116
3117 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003118 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003119 fcport->d_id.b.domain, fcport->d_id.b.area,
3120 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003121 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003122 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123
3124 rval = 3;
3125 break;
3126 }
3127 }
3128
3129 return (rval);
3130}
3131
3132/*
3133 * qla2x00_local_device_login
3134 * Issue local device login command.
3135 *
3136 * Input:
3137 * ha = adapter block pointer.
3138 * loop_id = loop id of device to login to.
3139 *
3140 * Returns (Where's the #define!!!!):
3141 * 0 - Login successfully
3142 * 1 - Login failed
3143 * 3 - Fatal error
3144 */
3145int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147{
3148 int rval;
3149 uint16_t mb[MAILBOX_REGISTER_COUNT];
3150
3151 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003152 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003153 if (rval == QLA_SUCCESS) {
3154 /* Interrogate mailbox registers for any errors */
3155 if (mb[0] == MBS_COMMAND_ERROR)
3156 rval = 1;
3157 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3158 /* device not in PCB table */
3159 rval = 3;
3160 }
3161
3162 return (rval);
3163}
3164
3165/*
3166 * qla2x00_loop_resync
3167 * Resync with fibre channel devices.
3168 *
3169 * Input:
3170 * ha = adapter block pointer.
3171 *
3172 * Returns:
3173 * 0 = success
3174 */
3175int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003176qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003177{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003178 int rval = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003179 uint32_t wait_time;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003180 struct req_que *req = vha->req;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003181 struct rsp_que *rsp = req->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003182
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003183 atomic_set(&vha->loop_state, LOOP_UPDATE);
3184 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3185 if (vha->flags.online) {
3186 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003187 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3188 wait_time = 256;
3189 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003190 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003191
Andrew Vasquez01071092005-07-06 10:31:37 -07003192 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003193 qla2x00_marker(vha, req, rsp, 0, 0,
3194 MK_SYNC_ALL);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003195 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003196
3197 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003198 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003200 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202 } while (!atomic_read(&vha->loop_down_timer) &&
3203 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3204 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3205 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207 }
3208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003209 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003210 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003214
3215 return (rval);
3216}
3217
Linus Torvalds1da177e2005-04-16 15:20:36 -07003218void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003219qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003220{
3221 fc_port_t *fcport;
3222
3223 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003224 list_for_each_entry(fcport, &vha->vp_fcports, list)
3225 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003226 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003227 qla2x00_rport_del(fcport);
3228}
3229
Linus Torvalds1da177e2005-04-16 15:20:36 -07003230/*
3231* qla2x00_abort_isp
3232* Resets ISP and aborts all outstanding commands.
3233*
3234* Input:
3235* ha = adapter block pointer.
3236*
3237* Returns:
3238* 0 = success
3239*/
3240int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003241qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003243 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003245 struct qla_hw_data *ha = vha->hw;
3246 struct scsi_qla_host *vp;
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003247 struct scsi_qla_host *tvp;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003248 struct req_que *req = ha->req_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 if (vha->flags.online) {
3251 vha->flags.online = 0;
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003252 ha->flags.chip_reset_done = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003253 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003254 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255
3256 qla_printk(KERN_INFO, ha,
3257 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003258 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003260 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3261 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3262 atomic_set(&vha->loop_state, LOOP_DOWN);
3263 qla2x00_mark_all_devices_lost(vha, 0);
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003264 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003265 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003266 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 if (!atomic_read(&vha->loop_down_timer))
3268 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 LOOP_DOWN_TIME);
3270 }
3271
Linus Torvalds1da177e2005-04-16 15:20:36 -07003272 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003273 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003275 ha->isp_ops->get_flash_version(vha, req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003276
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003279 if (!qla2x00_restart_isp(vha)) {
3280 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003282 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283 /*
3284 * Issue marker command only when we are going
3285 * to start the I/O .
3286 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003287 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 }
3289
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003290 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003292 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003294 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003295 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003296
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003297 if (ha->fce) {
3298 ha->flags.fce_enabled = 1;
3299 memset(ha->fce, 0,
3300 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003301 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003302 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3303 &ha->fce_bufs);
3304 if (rval) {
3305 qla_printk(KERN_WARNING, ha,
3306 "Unable to reinitialize FCE "
3307 "(%d).\n", rval);
3308 ha->flags.fce_enabled = 0;
3309 }
3310 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003311
3312 if (ha->eft) {
3313 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003314 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003315 ha->eft_dma, EFT_NUM_BUFFERS);
3316 if (rval) {
3317 qla_printk(KERN_WARNING, ha,
3318 "Unable to reinitialize EFT "
3319 "(%d).\n", rval);
3320 }
3321 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 vha->flags.online = 1;
3324 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 if (ha->isp_abort_cnt == 0) {
3326 qla_printk(KERN_WARNING, ha,
3327 "ISP error recovery failed - "
3328 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003329 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 * The next call disables the board
3331 * completely.
3332 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003333 ha->isp_ops->reset_adapter(vha);
3334 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003336 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003337 status = 0;
3338 } else { /* schedule another ISP abort */
3339 ha->isp_abort_cnt--;
3340 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003341 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003342 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003343 status = 1;
3344 }
3345 } else {
3346 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3347 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3348 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003349 vha->host_no, ha->isp_abort_cnt));
3350 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 status = 1;
3352 }
3353 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003354
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 }
3356
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003357 if (!status) {
3358 DEBUG(printk(KERN_INFO
3359 "qla2x00_abort_isp(%ld): succeeded.\n",
3360 vha->host_no));
Anirban Chakrabortyee546b62009-03-05 11:07:02 -08003361 list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003362 if (vp->vp_idx)
3363 qla2x00_vp_abort_isp(vp);
3364 }
3365 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003366 qla_printk(KERN_INFO, ha,
3367 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003368 }
3369
3370 return(status);
3371}
3372
3373/*
3374* qla2x00_restart_isp
3375* restarts the ISP after a reset
3376*
3377* Input:
3378* ha = adapter block pointer.
3379*
3380* Returns:
3381* 0 = success
3382*/
3383static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003384qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003385{
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08003386 int status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003387 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003389 struct req_que *req = ha->req_q_map[0];
3390 struct rsp_que *rsp = ha->rsp_q_map[0];
Linus Torvalds1da177e2005-04-16 15:20:36 -07003391
3392 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003393 if (qla2x00_isp_firmware(vha)) {
3394 vha->flags.online = 0;
3395 status = ha->isp_ops->chip_diag(vha);
3396 if (!status)
3397 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 }
3399
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003400 if (!status && !(status = qla2x00_init_rings(vha))) {
3401 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Lalit Chandivade2533cf62009-03-24 09:08:07 -07003402 ha->flags.chip_reset_done = 1;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003403 /* Initialize the queues in use */
3404 qla25xx_init_queues(ha);
3405
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003406 status = qla2x00_fw_ready(vha);
3407 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003408 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003409 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07003410
3411 /* Issue a marker after FW becomes ready. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003412 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Andrew Vasquez01071092005-07-06 10:31:37 -07003413
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003414 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003415 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3416 wait_time = 256;
3417 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003418 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3419 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003421 } while (!atomic_read(&vha->loop_down_timer) &&
3422 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3423 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3424 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 }
3426
3427 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003428 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 status = 0;
3430
3431 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3432 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003433 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 }
3435 return (status);
3436}
3437
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003438static int
3439qla25xx_init_queues(struct qla_hw_data *ha)
3440{
3441 struct rsp_que *rsp = NULL;
3442 struct req_que *req = NULL;
3443 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
3444 int ret = -1;
3445 int i;
3446
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003447 for (i = 1; i < ha->max_rsp_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003448 rsp = ha->rsp_q_map[i];
3449 if (rsp) {
3450 rsp->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003451 ret = qla25xx_init_rsp_que(base_vha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003452 if (ret != QLA_SUCCESS)
3453 DEBUG2_17(printk(KERN_WARNING
3454 "%s Rsp que:%d init failed\n", __func__,
3455 rsp->id));
3456 else
3457 DEBUG2_17(printk(KERN_INFO
3458 "%s Rsp que:%d inited\n", __func__,
3459 rsp->id));
3460 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07003461 }
3462 for (i = 1; i < ha->max_req_queues; i++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003463 req = ha->req_q_map[i];
3464 if (req) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003465 /* Clear outstanding commands array. */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003466 req->options &= ~BIT_0;
Anirban Chakraborty618a7522009-02-08 20:50:11 -08003467 ret = qla25xx_init_req_que(base_vha, req);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003468 if (ret != QLA_SUCCESS)
3469 DEBUG2_17(printk(KERN_WARNING
3470 "%s Req que:%d init failed\n", __func__,
3471 req->id));
3472 else
3473 DEBUG2_17(printk(KERN_WARNING
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08003474 "%s Req que:%d inited\n", __func__,
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003475 req->id));
3476 }
3477 }
3478 return ret;
3479}
3480
Linus Torvalds1da177e2005-04-16 15:20:36 -07003481/*
3482* qla2x00_reset_adapter
3483* Reset adapter.
3484*
3485* Input:
3486* ha = adapter block pointer.
3487*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003488void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003490{
3491 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003492 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003493 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003495 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003496 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498 spin_lock_irqsave(&ha->hardware_lock, flags);
3499 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3500 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3501 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3502 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3503 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3504}
Andrew Vasquez01071092005-07-06 10:31:37 -07003505
3506void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003507qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003508{
3509 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003510 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003511 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3512
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);
Andrew Vasquez01071092005-07-06 10:31:37 -07003515
3516 spin_lock_irqsave(&ha->hardware_lock, flags);
3517 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3518 RD_REG_DWORD(&reg->hccr);
3519 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3520 RD_REG_DWORD(&reg->hccr);
3521 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez09ff36d2009-01-22 09:45:30 -08003522
3523 if (IS_NOPOLLING_TYPE(ha))
3524 ha->isp_ops->enable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003525}
3526
David Miller4e08df32007-04-16 12:37:43 -07003527/* On sparc systems, obtain port and node WWN from firmware
3528 * properties.
3529 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003530static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3531 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003532{
3533#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003534 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003535 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003536 struct device_node *dp = pci_device_to_OF_node(pdev);
3537 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003538 int len;
3539
3540 val = of_get_property(dp, "port-wwn", &len);
3541 if (val && len >= WWN_SIZE)
3542 memcpy(nv->port_name, val, WWN_SIZE);
3543
3544 val = of_get_property(dp, "node-wwn", &len);
3545 if (val && len >= WWN_SIZE)
3546 memcpy(nv->node_name, val, WWN_SIZE);
3547#endif
3548}
3549
Andrew Vasquez01071092005-07-06 10:31:37 -07003550int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003551qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003552{
David Miller4e08df32007-04-16 12:37:43 -07003553 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07003554 struct init_cb_24xx *icb;
3555 struct nvram_24xx *nv;
3556 uint32_t *dptr;
3557 uint8_t *dptr1, *dptr2;
3558 uint32_t chksum;
3559 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003560 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003561
David Miller4e08df32007-04-16 12:37:43 -07003562 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07003563 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003564 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07003565
3566 /* Determine NVRAM starting address. */
3567 ha->nvram_size = sizeof(struct nvram_24xx);
3568 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003569 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3570 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3571 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003572 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003573 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3574 }
Andrew Vasquez01071092005-07-06 10:31:37 -07003575
Seokmann Ju281afe12007-07-26 13:43:34 -07003576 /* Get VPD data into cache */
3577 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003578 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003579 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3580
3581 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07003582 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003583 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07003584 ha->nvram_size);
3585 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3586 chksum += le32_to_cpu(*dptr++);
3587
Andrew Vasquez76403352009-04-06 22:33:39 -07003588 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003589 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07003590
3591 /* Bad NVRAM data, set defaults parameters. */
3592 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3593 || nv->id[3] != ' ' ||
3594 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3595 /* Reset NVRAM data. */
3596 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3597 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3598 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003599 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3600 "invalid -- WWPN) defaults.\n");
3601
3602 /*
3603 * Set default initialization control block.
3604 */
3605 memset(nv, 0, ha->nvram_size);
3606 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3607 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3608 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3609 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3610 nv->exchange_count = __constant_cpu_to_le16(0);
3611 nv->hard_address = __constant_cpu_to_le16(124);
3612 nv->port_name[0] = 0x21;
3613 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3614 nv->port_name[2] = 0x00;
3615 nv->port_name[3] = 0xe0;
3616 nv->port_name[4] = 0x8b;
3617 nv->port_name[5] = 0x1c;
3618 nv->port_name[6] = 0x55;
3619 nv->port_name[7] = 0x86;
3620 nv->node_name[0] = 0x20;
3621 nv->node_name[1] = 0x00;
3622 nv->node_name[2] = 0x00;
3623 nv->node_name[3] = 0xe0;
3624 nv->node_name[4] = 0x8b;
3625 nv->node_name[5] = 0x1c;
3626 nv->node_name[6] = 0x55;
3627 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003628 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003629 nv->login_retry_count = __constant_cpu_to_le16(8);
3630 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3631 nv->login_timeout = __constant_cpu_to_le16(0);
3632 nv->firmware_options_1 =
3633 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3634 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3635 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3636 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3637 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3638 nv->efi_parameters = __constant_cpu_to_le32(0);
3639 nv->reset_delay = 5;
3640 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3641 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3642 nv->link_down_timeout = __constant_cpu_to_le16(30);
3643
3644 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07003645 }
3646
3647 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003649
3650 /* Copy 1st segment. */
3651 dptr1 = (uint8_t *)icb;
3652 dptr2 = (uint8_t *)&nv->version;
3653 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3654 while (cnt--)
3655 *dptr1++ = *dptr2++;
3656
3657 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003658 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07003659
3660 /* Copy 2nd segment. */
3661 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3662 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3663 cnt = (uint8_t *)&icb->reserved_3 -
3664 (uint8_t *)&icb->interrupt_delay_timer;
3665 while (cnt--)
3666 *dptr1++ = *dptr2++;
3667
3668 /*
3669 * Setup driver NVRAM options.
3670 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003671 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003672 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07003673
Andrew Vasquez5341e862006-05-17 15:09:16 -07003674 /* Use alternate WWN? */
3675 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3676 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3677 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3678 }
3679
Andrew Vasquez01071092005-07-06 10:31:37 -07003680 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003681 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003682 /*
3683 * Firmware will apply the following mask if the nodename was
3684 * not provided.
3685 */
3686 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3687 icb->node_name[0] &= 0xF0;
3688 }
3689
3690 /* Set host adapter parameters. */
3691 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003692 ha->flags.enable_lip_reset = 0;
3693 ha->flags.enable_lip_full_login =
3694 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3695 ha->flags.enable_target_reset =
3696 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003697 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003698 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003699
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003700 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3701 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07003702
3703 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3704 sizeof(ha->fw_seriallink_options24));
3705
3706 /* save HBA serial number */
3707 ha->serial0 = icb->port_name[5];
3708 ha->serial1 = icb->port_name[6];
3709 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003710 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3711 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez01071092005-07-06 10:31:37 -07003712
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003713 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3714
Andrew Vasquez01071092005-07-06 10:31:37 -07003715 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3716
3717 /* Set minimum login_timeout to 4 seconds. */
3718 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3719 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3720 if (le16_to_cpu(nv->login_timeout) < 4)
3721 nv->login_timeout = __constant_cpu_to_le16(4);
3722 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003723 icb->login_timeout = nv->login_timeout;
Andrew Vasquez01071092005-07-06 10:31:37 -07003724
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003725 /* Set minimum RATOV to 100 tenths of a second. */
3726 ha->r_a_tov = 100;
Andrew Vasquez01071092005-07-06 10:31:37 -07003727
3728 ha->loop_reset_delay = nv->reset_delay;
3729
3730 /* Link Down Timeout = 0:
3731 *
3732 * When Port Down timer expires we will start returning
3733 * I/O's to OS with "DID_NO_CONNECT".
3734 *
3735 * Link Down Timeout != 0:
3736 *
3737 * The driver waits for the link to come up after link down
3738 * before returning I/Os to OS with "DID_NO_CONNECT".
3739 */
3740 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3741 ha->loop_down_abort_time =
3742 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3743 } else {
3744 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3745 ha->loop_down_abort_time =
3746 (LOOP_DOWN_TIME - ha->link_down_timeout);
3747 }
3748
3749 /* Need enough time to try and get the port back. */
3750 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3751 if (qlport_down_retry)
3752 ha->port_down_retry_count = qlport_down_retry;
3753
3754 /* Set login_retry_count */
3755 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3756 if (ha->port_down_retry_count ==
3757 le16_to_cpu(nv->port_down_retry_count) &&
3758 ha->port_down_retry_count > 3)
3759 ha->login_retry_count = ha->port_down_retry_count;
3760 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3761 ha->login_retry_count = ha->port_down_retry_count;
3762 if (ql2xloginretrycount)
3763 ha->login_retry_count = ql2xloginretrycount;
3764
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003765 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003766 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003767 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3768 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3769 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3770 le16_to_cpu(icb->interrupt_delay_timer): 2;
3771 }
3772 icb->firmware_options_2 &= __constant_cpu_to_le32(
3773 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003774 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003775 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003776 ha->zio_mode = QLA_ZIO_MODE_6;
3777
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003778 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003779 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003780 ha->zio_timer * 100));
3781 qla_printk(KERN_INFO, ha,
3782 "ZIO mode %d enabled; timer delay (%d us).\n",
3783 ha->zio_mode, ha->zio_timer * 100);
3784
3785 icb->firmware_options_2 |= cpu_to_le32(
3786 (uint32_t)ha->zio_mode);
3787 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003788 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003789 }
3790
David Miller4e08df32007-04-16 12:37:43 -07003791 if (rval) {
3792 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003793 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003794 }
3795 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07003796}
3797
Adrian Bunk413975a2006-06-30 02:33:06 -07003798static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003799qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003800{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003801 int rval = QLA_SUCCESS;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003802 int segments, fragment;
3803 uint32_t faddr;
3804 uint32_t *dcode, dlen;
3805 uint32_t risc_addr;
3806 uint32_t risc_size;
3807 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003808 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003809 struct req_que *req = ha->req_q_map[0];
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003810
3811 qla_printk(KERN_INFO, ha,
3812 "FW: Loading from flash (%x)...\n", ha->flt_region_fw);
3813
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003814 rval = QLA_SUCCESS;
3815
3816 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003817 faddr = ha->flt_region_fw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003818 dcode = (uint32_t *)req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003819 *srisc_addr = 0;
3820
3821 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003822 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003823 for (i = 0; i < 4; i++)
3824 dcode[i] = be32_to_cpu(dcode[i]);
3825 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3826 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3827 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3828 dcode[3] == 0)) {
3829 qla_printk(KERN_WARNING, ha,
3830 "Unable to verify integrity of flash firmware image!\n");
3831 qla_printk(KERN_WARNING, ha,
3832 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3833 dcode[1], dcode[2], dcode[3]);
3834
3835 return QLA_FUNCTION_FAILED;
3836 }
3837
3838 while (segments && rval == QLA_SUCCESS) {
3839 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003840 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003841
3842 risc_addr = be32_to_cpu(dcode[2]);
3843 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3844 risc_size = be32_to_cpu(dcode[3]);
3845
3846 fragment = 0;
3847 while (risc_size > 0 && rval == QLA_SUCCESS) {
3848 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3849 if (dlen > risc_size)
3850 dlen = risc_size;
3851
3852 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3853 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003854 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003855
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003856 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003857 for (i = 0; i < dlen; i++)
3858 dcode[i] = swab32(dcode[i]);
3859
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003860 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003861 dlen);
3862 if (rval) {
3863 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003864 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003865 fragment));
3866 qla_printk(KERN_WARNING, ha,
3867 "[ERROR] Failed to load segment %d of "
3868 "firmware\n", fragment);
3869 break;
3870 }
3871
3872 faddr += dlen;
3873 risc_addr += dlen;
3874 risc_size -= dlen;
3875 fragment++;
3876 }
3877
3878 /* Next segment. */
3879 segments--;
3880 }
3881
3882 return rval;
3883}
3884
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003885#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3886
Andrew Vasquez01071092005-07-06 10:31:37 -07003887int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003888qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003889{
3890 int rval;
3891 int i, fragment;
3892 uint16_t *wcode, *fwcode;
3893 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3894 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003895 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003896 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez54333832005-11-09 15:49:04 -08003897
3898 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003899 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003900 if (!blob) {
3901 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003902 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3903 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003904 return QLA_FUNCTION_FAILED;
3905 }
3906
3907 rval = QLA_SUCCESS;
3908
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003909 wcode = (uint16_t *)req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003910 *srisc_addr = 0;
3911 fwcode = (uint16_t *)blob->fw->data;
3912 fwclen = 0;
3913
3914 /* Validate firmware image by checking version. */
3915 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3916 qla_printk(KERN_WARNING, ha,
3917 "Unable to verify integrity of firmware image (%Zd)!\n",
3918 blob->fw->size);
3919 goto fail_fw_integrity;
3920 }
3921 for (i = 0; i < 4; i++)
3922 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3923 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3924 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3925 wcode[2] == 0 && wcode[3] == 0)) {
3926 qla_printk(KERN_WARNING, ha,
3927 "Unable to verify integrity of firmware image!\n");
3928 qla_printk(KERN_WARNING, ha,
3929 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3930 wcode[1], wcode[2], wcode[3]);
3931 goto fail_fw_integrity;
3932 }
3933
3934 seg = blob->segs;
3935 while (*seg && rval == QLA_SUCCESS) {
3936 risc_addr = *seg;
3937 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3938 risc_size = be16_to_cpu(fwcode[3]);
3939
3940 /* Validate firmware image size. */
3941 fwclen += risc_size * sizeof(uint16_t);
3942 if (blob->fw->size < fwclen) {
3943 qla_printk(KERN_WARNING, ha,
3944 "Unable to verify integrity of firmware image "
3945 "(%Zd)!\n", blob->fw->size);
3946 goto fail_fw_integrity;
3947 }
3948
3949 fragment = 0;
3950 while (risc_size > 0 && rval == QLA_SUCCESS) {
3951 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3952 if (wlen > risc_size)
3953 wlen = risc_size;
3954
3955 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003956 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003957 risc_addr, wlen));
3958
3959 for (i = 0; i < wlen; i++)
3960 wcode[i] = swab16(fwcode[i]);
3961
Anirban Chakraborty73208df2008-12-09 16:45:39 -08003962 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003963 wlen);
3964 if (rval) {
3965 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003966 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003967 fragment));
3968 qla_printk(KERN_WARNING, ha,
3969 "[ERROR] Failed to load segment %d of "
3970 "firmware\n", fragment);
3971 break;
3972 }
3973
3974 fwcode += wlen;
3975 risc_addr += wlen;
3976 risc_size -= wlen;
3977 fragment++;
3978 }
3979
3980 /* Next segment. */
3981 seg++;
3982 }
3983 return rval;
3984
3985fail_fw_integrity:
3986 return QLA_FUNCTION_FAILED;
3987}
3988
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08003989static int
3990qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez01071092005-07-06 10:31:37 -07003991{
3992 int rval;
3993 int segments, fragment;
3994 uint32_t *dcode, dlen;
3995 uint32_t risc_addr;
3996 uint32_t risc_size;
3997 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08003998 struct fw_blob *blob;
Andrew Vasquez01071092005-07-06 10:31:37 -07003999 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004000 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004001 struct req_que *req = ha->req_q_map[0];
Andrew Vasquez01071092005-07-06 10:31:37 -07004002
Andrew Vasquez54333832005-11-09 15:49:04 -08004003 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08004005 if (!blob) {
4006 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07004007 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
4008 "from: " QLA_FW_URL ".\n");
4009
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004010 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004011 }
4012
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004013 qla_printk(KERN_INFO, ha,
4014 "FW: Loading via request-firmware...\n");
4015
Andrew Vasquez01071092005-07-06 10:31:37 -07004016 rval = QLA_SUCCESS;
4017
4018 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004019 dcode = (uint32_t *)req->ring;
Andrew Vasquez01071092005-07-06 10:31:37 -07004020 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08004021 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez01071092005-07-06 10:31:37 -07004022 fwclen = 0;
4023
4024 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08004025 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004026 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004027 "Unable to verify integrity of firmware image (%Zd)!\n",
4028 blob->fw->size);
Andrew Vasquez01071092005-07-06 10:31:37 -07004029 goto fail_fw_integrity;
4030 }
4031 for (i = 0; i < 4; i++)
4032 dcode[i] = be32_to_cpu(fwcode[i + 4]);
4033 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
4034 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
4035 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
4036 dcode[3] == 0)) {
4037 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004038 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez01071092005-07-06 10:31:37 -07004039 qla_printk(KERN_WARNING, ha,
4040 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
4041 dcode[1], dcode[2], dcode[3]);
4042 goto fail_fw_integrity;
4043 }
4044
4045 while (segments && rval == QLA_SUCCESS) {
4046 risc_addr = be32_to_cpu(fwcode[2]);
4047 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
4048 risc_size = be32_to_cpu(fwcode[3]);
4049
4050 /* Validate firmware image size. */
4051 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08004052 if (blob->fw->size < fwclen) {
Andrew Vasquez01071092005-07-06 10:31:37 -07004053 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08004054 "Unable to verify integrity of firmware image "
4055 "(%Zd)!\n", blob->fw->size);
4056
Andrew Vasquez01071092005-07-06 10:31:37 -07004057 goto fail_fw_integrity;
4058 }
4059
4060 fragment = 0;
4061 while (risc_size > 0 && rval == QLA_SUCCESS) {
4062 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
4063 if (dlen > risc_size)
4064 dlen = risc_size;
4065
4066 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004068 risc_addr, dlen));
4069
4070 for (i = 0; i < dlen; i++)
4071 dcode[i] = swab32(fwcode[i]);
4072
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004073 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004074 dlen);
Andrew Vasquez01071092005-07-06 10:31:37 -07004075 if (rval) {
4076 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004077 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004078 fragment));
4079 qla_printk(KERN_WARNING, ha,
4080 "[ERROR] Failed to load segment %d of "
4081 "firmware\n", fragment);
4082 break;
4083 }
4084
4085 fwcode += dlen;
4086 risc_addr += dlen;
4087 risc_size -= dlen;
4088 fragment++;
4089 }
4090
4091 /* Next segment. */
4092 segments--;
4093 }
Andrew Vasquez01071092005-07-06 10:31:37 -07004094 return rval;
4095
4096fail_fw_integrity:
Andrew Vasquez01071092005-07-06 10:31:37 -07004097 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004098}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004099
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08004100int
4101qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4102{
4103 int rval;
4104
4105 /*
4106 * FW Load priority:
4107 * 1) Firmware via request-firmware interface (.bin file).
4108 * 2) Firmware residing in flash.
4109 */
4110 rval = qla24xx_load_risc_blob(vha, srisc_addr);
4111 if (rval == QLA_SUCCESS)
4112 return rval;
4113
4114 return qla24xx_load_risc_flash(vha, srisc_addr);
4115}
4116
4117int
4118qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
4119{
4120 int rval;
4121
4122 /*
4123 * FW Load priority:
4124 * 1) Firmware residing in flash.
4125 * 2) Firmware via request-firmware interface (.bin file).
4126 */
4127 rval = qla24xx_load_risc_flash(vha, srisc_addr);
4128 if (rval == QLA_SUCCESS)
4129 return rval;
4130
4131 return qla24xx_load_risc_blob(vha, srisc_addr);
4132}
4133
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004134void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004135qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004136{
4137 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004138 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004139
Andrew Vasqueze4289242007-07-19 15:05:56 -07004140 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004141 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004142 if (!ha->fw_major_version)
4143 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004144
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004145 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004146 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4147 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004148 ha->isp_ops->reset_chip(vha);
4149 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004150 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004152 continue;
4153 qla_printk(KERN_INFO, ha,
4154 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004155 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004156 }
4157}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004158
4159int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004160qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004161{
4162 int rval = QLA_SUCCESS;
4163 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004164 struct qla_hw_data *ha = vha->hw;
4165 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07004166 struct req_que *req = vha->req;
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08004167 struct rsp_que *rsp = req->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004168
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004169 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004170 return -EINVAL;
4171
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004172 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004173 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004174 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08004175 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004176 }
4177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004178 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004179
4180 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004181 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004182 if (mb[0] != MBS_COMMAND_COMPLETE) {
4183 DEBUG15(qla_printk(KERN_INFO, ha,
4184 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4185 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4186 mb[0], mb[1], mb[2], mb[6], mb[7]));
4187 return (QLA_FUNCTION_FAILED);
4188 }
4189
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004190 atomic_set(&vha->loop_down_timer, 0);
4191 atomic_set(&vha->loop_state, LOOP_UP);
4192 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4193 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4194 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004195
4196 return rval;
4197}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004198
4199/* 84XX Support **************************************************************/
4200
4201static LIST_HEAD(qla_cs84xx_list);
4202static DEFINE_MUTEX(qla_cs84xx_mutex);
4203
4204static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004205qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004206{
4207 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004208 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004209
4210 mutex_lock(&qla_cs84xx_mutex);
4211
4212 /* Find any shared 84xx chip. */
4213 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4214 if (cs84xx->bus == ha->pdev->bus) {
4215 kref_get(&cs84xx->kref);
4216 goto done;
4217 }
4218 }
4219
4220 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4221 if (!cs84xx)
4222 goto done;
4223
4224 kref_init(&cs84xx->kref);
4225 spin_lock_init(&cs84xx->access_lock);
4226 mutex_init(&cs84xx->fw_update_mutex);
4227 cs84xx->bus = ha->pdev->bus;
4228
4229 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4230done:
4231 mutex_unlock(&qla_cs84xx_mutex);
4232 return cs84xx;
4233}
4234
4235static void
4236__qla84xx_chip_release(struct kref *kref)
4237{
4238 struct qla_chip_state_84xx *cs84xx =
4239 container_of(kref, struct qla_chip_state_84xx, kref);
4240
4241 mutex_lock(&qla_cs84xx_mutex);
4242 list_del(&cs84xx->list);
4243 mutex_unlock(&qla_cs84xx_mutex);
4244 kfree(cs84xx);
4245}
4246
4247void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004248qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004249{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004250 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004251 if (ha->cs84xx)
4252 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4253}
4254
4255static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004256qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004257{
4258 int rval;
4259 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004260 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004261
4262 mutex_lock(&ha->cs84xx->fw_update_mutex);
4263
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004264 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004265
4266 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4267
4268 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4269 QLA_SUCCESS;
4270}
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004271
4272/* 81XX Support **************************************************************/
4273
4274int
4275qla81xx_nvram_config(scsi_qla_host_t *vha)
4276{
4277 int rval;
4278 struct init_cb_81xx *icb;
4279 struct nvram_81xx *nv;
4280 uint32_t *dptr;
4281 uint8_t *dptr1, *dptr2;
4282 uint32_t chksum;
4283 uint16_t cnt;
4284 struct qla_hw_data *ha = vha->hw;
4285
4286 rval = QLA_SUCCESS;
4287 icb = (struct init_cb_81xx *)ha->init_cb;
4288 nv = ha->nvram;
4289
4290 /* Determine NVRAM starting address. */
4291 ha->nvram_size = sizeof(struct nvram_81xx);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004292 ha->vpd_size = FA_NVRAM_VPD_SIZE;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004293
4294 /* Get VPD data into cache */
4295 ha->vpd = ha->nvram + VPD_OFFSET;
Andrew Vasquez3d790382009-03-24 09:08:14 -07004296 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
4297 ha->vpd_size);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004298
4299 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez3d790382009-03-24 09:08:14 -07004300 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004301 ha->nvram_size);
Andrew Vasquez3d790382009-03-24 09:08:14 -07004302 dptr = (uint32_t *)nv;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004303 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
4304 chksum += le32_to_cpu(*dptr++);
4305
Andrew Vasquez76403352009-04-06 22:33:39 -07004306 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004307 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
4308
4309 /* Bad NVRAM data, set defaults parameters. */
4310 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
4311 || nv->id[3] != ' ' ||
4312 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
4313 /* Reset NVRAM data. */
4314 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
4315 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
4316 le16_to_cpu(nv->nvram_version));
4317 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
4318 "invalid -- WWPN) defaults.\n");
4319
4320 /*
4321 * Set default initialization control block.
4322 */
4323 memset(nv, 0, ha->nvram_size);
4324 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
4325 nv->version = __constant_cpu_to_le16(ICB_VERSION);
4326 nv->frame_payload_size = __constant_cpu_to_le16(2048);
4327 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4328 nv->exchange_count = __constant_cpu_to_le16(0);
4329 nv->port_name[0] = 0x21;
4330 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
4331 nv->port_name[2] = 0x00;
4332 nv->port_name[3] = 0xe0;
4333 nv->port_name[4] = 0x8b;
4334 nv->port_name[5] = 0x1c;
4335 nv->port_name[6] = 0x55;
4336 nv->port_name[7] = 0x86;
4337 nv->node_name[0] = 0x20;
4338 nv->node_name[1] = 0x00;
4339 nv->node_name[2] = 0x00;
4340 nv->node_name[3] = 0xe0;
4341 nv->node_name[4] = 0x8b;
4342 nv->node_name[5] = 0x1c;
4343 nv->node_name[6] = 0x55;
4344 nv->node_name[7] = 0x86;
4345 nv->login_retry_count = __constant_cpu_to_le16(8);
4346 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
4347 nv->login_timeout = __constant_cpu_to_le16(0);
4348 nv->firmware_options_1 =
4349 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
4350 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
4351 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
4352 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
4353 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
4354 nv->efi_parameters = __constant_cpu_to_le32(0);
4355 nv->reset_delay = 5;
4356 nv->max_luns_per_target = __constant_cpu_to_le16(128);
4357 nv->port_down_retry_count = __constant_cpu_to_le16(30);
4358 nv->link_down_timeout = __constant_cpu_to_le16(30);
4359 nv->enode_mac[0] = 0x01;
4360 nv->enode_mac[1] = 0x02;
4361 nv->enode_mac[2] = 0x03;
4362 nv->enode_mac[3] = 0x04;
4363 nv->enode_mac[4] = 0x05;
4364 nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4365
4366 rval = 1;
4367 }
4368
4369 /* Reset Initialization control block */
4370 memset(icb, 0, sizeof(struct init_cb_81xx));
4371
4372 /* Copy 1st segment. */
4373 dptr1 = (uint8_t *)icb;
4374 dptr2 = (uint8_t *)&nv->version;
4375 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
4376 while (cnt--)
4377 *dptr1++ = *dptr2++;
4378
4379 icb->login_retry_count = nv->login_retry_count;
4380
4381 /* Copy 2nd segment. */
4382 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
4383 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
4384 cnt = (uint8_t *)&icb->reserved_5 -
4385 (uint8_t *)&icb->interrupt_delay_timer;
4386 while (cnt--)
4387 *dptr1++ = *dptr2++;
4388
4389 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
4390 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
4391 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
4392 icb->enode_mac[0] = 0x01;
4393 icb->enode_mac[1] = 0x02;
4394 icb->enode_mac[2] = 0x03;
4395 icb->enode_mac[3] = 0x04;
4396 icb->enode_mac[4] = 0x05;
4397 icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn);
4398 }
4399
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07004400 /* Use extended-initialization control block. */
4401 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
4402
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08004403 /*
4404 * Setup driver NVRAM options.
4405 */
4406 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
4407 "QLE81XX");
4408
4409 /* Use alternate WWN? */
4410 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
4411 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4412 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4413 }
4414
4415 /* Prepare nodename */
4416 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
4417 /*
4418 * Firmware will apply the following mask if the nodename was
4419 * not provided.
4420 */
4421 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4422 icb->node_name[0] &= 0xF0;
4423 }
4424
4425 /* Set host adapter parameters. */
4426 ha->flags.disable_risc_code_load = 0;
4427 ha->flags.enable_lip_reset = 0;
4428 ha->flags.enable_lip_full_login =
4429 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
4430 ha->flags.enable_target_reset =
4431 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
4432 ha->flags.enable_led_scheme = 0;
4433 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
4434
4435 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
4436 (BIT_6 | BIT_5 | BIT_4)) >> 4;
4437
4438 /* save HBA serial number */
4439 ha->serial0 = icb->port_name[5];
4440 ha->serial1 = icb->port_name[6];
4441 ha->serial2 = icb->port_name[7];
4442 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4443 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4444
4445 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
4446
4447 ha->retry_count = le16_to_cpu(nv->login_retry_count);
4448
4449 /* Set minimum login_timeout to 4 seconds. */
4450 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
4451 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
4452 if (le16_to_cpu(nv->login_timeout) < 4)
4453 nv->login_timeout = __constant_cpu_to_le16(4);
4454 ha->login_timeout = le16_to_cpu(nv->login_timeout);
4455 icb->login_timeout = nv->login_timeout;
4456
4457 /* Set minimum RATOV to 100 tenths of a second. */
4458 ha->r_a_tov = 100;
4459
4460 ha->loop_reset_delay = nv->reset_delay;
4461
4462 /* Link Down Timeout = 0:
4463 *
4464 * When Port Down timer expires we will start returning
4465 * I/O's to OS with "DID_NO_CONNECT".
4466 *
4467 * Link Down Timeout != 0:
4468 *
4469 * The driver waits for the link to come up after link down
4470 * before returning I/Os to OS with "DID_NO_CONNECT".
4471 */
4472 if (le16_to_cpu(nv->link_down_timeout) == 0) {
4473 ha->loop_down_abort_time =
4474 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4475 } else {
4476 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
4477 ha->loop_down_abort_time =
4478 (LOOP_DOWN_TIME - ha->link_down_timeout);
4479 }
4480
4481 /* Need enough time to try and get the port back. */
4482 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
4483 if (qlport_down_retry)
4484 ha->port_down_retry_count = qlport_down_retry;
4485
4486 /* Set login_retry_count */
4487 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
4488 if (ha->port_down_retry_count ==
4489 le16_to_cpu(nv->port_down_retry_count) &&
4490 ha->port_down_retry_count > 3)
4491 ha->login_retry_count = ha->port_down_retry_count;
4492 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4493 ha->login_retry_count = ha->port_down_retry_count;
4494 if (ql2xloginretrycount)
4495 ha->login_retry_count = ql2xloginretrycount;
4496
4497 /* Enable ZIO. */
4498 if (!vha->flags.init_done) {
4499 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
4500 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4501 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
4502 le16_to_cpu(icb->interrupt_delay_timer): 2;
4503 }
4504 icb->firmware_options_2 &= __constant_cpu_to_le32(
4505 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
4506 vha->flags.process_response_queue = 0;
4507 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4508 ha->zio_mode = QLA_ZIO_MODE_6;
4509
4510 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
4511 "(%d us).\n", vha->host_no, ha->zio_mode,
4512 ha->zio_timer * 100));
4513 qla_printk(KERN_INFO, ha,
4514 "ZIO mode %d enabled; timer delay (%d us).\n",
4515 ha->zio_mode, ha->zio_timer * 100);
4516
4517 icb->firmware_options_2 |= cpu_to_le32(
4518 (uint32_t)ha->zio_mode);
4519 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
4520 vha->flags.process_response_queue = 1;
4521 }
4522
4523 if (rval) {
4524 DEBUG2_3(printk(KERN_WARNING
4525 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
4526 }
4527 return (rval);
4528}
4529
4530void
4531qla81xx_update_fw_options(scsi_qla_host_t *ha)
4532{
4533}