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