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