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