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