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