Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2008 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 8 | #include "qla_gbl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <linux/delay.h> |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 11 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | |
| 13 | #include "qla_devtbl.h" |
| 14 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 15 | #ifdef CONFIG_SPARC |
| 16 | #include <asm/prom.h> |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 17 | #endif |
| 18 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | /* |
| 20 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
| 21 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static int qla2x00_init_rings(scsi_qla_host_t *); |
| 25 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 26 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 28 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
| 30 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); |
| 31 | static int qla2x00_device_resync(scsi_qla_host_t *); |
| 32 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, |
| 33 | uint16_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | |
| 35 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 37 | static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *); |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 38 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 39 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 40 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 41 | static int qla25xx_init_queues(struct qla_hw_data *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 42 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | /****************************************************************************/ |
| 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 | */ |
| 57 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 58 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | { |
| 60 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 61 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 62 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 63 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 65 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 66 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 67 | vha->flags.reset_active = 0; |
| 68 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 69 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 70 | vha->device_flags = DFLG_NO_CABLE; |
| 71 | vha->dpc_flags = 0; |
| 72 | vha->flags.management_server_logged_in = 0; |
| 73 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | ha->isp_abort_cnt = 0; |
| 75 | ha->beacon_blink_led = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 76 | set_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 78 | set_bit(0, ha->req_qid_map); |
| 79 | set_bit(0, ha->rsp_qid_map); |
| 80 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 81 | qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 82 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | if (rval) { |
Andrew Vasquez | 7c98a04 | 2007-01-29 10:22:29 -0800 | [diff] [blame] | 84 | DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 85 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | return (rval); |
| 87 | } |
| 88 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 89 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 91 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 92 | if (rval) { |
| 93 | DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 94 | vha->host_no)); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 95 | return (rval); |
| 96 | } |
| 97 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 98 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 99 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 101 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 102 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 104 | if (ha->flags.disable_serdes) { |
| 105 | /* Mask HBA via NVRAM settings? */ |
| 106 | qla_printk(KERN_INFO, ha, "Masking HBA WWPN " |
| 107 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 108 | vha->port_name[0], vha->port_name[1], |
| 109 | vha->port_name[2], vha->port_name[3], |
| 110 | vha->port_name[4], vha->port_name[5], |
| 111 | vha->port_name[6], vha->port_name[7]); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 112 | return QLA_FUNCTION_FAILED; |
| 113 | } |
| 114 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n"); |
| 116 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 117 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 118 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 119 | if (rval) |
| 120 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 121 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 122 | if (rval) |
| 123 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 125 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 126 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 127 | if (!ha->cs84xx) { |
| 128 | qla_printk(KERN_ERR, ha, |
| 129 | "Unable to configure ISP84XX.\n"); |
| 130 | return QLA_FUNCTION_FAILED; |
| 131 | } |
| 132 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 133 | rval = qla2x00_init_rings(vha); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 134 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | return (rval); |
| 137 | } |
| 138 | |
| 139 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 140 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | * @ha: HA context |
| 142 | * |
| 143 | * Returns 0 on success. |
| 144 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 145 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 146 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 148 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 149 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 150 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 151 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 154 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 157 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 159 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 160 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 162 | /* Get PCI bus information. */ |
| 163 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 164 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 165 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 166 | |
| 167 | return QLA_SUCCESS; |
| 168 | } |
| 169 | |
| 170 | /** |
| 171 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 172 | * @ha: HA context |
| 173 | * |
| 174 | * Returns 0 on success. |
| 175 | */ |
| 176 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 177 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 178 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 179 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 180 | unsigned long flags = 0; |
| 181 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 182 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 183 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 184 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 185 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 186 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 187 | |
| 188 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 189 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 190 | |
| 191 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 192 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 193 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * If this is a 2300 card and not 2312, reset the |
| 197 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 198 | * the 2310 also reports itself as a 2300 so we need to get the |
| 199 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 200 | * not a 2310. |
| 201 | */ |
| 202 | if (IS_QLA2300(ha)) { |
| 203 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 204 | |
| 205 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 206 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 207 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 208 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 209 | break; |
| 210 | |
| 211 | udelay(10); |
| 212 | } |
| 213 | |
| 214 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 215 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 216 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 217 | |
| 218 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 219 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 220 | |
| 221 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 222 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 223 | |
| 224 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 225 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 226 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 227 | |
| 228 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 229 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 230 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 231 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 232 | break; |
| 233 | |
| 234 | udelay(10); |
| 235 | } |
| 236 | |
| 237 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 238 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 239 | |
| 240 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 241 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 242 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 243 | |
| 244 | /* Get PCI bus information. */ |
| 245 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 246 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 247 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 248 | |
| 249 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 253 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 254 | * @ha: HA context |
| 255 | * |
| 256 | * Returns 0 on success. |
| 257 | */ |
| 258 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 259 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 260 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 261 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 262 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 263 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 264 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 265 | |
| 266 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 267 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 268 | |
| 269 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 270 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 271 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 272 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 273 | |
| 274 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 275 | |
| 276 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 277 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 278 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 279 | |
| 280 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 281 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 282 | pcie_set_readrq(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 283 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 284 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 285 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 286 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 287 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 288 | /* Get PCI bus information. */ |
| 289 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 290 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 291 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 292 | |
| 293 | return QLA_SUCCESS; |
| 294 | } |
| 295 | |
| 296 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 297 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 298 | * @ha: HA context |
| 299 | * |
| 300 | * Returns 0 on success. |
| 301 | */ |
| 302 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 303 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 304 | { |
| 305 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 306 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 307 | |
| 308 | pci_set_master(ha->pdev); |
| 309 | pci_try_set_mwi(ha->pdev); |
| 310 | |
| 311 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 312 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 313 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 314 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 315 | |
| 316 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
| 317 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 318 | pcie_set_readrq(ha->pdev, 2048); |
| 319 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 320 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 321 | |
| 322 | ha->chip_revision = ha->pdev->revision; |
| 323 | |
| 324 | return QLA_SUCCESS; |
| 325 | } |
| 326 | |
| 327 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | * qla2x00_isp_firmware() - Choose firmware image. |
| 329 | * @ha: HA context |
| 330 | * |
| 331 | * Returns 0 on success. |
| 332 | */ |
| 333 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 334 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | { |
| 336 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 337 | uint16_t loop_id, topo, sw_cap; |
| 338 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 339 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 342 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | if (ha->flags.disable_risc_code_load) { |
| 345 | DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 346 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n"); |
| 348 | |
| 349 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 350 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 351 | if (rval == QLA_SUCCESS) { |
| 352 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 353 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 354 | &area, &domain, &topo, &sw_cap); |
| 355 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | if (rval) { |
| 359 | DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 360 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | } |
| 362 | |
| 363 | return (rval); |
| 364 | } |
| 365 | |
| 366 | /** |
| 367 | * qla2x00_reset_chip() - Reset ISP chip. |
| 368 | * @ha: HA context |
| 369 | * |
| 370 | * Returns 0 on success. |
| 371 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 372 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 373 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | { |
| 375 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 376 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 377 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | uint16_t cmd; |
| 380 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 381 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | |
| 383 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 384 | |
| 385 | /* Turn off master enable */ |
| 386 | cmd = 0; |
| 387 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 388 | cmd &= ~PCI_COMMAND_MASTER; |
| 389 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 390 | |
| 391 | if (!IS_QLA2100(ha)) { |
| 392 | /* Pause RISC. */ |
| 393 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 394 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 395 | for (cnt = 0; cnt < 30000; cnt++) { |
| 396 | if ((RD_REG_WORD(®->hccr) & |
| 397 | HCCR_RISC_PAUSE) != 0) |
| 398 | break; |
| 399 | udelay(100); |
| 400 | } |
| 401 | } else { |
| 402 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 403 | udelay(10); |
| 404 | } |
| 405 | |
| 406 | /* Select FPM registers. */ |
| 407 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 408 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 409 | |
| 410 | /* FPM Soft Reset. */ |
| 411 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 412 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 413 | |
| 414 | /* Toggle Fpm Reset. */ |
| 415 | if (!IS_QLA2200(ha)) { |
| 416 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 417 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 418 | } |
| 419 | |
| 420 | /* Select frame buffer registers. */ |
| 421 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 422 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 423 | |
| 424 | /* Reset frame buffer FIFOs. */ |
| 425 | if (IS_QLA2200(ha)) { |
| 426 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 427 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 428 | } else { |
| 429 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 430 | |
| 431 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 432 | for (cnt = 0; cnt < 3000; cnt++) { |
| 433 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 434 | break; |
| 435 | udelay(100); |
| 436 | } |
| 437 | } |
| 438 | |
| 439 | /* Select RISC module registers. */ |
| 440 | WRT_REG_WORD(®->ctrl_status, 0); |
| 441 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 442 | |
| 443 | /* Reset RISC processor. */ |
| 444 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 445 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 446 | |
| 447 | /* Release RISC processor. */ |
| 448 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 449 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 450 | } |
| 451 | |
| 452 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 453 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 454 | |
| 455 | /* Reset ISP chip. */ |
| 456 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 457 | |
| 458 | /* Wait for RISC to recover from reset. */ |
| 459 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 460 | /* |
| 461 | * It is necessary to for a delay here since the card doesn't |
| 462 | * respond to PCI reads during a reset. On some architectures |
| 463 | * this will result in an MCA. |
| 464 | */ |
| 465 | udelay(20); |
| 466 | for (cnt = 30000; cnt; cnt--) { |
| 467 | if ((RD_REG_WORD(®->ctrl_status) & |
| 468 | CSR_ISP_SOFT_RESET) == 0) |
| 469 | break; |
| 470 | udelay(100); |
| 471 | } |
| 472 | } else |
| 473 | udelay(10); |
| 474 | |
| 475 | /* Reset RISC processor. */ |
| 476 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 477 | |
| 478 | WRT_REG_WORD(®->semaphore, 0); |
| 479 | |
| 480 | /* Release RISC processor. */ |
| 481 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 482 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 483 | |
| 484 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 485 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 486 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
| 489 | udelay(100); |
| 490 | } |
| 491 | } else |
| 492 | udelay(100); |
| 493 | |
| 494 | /* Turn on master enable */ |
| 495 | cmd |= PCI_COMMAND_MASTER; |
| 496 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 497 | |
| 498 | /* Disable RISC pause on FPM parity error. */ |
| 499 | if (!IS_QLA2100(ha)) { |
| 500 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 501 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 502 | } |
| 503 | |
| 504 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 505 | } |
| 506 | |
| 507 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 508 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 509 | * @ha: HA context |
| 510 | * |
| 511 | * Returns 0 on success. |
| 512 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 513 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 514 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 515 | { |
| 516 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 517 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 518 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 519 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 520 | uint16_t wd; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 521 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 522 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 523 | |
| 524 | /* Reset RISC. */ |
| 525 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 526 | for (cnt = 0; cnt < 30000; cnt++) { |
| 527 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 528 | break; |
| 529 | |
| 530 | udelay(10); |
| 531 | } |
| 532 | |
| 533 | WRT_REG_DWORD(®->ctrl_status, |
| 534 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 535 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 536 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 537 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 538 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 539 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 540 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 541 | udelay(5); |
| 542 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 543 | barrier(); |
| 544 | } |
| 545 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 546 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 547 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 548 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 549 | udelay(5); |
| 550 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 551 | barrier(); |
| 552 | } |
| 553 | |
| 554 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 555 | RD_REG_DWORD(®->hccr); |
| 556 | |
| 557 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 558 | RD_REG_DWORD(®->hccr); |
| 559 | |
| 560 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 561 | RD_REG_DWORD(®->hccr); |
| 562 | |
| 563 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 564 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 565 | udelay(5); |
| 566 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 567 | barrier(); |
| 568 | } |
| 569 | |
| 570 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 571 | |
| 572 | if (IS_NOPOLLING_TYPE(ha)) |
| 573 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 574 | } |
| 575 | |
| 576 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 577 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 578 | * @ha: HA context |
| 579 | * |
| 580 | * Returns 0 on success. |
| 581 | */ |
| 582 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 583 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 584 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 585 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 586 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 587 | |
| 588 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 589 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 594 | * @ha: HA context |
| 595 | * |
| 596 | * Returns 0 on success. |
| 597 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 598 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 599 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | { |
| 601 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 602 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 603 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | unsigned long flags = 0; |
| 605 | uint16_t data; |
| 606 | uint32_t cnt; |
| 607 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 608 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | /* Assume a failed state */ |
| 611 | rval = QLA_FUNCTION_FAILED; |
| 612 | |
| 613 | DEBUG3(printk("scsi(%ld): Testing device at %lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 614 | vha->host_no, (u_long)®->flash_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | |
| 616 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 617 | |
| 618 | /* Reset ISP chip. */ |
| 619 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 620 | |
| 621 | /* |
| 622 | * We need to have a delay here since the card will not respond while |
| 623 | * in reset causing an MCA on some architectures. |
| 624 | */ |
| 625 | udelay(20); |
| 626 | data = qla2x00_debounce_register(®->ctrl_status); |
| 627 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 628 | udelay(5); |
| 629 | data = RD_REG_WORD(®->ctrl_status); |
| 630 | barrier(); |
| 631 | } |
| 632 | |
| 633 | if (!cnt) |
| 634 | goto chip_diag_failed; |
| 635 | |
| 636 | DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n", |
| 637 | ha->host_no)); |
| 638 | |
| 639 | /* Reset RISC processor. */ |
| 640 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 641 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 642 | |
| 643 | /* Workaround for QLA2312 PCI parity error */ |
| 644 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 645 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 646 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 647 | udelay(5); |
| 648 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 649 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | } |
| 651 | } else |
| 652 | udelay(10); |
| 653 | |
| 654 | if (!cnt) |
| 655 | goto chip_diag_failed; |
| 656 | |
| 657 | /* Check product ID of chip */ |
| 658 | DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", ha->host_no)); |
| 659 | |
| 660 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 661 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 662 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 663 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 664 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 665 | mb[3] != PROD_ID_3) { |
| 666 | qla_printk(KERN_WARNING, ha, |
| 667 | "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]); |
| 668 | |
| 669 | goto chip_diag_failed; |
| 670 | } |
| 671 | ha->product_id[0] = mb[1]; |
| 672 | ha->product_id[1] = mb[2]; |
| 673 | ha->product_id[2] = mb[3]; |
| 674 | ha->product_id[3] = mb[4]; |
| 675 | |
| 676 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 677 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 679 | else |
| 680 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 681 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
| 683 | if (IS_QLA2200(ha) && |
| 684 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 685 | /* Limit firmware transfer size with a 2200A */ |
| 686 | DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 687 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 688 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 689 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 690 | ha->fw_transfer_size = 128; |
| 691 | } |
| 692 | |
| 693 | /* Wrap Incoming Mailboxes Test. */ |
| 694 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 695 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 696 | DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no)); |
| 697 | rval = qla2x00_mbx_reg_test(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | if (rval) { |
| 699 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 700 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | qla_printk(KERN_WARNING, ha, |
| 702 | "Failed mailbox send register test\n"); |
| 703 | } |
| 704 | else { |
| 705 | /* Flag a successful rval */ |
| 706 | rval = QLA_SUCCESS; |
| 707 | } |
| 708 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 709 | |
| 710 | chip_diag_failed: |
| 711 | if (rval) |
| 712 | DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 713 | "****\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | |
| 715 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 716 | |
| 717 | return (rval); |
| 718 | } |
| 719 | |
| 720 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 721 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 722 | * @ha: HA context |
| 723 | * |
| 724 | * Returns 0 on success. |
| 725 | */ |
| 726 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 727 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 728 | { |
| 729 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 730 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 731 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 732 | |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 733 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 734 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 735 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 736 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 737 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 738 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 739 | if (rval) { |
| 740 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 741 | vha->host_no)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 742 | qla_printk(KERN_WARNING, ha, |
| 743 | "Failed mailbox send register test\n"); |
| 744 | } else { |
| 745 | /* Flag a successful rval */ |
| 746 | rval = QLA_SUCCESS; |
| 747 | } |
| 748 | |
| 749 | return rval; |
| 750 | } |
| 751 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 752 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 753 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 754 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 755 | int rval; |
| 756 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 757 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 758 | dma_addr_t tc_dma; |
| 759 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 760 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 761 | struct req_que *req = ha->req_q_map[0]; |
| 762 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 763 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 764 | if (ha->fw_dump) { |
| 765 | qla_printk(KERN_WARNING, ha, |
| 766 | "Firmware dump previously allocated.\n"); |
| 767 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 768 | } |
| 769 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 770 | ha->fw_dumped = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 771 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 772 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 773 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 774 | } else if (IS_QLA23XX(ha)) { |
| 775 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 776 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 777 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 778 | } else if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 779 | if (IS_QLA81XX(ha)) |
| 780 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 781 | else if (IS_QLA25XX(ha)) |
| 782 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 783 | else |
| 784 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 785 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 786 | sizeof(uint32_t); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 787 | if (ha->mqenable) |
| 788 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 789 | |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 790 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 791 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 792 | goto try_eft; |
| 793 | |
| 794 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 795 | GFP_KERNEL); |
| 796 | if (!tc) { |
| 797 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 798 | "(%d KB) for FCE.\n", FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 799 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 800 | } |
| 801 | |
| 802 | memset(tc, 0, FCE_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 803 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 804 | ha->fce_mb, &ha->fce_bufs); |
| 805 | if (rval) { |
| 806 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 807 | "FCE (%d).\n", rval); |
| 808 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 809 | tc_dma); |
| 810 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 811 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 812 | } |
| 813 | |
| 814 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n", |
| 815 | FCE_SIZE / 1024); |
| 816 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 817 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 818 | ha->flags.fce_enabled = 1; |
| 819 | ha->fce_dma = tc_dma; |
| 820 | ha->fce = tc; |
| 821 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 822 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 823 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 824 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 825 | if (!tc) { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 826 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 827 | "(%d KB) for EFT.\n", EFT_SIZE / 1024); |
| 828 | goto cont_alloc; |
| 829 | } |
| 830 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 831 | memset(tc, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 832 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 833 | if (rval) { |
| 834 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 835 | "EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 836 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 837 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 838 | goto cont_alloc; |
| 839 | } |
| 840 | |
| 841 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n", |
| 842 | EFT_SIZE / 1024); |
| 843 | |
| 844 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 845 | ha->eft_dma = tc_dma; |
| 846 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 847 | } |
| 848 | cont_alloc: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 849 | req_q_size = req->length * sizeof(request_t); |
| 850 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 851 | |
| 852 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
| 853 | dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + |
Andrew Vasquez | bb99de6 | 2009-01-05 11:18:08 -0800 | [diff] [blame] | 854 | eft_size; |
| 855 | ha->chain_offset = dump_size; |
| 856 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 857 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 858 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 859 | if (!ha->fw_dump) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 860 | qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for " |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 861 | "firmware dump!!!\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 862 | |
| 863 | if (ha->eft) { |
| 864 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 865 | ha->eft_dma); |
| 866 | ha->eft = NULL; |
| 867 | ha->eft_dma = 0; |
| 868 | } |
| 869 | return; |
| 870 | } |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 871 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n", |
| 872 | dump_size / 1024); |
| 873 | |
| 874 | ha->fw_dump_len = dump_size; |
| 875 | ha->fw_dump->signature[0] = 'Q'; |
| 876 | ha->fw_dump->signature[1] = 'L'; |
| 877 | ha->fw_dump->signature[2] = 'G'; |
| 878 | ha->fw_dump->signature[3] = 'C'; |
| 879 | ha->fw_dump->version = __constant_htonl(1); |
| 880 | |
| 881 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 882 | ha->fw_dump->mem_size = htonl(mem_size); |
| 883 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 884 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 885 | |
| 886 | ha->fw_dump->eft_size = htonl(eft_size); |
| 887 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 888 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 889 | |
| 890 | ha->fw_dump->header_size = |
| 891 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 892 | } |
| 893 | |
| 894 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 896 | * @ha: HA context |
| 897 | * |
| 898 | * Returns 0 on success. |
| 899 | */ |
| 900 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 901 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 903 | int rval; |
| 904 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 905 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 906 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 907 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 908 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 909 | |
| 910 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 911 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 912 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 913 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 914 | RD_REG_WORD(®->hccr); |
| 915 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 916 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | |
| 918 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 919 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 920 | if (rval == QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 922 | "code.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 924 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | if (rval == QLA_SUCCESS) { |
| 926 | /* Start firmware execution. */ |
| 927 | DEBUG(printk("scsi(%ld): Checksum OK, start " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 928 | "firmware.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 930 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 932 | if (rval == QLA_SUCCESS) { |
| 933 | fw_major_version = ha->fw_major_version; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 934 | qla2x00_get_fw_version(vha, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | &ha->fw_major_version, |
| 936 | &ha->fw_minor_version, |
| 937 | &ha->fw_subminor_version, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 938 | &ha->fw_attributes, &ha->fw_memory_size, |
Andrew Vasquez | 55a9615 | 2009-03-24 09:08:03 -0700 | [diff] [blame] | 939 | ha->mpi_version, &ha->mpi_capabilities, |
| 940 | ha->phy_version); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 941 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 942 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 943 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 944 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 945 | if ((!ha->max_npiv_vports) || |
| 946 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 947 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 948 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 949 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 950 | } |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame^] | 951 | qla2x00_get_resource_cnts(vha, NULL, NULL, |
| 952 | NULL, NULL, &ha->max_npiv_vports); |
| 953 | |
| 954 | if (!fw_major_version && ql2xallocfwdump) |
| 955 | qla2x00_alloc_fw_dump(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | } |
| 957 | } else { |
| 958 | DEBUG2(printk(KERN_INFO |
| 959 | "scsi(%ld): ISP Firmware failed checksum.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 960 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | } |
| 963 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 964 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 965 | /* Enable proper parity. */ |
| 966 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 967 | if (IS_QLA2300(ha)) |
| 968 | /* SRAM parity */ |
| 969 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 970 | else |
| 971 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 972 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 973 | RD_REG_WORD(®->hccr); |
| 974 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 975 | } |
| 976 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 977 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
| 978 | uint32_t size; |
| 979 | |
| 980 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 981 | if (rval == QLA_SUCCESS) { |
| 982 | ha->flags.fac_supported = 1; |
| 983 | ha->fdt_block_size = size << 2; |
| 984 | } else { |
| 985 | qla_printk(KERN_ERR, ha, |
| 986 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 987 | ha->fw_major_version, ha->fw_minor_version, |
| 988 | ha->fw_subminor_version); |
| 989 | } |
| 990 | } |
| 991 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 992 | if (rval) { |
| 993 | DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 994 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | return (rval); |
| 998 | } |
| 999 | |
| 1000 | /** |
| 1001 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1002 | * @ha: HA context |
| 1003 | * |
| 1004 | * Beginning of request ring has initialization control block already built |
| 1005 | * by nvram config routine. |
| 1006 | * |
| 1007 | * Returns 0 on success. |
| 1008 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1009 | void |
| 1010 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1011 | { |
| 1012 | uint16_t cnt; |
| 1013 | response_t *pkt; |
| 1014 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1015 | pkt = rsp->ring_ptr; |
| 1016 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1017 | pkt->signature = RESPONSE_PROCESSED; |
| 1018 | pkt++; |
| 1019 | } |
| 1020 | |
| 1021 | } |
| 1022 | |
| 1023 | /** |
| 1024 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1025 | * @ha: HA context |
| 1026 | * |
| 1027 | * Returns 0 on success. |
| 1028 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1029 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1030 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1031 | { |
| 1032 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1033 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1034 | |
| 1035 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1036 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | |
| 1038 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1039 | return; |
| 1040 | |
| 1041 | /* Serial Link options. */ |
| 1042 | DEBUG3(printk("scsi(%ld): Serial link options:\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1043 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options, |
| 1045 | sizeof(ha->fw_seriallink_options))); |
| 1046 | |
| 1047 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1048 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1049 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1050 | |
| 1051 | /* 1G settings */ |
| 1052 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1053 | emphasis = (ha->fw_seriallink_options[2] & |
| 1054 | (BIT_4 | BIT_3)) >> 3; |
| 1055 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1056 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1057 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1058 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1059 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1060 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1061 | if (rx_sens == 0x0) |
| 1062 | rx_sens = 0x3; |
| 1063 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1064 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1065 | ha->fw_options[10] |= BIT_5 | |
| 1066 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1067 | (tx_sens & (BIT_1 | BIT_0)); |
| 1068 | |
| 1069 | /* 2G settings */ |
| 1070 | swing = (ha->fw_seriallink_options[2] & |
| 1071 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1072 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1073 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1074 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1076 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1077 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1078 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1079 | if (rx_sens == 0x0) |
| 1080 | rx_sens = 0x3; |
| 1081 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1082 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1083 | ha->fw_options[11] |= BIT_5 | |
| 1084 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1085 | (tx_sens & (BIT_1 | BIT_0)); |
| 1086 | } |
| 1087 | |
| 1088 | /* FCP2 options. */ |
| 1089 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1090 | ha->fw_options[3] |= BIT_13; |
| 1091 | |
| 1092 | /* LED scheme. */ |
| 1093 | if (ha->flags.enable_led_scheme) |
| 1094 | ha->fw_options[2] |= BIT_12; |
| 1095 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1096 | /* Detect ISP6312. */ |
| 1097 | if (IS_QLA6312(ha)) |
| 1098 | ha->fw_options[2] |= BIT_13; |
| 1099 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1100 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1101 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1104 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1105 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1106 | { |
| 1107 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1108 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1109 | |
| 1110 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1111 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1112 | return; |
| 1113 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1114 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1115 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1116 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1117 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1118 | if (rval != QLA_SUCCESS) { |
| 1119 | qla_printk(KERN_WARNING, ha, |
| 1120 | "Unable to update Serial Link options (%x).\n", rval); |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1125 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1126 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1127 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1128 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1129 | struct req_que *req = ha->req_q_map[0]; |
| 1130 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1131 | |
| 1132 | /* Setup ring parameters in initialization control block. */ |
| 1133 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1134 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1135 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 1136 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 1137 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1138 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1139 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1140 | ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1141 | |
| 1142 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1143 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1144 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1145 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1146 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1147 | } |
| 1148 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1149 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1150 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1151 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1152 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1153 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
| 1154 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1155 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1156 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1157 | uint16_t rid = 0; |
| 1158 | struct req_que *req = ha->req_q_map[0]; |
| 1159 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1160 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1161 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1162 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1163 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1164 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1165 | icb->request_q_length = cpu_to_le16(req->length); |
| 1166 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 1167 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1168 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1169 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1170 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1171 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1172 | if (ha->mqenable) { |
| 1173 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 1174 | icb->rid = __constant_cpu_to_le16(rid); |
| 1175 | if (ha->flags.msix_enabled) { |
| 1176 | msix = &ha->msix_entries[1]; |
| 1177 | DEBUG2_17(printk(KERN_INFO |
| 1178 | "Reistering vector 0x%x for base que\n", msix->entry)); |
| 1179 | icb->msix = cpu_to_le16(msix->entry); |
| 1180 | } |
| 1181 | /* Use alternate PCI bus number */ |
| 1182 | if (MSB(rid)) |
| 1183 | icb->firmware_options_2 |= |
| 1184 | __constant_cpu_to_le32(BIT_19); |
| 1185 | /* Use alternate PCI devfn */ |
| 1186 | if (LSB(rid)) |
| 1187 | icb->firmware_options_2 |= |
| 1188 | __constant_cpu_to_le32(BIT_18); |
| 1189 | |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 1190 | icb->firmware_options_2 &= __constant_cpu_to_le32(~BIT_22); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1191 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1192 | |
| 1193 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 1194 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 1195 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 1196 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 1197 | } else { |
| 1198 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 1199 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 1200 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 1201 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 1202 | } |
| 1203 | /* PCI posting */ |
| 1204 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1205 | } |
| 1206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | /** |
| 1208 | * qla2x00_init_rings() - Initializes firmware. |
| 1209 | * @ha: HA context |
| 1210 | * |
| 1211 | * Beginning of request ring has initialization control block already built |
| 1212 | * by nvram config routine. |
| 1213 | * |
| 1214 | * Returns 0 on success. |
| 1215 | */ |
| 1216 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1217 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | { |
| 1219 | int rval; |
| 1220 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1221 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1222 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1223 | struct req_que *req; |
| 1224 | struct rsp_que *rsp; |
| 1225 | struct scsi_qla_host *vp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1226 | struct mid_init_cb_24xx *mid_init_cb = |
| 1227 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | |
| 1229 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1230 | |
| 1231 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1232 | for (que = 0; que < ha->max_queues; que++) { |
| 1233 | req = ha->req_q_map[que]; |
| 1234 | if (!req) |
| 1235 | continue; |
| 1236 | for (cnt = 0; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
| 1237 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1239 | req->current_outstanding_cmd = 0; |
| 1240 | |
| 1241 | /* Initialize firmware. */ |
| 1242 | req->ring_ptr = req->ring; |
| 1243 | req->ring_index = 0; |
| 1244 | req->cnt = req->length; |
| 1245 | } |
| 1246 | |
| 1247 | for (que = 0; que < ha->max_queues; que++) { |
| 1248 | rsp = ha->rsp_q_map[que]; |
| 1249 | if (!rsp) |
| 1250 | continue; |
| 1251 | rsp->ring_ptr = rsp->ring; |
| 1252 | rsp->ring_index = 0; |
| 1253 | |
| 1254 | /* Initialize response queue entries */ |
| 1255 | qla2x00_init_response_q_entries(rsp); |
| 1256 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
| 1258 | /* Clear RSCN queue. */ |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1259 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 1260 | vp->rscn_in_ptr = 0; |
| 1261 | vp->rscn_out_ptr = 0; |
| 1262 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1263 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1264 | |
| 1265 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1266 | |
| 1267 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1268 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1269 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1270 | DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1271 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1272 | if (ha->flags.npiv_supported) { |
| 1273 | if (ha->operating_mode == LOOP) |
| 1274 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1275 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1276 | } |
| 1277 | |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1278 | |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1279 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1280 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1281 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | if (rval) { |
| 1283 | DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1284 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | } else { |
| 1286 | DEBUG3(printk("scsi(%ld): Init firmware -- success.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1287 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1288 | } |
| 1289 | |
| 1290 | return (rval); |
| 1291 | } |
| 1292 | |
| 1293 | /** |
| 1294 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 1295 | * @ha: HA context |
| 1296 | * |
| 1297 | * Returns 0 on success. |
| 1298 | */ |
| 1299 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1300 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1301 | { |
| 1302 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1303 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 1305 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1306 | uint16_t state[3]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1307 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1308 | |
| 1309 | rval = QLA_SUCCESS; |
| 1310 | |
| 1311 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1312 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | |
| 1314 | /* |
| 1315 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 1316 | * our own processing. |
| 1317 | */ |
| 1318 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 1319 | wait_time = min_wait; |
| 1320 | } |
| 1321 | |
| 1322 | /* Min wait time if loop down */ |
| 1323 | mtime = jiffies + (min_wait * HZ); |
| 1324 | |
| 1325 | /* wait time before firmware ready */ |
| 1326 | wtime = jiffies + (wait_time * HZ); |
| 1327 | |
| 1328 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1329 | if (!vha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1330 | qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n"); |
| 1331 | |
| 1332 | DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1333 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | |
| 1335 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1336 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1338 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1339 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1341 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
| 1342 | DEBUG16(printk("scsi(%ld): fw_state=%x " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1343 | "84xx=%x.\n", vha->host_no, state[0], |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1344 | state[2])); |
| 1345 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 1346 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
| 1347 | DEBUG16(printk("scsi(%ld): Sending " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1348 | "verify iocb.\n", vha->host_no)); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1349 | |
| 1350 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1351 | rval = qla84xx_init_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1352 | if (rval != QLA_SUCCESS) |
| 1353 | break; |
| 1354 | |
| 1355 | /* Add time taken to initialize. */ |
| 1356 | cs84xx_time = jiffies - cs84xx_time; |
| 1357 | wtime += cs84xx_time; |
| 1358 | mtime += cs84xx_time; |
| 1359 | DEBUG16(printk("scsi(%ld): Increasing " |
| 1360 | "wait time by %ld. New time %ld\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1361 | vha->host_no, cs84xx_time, wtime)); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1362 | } |
| 1363 | } else if (state[0] == FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | DEBUG(printk("scsi(%ld): F/W Ready - OK \n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1365 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1367 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1368 | &ha->login_timeout, &ha->r_a_tov); |
| 1369 | |
| 1370 | rval = QLA_SUCCESS; |
| 1371 | break; |
| 1372 | } |
| 1373 | |
| 1374 | rval = QLA_FUNCTION_FAILED; |
| 1375 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1376 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1377 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1379 | * other than Wait for Login. |
| 1380 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | if (time_after_eq(jiffies, mtime)) { |
| 1382 | qla_printk(KERN_INFO, ha, |
| 1383 | "Cable is unplugged...\n"); |
| 1384 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1385 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | break; |
| 1387 | } |
| 1388 | } |
| 1389 | } else { |
| 1390 | /* Mailbox cmd failed. Timeout on min_wait. */ |
| 1391 | if (time_after_eq(jiffies, mtime)) |
| 1392 | break; |
| 1393 | } |
| 1394 | |
| 1395 | if (time_after_eq(jiffies, wtime)) |
| 1396 | break; |
| 1397 | |
| 1398 | /* Delay for a while */ |
| 1399 | msleep(500); |
| 1400 | |
| 1401 | DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1402 | vha->host_no, state[0], jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | } while (1); |
| 1404 | |
| 1405 | DEBUG(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1406 | vha->host_no, state[0], jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
| 1408 | if (rval) { |
| 1409 | DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1410 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | return (rval); |
| 1414 | } |
| 1415 | |
| 1416 | /* |
| 1417 | * qla2x00_configure_hba |
| 1418 | * Setup adapter context. |
| 1419 | * |
| 1420 | * Input: |
| 1421 | * ha = adapter state pointer. |
| 1422 | * |
| 1423 | * Returns: |
| 1424 | * 0 = success |
| 1425 | * |
| 1426 | * Context: |
| 1427 | * Kernel context. |
| 1428 | */ |
| 1429 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1430 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | { |
| 1432 | int rval; |
| 1433 | uint16_t loop_id; |
| 1434 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1435 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | uint8_t al_pa; |
| 1437 | uint8_t area; |
| 1438 | uint8_t domain; |
| 1439 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1440 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | |
| 1442 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1443 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1444 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1446 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 1447 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
| 1448 | DEBUG2(printk("%s(%ld) Loop is in a transition state\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1449 | __func__, vha->host_no)); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 1450 | } else { |
| 1451 | qla_printk(KERN_WARNING, ha, |
| 1452 | "ERROR -- Unable to get host loop ID.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1453 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 1454 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | return (rval); |
| 1456 | } |
| 1457 | |
| 1458 | if (topo == 4) { |
| 1459 | qla_printk(KERN_INFO, ha, |
| 1460 | "Cannot get topology - retrying.\n"); |
| 1461 | return (QLA_FUNCTION_FAILED); |
| 1462 | } |
| 1463 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1464 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | |
| 1466 | /* initialize */ |
| 1467 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 1468 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1469 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1470 | |
| 1471 | switch (topo) { |
| 1472 | case 0: |
| 1473 | DEBUG3(printk("scsi(%ld): HBA in NL topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1474 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1475 | ha->current_topology = ISP_CFG_NL; |
| 1476 | strcpy(connect_type, "(Loop)"); |
| 1477 | break; |
| 1478 | |
| 1479 | case 1: |
| 1480 | DEBUG3(printk("scsi(%ld): HBA in FL topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1481 | vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1482 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | ha->current_topology = ISP_CFG_FL; |
| 1484 | strcpy(connect_type, "(FL_Port)"); |
| 1485 | break; |
| 1486 | |
| 1487 | case 2: |
| 1488 | DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1489 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | ha->operating_mode = P2P; |
| 1491 | ha->current_topology = ISP_CFG_N; |
| 1492 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 1493 | break; |
| 1494 | |
| 1495 | case 3: |
| 1496 | DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1497 | vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1498 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1499 | ha->operating_mode = P2P; |
| 1500 | ha->current_topology = ISP_CFG_F; |
| 1501 | strcpy(connect_type, "(F_Port)"); |
| 1502 | break; |
| 1503 | |
| 1504 | default: |
| 1505 | DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. " |
| 1506 | "Using NL.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1507 | vha->host_no, topo)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1508 | ha->current_topology = ISP_CFG_NL; |
| 1509 | strcpy(connect_type, "(Loop)"); |
| 1510 | break; |
| 1511 | } |
| 1512 | |
| 1513 | /* Save Host port and loop ID. */ |
| 1514 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1515 | vha->d_id.b.domain = domain; |
| 1516 | vha->d_id.b.area = area; |
| 1517 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1519 | if (!vha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | qla_printk(KERN_INFO, ha, |
| 1521 | "Topology - %s, Host Loop address 0x%x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1522 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
| 1524 | if (rval) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1525 | DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1527 | DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | return(rval); |
| 1531 | } |
| 1532 | |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1533 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1534 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 1535 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1536 | { |
| 1537 | char *st, *en; |
| 1538 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1539 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1540 | |
| 1541 | if (memcmp(model, BINZERO, len) != 0) { |
| 1542 | strncpy(ha->model_number, model, len); |
| 1543 | st = en = ha->model_number; |
| 1544 | en += len - 1; |
| 1545 | while (en > st) { |
| 1546 | if (*en != 0x20 && *en != 0x00) |
| 1547 | break; |
| 1548 | *en-- = '\0'; |
| 1549 | } |
| 1550 | |
| 1551 | index = (ha->pdev->subsystem_device & 0xff); |
| 1552 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
| 1553 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 1554 | strncpy(ha->model_desc, |
| 1555 | qla2x00_model_name[index * 2 + 1], |
| 1556 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1557 | } else { |
| 1558 | index = (ha->pdev->subsystem_device & 0xff); |
| 1559 | if (ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
| 1560 | index < QLA_MODEL_NAMES) { |
| 1561 | strcpy(ha->model_number, |
| 1562 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 1563 | strncpy(ha->model_desc, |
| 1564 | qla2x00_model_name[index * 2 + 1], |
| 1565 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1566 | } else { |
| 1567 | strcpy(ha->model_number, def); |
| 1568 | } |
| 1569 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 1570 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1571 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 1572 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1573 | } |
| 1574 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1575 | /* On sparc systems, obtain port and node WWN from firmware |
| 1576 | * properties. |
| 1577 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1578 | static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1579 | { |
| 1580 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1581 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1582 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 1583 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 1584 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1585 | int len; |
| 1586 | |
| 1587 | val = of_get_property(dp, "port-wwn", &len); |
| 1588 | if (val && len >= WWN_SIZE) |
| 1589 | memcpy(nv->port_name, val, WWN_SIZE); |
| 1590 | |
| 1591 | val = of_get_property(dp, "node-wwn", &len); |
| 1592 | if (val && len >= WWN_SIZE) |
| 1593 | memcpy(nv->node_name, val, WWN_SIZE); |
| 1594 | #endif |
| 1595 | } |
| 1596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | /* |
| 1598 | * NVRAM configuration for ISP 2xxx |
| 1599 | * |
| 1600 | * Input: |
| 1601 | * ha = adapter block pointer. |
| 1602 | * |
| 1603 | * Output: |
| 1604 | * initialization control block in response_ring |
| 1605 | * host adapters parameters in host adapter block |
| 1606 | * |
| 1607 | * Returns: |
| 1608 | * 0 = success. |
| 1609 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1610 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1611 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1612 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1613 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1614 | uint8_t chksum = 0; |
| 1615 | uint16_t cnt; |
| 1616 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1617 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1618 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 1619 | nvram_t *nv = ha->nvram; |
| 1620 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1621 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1623 | rval = QLA_SUCCESS; |
| 1624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1626 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1627 | ha->nvram_base = 0; |
| 1628 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 1629 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 1630 | ha->nvram_base = 0x80; |
| 1631 | |
| 1632 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1633 | ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1634 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 1635 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1637 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 1638 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | |
| 1640 | /* Bad NVRAM data, set defaults parameters. */ |
| 1641 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 1642 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 1643 | /* Reset NVRAM data. */ |
| 1644 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 1645 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 1646 | nv->nvram_version); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1647 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 1648 | "invalid -- WWPN) defaults.\n"); |
| 1649 | |
| 1650 | /* |
| 1651 | * Set default initialization control block. |
| 1652 | */ |
| 1653 | memset(nv, 0, ha->nvram_size); |
| 1654 | nv->parameter_block_version = ICB_VERSION; |
| 1655 | |
| 1656 | if (IS_QLA23XX(ha)) { |
| 1657 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 1658 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 1659 | nv->add_firmware_options[0] = BIT_5; |
| 1660 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 1661 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 1662 | nv->special_options[1] = BIT_7; |
| 1663 | } else if (IS_QLA2200(ha)) { |
| 1664 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 1665 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 1666 | nv->add_firmware_options[0] = BIT_5; |
| 1667 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 1668 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 1669 | } else if (IS_QLA2100(ha)) { |
| 1670 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 1671 | nv->firmware_options[1] = BIT_5; |
| 1672 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 1673 | } |
| 1674 | |
| 1675 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 1676 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 1677 | nv->retry_count = 8; |
| 1678 | nv->retry_delay = 1; |
| 1679 | |
| 1680 | nv->port_name[0] = 33; |
| 1681 | nv->port_name[3] = 224; |
| 1682 | nv->port_name[4] = 139; |
| 1683 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1684 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1685 | |
| 1686 | nv->login_timeout = 4; |
| 1687 | |
| 1688 | /* |
| 1689 | * Set default host adapter parameters |
| 1690 | */ |
| 1691 | nv->host_p[1] = BIT_2; |
| 1692 | nv->reset_delay = 5; |
| 1693 | nv->port_down_retry_count = 8; |
| 1694 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 1695 | nv->link_down_timeout = 60; |
| 1696 | |
| 1697 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | } |
| 1699 | |
| 1700 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 1701 | /* |
| 1702 | * The SN2 does not provide BIOS emulation which means you can't change |
| 1703 | * potentially bogus BIOS settings. Force the use of default settings |
| 1704 | * for link rate and frame size. Hope that the rest of the settings |
| 1705 | * are valid. |
| 1706 | */ |
| 1707 | if (ia64_platform_is("sn2")) { |
| 1708 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 1709 | if (IS_QLA23XX(ha)) |
| 1710 | nv->special_options[1] = BIT_7; |
| 1711 | } |
| 1712 | #endif |
| 1713 | |
| 1714 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1715 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | |
| 1717 | /* |
| 1718 | * Setup driver NVRAM options. |
| 1719 | */ |
| 1720 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 1721 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 1722 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 1723 | nv->firmware_options[1] &= ~BIT_4; |
| 1724 | |
| 1725 | if (IS_QLA23XX(ha)) { |
| 1726 | nv->firmware_options[0] |= BIT_2; |
| 1727 | nv->firmware_options[0] &= ~BIT_3; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1728 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1729 | |
| 1730 | if (IS_QLA2300(ha)) { |
| 1731 | if (ha->fb_rev == FPM_2310) { |
| 1732 | strcpy(ha->model_number, "QLA2310"); |
| 1733 | } else { |
| 1734 | strcpy(ha->model_number, "QLA2300"); |
| 1735 | } |
| 1736 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1737 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 1738 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1739 | } |
| 1740 | } else if (IS_QLA2200(ha)) { |
| 1741 | nv->firmware_options[0] |= BIT_2; |
| 1742 | /* |
| 1743 | * 'Point-to-point preferred, else loop' is not a safe |
| 1744 | * connection mode setting. |
| 1745 | */ |
| 1746 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 1747 | (BIT_5 | BIT_4)) { |
| 1748 | /* Force 'loop preferred, else point-to-point'. */ |
| 1749 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 1750 | nv->add_firmware_options[0] |= BIT_5; |
| 1751 | } |
| 1752 | strcpy(ha->model_number, "QLA22xx"); |
| 1753 | } else /*if (IS_QLA2100(ha))*/ { |
| 1754 | strcpy(ha->model_number, "QLA2100"); |
| 1755 | } |
| 1756 | |
| 1757 | /* |
| 1758 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 1759 | */ |
| 1760 | dptr1 = (uint8_t *)icb; |
| 1761 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 1762 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 1763 | while (cnt--) |
| 1764 | *dptr1++ = *dptr2++; |
| 1765 | |
| 1766 | /* Copy 2nd half. */ |
| 1767 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 1768 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 1769 | while (cnt--) |
| 1770 | *dptr1++ = *dptr2++; |
| 1771 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 1772 | /* Use alternate WWN? */ |
| 1773 | if (nv->host_p[1] & BIT_7) { |
| 1774 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 1775 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 1776 | } |
| 1777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1778 | /* Prepare nodename */ |
| 1779 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 1780 | /* |
| 1781 | * Firmware will apply the following mask if the nodename was |
| 1782 | * not provided. |
| 1783 | */ |
| 1784 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 1785 | icb->node_name[0] &= 0xF0; |
| 1786 | } |
| 1787 | |
| 1788 | /* |
| 1789 | * Set host adapter parameters. |
| 1790 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 1791 | if (nv->host_p[0] & BIT_7) |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 1792 | ql2xextended_error_logging = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1793 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 1794 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 1795 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 1796 | ha->flags.disable_risc_code_load = 0; |
| 1797 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 1798 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 1799 | ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0); |
Andrew Vasquez | 06c22bd | 2005-08-26 19:09:00 -0700 | [diff] [blame] | 1800 | ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 1801 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | |
| 1803 | ha->operating_mode = |
| 1804 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1805 | |
| 1806 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 1807 | sizeof(ha->fw_seriallink_options)); |
| 1808 | |
| 1809 | /* save HBA serial number */ |
| 1810 | ha->serial0 = icb->port_name[5]; |
| 1811 | ha->serial1 = icb->port_name[6]; |
| 1812 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1813 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 1814 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1815 | |
| 1816 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 1817 | |
| 1818 | ha->retry_count = nv->retry_count; |
| 1819 | |
| 1820 | /* Set minimum login_timeout to 4 seconds. */ |
| 1821 | if (nv->login_timeout < ql2xlogintimeout) |
| 1822 | nv->login_timeout = ql2xlogintimeout; |
| 1823 | if (nv->login_timeout < 4) |
| 1824 | nv->login_timeout = 4; |
| 1825 | ha->login_timeout = nv->login_timeout; |
| 1826 | icb->login_timeout = nv->login_timeout; |
| 1827 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 1828 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 1829 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | ha->loop_reset_delay = nv->reset_delay; |
| 1832 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1833 | /* Link Down Timeout = 0: |
| 1834 | * |
| 1835 | * When Port Down timer expires we will start returning |
| 1836 | * I/O's to OS with "DID_NO_CONNECT". |
| 1837 | * |
| 1838 | * Link Down Timeout != 0: |
| 1839 | * |
| 1840 | * The driver waits for the link to come up after link down |
| 1841 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1842 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | if (nv->link_down_timeout == 0) { |
| 1844 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 1845 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | } else { |
| 1847 | ha->link_down_timeout = nv->link_down_timeout; |
| 1848 | ha->loop_down_abort_time = |
| 1849 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1850 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | /* |
| 1853 | * Need enough time to try and get the port back. |
| 1854 | */ |
| 1855 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 1856 | if (qlport_down_retry) |
| 1857 | ha->port_down_retry_count = qlport_down_retry; |
| 1858 | /* Set login_retry_count */ |
| 1859 | ha->login_retry_count = nv->retry_count; |
| 1860 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 1861 | ha->port_down_retry_count > 3) |
| 1862 | ha->login_retry_count = ha->port_down_retry_count; |
| 1863 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 1864 | ha->login_retry_count = ha->port_down_retry_count; |
| 1865 | if (ql2xloginretrycount) |
| 1866 | ha->login_retry_count = ql2xloginretrycount; |
| 1867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 1869 | icb->command_resource_count = 0; |
| 1870 | icb->immediate_notify_resource_count = 0; |
| 1871 | icb->timeout = __constant_cpu_to_le16(0); |
| 1872 | |
| 1873 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1874 | /* Enable RIO */ |
| 1875 | icb->firmware_options[0] &= ~BIT_3; |
| 1876 | icb->add_firmware_options[0] &= |
| 1877 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 1878 | icb->add_firmware_options[0] |= BIT_2; |
| 1879 | icb->response_accumulation_timer = 3; |
| 1880 | icb->interrupt_delay_timer = 5; |
| 1881 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1882 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1883 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1884 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1885 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1886 | ha->zio_mode = icb->add_firmware_options[0] & |
| 1887 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 1888 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 1889 | icb->interrupt_delay_timer: 2; |
| 1890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | icb->add_firmware_options[0] &= |
| 1892 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1893 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1894 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 1895 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 1896 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1897 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1898 | "delay (%d us).\n", vha->host_no, ha->zio_mode, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1899 | ha->zio_timer * 100)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1901 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 1902 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1903 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1904 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 1905 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1906 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | } |
| 1908 | } |
| 1909 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1910 | if (rval) { |
| 1911 | DEBUG2_3(printk(KERN_WARNING |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1912 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 1913 | } |
| 1914 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | } |
| 1916 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1917 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1918 | qla2x00_rport_del(void *data) |
| 1919 | { |
| 1920 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1921 | struct fc_rport *rport; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1922 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1923 | spin_lock_irq(fcport->vha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1924 | rport = fcport->drport; |
| 1925 | fcport->drport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1926 | spin_unlock_irq(fcport->vha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 1927 | if (rport) |
| 1928 | fc_remote_port_delete(rport); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 1929 | } |
| 1930 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | /** |
| 1932 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 1933 | * @ha: HA context |
| 1934 | * @flags: allocation flags |
| 1935 | * |
| 1936 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 1937 | */ |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 1938 | static fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1939 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1940 | { |
| 1941 | fc_port_t *fcport; |
| 1942 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1943 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 1944 | if (!fcport) |
| 1945 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | |
| 1947 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1948 | fcport->vha = vha; |
| 1949 | fcport->vp_idx = vha->vp_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | fcport->port_type = FCT_UNKNOWN; |
| 1951 | fcport->loop_id = FC_NO_LOOP_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | atomic_set(&fcport->state, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 1953 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 1955 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | } |
| 1957 | |
| 1958 | /* |
| 1959 | * qla2x00_configure_loop |
| 1960 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 1961 | * |
| 1962 | * Input: |
| 1963 | * ha = adapter block pointer. |
| 1964 | * |
| 1965 | * Returns: |
| 1966 | * 0 = success. |
| 1967 | * 1 = error. |
| 1968 | * 2 = database was full and device was not configured. |
| 1969 | */ |
| 1970 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1971 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | { |
| 1973 | int rval; |
| 1974 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1975 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1976 | rval = QLA_SUCCESS; |
| 1977 | |
| 1978 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1979 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 1980 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1981 | if (rval != QLA_SUCCESS) { |
| 1982 | DEBUG(printk("scsi(%ld): Unable to configure HBA.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1983 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | return (rval); |
| 1985 | } |
| 1986 | } |
| 1987 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1988 | save_flags = flags = vha->dpc_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1989 | DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1990 | vha->host_no, flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | |
| 1992 | /* |
| 1993 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 1994 | * both at the same time. |
| 1995 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1996 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 1997 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | |
| 1999 | /* Determine what we need to do */ |
| 2000 | if (ha->current_topology == ISP_CFG_FL && |
| 2001 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2002 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2003 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2004 | set_bit(RSCN_UPDATE, &flags); |
| 2005 | |
| 2006 | } else if (ha->current_topology == ISP_CFG_F && |
| 2007 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2008 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2009 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | set_bit(RSCN_UPDATE, &flags); |
| 2011 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2012 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2013 | } else if (ha->current_topology == ISP_CFG_N) { |
| 2014 | clear_bit(RSCN_UPDATE, &flags); |
| 2015 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2016 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2017 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 2018 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2019 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2020 | set_bit(RSCN_UPDATE, &flags); |
| 2021 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2022 | } |
| 2023 | |
| 2024 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2025 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | rval = QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2027 | else |
| 2028 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | } |
| 2030 | |
| 2031 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2032 | if (LOOP_TRANSITION(vha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | rval = QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2034 | else |
| 2035 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | } |
| 2037 | |
| 2038 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2039 | if (atomic_read(&vha->loop_down_timer) || |
| 2040 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2041 | rval = QLA_FUNCTION_FAILED; |
| 2042 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2043 | atomic_set(&vha->loop_state, LOOP_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2045 | DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | } |
| 2047 | } |
| 2048 | |
| 2049 | if (rval) { |
| 2050 | DEBUG2_3(printk("%s(%ld): *** FAILED ***\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2051 | __func__, vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2052 | } else { |
| 2053 | DEBUG3(printk("%s: exiting normally\n", __func__)); |
| 2054 | } |
| 2055 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2056 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2057 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2058 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2059 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 2060 | if (test_bit(RSCN_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2061 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2062 | } |
| 2063 | |
| 2064 | return (rval); |
| 2065 | } |
| 2066 | |
| 2067 | |
| 2068 | |
| 2069 | /* |
| 2070 | * qla2x00_configure_local_loop |
| 2071 | * Updates Fibre Channel Device Database with local loop devices. |
| 2072 | * |
| 2073 | * Input: |
| 2074 | * ha = adapter block pointer. |
| 2075 | * |
| 2076 | * Returns: |
| 2077 | * 0 = success. |
| 2078 | */ |
| 2079 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2080 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | { |
| 2082 | int rval, rval2; |
| 2083 | int found_devs; |
| 2084 | int found; |
| 2085 | fc_port_t *fcport, *new_fcport; |
| 2086 | |
| 2087 | uint16_t index; |
| 2088 | uint16_t entries; |
| 2089 | char *id_iter; |
| 2090 | uint16_t loop_id; |
| 2091 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2092 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | |
| 2094 | found_devs = 0; |
| 2095 | new_fcport = NULL; |
| 2096 | entries = MAX_FIBRE_DEVICES; |
| 2097 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2098 | DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no)); |
| 2099 | DEBUG3(qla2x00_get_fcal_position_map(vha, NULL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | |
| 2101 | /* Get list of logged in devices. */ |
| 2102 | memset(ha->gid_list, 0, GID_LIST_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2103 | rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | &entries); |
| 2105 | if (rval != QLA_SUCCESS) |
| 2106 | goto cleanup_allocation; |
| 2107 | |
| 2108 | DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n", |
| 2109 | ha->host_no, entries)); |
| 2110 | DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list, |
| 2111 | entries * sizeof(struct gid_list_info))); |
| 2112 | |
| 2113 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2114 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | if (new_fcport == NULL) { |
| 2116 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2117 | goto cleanup_allocation; |
| 2118 | } |
| 2119 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2120 | |
| 2121 | /* |
| 2122 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2123 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2124 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2126 | fcport->port_type != FCT_BROADCAST && |
| 2127 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2128 | |
| 2129 | DEBUG(printk("scsi(%ld): Marking port lost, " |
| 2130 | "loop_id=0x%04x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2131 | vha->host_no, fcport->loop_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | |
| 2133 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | } |
| 2135 | } |
| 2136 | |
| 2137 | /* Add devices to port list. */ |
| 2138 | id_iter = (char *)ha->gid_list; |
| 2139 | for (index = 0; index < entries; index++) { |
| 2140 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2141 | area = ((struct gid_list_info *)id_iter)->area; |
| 2142 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2143 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | loop_id = (uint16_t) |
| 2145 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2146 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2147 | loop_id = le16_to_cpu( |
| 2148 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2149 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2150 | |
| 2151 | /* Bypass reserved domain fields. */ |
| 2152 | if ((domain & 0xf0) == 0xf0) |
| 2153 | continue; |
| 2154 | |
| 2155 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2156 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2157 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2158 | continue; |
| 2159 | |
| 2160 | /* Bypass invalid local loop ID. */ |
| 2161 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2162 | continue; |
| 2163 | |
| 2164 | /* Fill in member data. */ |
| 2165 | new_fcport->d_id.b.domain = domain; |
| 2166 | new_fcport->d_id.b.area = area; |
| 2167 | new_fcport->d_id.b.al_pa = al_pa; |
| 2168 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2169 | new_fcport->vp_idx = vha->vp_idx; |
| 2170 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2171 | if (rval2 != QLA_SUCCESS) { |
| 2172 | DEBUG2(printk("scsi(%ld): Failed to retrieve fcport " |
| 2173 | "information -- get_port_database=%x, " |
| 2174 | "loop_id=0x%04x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2175 | vha->host_no, rval2, new_fcport->loop_id)); |
andrew.vasquez@qlogic.com | c9d02ac | 2006-01-13 17:05:26 -0800 | [diff] [blame] | 2176 | DEBUG2(printk("scsi(%ld): Scheduling resync...\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2177 | vha->host_no)); |
| 2178 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2179 | continue; |
| 2180 | } |
| 2181 | |
| 2182 | /* Check for matching device in port list. */ |
| 2183 | found = 0; |
| 2184 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2185 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2187 | WWN_SIZE)) |
| 2188 | continue; |
| 2189 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 2190 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2191 | fcport->loop_id = new_fcport->loop_id; |
| 2192 | fcport->port_type = new_fcport->port_type; |
| 2193 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2194 | memcpy(fcport->node_name, new_fcport->node_name, |
| 2195 | WWN_SIZE); |
| 2196 | |
| 2197 | found++; |
| 2198 | break; |
| 2199 | } |
| 2200 | |
| 2201 | if (!found) { |
| 2202 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2203 | if (vha->vp_idx) { |
| 2204 | new_fcport->vha = vha; |
| 2205 | new_fcport->vp_idx = vha->vp_idx; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2206 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2207 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2208 | |
| 2209 | /* Allocate a new replacement fcport. */ |
| 2210 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2211 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | if (new_fcport == NULL) { |
| 2213 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2214 | goto cleanup_allocation; |
| 2215 | } |
| 2216 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2217 | } |
| 2218 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2219 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2220 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2221 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2222 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2223 | |
| 2224 | found_devs++; |
| 2225 | } |
| 2226 | |
| 2227 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2228 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | |
| 2230 | if (rval != QLA_SUCCESS) { |
| 2231 | DEBUG2(printk("scsi(%ld): Configure local loop error exit: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2232 | "rval=%x\n", vha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2233 | } |
| 2234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2235 | return (rval); |
| 2236 | } |
| 2237 | |
| 2238 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2239 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2240 | { |
| 2241 | #define LS_UNKNOWN 2 |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2242 | static char *link_speeds[5] = { "1", "2", "?", "4", "8" }; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2243 | int rval; |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2244 | uint16_t mb[6]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2245 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2246 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 2247 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2248 | return; |
| 2249 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 2250 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 2251 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2252 | return; |
| 2253 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2254 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2255 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2256 | if (rval != QLA_SUCCESS) { |
| 2257 | DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA " |
| 2258 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2259 | vha->host_no, fcport->port_name[0], fcport->port_name[1], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2260 | fcport->port_name[2], fcport->port_name[3], |
| 2261 | fcport->port_name[4], fcport->port_name[5], |
| 2262 | fcport->port_name[6], fcport->port_name[7], rval, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2263 | fcport->fp_speed, mb[0], mb[1])); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2264 | } else { |
| 2265 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 2266 | "iIDMA adjusted to %s GB/s on " |
| 2267 | "%02x%02x%02x%02x%02x%02x%02x%02x.\n", |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2268 | link_speeds[fcport->fp_speed], fcport->port_name[0], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2269 | fcport->port_name[1], fcport->port_name[2], |
| 2270 | fcport->port_name[3], fcport->port_name[4], |
| 2271 | fcport->port_name[5], fcport->port_name[6], |
| 2272 | fcport->port_name[7])); |
| 2273 | } |
| 2274 | } |
| 2275 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2276 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2277 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2278 | { |
| 2279 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2280 | struct fc_rport *rport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2281 | struct qla_hw_data *ha = vha->hw; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2282 | |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2283 | if (fcport->drport) |
| 2284 | qla2x00_rport_del(fcport); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2285 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 2286 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 2287 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2288 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 2289 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 2290 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2291 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2292 | if (!rport) { |
| 2293 | qla_printk(KERN_WARNING, ha, |
| 2294 | "Unable to allocate fc remote port!\n"); |
| 2295 | return; |
| 2296 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2297 | spin_lock_irq(fcport->vha->host->host_lock); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2298 | *((fc_port_t **)rport->dd_data) = fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2299 | spin_unlock_irq(fcport->vha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2300 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2301 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2302 | |
| 2303 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2304 | if (fcport->port_type == FCT_INITIATOR) |
| 2305 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 2306 | if (fcport->port_type == FCT_TARGET) |
| 2307 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2308 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2309 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | |
| 2311 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2312 | * qla2x00_update_fcport |
| 2313 | * Updates device on list. |
| 2314 | * |
| 2315 | * Input: |
| 2316 | * ha = adapter block pointer. |
| 2317 | * fcport = port structure pointer. |
| 2318 | * |
| 2319 | * Return: |
| 2320 | * 0 - Success |
| 2321 | * BIT_0 - error |
| 2322 | * |
| 2323 | * Context: |
| 2324 | * Kernel context. |
| 2325 | */ |
| 2326 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2327 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2328 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2329 | struct qla_hw_data *ha = vha->hw; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2330 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2331 | fcport->vha = vha; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2332 | fcport->login_retry = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2333 | fcport->port_login_retry_count = ha->port_down_retry_count * |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2334 | PORT_RETRY_TIME; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2335 | atomic_set(&fcport->port_down_timer, ha->port_down_retry_count * |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2336 | PORT_RETRY_TIME); |
| 2337 | fcport->flags &= ~FCF_LOGIN_NEEDED; |
| 2338 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2339 | qla2x00_iidma_fcport(vha, fcport); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2340 | |
| 2341 | atomic_set(&fcport->state, FCS_ONLINE); |
| 2342 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2343 | qla2x00_reg_remote_port(vha, fcport); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2344 | } |
| 2345 | |
| 2346 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2347 | * qla2x00_configure_fabric |
| 2348 | * Setup SNS devices with loop ID's. |
| 2349 | * |
| 2350 | * Input: |
| 2351 | * ha = adapter block pointer. |
| 2352 | * |
| 2353 | * Returns: |
| 2354 | * 0 = success. |
| 2355 | * BIT_0 = error |
| 2356 | */ |
| 2357 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2358 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2359 | { |
| 2360 | int rval, rval2; |
| 2361 | fc_port_t *fcport, *fcptemp; |
| 2362 | uint16_t next_loopid; |
| 2363 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2364 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2365 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2366 | struct qla_hw_data *ha = vha->hw; |
| 2367 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2368 | |
| 2369 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2370 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2371 | loop_id = NPH_F_PORT; |
| 2372 | else |
| 2373 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2374 | rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2375 | if (rval != QLA_SUCCESS) { |
| 2376 | DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2377 | "Port\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2378 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2379 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2380 | return (QLA_SUCCESS); |
| 2381 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2382 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2383 | |
| 2384 | /* Mark devices that need re-synchronization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2385 | rval2 = qla2x00_device_resync(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2386 | if (rval2 == QLA_RSCNS_HANDLED) { |
| 2387 | /* No point doing the scan, just continue. */ |
| 2388 | return (QLA_SUCCESS); |
| 2389 | } |
| 2390 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2391 | /* FDMI support. */ |
| 2392 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2393 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 2394 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2395 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2397 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2398 | loop_id = NPH_SNS; |
| 2399 | else |
| 2400 | loop_id = SIMPLE_NAME_SERVER; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2401 | ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2402 | 0xfc, mb, BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 2404 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 2405 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2406 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2407 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 2408 | return (QLA_SUCCESS); |
| 2409 | } |
| 2410 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2411 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 2412 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | /* EMPTY */ |
| 2414 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2415 | "TYPE failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2417 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | /* EMPTY */ |
| 2419 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2420 | "Features failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2421 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2422 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2423 | /* EMPTY */ |
| 2424 | DEBUG2(printk("scsi(%ld): Register Node Name " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2425 | "failed.\n", vha->host_no)); |
| 2426 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | /* EMPTY */ |
| 2428 | DEBUG2(printk("scsi(%ld): Register Symbolic " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2429 | "Node Name failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2430 | } |
| 2431 | } |
| 2432 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2433 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2434 | if (rval != QLA_SUCCESS) |
| 2435 | break; |
| 2436 | |
| 2437 | /* |
| 2438 | * Logout all previous fabric devices marked lost, except |
| 2439 | * tape devices. |
| 2440 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2441 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 2442 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2443 | break; |
| 2444 | |
| 2445 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 2446 | continue; |
| 2447 | |
| 2448 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2449 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2450 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2451 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 2452 | (fcport->flags & FCF_TAPE_PRESENT) == 0 && |
| 2453 | fcport->port_type != FCT_INITIATOR && |
| 2454 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2455 | ha->isp_ops->fabric_logout(vha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2456 | fcport->loop_id, |
| 2457 | fcport->d_id.b.domain, |
| 2458 | fcport->d_id.b.area, |
| 2459 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2460 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2461 | } |
| 2462 | } |
| 2463 | } |
| 2464 | |
| 2465 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2466 | next_loopid = ha->min_external_loopid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | |
| 2468 | /* |
| 2469 | * Scan through our port list and login entries that need to be |
| 2470 | * logged in. |
| 2471 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2472 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 2473 | if (atomic_read(&vha->loop_down_timer) || |
| 2474 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | break; |
| 2476 | |
| 2477 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 2478 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 2479 | continue; |
| 2480 | |
| 2481 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 2482 | fcport->loop_id = next_loopid; |
Seokmann Ju | d4486fd6 | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 2483 | rval = qla2x00_find_new_loop_id( |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2484 | base_vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | if (rval != QLA_SUCCESS) { |
| 2486 | /* Ran out of IDs to use */ |
| 2487 | break; |
| 2488 | } |
| 2489 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2490 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2491 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2492 | } |
| 2493 | |
| 2494 | /* Exit if out of loop IDs. */ |
| 2495 | if (rval != QLA_SUCCESS) { |
| 2496 | break; |
| 2497 | } |
| 2498 | |
| 2499 | /* |
| 2500 | * Login and add the new devices to our port list. |
| 2501 | */ |
| 2502 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2503 | if (atomic_read(&vha->loop_down_timer) || |
| 2504 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2505 | break; |
| 2506 | |
| 2507 | /* Find a new loop ID to use. */ |
| 2508 | fcport->loop_id = next_loopid; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2509 | rval = qla2x00_find_new_loop_id(base_vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2510 | if (rval != QLA_SUCCESS) { |
| 2511 | /* Ran out of IDs to use */ |
| 2512 | break; |
| 2513 | } |
| 2514 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2515 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2516 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2517 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2518 | if (vha->vp_idx) { |
| 2519 | fcport->vha = vha; |
| 2520 | fcport->vp_idx = vha->vp_idx; |
| 2521 | } |
| 2522 | list_move_tail(&fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2523 | } |
| 2524 | } while (0); |
| 2525 | |
| 2526 | /* Free all new device structures not processed. */ |
| 2527 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 2528 | list_del(&fcport->list); |
| 2529 | kfree(fcport); |
| 2530 | } |
| 2531 | |
| 2532 | if (rval) { |
| 2533 | DEBUG2(printk("scsi(%ld): Configure fabric error exit: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2534 | "rval=%d\n", vha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | } |
| 2536 | |
| 2537 | return (rval); |
| 2538 | } |
| 2539 | |
| 2540 | |
| 2541 | /* |
| 2542 | * qla2x00_find_all_fabric_devs |
| 2543 | * |
| 2544 | * Input: |
| 2545 | * ha = adapter block pointer. |
| 2546 | * dev = database device entry pointer. |
| 2547 | * |
| 2548 | * Returns: |
| 2549 | * 0 = success. |
| 2550 | * |
| 2551 | * Context: |
| 2552 | * Kernel context. |
| 2553 | */ |
| 2554 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2555 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 2556 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2557 | { |
| 2558 | int rval; |
| 2559 | uint16_t loop_id; |
| 2560 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 2561 | int found; |
| 2562 | |
| 2563 | sw_info_t *swl; |
| 2564 | int swl_idx; |
| 2565 | int first_dev, last_dev; |
| 2566 | port_id_t wrap, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2567 | struct qla_hw_data *ha = vha->hw; |
| 2568 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 2569 | struct scsi_qla_host *tvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | |
| 2571 | rval = QLA_SUCCESS; |
| 2572 | |
| 2573 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 4b89258 | 2008-09-11 21:22:48 -0700 | [diff] [blame] | 2574 | swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL); |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2575 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | /*EMPTY*/ |
| 2577 | DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2578 | "on GA_NXT\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2580 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2581 | kfree(swl); |
| 2582 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2583 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | kfree(swl); |
| 2585 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2586 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | kfree(swl); |
| 2588 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 2589 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2590 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 2591 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | } |
| 2593 | } |
| 2594 | swl_idx = 0; |
| 2595 | |
| 2596 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2597 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2599 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2600 | return (QLA_MEMORY_ALLOC_FAILED); |
| 2601 | } |
| 2602 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2603 | /* Set start port ID scan at adapter ID. */ |
| 2604 | first_dev = 1; |
| 2605 | last_dev = 0; |
| 2606 | |
| 2607 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2608 | loop_id = ha->min_external_loopid; |
| 2609 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 2610 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | continue; |
| 2612 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2613 | if (atomic_read(&vha->loop_down_timer) || LOOP_TRANSITION(vha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | break; |
| 2615 | |
| 2616 | if (swl != NULL) { |
| 2617 | if (last_dev) { |
| 2618 | wrap.b24 = new_fcport->d_id.b24; |
| 2619 | } else { |
| 2620 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 2621 | memcpy(new_fcport->node_name, |
| 2622 | swl[swl_idx].node_name, WWN_SIZE); |
| 2623 | memcpy(new_fcport->port_name, |
| 2624 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2625 | memcpy(new_fcport->fabric_port_name, |
| 2626 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 2627 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2628 | |
| 2629 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 2630 | last_dev = 1; |
| 2631 | } |
| 2632 | swl_idx++; |
| 2633 | } |
| 2634 | } else { |
| 2635 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2636 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2637 | if (rval != QLA_SUCCESS) { |
| 2638 | qla_printk(KERN_WARNING, ha, |
| 2639 | "SNS scan failed -- assuming zero-entry " |
| 2640 | "result...\n"); |
| 2641 | list_for_each_entry_safe(fcport, fcptemp, |
| 2642 | new_fcports, list) { |
| 2643 | list_del(&fcport->list); |
| 2644 | kfree(fcport); |
| 2645 | } |
| 2646 | rval = QLA_SUCCESS; |
| 2647 | break; |
| 2648 | } |
| 2649 | } |
| 2650 | |
| 2651 | /* If wrap on switch device list, exit. */ |
| 2652 | if (first_dev) { |
| 2653 | wrap.b24 = new_fcport->d_id.b24; |
| 2654 | first_dev = 0; |
| 2655 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
| 2656 | DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2657 | vha->host_no, new_fcport->d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa)); |
| 2659 | break; |
| 2660 | } |
| 2661 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2662 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2663 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2664 | continue; |
| 2665 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2666 | /* Bypass virtual ports of the same host. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2667 | found = 0; |
| 2668 | if (ha->num_vhosts) { |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 2669 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2670 | if (new_fcport->d_id.b24 == vp->d_id.b24) { |
| 2671 | found = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2672 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2673 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2674 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2675 | if (found) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2676 | continue; |
| 2677 | } |
| 2678 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2679 | /* Bypass if same domain and area of adapter. */ |
| 2680 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2681 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2682 | ISP_CFG_FL) |
| 2683 | continue; |
| 2684 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2685 | /* Bypass reserved domain fields. */ |
| 2686 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 2687 | continue; |
| 2688 | |
| 2689 | /* Locate matching device in database. */ |
| 2690 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2691 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2692 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2693 | WWN_SIZE)) |
| 2694 | continue; |
| 2695 | |
| 2696 | found++; |
| 2697 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2698 | /* Update port state. */ |
| 2699 | memcpy(fcport->fabric_port_name, |
| 2700 | new_fcport->fabric_port_name, WWN_SIZE); |
| 2701 | fcport->fp_speed = new_fcport->fp_speed; |
| 2702 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2703 | /* |
| 2704 | * If address the same and state FCS_ONLINE, nothing |
| 2705 | * changed. |
| 2706 | */ |
| 2707 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 2708 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 2709 | break; |
| 2710 | } |
| 2711 | |
| 2712 | /* |
| 2713 | * If device was not a fabric device before. |
| 2714 | */ |
| 2715 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2716 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2717 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2718 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 2719 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2720 | break; |
| 2721 | } |
| 2722 | |
| 2723 | /* |
| 2724 | * Port ID changed or device was marked to be updated; |
| 2725 | * Log it out if still logged in and mark it for |
| 2726 | * relogin later. |
| 2727 | */ |
| 2728 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2729 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 2730 | if (fcport->loop_id != FC_NO_LOOP_ID && |
| 2731 | (fcport->flags & FCF_TAPE_PRESENT) == 0 && |
| 2732 | fcport->port_type != FCT_INITIATOR && |
| 2733 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2734 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2735 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 2736 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2737 | fcport->loop_id = FC_NO_LOOP_ID; |
| 2738 | } |
| 2739 | |
| 2740 | break; |
| 2741 | } |
| 2742 | |
| 2743 | if (found) |
| 2744 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | /* If device was not in our fcports list, then add it. */ |
| 2746 | list_add_tail(&new_fcport->list, new_fcports); |
| 2747 | |
| 2748 | /* Allocate a new replacement fcport. */ |
| 2749 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2750 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2752 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | return (QLA_MEMORY_ALLOC_FAILED); |
| 2754 | } |
| 2755 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 2756 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 2757 | } |
| 2758 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2759 | kfree(swl); |
| 2760 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | return (rval); |
| 2763 | } |
| 2764 | |
| 2765 | /* |
| 2766 | * qla2x00_find_new_loop_id |
| 2767 | * Scan through our port list and find a new usable loop ID. |
| 2768 | * |
| 2769 | * Input: |
| 2770 | * ha: adapter state pointer. |
| 2771 | * dev: port structure pointer. |
| 2772 | * |
| 2773 | * Returns: |
| 2774 | * qla2x00 local function return status code. |
| 2775 | * |
| 2776 | * Context: |
| 2777 | * Kernel context. |
| 2778 | */ |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 2779 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2780 | qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | { |
| 2782 | int rval; |
| 2783 | int found; |
| 2784 | fc_port_t *fcport; |
| 2785 | uint16_t first_loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2786 | struct qla_hw_data *ha = vha->hw; |
| 2787 | struct scsi_qla_host *vp; |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 2788 | struct scsi_qla_host *tvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2789 | |
| 2790 | rval = QLA_SUCCESS; |
| 2791 | |
| 2792 | /* Save starting loop ID. */ |
| 2793 | first_loop_id = dev->loop_id; |
| 2794 | |
| 2795 | for (;;) { |
| 2796 | /* Skip loop ID if already used by adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2797 | if (dev->loop_id == vha->loop_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2798 | dev->loop_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | |
| 2800 | /* Skip reserved loop IDs. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2801 | while (qla2x00_is_reserved_id(vha, dev->loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2802 | dev->loop_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | |
| 2804 | /* Reset loop ID if passed the end. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2805 | if (dev->loop_id > ha->max_loop_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2806 | /* first loop ID. */ |
| 2807 | dev->loop_id = ha->min_external_loopid; |
| 2808 | } |
| 2809 | |
| 2810 | /* Check for loop ID being already in use. */ |
| 2811 | found = 0; |
| 2812 | fcport = NULL; |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 2813 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2814 | list_for_each_entry(fcport, &vp->vp_fcports, list) { |
| 2815 | if (fcport->loop_id == dev->loop_id && |
| 2816 | fcport != dev) { |
| 2817 | /* ID possibly in use */ |
| 2818 | found++; |
| 2819 | break; |
| 2820 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2822 | if (found) |
| 2823 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
| 2826 | /* If not in use then it is free to use. */ |
| 2827 | if (!found) { |
| 2828 | break; |
| 2829 | } |
| 2830 | |
| 2831 | /* ID in use. Try next value. */ |
| 2832 | dev->loop_id++; |
| 2833 | |
| 2834 | /* If wrap around. No free ID to use. */ |
| 2835 | if (dev->loop_id == first_loop_id) { |
| 2836 | dev->loop_id = FC_NO_LOOP_ID; |
| 2837 | rval = QLA_FUNCTION_FAILED; |
| 2838 | break; |
| 2839 | } |
| 2840 | } |
| 2841 | |
| 2842 | return (rval); |
| 2843 | } |
| 2844 | |
| 2845 | /* |
| 2846 | * qla2x00_device_resync |
| 2847 | * Marks devices in the database that needs resynchronization. |
| 2848 | * |
| 2849 | * Input: |
| 2850 | * ha = adapter block pointer. |
| 2851 | * |
| 2852 | * Context: |
| 2853 | * Kernel context. |
| 2854 | */ |
| 2855 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2856 | qla2x00_device_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2857 | { |
| 2858 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2859 | uint32_t mask; |
| 2860 | fc_port_t *fcport; |
| 2861 | uint32_t rscn_entry; |
| 2862 | uint8_t rscn_out_iter; |
| 2863 | uint8_t format; |
| 2864 | port_id_t d_id; |
| 2865 | |
| 2866 | rval = QLA_RSCNS_HANDLED; |
| 2867 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2868 | while (vha->rscn_out_ptr != vha->rscn_in_ptr || |
| 2869 | vha->flags.rscn_queue_overflow) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2870 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2871 | rscn_entry = vha->rscn_queue[vha->rscn_out_ptr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2872 | format = MSB(MSW(rscn_entry)); |
| 2873 | d_id.b.domain = LSB(MSW(rscn_entry)); |
| 2874 | d_id.b.area = MSB(LSW(rscn_entry)); |
| 2875 | d_id.b.al_pa = LSB(LSW(rscn_entry)); |
| 2876 | |
| 2877 | DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = " |
| 2878 | "[%02x/%02x%02x%02x].\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2879 | vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2880 | d_id.b.area, d_id.b.al_pa)); |
| 2881 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2882 | vha->rscn_out_ptr++; |
| 2883 | if (vha->rscn_out_ptr == MAX_RSCN_COUNT) |
| 2884 | vha->rscn_out_ptr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | |
| 2886 | /* Skip duplicate entries. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2887 | for (rscn_out_iter = vha->rscn_out_ptr; |
| 2888 | !vha->flags.rscn_queue_overflow && |
| 2889 | rscn_out_iter != vha->rscn_in_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2890 | rscn_out_iter = (rscn_out_iter == |
| 2891 | (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) { |
| 2892 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2893 | if (rscn_entry != vha->rscn_queue[rscn_out_iter]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2894 | break; |
| 2895 | |
| 2896 | DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2897 | "entry found at [%d].\n", vha->host_no, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2898 | rscn_out_iter)); |
| 2899 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2900 | vha->rscn_out_ptr = rscn_out_iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | /* Queue overflow, set switch default case. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2904 | if (vha->flags.rscn_queue_overflow) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2905 | DEBUG(printk("scsi(%ld): device_resync: rscn " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2906 | "overflow.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2907 | |
| 2908 | format = 3; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2909 | vha->flags.rscn_queue_overflow = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2910 | } |
| 2911 | |
| 2912 | switch (format) { |
| 2913 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2914 | mask = 0xffffff; |
| 2915 | break; |
| 2916 | case 1: |
| 2917 | mask = 0xffff00; |
| 2918 | break; |
| 2919 | case 2: |
| 2920 | mask = 0xff0000; |
| 2921 | break; |
| 2922 | default: |
| 2923 | mask = 0x0; |
| 2924 | d_id.b24 = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2925 | vha->rscn_out_ptr = vha->rscn_in_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2926 | break; |
| 2927 | } |
| 2928 | |
| 2929 | rval = QLA_SUCCESS; |
| 2930 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2931 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2932 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 2933 | (fcport->d_id.b24 & mask) != d_id.b24 || |
| 2934 | fcport->port_type == FCT_BROADCAST) |
| 2935 | continue; |
| 2936 | |
| 2937 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
| 2938 | if (format != 3 || |
| 2939 | fcport->port_type != FCT_INITIATOR) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2940 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2941 | 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | } |
| 2943 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2944 | } |
| 2945 | } |
| 2946 | return (rval); |
| 2947 | } |
| 2948 | |
| 2949 | /* |
| 2950 | * qla2x00_fabric_dev_login |
| 2951 | * Login fabric target device and update FC port database. |
| 2952 | * |
| 2953 | * Input: |
| 2954 | * ha: adapter state pointer. |
| 2955 | * fcport: port structure list pointer. |
| 2956 | * next_loopid: contains value of a new loop ID that can be used |
| 2957 | * by the next login attempt. |
| 2958 | * |
| 2959 | * Returns: |
| 2960 | * qla2x00 local function return status code. |
| 2961 | * |
| 2962 | * Context: |
| 2963 | * Kernel context. |
| 2964 | */ |
| 2965 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2966 | qla2x00_fabric_dev_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | uint16_t *next_loopid) |
| 2968 | { |
| 2969 | int rval; |
| 2970 | int retry; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2971 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2972 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2973 | |
| 2974 | rval = QLA_SUCCESS; |
| 2975 | retry = 0; |
| 2976 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2977 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2979 | /* Send an ADISC to tape devices.*/ |
| 2980 | opts = 0; |
| 2981 | if (fcport->flags & FCF_TAPE_PRESENT) |
| 2982 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2983 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2984 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2985 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 2986 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 2987 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2988 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2989 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2990 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | } |
| 2992 | } |
| 2993 | |
| 2994 | return (rval); |
| 2995 | } |
| 2996 | |
| 2997 | /* |
| 2998 | * qla2x00_fabric_login |
| 2999 | * Issue fabric login command. |
| 3000 | * |
| 3001 | * Input: |
| 3002 | * ha = adapter block pointer. |
| 3003 | * device = pointer to FC device type structure. |
| 3004 | * |
| 3005 | * Returns: |
| 3006 | * 0 - Login successfully |
| 3007 | * 1 - Login failed |
| 3008 | * 2 - Initiator device |
| 3009 | * 3 - Fatal error |
| 3010 | */ |
| 3011 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3012 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | uint16_t *next_loopid) |
| 3014 | { |
| 3015 | int rval; |
| 3016 | int retry; |
| 3017 | uint16_t tmp_loopid; |
| 3018 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3019 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | |
| 3021 | retry = 0; |
| 3022 | tmp_loopid = 0; |
| 3023 | |
| 3024 | for (;;) { |
| 3025 | DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x " |
| 3026 | "for port %02x%02x%02x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3027 | vha->host_no, fcport->loop_id, fcport->d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3028 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3029 | |
| 3030 | /* Login fcport on switch. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3031 | ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3033 | fcport->d_id.b.al_pa, mb, BIT_0); |
| 3034 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3035 | /* |
| 3036 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3037 | * recommends the driver perform an implicit login with |
| 3038 | * the specified ID again. The ID we just used is save |
| 3039 | * here so we return with an ID that can be tried by |
| 3040 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3041 | */ |
| 3042 | retry++; |
| 3043 | tmp_loopid = fcport->loop_id; |
| 3044 | fcport->loop_id = mb[1]; |
| 3045 | |
| 3046 | DEBUG(printk("Fabric Login: port in use - next " |
| 3047 | "loop id=0x%04x, port Id=%02x%02x%02x.\n", |
| 3048 | fcport->loop_id, fcport->d_id.b.domain, |
| 3049 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3050 | |
| 3051 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3052 | /* |
| 3053 | * Login succeeded. |
| 3054 | */ |
| 3055 | if (retry) { |
| 3056 | /* A retry occurred before. */ |
| 3057 | *next_loopid = tmp_loopid; |
| 3058 | } else { |
| 3059 | /* |
| 3060 | * No retry occurred before. Just increment the |
| 3061 | * ID value for next login. |
| 3062 | */ |
| 3063 | *next_loopid = (fcport->loop_id + 1); |
| 3064 | } |
| 3065 | |
| 3066 | if (mb[1] & BIT_0) { |
| 3067 | fcport->port_type = FCT_INITIATOR; |
| 3068 | } else { |
| 3069 | fcport->port_type = FCT_TARGET; |
| 3070 | if (mb[1] & BIT_1) { |
| 3071 | fcport->flags |= FCF_TAPE_PRESENT; |
| 3072 | } |
| 3073 | } |
| 3074 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3075 | if (mb[10] & BIT_0) |
| 3076 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3077 | if (mb[10] & BIT_1) |
| 3078 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3079 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3080 | rval = QLA_SUCCESS; |
| 3081 | break; |
| 3082 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3083 | /* |
| 3084 | * Loop ID already used, try next loop ID. |
| 3085 | */ |
| 3086 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3087 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3088 | if (rval != QLA_SUCCESS) { |
| 3089 | /* Ran out of loop IDs to use */ |
| 3090 | break; |
| 3091 | } |
| 3092 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3093 | /* |
| 3094 | * Firmware possibly timed out during login. If NO |
| 3095 | * retries are left to do then the device is declared |
| 3096 | * dead. |
| 3097 | */ |
| 3098 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3099 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3100 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3101 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3102 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3103 | |
| 3104 | rval = 1; |
| 3105 | break; |
| 3106 | } else { |
| 3107 | /* |
| 3108 | * unrecoverable / not handled error |
| 3109 | */ |
| 3110 | DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x " |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3111 | "loop_id=%x jiffies=%lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3112 | __func__, vha->host_no, mb[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3113 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3114 | fcport->d_id.b.al_pa, fcport->loop_id, jiffies)); |
| 3115 | |
| 3116 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3117 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3118 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3119 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3120 | fcport->loop_id = FC_NO_LOOP_ID; |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3121 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | |
| 3123 | rval = 3; |
| 3124 | break; |
| 3125 | } |
| 3126 | } |
| 3127 | |
| 3128 | return (rval); |
| 3129 | } |
| 3130 | |
| 3131 | /* |
| 3132 | * qla2x00_local_device_login |
| 3133 | * Issue local device login command. |
| 3134 | * |
| 3135 | * Input: |
| 3136 | * ha = adapter block pointer. |
| 3137 | * loop_id = loop id of device to login to. |
| 3138 | * |
| 3139 | * Returns (Where's the #define!!!!): |
| 3140 | * 0 - Login successfully |
| 3141 | * 1 - Login failed |
| 3142 | * 3 - Fatal error |
| 3143 | */ |
| 3144 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3145 | qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3146 | { |
| 3147 | int rval; |
| 3148 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3149 | |
| 3150 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3151 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3152 | if (rval == QLA_SUCCESS) { |
| 3153 | /* Interrogate mailbox registers for any errors */ |
| 3154 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3155 | rval = 1; |
| 3156 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3157 | /* device not in PCB table */ |
| 3158 | rval = 3; |
| 3159 | } |
| 3160 | |
| 3161 | return (rval); |
| 3162 | } |
| 3163 | |
| 3164 | /* |
| 3165 | * qla2x00_loop_resync |
| 3166 | * Resync with fibre channel devices. |
| 3167 | * |
| 3168 | * Input: |
| 3169 | * ha = adapter block pointer. |
| 3170 | * |
| 3171 | * Returns: |
| 3172 | * 0 = success |
| 3173 | */ |
| 3174 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3175 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3176 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3177 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | uint32_t wait_time; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3179 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3180 | struct req_que *req = ha->req_q_map[vha->req_ques[0]]; |
| 3181 | struct rsp_que *rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3183 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
| 3184 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 3185 | if (vha->flags.online) { |
| 3186 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3187 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3188 | wait_time = 256; |
| 3189 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3190 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3191 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3192 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3193 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 3194 | MK_SYNC_ALL); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3195 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3196 | |
| 3197 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3198 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3199 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3200 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3201 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3202 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3203 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3204 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3205 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3207 | } |
| 3208 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3209 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3210 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3211 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3212 | if (rval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3213 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | |
| 3215 | return (rval); |
| 3216 | } |
| 3217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3218 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3219 | qla2x00_update_fcports(scsi_qla_host_t *vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3220 | { |
| 3221 | fc_port_t *fcport; |
| 3222 | |
| 3223 | /* Go with deferred removal of rport references. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3224 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 3225 | if (fcport && fcport->drport && |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 3226 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3227 | qla2x00_rport_del(fcport); |
| 3228 | } |
| 3229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | /* |
| 3231 | * qla2x00_abort_isp |
| 3232 | * Resets ISP and aborts all outstanding commands. |
| 3233 | * |
| 3234 | * Input: |
| 3235 | * ha = adapter block pointer. |
| 3236 | * |
| 3237 | * Returns: |
| 3238 | * 0 = success |
| 3239 | */ |
| 3240 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3241 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3242 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 3243 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3244 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3245 | struct qla_hw_data *ha = vha->hw; |
| 3246 | struct scsi_qla_host *vp; |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3247 | struct scsi_qla_host *tvp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3248 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3250 | if (vha->flags.online) { |
| 3251 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 3252 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3253 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Harish Zunjarrao | e5f5f6f | 2008-07-10 16:55:49 -0700 | [diff] [blame] | 3254 | ha->qla_stats.total_isp_aborts++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3255 | |
| 3256 | qla_printk(KERN_INFO, ha, |
| 3257 | "Performing ISP error recovery - ha= %p.\n", ha); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3258 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3260 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 3261 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 3262 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 3263 | qla2x00_mark_all_devices_lost(vha, 0); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3264 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3265 | qla2x00_mark_all_devices_lost(vp, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3267 | if (!atomic_read(&vha->loop_down_timer)) |
| 3268 | atomic_set(&vha->loop_down_timer, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | LOOP_DOWN_TIME); |
| 3270 | } |
| 3271 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3272 | /* Requeue all commands in outstanding command list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3273 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3274 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3275 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 3276 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3277 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3278 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3279 | if (!qla2x00_restart_isp(vha)) { |
| 3280 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3281 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3282 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3283 | /* |
| 3284 | * Issue marker command only when we are going |
| 3285 | * to start the I/O . |
| 3286 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3287 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | } |
| 3289 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3290 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3291 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3292 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3293 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3294 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3295 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 3296 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 3297 | if (ha->fce) { |
| 3298 | ha->flags.fce_enabled = 1; |
| 3299 | memset(ha->fce, 0, |
| 3300 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3301 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 3302 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 3303 | &ha->fce_bufs); |
| 3304 | if (rval) { |
| 3305 | qla_printk(KERN_WARNING, ha, |
| 3306 | "Unable to reinitialize FCE " |
| 3307 | "(%d).\n", rval); |
| 3308 | ha->flags.fce_enabled = 0; |
| 3309 | } |
| 3310 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 3311 | |
| 3312 | if (ha->eft) { |
| 3313 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3314 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 3315 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 3316 | if (rval) { |
| 3317 | qla_printk(KERN_WARNING, ha, |
| 3318 | "Unable to reinitialize EFT " |
| 3319 | "(%d).\n", rval); |
| 3320 | } |
| 3321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3322 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3323 | vha->flags.online = 1; |
| 3324 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3325 | if (ha->isp_abort_cnt == 0) { |
| 3326 | qla_printk(KERN_WARNING, ha, |
| 3327 | "ISP error recovery failed - " |
| 3328 | "board disabled\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3329 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | * The next call disables the board |
| 3331 | * completely. |
| 3332 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3333 | ha->isp_ops->reset_adapter(vha); |
| 3334 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3335 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3336 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3337 | status = 0; |
| 3338 | } else { /* schedule another ISP abort */ |
| 3339 | ha->isp_abort_cnt--; |
| 3340 | DEBUG(printk("qla%ld: ISP abort - " |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3341 | "retry remaining %d\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3342 | vha->host_no, ha->isp_abort_cnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | status = 1; |
| 3344 | } |
| 3345 | } else { |
| 3346 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
| 3347 | DEBUG(printk("qla2x00(%ld): ISP error recovery " |
| 3348 | "- retrying (%d) more times\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3349 | vha->host_no, ha->isp_abort_cnt)); |
| 3350 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3351 | status = 1; |
| 3352 | } |
| 3353 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3354 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | } |
| 3356 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3357 | if (!status) { |
| 3358 | DEBUG(printk(KERN_INFO |
| 3359 | "qla2x00_abort_isp(%ld): succeeded.\n", |
| 3360 | vha->host_no)); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3361 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3362 | if (vp->vp_idx) |
| 3363 | qla2x00_vp_abort_isp(vp); |
| 3364 | } |
| 3365 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | qla_printk(KERN_INFO, ha, |
| 3367 | "qla2x00_abort_isp: **** FAILED ****\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | } |
| 3369 | |
| 3370 | return(status); |
| 3371 | } |
| 3372 | |
| 3373 | /* |
| 3374 | * qla2x00_restart_isp |
| 3375 | * restarts the ISP after a reset |
| 3376 | * |
| 3377 | * Input: |
| 3378 | * ha = adapter block pointer. |
| 3379 | * |
| 3380 | * Returns: |
| 3381 | * 0 = success |
| 3382 | */ |
| 3383 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3384 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 3386 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3387 | uint32_t wait_time; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3388 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3389 | struct req_que *req = ha->req_q_map[0]; |
| 3390 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | |
| 3392 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3393 | if (qla2x00_isp_firmware(vha)) { |
| 3394 | vha->flags.online = 0; |
| 3395 | status = ha->isp_ops->chip_diag(vha); |
| 3396 | if (!status) |
| 3397 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3398 | } |
| 3399 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3400 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 3401 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 3402 | ha->flags.chip_reset_done = 1; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3403 | /* Initialize the queues in use */ |
| 3404 | qla25xx_init_queues(ha); |
| 3405 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3406 | status = qla2x00_fw_ready(vha); |
| 3407 | if (!status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | DEBUG(printk("%s(): Start configure loop, " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 3409 | "status = %d\n", __func__, status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3410 | |
| 3411 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3412 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3413 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3414 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3415 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3416 | wait_time = 256; |
| 3417 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3418 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3419 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3421 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3422 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3423 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3424 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | } |
| 3426 | |
| 3427 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3428 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3429 | status = 0; |
| 3430 | |
| 3431 | DEBUG(printk("%s(): Configure loop done, status = 0x%x\n", |
| 3432 | __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 3433 | status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3434 | } |
| 3435 | return (status); |
| 3436 | } |
| 3437 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3438 | static int |
| 3439 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 3440 | { |
| 3441 | struct rsp_que *rsp = NULL; |
| 3442 | struct req_que *req = NULL; |
| 3443 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 3444 | int ret = -1; |
| 3445 | int i; |
| 3446 | |
| 3447 | for (i = 1; i < ha->max_queues; i++) { |
| 3448 | rsp = ha->rsp_q_map[i]; |
| 3449 | if (rsp) { |
| 3450 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 3451 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3452 | if (ret != QLA_SUCCESS) |
| 3453 | DEBUG2_17(printk(KERN_WARNING |
| 3454 | "%s Rsp que:%d init failed\n", __func__, |
| 3455 | rsp->id)); |
| 3456 | else |
| 3457 | DEBUG2_17(printk(KERN_INFO |
| 3458 | "%s Rsp que:%d inited\n", __func__, |
| 3459 | rsp->id)); |
| 3460 | } |
| 3461 | req = ha->req_q_map[i]; |
| 3462 | if (req) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3463 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3464 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 3465 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3466 | if (ret != QLA_SUCCESS) |
| 3467 | DEBUG2_17(printk(KERN_WARNING |
| 3468 | "%s Req que:%d init failed\n", __func__, |
| 3469 | req->id)); |
| 3470 | else |
| 3471 | DEBUG2_17(printk(KERN_WARNING |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 3472 | "%s Req que:%d inited\n", __func__, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3473 | req->id)); |
| 3474 | } |
| 3475 | } |
| 3476 | return ret; |
| 3477 | } |
| 3478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3479 | /* |
| 3480 | * qla2x00_reset_adapter |
| 3481 | * Reset adapter. |
| 3482 | * |
| 3483 | * Input: |
| 3484 | * ha = adapter block pointer. |
| 3485 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3486 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3487 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3488 | { |
| 3489 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3490 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 3491 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3493 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3494 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3495 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3496 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3497 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 3498 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 3499 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 3500 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 3501 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3502 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3503 | |
| 3504 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3505 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3506 | { |
| 3507 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3508 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3509 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 3510 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3511 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 3512 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3513 | |
| 3514 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3515 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 3516 | RD_REG_DWORD(®->hccr); |
| 3517 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 3518 | RD_REG_DWORD(®->hccr); |
| 3519 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 3520 | |
| 3521 | if (IS_NOPOLLING_TYPE(ha)) |
| 3522 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3523 | } |
| 3524 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3525 | /* On sparc systems, obtain port and node WWN from firmware |
| 3526 | * properties. |
| 3527 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3528 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 3529 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3530 | { |
| 3531 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3532 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3533 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 3534 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 3535 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3536 | int len; |
| 3537 | |
| 3538 | val = of_get_property(dp, "port-wwn", &len); |
| 3539 | if (val && len >= WWN_SIZE) |
| 3540 | memcpy(nv->port_name, val, WWN_SIZE); |
| 3541 | |
| 3542 | val = of_get_property(dp, "node-wwn", &len); |
| 3543 | if (val && len >= WWN_SIZE) |
| 3544 | memcpy(nv->node_name, val, WWN_SIZE); |
| 3545 | #endif |
| 3546 | } |
| 3547 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3548 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3549 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3550 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3551 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3552 | struct init_cb_24xx *icb; |
| 3553 | struct nvram_24xx *nv; |
| 3554 | uint32_t *dptr; |
| 3555 | uint8_t *dptr1, *dptr2; |
| 3556 | uint32_t chksum; |
| 3557 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3558 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3559 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3560 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3561 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3562 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3563 | |
| 3564 | /* Determine NVRAM starting address. */ |
| 3565 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 3566 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 3567 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
| 3568 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 3569 | if (PCI_FUNC(ha->pdev->devfn)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3570 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 3571 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 3572 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3573 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3574 | /* Get VPD data into cache */ |
| 3575 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3576 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3577 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 3578 | |
| 3579 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3580 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3581 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3582 | ha->nvram_size); |
| 3583 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 3584 | chksum += le32_to_cpu(*dptr++); |
| 3585 | |
| 3586 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 3587 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3588 | |
| 3589 | /* Bad NVRAM data, set defaults parameters. */ |
| 3590 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 3591 | || nv->id[3] != ' ' || |
| 3592 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 3593 | /* Reset NVRAM data. */ |
| 3594 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 3595 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 3596 | le16_to_cpu(nv->nvram_version)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3597 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 3598 | "invalid -- WWPN) defaults.\n"); |
| 3599 | |
| 3600 | /* |
| 3601 | * Set default initialization control block. |
| 3602 | */ |
| 3603 | memset(nv, 0, ha->nvram_size); |
| 3604 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 3605 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 3606 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 3607 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 3608 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 3609 | nv->hard_address = __constant_cpu_to_le16(124); |
| 3610 | nv->port_name[0] = 0x21; |
| 3611 | nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn); |
| 3612 | nv->port_name[2] = 0x00; |
| 3613 | nv->port_name[3] = 0xe0; |
| 3614 | nv->port_name[4] = 0x8b; |
| 3615 | nv->port_name[5] = 0x1c; |
| 3616 | nv->port_name[6] = 0x55; |
| 3617 | nv->port_name[7] = 0x86; |
| 3618 | nv->node_name[0] = 0x20; |
| 3619 | nv->node_name[1] = 0x00; |
| 3620 | nv->node_name[2] = 0x00; |
| 3621 | nv->node_name[3] = 0xe0; |
| 3622 | nv->node_name[4] = 0x8b; |
| 3623 | nv->node_name[5] = 0x1c; |
| 3624 | nv->node_name[6] = 0x55; |
| 3625 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3626 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3627 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 3628 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 3629 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 3630 | nv->firmware_options_1 = |
| 3631 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 3632 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 3633 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 3634 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 3635 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 3636 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 3637 | nv->reset_delay = 5; |
| 3638 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 3639 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 3640 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 3641 | |
| 3642 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3643 | } |
| 3644 | |
| 3645 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3646 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3647 | |
| 3648 | /* Copy 1st segment. */ |
| 3649 | dptr1 = (uint8_t *)icb; |
| 3650 | dptr2 = (uint8_t *)&nv->version; |
| 3651 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 3652 | while (cnt--) |
| 3653 | *dptr1++ = *dptr2++; |
| 3654 | |
| 3655 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 3656 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3657 | |
| 3658 | /* Copy 2nd segment. */ |
| 3659 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 3660 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 3661 | cnt = (uint8_t *)&icb->reserved_3 - |
| 3662 | (uint8_t *)&icb->interrupt_delay_timer; |
| 3663 | while (cnt--) |
| 3664 | *dptr1++ = *dptr2++; |
| 3665 | |
| 3666 | /* |
| 3667 | * Setup driver NVRAM options. |
| 3668 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3669 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 3670 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3671 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 3672 | /* Use alternate WWN? */ |
| 3673 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 3674 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 3675 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 3676 | } |
| 3677 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3678 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 3679 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3680 | /* |
| 3681 | * Firmware will apply the following mask if the nodename was |
| 3682 | * not provided. |
| 3683 | */ |
| 3684 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 3685 | icb->node_name[0] &= 0xF0; |
| 3686 | } |
| 3687 | |
| 3688 | /* Set host adapter parameters. */ |
| 3689 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 3690 | ha->flags.enable_lip_reset = 0; |
| 3691 | ha->flags.enable_lip_full_login = |
| 3692 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 3693 | ha->flags.enable_target_reset = |
| 3694 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3695 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 3696 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3697 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 3698 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 3699 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3700 | |
| 3701 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 3702 | sizeof(ha->fw_seriallink_options24)); |
| 3703 | |
| 3704 | /* save HBA serial number */ |
| 3705 | ha->serial0 = icb->port_name[5]; |
| 3706 | ha->serial1 = icb->port_name[6]; |
| 3707 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3708 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 3709 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3710 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 3711 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 3712 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3713 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 3714 | |
| 3715 | /* Set minimum login_timeout to 4 seconds. */ |
| 3716 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 3717 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 3718 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 3719 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 3720 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 3721 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3722 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 3723 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 3724 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3725 | |
| 3726 | ha->loop_reset_delay = nv->reset_delay; |
| 3727 | |
| 3728 | /* Link Down Timeout = 0: |
| 3729 | * |
| 3730 | * When Port Down timer expires we will start returning |
| 3731 | * I/O's to OS with "DID_NO_CONNECT". |
| 3732 | * |
| 3733 | * Link Down Timeout != 0: |
| 3734 | * |
| 3735 | * The driver waits for the link to come up after link down |
| 3736 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 3737 | */ |
| 3738 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 3739 | ha->loop_down_abort_time = |
| 3740 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 3741 | } else { |
| 3742 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 3743 | ha->loop_down_abort_time = |
| 3744 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 3745 | } |
| 3746 | |
| 3747 | /* Need enough time to try and get the port back. */ |
| 3748 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 3749 | if (qlport_down_retry) |
| 3750 | ha->port_down_retry_count = qlport_down_retry; |
| 3751 | |
| 3752 | /* Set login_retry_count */ |
| 3753 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 3754 | if (ha->port_down_retry_count == |
| 3755 | le16_to_cpu(nv->port_down_retry_count) && |
| 3756 | ha->port_down_retry_count > 3) |
| 3757 | ha->login_retry_count = ha->port_down_retry_count; |
| 3758 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 3759 | ha->login_retry_count = ha->port_down_retry_count; |
| 3760 | if (ql2xloginretrycount) |
| 3761 | ha->login_retry_count = ql2xloginretrycount; |
| 3762 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3763 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3764 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3765 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 3766 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 3767 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 3768 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 3769 | } |
| 3770 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 3771 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3772 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3773 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 3774 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 3775 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3776 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3777 | "(%d us).\n", vha->host_no, ha->zio_mode, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3778 | ha->zio_timer * 100)); |
| 3779 | qla_printk(KERN_INFO, ha, |
| 3780 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 3781 | ha->zio_mode, ha->zio_timer * 100); |
| 3782 | |
| 3783 | icb->firmware_options_2 |= cpu_to_le32( |
| 3784 | (uint32_t)ha->zio_mode); |
| 3785 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3786 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 3787 | } |
| 3788 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3789 | if (rval) { |
| 3790 | DEBUG2_3(printk(KERN_WARNING |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3791 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 3792 | } |
| 3793 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3794 | } |
| 3795 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 3796 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3797 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3798 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3799 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3800 | int segments, fragment; |
| 3801 | uint32_t faddr; |
| 3802 | uint32_t *dcode, dlen; |
| 3803 | uint32_t risc_addr; |
| 3804 | uint32_t risc_size; |
| 3805 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3806 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3807 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 3808 | |
| 3809 | qla_printk(KERN_INFO, ha, |
| 3810 | "FW: Loading from flash (%x)...\n", ha->flt_region_fw); |
| 3811 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3812 | rval = QLA_SUCCESS; |
| 3813 | |
| 3814 | segments = FA_RISC_CODE_SEGMENTS; |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 3815 | faddr = ha->flt_region_fw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3816 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3817 | *srisc_addr = 0; |
| 3818 | |
| 3819 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3820 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3821 | for (i = 0; i < 4; i++) |
| 3822 | dcode[i] = be32_to_cpu(dcode[i]); |
| 3823 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 3824 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 3825 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 3826 | dcode[3] == 0)) { |
| 3827 | qla_printk(KERN_WARNING, ha, |
| 3828 | "Unable to verify integrity of flash firmware image!\n"); |
| 3829 | qla_printk(KERN_WARNING, ha, |
| 3830 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 3831 | dcode[1], dcode[2], dcode[3]); |
| 3832 | |
| 3833 | return QLA_FUNCTION_FAILED; |
| 3834 | } |
| 3835 | |
| 3836 | while (segments && rval == QLA_SUCCESS) { |
| 3837 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3838 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3839 | |
| 3840 | risc_addr = be32_to_cpu(dcode[2]); |
| 3841 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 3842 | risc_size = be32_to_cpu(dcode[3]); |
| 3843 | |
| 3844 | fragment = 0; |
| 3845 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 3846 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 3847 | if (dlen > risc_size) |
| 3848 | dlen = risc_size; |
| 3849 | |
| 3850 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
| 3851 | "addr %x, number of dwords 0x%x, offset 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3852 | vha->host_no, risc_addr, dlen, faddr)); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3853 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3854 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3855 | for (i = 0; i < dlen; i++) |
| 3856 | dcode[i] = swab32(dcode[i]); |
| 3857 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3858 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3859 | dlen); |
| 3860 | if (rval) { |
| 3861 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3862 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3863 | fragment)); |
| 3864 | qla_printk(KERN_WARNING, ha, |
| 3865 | "[ERROR] Failed to load segment %d of " |
| 3866 | "firmware\n", fragment); |
| 3867 | break; |
| 3868 | } |
| 3869 | |
| 3870 | faddr += dlen; |
| 3871 | risc_addr += dlen; |
| 3872 | risc_size -= dlen; |
| 3873 | fragment++; |
| 3874 | } |
| 3875 | |
| 3876 | /* Next segment. */ |
| 3877 | segments--; |
| 3878 | } |
| 3879 | |
| 3880 | return rval; |
| 3881 | } |
| 3882 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3883 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" |
| 3884 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3885 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3886 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3887 | { |
| 3888 | int rval; |
| 3889 | int i, fragment; |
| 3890 | uint16_t *wcode, *fwcode; |
| 3891 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 3892 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3893 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3894 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3895 | |
| 3896 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3897 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3898 | if (!blob) { |
| 3899 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 3900 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 3901 | "from: " QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3902 | return QLA_FUNCTION_FAILED; |
| 3903 | } |
| 3904 | |
| 3905 | rval = QLA_SUCCESS; |
| 3906 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3907 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3908 | *srisc_addr = 0; |
| 3909 | fwcode = (uint16_t *)blob->fw->data; |
| 3910 | fwclen = 0; |
| 3911 | |
| 3912 | /* Validate firmware image by checking version. */ |
| 3913 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
| 3914 | qla_printk(KERN_WARNING, ha, |
| 3915 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 3916 | blob->fw->size); |
| 3917 | goto fail_fw_integrity; |
| 3918 | } |
| 3919 | for (i = 0; i < 4; i++) |
| 3920 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 3921 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 3922 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 3923 | wcode[2] == 0 && wcode[3] == 0)) { |
| 3924 | qla_printk(KERN_WARNING, ha, |
| 3925 | "Unable to verify integrity of firmware image!\n"); |
| 3926 | qla_printk(KERN_WARNING, ha, |
| 3927 | "Firmware data: %04x %04x %04x %04x!\n", wcode[0], |
| 3928 | wcode[1], wcode[2], wcode[3]); |
| 3929 | goto fail_fw_integrity; |
| 3930 | } |
| 3931 | |
| 3932 | seg = blob->segs; |
| 3933 | while (*seg && rval == QLA_SUCCESS) { |
| 3934 | risc_addr = *seg; |
| 3935 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 3936 | risc_size = be16_to_cpu(fwcode[3]); |
| 3937 | |
| 3938 | /* Validate firmware image size. */ |
| 3939 | fwclen += risc_size * sizeof(uint16_t); |
| 3940 | if (blob->fw->size < fwclen) { |
| 3941 | qla_printk(KERN_WARNING, ha, |
| 3942 | "Unable to verify integrity of firmware image " |
| 3943 | "(%Zd)!\n", blob->fw->size); |
| 3944 | goto fail_fw_integrity; |
| 3945 | } |
| 3946 | |
| 3947 | fragment = 0; |
| 3948 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 3949 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 3950 | if (wlen > risc_size) |
| 3951 | wlen = risc_size; |
| 3952 | |
| 3953 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3954 | "addr %x, number of words 0x%x.\n", vha->host_no, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3955 | risc_addr, wlen)); |
| 3956 | |
| 3957 | for (i = 0; i < wlen; i++) |
| 3958 | wcode[i] = swab16(fwcode[i]); |
| 3959 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3960 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3961 | wlen); |
| 3962 | if (rval) { |
| 3963 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3964 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3965 | fragment)); |
| 3966 | qla_printk(KERN_WARNING, ha, |
| 3967 | "[ERROR] Failed to load segment %d of " |
| 3968 | "firmware\n", fragment); |
| 3969 | break; |
| 3970 | } |
| 3971 | |
| 3972 | fwcode += wlen; |
| 3973 | risc_addr += wlen; |
| 3974 | risc_size -= wlen; |
| 3975 | fragment++; |
| 3976 | } |
| 3977 | |
| 3978 | /* Next segment. */ |
| 3979 | seg++; |
| 3980 | } |
| 3981 | return rval; |
| 3982 | |
| 3983 | fail_fw_integrity: |
| 3984 | return QLA_FUNCTION_FAILED; |
| 3985 | } |
| 3986 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 3987 | static int |
| 3988 | qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3989 | { |
| 3990 | int rval; |
| 3991 | int segments, fragment; |
| 3992 | uint32_t *dcode, dlen; |
| 3993 | uint32_t risc_addr; |
| 3994 | uint32_t risc_size; |
| 3995 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 3996 | struct fw_blob *blob; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3997 | uint32_t *fwcode, fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3998 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3999 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4000 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4001 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4002 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4003 | if (!blob) { |
| 4004 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4005 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 4006 | "from: " QLA_FW_URL ".\n"); |
| 4007 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4008 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4009 | } |
| 4010 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4011 | qla_printk(KERN_INFO, ha, |
| 4012 | "FW: Loading via request-firmware...\n"); |
| 4013 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4014 | rval = QLA_SUCCESS; |
| 4015 | |
| 4016 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4017 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4018 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4019 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4020 | fwclen = 0; |
| 4021 | |
| 4022 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4023 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4024 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4025 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 4026 | blob->fw->size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4027 | goto fail_fw_integrity; |
| 4028 | } |
| 4029 | for (i = 0; i < 4; i++) |
| 4030 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 4031 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 4032 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 4033 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 4034 | dcode[3] == 0)) { |
| 4035 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4036 | "Unable to verify integrity of firmware image!\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4037 | qla_printk(KERN_WARNING, ha, |
| 4038 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 4039 | dcode[1], dcode[2], dcode[3]); |
| 4040 | goto fail_fw_integrity; |
| 4041 | } |
| 4042 | |
| 4043 | while (segments && rval == QLA_SUCCESS) { |
| 4044 | risc_addr = be32_to_cpu(fwcode[2]); |
| 4045 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 4046 | risc_size = be32_to_cpu(fwcode[3]); |
| 4047 | |
| 4048 | /* Validate firmware image size. */ |
| 4049 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4050 | if (blob->fw->size < fwclen) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4051 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4052 | "Unable to verify integrity of firmware image " |
| 4053 | "(%Zd)!\n", blob->fw->size); |
| 4054 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4055 | goto fail_fw_integrity; |
| 4056 | } |
| 4057 | |
| 4058 | fragment = 0; |
| 4059 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4060 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 4061 | if (dlen > risc_size) |
| 4062 | dlen = risc_size; |
| 4063 | |
| 4064 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4065 | "addr %x, number of dwords 0x%x.\n", vha->host_no, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4066 | risc_addr, dlen)); |
| 4067 | |
| 4068 | for (i = 0; i < dlen; i++) |
| 4069 | dcode[i] = swab32(fwcode[i]); |
| 4070 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4071 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 4072 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4073 | if (rval) { |
| 4074 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4075 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4076 | fragment)); |
| 4077 | qla_printk(KERN_WARNING, ha, |
| 4078 | "[ERROR] Failed to load segment %d of " |
| 4079 | "firmware\n", fragment); |
| 4080 | break; |
| 4081 | } |
| 4082 | |
| 4083 | fwcode += dlen; |
| 4084 | risc_addr += dlen; |
| 4085 | risc_size -= dlen; |
| 4086 | fragment++; |
| 4087 | } |
| 4088 | |
| 4089 | /* Next segment. */ |
| 4090 | segments--; |
| 4091 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4092 | return rval; |
| 4093 | |
| 4094 | fail_fw_integrity: |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4095 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4096 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4097 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4098 | int |
| 4099 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 4100 | { |
| 4101 | int rval; |
| 4102 | |
| 4103 | /* |
| 4104 | * FW Load priority: |
| 4105 | * 1) Firmware via request-firmware interface (.bin file). |
| 4106 | * 2) Firmware residing in flash. |
| 4107 | */ |
| 4108 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 4109 | if (rval == QLA_SUCCESS) |
| 4110 | return rval; |
| 4111 | |
| 4112 | return qla24xx_load_risc_flash(vha, srisc_addr); |
| 4113 | } |
| 4114 | |
| 4115 | int |
| 4116 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 4117 | { |
| 4118 | int rval; |
| 4119 | |
| 4120 | /* |
| 4121 | * FW Load priority: |
| 4122 | * 1) Firmware residing in flash. |
| 4123 | * 2) Firmware via request-firmware interface (.bin file). |
| 4124 | */ |
| 4125 | rval = qla24xx_load_risc_flash(vha, srisc_addr); |
| 4126 | if (rval == QLA_SUCCESS) |
| 4127 | return rval; |
| 4128 | |
| 4129 | return qla24xx_load_risc_blob(vha, srisc_addr); |
| 4130 | } |
| 4131 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4132 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4133 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4134 | { |
| 4135 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4136 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4137 | |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4138 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4139 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 4140 | if (!ha->fw_major_version) |
| 4141 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4142 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4143 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 4144 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
| 4145 | retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4146 | ha->isp_ops->reset_chip(vha); |
| 4147 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4148 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4149 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4150 | continue; |
| 4151 | qla_printk(KERN_INFO, ha, |
| 4152 | "Attempting retry of stop-firmware command...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4153 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4154 | } |
| 4155 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4156 | |
| 4157 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4158 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4159 | { |
| 4160 | int rval = QLA_SUCCESS; |
| 4161 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4162 | struct qla_hw_data *ha = vha->hw; |
| 4163 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4164 | struct req_que *req = ha->req_q_map[vha->req_ques[0]]; |
| 4165 | struct rsp_que *rsp = req->rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4166 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4167 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4168 | return -EINVAL; |
| 4169 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4170 | rval = qla2x00_fw_ready(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4171 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4172 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4173 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4176 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4177 | |
| 4178 | /* Login to SNS first */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4179 | ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb, BIT_1); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4180 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 4181 | DEBUG15(qla_printk(KERN_INFO, ha, |
| 4182 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 4183 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS, |
| 4184 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 4185 | return (QLA_FUNCTION_FAILED); |
| 4186 | } |
| 4187 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4188 | atomic_set(&vha->loop_down_timer, 0); |
| 4189 | atomic_set(&vha->loop_state, LOOP_UP); |
| 4190 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4191 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 4192 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4193 | |
| 4194 | return rval; |
| 4195 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4196 | |
| 4197 | /* 84XX Support **************************************************************/ |
| 4198 | |
| 4199 | static LIST_HEAD(qla_cs84xx_list); |
| 4200 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 4201 | |
| 4202 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4203 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4204 | { |
| 4205 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4206 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4207 | |
| 4208 | mutex_lock(&qla_cs84xx_mutex); |
| 4209 | |
| 4210 | /* Find any shared 84xx chip. */ |
| 4211 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 4212 | if (cs84xx->bus == ha->pdev->bus) { |
| 4213 | kref_get(&cs84xx->kref); |
| 4214 | goto done; |
| 4215 | } |
| 4216 | } |
| 4217 | |
| 4218 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 4219 | if (!cs84xx) |
| 4220 | goto done; |
| 4221 | |
| 4222 | kref_init(&cs84xx->kref); |
| 4223 | spin_lock_init(&cs84xx->access_lock); |
| 4224 | mutex_init(&cs84xx->fw_update_mutex); |
| 4225 | cs84xx->bus = ha->pdev->bus; |
| 4226 | |
| 4227 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 4228 | done: |
| 4229 | mutex_unlock(&qla_cs84xx_mutex); |
| 4230 | return cs84xx; |
| 4231 | } |
| 4232 | |
| 4233 | static void |
| 4234 | __qla84xx_chip_release(struct kref *kref) |
| 4235 | { |
| 4236 | struct qla_chip_state_84xx *cs84xx = |
| 4237 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 4238 | |
| 4239 | mutex_lock(&qla_cs84xx_mutex); |
| 4240 | list_del(&cs84xx->list); |
| 4241 | mutex_unlock(&qla_cs84xx_mutex); |
| 4242 | kfree(cs84xx); |
| 4243 | } |
| 4244 | |
| 4245 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4246 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4247 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4248 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4249 | if (ha->cs84xx) |
| 4250 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 4251 | } |
| 4252 | |
| 4253 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4254 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4255 | { |
| 4256 | int rval; |
| 4257 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4258 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4259 | |
| 4260 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 4261 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4262 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 4263 | |
| 4264 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 4265 | |
| 4266 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 4267 | QLA_SUCCESS; |
| 4268 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4269 | |
| 4270 | /* 81XX Support **************************************************************/ |
| 4271 | |
| 4272 | int |
| 4273 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 4274 | { |
| 4275 | int rval; |
| 4276 | struct init_cb_81xx *icb; |
| 4277 | struct nvram_81xx *nv; |
| 4278 | uint32_t *dptr; |
| 4279 | uint8_t *dptr1, *dptr2; |
| 4280 | uint32_t chksum; |
| 4281 | uint16_t cnt; |
| 4282 | struct qla_hw_data *ha = vha->hw; |
| 4283 | |
| 4284 | rval = QLA_SUCCESS; |
| 4285 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 4286 | nv = ha->nvram; |
| 4287 | |
| 4288 | /* Determine NVRAM starting address. */ |
| 4289 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4290 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4291 | |
| 4292 | /* Get VPD data into cache */ |
| 4293 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 4294 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 4295 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4296 | |
| 4297 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 4298 | ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4299 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 4300 | dptr = (uint32_t *)nv; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4301 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 4302 | chksum += le32_to_cpu(*dptr++); |
| 4303 | |
| 4304 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", ha->host_no)); |
| 4305 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
| 4306 | |
| 4307 | /* Bad NVRAM data, set defaults parameters. */ |
| 4308 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 4309 | || nv->id[3] != ' ' || |
| 4310 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 4311 | /* Reset NVRAM data. */ |
| 4312 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 4313 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 4314 | le16_to_cpu(nv->nvram_version)); |
| 4315 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 4316 | "invalid -- WWPN) defaults.\n"); |
| 4317 | |
| 4318 | /* |
| 4319 | * Set default initialization control block. |
| 4320 | */ |
| 4321 | memset(nv, 0, ha->nvram_size); |
| 4322 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 4323 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 4324 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 4325 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4326 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 4327 | nv->port_name[0] = 0x21; |
| 4328 | nv->port_name[1] = 0x00 + PCI_FUNC(ha->pdev->devfn); |
| 4329 | nv->port_name[2] = 0x00; |
| 4330 | nv->port_name[3] = 0xe0; |
| 4331 | nv->port_name[4] = 0x8b; |
| 4332 | nv->port_name[5] = 0x1c; |
| 4333 | nv->port_name[6] = 0x55; |
| 4334 | nv->port_name[7] = 0x86; |
| 4335 | nv->node_name[0] = 0x20; |
| 4336 | nv->node_name[1] = 0x00; |
| 4337 | nv->node_name[2] = 0x00; |
| 4338 | nv->node_name[3] = 0xe0; |
| 4339 | nv->node_name[4] = 0x8b; |
| 4340 | nv->node_name[5] = 0x1c; |
| 4341 | nv->node_name[6] = 0x55; |
| 4342 | nv->node_name[7] = 0x86; |
| 4343 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 4344 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 4345 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 4346 | nv->firmware_options_1 = |
| 4347 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 4348 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 4349 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 4350 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 4351 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 4352 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 4353 | nv->reset_delay = 5; |
| 4354 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 4355 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 4356 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 4357 | nv->enode_mac[0] = 0x01; |
| 4358 | nv->enode_mac[1] = 0x02; |
| 4359 | nv->enode_mac[2] = 0x03; |
| 4360 | nv->enode_mac[3] = 0x04; |
| 4361 | nv->enode_mac[4] = 0x05; |
| 4362 | nv->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn); |
| 4363 | |
| 4364 | rval = 1; |
| 4365 | } |
| 4366 | |
| 4367 | /* Reset Initialization control block */ |
| 4368 | memset(icb, 0, sizeof(struct init_cb_81xx)); |
| 4369 | |
| 4370 | /* Copy 1st segment. */ |
| 4371 | dptr1 = (uint8_t *)icb; |
| 4372 | dptr2 = (uint8_t *)&nv->version; |
| 4373 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 4374 | while (cnt--) |
| 4375 | *dptr1++ = *dptr2++; |
| 4376 | |
| 4377 | icb->login_retry_count = nv->login_retry_count; |
| 4378 | |
| 4379 | /* Copy 2nd segment. */ |
| 4380 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 4381 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 4382 | cnt = (uint8_t *)&icb->reserved_5 - |
| 4383 | (uint8_t *)&icb->interrupt_delay_timer; |
| 4384 | while (cnt--) |
| 4385 | *dptr1++ = *dptr2++; |
| 4386 | |
| 4387 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 4388 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 4389 | if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) { |
| 4390 | icb->enode_mac[0] = 0x01; |
| 4391 | icb->enode_mac[1] = 0x02; |
| 4392 | icb->enode_mac[2] = 0x03; |
| 4393 | icb->enode_mac[3] = 0x04; |
| 4394 | icb->enode_mac[4] = 0x05; |
| 4395 | icb->enode_mac[5] = 0x06 + PCI_FUNC(ha->pdev->devfn); |
| 4396 | } |
| 4397 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 4398 | /* Use extended-initialization control block. */ |
| 4399 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 4400 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 4401 | /* |
| 4402 | * Setup driver NVRAM options. |
| 4403 | */ |
| 4404 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
| 4405 | "QLE81XX"); |
| 4406 | |
| 4407 | /* Use alternate WWN? */ |
| 4408 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 4409 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4410 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4411 | } |
| 4412 | |
| 4413 | /* Prepare nodename */ |
| 4414 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
| 4415 | /* |
| 4416 | * Firmware will apply the following mask if the nodename was |
| 4417 | * not provided. |
| 4418 | */ |
| 4419 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4420 | icb->node_name[0] &= 0xF0; |
| 4421 | } |
| 4422 | |
| 4423 | /* Set host adapter parameters. */ |
| 4424 | ha->flags.disable_risc_code_load = 0; |
| 4425 | ha->flags.enable_lip_reset = 0; |
| 4426 | ha->flags.enable_lip_full_login = |
| 4427 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 4428 | ha->flags.enable_target_reset = |
| 4429 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 4430 | ha->flags.enable_led_scheme = 0; |
| 4431 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 4432 | |
| 4433 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 4434 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 4435 | |
| 4436 | /* save HBA serial number */ |
| 4437 | ha->serial0 = icb->port_name[5]; |
| 4438 | ha->serial1 = icb->port_name[6]; |
| 4439 | ha->serial2 = icb->port_name[7]; |
| 4440 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4441 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 4442 | |
| 4443 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4444 | |
| 4445 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 4446 | |
| 4447 | /* Set minimum login_timeout to 4 seconds. */ |
| 4448 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 4449 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 4450 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 4451 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 4452 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
| 4453 | icb->login_timeout = nv->login_timeout; |
| 4454 | |
| 4455 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4456 | ha->r_a_tov = 100; |
| 4457 | |
| 4458 | ha->loop_reset_delay = nv->reset_delay; |
| 4459 | |
| 4460 | /* Link Down Timeout = 0: |
| 4461 | * |
| 4462 | * When Port Down timer expires we will start returning |
| 4463 | * I/O's to OS with "DID_NO_CONNECT". |
| 4464 | * |
| 4465 | * Link Down Timeout != 0: |
| 4466 | * |
| 4467 | * The driver waits for the link to come up after link down |
| 4468 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 4469 | */ |
| 4470 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 4471 | ha->loop_down_abort_time = |
| 4472 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 4473 | } else { |
| 4474 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 4475 | ha->loop_down_abort_time = |
| 4476 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 4477 | } |
| 4478 | |
| 4479 | /* Need enough time to try and get the port back. */ |
| 4480 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 4481 | if (qlport_down_retry) |
| 4482 | ha->port_down_retry_count = qlport_down_retry; |
| 4483 | |
| 4484 | /* Set login_retry_count */ |
| 4485 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 4486 | if (ha->port_down_retry_count == |
| 4487 | le16_to_cpu(nv->port_down_retry_count) && |
| 4488 | ha->port_down_retry_count > 3) |
| 4489 | ha->login_retry_count = ha->port_down_retry_count; |
| 4490 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4491 | ha->login_retry_count = ha->port_down_retry_count; |
| 4492 | if (ql2xloginretrycount) |
| 4493 | ha->login_retry_count = ql2xloginretrycount; |
| 4494 | |
| 4495 | /* Enable ZIO. */ |
| 4496 | if (!vha->flags.init_done) { |
| 4497 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 4498 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4499 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 4500 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 4501 | } |
| 4502 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 4503 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 4504 | vha->flags.process_response_queue = 0; |
| 4505 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 4506 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4507 | |
| 4508 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
| 4509 | "(%d us).\n", vha->host_no, ha->zio_mode, |
| 4510 | ha->zio_timer * 100)); |
| 4511 | qla_printk(KERN_INFO, ha, |
| 4512 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4513 | ha->zio_mode, ha->zio_timer * 100); |
| 4514 | |
| 4515 | icb->firmware_options_2 |= cpu_to_le32( |
| 4516 | (uint32_t)ha->zio_mode); |
| 4517 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 4518 | vha->flags.process_response_queue = 1; |
| 4519 | } |
| 4520 | |
| 4521 | if (rval) { |
| 4522 | DEBUG2_3(printk(KERN_WARNING |
| 4523 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
| 4524 | } |
| 4525 | return (rval); |
| 4526 | } |
| 4527 | |
| 4528 | void |
| 4529 | qla81xx_update_fw_options(scsi_qla_host_t *ha) |
| 4530 | { |
| 4531 | } |