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