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