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