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