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