blob: 7bee87f90f6d5880fa8febfd983e02d61b6ecb3f [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"
8
9#include <linux/delay.h>
Andrew Vasquez01071092005-07-06 10:31:37 -070010#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011
12#include "qla_devtbl.h"
13
David Miller4e08df32007-04-16 12:37:43 -070014#ifdef CONFIG_SPARC
15#include <asm/prom.h>
David Miller4e08df32007-04-16 12:37:43 -070016#endif
17
Linus Torvalds1da177e2005-04-16 15:20:36 -070018/*
19* QLogic ISP2x00 Hardware Support Function Prototypes.
20*/
Linus Torvalds1da177e2005-04-16 15:20:36 -070021static int qla2x00_isp_firmware(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070022static void qla2x00_resize_request_q(scsi_qla_host_t *);
23static int qla2x00_setup_chip(scsi_qla_host_t *);
24static void qla2x00_init_response_q_entries(scsi_qla_host_t *);
25static int qla2x00_init_rings(scsi_qla_host_t *);
26static int qla2x00_fw_ready(scsi_qla_host_t *);
27static int qla2x00_configure_hba(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070028static int qla2x00_configure_loop(scsi_qla_host_t *);
29static int qla2x00_configure_local_loop(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070030static int qla2x00_configure_fabric(scsi_qla_host_t *);
31static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *);
32static int qla2x00_device_resync(scsi_qla_host_t *);
33static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *,
34 uint16_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36static int qla2x00_restart_isp(scsi_qla_host_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080038static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *);
Adrian Bunk413975a2006-06-30 02:33:06 -070039
Harihara Kadayam4d4df192008-04-03 13:13:26 -070040static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
41static int qla84xx_init_chip(scsi_qla_host_t *);
42
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;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 /* Clear adapter flags. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080063 vha->flags.online = 0;
64 vha->flags.reset_active = 0;
65 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
66 atomic_set(&vha->loop_state, LOOP_DOWN);
67 vha->device_flags = DFLG_NO_CABLE;
68 vha->dpc_flags = 0;
69 vha->flags.management_server_logged_in = 0;
70 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 ha->mbx_flags = 0;
72 ha->isp_abort_cnt = 0;
73 ha->beacon_blink_led = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080074 set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Andrew Vasquez01071092005-07-06 10:31:37 -070076 qla_printk(KERN_INFO, ha, "Configuring PCI space...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080077 rval = ha->isp_ops->pci_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 if (rval) {
Andrew Vasquez7c98a042007-01-29 10:22:29 -080079 DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080080 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 return (rval);
82 }
83
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080084 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080086 rval = qla2xxx_get_flash_info(vha);
Andrew Vasquezc00d8992008-09-11 21:22:49 -070087 if (rval) {
88 DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080089 vha->host_no));
Andrew Vasquezc00d8992008-09-11 21:22:49 -070090 return (rval);
91 }
92
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080093 ha->isp_ops->get_flash_version(vha, ha->req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -080094
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n");
Andrew Vasquez01071092005-07-06 10:31:37 -070096
Anirban Chakrabortye315cd22008-11-06 10:40:51 -080097 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Andrew Vasquezd4c760c2006-06-23 16:10:39 -070099 if (ha->flags.disable_serdes) {
100 /* Mask HBA via NVRAM settings? */
101 qla_printk(KERN_INFO, ha, "Masking HBA WWPN "
102 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800103 vha->port_name[0], vha->port_name[1],
104 vha->port_name[2], vha->port_name[3],
105 vha->port_name[4], vha->port_name[5],
106 vha->port_name[6], vha->port_name[7]);
Andrew Vasquezd4c760c2006-06-23 16:10:39 -0700107 return QLA_FUNCTION_FAILED;
108 }
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n");
111
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800112 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
113 rval = ha->isp_ops->chip_diag(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800114 if (rval)
115 return (rval);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800116 rval = qla2x00_setup_chip(vha);
Andrew Vasquezd19044c2006-11-22 08:22:19 -0800117 if (rval)
118 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700120 if (IS_QLA84XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800121 ha->cs84xx = qla84xx_get_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -0700122 if (!ha->cs84xx) {
123 qla_printk(KERN_ERR, ha,
124 "Unable to configure ISP84XX.\n");
125 return QLA_FUNCTION_FAILED;
126 }
127 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800128 rval = qla2x00_init_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 return (rval);
131}
132
133/**
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700134 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 * @ha: HA context
136 *
137 * Returns 0 on success.
138 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700139int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800140qla2100_pci_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700142 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700143 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800144 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700145 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700148 pci_try_set_mwi(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700151 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
153
Andrew Vasquez737faec2008-10-24 15:13:45 -0700154 pci_disable_rom(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700156 /* Get PCI bus information. */
157 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700158 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700159 spin_unlock_irqrestore(&ha->hardware_lock, flags);
160
161 return QLA_SUCCESS;
162}
163
164/**
165 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
166 * @ha: HA context
167 *
168 * Returns 0 on success.
169 */
170int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800171qla2300_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700172{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700173 uint16_t w;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700174 unsigned long flags = 0;
175 uint32_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800176 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700177 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700178
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700179 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700180 pci_try_set_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700181
182 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700183 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700184
185 if (IS_QLA2322(ha) || IS_QLA6322(ha))
186 w &= ~PCI_COMMAND_INTX_DISABLE;
Andrew Vasqueza157b102007-05-07 07:43:01 -0700187 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700188
189 /*
190 * If this is a 2300 card and not 2312, reset the
191 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
192 * the 2310 also reports itself as a 2300 so we need to get the
193 * fb revision level -- a 6 indicates it really is a 2300 and
194 * not a 2310.
195 */
196 if (IS_QLA2300(ha)) {
197 spin_lock_irqsave(&ha->hardware_lock, flags);
198
199 /* Pause RISC. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700200 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700201 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700202 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) != 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700203 break;
204
205 udelay(10);
206 }
207
208 /* Select FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700209 WRT_REG_WORD(&reg->ctrl_status, 0x20);
210 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700211
212 /* Get the fb rev level */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700213 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700214
215 if (ha->fb_rev == FPM_2300)
Andrew Vasqueza157b102007-05-07 07:43:01 -0700216 pci_clear_mwi(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700217
218 /* Deselect FPM registers. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700219 WRT_REG_WORD(&reg->ctrl_status, 0x0);
220 RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700221
222 /* Release RISC module. */
Andrew Vasquez3d716442005-07-06 10:30:26 -0700223 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700224 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquez3d716442005-07-06 10:30:26 -0700225 if ((RD_REG_WORD(&reg->hccr) & HCCR_RISC_PAUSE) == 0)
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700226 break;
227
228 udelay(10);
229 }
230
231 spin_unlock_irqrestore(&ha->hardware_lock, flags);
232 }
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700233
234 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
235
Andrew Vasquez737faec2008-10-24 15:13:45 -0700236 pci_disable_rom(ha->pdev);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700237
238 /* Get PCI bus information. */
239 spin_lock_irqsave(&ha->hardware_lock, flags);
Andrew Vasquez3d716442005-07-06 10:30:26 -0700240 ha->pci_attr = RD_REG_WORD(&reg->ctrl_status);
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700241 spin_unlock_irqrestore(&ha->hardware_lock, flags);
242
243 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244}
245
246/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700247 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
248 * @ha: HA context
249 *
250 * Returns 0 on success.
251 */
252int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800253qla24xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700254{
Andrew Vasqueza157b102007-05-07 07:43:01 -0700255 uint16_t w;
Andrew Vasquez01071092005-07-06 10:31:37 -0700256 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800257 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700258 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
Andrew Vasquez01071092005-07-06 10:31:37 -0700259
260 pci_set_master(ha->pdev);
Andrew Vasquezaf6177d2007-07-19 15:06:02 -0700261 pci_try_set_mwi(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700262
263 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
Andrew Vasqueza157b102007-05-07 07:43:01 -0700264 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
Andrew Vasquez01071092005-07-06 10:31:37 -0700265 w &= ~PCI_COMMAND_INTX_DISABLE;
266 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
267
268 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
269
270 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700271 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
272 pcix_set_mmrbc(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700273
274 /* PCIe -- adjust Maximum Read Request Size (2048). */
Andrew Vasquezf85ec182007-07-19 15:06:01 -0700275 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
276 pcie_set_readrq(ha->pdev, 2048);
Andrew Vasquez01071092005-07-06 10:31:37 -0700277
Andrew Vasquez737faec2008-10-24 15:13:45 -0700278 pci_disable_rom(ha->pdev);
Andrew Vasquez01071092005-07-06 10:31:37 -0700279
Auke Kok44c10132007-06-08 15:46:36 -0700280 ha->chip_revision = ha->pdev->revision;
Andrew Vasqueza8488ab2007-01-29 10:22:19 -0800281
Andrew Vasquez01071092005-07-06 10:31:37 -0700282 /* Get PCI bus information. */
283 spin_lock_irqsave(&ha->hardware_lock, flags);
284 ha->pci_attr = RD_REG_DWORD(&reg->ctrl_status);
285 spin_unlock_irqrestore(&ha->hardware_lock, flags);
286
287 return QLA_SUCCESS;
288}
289
290/**
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700291 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
292 * @ha: HA context
293 *
294 * Returns 0 on success.
295 */
296int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800297qla25xx_pci_config(scsi_qla_host_t *vha)
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700298{
299 uint16_t w;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800300 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700301
302 pci_set_master(ha->pdev);
303 pci_try_set_mwi(ha->pdev);
304
305 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
306 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
307 w &= ~PCI_COMMAND_INTX_DISABLE;
308 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
309
310 /* PCIe -- adjust Maximum Read Request Size (2048). */
311 if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP))
312 pcie_set_readrq(ha->pdev, 2048);
313
Andrew Vasquez737faec2008-10-24 15:13:45 -0700314 pci_disable_rom(ha->pdev);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700315
316 ha->chip_revision = ha->pdev->revision;
317
318 return QLA_SUCCESS;
319}
320
321/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * qla2x00_isp_firmware() - Choose firmware image.
323 * @ha: HA context
324 *
325 * Returns 0 on success.
326 */
327static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800328qla2x00_isp_firmware(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329{
330 int rval;
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700331 uint16_t loop_id, topo, sw_cap;
332 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800333 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334
335 /* Assume loading risc code */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700336 rval = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 if (ha->flags.disable_risc_code_load) {
339 DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800340 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n");
342
343 /* Verify checksum of loaded RISC code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800344 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700345 if (rval == QLA_SUCCESS) {
346 /* And, verify we are not in ROM code. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800347 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
Andrew Vasquez42e421b2008-07-10 16:56:01 -0700348 &area, &domain, &topo, &sw_cap);
349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
352 if (rval) {
353 DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800354 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355 }
356
357 return (rval);
358}
359
360/**
361 * qla2x00_reset_chip() - Reset ISP chip.
362 * @ha: HA context
363 *
364 * Returns 0 on success.
365 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700366void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800367qla2x00_reset_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368{
369 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800370 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700371 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372 uint32_t cnt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 uint16_t cmd;
374
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700375 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
377 spin_lock_irqsave(&ha->hardware_lock, flags);
378
379 /* Turn off master enable */
380 cmd = 0;
381 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
382 cmd &= ~PCI_COMMAND_MASTER;
383 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
384
385 if (!IS_QLA2100(ha)) {
386 /* Pause RISC. */
387 WRT_REG_WORD(&reg->hccr, HCCR_PAUSE_RISC);
388 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
389 for (cnt = 0; cnt < 30000; cnt++) {
390 if ((RD_REG_WORD(&reg->hccr) &
391 HCCR_RISC_PAUSE) != 0)
392 break;
393 udelay(100);
394 }
395 } else {
396 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
397 udelay(10);
398 }
399
400 /* Select FPM registers. */
401 WRT_REG_WORD(&reg->ctrl_status, 0x20);
402 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
403
404 /* FPM Soft Reset. */
405 WRT_REG_WORD(&reg->fpm_diag_config, 0x100);
406 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
407
408 /* Toggle Fpm Reset. */
409 if (!IS_QLA2200(ha)) {
410 WRT_REG_WORD(&reg->fpm_diag_config, 0x0);
411 RD_REG_WORD(&reg->fpm_diag_config); /* PCI Posting. */
412 }
413
414 /* Select frame buffer registers. */
415 WRT_REG_WORD(&reg->ctrl_status, 0x10);
416 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
417
418 /* Reset frame buffer FIFOs. */
419 if (IS_QLA2200(ha)) {
420 WRT_FB_CMD_REG(ha, reg, 0xa000);
421 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
422 } else {
423 WRT_FB_CMD_REG(ha, reg, 0x00fc);
424
425 /* Read back fb_cmd until zero or 3 seconds max */
426 for (cnt = 0; cnt < 3000; cnt++) {
427 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
428 break;
429 udelay(100);
430 }
431 }
432
433 /* Select RISC module registers. */
434 WRT_REG_WORD(&reg->ctrl_status, 0);
435 RD_REG_WORD(&reg->ctrl_status); /* PCI Posting. */
436
437 /* Reset RISC processor. */
438 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
439 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
440
441 /* Release RISC processor. */
442 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
443 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
444 }
445
446 WRT_REG_WORD(&reg->hccr, HCCR_CLR_RISC_INT);
447 WRT_REG_WORD(&reg->hccr, HCCR_CLR_HOST_INT);
448
449 /* Reset ISP chip. */
450 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
451
452 /* Wait for RISC to recover from reset. */
453 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
454 /*
455 * It is necessary to for a delay here since the card doesn't
456 * respond to PCI reads during a reset. On some architectures
457 * this will result in an MCA.
458 */
459 udelay(20);
460 for (cnt = 30000; cnt; cnt--) {
461 if ((RD_REG_WORD(&reg->ctrl_status) &
462 CSR_ISP_SOFT_RESET) == 0)
463 break;
464 udelay(100);
465 }
466 } else
467 udelay(10);
468
469 /* Reset RISC processor. */
470 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
471
472 WRT_REG_WORD(&reg->semaphore, 0);
473
474 /* Release RISC processor. */
475 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
476 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
477
478 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
479 for (cnt = 0; cnt < 30000; cnt++) {
Andrew Vasquezffb39f02006-05-17 15:09:06 -0700480 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 udelay(100);
484 }
485 } else
486 udelay(100);
487
488 /* Turn on master enable */
489 cmd |= PCI_COMMAND_MASTER;
490 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
491
492 /* Disable RISC pause on FPM parity error. */
493 if (!IS_QLA2100(ha)) {
494 WRT_REG_WORD(&reg->hccr, HCCR_DISABLE_PARITY_PAUSE);
495 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
496 }
497
498 spin_unlock_irqrestore(&ha->hardware_lock, flags);
499}
500
501/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700502 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
Andrew Vasquez01071092005-07-06 10:31:37 -0700503 * @ha: HA context
504 *
505 * Returns 0 on success.
506 */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700507static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800508qla24xx_reset_risc(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700509{
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700510 int hw_evt = 0;
Andrew Vasquez01071092005-07-06 10:31:37 -0700511 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800512 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700513 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
514 uint32_t cnt, d2;
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800515 uint16_t wd;
Andrew Vasquez01071092005-07-06 10:31:37 -0700516
Andrew Vasquez01071092005-07-06 10:31:37 -0700517 spin_lock_irqsave(&ha->hardware_lock, flags);
518
519 /* Reset RISC. */
520 WRT_REG_DWORD(&reg->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
521 for (cnt = 0; cnt < 30000; cnt++) {
522 if ((RD_REG_DWORD(&reg->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
523 break;
524
525 udelay(10);
526 }
527
528 WRT_REG_DWORD(&reg->ctrl_status,
529 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800530 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700531
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800532 udelay(100);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700533 /* Wait for firmware to complete NVRAM accesses. */
Andrew Vasquez88c26662005-07-08 17:59:26 -0700534 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
535 for (cnt = 10000 ; cnt && d2; cnt--) {
536 udelay(5);
537 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
538 barrier();
539 }
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700540 if (cnt == 0)
541 hw_evt = 1;
Andrew Vasquez88c26662005-07-08 17:59:26 -0700542
Andrew Vasquez335a1cc2005-11-08 14:37:48 -0800543 /* Wait for soft-reset to complete. */
Andrew Vasquez01071092005-07-06 10:31:37 -0700544 d2 = RD_REG_DWORD(&reg->ctrl_status);
545 for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) {
546 udelay(5);
547 d2 = RD_REG_DWORD(&reg->ctrl_status);
548 barrier();
549 }
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700550 if (cnt == 0 || hw_evt)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800551 qla2xxx_hw_event_log(vha, HW_EVENT_RESET_ERR,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -0700552 RD_REG_WORD(&reg->mailbox1), RD_REG_WORD(&reg->mailbox2),
553 RD_REG_WORD(&reg->mailbox3));
Andrew Vasquez01071092005-07-06 10:31:37 -0700554
555 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
556 RD_REG_DWORD(&reg->hccr);
557
558 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
559 RD_REG_DWORD(&reg->hccr);
560
561 WRT_REG_DWORD(&reg->hccr, HCCRX_CLR_RISC_RESET);
562 RD_REG_DWORD(&reg->hccr);
563
564 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
565 for (cnt = 6000000 ; cnt && d2; cnt--) {
566 udelay(5);
567 d2 = (uint32_t) RD_REG_WORD(&reg->mailbox0);
568 barrier();
569 }
570
571 spin_unlock_irqrestore(&ha->hardware_lock, flags);
572}
573
574/**
Andrew Vasquez88c26662005-07-08 17:59:26 -0700575 * qla24xx_reset_chip() - Reset ISP24xx chip.
576 * @ha: HA context
577 *
578 * Returns 0 on success.
579 */
580void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800581qla24xx_reset_chip(scsi_qla_host_t *vha)
Andrew Vasquez88c26662005-07-08 17:59:26 -0700582{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfd34f552007-07-19 15:06:00 -0700584 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700585
586 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 qla24xx_reset_risc(vha);
Andrew Vasquez88c26662005-07-08 17:59:26 -0700588}
589
590/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700591 * qla2x00_chip_diag() - Test chip for proper operation.
592 * @ha: HA context
593 *
594 * Returns 0 on success.
595 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -0700596int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800597qla2x00_chip_diag(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
599 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800600 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -0700601 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602 unsigned long flags = 0;
603 uint16_t data;
604 uint32_t cnt;
605 uint16_t mb[5];
606
607 /* Assume a failed state */
608 rval = QLA_FUNCTION_FAILED;
609
610 DEBUG3(printk("scsi(%ld): Testing device at %lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800611 vha->host_no, (u_long)&reg->flash_address));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612
613 spin_lock_irqsave(&ha->hardware_lock, flags);
614
615 /* Reset ISP chip. */
616 WRT_REG_WORD(&reg->ctrl_status, CSR_ISP_SOFT_RESET);
617
618 /*
619 * We need to have a delay here since the card will not respond while
620 * in reset causing an MCA on some architectures.
621 */
622 udelay(20);
623 data = qla2x00_debounce_register(&reg->ctrl_status);
624 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
625 udelay(5);
626 data = RD_REG_WORD(&reg->ctrl_status);
627 barrier();
628 }
629
630 if (!cnt)
631 goto chip_diag_failed;
632
633 DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n",
634 ha->host_no));
635
636 /* Reset RISC processor. */
637 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
638 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
639
640 /* Workaround for QLA2312 PCI parity error */
641 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
642 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
643 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
644 udelay(5);
645 data = RD_MAILBOX_REG(ha, reg, 0);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700646 barrier();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 }
648 } else
649 udelay(10);
650
651 if (!cnt)
652 goto chip_diag_failed;
653
654 /* Check product ID of chip */
655 DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no));
656
657 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
658 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
659 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
660 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
661 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
662 mb[3] != PROD_ID_3) {
663 qla_printk(KERN_WARNING, ha,
664 "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]);
665
666 goto chip_diag_failed;
667 }
668 ha->product_id[0] = mb[1];
669 ha->product_id[1] = mb[2];
670 ha->product_id[2] = mb[3];
671 ha->product_id[3] = mb[4];
672
673 /* Adjust fw RISC transfer size */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800674 if (ha->req->length > 1024)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
676 else
677 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800678 ha->req->length;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679
680 if (IS_QLA2200(ha) &&
681 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
682 /* Limit firmware transfer size with a 2200A */
683 DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800684 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -0800686 ha->device_type |= DT_ISP2200A;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 ha->fw_transfer_size = 128;
688 }
689
690 /* Wrap Incoming Mailboxes Test. */
691 spin_unlock_irqrestore(&ha->hardware_lock, flags);
692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800693 DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no));
694 rval = qla2x00_mbx_reg_test(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 if (rval) {
696 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800697 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 qla_printk(KERN_WARNING, ha,
699 "Failed mailbox send register test\n");
700 }
701 else {
702 /* Flag a successful rval */
703 rval = QLA_SUCCESS;
704 }
705 spin_lock_irqsave(&ha->hardware_lock, flags);
706
707chip_diag_failed:
708 if (rval)
709 DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800710 "****\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
712 spin_unlock_irqrestore(&ha->hardware_lock, flags);
713
714 return (rval);
715}
716
717/**
Andrew Vasquez01071092005-07-06 10:31:37 -0700718 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
719 * @ha: HA context
720 *
721 * Returns 0 on success.
722 */
723int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800724qla24xx_chip_diag(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700725{
726 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800727 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -0700728
Andrew Vasquez88c26662005-07-08 17:59:26 -0700729 /* Perform RISC reset. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800730 qla24xx_reset_risc(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700731
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800732 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * ha->req->length;
Andrew Vasquez01071092005-07-06 10:31:37 -0700733
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800734 rval = qla2x00_mbx_reg_test(vha);
Andrew Vasquez01071092005-07-06 10:31:37 -0700735 if (rval) {
736 DEBUG(printk("scsi(%ld): Failed mailbox send register test\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800737 vha->host_no));
Andrew Vasquez01071092005-07-06 10:31:37 -0700738 qla_printk(KERN_WARNING, ha,
739 "Failed mailbox send register test\n");
740 } else {
741 /* Flag a successful rval */
742 rval = QLA_SUCCESS;
743 }
744
745 return rval;
746}
747
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700748void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800749qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -0700750{
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700751 int rval;
752 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800753 eft_size, fce_size;
754 dma_addr_t tc_dma;
755 void *tc;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800756 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700757
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700758 if (ha->fw_dump) {
759 qla_printk(KERN_WARNING, ha,
760 "Firmware dump previously allocated.\n");
761 return;
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700762 }
763
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700764 ha->fw_dumped = 0;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800765 fixed_size = mem_size = eft_size = fce_size = 0;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700766 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
767 fixed_size = sizeof(struct qla2100_fw_dump);
768 } else if (IS_QLA23XX(ha)) {
769 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
770 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
771 sizeof(uint16_t);
Andrew Vasqueze4289242007-07-19 15:05:56 -0700772 } else if (IS_FWI2_CAPABLE(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700773 fixed_size = IS_QLA25XX(ha) ?
774 offsetof(struct qla25xx_fw_dump, ext_mem):
775 offsetof(struct qla24xx_fw_dump, ext_mem);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700776 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
777 sizeof(uint32_t);
778
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700779 /* Allocate memory for Fibre Channel Event Buffer. */
780 if (!IS_QLA25XX(ha))
781 goto try_eft;
782
783 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
784 GFP_KERNEL);
785 if (!tc) {
786 qla_printk(KERN_WARNING, ha, "Unable to allocate "
787 "(%d KB) for FCE.\n", FCE_SIZE / 1024);
788 goto try_eft;
789 }
790
791 memset(tc, 0, FCE_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800792 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
Andrew Vasquez436a7b12008-07-10 16:55:54 -0700793 ha->fce_mb, &ha->fce_bufs);
794 if (rval) {
795 qla_printk(KERN_WARNING, ha, "Unable to initialize "
796 "FCE (%d).\n", rval);
797 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
798 tc_dma);
799 ha->flags.fce_enabled = 0;
800 goto try_eft;
801 }
802
803 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n",
804 FCE_SIZE / 1024);
805
806 fce_size = sizeof(struct qla2xxx_fce_chain) + EFT_SIZE;
807 ha->flags.fce_enabled = 1;
808 ha->fce_dma = tc_dma;
809 ha->fce = tc;
810try_eft:
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700811 /* Allocate memory for Extended Trace Buffer. */
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800812 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700813 GFP_KERNEL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800814 if (!tc) {
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700815 qla_printk(KERN_WARNING, ha, "Unable to allocate "
816 "(%d KB) for EFT.\n", EFT_SIZE / 1024);
817 goto cont_alloc;
818 }
819
Andrew Vasquezfc447652008-01-17 09:02:18 -0800820 memset(tc, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800821 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700822 if (rval) {
823 qla_printk(KERN_WARNING, ha, "Unable to initialize "
824 "EFT (%d).\n", rval);
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800825 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
826 tc_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700827 goto cont_alloc;
828 }
829
830 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n",
831 EFT_SIZE / 1024);
832
833 eft_size = EFT_SIZE;
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800834 ha->eft_dma = tc_dma;
835 ha->eft = tc;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700836 }
837cont_alloc:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 req_q_size = ha->req->length * sizeof(request_t);
839 rsp_q_size = ha->rsp->length * sizeof(response_t);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700840
841 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
842 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size +
Andrew Vasquezdf613b92008-01-17 09:02:17 -0800843 eft_size + fce_size;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700844
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700845 ha->fw_dump = vmalloc(dump_size);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700846 if (!ha->fw_dump) {
Andrew Vasquez01071092005-07-06 10:31:37 -0700847 qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for "
Andrew Vasquezd4e3e042006-05-17 15:09:50 -0700848 "firmware dump!!!\n", dump_size / 1024);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700849
850 if (ha->eft) {
851 dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft,
852 ha->eft_dma);
853 ha->eft = NULL;
854 ha->eft_dma = 0;
855 }
856 return;
857 }
858
859 qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n",
860 dump_size / 1024);
861
862 ha->fw_dump_len = dump_size;
863 ha->fw_dump->signature[0] = 'Q';
864 ha->fw_dump->signature[1] = 'L';
865 ha->fw_dump->signature[2] = 'G';
866 ha->fw_dump->signature[3] = 'C';
867 ha->fw_dump->version = __constant_htonl(1);
868
869 ha->fw_dump->fixed_size = htonl(fixed_size);
870 ha->fw_dump->mem_size = htonl(mem_size);
871 ha->fw_dump->req_q_size = htonl(req_q_size);
872 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
873
874 ha->fw_dump->eft_size = htonl(eft_size);
875 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
876 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
877
878 ha->fw_dump->header_size =
879 htonl(offsetof(struct qla2xxx_fw_dump, isp));
Andrew Vasquez01071092005-07-06 10:31:37 -0700880}
881
882/**
Linus Torvalds1da177e2005-04-16 15:20:36 -0700883 * qla2x00_resize_request_q() - Resize request queue given available ISP memory.
884 * @ha: HA context
885 *
886 * Returns 0 on success.
887 */
888static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800889qla2x00_resize_request_q(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700890{
891 int rval;
892 uint16_t fw_iocb_cnt = 0;
893 uint16_t request_q_length = REQUEST_ENTRY_CNT_2XXX_EXT_MEM;
894 dma_addr_t request_dma;
895 request_t *request_ring;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800896 struct qla_hw_data *ha = vha->hw;
897 struct req_que *req = ha->req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898
899 /* Valid only on recent ISPs. */
900 if (IS_QLA2100(ha) || IS_QLA2200(ha))
901 return;
902
903 /* Retrieve IOCB counts available to the firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800904 rval = qla2x00_get_resource_cnts(vha, NULL, NULL, NULL, &fw_iocb_cnt,
905 &ha->max_npiv_vports);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700906 if (rval)
907 return;
908 /* No point in continuing if current settings are sufficient. */
909 if (fw_iocb_cnt < 1024)
910 return;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800911 if (req->length >= request_q_length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 return;
913
914 /* Attempt to claim larger area for request queue. */
915 request_ring = dma_alloc_coherent(&ha->pdev->dev,
916 (request_q_length + 1) * sizeof(request_t), &request_dma,
917 GFP_KERNEL);
918 if (request_ring == NULL)
919 return;
920
921 /* Resize successful, report extensions. */
922 qla_printk(KERN_INFO, ha, "Extended memory detected (%d KB)...\n",
923 (ha->fw_memory_size + 1) / 1024);
924 qla_printk(KERN_INFO, ha, "Resizing request queue depth "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800925 "(%d -> %d)...\n", req->length, request_q_length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700926
927 /* Clear old allocations. */
928 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800929 (req->length + 1) * sizeof(request_t), req->ring,
930 req->dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931
932 /* Begin using larger queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800933 req->length = request_q_length;
934 req->ring = request_ring;
935 req->dma = request_dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936}
937
938/**
939 * qla2x00_setup_chip() - Load and start RISC firmware.
940 * @ha: HA context
941 *
942 * Returns 0 on success.
943 */
944static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800945qla2x00_setup_chip(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700946{
Andrew Vasquez01071092005-07-06 10:31:37 -0700947 int rval;
948 uint32_t srisc_address = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800949 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3db06522008-01-31 12:33:49 -0800950 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
951 unsigned long flags;
952
953 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
954 /* Disable SRAM, Instruction RAM and GP RAM parity. */
955 spin_lock_irqsave(&ha->hardware_lock, flags);
956 WRT_REG_WORD(&reg->hccr, (HCCR_ENABLE_PARITY + 0x0));
957 RD_REG_WORD(&reg->hccr);
958 spin_unlock_irqrestore(&ha->hardware_lock, flags);
959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700960
961 /* Load firmware sequences */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800962 rval = ha->isp_ops->load_risc(vha, &srisc_address);
Andrew Vasquez01071092005-07-06 10:31:37 -0700963 if (rval == QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800965 "code.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700966
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800967 rval = qla2x00_verify_checksum(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700968 if (rval == QLA_SUCCESS) {
969 /* Start firmware execution. */
970 DEBUG(printk("scsi(%ld): Checksum OK, start "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800971 "firmware.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800973 rval = qla2x00_execute_fw(vha, srisc_address);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974 /* Retrieve firmware information. */
975 if (rval == QLA_SUCCESS && ha->fw_major_version == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800976 qla2x00_get_fw_version(vha,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 &ha->fw_major_version,
978 &ha->fw_minor_version,
979 &ha->fw_subminor_version,
980 &ha->fw_attributes, &ha->fw_memory_size);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700981 ha->flags.npiv_supported = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800982 if (IS_QLA2XXX_MIDTYPE(ha) &&
Mike Hernandez946fb892008-08-13 21:36:59 -0700983 (ha->fw_attributes & BIT_2)) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700984 ha->flags.npiv_supported = 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700985 if ((!ha->max_npiv_vports) ||
986 ((ha->max_npiv_vports + 1) %
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800987 MIN_MULTI_ID_FABRIC))
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700988 ha->max_npiv_vports =
Andrew Vasquezeb66dc62007-11-12 10:30:58 -0800989 MIN_MULTI_ID_FABRIC - 1;
Seokmann Ju4d0ea242007-09-20 14:07:43 -0700990 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800991 qla2x00_resize_request_q(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -0700992
993 if (ql2xallocfwdump)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800994 qla2x00_alloc_fw_dump(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700995 }
996 } else {
997 DEBUG2(printk(KERN_INFO
998 "scsi(%ld): ISP Firmware failed checksum.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800999 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000 }
1001 }
1002
Andrew Vasquez3db06522008-01-31 12:33:49 -08001003 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
1004 /* Enable proper parity. */
1005 spin_lock_irqsave(&ha->hardware_lock, flags);
1006 if (IS_QLA2300(ha))
1007 /* SRAM parity */
1008 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x1);
1009 else
1010 /* SRAM, Instruction RAM and GP RAM parity */
1011 WRT_REG_WORD(&reg->hccr, HCCR_ENABLE_PARITY + 0x7);
1012 RD_REG_WORD(&reg->hccr);
1013 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1014 }
1015
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016 if (rval) {
1017 DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001018 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019 }
1020
1021 return (rval);
1022}
1023
1024/**
1025 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1026 * @ha: HA context
1027 *
1028 * Beginning of request ring has initialization control block already built
1029 * by nvram config routine.
1030 *
1031 * Returns 0 on success.
1032 */
1033static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001034qla2x00_init_response_q_entries(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035{
1036 uint16_t cnt;
1037 response_t *pkt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001038 struct rsp_que *rsp = vha->hw->rsp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001039
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001040 pkt = rsp->ring_ptr;
1041 for (cnt = 0; cnt < rsp->length; cnt++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001042 pkt->signature = RESPONSE_PROCESSED;
1043 pkt++;
1044 }
1045
1046}
1047
1048/**
1049 * qla2x00_update_fw_options() - Read and process firmware options.
1050 * @ha: HA context
1051 *
1052 * Returns 0 on success.
1053 */
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001054void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001055qla2x00_update_fw_options(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001056{
1057 uint16_t swing, emphasis, tx_sens, rx_sens;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001058 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001059
1060 memset(ha->fw_options, 0, sizeof(ha->fw_options));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001061 qla2x00_get_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062
1063 if (IS_QLA2100(ha) || IS_QLA2200(ha))
1064 return;
1065
1066 /* Serial Link options. */
1067 DEBUG3(printk("scsi(%ld): Serial link options:\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001068 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001069 DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options,
1070 sizeof(ha->fw_seriallink_options)));
1071
1072 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
1073 if (ha->fw_seriallink_options[3] & BIT_2) {
1074 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
1075
1076 /* 1G settings */
1077 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
1078 emphasis = (ha->fw_seriallink_options[2] &
1079 (BIT_4 | BIT_3)) >> 3;
1080 tx_sens = ha->fw_seriallink_options[0] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001081 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001082 rx_sens = (ha->fw_seriallink_options[0] &
1083 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1084 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
1085 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1086 if (rx_sens == 0x0)
1087 rx_sens = 0x3;
1088 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
1089 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1090 ha->fw_options[10] |= BIT_5 |
1091 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1092 (tx_sens & (BIT_1 | BIT_0));
1093
1094 /* 2G settings */
1095 swing = (ha->fw_seriallink_options[2] &
1096 (BIT_7 | BIT_6 | BIT_5)) >> 5;
1097 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
1098 tx_sens = ha->fw_seriallink_options[1] &
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001099 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100 rx_sens = (ha->fw_seriallink_options[1] &
1101 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
1102 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
1103 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
1104 if (rx_sens == 0x0)
1105 rx_sens = 0x3;
1106 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
1107 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
1108 ha->fw_options[11] |= BIT_5 |
1109 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
1110 (tx_sens & (BIT_1 | BIT_0));
1111 }
1112
1113 /* FCP2 options. */
1114 /* Return command IOCBs without waiting for an ABTS to complete. */
1115 ha->fw_options[3] |= BIT_13;
1116
1117 /* LED scheme. */
1118 if (ha->flags.enable_led_scheme)
1119 ha->fw_options[2] |= BIT_12;
1120
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08001121 /* Detect ISP6312. */
1122 if (IS_QLA6312(ha))
1123 ha->fw_options[2] |= BIT_13;
1124
Linus Torvalds1da177e2005-04-16 15:20:36 -07001125 /* Update firmware options. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001126 qla2x00_set_fw_options(vha, ha->fw_options);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127}
1128
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001129void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001130qla24xx_update_fw_options(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001131{
1132 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001133 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001134
1135 /* Update Serial Link options. */
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001136 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
Andrew Vasquez01071092005-07-06 10:31:37 -07001137 return;
1138
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001139 rval = qla2x00_set_serdes_params(vha,
andrew.vasquez@qlogic.comf94097e2006-01-13 17:05:32 -08001140 le16_to_cpu(ha->fw_seriallink_options24[1]),
1141 le16_to_cpu(ha->fw_seriallink_options24[2]),
1142 le16_to_cpu(ha->fw_seriallink_options24[3]));
Andrew Vasquez01071092005-07-06 10:31:37 -07001143 if (rval != QLA_SUCCESS) {
1144 qla_printk(KERN_WARNING, ha,
1145 "Unable to update Serial Link options (%x).\n", rval);
1146 }
1147}
1148
1149void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001150qla2x00_config_rings(struct scsi_qla_host *vha)
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001151{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001152 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001153 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001154 struct req_que *req = ha->req;
1155 struct rsp_que *rsp = ha->rsp;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001156
1157 /* Setup ring parameters in initialization control block. */
1158 ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0);
1159 ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001160 ha->init_cb->request_q_length = cpu_to_le16(req->length);
1161 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
1162 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1163 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1164 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1165 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001166
1167 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
1168 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
1169 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
1170 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
1171 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
1172}
1173
Andrew Vasquez01071092005-07-06 10:31:37 -07001174void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001175qla24xx_config_rings(struct scsi_qla_host *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07001176{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001177 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001178 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1179 struct init_cb_24xx *icb;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001180 struct req_que *req = ha->req;
1181 struct rsp_que *rsp = ha->rsp;
Andrew Vasquez01071092005-07-06 10:31:37 -07001182
1183 /* Setup ring parameters in initialization control block. */
1184 icb = (struct init_cb_24xx *)ha->init_cb;
1185 icb->request_q_outpointer = __constant_cpu_to_le16(0);
1186 icb->response_q_inpointer = __constant_cpu_to_le16(0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001187 icb->request_q_length = cpu_to_le16(req->length);
1188 icb->response_q_length = cpu_to_le16(rsp->length);
1189 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
1190 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
1191 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
1192 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
Andrew Vasquez01071092005-07-06 10:31:37 -07001193
1194 WRT_REG_DWORD(&reg->req_q_in, 0);
1195 WRT_REG_DWORD(&reg->req_q_out, 0);
1196 WRT_REG_DWORD(&reg->rsp_q_in, 0);
1197 WRT_REG_DWORD(&reg->rsp_q_out, 0);
1198 RD_REG_DWORD(&reg->rsp_q_out);
1199}
1200
Linus Torvalds1da177e2005-04-16 15:20:36 -07001201/**
1202 * qla2x00_init_rings() - Initializes firmware.
1203 * @ha: HA context
1204 *
1205 * Beginning of request ring has initialization control block already built
1206 * by nvram config routine.
1207 *
1208 * Returns 0 on success.
1209 */
1210static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001211qla2x00_init_rings(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212{
1213 int rval;
1214 unsigned long flags = 0;
1215 int cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001216 struct qla_hw_data *ha = vha->hw;
1217 struct req_que *req = ha->req;
1218 struct rsp_que *rsp = ha->rsp;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001219 struct mid_init_cb_24xx *mid_init_cb =
1220 (struct mid_init_cb_24xx *) ha->init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001221
1222 spin_lock_irqsave(&ha->hardware_lock, flags);
1223
1224 /* Clear outstanding commands array. */
1225 for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001226 req->outstanding_cmds[cnt] = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001227
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001228 req->current_outstanding_cmd = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001229
1230 /* Clear RSCN queue. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001231 vha->rscn_in_ptr = 0;
1232 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001233
1234 /* Initialize firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235 req->ring_ptr = req->ring;
1236 req->ring_index = 0;
1237 req->cnt = req->length;
1238 rsp->ring_ptr = rsp->ring;
1239 rsp->ring_index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241 /* Initialize response queue entries */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001242 qla2x00_init_response_q_entries(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001243
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001244 ha->isp_ops->config_rings(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245
1246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1247
1248 /* Update any ISP specific firmware options before initialization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001249 ha->isp_ops->update_fw_options(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001251 DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001252
Seokmann Juc48339d2008-01-17 09:02:19 -08001253 if (ha->flags.npiv_supported)
1254 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
1255
Andrew Vasquezeb66dc62007-11-12 10:30:58 -08001256 mid_init_cb->options = __constant_cpu_to_le16(BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001257
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001258 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 if (rval) {
1260 DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001261 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262 } else {
1263 DEBUG3(printk("scsi(%ld): Init firmware -- success.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001264 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 }
1266
1267 return (rval);
1268}
1269
1270/**
1271 * qla2x00_fw_ready() - Waits for firmware ready.
1272 * @ha: HA context
1273 *
1274 * Returns 0 on success.
1275 */
1276static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001277qla2x00_fw_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001278{
1279 int rval;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001280 unsigned long wtime, mtime, cs84xx_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281 uint16_t min_wait; /* Minimum wait time if loop is down */
1282 uint16_t wait_time; /* Wait time if loop is coming ready */
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001283 uint16_t state[3];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001284 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
1286 rval = QLA_SUCCESS;
1287
1288 /* 20 seconds for loop down. */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001289 min_wait = 20;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290
1291 /*
1292 * Firmware should take at most one RATOV to login, plus 5 seconds for
1293 * our own processing.
1294 */
1295 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
1296 wait_time = min_wait;
1297 }
1298
1299 /* Min wait time if loop down */
1300 mtime = jiffies + (min_wait * HZ);
1301
1302 /* wait time before firmware ready */
1303 wtime = jiffies + (wait_time * HZ);
1304
1305 /* Wait for ISP to finish LIP */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001306 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n");
1308
1309 DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001310 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001311
1312 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001313 rval = qla2x00_get_firmware_state(vha, state);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 if (rval == QLA_SUCCESS) {
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001315 if (state[0] < FSTATE_LOSS_OF_SYNC) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001316 vha->device_flags &= ~DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001317 }
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001318 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
1319 DEBUG16(printk("scsi(%ld): fw_state=%x "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001320 "84xx=%x.\n", vha->host_no, state[0],
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001321 state[2]));
1322 if ((state[2] & FSTATE_LOGGED_IN) &&
1323 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
1324 DEBUG16(printk("scsi(%ld): Sending "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001325 "verify iocb.\n", vha->host_no));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001326
1327 cs84xx_time = jiffies;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001328 rval = qla84xx_init_chip(vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001329 if (rval != QLA_SUCCESS)
1330 break;
1331
1332 /* Add time taken to initialize. */
1333 cs84xx_time = jiffies - cs84xx_time;
1334 wtime += cs84xx_time;
1335 mtime += cs84xx_time;
1336 DEBUG16(printk("scsi(%ld): Increasing "
1337 "wait time by %ld. New time %ld\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001338 vha->host_no, cs84xx_time, wtime));
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001339 }
1340 } else if (state[0] == FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341 DEBUG(printk("scsi(%ld): F/W Ready - OK \n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001342 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001344 qla2x00_get_retry_cnt(vha, &ha->retry_count,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001345 &ha->login_timeout, &ha->r_a_tov);
1346
1347 rval = QLA_SUCCESS;
1348 break;
1349 }
1350
1351 rval = QLA_FUNCTION_FAILED;
1352
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001353 if (atomic_read(&vha->loop_down_timer) &&
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001354 state[0] != FSTATE_READY) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001355 /* Loop down. Timeout on min_wait for states
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001356 * other than Wait for Login.
1357 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 if (time_after_eq(jiffies, mtime)) {
1359 qla_printk(KERN_INFO, ha,
1360 "Cable is unplugged...\n");
1361
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001362 vha->device_flags |= DFLG_NO_CABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001363 break;
1364 }
1365 }
1366 } else {
1367 /* Mailbox cmd failed. Timeout on min_wait. */
1368 if (time_after_eq(jiffies, mtime))
1369 break;
1370 }
1371
1372 if (time_after_eq(jiffies, wtime))
1373 break;
1374
1375 /* Delay for a while */
1376 msleep(500);
1377
1378 DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001379 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001380 } while (1);
1381
1382 DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001383 vha->host_no, state[0], jiffies));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001384
1385 if (rval) {
1386 DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001387 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001388 }
1389
1390 return (rval);
1391}
1392
1393/*
1394* qla2x00_configure_hba
1395* Setup adapter context.
1396*
1397* Input:
1398* ha = adapter state pointer.
1399*
1400* Returns:
1401* 0 = success
1402*
1403* Context:
1404* Kernel context.
1405*/
1406static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001407qla2x00_configure_hba(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001408{
1409 int rval;
1410 uint16_t loop_id;
1411 uint16_t topo;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001412 uint16_t sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413 uint8_t al_pa;
1414 uint8_t area;
1415 uint8_t domain;
1416 char connect_type[22];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001417 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001418
1419 /* Get host addresses. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001420 rval = qla2x00_get_adapter_id(vha,
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001421 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001422 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001423 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
Ravi Anand33135aa2005-11-08 14:37:20 -08001424 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
1425 DEBUG2(printk("%s(%ld) Loop is in a transition state\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001426 __func__, vha->host_no));
Ravi Anand33135aa2005-11-08 14:37:20 -08001427 } else {
1428 qla_printk(KERN_WARNING, ha,
1429 "ERROR -- Unable to get host loop ID.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001430 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Ravi Anand33135aa2005-11-08 14:37:20 -08001431 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 return (rval);
1433 }
1434
1435 if (topo == 4) {
1436 qla_printk(KERN_INFO, ha,
1437 "Cannot get topology - retrying.\n");
1438 return (QLA_FUNCTION_FAILED);
1439 }
1440
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001441 vha->loop_id = loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
1443 /* initialize */
1444 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
1445 ha->operating_mode = LOOP;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001446 ha->switch_cap = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447
1448 switch (topo) {
1449 case 0:
1450 DEBUG3(printk("scsi(%ld): HBA in NL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001451 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001452 ha->current_topology = ISP_CFG_NL;
1453 strcpy(connect_type, "(Loop)");
1454 break;
1455
1456 case 1:
1457 DEBUG3(printk("scsi(%ld): HBA in FL topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001458 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001459 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 ha->current_topology = ISP_CFG_FL;
1461 strcpy(connect_type, "(FL_Port)");
1462 break;
1463
1464 case 2:
1465 DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001466 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001467 ha->operating_mode = P2P;
1468 ha->current_topology = ISP_CFG_N;
1469 strcpy(connect_type, "(N_Port-to-N_Port)");
1470 break;
1471
1472 case 3:
1473 DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001474 vha->host_no));
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001475 ha->switch_cap = sw_cap;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001476 ha->operating_mode = P2P;
1477 ha->current_topology = ISP_CFG_F;
1478 strcpy(connect_type, "(F_Port)");
1479 break;
1480
1481 default:
1482 DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. "
1483 "Using NL.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001484 vha->host_no, topo));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001485 ha->current_topology = ISP_CFG_NL;
1486 strcpy(connect_type, "(Loop)");
1487 break;
1488 }
1489
1490 /* Save Host port and loop ID. */
1491 /* byte order - Big Endian */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001492 vha->d_id.b.domain = domain;
1493 vha->d_id.b.area = area;
1494 vha->d_id.b.al_pa = al_pa;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001495
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001496 if (!vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 qla_printk(KERN_INFO, ha,
1498 "Topology - %s, Host Loop address 0x%x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001499 connect_type, vha->loop_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001500
1501 if (rval) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001502 DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001504 DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001505 }
1506
1507 return(rval);
1508}
1509
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001510static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001511qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
1512 char *def)
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001513{
1514 char *st, *en;
1515 uint16_t index;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001516 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001517
1518 if (memcmp(model, BINZERO, len) != 0) {
1519 strncpy(ha->model_number, model, len);
1520 st = en = ha->model_number;
1521 en += len - 1;
1522 while (en > st) {
1523 if (*en != 0x20 && *en != 0x00)
1524 break;
1525 *en-- = '\0';
1526 }
1527
1528 index = (ha->pdev->subsystem_device & 0xff);
1529 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1530 index < QLA_MODEL_NAMES)
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001531 strncpy(ha->model_desc,
1532 qla2x00_model_name[index * 2 + 1],
1533 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001534 } else {
1535 index = (ha->pdev->subsystem_device & 0xff);
1536 if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
1537 index < QLA_MODEL_NAMES) {
1538 strcpy(ha->model_number,
1539 qla2x00_model_name[index * 2]);
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001540 strncpy(ha->model_desc,
1541 qla2x00_model_name[index * 2 + 1],
1542 sizeof(ha->model_desc) - 1);
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001543 } else {
1544 strcpy(ha->model_number, def);
1545 }
1546 }
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001547 if (IS_FWI2_CAPABLE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001548 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
Joe Carnuccio1ee27142008-07-10 16:55:53 -07001549 sizeof(ha->model_desc));
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001550}
1551
David Miller4e08df32007-04-16 12:37:43 -07001552/* On sparc systems, obtain port and node WWN from firmware
1553 * properties.
1554 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001555static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
David Miller4e08df32007-04-16 12:37:43 -07001556{
1557#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001558 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07001559 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07001560 struct device_node *dp = pci_device_to_OF_node(pdev);
1561 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07001562 int len;
1563
1564 val = of_get_property(dp, "port-wwn", &len);
1565 if (val && len >= WWN_SIZE)
1566 memcpy(nv->port_name, val, WWN_SIZE);
1567
1568 val = of_get_property(dp, "node-wwn", &len);
1569 if (val && len >= WWN_SIZE)
1570 memcpy(nv->node_name, val, WWN_SIZE);
1571#endif
1572}
1573
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574/*
1575* NVRAM configuration for ISP 2xxx
1576*
1577* Input:
1578* ha = adapter block pointer.
1579*
1580* Output:
1581* initialization control block in response_ring
1582* host adapters parameters in host adapter block
1583*
1584* Returns:
1585* 0 = success.
1586*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001587int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001588qla2x00_nvram_config(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589{
David Miller4e08df32007-04-16 12:37:43 -07001590 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07001591 uint8_t chksum = 0;
1592 uint16_t cnt;
1593 uint8_t *dptr1, *dptr2;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07001595 init_cb_t *icb = ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07001596 nvram_t *nv = ha->nvram;
1597 uint8_t *ptr = ha->nvram;
Andrew Vasquez3d716442005-07-06 10:30:26 -07001598 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
David Miller4e08df32007-04-16 12:37:43 -07001600 rval = QLA_SUCCESS;
1601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602 /* Determine NVRAM starting address. */
Andrew Vasquez01071092005-07-06 10:31:37 -07001603 ha->nvram_size = sizeof(nvram_t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 ha->nvram_base = 0;
1605 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
1606 if ((RD_REG_WORD(&reg->ctrl_status) >> 14) == 1)
1607 ha->nvram_base = 0x80;
1608
1609 /* Get NVRAM data and calculate checksum. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001610 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07001611 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
1612 chksum += *ptr++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001614 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07001615 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616
1617 /* Bad NVRAM data, set defaults parameters. */
1618 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
1619 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
1620 /* Reset NVRAM data. */
1621 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
1622 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
1623 nv->nvram_version);
David Miller4e08df32007-04-16 12:37:43 -07001624 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
1625 "invalid -- WWPN) defaults.\n");
1626
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001627 if (chksum)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001628 qla2xxx_hw_event_log(vha, HW_EVENT_NVRAM_CHKSUM_ERR, 0,
Andrew Vasquezcb8dacb2008-04-03 13:13:19 -07001629 MSW(chksum), LSW(chksum));
1630
David Miller4e08df32007-04-16 12:37:43 -07001631 /*
1632 * Set default initialization control block.
1633 */
1634 memset(nv, 0, ha->nvram_size);
1635 nv->parameter_block_version = ICB_VERSION;
1636
1637 if (IS_QLA23XX(ha)) {
1638 nv->firmware_options[0] = BIT_2 | BIT_1;
1639 nv->firmware_options[1] = BIT_7 | BIT_5;
1640 nv->add_firmware_options[0] = BIT_5;
1641 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1642 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1643 nv->special_options[1] = BIT_7;
1644 } else if (IS_QLA2200(ha)) {
1645 nv->firmware_options[0] = BIT_2 | BIT_1;
1646 nv->firmware_options[1] = BIT_7 | BIT_5;
1647 nv->add_firmware_options[0] = BIT_5;
1648 nv->add_firmware_options[1] = BIT_5 | BIT_4;
1649 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1650 } else if (IS_QLA2100(ha)) {
1651 nv->firmware_options[0] = BIT_3 | BIT_1;
1652 nv->firmware_options[1] = BIT_5;
1653 nv->frame_payload_size = __constant_cpu_to_le16(1024);
1654 }
1655
1656 nv->max_iocb_allocation = __constant_cpu_to_le16(256);
1657 nv->execution_throttle = __constant_cpu_to_le16(16);
1658 nv->retry_count = 8;
1659 nv->retry_delay = 1;
1660
1661 nv->port_name[0] = 33;
1662 nv->port_name[3] = 224;
1663 nv->port_name[4] = 139;
1664
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001665 qla2xxx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07001666
1667 nv->login_timeout = 4;
1668
1669 /*
1670 * Set default host adapter parameters
1671 */
1672 nv->host_p[1] = BIT_2;
1673 nv->reset_delay = 5;
1674 nv->port_down_retry_count = 8;
1675 nv->max_luns_per_target = __constant_cpu_to_le16(8);
1676 nv->link_down_timeout = 60;
1677
1678 rval = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001679 }
1680
1681#if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
1682 /*
1683 * The SN2 does not provide BIOS emulation which means you can't change
1684 * potentially bogus BIOS settings. Force the use of default settings
1685 * for link rate and frame size. Hope that the rest of the settings
1686 * are valid.
1687 */
1688 if (ia64_platform_is("sn2")) {
1689 nv->frame_payload_size = __constant_cpu_to_le16(2048);
1690 if (IS_QLA23XX(ha))
1691 nv->special_options[1] = BIT_7;
1692 }
1693#endif
1694
1695 /* Reset Initialization control block */
Andrew Vasquez01071092005-07-06 10:31:37 -07001696 memset(icb, 0, ha->init_cb_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001697
1698 /*
1699 * Setup driver NVRAM options.
1700 */
1701 nv->firmware_options[0] |= (BIT_6 | BIT_1);
1702 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
1703 nv->firmware_options[1] |= (BIT_5 | BIT_0);
1704 nv->firmware_options[1] &= ~BIT_4;
1705
1706 if (IS_QLA23XX(ha)) {
1707 nv->firmware_options[0] |= BIT_2;
1708 nv->firmware_options[0] &= ~BIT_3;
Andrew Vasquez01071092005-07-06 10:31:37 -07001709 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001710
1711 if (IS_QLA2300(ha)) {
1712 if (ha->fb_rev == FPM_2310) {
1713 strcpy(ha->model_number, "QLA2310");
1714 } else {
1715 strcpy(ha->model_number, "QLA2300");
1716 }
1717 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001718 qla2x00_set_model_info(vha, nv->model_number,
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08001719 sizeof(nv->model_number), "QLA23xx");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 }
1721 } else if (IS_QLA2200(ha)) {
1722 nv->firmware_options[0] |= BIT_2;
1723 /*
1724 * 'Point-to-point preferred, else loop' is not a safe
1725 * connection mode setting.
1726 */
1727 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
1728 (BIT_5 | BIT_4)) {
1729 /* Force 'loop preferred, else point-to-point'. */
1730 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
1731 nv->add_firmware_options[0] |= BIT_5;
1732 }
1733 strcpy(ha->model_number, "QLA22xx");
1734 } else /*if (IS_QLA2100(ha))*/ {
1735 strcpy(ha->model_number, "QLA2100");
1736 }
1737
1738 /*
1739 * Copy over NVRAM RISC parameter block to initialization control block.
1740 */
1741 dptr1 = (uint8_t *)icb;
1742 dptr2 = (uint8_t *)&nv->parameter_block_version;
1743 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
1744 while (cnt--)
1745 *dptr1++ = *dptr2++;
1746
1747 /* Copy 2nd half. */
1748 dptr1 = (uint8_t *)icb->add_firmware_options;
1749 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
1750 while (cnt--)
1751 *dptr1++ = *dptr2++;
1752
Andrew Vasquez5341e862006-05-17 15:09:16 -07001753 /* Use alternate WWN? */
1754 if (nv->host_p[1] & BIT_7) {
1755 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
1756 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
1757 }
1758
Linus Torvalds1da177e2005-04-16 15:20:36 -07001759 /* Prepare nodename */
1760 if ((icb->firmware_options[1] & BIT_6) == 0) {
1761 /*
1762 * Firmware will apply the following mask if the nodename was
1763 * not provided.
1764 */
1765 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
1766 icb->node_name[0] &= 0xF0;
1767 }
1768
1769 /*
1770 * Set host adapter parameters.
1771 */
Andrew Vasquez01819442006-06-23 16:11:10 -07001772 if (nv->host_p[0] & BIT_7)
Andrew Vasquez11010fe2006-10-06 09:54:59 -07001773 ql2xextended_error_logging = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
1775 /* Always load RISC code on non ISP2[12]00 chips. */
1776 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
1777 ha->flags.disable_risc_code_load = 0;
1778 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
1779 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
1780 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
Andrew Vasquez06c22bd2005-08-26 19:09:00 -07001781 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07001782 ha->flags.disable_serdes = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784 ha->operating_mode =
1785 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
1786
1787 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
1788 sizeof(ha->fw_seriallink_options));
1789
1790 /* save HBA serial number */
1791 ha->serial0 = icb->port_name[5];
1792 ha->serial1 = icb->port_name[6];
1793 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001794 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
1795 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796
1797 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
1798
1799 ha->retry_count = nv->retry_count;
1800
1801 /* Set minimum login_timeout to 4 seconds. */
1802 if (nv->login_timeout < ql2xlogintimeout)
1803 nv->login_timeout = ql2xlogintimeout;
1804 if (nv->login_timeout < 4)
1805 nv->login_timeout = 4;
1806 ha->login_timeout = nv->login_timeout;
1807 icb->login_timeout = nv->login_timeout;
1808
Andrew Vasquez00a537b2008-02-28 14:06:11 -08001809 /* Set minimum RATOV to 100 tenths of a second. */
1810 ha->r_a_tov = 100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812 ha->loop_reset_delay = nv->reset_delay;
1813
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814 /* Link Down Timeout = 0:
1815 *
1816 * When Port Down timer expires we will start returning
1817 * I/O's to OS with "DID_NO_CONNECT".
1818 *
1819 * Link Down Timeout != 0:
1820 *
1821 * The driver waits for the link to come up after link down
1822 * before returning I/Os to OS with "DID_NO_CONNECT".
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001823 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001824 if (nv->link_down_timeout == 0) {
1825 ha->loop_down_abort_time =
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04001826 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001827 } else {
1828 ha->link_down_timeout = nv->link_down_timeout;
1829 ha->loop_down_abort_time =
1830 (LOOP_DOWN_TIME - ha->link_down_timeout);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001831 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832
Linus Torvalds1da177e2005-04-16 15:20:36 -07001833 /*
1834 * Need enough time to try and get the port back.
1835 */
1836 ha->port_down_retry_count = nv->port_down_retry_count;
1837 if (qlport_down_retry)
1838 ha->port_down_retry_count = qlport_down_retry;
1839 /* Set login_retry_count */
1840 ha->login_retry_count = nv->retry_count;
1841 if (ha->port_down_retry_count == nv->port_down_retry_count &&
1842 ha->port_down_retry_count > 3)
1843 ha->login_retry_count = ha->port_down_retry_count;
1844 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
1845 ha->login_retry_count = ha->port_down_retry_count;
1846 if (ql2xloginretrycount)
1847 ha->login_retry_count = ql2xloginretrycount;
1848
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 icb->lun_enables = __constant_cpu_to_le16(0);
1850 icb->command_resource_count = 0;
1851 icb->immediate_notify_resource_count = 0;
1852 icb->timeout = __constant_cpu_to_le16(0);
1853
1854 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
1855 /* Enable RIO */
1856 icb->firmware_options[0] &= ~BIT_3;
1857 icb->add_firmware_options[0] &=
1858 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
1859 icb->add_firmware_options[0] |= BIT_2;
1860 icb->response_accumulation_timer = 3;
1861 icb->interrupt_delay_timer = 5;
1862
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001863 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001864 } else {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001865 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001866 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001867 ha->zio_mode = icb->add_firmware_options[0] &
1868 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
1869 ha->zio_timer = icb->interrupt_delay_timer ?
1870 icb->interrupt_delay_timer: 2;
1871 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001872 icb->add_firmware_options[0] &=
1873 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001874 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001875 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001876 ha->zio_mode = QLA_ZIO_MODE_6;
1877
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001878 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001879 "delay (%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001880 ha->zio_timer * 100));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 qla_printk(KERN_INFO, ha,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001882 "ZIO mode %d enabled; timer delay (%d us).\n",
1883 ha->zio_mode, ha->zio_timer * 100);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001884
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07001885 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
1886 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 vha->flags.process_response_queue = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888 }
1889 }
1890
David Miller4e08df32007-04-16 12:37:43 -07001891 if (rval) {
1892 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001893 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07001894 }
1895 return (rval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896}
1897
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001898static void
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001899qla2x00_rport_del(void *data)
1900{
1901 fc_port_t *fcport = data;
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001902 struct fc_rport *rport;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001904 spin_lock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001905 rport = fcport->drport;
1906 fcport->drport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001907 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08001908 if (rport)
1909 fc_remote_port_delete(rport);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001910}
1911
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912/**
1913 * qla2x00_alloc_fcport() - Allocate a generic fcport.
1914 * @ha: HA context
1915 * @flags: allocation flags
1916 *
1917 * Returns a pointer to the allocated fcport, or NULL, if none available.
1918 */
Adrian Bunk413975a2006-06-30 02:33:06 -07001919static fc_port_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001920qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921{
1922 fc_port_t *fcport;
1923
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001924 fcport = kzalloc(sizeof(fc_port_t), flags);
1925 if (!fcport)
1926 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001927
1928 /* Setup fcport template structure. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001929 fcport->vha = vha;
1930 fcport->vp_idx = vha->vp_idx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001931 fcport->port_type = FCT_UNKNOWN;
1932 fcport->loop_id = FC_NO_LOOP_ID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001933 atomic_set(&fcport->state, FCS_UNCONFIGURED);
1934 fcport->flags = FCF_RLC_SUPPORT;
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07001935 fcport->supported_classes = FC_COS_UNSPECIFIED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02001937 return fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001938}
1939
1940/*
1941 * qla2x00_configure_loop
1942 * Updates Fibre Channel Device Database with what is actually on loop.
1943 *
1944 * Input:
1945 * ha = adapter block pointer.
1946 *
1947 * Returns:
1948 * 0 = success.
1949 * 1 = error.
1950 * 2 = database was full and device was not configured.
1951 */
1952static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001953qla2x00_configure_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954{
1955 int rval;
1956 unsigned long flags, save_flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001957 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001958 rval = QLA_SUCCESS;
1959
1960 /* Get Initiator ID */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001961 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
1962 rval = qla2x00_configure_hba(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 if (rval != QLA_SUCCESS) {
1964 DEBUG(printk("scsi(%ld): Unable to configure HBA.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001965 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 return (rval);
1967 }
1968 }
1969
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001970 save_flags = flags = vha->dpc_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001971 DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001972 vha->host_no, flags));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973
1974 /*
1975 * If we have both an RSCN and PORT UPDATE pending then handle them
1976 * both at the same time.
1977 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001978 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1979 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001980
1981 /* Determine what we need to do */
1982 if (ha->current_topology == ISP_CFG_FL &&
1983 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1984
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001985 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001986 set_bit(RSCN_UPDATE, &flags);
1987
1988 } else if (ha->current_topology == ISP_CFG_F &&
1989 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
1990
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001991 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001992 set_bit(RSCN_UPDATE, &flags);
1993 clear_bit(LOCAL_LOOP_UPDATE, &flags);
1994
Andrew Vasquez21333b42006-05-17 15:09:56 -07001995 } else if (ha->current_topology == ISP_CFG_N) {
1996 clear_bit(RSCN_UPDATE, &flags);
1997
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 } else if (!vha->flags.online ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07001999 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
2000
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002001 vha->flags.rscn_queue_overflow = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 set_bit(RSCN_UPDATE, &flags);
2003 set_bit(LOCAL_LOOP_UPDATE, &flags);
2004 }
2005
2006 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002008 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002009 else
2010 rval = qla2x00_configure_local_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011 }
2012
2013 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002014 if (LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015 rval = QLA_FUNCTION_FAILED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002016 else
2017 rval = qla2x00_configure_fabric(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 }
2019
2020 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 if (atomic_read(&vha->loop_down_timer) ||
2022 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023 rval = QLA_FUNCTION_FAILED;
2024 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002025 atomic_set(&vha->loop_state, LOOP_READY);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002026
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002027 DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 }
2029 }
2030
2031 if (rval) {
2032 DEBUG2_3(printk("%s(%ld): *** FAILED ***\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002033 __func__, vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002034 } else {
2035 DEBUG3(printk("%s: exiting normally\n", __func__));
2036 }
2037
Bjorn Helgaascc3ef7b2008-09-11 21:22:51 -07002038 /* Restore state if a resync event occurred during processing */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002039 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002041 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
Seokmann Ju5de1f702008-07-10 16:55:58 -07002042 if (test_bit(RSCN_UPDATE, &save_flags)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2044 vha->flags.rscn_queue_overflow = 1;
Seokmann Ju5de1f702008-07-10 16:55:58 -07002045 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046 }
2047
2048 return (rval);
2049}
2050
2051
2052
2053/*
2054 * qla2x00_configure_local_loop
2055 * Updates Fibre Channel Device Database with local loop devices.
2056 *
2057 * Input:
2058 * ha = adapter block pointer.
2059 *
2060 * Returns:
2061 * 0 = success.
2062 */
2063static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002064qla2x00_configure_local_loop(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
2066 int rval, rval2;
2067 int found_devs;
2068 int found;
2069 fc_port_t *fcport, *new_fcport;
2070
2071 uint16_t index;
2072 uint16_t entries;
2073 char *id_iter;
2074 uint16_t loop_id;
2075 uint8_t domain, area, al_pa;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002076 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077
2078 found_devs = 0;
2079 new_fcport = NULL;
2080 entries = MAX_FIBRE_DEVICES;
2081
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002082 DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no));
2083 DEBUG3(qla2x00_get_fcal_position_map(vha, NULL));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084
2085 /* Get list of logged in devices. */
2086 memset(ha->gid_list, 0, GID_LIST_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002087 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002088 &entries);
2089 if (rval != QLA_SUCCESS)
2090 goto cleanup_allocation;
2091
2092 DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n",
2093 ha->host_no, entries));
2094 DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list,
2095 entries * sizeof(struct gid_list_info)));
2096
2097 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 if (new_fcport == NULL) {
2100 rval = QLA_MEMORY_ALLOC_FAILED;
2101 goto cleanup_allocation;
2102 }
2103 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2104
2105 /*
2106 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2107 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002108 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002109 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2110 fcport->port_type != FCT_BROADCAST &&
2111 (fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2112
2113 DEBUG(printk("scsi(%ld): Marking port lost, "
2114 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002115 vha->host_no, fcport->loop_id));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002116
2117 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2118 fcport->flags &= ~FCF_FARP_DONE;
2119 }
2120 }
2121
2122 /* Add devices to port list. */
2123 id_iter = (char *)ha->gid_list;
2124 for (index = 0; index < entries; index++) {
2125 domain = ((struct gid_list_info *)id_iter)->domain;
2126 area = ((struct gid_list_info *)id_iter)->area;
2127 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002128 if (IS_QLA2100(ha) || IS_QLA2200(ha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002129 loop_id = (uint16_t)
2130 ((struct gid_list_info *)id_iter)->loop_id_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002131 else
Linus Torvalds1da177e2005-04-16 15:20:36 -07002132 loop_id = le16_to_cpu(
2133 ((struct gid_list_info *)id_iter)->loop_id);
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002134 id_iter += ha->gid_list_info_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002135
2136 /* Bypass reserved domain fields. */
2137 if ((domain & 0xf0) == 0xf0)
2138 continue;
2139
2140 /* Bypass if not same domain and area of adapter. */
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002141 if (area && domain &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002142 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 continue;
2144
2145 /* Bypass invalid local loop ID. */
2146 if (loop_id > LAST_LOCAL_LOOP_ID)
2147 continue;
2148
2149 /* Fill in member data. */
2150 new_fcport->d_id.b.domain = domain;
2151 new_fcport->d_id.b.area = area;
2152 new_fcport->d_id.b.al_pa = al_pa;
2153 new_fcport->loop_id = loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002154 new_fcport->vp_idx = vha->vp_idx;
2155 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002156 if (rval2 != QLA_SUCCESS) {
2157 DEBUG2(printk("scsi(%ld): Failed to retrieve fcport "
2158 "information -- get_port_database=%x, "
2159 "loop_id=0x%04x\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002160 vha->host_no, rval2, new_fcport->loop_id));
andrew.vasquez@qlogic.comc9d02ac2006-01-13 17:05:26 -08002161 DEBUG2(printk("scsi(%ld): Scheduling resync...\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002162 vha->host_no));
2163 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 continue;
2165 }
2166
2167 /* Check for matching device in port list. */
2168 found = 0;
2169 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002170 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171 if (memcmp(new_fcport->port_name, fcport->port_name,
2172 WWN_SIZE))
2173 continue;
2174
2175 fcport->flags &= ~(FCF_FABRIC_DEVICE |
2176 FCF_PERSISTENT_BOUND);
2177 fcport->loop_id = new_fcport->loop_id;
2178 fcport->port_type = new_fcport->port_type;
2179 fcport->d_id.b24 = new_fcport->d_id.b24;
2180 memcpy(fcport->node_name, new_fcport->node_name,
2181 WWN_SIZE);
2182
2183 found++;
2184 break;
2185 }
2186
2187 if (!found) {
2188 /* New device, add to fcports list. */
2189 new_fcport->flags &= ~FCF_PERSISTENT_BOUND;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 if (vha->vp_idx) {
2191 new_fcport->vha = vha;
2192 new_fcport->vp_idx = vha->vp_idx;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002193 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002194 list_add_tail(&new_fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 /* Allocate a new replacement fcport. */
2197 fcport = new_fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002198 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002199 if (new_fcport == NULL) {
2200 rval = QLA_MEMORY_ALLOC_FAILED;
2201 goto cleanup_allocation;
2202 }
2203 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
2204 }
2205
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002206 /* Base iIDMA settings on HBA port speed. */
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002207 fcport->fp_speed = ha->link_data_rate;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002208
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002209 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002210
2211 found_devs++;
2212 }
2213
2214cleanup_allocation:
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002215 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002216
2217 if (rval != QLA_SUCCESS) {
2218 DEBUG2(printk("scsi(%ld): Configure local loop error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002219 "rval=%x\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002220 }
2221
2222 if (found_devs) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002223 vha->device_flags |= DFLG_LOCAL_DEVICES;
2224 vha->device_flags &= ~DFLG_RETRY_LOCAL_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002225 }
2226
2227 return (rval);
2228}
2229
2230static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002231qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002232{
2233#define LS_UNKNOWN 2
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002234 static char *link_speeds[5] = { "1", "2", "?", "4", "8" };
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002235 int rval;
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002236 uint16_t mb[6];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002237 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002238
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07002239 if (!IS_IIDMA_CAPABLE(ha))
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002240 return;
2241
Andrew Vasquez39bd9622007-09-20 14:07:34 -07002242 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
2243 fcport->fp_speed > ha->link_data_rate)
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002244 return;
2245
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002246 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002247 mb);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002248 if (rval != QLA_SUCCESS) {
2249 DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA "
2250 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002251 vha->host_no, fcport->port_name[0], fcport->port_name[1],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002252 fcport->port_name[2], fcport->port_name[3],
2253 fcport->port_name[4], fcport->port_name[5],
2254 fcport->port_name[6], fcport->port_name[7], rval,
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002255 fcport->fp_speed, mb[0], mb[1]));
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002256 } else {
2257 DEBUG2(qla_printk(KERN_INFO, ha,
2258 "iIDMA adjusted to %s GB/s on "
2259 "%02x%02x%02x%02x%02x%02x%02x%02x.\n",
Andrew Vasqueza3cbdfa2007-08-13 10:13:18 -07002260 link_speeds[fcport->fp_speed], fcport->port_name[0],
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002261 fcport->port_name[1], fcport->port_name[2],
2262 fcport->port_name[3], fcport->port_name[4],
2263 fcport->port_name[5], fcport->port_name[6],
2264 fcport->port_name[7]));
2265 }
2266}
2267
Adrian Bunk23be3312006-11-24 02:46:01 +01002268static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002269qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
8482e112005-04-17 15:04:54 -05002270{
2271 struct fc_rport_identifiers rport_ids;
bdf79622005-04-17 15:06:53 -05002272 struct fc_rport *rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002273 struct qla_hw_data *ha = vha->hw;
8482e112005-04-17 15:04:54 -05002274
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002275 if (fcport->drport)
2276 qla2x00_rport_del(fcport);
8482e112005-04-17 15:04:54 -05002277
Andrew Vasquezf8b02a82005-08-31 15:21:20 -07002278 rport_ids.node_name = wwn_to_u64(fcport->node_name);
2279 rport_ids.port_name = wwn_to_u64(fcport->port_name);
8482e112005-04-17 15:04:54 -05002280 rport_ids.port_id = fcport->d_id.b.domain << 16 |
2281 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
2282 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002283 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
Andrew Vasquez77d74142005-07-08 18:00:36 -07002284 if (!rport) {
2285 qla_printk(KERN_WARNING, ha,
2286 "Unable to allocate fc remote port!\n");
2287 return;
2288 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002289 spin_lock_irq(fcport->vha->host->host_lock);
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04002290 *((fc_port_t **)rport->dd_data) = fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002291 spin_unlock_irq(fcport->vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002292
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07002293 rport->supported_classes = fcport->supported_classes;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002294
2295 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
8482e112005-04-17 15:04:54 -05002296 if (fcport->port_type == FCT_INITIATOR)
2297 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
2298 if (fcport->port_type == FCT_TARGET)
2299 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
Andrew Vasquez77d74142005-07-08 18:00:36 -07002300 fc_remote_port_rolechg(rport, rport_ids.roles);
8482e112005-04-17 15:04:54 -05002301}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002302
2303/*
Adrian Bunk23be3312006-11-24 02:46:01 +01002304 * qla2x00_update_fcport
2305 * Updates device on list.
2306 *
2307 * Input:
2308 * ha = adapter block pointer.
2309 * fcport = port structure pointer.
2310 *
2311 * Return:
2312 * 0 - Success
2313 * BIT_0 - error
2314 *
2315 * Context:
2316 * Kernel context.
2317 */
2318void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
Adrian Bunk23be3312006-11-24 02:46:01 +01002320{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002321 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002322
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002323 fcport->vha = vha;
Adrian Bunk23be3312006-11-24 02:46:01 +01002324 fcport->login_retry = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 fcport->port_login_retry_count = ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002326 PORT_RETRY_TIME;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 atomic_set(&fcport->port_down_timer, ha->port_down_retry_count *
Adrian Bunk23be3312006-11-24 02:46:01 +01002328 PORT_RETRY_TIME);
2329 fcport->flags &= ~FCF_LOGIN_NEEDED;
2330
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 qla2x00_iidma_fcport(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002332
2333 atomic_set(&fcport->state, FCS_ONLINE);
2334
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 qla2x00_reg_remote_port(vha, fcport);
Adrian Bunk23be3312006-11-24 02:46:01 +01002336}
2337
2338/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002339 * qla2x00_configure_fabric
2340 * Setup SNS devices with loop ID's.
2341 *
2342 * Input:
2343 * ha = adapter block pointer.
2344 *
2345 * Returns:
2346 * 0 = success.
2347 * BIT_0 = error
2348 */
2349static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002350qla2x00_configure_fabric(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002351{
2352 int rval, rval2;
2353 fc_port_t *fcport, *fcptemp;
2354 uint16_t next_loopid;
2355 uint16_t mb[MAILBOX_REGISTER_COUNT];
Andrew Vasquez01071092005-07-06 10:31:37 -07002356 uint16_t loop_id;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002357 LIST_HEAD(new_fcports);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002358 struct qla_hw_data *ha = vha->hw;
2359 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360
2361 /* If FL port exists, then SNS is present */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002362 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002363 loop_id = NPH_F_PORT;
2364 else
2365 loop_id = SNS_FL_PORT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002366 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002367 if (rval != QLA_SUCCESS) {
2368 DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002369 "Port\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002370
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371 vha->device_flags &= ~SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 return (QLA_SUCCESS);
2373 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002374 vha->device_flags |= SWITCH_FOUND;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002375
2376 /* Mark devices that need re-synchronization. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002377 rval2 = qla2x00_device_resync(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378 if (rval2 == QLA_RSCNS_HANDLED) {
2379 /* No point doing the scan, just continue. */
2380 return (QLA_SUCCESS);
2381 }
2382 do {
Andrew Vasquezcca53352005-08-26 19:08:30 -07002383 /* FDMI support. */
2384 if (ql2xfdmienable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002385 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
2386 qla2x00_fdmi_register(vha);
Andrew Vasquezcca53352005-08-26 19:08:30 -07002387
Linus Torvalds1da177e2005-04-16 15:20:36 -07002388 /* Ensure we are logged into the SNS. */
Andrew Vasqueze4289242007-07-19 15:05:56 -07002389 if (IS_FWI2_CAPABLE(ha))
Andrew Vasquez01071092005-07-06 10:31:37 -07002390 loop_id = NPH_SNS;
2391 else
2392 loop_id = SIMPLE_NAME_SERVER;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002393 ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
Andrew Vasquezabbd8872005-07-06 10:30:05 -07002394 0xfc, mb, BIT_1 | BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002395 if (mb[0] != MBS_COMMAND_COMPLETE) {
2396 DEBUG2(qla_printk(KERN_INFO, ha,
2397 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
Andrew Vasquez01071092005-07-06 10:31:37 -07002398 "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002399 mb[0], mb[1], mb[2], mb[6], mb[7]));
2400 return (QLA_SUCCESS);
2401 }
2402
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
2404 if (qla2x00_rft_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002405 /* EMPTY */
2406 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002407 "TYPE failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002408 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 if (qla2x00_rff_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002410 /* EMPTY */
2411 DEBUG2(printk("scsi(%ld): Register FC-4 "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002412 "Features failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002413 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002414 if (qla2x00_rnn_id(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002415 /* EMPTY */
2416 DEBUG2(printk("scsi(%ld): Register Node Name "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002417 "failed.\n", vha->host_no));
2418 } else if (qla2x00_rsnn_nn(vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002419 /* EMPTY */
2420 DEBUG2(printk("scsi(%ld): Register Symbolic "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421 "Node Name failed.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422 }
2423 }
2424
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002425 rval = qla2x00_find_all_fabric_devs(vha, &new_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002426 if (rval != QLA_SUCCESS)
2427 break;
2428
2429 /*
2430 * Logout all previous fabric devices marked lost, except
2431 * tape devices.
2432 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2434 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002435 break;
2436
2437 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
2438 continue;
2439
2440 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002441 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002442 ql2xplogiabsentdevice, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002443 if (fcport->loop_id != FC_NO_LOOP_ID &&
2444 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2445 fcport->port_type != FCT_INITIATOR &&
2446 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 ha->isp_ops->fabric_logout(vha,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002448 fcport->loop_id,
2449 fcport->d_id.b.domain,
2450 fcport->d_id.b.area,
2451 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002452 fcport->loop_id = FC_NO_LOOP_ID;
2453 }
2454 }
2455 }
2456
2457 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002458 next_loopid = ha->min_external_loopid;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459
2460 /*
2461 * Scan through our port list and login entries that need to be
2462 * logged in.
2463 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002464 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2465 if (atomic_read(&vha->loop_down_timer) ||
2466 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467 break;
2468
2469 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2470 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
2471 continue;
2472
2473 if (fcport->loop_id == FC_NO_LOOP_ID) {
2474 fcport->loop_id = next_loopid;
Seokmann Jud4486fd2008-04-03 13:13:28 -07002475 rval = qla2x00_find_new_loop_id(
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002476 base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002477 if (rval != QLA_SUCCESS) {
2478 /* Ran out of IDs to use */
2479 break;
2480 }
2481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 }
2485
2486 /* Exit if out of loop IDs. */
2487 if (rval != QLA_SUCCESS) {
2488 break;
2489 }
2490
2491 /*
2492 * Login and add the new devices to our port list.
2493 */
2494 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002495 if (atomic_read(&vha->loop_down_timer) ||
2496 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002497 break;
2498
2499 /* Find a new loop ID to use. */
2500 fcport->loop_id = next_loopid;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002501 rval = qla2x00_find_new_loop_id(base_vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002502 if (rval != QLA_SUCCESS) {
2503 /* Ran out of IDs to use */
2504 break;
2505 }
2506
bdf79622005-04-17 15:06:53 -05002507 /* Login and update database */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002508 qla2x00_fabric_dev_login(vha, fcport, &next_loopid);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002509
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002510 if (vha->vp_idx) {
2511 fcport->vha = vha;
2512 fcport->vp_idx = vha->vp_idx;
2513 }
2514 list_move_tail(&fcport->list, &vha->vp_fcports);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002515 }
2516 } while (0);
2517
2518 /* Free all new device structures not processed. */
2519 list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) {
2520 list_del(&fcport->list);
2521 kfree(fcport);
2522 }
2523
2524 if (rval) {
2525 DEBUG2(printk("scsi(%ld): Configure fabric error exit: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002526 "rval=%d\n", vha->host_no, rval));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002527 }
2528
2529 return (rval);
2530}
2531
2532
2533/*
2534 * qla2x00_find_all_fabric_devs
2535 *
2536 * Input:
2537 * ha = adapter block pointer.
2538 * dev = database device entry pointer.
2539 *
2540 * Returns:
2541 * 0 = success.
2542 *
2543 * Context:
2544 * Kernel context.
2545 */
2546static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002547qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha,
2548 struct list_head *new_fcports)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002549{
2550 int rval;
2551 uint16_t loop_id;
2552 fc_port_t *fcport, *new_fcport, *fcptemp;
2553 int found;
2554
2555 sw_info_t *swl;
2556 int swl_idx;
2557 int first_dev, last_dev;
2558 port_id_t wrap, nxt_d_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 struct qla_hw_data *ha = vha->hw;
2560 struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
2562 rval = QLA_SUCCESS;
2563
2564 /* Try GID_PT to get device list, else GAN. */
Andrew Vasquez4b892582008-09-11 21:22:48 -07002565 swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL);
Mariusz Kozlowskibbfbbbc2007-08-11 10:13:24 +02002566 if (!swl) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002567 /*EMPTY*/
2568 DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 "on GA_NXT\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002571 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002572 kfree(swl);
2573 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002574 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002575 kfree(swl);
2576 swl = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002577 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578 kfree(swl);
2579 swl = NULL;
Andrew Vasqueze5896bd2008-07-10 16:55:52 -07002580 } else if (ql2xiidmaenable &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002581 qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) {
2582 qla2x00_gpsc(vha, swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002583 }
2584 }
2585 swl_idx = 0;
2586
2587 /* Allocate temporary fcport for any new fcports discovered. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002588 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002590 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002591 return (QLA_MEMORY_ALLOC_FAILED);
2592 }
2593 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 /* Set start port ID scan at adapter ID. */
2595 first_dev = 1;
2596 last_dev = 0;
2597
2598 /* Starting free loop ID. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002599 loop_id = ha->min_external_loopid;
2600 for (; loop_id <= ha->max_loop_id; loop_id++) {
2601 if (qla2x00_is_reserved_id(vha, loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 continue;
2603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605 break;
2606
2607 if (swl != NULL) {
2608 if (last_dev) {
2609 wrap.b24 = new_fcport->d_id.b24;
2610 } else {
2611 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
2612 memcpy(new_fcport->node_name,
2613 swl[swl_idx].node_name, WWN_SIZE);
2614 memcpy(new_fcport->port_name,
2615 swl[swl_idx].port_name, WWN_SIZE);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002616 memcpy(new_fcport->fabric_port_name,
2617 swl[swl_idx].fabric_port_name, WWN_SIZE);
2618 new_fcport->fp_speed = swl[swl_idx].fp_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002619
2620 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
2621 last_dev = 1;
2622 }
2623 swl_idx++;
2624 }
2625 } else {
2626 /* Send GA_NXT to the switch */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 rval = qla2x00_ga_nxt(vha, new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 if (rval != QLA_SUCCESS) {
2629 qla_printk(KERN_WARNING, ha,
2630 "SNS scan failed -- assuming zero-entry "
2631 "result...\n");
2632 list_for_each_entry_safe(fcport, fcptemp,
2633 new_fcports, list) {
2634 list_del(&fcport->list);
2635 kfree(fcport);
2636 }
2637 rval = QLA_SUCCESS;
2638 break;
2639 }
2640 }
2641
2642 /* If wrap on switch device list, exit. */
2643 if (first_dev) {
2644 wrap.b24 = new_fcport->d_id.b24;
2645 first_dev = 0;
2646 } else if (new_fcport->d_id.b24 == wrap.b24) {
2647 DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002648 vha->host_no, new_fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa));
2650 break;
2651 }
2652
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002653 /* Bypass if same physical adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002654 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 continue;
2656
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002657 /* Bypass virtual ports of the same host. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002658 found = 0;
2659 if (ha->num_vhosts) {
2660 list_for_each_entry(vp, &ha->vp_list, list) {
2661 if (new_fcport->d_id.b24 == vp->d_id.b24) {
2662 found = 1;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002663 break;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 }
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002665 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002666 if (found)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002667 continue;
2668 }
2669
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002670 /* Bypass if same domain and area of adapter. */
2671 if (((new_fcport->d_id.b24 & 0xffff00) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002672 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
Andrew Vasquezf7d289f2005-08-26 19:08:40 -07002673 ISP_CFG_FL)
2674 continue;
2675
Linus Torvalds1da177e2005-04-16 15:20:36 -07002676 /* Bypass reserved domain fields. */
2677 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
2678 continue;
2679
2680 /* Locate matching device in database. */
2681 found = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002682 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 if (memcmp(new_fcport->port_name, fcport->port_name,
2684 WWN_SIZE))
2685 continue;
2686
2687 found++;
2688
Andrew Vasquezd8b45212006-10-02 12:00:43 -07002689 /* Update port state. */
2690 memcpy(fcport->fabric_port_name,
2691 new_fcport->fabric_port_name, WWN_SIZE);
2692 fcport->fp_speed = new_fcport->fp_speed;
2693
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694 /*
2695 * If address the same and state FCS_ONLINE, nothing
2696 * changed.
2697 */
2698 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
2699 atomic_read(&fcport->state) == FCS_ONLINE) {
2700 break;
2701 }
2702
2703 /*
2704 * If device was not a fabric device before.
2705 */
2706 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
2707 fcport->d_id.b24 = new_fcport->d_id.b24;
2708 fcport->loop_id = FC_NO_LOOP_ID;
2709 fcport->flags |= (FCF_FABRIC_DEVICE |
2710 FCF_LOGIN_NEEDED);
2711 fcport->flags &= ~FCF_PERSISTENT_BOUND;
2712 break;
2713 }
2714
2715 /*
2716 * Port ID changed or device was marked to be updated;
2717 * Log it out if still logged in and mark it for
2718 * relogin later.
2719 */
2720 fcport->d_id.b24 = new_fcport->d_id.b24;
2721 fcport->flags |= FCF_LOGIN_NEEDED;
2722 if (fcport->loop_id != FC_NO_LOOP_ID &&
2723 (fcport->flags & FCF_TAPE_PRESENT) == 0 &&
2724 fcport->port_type != FCT_INITIATOR &&
2725 fcport->port_type != FCT_BROADCAST) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002726 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002727 fcport->d_id.b.domain, fcport->d_id.b.area,
2728 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729 fcport->loop_id = FC_NO_LOOP_ID;
2730 }
2731
2732 break;
2733 }
2734
2735 if (found)
2736 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 /* If device was not in our fcports list, then add it. */
2738 list_add_tail(&new_fcport->list, new_fcports);
2739
2740 /* Allocate a new replacement fcport. */
2741 nxt_d_id.b24 = new_fcport->d_id.b24;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002742 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 if (new_fcport == NULL) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002744 kfree(swl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 return (QLA_MEMORY_ALLOC_FAILED);
2746 }
2747 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
2748 new_fcport->d_id.b24 = nxt_d_id.b24;
2749 }
2750
Jesper Juhlc9475cb2005-11-07 01:01:26 -08002751 kfree(swl);
2752 kfree(new_fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
2754 if (!list_empty(new_fcports))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002755 vha->device_flags |= DFLG_FABRIC_DEVICES;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002756
2757 return (rval);
2758}
2759
2760/*
2761 * qla2x00_find_new_loop_id
2762 * Scan through our port list and find a new usable loop ID.
2763 *
2764 * Input:
2765 * ha: adapter state pointer.
2766 * dev: port structure pointer.
2767 *
2768 * Returns:
2769 * qla2x00 local function return status code.
2770 *
2771 * Context:
2772 * Kernel context.
2773 */
Adrian Bunk413975a2006-06-30 02:33:06 -07002774static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002775qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002776{
2777 int rval;
2778 int found;
2779 fc_port_t *fcport;
2780 uint16_t first_loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002781 struct qla_hw_data *ha = vha->hw;
2782 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002783
2784 rval = QLA_SUCCESS;
2785
2786 /* Save starting loop ID. */
2787 first_loop_id = dev->loop_id;
2788
2789 for (;;) {
2790 /* Skip loop ID if already used by adapter. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 if (dev->loop_id == vha->loop_id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793
2794 /* Skip reserved loop IDs. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 while (qla2x00_is_reserved_id(vha, dev->loop_id))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 dev->loop_id++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002797
2798 /* Reset loop ID if passed the end. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002799 if (dev->loop_id > ha->max_loop_id) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002800 /* first loop ID. */
2801 dev->loop_id = ha->min_external_loopid;
2802 }
2803
2804 /* Check for loop ID being already in use. */
2805 found = 0;
2806 fcport = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807 list_for_each_entry(vp, &ha->vp_list, list) {
2808 list_for_each_entry(fcport, &vp->vp_fcports, list) {
2809 if (fcport->loop_id == dev->loop_id &&
2810 fcport != dev) {
2811 /* ID possibly in use */
2812 found++;
2813 break;
2814 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002815 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 if (found)
2817 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002818 }
2819
2820 /* If not in use then it is free to use. */
2821 if (!found) {
2822 break;
2823 }
2824
2825 /* ID in use. Try next value. */
2826 dev->loop_id++;
2827
2828 /* If wrap around. No free ID to use. */
2829 if (dev->loop_id == first_loop_id) {
2830 dev->loop_id = FC_NO_LOOP_ID;
2831 rval = QLA_FUNCTION_FAILED;
2832 break;
2833 }
2834 }
2835
2836 return (rval);
2837}
2838
2839/*
2840 * qla2x00_device_resync
2841 * Marks devices in the database that needs resynchronization.
2842 *
2843 * Input:
2844 * ha = adapter block pointer.
2845 *
2846 * Context:
2847 * Kernel context.
2848 */
2849static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850qla2x00_device_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851{
2852 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002853 uint32_t mask;
2854 fc_port_t *fcport;
2855 uint32_t rscn_entry;
2856 uint8_t rscn_out_iter;
2857 uint8_t format;
2858 port_id_t d_id;
2859
2860 rval = QLA_RSCNS_HANDLED;
2861
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002862 while (vha->rscn_out_ptr != vha->rscn_in_ptr ||
2863 vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002864
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002865 rscn_entry = vha->rscn_queue[vha->rscn_out_ptr];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002866 format = MSB(MSW(rscn_entry));
2867 d_id.b.domain = LSB(MSW(rscn_entry));
2868 d_id.b.area = MSB(LSW(rscn_entry));
2869 d_id.b.al_pa = LSB(LSW(rscn_entry));
2870
2871 DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = "
2872 "[%02x/%02x%02x%02x].\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002873 vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002874 d_id.b.area, d_id.b.al_pa));
2875
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002876 vha->rscn_out_ptr++;
2877 if (vha->rscn_out_ptr == MAX_RSCN_COUNT)
2878 vha->rscn_out_ptr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002879
2880 /* Skip duplicate entries. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002881 for (rscn_out_iter = vha->rscn_out_ptr;
2882 !vha->flags.rscn_queue_overflow &&
2883 rscn_out_iter != vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002884 rscn_out_iter = (rscn_out_iter ==
2885 (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) {
2886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002887 if (rscn_entry != vha->rscn_queue[rscn_out_iter])
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 break;
2889
2890 DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002891 "entry found at [%d].\n", vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 rscn_out_iter));
2893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894 vha->rscn_out_ptr = rscn_out_iter;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002895 }
2896
2897 /* Queue overflow, set switch default case. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002898 if (vha->flags.rscn_queue_overflow) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 DEBUG(printk("scsi(%ld): device_resync: rscn "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002900 "overflow.\n", vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002901
2902 format = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 vha->flags.rscn_queue_overflow = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002904 }
2905
2906 switch (format) {
2907 case 0:
Linus Torvalds1da177e2005-04-16 15:20:36 -07002908 mask = 0xffffff;
2909 break;
2910 case 1:
2911 mask = 0xffff00;
2912 break;
2913 case 2:
2914 mask = 0xff0000;
2915 break;
2916 default:
2917 mask = 0x0;
2918 d_id.b24 = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002919 vha->rscn_out_ptr = vha->rscn_in_ptr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 break;
2921 }
2922
2923 rval = QLA_SUCCESS;
2924
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002925 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002926 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
2927 (fcport->d_id.b24 & mask) != d_id.b24 ||
2928 fcport->port_type == FCT_BROADCAST)
2929 continue;
2930
2931 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2932 if (format != 3 ||
2933 fcport->port_type != FCT_INITIATOR) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002934 qla2x00_mark_device_lost(vha, fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002935 0, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 }
2937 }
2938 fcport->flags &= ~FCF_FARP_DONE;
2939 }
2940 }
2941 return (rval);
2942}
2943
2944/*
2945 * qla2x00_fabric_dev_login
2946 * Login fabric target device and update FC port database.
2947 *
2948 * Input:
2949 * ha: adapter state pointer.
2950 * fcport: port structure list pointer.
2951 * next_loopid: contains value of a new loop ID that can be used
2952 * by the next login attempt.
2953 *
2954 * Returns:
2955 * qla2x00 local function return status code.
2956 *
2957 * Context:
2958 * Kernel context.
2959 */
2960static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002961qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002962 uint16_t *next_loopid)
2963{
2964 int rval;
2965 int retry;
Andrew Vasquez01071092005-07-06 10:31:37 -07002966 uint8_t opts;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002968
2969 rval = QLA_SUCCESS;
2970 retry = 0;
2971
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 rval = qla2x00_fabric_login(vha, fcport, next_loopid);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 if (rval == QLA_SUCCESS) {
Andrew Vasquez01071092005-07-06 10:31:37 -07002974 /* Send an ADISC to tape devices.*/
2975 opts = 0;
2976 if (fcport->flags & FCF_TAPE_PRESENT)
2977 opts |= BIT_1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 rval = qla2x00_get_port_database(vha, fcport, opts);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002979 if (rval != QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002980 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07002981 fcport->d_id.b.domain, fcport->d_id.b.area,
2982 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002983 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002985 qla2x00_update_fcport(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002986 }
2987 }
2988
2989 return (rval);
2990}
2991
2992/*
2993 * qla2x00_fabric_login
2994 * Issue fabric login command.
2995 *
2996 * Input:
2997 * ha = adapter block pointer.
2998 * device = pointer to FC device type structure.
2999 *
3000 * Returns:
3001 * 0 - Login successfully
3002 * 1 - Login failed
3003 * 2 - Initiator device
3004 * 3 - Fatal error
3005 */
3006int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003007qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003008 uint16_t *next_loopid)
3009{
3010 int rval;
3011 int retry;
3012 uint16_t tmp_loopid;
3013 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003014 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
3016 retry = 0;
3017 tmp_loopid = 0;
3018
3019 for (;;) {
3020 DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x "
3021 "for port %02x%02x%02x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003022 vha->host_no, fcport->loop_id, fcport->d_id.b.domain,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3024
3025 /* Login fcport on switch. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003026 ha->isp_ops->fabric_login(vha, fcport->loop_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 fcport->d_id.b.domain, fcport->d_id.b.area,
3028 fcport->d_id.b.al_pa, mb, BIT_0);
3029 if (mb[0] == MBS_PORT_ID_USED) {
3030 /*
3031 * Device has another loop ID. The firmware team
Andrew Vasquez01071092005-07-06 10:31:37 -07003032 * recommends the driver perform an implicit login with
3033 * the specified ID again. The ID we just used is save
3034 * here so we return with an ID that can be tried by
3035 * the next login.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 */
3037 retry++;
3038 tmp_loopid = fcport->loop_id;
3039 fcport->loop_id = mb[1];
3040
3041 DEBUG(printk("Fabric Login: port in use - next "
3042 "loop id=0x%04x, port Id=%02x%02x%02x.\n",
3043 fcport->loop_id, fcport->d_id.b.domain,
3044 fcport->d_id.b.area, fcport->d_id.b.al_pa));
3045
3046 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
3047 /*
3048 * Login succeeded.
3049 */
3050 if (retry) {
3051 /* A retry occurred before. */
3052 *next_loopid = tmp_loopid;
3053 } else {
3054 /*
3055 * No retry occurred before. Just increment the
3056 * ID value for next login.
3057 */
3058 *next_loopid = (fcport->loop_id + 1);
3059 }
3060
3061 if (mb[1] & BIT_0) {
3062 fcport->port_type = FCT_INITIATOR;
3063 } else {
3064 fcport->port_type = FCT_TARGET;
3065 if (mb[1] & BIT_1) {
3066 fcport->flags |= FCF_TAPE_PRESENT;
3067 }
3068 }
3069
Andrew Vasquezad3e0ed2005-08-26 19:08:10 -07003070 if (mb[10] & BIT_0)
3071 fcport->supported_classes |= FC_COS_CLASS2;
3072 if (mb[10] & BIT_1)
3073 fcport->supported_classes |= FC_COS_CLASS3;
3074
Linus Torvalds1da177e2005-04-16 15:20:36 -07003075 rval = QLA_SUCCESS;
3076 break;
3077 } else if (mb[0] == MBS_LOOP_ID_USED) {
3078 /*
3079 * Loop ID already used, try next loop ID.
3080 */
3081 fcport->loop_id++;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 rval = qla2x00_find_new_loop_id(vha, fcport);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 if (rval != QLA_SUCCESS) {
3084 /* Ran out of loop IDs to use */
3085 break;
3086 }
3087 } else if (mb[0] == MBS_COMMAND_ERROR) {
3088 /*
3089 * Firmware possibly timed out during login. If NO
3090 * retries are left to do then the device is declared
3091 * dead.
3092 */
3093 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003094 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003095 fcport->d_id.b.domain, fcport->d_id.b.area,
3096 fcport->d_id.b.al_pa);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003097 qla2x00_mark_device_lost(vha, fcport, 1, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003098
3099 rval = 1;
3100 break;
3101 } else {
3102 /*
3103 * unrecoverable / not handled error
3104 */
3105 DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x "
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003106 "loop_id=%x jiffies=%lx.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003107 __func__, vha->host_no, mb[0],
Linus Torvalds1da177e2005-04-16 15:20:36 -07003108 fcport->d_id.b.domain, fcport->d_id.b.area,
3109 fcport->d_id.b.al_pa, fcport->loop_id, jiffies));
3110
3111 *next_loopid = fcport->loop_id;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003112 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
Andrew Vasquez1c7c6352005-07-06 10:30:57 -07003113 fcport->d_id.b.domain, fcport->d_id.b.area,
3114 fcport->d_id.b.al_pa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003115 fcport->loop_id = FC_NO_LOOP_ID;
Andrew Vasquez0eedfcf2005-10-27 11:09:38 -07003116 fcport->login_retry = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003117
3118 rval = 3;
3119 break;
3120 }
3121 }
3122
3123 return (rval);
3124}
3125
3126/*
3127 * qla2x00_local_device_login
3128 * Issue local device login command.
3129 *
3130 * Input:
3131 * ha = adapter block pointer.
3132 * loop_id = loop id of device to login to.
3133 *
3134 * Returns (Where's the #define!!!!):
3135 * 0 - Login successfully
3136 * 1 - Login failed
3137 * 3 - Fatal error
3138 */
3139int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003140qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141{
3142 int rval;
3143 uint16_t mb[MAILBOX_REGISTER_COUNT];
3144
3145 memset(mb, 0, sizeof(mb));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003146 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003147 if (rval == QLA_SUCCESS) {
3148 /* Interrogate mailbox registers for any errors */
3149 if (mb[0] == MBS_COMMAND_ERROR)
3150 rval = 1;
3151 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
3152 /* device not in PCB table */
3153 rval = 3;
3154 }
3155
3156 return (rval);
3157}
3158
3159/*
3160 * qla2x00_loop_resync
3161 * Resync with fibre channel devices.
3162 *
3163 * Input:
3164 * ha = adapter block pointer.
3165 *
3166 * Returns:
3167 * 0 = success
3168 */
3169int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003170qla2x00_loop_resync(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003171{
3172 int rval;
3173 uint32_t wait_time;
3174
3175 rval = QLA_SUCCESS;
3176
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003177 atomic_set(&vha->loop_state, LOOP_UPDATE);
3178 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
3179 if (vha->flags.online) {
3180 if (!(rval = qla2x00_fw_ready(vha))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003181 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3182 wait_time = 256;
3183 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 atomic_set(&vha->loop_state, LOOP_UPDATE);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003185
Andrew Vasquez01071092005-07-06 10:31:37 -07003186 /* Issue a marker after FW becomes ready. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003187 qla2x00_marker(vha, 0, 0, MK_SYNC_ALL);
3188 vha->marker_needed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003189
3190 /* Remap devices on Loop. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003191 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003192
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003193 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003194 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003195 } while (!atomic_read(&vha->loop_down_timer) &&
3196 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3197 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3198 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003200 }
3201
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003202 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003203 return (QLA_FUNCTION_FAILED);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003204
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003205 if (rval)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003206 DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003207
3208 return (rval);
3209}
3210
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003212qla2x00_update_fcports(scsi_qla_host_t *vha)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003213{
3214 fc_port_t *fcport;
3215
3216 /* Go with deferred removal of rport references. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003217 list_for_each_entry(fcport, &vha->vp_fcports, list)
3218 if (fcport && fcport->drport &&
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07003219 atomic_read(&fcport->state) != FCS_UNCONFIGURED)
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08003220 qla2x00_rport_del(fcport);
3221}
3222
Linus Torvalds1da177e2005-04-16 15:20:36 -07003223/*
3224* qla2x00_abort_isp
3225* Resets ISP and aborts all outstanding commands.
3226*
3227* Input:
3228* ha = adapter block pointer.
3229*
3230* Returns:
3231* 0 = success
3232*/
3233int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003234qla2x00_abort_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003235{
Andrew Vasquez476e8972006-08-23 14:54:55 -07003236 int rval;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 uint8_t status = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003238 struct qla_hw_data *ha = vha->hw;
3239 struct scsi_qla_host *vp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003240
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003241 if (vha->flags.online) {
3242 vha->flags.online = 0;
3243 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Harish Zunjarraoe5f5f6f2008-07-10 16:55:49 -07003244 ha->qla_stats.total_isp_aborts++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245
3246 qla_printk(KERN_INFO, ha,
3247 "Performing ISP error recovery - ha= %p.\n", ha);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003248 ha->isp_ops->reset_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003249
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003250 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
3251 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
3252 atomic_set(&vha->loop_state, LOOP_DOWN);
3253 qla2x00_mark_all_devices_lost(vha, 0);
3254 list_for_each_entry(vp, &ha->vp_list, list)
3255 qla2x00_mark_all_devices_lost(vp, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003257 if (!atomic_read(&vha->loop_down_timer))
3258 atomic_set(&vha->loop_down_timer,
Linus Torvalds1da177e2005-04-16 15:20:36 -07003259 LOOP_DOWN_TIME);
3260 }
3261
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 /* Requeue all commands in outstanding command list. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003263 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003264
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003265 ha->isp_ops->get_flash_version(vha, ha->req->ring);
Andrew Vasquez30c47662007-01-29 10:22:21 -08003266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003267 ha->isp_ops->nvram_config(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003269 if (!qla2x00_restart_isp(vha)) {
3270 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003271
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003272 if (!atomic_read(&vha->loop_down_timer)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273 /*
3274 * Issue marker command only when we are going
3275 * to start the I/O .
3276 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003277 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003278 }
3279
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003280 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003281
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003282 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003283
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003284 ha->isp_abort_cnt = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003285 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Andrew Vasquez476e8972006-08-23 14:54:55 -07003286
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003287 if (ha->fce) {
3288 ha->flags.fce_enabled = 1;
3289 memset(ha->fce, 0,
3290 fce_calc_size(ha->fce_bufs));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003291 rval = qla2x00_enable_fce_trace(vha,
Andrew Vasquezdf613b92008-01-17 09:02:17 -08003292 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
3293 &ha->fce_bufs);
3294 if (rval) {
3295 qla_printk(KERN_WARNING, ha,
3296 "Unable to reinitialize FCE "
3297 "(%d).\n", rval);
3298 ha->flags.fce_enabled = 0;
3299 }
3300 }
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003301
3302 if (ha->eft) {
3303 memset(ha->eft, 0, EFT_SIZE);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003304 rval = qla2x00_enable_eft_trace(vha,
Andrew Vasquez436a7b12008-07-10 16:55:54 -07003305 ha->eft_dma, EFT_NUM_BUFFERS);
3306 if (rval) {
3307 qla_printk(KERN_WARNING, ha,
3308 "Unable to reinitialize EFT "
3309 "(%d).\n", rval);
3310 }
3311 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003312 } else { /* failed the ISP abort */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003313 vha->flags.online = 1;
3314 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 if (ha->isp_abort_cnt == 0) {
3316 qla_printk(KERN_WARNING, ha,
3317 "ISP error recovery failed - "
3318 "board disabled\n");
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003319 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 * The next call disables the board
3321 * completely.
3322 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003323 ha->isp_ops->reset_adapter(vha);
3324 vha->flags.online = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 clear_bit(ISP_ABORT_RETRY,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003326 &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 status = 0;
3328 } else { /* schedule another ISP abort */
3329 ha->isp_abort_cnt--;
3330 DEBUG(printk("qla%ld: ISP abort - "
Andrew Vasquez01071092005-07-06 10:31:37 -07003331 "retry remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003332 vha->host_no, ha->isp_abort_cnt));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 status = 1;
3334 }
3335 } else {
3336 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
3337 DEBUG(printk("qla2x00(%ld): ISP error recovery "
3338 "- retrying (%d) more times\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003339 vha->host_no, ha->isp_abort_cnt));
3340 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003341 status = 1;
3342 }
3343 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07003344
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 }
3346
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003347 if (!status) {
3348 DEBUG(printk(KERN_INFO
3349 "qla2x00_abort_isp(%ld): succeeded.\n",
3350 vha->host_no));
3351 list_for_each_entry(vp, &ha->vp_list, list) {
3352 if (vp->vp_idx)
3353 qla2x00_vp_abort_isp(vp);
3354 }
3355 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003356 qla_printk(KERN_INFO, ha,
3357 "qla2x00_abort_isp: **** FAILED ****\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07003358 }
3359
3360 return(status);
3361}
3362
3363/*
3364* qla2x00_restart_isp
3365* restarts the ISP after a reset
3366*
3367* Input:
3368* ha = adapter block pointer.
3369*
3370* Returns:
3371* 0 = success
3372*/
3373static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003374qla2x00_restart_isp(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003375{
3376 uint8_t status = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 uint32_t wait_time;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003378 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003379
3380 /* If firmware needs to be loaded */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003381 if (qla2x00_isp_firmware(vha)) {
3382 vha->flags.online = 0;
3383 status = ha->isp_ops->chip_diag(vha);
3384 if (!status)
3385 status = qla2x00_setup_chip(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 }
3387
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003388 if (!status && !(status = qla2x00_init_rings(vha))) {
3389 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3390 status = qla2x00_fw_ready(vha);
3391 if (!status) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 DEBUG(printk("%s(): Start configure loop, "
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003393 "status = %d\n", __func__, status));
Andrew Vasquez01071092005-07-06 10:31:37 -07003394
3395 /* Issue a marker after FW becomes ready. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003396 qla2x00_marker(vha, 0, 0, MK_SYNC_ALL);
Andrew Vasquez01071092005-07-06 10:31:37 -07003397
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003398 vha->flags.online = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003399 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3400 wait_time = 256;
3401 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003402 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
3403 qla2x00_configure_loop(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003404 wait_time--;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003405 } while (!atomic_read(&vha->loop_down_timer) &&
3406 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
3407 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
3408 &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003409 }
3410
3411 /* if no cable then assume it's good */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003412 if ((vha->device_flags & DFLG_NO_CABLE))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003413 status = 0;
3414
3415 DEBUG(printk("%s(): Configure loop done, status = 0x%x\n",
3416 __func__,
Andrew Vasquez744f11fd2006-06-23 16:11:05 -07003417 status));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418 }
3419 return (status);
3420}
3421
3422/*
3423* qla2x00_reset_adapter
3424* Reset adapter.
3425*
3426* Input:
3427* ha = adapter block pointer.
3428*/
Andrew Vasquezabbd8872005-07-06 10:30:05 -07003429void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003430qla2x00_reset_adapter(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003431{
3432 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003433 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez3d716442005-07-06 10:30:26 -07003434 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003435
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003436 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003437 ha->isp_ops->disable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003438
Linus Torvalds1da177e2005-04-16 15:20:36 -07003439 spin_lock_irqsave(&ha->hardware_lock, flags);
3440 WRT_REG_WORD(&reg->hccr, HCCR_RESET_RISC);
3441 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3442 WRT_REG_WORD(&reg->hccr, HCCR_RELEASE_RISC);
3443 RD_REG_WORD(&reg->hccr); /* PCI Posting. */
3444 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3445}
Andrew Vasquez01071092005-07-06 10:31:37 -07003446
3447void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003448qla24xx_reset_adapter(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003449{
3450 unsigned long flags = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003451 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003452 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
3453
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003454 vha->flags.online = 0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07003455 ha->isp_ops->disable_intrs(ha);
Andrew Vasquez01071092005-07-06 10:31:37 -07003456
3457 spin_lock_irqsave(&ha->hardware_lock, flags);
3458 WRT_REG_DWORD(&reg->hccr, HCCRX_SET_RISC_RESET);
3459 RD_REG_DWORD(&reg->hccr);
3460 WRT_REG_DWORD(&reg->hccr, HCCRX_REL_RISC_PAUSE);
3461 RD_REG_DWORD(&reg->hccr);
3462 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3463}
3464
David Miller4e08df32007-04-16 12:37:43 -07003465/* On sparc systems, obtain port and node WWN from firmware
3466 * properties.
3467 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003468static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
3469 struct nvram_24xx *nv)
David Miller4e08df32007-04-16 12:37:43 -07003470{
3471#ifdef CONFIG_SPARC
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003472 struct qla_hw_data *ha = vha->hw;
David Miller4e08df32007-04-16 12:37:43 -07003473 struct pci_dev *pdev = ha->pdev;
David S. Miller15576bc2007-05-08 00:36:49 -07003474 struct device_node *dp = pci_device_to_OF_node(pdev);
3475 const u8 *val;
David Miller4e08df32007-04-16 12:37:43 -07003476 int len;
3477
3478 val = of_get_property(dp, "port-wwn", &len);
3479 if (val && len >= WWN_SIZE)
3480 memcpy(nv->port_name, val, WWN_SIZE);
3481
3482 val = of_get_property(dp, "node-wwn", &len);
3483 if (val && len >= WWN_SIZE)
3484 memcpy(nv->node_name, val, WWN_SIZE);
3485#endif
3486}
3487
Andrew Vasquez01071092005-07-06 10:31:37 -07003488int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003489qla24xx_nvram_config(scsi_qla_host_t *vha)
Andrew Vasquez01071092005-07-06 10:31:37 -07003490{
David Miller4e08df32007-04-16 12:37:43 -07003491 int rval;
Andrew Vasquez01071092005-07-06 10:31:37 -07003492 struct init_cb_24xx *icb;
3493 struct nvram_24xx *nv;
3494 uint32_t *dptr;
3495 uint8_t *dptr1, *dptr2;
3496 uint32_t chksum;
3497 uint16_t cnt;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003498 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003499
David Miller4e08df32007-04-16 12:37:43 -07003500 rval = QLA_SUCCESS;
Andrew Vasquez01071092005-07-06 10:31:37 -07003501 icb = (struct init_cb_24xx *)ha->init_cb;
Seokmann Ju281afe12007-07-26 13:43:34 -07003502 nv = ha->nvram;
Andrew Vasquez01071092005-07-06 10:31:37 -07003503
3504 /* Determine NVRAM starting address. */
3505 ha->nvram_size = sizeof(struct nvram_24xx);
3506 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003507 ha->vpd_size = FA_NVRAM_VPD_SIZE;
3508 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
3509 if (PCI_FUNC(ha->pdev->devfn)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003510 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
andrew.vasquez@qlogic.com6f641792006-03-09 14:27:34 -08003511 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
3512 }
Andrew Vasquez01071092005-07-06 10:31:37 -07003513
Seokmann Ju281afe12007-07-26 13:43:34 -07003514 /* Get VPD data into cache */
3515 ha->vpd = ha->nvram + VPD_OFFSET;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003516 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
Seokmann Ju281afe12007-07-26 13:43:34 -07003517 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
3518
3519 /* Get NVRAM data into cache and calculate checksum. */
Andrew Vasquez01071092005-07-06 10:31:37 -07003520 dptr = (uint32_t *)nv;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003521 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
Andrew Vasquez01071092005-07-06 10:31:37 -07003522 ha->nvram_size);
3523 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++)
3524 chksum += le32_to_cpu(*dptr++);
3525
3526 DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no));
Seokmann Ju281afe12007-07-26 13:43:34 -07003527 DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size));
Andrew Vasquez01071092005-07-06 10:31:37 -07003528
3529 /* Bad NVRAM data, set defaults parameters. */
3530 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
3531 || nv->id[3] != ' ' ||
3532 nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) {
3533 /* Reset NVRAM data. */
3534 qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: "
3535 "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0],
3536 le16_to_cpu(nv->nvram_version));
David Miller4e08df32007-04-16 12:37:43 -07003537 qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet "
3538 "invalid -- WWPN) defaults.\n");
3539
3540 /*
3541 * Set default initialization control block.
3542 */
3543 memset(nv, 0, ha->nvram_size);
3544 nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION);
3545 nv->version = __constant_cpu_to_le16(ICB_VERSION);
3546 nv->frame_payload_size = __constant_cpu_to_le16(2048);
3547 nv->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3548 nv->exchange_count = __constant_cpu_to_le16(0);
3549 nv->hard_address = __constant_cpu_to_le16(124);
3550 nv->port_name[0] = 0x21;
3551 nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn);
3552 nv->port_name[2] = 0x00;
3553 nv->port_name[3] = 0xe0;
3554 nv->port_name[4] = 0x8b;
3555 nv->port_name[5] = 0x1c;
3556 nv->port_name[6] = 0x55;
3557 nv->port_name[7] = 0x86;
3558 nv->node_name[0] = 0x20;
3559 nv->node_name[1] = 0x00;
3560 nv->node_name[2] = 0x00;
3561 nv->node_name[3] = 0xe0;
3562 nv->node_name[4] = 0x8b;
3563 nv->node_name[5] = 0x1c;
3564 nv->node_name[6] = 0x55;
3565 nv->node_name[7] = 0x86;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003566 qla24xx_nvram_wwn_from_ofw(vha, nv);
David Miller4e08df32007-04-16 12:37:43 -07003567 nv->login_retry_count = __constant_cpu_to_le16(8);
3568 nv->interrupt_delay_timer = __constant_cpu_to_le16(0);
3569 nv->login_timeout = __constant_cpu_to_le16(0);
3570 nv->firmware_options_1 =
3571 __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
3572 nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4);
3573 nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12);
3574 nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13);
3575 nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10);
3576 nv->efi_parameters = __constant_cpu_to_le32(0);
3577 nv->reset_delay = 5;
3578 nv->max_luns_per_target = __constant_cpu_to_le16(128);
3579 nv->port_down_retry_count = __constant_cpu_to_le16(30);
3580 nv->link_down_timeout = __constant_cpu_to_le16(30);
3581
3582 rval = 1;
Andrew Vasquez01071092005-07-06 10:31:37 -07003583 }
3584
3585 /* Reset Initialization control block */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003586 memset(icb, 0, ha->init_cb_size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003587
3588 /* Copy 1st segment. */
3589 dptr1 = (uint8_t *)icb;
3590 dptr2 = (uint8_t *)&nv->version;
3591 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
3592 while (cnt--)
3593 *dptr1++ = *dptr2++;
3594
3595 icb->login_retry_count = nv->login_retry_count;
Andrew Vasquez3ea66e22006-06-23 16:11:27 -07003596 icb->link_down_on_nos = nv->link_down_on_nos;
Andrew Vasquez01071092005-07-06 10:31:37 -07003597
3598 /* Copy 2nd segment. */
3599 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
3600 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
3601 cnt = (uint8_t *)&icb->reserved_3 -
3602 (uint8_t *)&icb->interrupt_delay_timer;
3603 while (cnt--)
3604 *dptr1++ = *dptr2++;
3605
3606 /*
3607 * Setup driver NVRAM options.
3608 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003609 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
Andrew Vasquez9bb9fcf2007-01-29 10:22:24 -08003610 "QLA2462");
Andrew Vasquez01071092005-07-06 10:31:37 -07003611
Andrew Vasquez5341e862006-05-17 15:09:16 -07003612 /* Use alternate WWN? */
3613 if (nv->host_p & __constant_cpu_to_le32(BIT_15)) {
3614 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
3615 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
3616 }
3617
Andrew Vasquez01071092005-07-06 10:31:37 -07003618 /* Prepare nodename */
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003619 if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003620 /*
3621 * Firmware will apply the following mask if the nodename was
3622 * not provided.
3623 */
3624 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
3625 icb->node_name[0] &= 0xF0;
3626 }
3627
3628 /* Set host adapter parameters. */
3629 ha->flags.disable_risc_code_load = 0;
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08003630 ha->flags.enable_lip_reset = 0;
3631 ha->flags.enable_lip_full_login =
3632 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
3633 ha->flags.enable_target_reset =
3634 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003635 ha->flags.enable_led_scheme = 0;
Andrew Vasquezd4c760c2006-06-23 16:10:39 -07003636 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
Andrew Vasquez01071092005-07-06 10:31:37 -07003637
Andrew Vasquezfd0e7e42006-05-17 15:09:11 -07003638 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
3639 (BIT_6 | BIT_5 | BIT_4)) >> 4;
Andrew Vasquez01071092005-07-06 10:31:37 -07003640
3641 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
3642 sizeof(ha->fw_seriallink_options24));
3643
3644 /* save HBA serial number */
3645 ha->serial0 = icb->port_name[5];
3646 ha->serial1 = icb->port_name[6];
3647 ha->serial2 = icb->port_name[7];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003648 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
3649 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
Andrew Vasquez01071092005-07-06 10:31:37 -07003650
andrew.vasquez@qlogic.combc8fb3c2006-01-13 17:05:42 -08003651 icb->execution_throttle = __constant_cpu_to_le16(0xFFFF);
3652
Andrew Vasquez01071092005-07-06 10:31:37 -07003653 ha->retry_count = le16_to_cpu(nv->login_retry_count);
3654
3655 /* Set minimum login_timeout to 4 seconds. */
3656 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
3657 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
3658 if (le16_to_cpu(nv->login_timeout) < 4)
3659 nv->login_timeout = __constant_cpu_to_le16(4);
3660 ha->login_timeout = le16_to_cpu(nv->login_timeout);
Seokmann Juc6852c42008-04-24 15:21:29 -07003661 icb->login_timeout = nv->login_timeout;
Andrew Vasquez01071092005-07-06 10:31:37 -07003662
Andrew Vasquez00a537b2008-02-28 14:06:11 -08003663 /* Set minimum RATOV to 100 tenths of a second. */
3664 ha->r_a_tov = 100;
Andrew Vasquez01071092005-07-06 10:31:37 -07003665
3666 ha->loop_reset_delay = nv->reset_delay;
3667
3668 /* Link Down Timeout = 0:
3669 *
3670 * When Port Down timer expires we will start returning
3671 * I/O's to OS with "DID_NO_CONNECT".
3672 *
3673 * Link Down Timeout != 0:
3674 *
3675 * The driver waits for the link to come up after link down
3676 * before returning I/Os to OS with "DID_NO_CONNECT".
3677 */
3678 if (le16_to_cpu(nv->link_down_timeout) == 0) {
3679 ha->loop_down_abort_time =
3680 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
3681 } else {
3682 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
3683 ha->loop_down_abort_time =
3684 (LOOP_DOWN_TIME - ha->link_down_timeout);
3685 }
3686
3687 /* Need enough time to try and get the port back. */
3688 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
3689 if (qlport_down_retry)
3690 ha->port_down_retry_count = qlport_down_retry;
3691
3692 /* Set login_retry_count */
3693 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
3694 if (ha->port_down_retry_count ==
3695 le16_to_cpu(nv->port_down_retry_count) &&
3696 ha->port_down_retry_count > 3)
3697 ha->login_retry_count = ha->port_down_retry_count;
3698 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
3699 ha->login_retry_count = ha->port_down_retry_count;
3700 if (ql2xloginretrycount)
3701 ha->login_retry_count = ql2xloginretrycount;
3702
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003703 /* Enable ZIO. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003704 if (!vha->flags.init_done) {
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003705 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
3706 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3707 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
3708 le16_to_cpu(icb->interrupt_delay_timer): 2;
3709 }
3710 icb->firmware_options_2 &= __constant_cpu_to_le32(
3711 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003712 vha->flags.process_response_queue = 0;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003713 if (ha->zio_mode != QLA_ZIO_DISABLED) {
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08003714 ha->zio_mode = QLA_ZIO_MODE_6;
3715
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003716 DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003717 "(%d us).\n", vha->host_no, ha->zio_mode,
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003718 ha->zio_timer * 100));
3719 qla_printk(KERN_INFO, ha,
3720 "ZIO mode %d enabled; timer delay (%d us).\n",
3721 ha->zio_mode, ha->zio_timer * 100);
3722
3723 icb->firmware_options_2 |= cpu_to_le32(
3724 (uint32_t)ha->zio_mode);
3725 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003726 vha->flags.process_response_queue = 1;
Andrew Vasquez4fdfefe2005-10-27 11:09:48 -07003727 }
3728
David Miller4e08df32007-04-16 12:37:43 -07003729 if (rval) {
3730 DEBUG2_3(printk(KERN_WARNING
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003731 "scsi(%ld): NVRAM configuration failed!\n", vha->host_no));
David Miller4e08df32007-04-16 12:37:43 -07003732 }
3733 return (rval);
Andrew Vasquez01071092005-07-06 10:31:37 -07003734}
3735
Adrian Bunk413975a2006-06-30 02:33:06 -07003736static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003737qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003738{
3739 int rval;
3740 int segments, fragment;
3741 uint32_t faddr;
3742 uint32_t *dcode, dlen;
3743 uint32_t risc_addr;
3744 uint32_t risc_size;
3745 uint32_t i;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003746 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003747 rval = QLA_SUCCESS;
3748
3749 segments = FA_RISC_CODE_SEGMENTS;
Andrew Vasquezc00d8992008-09-11 21:22:49 -07003750 faddr = ha->flt_region_fw;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003751 dcode = (uint32_t *)ha->req->ring;
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003752 *srisc_addr = 0;
3753
3754 /* Validate firmware image by checking version. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003755 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003756 for (i = 0; i < 4; i++)
3757 dcode[i] = be32_to_cpu(dcode[i]);
3758 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3759 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3760 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3761 dcode[3] == 0)) {
3762 qla_printk(KERN_WARNING, ha,
3763 "Unable to verify integrity of flash firmware image!\n");
3764 qla_printk(KERN_WARNING, ha,
3765 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3766 dcode[1], dcode[2], dcode[3]);
3767
3768 return QLA_FUNCTION_FAILED;
3769 }
3770
3771 while (segments && rval == QLA_SUCCESS) {
3772 /* Read segment's load information. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003773 qla24xx_read_flash_data(vha, dcode, faddr, 4);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003774
3775 risc_addr = be32_to_cpu(dcode[2]);
3776 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3777 risc_size = be32_to_cpu(dcode[3]);
3778
3779 fragment = 0;
3780 while (risc_size > 0 && rval == QLA_SUCCESS) {
3781 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3782 if (dlen > risc_size)
3783 dlen = risc_size;
3784
3785 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
3786 "addr %x, number of dwords 0x%x, offset 0x%x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003787 vha->host_no, risc_addr, dlen, faddr));
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003788
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003789 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003790 for (i = 0; i < dlen; i++)
3791 dcode[i] = swab32(dcode[i]);
3792
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003793 rval = qla2x00_load_ram(vha, ha->req->dma, risc_addr,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003794 dlen);
3795 if (rval) {
3796 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003797 "segment %d of firmware\n", vha->host_no,
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003798 fragment));
3799 qla_printk(KERN_WARNING, ha,
3800 "[ERROR] Failed to load segment %d of "
3801 "firmware\n", fragment);
3802 break;
3803 }
3804
3805 faddr += dlen;
3806 risc_addr += dlen;
3807 risc_size -= dlen;
3808 fragment++;
3809 }
3810
3811 /* Next segment. */
3812 segments--;
3813 }
3814
3815 return rval;
3816}
3817
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003818#define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
3819
Andrew Vasquez01071092005-07-06 10:31:37 -07003820int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003821qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez54333832005-11-09 15:49:04 -08003822{
3823 int rval;
3824 int i, fragment;
3825 uint16_t *wcode, *fwcode;
3826 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
3827 struct fw_blob *blob;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003828 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003829
3830 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003831 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003832 if (!blob) {
3833 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003834 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3835 "from: " QLA_FW_URL ".\n");
Andrew Vasquez54333832005-11-09 15:49:04 -08003836 return QLA_FUNCTION_FAILED;
3837 }
3838
3839 rval = QLA_SUCCESS;
3840
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003841 wcode = (uint16_t *)ha->req->ring;
Andrew Vasquez54333832005-11-09 15:49:04 -08003842 *srisc_addr = 0;
3843 fwcode = (uint16_t *)blob->fw->data;
3844 fwclen = 0;
3845
3846 /* Validate firmware image by checking version. */
3847 if (blob->fw->size < 8 * sizeof(uint16_t)) {
3848 qla_printk(KERN_WARNING, ha,
3849 "Unable to verify integrity of firmware image (%Zd)!\n",
3850 blob->fw->size);
3851 goto fail_fw_integrity;
3852 }
3853 for (i = 0; i < 4; i++)
3854 wcode[i] = be16_to_cpu(fwcode[i + 4]);
3855 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
3856 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
3857 wcode[2] == 0 && wcode[3] == 0)) {
3858 qla_printk(KERN_WARNING, ha,
3859 "Unable to verify integrity of firmware image!\n");
3860 qla_printk(KERN_WARNING, ha,
3861 "Firmware data: %04x %04x %04x %04x!\n", wcode[0],
3862 wcode[1], wcode[2], wcode[3]);
3863 goto fail_fw_integrity;
3864 }
3865
3866 seg = blob->segs;
3867 while (*seg && rval == QLA_SUCCESS) {
3868 risc_addr = *seg;
3869 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
3870 risc_size = be16_to_cpu(fwcode[3]);
3871
3872 /* Validate firmware image size. */
3873 fwclen += risc_size * sizeof(uint16_t);
3874 if (blob->fw->size < fwclen) {
3875 qla_printk(KERN_WARNING, ha,
3876 "Unable to verify integrity of firmware image "
3877 "(%Zd)!\n", blob->fw->size);
3878 goto fail_fw_integrity;
3879 }
3880
3881 fragment = 0;
3882 while (risc_size > 0 && rval == QLA_SUCCESS) {
3883 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
3884 if (wlen > risc_size)
3885 wlen = risc_size;
3886
3887 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003888 "addr %x, number of words 0x%x.\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003889 risc_addr, wlen));
3890
3891 for (i = 0; i < wlen; i++)
3892 wcode[i] = swab16(fwcode[i]);
3893
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003894 rval = qla2x00_load_ram(vha, ha->req->dma, risc_addr,
Andrew Vasquez54333832005-11-09 15:49:04 -08003895 wlen);
3896 if (rval) {
3897 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003898 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez54333832005-11-09 15:49:04 -08003899 fragment));
3900 qla_printk(KERN_WARNING, ha,
3901 "[ERROR] Failed to load segment %d of "
3902 "firmware\n", fragment);
3903 break;
3904 }
3905
3906 fwcode += wlen;
3907 risc_addr += wlen;
3908 risc_size -= wlen;
3909 fragment++;
3910 }
3911
3912 /* Next segment. */
3913 seg++;
3914 }
3915 return rval;
3916
3917fail_fw_integrity:
3918 return QLA_FUNCTION_FAILED;
3919}
3920
3921int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003922qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
Andrew Vasquez01071092005-07-06 10:31:37 -07003923{
3924 int rval;
3925 int segments, fragment;
3926 uint32_t *dcode, dlen;
3927 uint32_t risc_addr;
3928 uint32_t risc_size;
3929 uint32_t i;
Andrew Vasquez54333832005-11-09 15:49:04 -08003930 struct fw_blob *blob;
Andrew Vasquez01071092005-07-06 10:31:37 -07003931 uint32_t *fwcode, fwclen;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003932 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez01071092005-07-06 10:31:37 -07003933
Andrew Vasquez54333832005-11-09 15:49:04 -08003934 /* Load firmware blob. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003935 blob = qla2x00_request_firmware(vha);
Andrew Vasquez54333832005-11-09 15:49:04 -08003936 if (!blob) {
3937 qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n");
Andrew Vasquezd1c61902006-05-17 15:09:00 -07003938 qla_printk(KERN_ERR, ha, "Firmware images can be retrieved "
3939 "from: " QLA_FW_URL ".\n");
3940
3941 /* Try to load RISC code from flash. */
3942 qla_printk(KERN_ERR, ha, "Attempting to load (potentially "
3943 "outdated) firmware from flash.\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003944 return qla24xx_load_risc_flash(vha, srisc_addr);
Andrew Vasquez01071092005-07-06 10:31:37 -07003945 }
3946
3947 rval = QLA_SUCCESS;
3948
3949 segments = FA_RISC_CODE_SEGMENTS;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003950 dcode = (uint32_t *)ha->req->ring;
Andrew Vasquez01071092005-07-06 10:31:37 -07003951 *srisc_addr = 0;
Andrew Vasquez54333832005-11-09 15:49:04 -08003952 fwcode = (uint32_t *)blob->fw->data;
Andrew Vasquez01071092005-07-06 10:31:37 -07003953 fwclen = 0;
3954
3955 /* Validate firmware image by checking version. */
Andrew Vasquez54333832005-11-09 15:49:04 -08003956 if (blob->fw->size < 8 * sizeof(uint32_t)) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003957 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003958 "Unable to verify integrity of firmware image (%Zd)!\n",
3959 blob->fw->size);
Andrew Vasquez01071092005-07-06 10:31:37 -07003960 goto fail_fw_integrity;
3961 }
3962 for (i = 0; i < 4; i++)
3963 dcode[i] = be32_to_cpu(fwcode[i + 4]);
3964 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
3965 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
3966 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
3967 dcode[3] == 0)) {
3968 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003969 "Unable to verify integrity of firmware image!\n");
Andrew Vasquez01071092005-07-06 10:31:37 -07003970 qla_printk(KERN_WARNING, ha,
3971 "Firmware data: %08x %08x %08x %08x!\n", dcode[0],
3972 dcode[1], dcode[2], dcode[3]);
3973 goto fail_fw_integrity;
3974 }
3975
3976 while (segments && rval == QLA_SUCCESS) {
3977 risc_addr = be32_to_cpu(fwcode[2]);
3978 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
3979 risc_size = be32_to_cpu(fwcode[3]);
3980
3981 /* Validate firmware image size. */
3982 fwclen += risc_size * sizeof(uint32_t);
Andrew Vasquez54333832005-11-09 15:49:04 -08003983 if (blob->fw->size < fwclen) {
Andrew Vasquez01071092005-07-06 10:31:37 -07003984 qla_printk(KERN_WARNING, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08003985 "Unable to verify integrity of firmware image "
3986 "(%Zd)!\n", blob->fw->size);
3987
Andrew Vasquez01071092005-07-06 10:31:37 -07003988 goto fail_fw_integrity;
3989 }
3990
3991 fragment = 0;
3992 while (risc_size > 0 && rval == QLA_SUCCESS) {
3993 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
3994 if (dlen > risc_size)
3995 dlen = risc_size;
3996
3997 DEBUG7(printk("scsi(%ld): Loading risc segment@ risc "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003998 "addr %x, number of dwords 0x%x.\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07003999 risc_addr, dlen));
4000
4001 for (i = 0; i < dlen; i++)
4002 dcode[i] = swab32(fwcode[i]);
4003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004004 rval = qla2x00_load_ram(vha, ha->req->dma, risc_addr,
andrew.vasquez@qlogic.com590f98e2006-01-13 17:05:37 -08004005 dlen);
Andrew Vasquez01071092005-07-06 10:31:37 -07004006 if (rval) {
4007 DEBUG(printk("scsi(%ld):[ERROR] Failed to load "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004008 "segment %d of firmware\n", vha->host_no,
Andrew Vasquez01071092005-07-06 10:31:37 -07004009 fragment));
4010 qla_printk(KERN_WARNING, ha,
4011 "[ERROR] Failed to load segment %d of "
4012 "firmware\n", fragment);
4013 break;
4014 }
4015
4016 fwcode += dlen;
4017 risc_addr += dlen;
4018 risc_size -= dlen;
4019 fragment++;
4020 }
4021
4022 /* Next segment. */
4023 segments--;
4024 }
Andrew Vasquez01071092005-07-06 10:31:37 -07004025 return rval;
4026
4027fail_fw_integrity:
Andrew Vasquez01071092005-07-06 10:31:37 -07004028 return QLA_FUNCTION_FAILED;
Andrew Vasquez01071092005-07-06 10:31:37 -07004029}
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004030
4031void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004032qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004033{
4034 int ret, retries;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004035 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004036
Andrew Vasqueze4289242007-07-19 15:05:56 -07004037 if (!IS_FWI2_CAPABLE(ha))
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004038 return;
Andrew Vasquez75edf812007-05-07 07:43:00 -07004039 if (!ha->fw_major_version)
4040 return;
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004041
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004042 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez7c7f1f22008-02-28 14:06:09 -08004043 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
4044 retries ; retries--) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004045 ha->isp_ops->reset_chip(vha);
4046 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004047 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004048 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004049 continue;
4050 qla_printk(KERN_INFO, ha,
4051 "Attempting retry of stop-firmware command...\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004052 ret = qla2x00_stop_firmware(vha);
Andrew Vasquez18c6c122006-10-13 09:33:38 -07004053 }
4054}
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004055
4056int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004057qla24xx_configure_vhba(scsi_qla_host_t *vha)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004058{
4059 int rval = QLA_SUCCESS;
4060 uint16_t mb[MAILBOX_REGISTER_COUNT];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004061 struct qla_hw_data *ha = vha->hw;
4062 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004063
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004064 if (!vha->vp_idx)
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004065 return -EINVAL;
4066
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004067 rval = qla2x00_fw_ready(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004068 if (rval == QLA_SUCCESS) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004069 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
4070 qla2x00_marker(vha, 0, 0, MK_SYNC_ALL);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004071 }
4072
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004073 vha->flags.management_server_logged_in = 0;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004074
4075 /* Login to SNS first */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004076 ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004077 if (mb[0] != MBS_COMMAND_COMPLETE) {
4078 DEBUG15(qla_printk(KERN_INFO, ha,
4079 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4080 "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS,
4081 mb[0], mb[1], mb[2], mb[6], mb[7]));
4082 return (QLA_FUNCTION_FAILED);
4083 }
4084
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004085 atomic_set(&vha->loop_down_timer, 0);
4086 atomic_set(&vha->loop_state, LOOP_UP);
4087 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4088 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4089 rval = qla2x00_loop_resync(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07004090
4091 return rval;
4092}
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004093
4094/* 84XX Support **************************************************************/
4095
4096static LIST_HEAD(qla_cs84xx_list);
4097static DEFINE_MUTEX(qla_cs84xx_mutex);
4098
4099static struct qla_chip_state_84xx *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004100qla84xx_get_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004101{
4102 struct qla_chip_state_84xx *cs84xx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004103 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004104
4105 mutex_lock(&qla_cs84xx_mutex);
4106
4107 /* Find any shared 84xx chip. */
4108 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
4109 if (cs84xx->bus == ha->pdev->bus) {
4110 kref_get(&cs84xx->kref);
4111 goto done;
4112 }
4113 }
4114
4115 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
4116 if (!cs84xx)
4117 goto done;
4118
4119 kref_init(&cs84xx->kref);
4120 spin_lock_init(&cs84xx->access_lock);
4121 mutex_init(&cs84xx->fw_update_mutex);
4122 cs84xx->bus = ha->pdev->bus;
4123
4124 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
4125done:
4126 mutex_unlock(&qla_cs84xx_mutex);
4127 return cs84xx;
4128}
4129
4130static void
4131__qla84xx_chip_release(struct kref *kref)
4132{
4133 struct qla_chip_state_84xx *cs84xx =
4134 container_of(kref, struct qla_chip_state_84xx, kref);
4135
4136 mutex_lock(&qla_cs84xx_mutex);
4137 list_del(&cs84xx->list);
4138 mutex_unlock(&qla_cs84xx_mutex);
4139 kfree(cs84xx);
4140}
4141
4142void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004143qla84xx_put_chip(struct scsi_qla_host *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004144{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004145 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004146 if (ha->cs84xx)
4147 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
4148}
4149
4150static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004151qla84xx_init_chip(scsi_qla_host_t *vha)
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004152{
4153 int rval;
4154 uint16_t status[2];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004155 struct qla_hw_data *ha = vha->hw;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004156
4157 mutex_lock(&ha->cs84xx->fw_update_mutex);
4158
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08004159 rval = qla84xx_verify_chip(vha, status);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07004160
4161 mutex_unlock(&ha->cs84xx->fw_update_mutex);
4162
4163 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
4164 QLA_SUCCESS;
4165}