Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 07e264b | 2011-03-30 11:46:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2011 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 | 0107109 | 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 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 38 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 39 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 40 | static int qla25xx_init_queues(struct qla_hw_data *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 41 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 42 | /* SRB Extensions ---------------------------------------------------------- */ |
| 43 | |
| 44 | static void |
| 45 | qla2x00_ctx_sp_timeout(unsigned long __data) |
| 46 | { |
| 47 | srb_t *sp = (srb_t *)__data; |
| 48 | struct srb_ctx *ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 49 | struct srb_iocb *iocb; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 50 | fc_port_t *fcport = sp->fcport; |
| 51 | struct qla_hw_data *ha = fcport->vha->hw; |
| 52 | struct req_que *req; |
| 53 | unsigned long flags; |
| 54 | |
| 55 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 56 | req = ha->req_q_map[0]; |
| 57 | req->outstanding_cmds[sp->handle] = NULL; |
| 58 | ctx = sp->ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 59 | iocb = ctx->u.iocb_cmd; |
| 60 | iocb->timeout(sp); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 61 | iocb->free(sp); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 62 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 63 | } |
| 64 | |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 65 | static void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 66 | qla2x00_ctx_sp_free(srb_t *sp) |
| 67 | { |
| 68 | struct srb_ctx *ctx = sp->ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 69 | struct srb_iocb *iocb = ctx->u.iocb_cmd; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 70 | struct scsi_qla_host *vha = sp->fcport->vha; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 71 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 72 | del_timer(&iocb->timer); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 73 | kfree(iocb); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 74 | kfree(ctx); |
| 75 | mempool_free(sp, sp->fcport->vha->hw->srb_mempool); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 76 | |
| 77 | QLA_VHA_MARK_NOT_BUSY(vha); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | inline srb_t * |
| 81 | qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size, |
| 82 | unsigned long tmo) |
| 83 | { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 84 | srb_t *sp = NULL; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 85 | struct qla_hw_data *ha = vha->hw; |
| 86 | struct srb_ctx *ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 87 | struct srb_iocb *iocb; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 88 | uint8_t bail; |
| 89 | |
| 90 | QLA_VHA_MARK_BUSY(vha, bail); |
| 91 | if (bail) |
| 92 | return NULL; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 93 | |
| 94 | sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL); |
| 95 | if (!sp) |
| 96 | goto done; |
| 97 | ctx = kzalloc(size, GFP_KERNEL); |
| 98 | if (!ctx) { |
| 99 | mempool_free(sp, ha->srb_mempool); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 100 | sp = NULL; |
| 101 | goto done; |
| 102 | } |
| 103 | iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL); |
| 104 | if (!iocb) { |
| 105 | mempool_free(sp, ha->srb_mempool); |
| 106 | sp = NULL; |
| 107 | kfree(ctx); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 108 | goto done; |
| 109 | } |
| 110 | |
| 111 | memset(sp, 0, sizeof(*sp)); |
| 112 | sp->fcport = fcport; |
| 113 | sp->ctx = ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 114 | ctx->u.iocb_cmd = iocb; |
| 115 | iocb->free = qla2x00_ctx_sp_free; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 116 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 117 | init_timer(&iocb->timer); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 118 | if (!tmo) |
| 119 | goto done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 120 | iocb->timer.expires = jiffies + tmo * HZ; |
| 121 | iocb->timer.data = (unsigned long)sp; |
| 122 | iocb->timer.function = qla2x00_ctx_sp_timeout; |
| 123 | add_timer(&iocb->timer); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 124 | done: |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 125 | if (!sp) |
| 126 | QLA_VHA_MARK_NOT_BUSY(vha); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 127 | return sp; |
| 128 | } |
| 129 | |
| 130 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 131 | |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 132 | static inline unsigned long |
| 133 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 134 | { |
| 135 | unsigned long tmo; |
| 136 | struct qla_hw_data *ha = vha->hw; |
| 137 | |
| 138 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 139 | tmo = ha->r_a_tov / 10 * 2; |
| 140 | if (!IS_FWI2_CAPABLE(ha)) { |
| 141 | /* |
| 142 | * Except for earlier ISPs where the timeout is seeded from the |
| 143 | * initialization control block. |
| 144 | */ |
| 145 | tmo = ha->login_timeout; |
| 146 | } |
| 147 | return tmo; |
| 148 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 149 | |
| 150 | static void |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 151 | qla2x00_async_iocb_timeout(srb_t *sp) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 152 | { |
| 153 | fc_port_t *fcport = sp->fcport; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 154 | struct srb_ctx *ctx = sp->ctx; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 155 | |
| 156 | DEBUG2(printk(KERN_WARNING |
Andrew Vasquez | d3fa9e7 | 2010-05-28 15:08:16 -0700 | [diff] [blame] | 157 | "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n", |
| 158 | fcport->vha->host_no, sp->handle, |
| 159 | ctx->name, fcport->d_id.b.domain, |
| 160 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 161 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 162 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 163 | if (ctx->type == SRB_LOGIN_CMD) { |
| 164 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 165 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 166 | /* Retry as needed. */ |
| 167 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 168 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 169 | QLA_LOGIO_LOGIN_RETRIED : 0; |
| 170 | qla2x00_post_async_login_done_work(fcport->vha, fcport, |
| 171 | lio->u.logio.data); |
| 172 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 175 | static void |
| 176 | qla2x00_async_login_ctx_done(srb_t *sp) |
| 177 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 178 | struct srb_ctx *ctx = sp->ctx; |
| 179 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 180 | |
| 181 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 182 | lio->u.logio.data); |
| 183 | lio->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 184 | } |
| 185 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 186 | int |
| 187 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 188 | uint16_t *data) |
| 189 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 190 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 191 | struct srb_ctx *ctx; |
| 192 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 193 | int rval; |
| 194 | |
| 195 | rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 196 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 197 | qla2x00_get_async_timeout(vha) + 2); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 198 | if (!sp) |
| 199 | goto done; |
| 200 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 201 | ctx = sp->ctx; |
| 202 | ctx->type = SRB_LOGIN_CMD; |
| 203 | ctx->name = "login"; |
| 204 | lio = ctx->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 205 | lio->timeout = qla2x00_async_iocb_timeout; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 206 | lio->done = qla2x00_async_login_ctx_done; |
| 207 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 208 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 209 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 210 | rval = qla2x00_start_sp(sp); |
| 211 | if (rval != QLA_SUCCESS) |
| 212 | goto done_free_sp; |
| 213 | |
| 214 | DEBUG2(printk(KERN_DEBUG |
| 215 | "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x " |
| 216 | "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 217 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 218 | fcport->login_retry)); |
| 219 | return rval; |
| 220 | |
| 221 | done_free_sp: |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 222 | lio->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 223 | done: |
| 224 | return rval; |
| 225 | } |
| 226 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 227 | static void |
| 228 | qla2x00_async_logout_ctx_done(srb_t *sp) |
| 229 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 230 | struct srb_ctx *ctx = sp->ctx; |
| 231 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 232 | |
| 233 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 234 | lio->u.logio.data); |
| 235 | lio->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 238 | int |
| 239 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 240 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 241 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 242 | struct srb_ctx *ctx; |
| 243 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 244 | int rval; |
| 245 | |
| 246 | rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 247 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 248 | qla2x00_get_async_timeout(vha) + 2); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 249 | if (!sp) |
| 250 | goto done; |
| 251 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 252 | ctx = sp->ctx; |
| 253 | ctx->type = SRB_LOGOUT_CMD; |
| 254 | ctx->name = "logout"; |
| 255 | lio = ctx->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 256 | lio->timeout = qla2x00_async_iocb_timeout; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 257 | lio->done = qla2x00_async_logout_ctx_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 258 | rval = qla2x00_start_sp(sp); |
| 259 | if (rval != QLA_SUCCESS) |
| 260 | goto done_free_sp; |
| 261 | |
| 262 | DEBUG2(printk(KERN_DEBUG |
| 263 | "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n", |
| 264 | fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 265 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 266 | return rval; |
| 267 | |
| 268 | done_free_sp: |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 269 | lio->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 270 | done: |
| 271 | return rval; |
| 272 | } |
| 273 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 274 | static void |
| 275 | qla2x00_async_adisc_ctx_done(srb_t *sp) |
| 276 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 277 | struct srb_ctx *ctx = sp->ctx; |
| 278 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 279 | |
| 280 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 281 | lio->u.logio.data); |
| 282 | lio->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | int |
| 286 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 287 | uint16_t *data) |
| 288 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 289 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 290 | struct srb_ctx *ctx; |
| 291 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 292 | int rval; |
| 293 | |
| 294 | rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 295 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 296 | qla2x00_get_async_timeout(vha) + 2); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 297 | if (!sp) |
| 298 | goto done; |
| 299 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 300 | ctx = sp->ctx; |
| 301 | ctx->type = SRB_ADISC_CMD; |
| 302 | ctx->name = "adisc"; |
| 303 | lio = ctx->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 304 | lio->timeout = qla2x00_async_iocb_timeout; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 305 | lio->done = qla2x00_async_adisc_ctx_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 306 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 307 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 308 | rval = qla2x00_start_sp(sp); |
| 309 | if (rval != QLA_SUCCESS) |
| 310 | goto done_free_sp; |
| 311 | |
| 312 | DEBUG2(printk(KERN_DEBUG |
| 313 | "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n", |
| 314 | fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 315 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 316 | |
| 317 | return rval; |
| 318 | |
| 319 | done_free_sp: |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 320 | lio->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 321 | done: |
| 322 | return rval; |
| 323 | } |
| 324 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 325 | static void |
| 326 | qla2x00_async_tm_cmd_ctx_done(srb_t *sp) |
| 327 | { |
| 328 | struct srb_ctx *ctx = sp->ctx; |
| 329 | struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd; |
| 330 | |
| 331 | qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb); |
| 332 | iocb->free(sp); |
| 333 | } |
| 334 | |
| 335 | int |
| 336 | qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun, |
| 337 | uint32_t tag) |
| 338 | { |
| 339 | struct scsi_qla_host *vha = fcport->vha; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 340 | srb_t *sp; |
| 341 | struct srb_ctx *ctx; |
| 342 | struct srb_iocb *tcf; |
| 343 | int rval; |
| 344 | |
| 345 | rval = QLA_FUNCTION_FAILED; |
| 346 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 347 | qla2x00_get_async_timeout(vha) + 2); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 348 | if (!sp) |
| 349 | goto done; |
| 350 | |
| 351 | ctx = sp->ctx; |
| 352 | ctx->type = SRB_TM_CMD; |
| 353 | ctx->name = "tmf"; |
| 354 | tcf = ctx->u.iocb_cmd; |
| 355 | tcf->u.tmf.flags = flags; |
| 356 | tcf->u.tmf.lun = lun; |
| 357 | tcf->u.tmf.data = tag; |
| 358 | tcf->timeout = qla2x00_async_iocb_timeout; |
| 359 | tcf->done = qla2x00_async_tm_cmd_ctx_done; |
| 360 | |
| 361 | rval = qla2x00_start_sp(sp); |
| 362 | if (rval != QLA_SUCCESS) |
| 363 | goto done_free_sp; |
| 364 | |
| 365 | DEBUG2(printk(KERN_DEBUG |
| 366 | "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n", |
| 367 | fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 368 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 369 | |
| 370 | return rval; |
| 371 | |
| 372 | done_free_sp: |
| 373 | tcf->free(sp); |
| 374 | done: |
| 375 | return rval; |
| 376 | } |
| 377 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 378 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 379 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 380 | uint16_t *data) |
| 381 | { |
| 382 | int rval; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 383 | |
| 384 | switch (data[0]) { |
| 385 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | a4f92a3 | 2011-03-30 11:46:31 -0700 | [diff] [blame] | 386 | /* |
| 387 | * Driver must validate login state - If PRLI not complete, |
| 388 | * force a relogin attempt via implicit LOGO, PLOGI, and PRLI |
| 389 | * requests. |
| 390 | */ |
| 391 | rval = qla2x00_get_port_database(vha, fcport, 0); |
| 392 | if (rval != QLA_SUCCESS) { |
| 393 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
| 394 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 395 | break; |
| 396 | } |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 397 | if (fcport->flags & FCF_FCP2_DEVICE) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 398 | qla2x00_post_async_adisc_work(vha, fcport, data); |
| 399 | break; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 400 | } |
| 401 | qla2x00_update_fcport(vha, fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 402 | break; |
| 403 | case MBS_COMMAND_ERROR: |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 404 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 405 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 406 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 407 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 408 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 409 | break; |
| 410 | case MBS_PORT_ID_USED: |
| 411 | fcport->loop_id = data[1]; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 412 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 413 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 414 | break; |
| 415 | case MBS_LOOP_ID_USED: |
| 416 | fcport->loop_id++; |
| 417 | rval = qla2x00_find_new_loop_id(vha, fcport); |
| 418 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 419 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 420 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 421 | break; |
| 422 | } |
| 423 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 424 | break; |
| 425 | } |
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 | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 430 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 431 | uint16_t *data) |
| 432 | { |
| 433 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 434 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 437 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 438 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 439 | uint16_t *data) |
| 440 | { |
| 441 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 442 | qla2x00_update_fcport(vha, fcport); |
| 443 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 444 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 445 | } |
| 446 | |
| 447 | /* Retry login. */ |
| 448 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 449 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 450 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 451 | else |
Andrew Vasquez | 80d7944 | 2011-03-30 11:46:17 -0700 | [diff] [blame] | 452 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 453 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 454 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 455 | } |
| 456 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 457 | void |
| 458 | qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 459 | struct srb_iocb *iocb) |
| 460 | { |
| 461 | int rval; |
| 462 | uint32_t flags; |
| 463 | uint16_t lun; |
| 464 | |
| 465 | flags = iocb->u.tmf.flags; |
| 466 | lun = (uint16_t)iocb->u.tmf.lun; |
| 467 | |
| 468 | /* Issue Marker IOCB */ |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 469 | rval = qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 470 | vha->hw->rsp_q_map[0], fcport->loop_id, lun, |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 471 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 472 | |
| 473 | if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) { |
| 474 | DEBUG2_3_11(printk(KERN_WARNING |
| 475 | "%s(%ld): TM IOCB failed (%x).\n", |
| 476 | __func__, vha->host_no, rval)); |
| 477 | } |
| 478 | |
| 479 | return; |
| 480 | } |
| 481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | /****************************************************************************/ |
| 483 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 484 | /****************************************************************************/ |
| 485 | |
| 486 | /* |
| 487 | * qla2x00_initialize_adapter |
| 488 | * Initialize board. |
| 489 | * |
| 490 | * Input: |
| 491 | * ha = adapter block pointer. |
| 492 | * |
| 493 | * Returns: |
| 494 | * 0 = success |
| 495 | */ |
| 496 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 497 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | { |
| 499 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 500 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 501 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 504 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 505 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 506 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 507 | ha->flags.pci_channel_io_perm_failure = 0; |
| 508 | ha->flags.eeh_busy = 0; |
Andrew Vasquez | 794a569 | 2010-12-21 16:00:21 -0800 | [diff] [blame] | 509 | ha->flags.thermal_supported = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 510 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 511 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 512 | vha->device_flags = DFLG_NO_CABLE; |
| 513 | vha->dpc_flags = 0; |
| 514 | vha->flags.management_server_logged_in = 0; |
| 515 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | ha->isp_abort_cnt = 0; |
| 517 | ha->beacon_blink_led = 0; |
| 518 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 519 | set_bit(0, ha->req_qid_map); |
| 520 | set_bit(0, ha->rsp_qid_map); |
| 521 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 522 | qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 523 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | if (rval) { |
Andrew Vasquez | 7c98a04 | 2007-01-29 10:22:29 -0800 | [diff] [blame] | 525 | DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 526 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | return (rval); |
| 528 | } |
| 529 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 530 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 532 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 533 | if (rval) { |
| 534 | DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 535 | vha->host_no)); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 536 | return (rval); |
| 537 | } |
| 538 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 539 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 540 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 542 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 543 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 545 | if (ha->flags.disable_serdes) { |
| 546 | /* Mask HBA via NVRAM settings? */ |
| 547 | qla_printk(KERN_INFO, ha, "Masking HBA WWPN " |
| 548 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 549 | vha->port_name[0], vha->port_name[1], |
| 550 | vha->port_name[2], vha->port_name[3], |
| 551 | vha->port_name[4], vha->port_name[5], |
| 552 | vha->port_name[6], vha->port_name[7]); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 553 | return QLA_FUNCTION_FAILED; |
| 554 | } |
| 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n"); |
| 557 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 558 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 559 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 560 | if (rval) |
| 561 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 562 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 563 | if (rval) |
| 564 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 566 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 567 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 568 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 569 | if (!ha->cs84xx) { |
| 570 | qla_printk(KERN_ERR, ha, |
| 571 | "Unable to configure ISP84XX.\n"); |
| 572 | return QLA_FUNCTION_FAILED; |
| 573 | } |
| 574 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 575 | rval = qla2x00_init_rings(vha); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 576 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 578 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 579 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 580 | rval = qla84xx_init_chip(vha); |
| 581 | if (rval != QLA_SUCCESS) { |
| 582 | qla_printk(KERN_ERR, ha, |
| 583 | "Unable to initialize ISP84XX.\n"); |
| 584 | qla84xx_put_chip(vha); |
| 585 | } |
| 586 | } |
| 587 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 588 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 589 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | return (rval); |
| 592 | } |
| 593 | |
| 594 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 595 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | * @ha: HA context |
| 597 | * |
| 598 | * Returns 0 on success. |
| 599 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 600 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 601 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 603 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 604 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 605 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 606 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 609 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 611 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 612 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 614 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 615 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 617 | /* Get PCI bus information. */ |
| 618 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 619 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 620 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 621 | |
| 622 | return QLA_SUCCESS; |
| 623 | } |
| 624 | |
| 625 | /** |
| 626 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 627 | * @ha: HA context |
| 628 | * |
| 629 | * Returns 0 on success. |
| 630 | */ |
| 631 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 632 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 633 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 634 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 635 | unsigned long flags = 0; |
| 636 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 637 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 638 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 639 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 640 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 641 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 642 | |
| 643 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 644 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 645 | |
| 646 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 647 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 648 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 649 | |
| 650 | /* |
| 651 | * If this is a 2300 card and not 2312, reset the |
| 652 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 653 | * the 2310 also reports itself as a 2300 so we need to get the |
| 654 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 655 | * not a 2310. |
| 656 | */ |
| 657 | if (IS_QLA2300(ha)) { |
| 658 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 659 | |
| 660 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 661 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 662 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 663 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 664 | break; |
| 665 | |
| 666 | udelay(10); |
| 667 | } |
| 668 | |
| 669 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 670 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 671 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 672 | |
| 673 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 674 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 675 | |
| 676 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 677 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 678 | |
| 679 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 680 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 681 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 682 | |
| 683 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 684 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 685 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 686 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 687 | break; |
| 688 | |
| 689 | udelay(10); |
| 690 | } |
| 691 | |
| 692 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 693 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 694 | |
| 695 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 696 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 697 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 698 | |
| 699 | /* Get PCI bus information. */ |
| 700 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 701 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 702 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 703 | |
| 704 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | } |
| 706 | |
| 707 | /** |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 708 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 709 | * @ha: HA context |
| 710 | * |
| 711 | * Returns 0 on success. |
| 712 | */ |
| 713 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 714 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 715 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 716 | uint16_t w; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 717 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 718 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 719 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 720 | |
| 721 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 722 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 723 | |
| 724 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 725 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 726 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 727 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 728 | |
| 729 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 730 | |
| 731 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 732 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 733 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 734 | |
| 735 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 736 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 737 | pcie_set_readrq(ha->pdev, 2048); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 738 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 739 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 740 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 741 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 742 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 743 | /* Get PCI bus information. */ |
| 744 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 745 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 746 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 747 | |
| 748 | return QLA_SUCCESS; |
| 749 | } |
| 750 | |
| 751 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 752 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 753 | * @ha: HA context |
| 754 | * |
| 755 | * Returns 0 on success. |
| 756 | */ |
| 757 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 758 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 759 | { |
| 760 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 761 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 762 | |
| 763 | pci_set_master(ha->pdev); |
| 764 | pci_try_set_mwi(ha->pdev); |
| 765 | |
| 766 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 767 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 768 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 769 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 770 | |
| 771 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
| 772 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 773 | pcie_set_readrq(ha->pdev, 2048); |
| 774 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 775 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 776 | |
| 777 | ha->chip_revision = ha->pdev->revision; |
| 778 | |
| 779 | return QLA_SUCCESS; |
| 780 | } |
| 781 | |
| 782 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | * qla2x00_isp_firmware() - Choose firmware image. |
| 784 | * @ha: HA context |
| 785 | * |
| 786 | * Returns 0 on success. |
| 787 | */ |
| 788 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 789 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | { |
| 791 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 792 | uint16_t loop_id, topo, sw_cap; |
| 793 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 794 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | |
| 796 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 797 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | |
| 799 | if (ha->flags.disable_risc_code_load) { |
| 800 | DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 801 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 802 | qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n"); |
| 803 | |
| 804 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 805 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 806 | if (rval == QLA_SUCCESS) { |
| 807 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 808 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 809 | &area, &domain, &topo, &sw_cap); |
| 810 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | if (rval) { |
| 814 | DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 815 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | } |
| 817 | |
| 818 | return (rval); |
| 819 | } |
| 820 | |
| 821 | /** |
| 822 | * qla2x00_reset_chip() - Reset ISP chip. |
| 823 | * @ha: HA context |
| 824 | * |
| 825 | * Returns 0 on success. |
| 826 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 827 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 828 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | { |
| 830 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 831 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 832 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | uint16_t cmd; |
| 835 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 836 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 837 | return; |
| 838 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 839 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | |
| 841 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 842 | |
| 843 | /* Turn off master enable */ |
| 844 | cmd = 0; |
| 845 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 846 | cmd &= ~PCI_COMMAND_MASTER; |
| 847 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 848 | |
| 849 | if (!IS_QLA2100(ha)) { |
| 850 | /* Pause RISC. */ |
| 851 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 852 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 853 | for (cnt = 0; cnt < 30000; cnt++) { |
| 854 | if ((RD_REG_WORD(®->hccr) & |
| 855 | HCCR_RISC_PAUSE) != 0) |
| 856 | break; |
| 857 | udelay(100); |
| 858 | } |
| 859 | } else { |
| 860 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 861 | udelay(10); |
| 862 | } |
| 863 | |
| 864 | /* Select FPM registers. */ |
| 865 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 866 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 867 | |
| 868 | /* FPM Soft Reset. */ |
| 869 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 870 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 871 | |
| 872 | /* Toggle Fpm Reset. */ |
| 873 | if (!IS_QLA2200(ha)) { |
| 874 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 875 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 876 | } |
| 877 | |
| 878 | /* Select frame buffer registers. */ |
| 879 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 880 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 881 | |
| 882 | /* Reset frame buffer FIFOs. */ |
| 883 | if (IS_QLA2200(ha)) { |
| 884 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 885 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 886 | } else { |
| 887 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 888 | |
| 889 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 890 | for (cnt = 0; cnt < 3000; cnt++) { |
| 891 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 892 | break; |
| 893 | udelay(100); |
| 894 | } |
| 895 | } |
| 896 | |
| 897 | /* Select RISC module registers. */ |
| 898 | WRT_REG_WORD(®->ctrl_status, 0); |
| 899 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 900 | |
| 901 | /* Reset RISC processor. */ |
| 902 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 903 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 904 | |
| 905 | /* Release RISC processor. */ |
| 906 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 907 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 908 | } |
| 909 | |
| 910 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 911 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 912 | |
| 913 | /* Reset ISP chip. */ |
| 914 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 915 | |
| 916 | /* Wait for RISC to recover from reset. */ |
| 917 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 918 | /* |
| 919 | * It is necessary to for a delay here since the card doesn't |
| 920 | * respond to PCI reads during a reset. On some architectures |
| 921 | * this will result in an MCA. |
| 922 | */ |
| 923 | udelay(20); |
| 924 | for (cnt = 30000; cnt; cnt--) { |
| 925 | if ((RD_REG_WORD(®->ctrl_status) & |
| 926 | CSR_ISP_SOFT_RESET) == 0) |
| 927 | break; |
| 928 | udelay(100); |
| 929 | } |
| 930 | } else |
| 931 | udelay(10); |
| 932 | |
| 933 | /* Reset RISC processor. */ |
| 934 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 935 | |
| 936 | WRT_REG_WORD(®->semaphore, 0); |
| 937 | |
| 938 | /* Release RISC processor. */ |
| 939 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 940 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 941 | |
| 942 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 943 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 944 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | |
| 947 | udelay(100); |
| 948 | } |
| 949 | } else |
| 950 | udelay(100); |
| 951 | |
| 952 | /* Turn on master enable */ |
| 953 | cmd |= PCI_COMMAND_MASTER; |
| 954 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 955 | |
| 956 | /* Disable RISC pause on FPM parity error. */ |
| 957 | if (!IS_QLA2100(ha)) { |
| 958 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 959 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 960 | } |
| 961 | |
| 962 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 963 | } |
| 964 | |
| 965 | /** |
Madhuranath Iyengar | b1d4698 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 966 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 967 | * |
| 968 | * Returns 0 on success. |
| 969 | */ |
| 970 | int |
| 971 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 972 | { |
| 973 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 974 | |
| 975 | return qla81xx_write_mpi_register(vha, mb); |
| 976 | } |
| 977 | |
| 978 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 979 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 980 | * @ha: HA context |
| 981 | * |
| 982 | * Returns 0 on success. |
| 983 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 984 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 985 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 986 | { |
| 987 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 988 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 989 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 990 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 991 | uint16_t wd; |
Madhuranath Iyengar | b1d4698 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 992 | static int abts_cnt; /* ISP abort retry counts */ |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 993 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 994 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 995 | |
| 996 | /* Reset RISC. */ |
| 997 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 998 | for (cnt = 0; cnt < 30000; cnt++) { |
| 999 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 1000 | break; |
| 1001 | |
| 1002 | udelay(10); |
| 1003 | } |
| 1004 | |
| 1005 | WRT_REG_DWORD(®->ctrl_status, |
| 1006 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1007 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1008 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1009 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1010 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1011 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1012 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 1013 | udelay(5); |
| 1014 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1015 | barrier(); |
| 1016 | } |
| 1017 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1018 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1019 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1020 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 1021 | udelay(5); |
| 1022 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1023 | barrier(); |
| 1024 | } |
| 1025 | |
Madhuranath Iyengar | b1d4698 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1026 | /* If required, do an MPI FW reset now */ |
| 1027 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 1028 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 1029 | if (++abts_cnt < 5) { |
| 1030 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1031 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 1032 | } else { |
| 1033 | /* |
| 1034 | * We exhausted the ISP abort retries. We have to |
| 1035 | * set the board offline. |
| 1036 | */ |
| 1037 | abts_cnt = 0; |
| 1038 | vha->flags.online = 0; |
| 1039 | } |
| 1040 | } |
| 1041 | } |
| 1042 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1043 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 1044 | RD_REG_DWORD(®->hccr); |
| 1045 | |
| 1046 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 1047 | RD_REG_DWORD(®->hccr); |
| 1048 | |
| 1049 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 1050 | RD_REG_DWORD(®->hccr); |
| 1051 | |
| 1052 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1053 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 1054 | udelay(5); |
| 1055 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1056 | barrier(); |
| 1057 | } |
| 1058 | |
| 1059 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1060 | |
| 1061 | if (IS_NOPOLLING_TYPE(ha)) |
| 1062 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1063 | } |
| 1064 | |
| 1065 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1066 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 1067 | * @ha: HA context |
| 1068 | * |
| 1069 | * Returns 0 on success. |
| 1070 | */ |
| 1071 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1072 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1073 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1074 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1075 | |
| 1076 | if (pci_channel_offline(ha->pdev) && |
| 1077 | ha->flags.pci_channel_io_perm_failure) { |
| 1078 | return; |
| 1079 | } |
| 1080 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1081 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1082 | |
| 1083 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1084 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 1089 | * @ha: HA context |
| 1090 | * |
| 1091 | * Returns 0 on success. |
| 1092 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1093 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1094 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | { |
| 1096 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1097 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1098 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1099 | unsigned long flags = 0; |
| 1100 | uint16_t data; |
| 1101 | uint32_t cnt; |
| 1102 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1103 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
| 1105 | /* Assume a failed state */ |
| 1106 | rval = QLA_FUNCTION_FAILED; |
| 1107 | |
| 1108 | DEBUG3(printk("scsi(%ld): Testing device at %lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1109 | vha->host_no, (u_long)®->flash_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1110 | |
| 1111 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1112 | |
| 1113 | /* Reset ISP chip. */ |
| 1114 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1115 | |
| 1116 | /* |
| 1117 | * We need to have a delay here since the card will not respond while |
| 1118 | * in reset causing an MCA on some architectures. |
| 1119 | */ |
| 1120 | udelay(20); |
| 1121 | data = qla2x00_debounce_register(®->ctrl_status); |
| 1122 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 1123 | udelay(5); |
| 1124 | data = RD_REG_WORD(®->ctrl_status); |
| 1125 | barrier(); |
| 1126 | } |
| 1127 | |
| 1128 | if (!cnt) |
| 1129 | goto chip_diag_failed; |
| 1130 | |
| 1131 | DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n", |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 1132 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
| 1134 | /* Reset RISC processor. */ |
| 1135 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1136 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1137 | |
| 1138 | /* Workaround for QLA2312 PCI parity error */ |
| 1139 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1140 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 1141 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 1142 | udelay(5); |
| 1143 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1144 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | } else |
| 1147 | udelay(10); |
| 1148 | |
| 1149 | if (!cnt) |
| 1150 | goto chip_diag_failed; |
| 1151 | |
| 1152 | /* Check product ID of chip */ |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 1153 | DEBUG3(printk("scsi(%ld): Checking product ID of chip\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1154 | |
| 1155 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 1156 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 1157 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 1158 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 1159 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 1160 | mb[3] != PROD_ID_3) { |
| 1161 | qla_printk(KERN_WARNING, ha, |
| 1162 | "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]); |
| 1163 | |
| 1164 | goto chip_diag_failed; |
| 1165 | } |
| 1166 | ha->product_id[0] = mb[1]; |
| 1167 | ha->product_id[1] = mb[2]; |
| 1168 | ha->product_id[2] = mb[3]; |
| 1169 | ha->product_id[3] = mb[4]; |
| 1170 | |
| 1171 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1172 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 1174 | else |
| 1175 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1176 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | |
| 1178 | if (IS_QLA2200(ha) && |
| 1179 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 1180 | /* Limit firmware transfer size with a 2200A */ |
| 1181 | DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1182 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1184 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | ha->fw_transfer_size = 128; |
| 1186 | } |
| 1187 | |
| 1188 | /* Wrap Incoming Mailboxes Test. */ |
| 1189 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1190 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1191 | DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no)); |
| 1192 | rval = qla2x00_mbx_reg_test(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | if (rval) { |
| 1194 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1195 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | qla_printk(KERN_WARNING, ha, |
| 1197 | "Failed mailbox send register test\n"); |
| 1198 | } |
| 1199 | else { |
| 1200 | /* Flag a successful rval */ |
| 1201 | rval = QLA_SUCCESS; |
| 1202 | } |
| 1203 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1204 | |
| 1205 | chip_diag_failed: |
| 1206 | if (rval) |
| 1207 | DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1208 | "****\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | |
| 1210 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1211 | |
| 1212 | return (rval); |
| 1213 | } |
| 1214 | |
| 1215 | /** |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1216 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 1217 | * @ha: HA context |
| 1218 | * |
| 1219 | * Returns 0 on success. |
| 1220 | */ |
| 1221 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1222 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1223 | { |
| 1224 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1225 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1226 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1227 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1228 | if (IS_QLA82XX(ha)) |
| 1229 | return QLA_SUCCESS; |
| 1230 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1231 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1232 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1233 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1234 | if (rval) { |
| 1235 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1236 | vha->host_no)); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1237 | qla_printk(KERN_WARNING, ha, |
| 1238 | "Failed mailbox send register test\n"); |
| 1239 | } else { |
| 1240 | /* Flag a successful rval */ |
| 1241 | rval = QLA_SUCCESS; |
| 1242 | } |
| 1243 | |
| 1244 | return rval; |
| 1245 | } |
| 1246 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1247 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1248 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1249 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1250 | int rval; |
| 1251 | uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1252 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1253 | dma_addr_t tc_dma; |
| 1254 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1255 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1256 | struct req_que *req = ha->req_q_map[0]; |
| 1257 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1258 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1259 | if (ha->fw_dump) { |
| 1260 | qla_printk(KERN_WARNING, ha, |
| 1261 | "Firmware dump previously allocated.\n"); |
| 1262 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1263 | } |
| 1264 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1265 | ha->fw_dumped = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1266 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1267 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1268 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 1269 | } else if (IS_QLA23XX(ha)) { |
| 1270 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 1271 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 1272 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1273 | } else if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1274 | if (IS_QLA81XX(ha)) |
| 1275 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 1276 | else if (IS_QLA25XX(ha)) |
| 1277 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 1278 | else |
| 1279 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1280 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 1281 | sizeof(uint32_t); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1282 | if (ha->mqenable) |
| 1283 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1284 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1285 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1286 | goto try_eft; |
| 1287 | |
| 1288 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 1289 | GFP_KERNEL); |
| 1290 | if (!tc) { |
| 1291 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 1292 | "(%d KB) for FCE.\n", FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1293 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1294 | } |
| 1295 | |
| 1296 | memset(tc, 0, FCE_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1297 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1298 | ha->fce_mb, &ha->fce_bufs); |
| 1299 | if (rval) { |
| 1300 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 1301 | "FCE (%d).\n", rval); |
| 1302 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 1303 | tc_dma); |
| 1304 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1305 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1306 | } |
| 1307 | |
| 1308 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n", |
| 1309 | FCE_SIZE / 1024); |
| 1310 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1311 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1312 | ha->flags.fce_enabled = 1; |
| 1313 | ha->fce_dma = tc_dma; |
| 1314 | ha->fce = tc; |
| 1315 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1316 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1317 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1318 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1319 | if (!tc) { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1320 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 1321 | "(%d KB) for EFT.\n", EFT_SIZE / 1024); |
| 1322 | goto cont_alloc; |
| 1323 | } |
| 1324 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 1325 | memset(tc, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1326 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1327 | if (rval) { |
| 1328 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 1329 | "EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1330 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 1331 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1332 | goto cont_alloc; |
| 1333 | } |
| 1334 | |
| 1335 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n", |
| 1336 | EFT_SIZE / 1024); |
| 1337 | |
| 1338 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1339 | ha->eft_dma = tc_dma; |
| 1340 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1341 | } |
| 1342 | cont_alloc: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1343 | req_q_size = req->length * sizeof(request_t); |
| 1344 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1345 | |
| 1346 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1347 | dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size; |
Andrew Vasquez | bb99de6 | 2009-01-05 11:18:08 -0800 | [diff] [blame] | 1348 | ha->chain_offset = dump_size; |
| 1349 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1350 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1351 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1352 | if (!ha->fw_dump) { |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1353 | qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for " |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1354 | "firmware dump!!!\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1355 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1356 | if (ha->fce) { |
| 1357 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 1358 | ha->fce_dma); |
| 1359 | ha->fce = NULL; |
| 1360 | ha->fce_dma = 0; |
| 1361 | } |
| 1362 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1363 | if (ha->eft) { |
| 1364 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 1365 | ha->eft_dma); |
| 1366 | ha->eft = NULL; |
| 1367 | ha->eft_dma = 0; |
| 1368 | } |
| 1369 | return; |
| 1370 | } |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1371 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n", |
| 1372 | dump_size / 1024); |
| 1373 | |
| 1374 | ha->fw_dump_len = dump_size; |
| 1375 | ha->fw_dump->signature[0] = 'Q'; |
| 1376 | ha->fw_dump->signature[1] = 'L'; |
| 1377 | ha->fw_dump->signature[2] = 'G'; |
| 1378 | ha->fw_dump->signature[3] = 'C'; |
| 1379 | ha->fw_dump->version = __constant_htonl(1); |
| 1380 | |
| 1381 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 1382 | ha->fw_dump->mem_size = htonl(mem_size); |
| 1383 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 1384 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 1385 | |
| 1386 | ha->fw_dump->eft_size = htonl(eft_size); |
| 1387 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 1388 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 1389 | |
| 1390 | ha->fw_dump->header_size = |
| 1391 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1392 | } |
| 1393 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1394 | static int |
| 1395 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 1396 | { |
| 1397 | #define MPS_MASK 0xe0 |
| 1398 | int rval; |
| 1399 | uint16_t dc; |
| 1400 | uint32_t dw; |
| 1401 | struct qla_hw_data *ha = vha->hw; |
| 1402 | |
| 1403 | if (!IS_QLA81XX(vha->hw)) |
| 1404 | return QLA_SUCCESS; |
| 1405 | |
| 1406 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 1407 | if (rval != QLA_SUCCESS) { |
| 1408 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1409 | "Sync-MPI: Unable to acquire semaphore.\n")); |
| 1410 | goto done; |
| 1411 | } |
| 1412 | |
| 1413 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 1414 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 1415 | if (rval != QLA_SUCCESS) { |
| 1416 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1417 | "Sync-MPI: Unable to read sync.\n")); |
| 1418 | goto done_release; |
| 1419 | } |
| 1420 | |
| 1421 | dc &= MPS_MASK; |
| 1422 | if (dc == (dw & MPS_MASK)) |
| 1423 | goto done_release; |
| 1424 | |
| 1425 | dw &= ~MPS_MASK; |
| 1426 | dw |= dc; |
| 1427 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 1428 | if (rval != QLA_SUCCESS) { |
| 1429 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1430 | "Sync-MPI: Unable to gain sync.\n")); |
| 1431 | } |
| 1432 | |
| 1433 | done_release: |
| 1434 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 1435 | if (rval != QLA_SUCCESS) { |
| 1436 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1437 | "Sync-MPI: Unable to release semaphore.\n")); |
| 1438 | } |
| 1439 | |
| 1440 | done: |
| 1441 | return rval; |
| 1442 | } |
| 1443 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1444 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1445 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 1446 | * @ha: HA context |
| 1447 | * |
| 1448 | * Returns 0 on success. |
| 1449 | */ |
| 1450 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1451 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | { |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1453 | int rval; |
| 1454 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1455 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1456 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1457 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1458 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1459 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1460 | if (IS_QLA82XX(ha)) { |
| 1461 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1462 | if (rval == QLA_SUCCESS) { |
| 1463 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1464 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1465 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1466 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1467 | } |
| 1468 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1469 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1470 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 1471 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1472 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 1473 | RD_REG_WORD(®->hccr); |
| 1474 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1475 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1477 | qla81xx_mpi_sync(vha); |
| 1478 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1479 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1480 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1481 | if (rval == QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1483 | "code.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1485 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1486 | if (rval == QLA_SUCCESS) { |
| 1487 | /* Start firmware execution. */ |
| 1488 | DEBUG(printk("scsi(%ld): Checksum OK, start " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1489 | "firmware.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1490 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1491 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1493 | if (rval == QLA_SUCCESS) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1494 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1495 | fw_major_version = ha->fw_major_version; |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1496 | rval = qla2x00_get_fw_version(vha, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | &ha->fw_major_version, |
| 1498 | &ha->fw_minor_version, |
| 1499 | &ha->fw_subminor_version, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1500 | &ha->fw_attributes, &ha->fw_memory_size, |
Andrew Vasquez | 55a9615 | 2009-03-24 09:08:03 -0700 | [diff] [blame] | 1501 | ha->mpi_version, &ha->mpi_capabilities, |
| 1502 | ha->phy_version); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1503 | if (rval != QLA_SUCCESS) |
| 1504 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1505 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1506 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1507 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1508 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1509 | if ((!ha->max_npiv_vports) || |
| 1510 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1511 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1512 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1513 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1514 | } |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1515 | qla2x00_get_resource_cnts(vha, NULL, |
| 1516 | &ha->fw_xcb_count, NULL, NULL, |
Andrew Vasquez | f3a0a77 | 2009-10-13 15:16:49 -0700 | [diff] [blame] | 1517 | &ha->max_npiv_vports, NULL); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1518 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1519 | if (!fw_major_version && ql2xallocfwdump) { |
| 1520 | if (!IS_QLA82XX(ha)) |
| 1521 | qla2x00_alloc_fw_dump(vha); |
| 1522 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | } |
| 1524 | } else { |
| 1525 | DEBUG2(printk(KERN_INFO |
| 1526 | "scsi(%ld): ISP Firmware failed checksum.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1527 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | } |
| 1529 | } |
| 1530 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1531 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1532 | /* Enable proper parity. */ |
| 1533 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1534 | if (IS_QLA2300(ha)) |
| 1535 | /* SRAM parity */ |
| 1536 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1537 | else |
| 1538 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1539 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1540 | RD_REG_WORD(®->hccr); |
| 1541 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1542 | } |
| 1543 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1544 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
| 1545 | uint32_t size; |
| 1546 | |
| 1547 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 1548 | if (rval == QLA_SUCCESS) { |
| 1549 | ha->flags.fac_supported = 1; |
| 1550 | ha->fdt_block_size = size << 2; |
| 1551 | } else { |
| 1552 | qla_printk(KERN_ERR, ha, |
| 1553 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 1554 | ha->fw_major_version, ha->fw_minor_version, |
| 1555 | ha->fw_subminor_version); |
| 1556 | } |
| 1557 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1558 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1559 | if (rval) { |
| 1560 | DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1561 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | } |
| 1563 | |
| 1564 | return (rval); |
| 1565 | } |
| 1566 | |
| 1567 | /** |
| 1568 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1569 | * @ha: HA context |
| 1570 | * |
| 1571 | * Beginning of request ring has initialization control block already built |
| 1572 | * by nvram config routine. |
| 1573 | * |
| 1574 | * Returns 0 on success. |
| 1575 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1576 | void |
| 1577 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | { |
| 1579 | uint16_t cnt; |
| 1580 | response_t *pkt; |
| 1581 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1582 | rsp->ring_ptr = rsp->ring; |
| 1583 | rsp->ring_index = 0; |
| 1584 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1585 | pkt = rsp->ring_ptr; |
| 1586 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | pkt->signature = RESPONSE_PROCESSED; |
| 1588 | pkt++; |
| 1589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | /** |
| 1593 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1594 | * @ha: HA context |
| 1595 | * |
| 1596 | * Returns 0 on success. |
| 1597 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1598 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1599 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | { |
| 1601 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1602 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1603 | |
| 1604 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1605 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | |
| 1607 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1608 | return; |
| 1609 | |
| 1610 | /* Serial Link options. */ |
| 1611 | DEBUG3(printk("scsi(%ld): Serial link options:\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1612 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options, |
| 1614 | sizeof(ha->fw_seriallink_options))); |
| 1615 | |
| 1616 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1617 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1618 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1619 | |
| 1620 | /* 1G settings */ |
| 1621 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1622 | emphasis = (ha->fw_seriallink_options[2] & |
| 1623 | (BIT_4 | BIT_3)) >> 3; |
| 1624 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1625 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1626 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1627 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1628 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1629 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1630 | if (rx_sens == 0x0) |
| 1631 | rx_sens = 0x3; |
| 1632 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1633 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1634 | ha->fw_options[10] |= BIT_5 | |
| 1635 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1636 | (tx_sens & (BIT_1 | BIT_0)); |
| 1637 | |
| 1638 | /* 2G settings */ |
| 1639 | swing = (ha->fw_seriallink_options[2] & |
| 1640 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1641 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1642 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1643 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1644 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1645 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1646 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1647 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1648 | if (rx_sens == 0x0) |
| 1649 | rx_sens = 0x3; |
| 1650 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1651 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1652 | ha->fw_options[11] |= BIT_5 | |
| 1653 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1654 | (tx_sens & (BIT_1 | BIT_0)); |
| 1655 | } |
| 1656 | |
| 1657 | /* FCP2 options. */ |
| 1658 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1659 | ha->fw_options[3] |= BIT_13; |
| 1660 | |
| 1661 | /* LED scheme. */ |
| 1662 | if (ha->flags.enable_led_scheme) |
| 1663 | ha->fw_options[2] |= BIT_12; |
| 1664 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1665 | /* Detect ISP6312. */ |
| 1666 | if (IS_QLA6312(ha)) |
| 1667 | ha->fw_options[2] |= BIT_13; |
| 1668 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1670 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | } |
| 1672 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1673 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1674 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1675 | { |
| 1676 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1677 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1678 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1679 | if (IS_QLA82XX(ha)) |
| 1680 | return; |
| 1681 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1682 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1683 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1684 | return; |
| 1685 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1686 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1687 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1688 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1689 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1690 | if (rval != QLA_SUCCESS) { |
| 1691 | qla_printk(KERN_WARNING, ha, |
| 1692 | "Unable to update Serial Link options (%x).\n", rval); |
| 1693 | } |
| 1694 | } |
| 1695 | |
| 1696 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1697 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1698 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1699 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1700 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1701 | struct req_que *req = ha->req_q_map[0]; |
| 1702 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1703 | |
| 1704 | /* Setup ring parameters in initialization control block. */ |
| 1705 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1706 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1707 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 1708 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 1709 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1710 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1711 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1712 | 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] | 1713 | |
| 1714 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1715 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1716 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1717 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1718 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1719 | } |
| 1720 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1721 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1722 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1723 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1724 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1725 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
| 1726 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1727 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1728 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1729 | uint16_t rid = 0; |
| 1730 | struct req_que *req = ha->req_q_map[0]; |
| 1731 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1732 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1733 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1734 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1735 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1736 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1737 | icb->request_q_length = cpu_to_le16(req->length); |
| 1738 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 1739 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1740 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1741 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1742 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1743 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1744 | if (ha->mqenable) { |
| 1745 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 1746 | icb->rid = __constant_cpu_to_le16(rid); |
| 1747 | if (ha->flags.msix_enabled) { |
| 1748 | msix = &ha->msix_entries[1]; |
| 1749 | DEBUG2_17(printk(KERN_INFO |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1750 | "Registering vector 0x%x for base que\n", msix->entry)); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1751 | icb->msix = cpu_to_le16(msix->entry); |
| 1752 | } |
| 1753 | /* Use alternate PCI bus number */ |
| 1754 | if (MSB(rid)) |
| 1755 | icb->firmware_options_2 |= |
| 1756 | __constant_cpu_to_le32(BIT_19); |
| 1757 | /* Use alternate PCI devfn */ |
| 1758 | if (LSB(rid)) |
| 1759 | icb->firmware_options_2 |= |
| 1760 | __constant_cpu_to_le32(BIT_18); |
| 1761 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1762 | /* Use Disable MSIX Handshake mode for capable adapters */ |
| 1763 | if (IS_MSIX_NACK_CAPABLE(ha)) { |
| 1764 | icb->firmware_options_2 &= |
| 1765 | __constant_cpu_to_le32(~BIT_22); |
| 1766 | ha->flags.disable_msix_handshake = 1; |
| 1767 | qla_printk(KERN_INFO, ha, |
| 1768 | "MSIX Handshake Disable Mode turned on\n"); |
| 1769 | } else { |
| 1770 | icb->firmware_options_2 |= |
| 1771 | __constant_cpu_to_le32(BIT_22); |
| 1772 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1773 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1774 | |
| 1775 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 1776 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 1777 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 1778 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 1779 | } else { |
| 1780 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 1781 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 1782 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 1783 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 1784 | } |
| 1785 | /* PCI posting */ |
| 1786 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1787 | } |
| 1788 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1789 | /** |
| 1790 | * qla2x00_init_rings() - Initializes firmware. |
| 1791 | * @ha: HA context |
| 1792 | * |
| 1793 | * Beginning of request ring has initialization control block already built |
| 1794 | * by nvram config routine. |
| 1795 | * |
| 1796 | * Returns 0 on success. |
| 1797 | */ |
| 1798 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1799 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1800 | { |
| 1801 | int rval; |
| 1802 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1803 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1804 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1805 | struct req_que *req; |
| 1806 | struct rsp_que *rsp; |
| 1807 | struct scsi_qla_host *vp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1808 | struct mid_init_cb_24xx *mid_init_cb = |
| 1809 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
| 1811 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1812 | |
| 1813 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1814 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1815 | req = ha->req_q_map[que]; |
| 1816 | if (!req) |
| 1817 | continue; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1818 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1819 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1821 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1822 | |
| 1823 | /* Initialize firmware. */ |
| 1824 | req->ring_ptr = req->ring; |
| 1825 | req->ring_index = 0; |
| 1826 | req->cnt = req->length; |
| 1827 | } |
| 1828 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1829 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1830 | rsp = ha->rsp_q_map[que]; |
| 1831 | if (!rsp) |
| 1832 | continue; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1833 | /* Initialize response queue entries */ |
| 1834 | qla2x00_init_response_q_entries(rsp); |
| 1835 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1837 | spin_lock(&ha->vport_slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1838 | /* Clear RSCN queue. */ |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1839 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 1840 | vp->rscn_in_ptr = 0; |
| 1841 | vp->rscn_out_ptr = 0; |
| 1842 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1843 | |
Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1844 | spin_unlock(&ha->vport_slock); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1845 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1846 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1847 | |
| 1848 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1849 | |
| 1850 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1851 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1853 | DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1854 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1855 | if (ha->flags.npiv_supported) { |
| 1856 | if (ha->operating_mode == LOOP) |
| 1857 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1858 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1859 | } |
| 1860 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1861 | if (IS_FWI2_CAPABLE(ha)) { |
| 1862 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
| 1863 | mid_init_cb->init_cb.execution_throttle = |
| 1864 | cpu_to_le16(ha->fw_xcb_count); |
| 1865 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1866 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1867 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | if (rval) { |
| 1869 | DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1870 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1871 | } else { |
| 1872 | DEBUG3(printk("scsi(%ld): Init firmware -- success.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1873 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1874 | } |
| 1875 | |
| 1876 | return (rval); |
| 1877 | } |
| 1878 | |
| 1879 | /** |
| 1880 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 1881 | * @ha: HA context |
| 1882 | * |
| 1883 | * Returns 0 on success. |
| 1884 | */ |
| 1885 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1886 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | { |
| 1888 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1889 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 1891 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1892 | uint16_t state[5]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1893 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | |
| 1895 | rval = QLA_SUCCESS; |
| 1896 | |
| 1897 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1898 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1899 | |
| 1900 | /* |
| 1901 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 1902 | * our own processing. |
| 1903 | */ |
| 1904 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 1905 | wait_time = min_wait; |
| 1906 | } |
| 1907 | |
| 1908 | /* Min wait time if loop down */ |
| 1909 | mtime = jiffies + (min_wait * HZ); |
| 1910 | |
| 1911 | /* wait time before firmware ready */ |
| 1912 | wtime = jiffies + (wait_time * HZ); |
| 1913 | |
| 1914 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1915 | if (!vha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1916 | qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n"); |
| 1917 | |
| 1918 | DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1919 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
| 1921 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1922 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1924 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1925 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1927 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
| 1928 | DEBUG16(printk("scsi(%ld): fw_state=%x " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1929 | "84xx=%x.\n", vha->host_no, state[0], |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1930 | state[2])); |
| 1931 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 1932 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
| 1933 | DEBUG16(printk("scsi(%ld): Sending " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1934 | "verify iocb.\n", vha->host_no)); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1935 | |
| 1936 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1937 | rval = qla84xx_init_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1938 | if (rval != QLA_SUCCESS) |
| 1939 | break; |
| 1940 | |
| 1941 | /* Add time taken to initialize. */ |
| 1942 | cs84xx_time = jiffies - cs84xx_time; |
| 1943 | wtime += cs84xx_time; |
| 1944 | mtime += cs84xx_time; |
| 1945 | DEBUG16(printk("scsi(%ld): Increasing " |
| 1946 | "wait time by %ld. New time %ld\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1947 | vha->host_no, cs84xx_time, wtime)); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1948 | } |
| 1949 | } else if (state[0] == FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | DEBUG(printk("scsi(%ld): F/W Ready - OK \n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1951 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1953 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1954 | &ha->login_timeout, &ha->r_a_tov); |
| 1955 | |
| 1956 | rval = QLA_SUCCESS; |
| 1957 | break; |
| 1958 | } |
| 1959 | |
| 1960 | rval = QLA_FUNCTION_FAILED; |
| 1961 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1962 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1963 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1965 | * other than Wait for Login. |
| 1966 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | if (time_after_eq(jiffies, mtime)) { |
| 1968 | qla_printk(KERN_INFO, ha, |
| 1969 | "Cable is unplugged...\n"); |
| 1970 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1971 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1972 | break; |
| 1973 | } |
| 1974 | } |
| 1975 | } else { |
| 1976 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4 | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 1977 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 1978 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1979 | break; |
| 1980 | } |
| 1981 | |
| 1982 | if (time_after_eq(jiffies, wtime)) |
| 1983 | break; |
| 1984 | |
| 1985 | /* Delay for a while */ |
| 1986 | msleep(500); |
| 1987 | |
| 1988 | DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1989 | vha->host_no, state[0], jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1990 | } while (1); |
| 1991 | |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1992 | DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n", |
| 1993 | vha->host_no, state[0], state[1], state[2], state[3], state[4], |
| 1994 | jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
| 1996 | if (rval) { |
| 1997 | DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1998 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1999 | } |
| 2000 | |
| 2001 | return (rval); |
| 2002 | } |
| 2003 | |
| 2004 | /* |
| 2005 | * qla2x00_configure_hba |
| 2006 | * Setup adapter context. |
| 2007 | * |
| 2008 | * Input: |
| 2009 | * ha = adapter state pointer. |
| 2010 | * |
| 2011 | * Returns: |
| 2012 | * 0 = success |
| 2013 | * |
| 2014 | * Context: |
| 2015 | * Kernel context. |
| 2016 | */ |
| 2017 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2018 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2019 | { |
| 2020 | int rval; |
| 2021 | uint16_t loop_id; |
| 2022 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2023 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | uint8_t al_pa; |
| 2025 | uint8_t area; |
| 2026 | uint8_t domain; |
| 2027 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2028 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | |
| 2030 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2031 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2032 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2033 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2034 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Andrew Vasquez | 7a44b86 | 2010-12-21 16:00:23 -0800 | [diff] [blame] | 2035 | IS_QLA8XXX_TYPE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2036 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
| 2037 | DEBUG2(printk("%s(%ld) Loop is in a transition state\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2038 | __func__, vha->host_no)); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2039 | } else { |
| 2040 | qla_printk(KERN_WARNING, ha, |
| 2041 | "ERROR -- Unable to get host loop ID.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2042 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2043 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2044 | return (rval); |
| 2045 | } |
| 2046 | |
| 2047 | if (topo == 4) { |
| 2048 | qla_printk(KERN_INFO, ha, |
| 2049 | "Cannot get topology - retrying.\n"); |
| 2050 | return (QLA_FUNCTION_FAILED); |
| 2051 | } |
| 2052 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2053 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | |
| 2055 | /* initialize */ |
| 2056 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 2057 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2058 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | |
| 2060 | switch (topo) { |
| 2061 | case 0: |
| 2062 | DEBUG3(printk("scsi(%ld): HBA in NL topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2063 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | ha->current_topology = ISP_CFG_NL; |
| 2065 | strcpy(connect_type, "(Loop)"); |
| 2066 | break; |
| 2067 | |
| 2068 | case 1: |
| 2069 | DEBUG3(printk("scsi(%ld): HBA in FL topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2070 | vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2071 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2072 | ha->current_topology = ISP_CFG_FL; |
| 2073 | strcpy(connect_type, "(FL_Port)"); |
| 2074 | break; |
| 2075 | |
| 2076 | case 2: |
| 2077 | DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2078 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2079 | ha->operating_mode = P2P; |
| 2080 | ha->current_topology = ISP_CFG_N; |
| 2081 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 2082 | break; |
| 2083 | |
| 2084 | case 3: |
| 2085 | DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2086 | vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2087 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2088 | ha->operating_mode = P2P; |
| 2089 | ha->current_topology = ISP_CFG_F; |
| 2090 | strcpy(connect_type, "(F_Port)"); |
| 2091 | break; |
| 2092 | |
| 2093 | default: |
| 2094 | DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. " |
| 2095 | "Using NL.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2096 | vha->host_no, topo)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | ha->current_topology = ISP_CFG_NL; |
| 2098 | strcpy(connect_type, "(Loop)"); |
| 2099 | break; |
| 2100 | } |
| 2101 | |
| 2102 | /* Save Host port and loop ID. */ |
| 2103 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2104 | vha->d_id.b.domain = domain; |
| 2105 | vha->d_id.b.area = area; |
| 2106 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2108 | if (!vha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | qla_printk(KERN_INFO, ha, |
| 2110 | "Topology - %s, Host Loop address 0x%x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2111 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2112 | |
| 2113 | if (rval) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2114 | DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2115 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2116 | DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | } |
| 2118 | |
| 2119 | return(rval); |
| 2120 | } |
| 2121 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2122 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2123 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 2124 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2125 | { |
| 2126 | char *st, *en; |
| 2127 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2128 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2129 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2130 | !IS_QLA8XXX_TYPE(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2131 | |
| 2132 | if (memcmp(model, BINZERO, len) != 0) { |
| 2133 | strncpy(ha->model_number, model, len); |
| 2134 | st = en = ha->model_number; |
| 2135 | en += len - 1; |
| 2136 | while (en > st) { |
| 2137 | if (*en != 0x20 && *en != 0x00) |
| 2138 | break; |
| 2139 | *en-- = '\0'; |
| 2140 | } |
| 2141 | |
| 2142 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2143 | if (use_tbl && |
| 2144 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2145 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2146 | strncpy(ha->model_desc, |
| 2147 | qla2x00_model_name[index * 2 + 1], |
| 2148 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2149 | } else { |
| 2150 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2151 | if (use_tbl && |
| 2152 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2153 | index < QLA_MODEL_NAMES) { |
| 2154 | strcpy(ha->model_number, |
| 2155 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2156 | strncpy(ha->model_desc, |
| 2157 | qla2x00_model_name[index * 2 + 1], |
| 2158 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2159 | } else { |
| 2160 | strcpy(ha->model_number, def); |
| 2161 | } |
| 2162 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2163 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2164 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2165 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2166 | } |
| 2167 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2168 | /* On sparc systems, obtain port and node WWN from firmware |
| 2169 | * properties. |
| 2170 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2171 | 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] | 2172 | { |
| 2173 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2174 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2175 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2176 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 2177 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2178 | int len; |
| 2179 | |
| 2180 | val = of_get_property(dp, "port-wwn", &len); |
| 2181 | if (val && len >= WWN_SIZE) |
| 2182 | memcpy(nv->port_name, val, WWN_SIZE); |
| 2183 | |
| 2184 | val = of_get_property(dp, "node-wwn", &len); |
| 2185 | if (val && len >= WWN_SIZE) |
| 2186 | memcpy(nv->node_name, val, WWN_SIZE); |
| 2187 | #endif |
| 2188 | } |
| 2189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | /* |
| 2191 | * NVRAM configuration for ISP 2xxx |
| 2192 | * |
| 2193 | * Input: |
| 2194 | * ha = adapter block pointer. |
| 2195 | * |
| 2196 | * Output: |
| 2197 | * initialization control block in response_ring |
| 2198 | * host adapters parameters in host adapter block |
| 2199 | * |
| 2200 | * Returns: |
| 2201 | * 0 = success. |
| 2202 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2203 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2204 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2205 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2206 | int rval; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2207 | uint8_t chksum = 0; |
| 2208 | uint16_t cnt; |
| 2209 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2210 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2211 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2212 | nvram_t *nv = ha->nvram; |
| 2213 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2214 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2215 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2216 | rval = QLA_SUCCESS; |
| 2217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2218 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2219 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | ha->nvram_base = 0; |
| 2221 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 2222 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 2223 | ha->nvram_base = 0x80; |
| 2224 | |
| 2225 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2226 | ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2227 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 2228 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2229 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2230 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2231 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2232 | |
| 2233 | /* Bad NVRAM data, set defaults parameters. */ |
| 2234 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 2235 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 2236 | /* Reset NVRAM data. */ |
| 2237 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 2238 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 2239 | nv->nvram_version); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2240 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 2241 | "invalid -- WWPN) defaults.\n"); |
| 2242 | |
| 2243 | /* |
| 2244 | * Set default initialization control block. |
| 2245 | */ |
| 2246 | memset(nv, 0, ha->nvram_size); |
| 2247 | nv->parameter_block_version = ICB_VERSION; |
| 2248 | |
| 2249 | if (IS_QLA23XX(ha)) { |
| 2250 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2251 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2252 | nv->add_firmware_options[0] = BIT_5; |
| 2253 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2254 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2255 | nv->special_options[1] = BIT_7; |
| 2256 | } else if (IS_QLA2200(ha)) { |
| 2257 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2258 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2259 | nv->add_firmware_options[0] = BIT_5; |
| 2260 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2261 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2262 | } else if (IS_QLA2100(ha)) { |
| 2263 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 2264 | nv->firmware_options[1] = BIT_5; |
| 2265 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2266 | } |
| 2267 | |
| 2268 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 2269 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 2270 | nv->retry_count = 8; |
| 2271 | nv->retry_delay = 1; |
| 2272 | |
| 2273 | nv->port_name[0] = 33; |
| 2274 | nv->port_name[3] = 224; |
| 2275 | nv->port_name[4] = 139; |
| 2276 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2277 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2278 | |
| 2279 | nv->login_timeout = 4; |
| 2280 | |
| 2281 | /* |
| 2282 | * Set default host adapter parameters |
| 2283 | */ |
| 2284 | nv->host_p[1] = BIT_2; |
| 2285 | nv->reset_delay = 5; |
| 2286 | nv->port_down_retry_count = 8; |
| 2287 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 2288 | nv->link_down_timeout = 60; |
| 2289 | |
| 2290 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2291 | } |
| 2292 | |
| 2293 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 2294 | /* |
| 2295 | * The SN2 does not provide BIOS emulation which means you can't change |
| 2296 | * potentially bogus BIOS settings. Force the use of default settings |
| 2297 | * for link rate and frame size. Hope that the rest of the settings |
| 2298 | * are valid. |
| 2299 | */ |
| 2300 | if (ia64_platform_is("sn2")) { |
| 2301 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2302 | if (IS_QLA23XX(ha)) |
| 2303 | nv->special_options[1] = BIT_7; |
| 2304 | } |
| 2305 | #endif |
| 2306 | |
| 2307 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2308 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2309 | |
| 2310 | /* |
| 2311 | * Setup driver NVRAM options. |
| 2312 | */ |
| 2313 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 2314 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 2315 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 2316 | nv->firmware_options[1] &= ~BIT_4; |
| 2317 | |
| 2318 | if (IS_QLA23XX(ha)) { |
| 2319 | nv->firmware_options[0] |= BIT_2; |
| 2320 | nv->firmware_options[0] &= ~BIT_3; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2321 | nv->firmware_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2322 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2323 | |
| 2324 | if (IS_QLA2300(ha)) { |
| 2325 | if (ha->fb_rev == FPM_2310) { |
| 2326 | strcpy(ha->model_number, "QLA2310"); |
| 2327 | } else { |
| 2328 | strcpy(ha->model_number, "QLA2300"); |
| 2329 | } |
| 2330 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2331 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2332 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | } |
| 2334 | } else if (IS_QLA2200(ha)) { |
| 2335 | nv->firmware_options[0] |= BIT_2; |
| 2336 | /* |
| 2337 | * 'Point-to-point preferred, else loop' is not a safe |
| 2338 | * connection mode setting. |
| 2339 | */ |
| 2340 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 2341 | (BIT_5 | BIT_4)) { |
| 2342 | /* Force 'loop preferred, else point-to-point'. */ |
| 2343 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 2344 | nv->add_firmware_options[0] |= BIT_5; |
| 2345 | } |
| 2346 | strcpy(ha->model_number, "QLA22xx"); |
| 2347 | } else /*if (IS_QLA2100(ha))*/ { |
| 2348 | strcpy(ha->model_number, "QLA2100"); |
| 2349 | } |
| 2350 | |
| 2351 | /* |
| 2352 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 2353 | */ |
| 2354 | dptr1 = (uint8_t *)icb; |
| 2355 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 2356 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 2357 | while (cnt--) |
| 2358 | *dptr1++ = *dptr2++; |
| 2359 | |
| 2360 | /* Copy 2nd half. */ |
| 2361 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 2362 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 2363 | while (cnt--) |
| 2364 | *dptr1++ = *dptr2++; |
| 2365 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2366 | /* Use alternate WWN? */ |
| 2367 | if (nv->host_p[1] & BIT_7) { |
| 2368 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 2369 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 2370 | } |
| 2371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2372 | /* Prepare nodename */ |
| 2373 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 2374 | /* |
| 2375 | * Firmware will apply the following mask if the nodename was |
| 2376 | * not provided. |
| 2377 | */ |
| 2378 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 2379 | icb->node_name[0] &= 0xF0; |
| 2380 | } |
| 2381 | |
| 2382 | /* |
| 2383 | * Set host adapter parameters. |
| 2384 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2385 | if (nv->host_p[0] & BIT_7) |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 2386 | ql2xextended_error_logging = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2387 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 2388 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 2389 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2390 | ha->flags.disable_risc_code_load = 0; |
| 2391 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 2392 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 2393 | 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] | 2394 | 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] | 2395 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | |
| 2397 | ha->operating_mode = |
| 2398 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2399 | |
| 2400 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 2401 | sizeof(ha->fw_seriallink_options)); |
| 2402 | |
| 2403 | /* save HBA serial number */ |
| 2404 | ha->serial0 = icb->port_name[5]; |
| 2405 | ha->serial1 = icb->port_name[6]; |
| 2406 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2407 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 2408 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2409 | |
| 2410 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 2411 | |
| 2412 | ha->retry_count = nv->retry_count; |
| 2413 | |
| 2414 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2415 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | nv->login_timeout = ql2xlogintimeout; |
| 2417 | if (nv->login_timeout < 4) |
| 2418 | nv->login_timeout = 4; |
| 2419 | ha->login_timeout = nv->login_timeout; |
| 2420 | icb->login_timeout = nv->login_timeout; |
| 2421 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2422 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 2423 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2425 | ha->loop_reset_delay = nv->reset_delay; |
| 2426 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2427 | /* Link Down Timeout = 0: |
| 2428 | * |
| 2429 | * When Port Down timer expires we will start returning |
| 2430 | * I/O's to OS with "DID_NO_CONNECT". |
| 2431 | * |
| 2432 | * Link Down Timeout != 0: |
| 2433 | * |
| 2434 | * The driver waits for the link to come up after link down |
| 2435 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2436 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2437 | if (nv->link_down_timeout == 0) { |
| 2438 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2439 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2440 | } else { |
| 2441 | ha->link_down_timeout = nv->link_down_timeout; |
| 2442 | ha->loop_down_abort_time = |
| 2443 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2445 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2446 | /* |
| 2447 | * Need enough time to try and get the port back. |
| 2448 | */ |
| 2449 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 2450 | if (qlport_down_retry) |
| 2451 | ha->port_down_retry_count = qlport_down_retry; |
| 2452 | /* Set login_retry_count */ |
| 2453 | ha->login_retry_count = nv->retry_count; |
| 2454 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 2455 | ha->port_down_retry_count > 3) |
| 2456 | ha->login_retry_count = ha->port_down_retry_count; |
| 2457 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 2458 | ha->login_retry_count = ha->port_down_retry_count; |
| 2459 | if (ql2xloginretrycount) |
| 2460 | ha->login_retry_count = ql2xloginretrycount; |
| 2461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2462 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 2463 | icb->command_resource_count = 0; |
| 2464 | icb->immediate_notify_resource_count = 0; |
| 2465 | icb->timeout = __constant_cpu_to_le16(0); |
| 2466 | |
| 2467 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2468 | /* Enable RIO */ |
| 2469 | icb->firmware_options[0] &= ~BIT_3; |
| 2470 | icb->add_firmware_options[0] &= |
| 2471 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2472 | icb->add_firmware_options[0] |= BIT_2; |
| 2473 | icb->response_accumulation_timer = 3; |
| 2474 | icb->interrupt_delay_timer = 5; |
| 2475 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2476 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2478 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2479 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2480 | ha->zio_mode = icb->add_firmware_options[0] & |
| 2481 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2482 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 2483 | icb->interrupt_delay_timer: 2; |
| 2484 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2485 | icb->add_firmware_options[0] &= |
| 2486 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2487 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2488 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2489 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 2490 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2491 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2492 | "delay (%d us).\n", vha->host_no, ha->zio_mode, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2493 | ha->zio_timer * 100)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2494 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2495 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 2496 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2498 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 2499 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2500 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | } |
| 2502 | } |
| 2503 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2504 | if (rval) { |
| 2505 | DEBUG2_3(printk(KERN_WARNING |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2506 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2507 | } |
| 2508 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2509 | } |
| 2510 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2511 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2512 | qla2x00_rport_del(void *data) |
| 2513 | { |
| 2514 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2515 | struct fc_rport *rport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2516 | unsigned long flags; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2517 | |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2518 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2519 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2520 | fcport->drport = NULL; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2521 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2522 | if (rport) |
| 2523 | fc_remote_port_delete(rport); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2524 | } |
| 2525 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | /** |
| 2527 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 2528 | * @ha: HA context |
| 2529 | * @flags: allocation flags |
| 2530 | * |
| 2531 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 2532 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2533 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2534 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | { |
| 2536 | fc_port_t *fcport; |
| 2537 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2538 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 2539 | if (!fcport) |
| 2540 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2541 | |
| 2542 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2543 | fcport->vha = vha; |
| 2544 | fcport->vp_idx = vha->vp_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2545 | fcport->port_type = FCT_UNKNOWN; |
| 2546 | fcport->loop_id = FC_NO_LOOP_ID; |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2547 | qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2548 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2549 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2550 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2551 | } |
| 2552 | |
| 2553 | /* |
| 2554 | * qla2x00_configure_loop |
| 2555 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 2556 | * |
| 2557 | * Input: |
| 2558 | * ha = adapter block pointer. |
| 2559 | * |
| 2560 | * Returns: |
| 2561 | * 0 = success. |
| 2562 | * 1 = error. |
| 2563 | * 2 = database was full and device was not configured. |
| 2564 | */ |
| 2565 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2566 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | { |
| 2568 | int rval; |
| 2569 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2570 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | rval = QLA_SUCCESS; |
| 2572 | |
| 2573 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2574 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 2575 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | if (rval != QLA_SUCCESS) { |
| 2577 | DEBUG(printk("scsi(%ld): Unable to configure HBA.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2578 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | return (rval); |
| 2580 | } |
| 2581 | } |
| 2582 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2583 | save_flags = flags = vha->dpc_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2585 | vha->host_no, flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2586 | |
| 2587 | /* |
| 2588 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 2589 | * both at the same time. |
| 2590 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2591 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 2592 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 2594 | qla2x00_get_data_rate(vha); |
| 2595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2596 | /* Determine what we need to do */ |
| 2597 | if (ha->current_topology == ISP_CFG_FL && |
| 2598 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2599 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2600 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2601 | set_bit(RSCN_UPDATE, &flags); |
| 2602 | |
| 2603 | } else if (ha->current_topology == ISP_CFG_F && |
| 2604 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2605 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2606 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | set_bit(RSCN_UPDATE, &flags); |
| 2608 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2609 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2610 | } else if (ha->current_topology == ISP_CFG_N) { |
| 2611 | clear_bit(RSCN_UPDATE, &flags); |
| 2612 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2613 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 2615 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2616 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | set_bit(RSCN_UPDATE, &flags); |
| 2618 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2619 | } |
| 2620 | |
| 2621 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2622 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2623 | rval = QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2624 | else |
| 2625 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2626 | } |
| 2627 | |
| 2628 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2629 | if (LOOP_TRANSITION(vha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2630 | rval = QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2631 | else |
| 2632 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | } |
| 2634 | |
| 2635 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2636 | if (atomic_read(&vha->loop_down_timer) || |
| 2637 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2638 | rval = QLA_FUNCTION_FAILED; |
| 2639 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2640 | atomic_set(&vha->loop_state, LOOP_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2641 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2642 | DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | } |
| 2644 | } |
| 2645 | |
| 2646 | if (rval) { |
| 2647 | DEBUG2_3(printk("%s(%ld): *** FAILED ***\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2648 | __func__, vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2649 | } else { |
| 2650 | DEBUG3(printk("%s: exiting normally\n", __func__)); |
| 2651 | } |
| 2652 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2653 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2654 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2655 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2656 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2657 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2658 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 2659 | if (!IS_ALOGIO_CAPABLE(ha)) |
| 2660 | vha->flags.rscn_queue_overflow = 1; |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2661 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | return (rval); |
| 2665 | } |
| 2666 | |
| 2667 | |
| 2668 | |
| 2669 | /* |
| 2670 | * qla2x00_configure_local_loop |
| 2671 | * Updates Fibre Channel Device Database with local loop devices. |
| 2672 | * |
| 2673 | * Input: |
| 2674 | * ha = adapter block pointer. |
| 2675 | * |
| 2676 | * Returns: |
| 2677 | * 0 = success. |
| 2678 | */ |
| 2679 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2680 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2681 | { |
| 2682 | int rval, rval2; |
| 2683 | int found_devs; |
| 2684 | int found; |
| 2685 | fc_port_t *fcport, *new_fcport; |
| 2686 | |
| 2687 | uint16_t index; |
| 2688 | uint16_t entries; |
| 2689 | char *id_iter; |
| 2690 | uint16_t loop_id; |
| 2691 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2692 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | |
| 2694 | found_devs = 0; |
| 2695 | new_fcport = NULL; |
| 2696 | entries = MAX_FIBRE_DEVICES; |
| 2697 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2698 | DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no)); |
| 2699 | DEBUG3(qla2x00_get_fcal_position_map(vha, NULL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2700 | |
| 2701 | /* Get list of logged in devices. */ |
| 2702 | memset(ha->gid_list, 0, GID_LIST_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2703 | 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] | 2704 | &entries); |
| 2705 | if (rval != QLA_SUCCESS) |
| 2706 | goto cleanup_allocation; |
| 2707 | |
| 2708 | DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n", |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 2709 | vha->host_no, entries)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2710 | DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list, |
| 2711 | entries * sizeof(struct gid_list_info))); |
| 2712 | |
| 2713 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2714 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | if (new_fcport == NULL) { |
| 2716 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2717 | goto cleanup_allocation; |
| 2718 | } |
| 2719 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2720 | |
| 2721 | /* |
| 2722 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2723 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2724 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2726 | fcport->port_type != FCT_BROADCAST && |
| 2727 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2728 | |
| 2729 | DEBUG(printk("scsi(%ld): Marking port lost, " |
| 2730 | "loop_id=0x%04x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2731 | vha->host_no, fcport->loop_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2732 | |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2733 | qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2734 | } |
| 2735 | } |
| 2736 | |
| 2737 | /* Add devices to port list. */ |
| 2738 | id_iter = (char *)ha->gid_list; |
| 2739 | for (index = 0; index < entries; index++) { |
| 2740 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2741 | area = ((struct gid_list_info *)id_iter)->area; |
| 2742 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2743 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | loop_id = (uint16_t) |
| 2745 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2746 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2747 | loop_id = le16_to_cpu( |
| 2748 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2749 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | |
| 2751 | /* Bypass reserved domain fields. */ |
| 2752 | if ((domain & 0xf0) == 0xf0) |
| 2753 | continue; |
| 2754 | |
| 2755 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2756 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2757 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | continue; |
| 2759 | |
| 2760 | /* Bypass invalid local loop ID. */ |
| 2761 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2762 | continue; |
| 2763 | |
| 2764 | /* Fill in member data. */ |
| 2765 | new_fcport->d_id.b.domain = domain; |
| 2766 | new_fcport->d_id.b.area = area; |
| 2767 | new_fcport->d_id.b.al_pa = al_pa; |
| 2768 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2769 | new_fcport->vp_idx = vha->vp_idx; |
| 2770 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | if (rval2 != QLA_SUCCESS) { |
| 2772 | DEBUG2(printk("scsi(%ld): Failed to retrieve fcport " |
| 2773 | "information -- get_port_database=%x, " |
| 2774 | "loop_id=0x%04x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2775 | vha->host_no, rval2, new_fcport->loop_id)); |
andrew.vasquez@qlogic.com | c9d02ac | 2006-01-13 17:05:26 -0800 | [diff] [blame] | 2776 | DEBUG2(printk("scsi(%ld): Scheduling resync...\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2777 | vha->host_no)); |
| 2778 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | continue; |
| 2780 | } |
| 2781 | |
| 2782 | /* Check for matching device in port list. */ |
| 2783 | found = 0; |
| 2784 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2785 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2786 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2787 | WWN_SIZE)) |
| 2788 | continue; |
| 2789 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 2790 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | fcport->loop_id = new_fcport->loop_id; |
| 2792 | fcport->port_type = new_fcport->port_type; |
| 2793 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2794 | memcpy(fcport->node_name, new_fcport->node_name, |
| 2795 | WWN_SIZE); |
| 2796 | |
| 2797 | found++; |
| 2798 | break; |
| 2799 | } |
| 2800 | |
| 2801 | if (!found) { |
| 2802 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2803 | if (vha->vp_idx) { |
| 2804 | new_fcport->vha = vha; |
| 2805 | new_fcport->vp_idx = vha->vp_idx; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2806 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2807 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2808 | |
| 2809 | /* Allocate a new replacement fcport. */ |
| 2810 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2811 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | if (new_fcport == NULL) { |
| 2813 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2814 | goto cleanup_allocation; |
| 2815 | } |
| 2816 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2817 | } |
| 2818 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2819 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2820 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2821 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2822 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | |
| 2824 | found_devs++; |
| 2825 | } |
| 2826 | |
| 2827 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2828 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2829 | |
| 2830 | if (rval != QLA_SUCCESS) { |
| 2831 | DEBUG2(printk("scsi(%ld): Configure local loop error exit: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2832 | "rval=%x\n", vha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2833 | } |
| 2834 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2835 | return (rval); |
| 2836 | } |
| 2837 | |
| 2838 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2839 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2840 | { |
| 2841 | #define LS_UNKNOWN 2 |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2842 | static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" }; |
| 2843 | char *link_speed; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2844 | int rval; |
Harish Zunjarrao | 1bb3954 | 2009-06-17 10:30:29 -0700 | [diff] [blame] | 2845 | uint16_t mb[4]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2846 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2847 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 2848 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2849 | return; |
| 2850 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 2851 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 2852 | return; |
| 2853 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 2854 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 2855 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2856 | return; |
| 2857 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2858 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2859 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2860 | if (rval != QLA_SUCCESS) { |
| 2861 | DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA " |
| 2862 | "%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] | 2863 | vha->host_no, fcport->port_name[0], fcport->port_name[1], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2864 | fcport->port_name[2], fcport->port_name[3], |
| 2865 | fcport->port_name[4], fcport->port_name[5], |
| 2866 | fcport->port_name[6], fcport->port_name[7], rval, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2867 | fcport->fp_speed, mb[0], mb[1])); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2868 | } else { |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2869 | link_speed = link_speeds[LS_UNKNOWN]; |
| 2870 | if (fcport->fp_speed < 5) |
| 2871 | link_speed = link_speeds[fcport->fp_speed]; |
| 2872 | else if (fcport->fp_speed == 0x13) |
| 2873 | link_speed = link_speeds[5]; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2874 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 2875 | "iIDMA adjusted to %s GB/s on " |
| 2876 | "%02x%02x%02x%02x%02x%02x%02x%02x.\n", |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2877 | link_speed, fcport->port_name[0], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2878 | fcport->port_name[1], fcport->port_name[2], |
| 2879 | fcport->port_name[3], fcport->port_name[4], |
| 2880 | fcport->port_name[5], fcport->port_name[6], |
| 2881 | fcport->port_name[7])); |
| 2882 | } |
| 2883 | } |
| 2884 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2885 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2886 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2887 | { |
| 2888 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2889 | struct fc_rport *rport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2890 | struct qla_hw_data *ha = vha->hw; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2891 | unsigned long flags; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2892 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2893 | qla2x00_rport_del(fcport); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2894 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 2895 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 2896 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2897 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 2898 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 2899 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2900 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2901 | if (!rport) { |
| 2902 | qla_printk(KERN_WARNING, ha, |
| 2903 | "Unable to allocate fc remote port!\n"); |
| 2904 | return; |
| 2905 | } |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2906 | spin_lock_irqsave(fcport->vha->host->host_lock, flags); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2907 | *((fc_port_t **)rport->dd_data) = fcport; |
Madhuranath Iyengar | 044d78e | 2011-01-28 15:17:56 -0800 | [diff] [blame] | 2908 | spin_unlock_irqrestore(fcport->vha->host->host_lock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2909 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2910 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2911 | |
| 2912 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2913 | if (fcport->port_type == FCT_INITIATOR) |
| 2914 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 2915 | if (fcport->port_type == FCT_TARGET) |
| 2916 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2917 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e11 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2919 | |
| 2920 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2921 | * qla2x00_update_fcport |
| 2922 | * Updates device on list. |
| 2923 | * |
| 2924 | * Input: |
| 2925 | * ha = adapter block pointer. |
| 2926 | * fcport = port structure pointer. |
| 2927 | * |
| 2928 | * Return: |
| 2929 | * 0 - Success |
| 2930 | * BIT_0 - error |
| 2931 | * |
| 2932 | * Context: |
| 2933 | * Kernel context. |
| 2934 | */ |
| 2935 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2936 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2937 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2938 | fcport->vha = vha; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2939 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2940 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2941 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2942 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 2943 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2944 | qla2x00_reg_remote_port(vha, fcport); |
Chad Dupuis | ec426e1 | 2011-03-30 11:46:32 -0700 | [diff] [blame] | 2945 | qla2x00_set_fcport_state(fcport, FCS_ONLINE); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2946 | } |
| 2947 | |
| 2948 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2949 | * qla2x00_configure_fabric |
| 2950 | * Setup SNS devices with loop ID's. |
| 2951 | * |
| 2952 | * Input: |
| 2953 | * ha = adapter block pointer. |
| 2954 | * |
| 2955 | * Returns: |
| 2956 | * 0 = success. |
| 2957 | * BIT_0 = error |
| 2958 | */ |
| 2959 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2960 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2961 | { |
| 2962 | int rval, rval2; |
| 2963 | fc_port_t *fcport, *fcptemp; |
| 2964 | uint16_t next_loopid; |
| 2965 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2966 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2967 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2968 | struct qla_hw_data *ha = vha->hw; |
| 2969 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | |
| 2971 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2972 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2973 | loop_id = NPH_F_PORT; |
| 2974 | else |
| 2975 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2976 | 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] | 2977 | if (rval != QLA_SUCCESS) { |
| 2978 | DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2979 | "Port\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2980 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2981 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2982 | return (QLA_SUCCESS); |
| 2983 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2984 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2985 | |
| 2986 | /* Mark devices that need re-synchronization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2987 | rval2 = qla2x00_device_resync(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | if (rval2 == QLA_RSCNS_HANDLED) { |
| 2989 | /* No point doing the scan, just continue. */ |
| 2990 | return (QLA_SUCCESS); |
| 2991 | } |
| 2992 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2993 | /* FDMI support. */ |
| 2994 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2995 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 2996 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2998 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2999 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3000 | loop_id = NPH_SNS; |
| 3001 | else |
| 3002 | loop_id = SIMPLE_NAME_SERVER; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3003 | ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 3004 | 0xfc, mb, BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 3006 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 3007 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3008 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3009 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 3010 | return (QLA_SUCCESS); |
| 3011 | } |
| 3012 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3013 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 3014 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | /* EMPTY */ |
| 3016 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3017 | "TYPE failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3019 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3020 | /* EMPTY */ |
| 3021 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3022 | "Features failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3023 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3024 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3025 | /* EMPTY */ |
| 3026 | DEBUG2(printk("scsi(%ld): Register Node Name " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3027 | "failed.\n", vha->host_no)); |
| 3028 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3029 | /* EMPTY */ |
| 3030 | DEBUG2(printk("scsi(%ld): Register Symbolic " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3031 | "Node Name failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | } |
| 3033 | } |
| 3034 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3035 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3036 | if (rval != QLA_SUCCESS) |
| 3037 | break; |
| 3038 | |
| 3039 | /* |
| 3040 | * Logout all previous fabric devices marked lost, except |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3041 | * FCP2 devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3043 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3044 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | break; |
| 3046 | |
| 3047 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 3048 | continue; |
| 3049 | |
| 3050 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3051 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3052 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3053 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3054 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | fcport->port_type != FCT_INITIATOR && |
| 3056 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3057 | ha->isp_ops->fabric_logout(vha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3058 | fcport->loop_id, |
| 3059 | fcport->d_id.b.domain, |
| 3060 | fcport->d_id.b.area, |
| 3061 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3062 | fcport->loop_id = FC_NO_LOOP_ID; |
| 3063 | } |
| 3064 | } |
| 3065 | } |
| 3066 | |
| 3067 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3068 | next_loopid = ha->min_external_loopid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3069 | |
| 3070 | /* |
| 3071 | * Scan through our port list and login entries that need to be |
| 3072 | * logged in. |
| 3073 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3074 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3075 | if (atomic_read(&vha->loop_down_timer) || |
| 3076 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | break; |
| 3078 | |
| 3079 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 3080 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 3081 | continue; |
| 3082 | |
| 3083 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 3084 | fcport->loop_id = next_loopid; |
Seokmann Ju | d4486fd | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 3085 | rval = qla2x00_find_new_loop_id( |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3086 | base_vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3087 | if (rval != QLA_SUCCESS) { |
| 3088 | /* Ran out of IDs to use */ |
| 3089 | break; |
| 3090 | } |
| 3091 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3092 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3093 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3094 | } |
| 3095 | |
| 3096 | /* Exit if out of loop IDs. */ |
| 3097 | if (rval != QLA_SUCCESS) { |
| 3098 | break; |
| 3099 | } |
| 3100 | |
| 3101 | /* |
| 3102 | * Login and add the new devices to our port list. |
| 3103 | */ |
| 3104 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3105 | if (atomic_read(&vha->loop_down_timer) || |
| 3106 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3107 | break; |
| 3108 | |
| 3109 | /* Find a new loop ID to use. */ |
| 3110 | fcport->loop_id = next_loopid; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3111 | rval = qla2x00_find_new_loop_id(base_vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3112 | if (rval != QLA_SUCCESS) { |
| 3113 | /* Ran out of IDs to use */ |
| 3114 | break; |
| 3115 | } |
| 3116 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3117 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3118 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3119 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3120 | if (vha->vp_idx) { |
| 3121 | fcport->vha = vha; |
| 3122 | fcport->vp_idx = vha->vp_idx; |
| 3123 | } |
| 3124 | list_move_tail(&fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3125 | } |
| 3126 | } while (0); |
| 3127 | |
| 3128 | /* Free all new device structures not processed. */ |
| 3129 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 3130 | list_del(&fcport->list); |
| 3131 | kfree(fcport); |
| 3132 | } |
| 3133 | |
| 3134 | if (rval) { |
| 3135 | DEBUG2(printk("scsi(%ld): Configure fabric error exit: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3136 | "rval=%d\n", vha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3137 | } |
| 3138 | |
| 3139 | return (rval); |
| 3140 | } |
| 3141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3142 | /* |
| 3143 | * qla2x00_find_all_fabric_devs |
| 3144 | * |
| 3145 | * Input: |
| 3146 | * ha = adapter block pointer. |
| 3147 | * dev = database device entry pointer. |
| 3148 | * |
| 3149 | * Returns: |
| 3150 | * 0 = success. |
| 3151 | * |
| 3152 | * Context: |
| 3153 | * Kernel context. |
| 3154 | */ |
| 3155 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3156 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 3157 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3158 | { |
| 3159 | int rval; |
| 3160 | uint16_t loop_id; |
| 3161 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 3162 | int found; |
| 3163 | |
| 3164 | sw_info_t *swl; |
| 3165 | int swl_idx; |
| 3166 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3167 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3168 | struct qla_hw_data *ha = vha->hw; |
| 3169 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3170 | struct scsi_qla_host *tvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3171 | |
| 3172 | rval = QLA_SUCCESS; |
| 3173 | |
| 3174 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 4b89258 | 2008-09-11 21:22:48 -0700 | [diff] [blame] | 3175 | swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL); |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3176 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3177 | /*EMPTY*/ |
| 3178 | DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3179 | "on GA_NXT\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3180 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3181 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3182 | kfree(swl); |
| 3183 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3184 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3185 | kfree(swl); |
| 3186 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3187 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | kfree(swl); |
| 3189 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3190 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3191 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 3192 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3194 | |
| 3195 | /* If other queries succeeded probe for FC-4 type */ |
| 3196 | if (swl) |
| 3197 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | } |
| 3199 | swl_idx = 0; |
| 3200 | |
| 3201 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3202 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3203 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3204 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3205 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3206 | } |
| 3207 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3208 | /* Set start port ID scan at adapter ID. */ |
| 3209 | first_dev = 1; |
| 3210 | last_dev = 0; |
| 3211 | |
| 3212 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3213 | loop_id = ha->min_external_loopid; |
| 3214 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 3215 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | continue; |
| 3217 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3218 | if (ha->current_topology == ISP_CFG_FL && |
| 3219 | (atomic_read(&vha->loop_down_timer) || |
| 3220 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3221 | atomic_set(&vha->loop_down_timer, 0); |
| 3222 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3223 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3224 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3225 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3226 | |
| 3227 | if (swl != NULL) { |
| 3228 | if (last_dev) { |
| 3229 | wrap.b24 = new_fcport->d_id.b24; |
| 3230 | } else { |
| 3231 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 3232 | memcpy(new_fcport->node_name, |
| 3233 | swl[swl_idx].node_name, WWN_SIZE); |
| 3234 | memcpy(new_fcport->port_name, |
| 3235 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3236 | memcpy(new_fcport->fabric_port_name, |
| 3237 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 3238 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3239 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3240 | |
| 3241 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 3242 | last_dev = 1; |
| 3243 | } |
| 3244 | swl_idx++; |
| 3245 | } |
| 3246 | } else { |
| 3247 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3248 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3249 | if (rval != QLA_SUCCESS) { |
| 3250 | qla_printk(KERN_WARNING, ha, |
| 3251 | "SNS scan failed -- assuming zero-entry " |
| 3252 | "result...\n"); |
| 3253 | list_for_each_entry_safe(fcport, fcptemp, |
| 3254 | new_fcports, list) { |
| 3255 | list_del(&fcport->list); |
| 3256 | kfree(fcport); |
| 3257 | } |
| 3258 | rval = QLA_SUCCESS; |
| 3259 | break; |
| 3260 | } |
| 3261 | } |
| 3262 | |
| 3263 | /* If wrap on switch device list, exit. */ |
| 3264 | if (first_dev) { |
| 3265 | wrap.b24 = new_fcport->d_id.b24; |
| 3266 | first_dev = 0; |
| 3267 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
| 3268 | DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3269 | vha->host_no, new_fcport->d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3270 | new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa)); |
| 3271 | break; |
| 3272 | } |
| 3273 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3274 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3275 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3276 | continue; |
| 3277 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3278 | /* Bypass virtual ports of the same host. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3279 | found = 0; |
| 3280 | if (ha->num_vhosts) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3281 | unsigned long flags; |
| 3282 | |
| 3283 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3284 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3285 | if (new_fcport->d_id.b24 == vp->d_id.b24) { |
| 3286 | found = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3287 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3288 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3289 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3290 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3291 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3292 | if (found) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3293 | continue; |
| 3294 | } |
| 3295 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3296 | /* Bypass if same domain and area of adapter. */ |
| 3297 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3298 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3299 | ISP_CFG_FL) |
| 3300 | continue; |
| 3301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | /* Bypass reserved domain fields. */ |
| 3303 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 3304 | continue; |
| 3305 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3306 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3307 | if (ql2xgffidenable && |
| 3308 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 3309 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3310 | continue; |
| 3311 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3312 | /* Locate matching device in database. */ |
| 3313 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3314 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3315 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3316 | WWN_SIZE)) |
| 3317 | continue; |
| 3318 | |
| 3319 | found++; |
| 3320 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3321 | /* Update port state. */ |
| 3322 | memcpy(fcport->fabric_port_name, |
| 3323 | new_fcport->fabric_port_name, WWN_SIZE); |
| 3324 | fcport->fp_speed = new_fcport->fp_speed; |
| 3325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | /* |
| 3327 | * If address the same and state FCS_ONLINE, nothing |
| 3328 | * changed. |
| 3329 | */ |
| 3330 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 3331 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3332 | break; |
| 3333 | } |
| 3334 | |
| 3335 | /* |
| 3336 | * If device was not a fabric device before. |
| 3337 | */ |
| 3338 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3339 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3340 | fcport->loop_id = FC_NO_LOOP_ID; |
| 3341 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 3342 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3343 | break; |
| 3344 | } |
| 3345 | |
| 3346 | /* |
| 3347 | * Port ID changed or device was marked to be updated; |
| 3348 | * Log it out if still logged in and mark it for |
| 3349 | * relogin later. |
| 3350 | */ |
| 3351 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3352 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 3353 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3354 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3355 | fcport->port_type != FCT_INITIATOR && |
| 3356 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3357 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3358 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3359 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3360 | fcport->loop_id = FC_NO_LOOP_ID; |
| 3361 | } |
| 3362 | |
| 3363 | break; |
| 3364 | } |
| 3365 | |
| 3366 | if (found) |
| 3367 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | /* If device was not in our fcports list, then add it. */ |
| 3369 | list_add_tail(&new_fcport->list, new_fcports); |
| 3370 | |
| 3371 | /* Allocate a new replacement fcport. */ |
| 3372 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3373 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3375 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3377 | } |
| 3378 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 3379 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 3380 | } |
| 3381 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3382 | kfree(swl); |
| 3383 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | return (rval); |
| 3386 | } |
| 3387 | |
| 3388 | /* |
| 3389 | * qla2x00_find_new_loop_id |
| 3390 | * Scan through our port list and find a new usable loop ID. |
| 3391 | * |
| 3392 | * Input: |
| 3393 | * ha: adapter state pointer. |
| 3394 | * dev: port structure pointer. |
| 3395 | * |
| 3396 | * Returns: |
| 3397 | * qla2x00 local function return status code. |
| 3398 | * |
| 3399 | * Context: |
| 3400 | * Kernel context. |
| 3401 | */ |
Joe Carnuccio | 03bcfb5 | 2011-03-30 11:46:27 -0700 | [diff] [blame] | 3402 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3403 | 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] | 3404 | { |
| 3405 | int rval; |
| 3406 | int found; |
| 3407 | fc_port_t *fcport; |
| 3408 | uint16_t first_loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3409 | struct qla_hw_data *ha = vha->hw; |
| 3410 | struct scsi_qla_host *vp; |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3411 | struct scsi_qla_host *tvp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3412 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | |
| 3414 | rval = QLA_SUCCESS; |
| 3415 | |
| 3416 | /* Save starting loop ID. */ |
| 3417 | first_loop_id = dev->loop_id; |
| 3418 | |
| 3419 | for (;;) { |
| 3420 | /* Skip loop ID if already used by adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3421 | if (dev->loop_id == vha->loop_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3422 | dev->loop_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | |
| 3424 | /* Skip reserved loop IDs. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3425 | while (qla2x00_is_reserved_id(vha, dev->loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | dev->loop_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | |
| 3428 | /* Reset loop ID if passed the end. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3429 | if (dev->loop_id > ha->max_loop_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3430 | /* first loop ID. */ |
| 3431 | dev->loop_id = ha->min_external_loopid; |
| 3432 | } |
| 3433 | |
| 3434 | /* Check for loop ID being already in use. */ |
| 3435 | found = 0; |
| 3436 | fcport = NULL; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3437 | |
| 3438 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3439 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3440 | list_for_each_entry(fcport, &vp->vp_fcports, list) { |
| 3441 | if (fcport->loop_id == dev->loop_id && |
| 3442 | fcport != dev) { |
| 3443 | /* ID possibly in use */ |
| 3444 | found++; |
| 3445 | break; |
| 3446 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3447 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3448 | if (found) |
| 3449 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3450 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3451 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | |
| 3453 | /* If not in use then it is free to use. */ |
| 3454 | if (!found) { |
| 3455 | break; |
| 3456 | } |
| 3457 | |
| 3458 | /* ID in use. Try next value. */ |
| 3459 | dev->loop_id++; |
| 3460 | |
| 3461 | /* If wrap around. No free ID to use. */ |
| 3462 | if (dev->loop_id == first_loop_id) { |
| 3463 | dev->loop_id = FC_NO_LOOP_ID; |
| 3464 | rval = QLA_FUNCTION_FAILED; |
| 3465 | break; |
| 3466 | } |
| 3467 | } |
| 3468 | |
| 3469 | return (rval); |
| 3470 | } |
| 3471 | |
| 3472 | /* |
| 3473 | * qla2x00_device_resync |
| 3474 | * Marks devices in the database that needs resynchronization. |
| 3475 | * |
| 3476 | * Input: |
| 3477 | * ha = adapter block pointer. |
| 3478 | * |
| 3479 | * Context: |
| 3480 | * Kernel context. |
| 3481 | */ |
| 3482 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3483 | qla2x00_device_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3484 | { |
| 3485 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | uint32_t mask; |
| 3487 | fc_port_t *fcport; |
| 3488 | uint32_t rscn_entry; |
| 3489 | uint8_t rscn_out_iter; |
| 3490 | uint8_t format; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3491 | port_id_t d_id = {}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3492 | |
| 3493 | rval = QLA_RSCNS_HANDLED; |
| 3494 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3495 | while (vha->rscn_out_ptr != vha->rscn_in_ptr || |
| 3496 | vha->flags.rscn_queue_overflow) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3498 | rscn_entry = vha->rscn_queue[vha->rscn_out_ptr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3499 | format = MSB(MSW(rscn_entry)); |
| 3500 | d_id.b.domain = LSB(MSW(rscn_entry)); |
| 3501 | d_id.b.area = MSB(LSW(rscn_entry)); |
| 3502 | d_id.b.al_pa = LSB(LSW(rscn_entry)); |
| 3503 | |
| 3504 | DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = " |
| 3505 | "[%02x/%02x%02x%02x].\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3506 | vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | d_id.b.area, d_id.b.al_pa)); |
| 3508 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3509 | vha->rscn_out_ptr++; |
| 3510 | if (vha->rscn_out_ptr == MAX_RSCN_COUNT) |
| 3511 | vha->rscn_out_ptr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | |
| 3513 | /* Skip duplicate entries. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3514 | for (rscn_out_iter = vha->rscn_out_ptr; |
| 3515 | !vha->flags.rscn_queue_overflow && |
| 3516 | rscn_out_iter != vha->rscn_in_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | rscn_out_iter = (rscn_out_iter == |
| 3518 | (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) { |
| 3519 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3520 | if (rscn_entry != vha->rscn_queue[rscn_out_iter]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3521 | break; |
| 3522 | |
| 3523 | DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3524 | "entry found at [%d].\n", vha->host_no, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3525 | rscn_out_iter)); |
| 3526 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3527 | vha->rscn_out_ptr = rscn_out_iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | } |
| 3529 | |
| 3530 | /* Queue overflow, set switch default case. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3531 | if (vha->flags.rscn_queue_overflow) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3532 | DEBUG(printk("scsi(%ld): device_resync: rscn " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3533 | "overflow.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | |
| 3535 | format = 3; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3536 | vha->flags.rscn_queue_overflow = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3537 | } |
| 3538 | |
| 3539 | switch (format) { |
| 3540 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3541 | mask = 0xffffff; |
| 3542 | break; |
| 3543 | case 1: |
| 3544 | mask = 0xffff00; |
| 3545 | break; |
| 3546 | case 2: |
| 3547 | mask = 0xff0000; |
| 3548 | break; |
| 3549 | default: |
| 3550 | mask = 0x0; |
| 3551 | d_id.b24 = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3552 | vha->rscn_out_ptr = vha->rscn_in_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3553 | break; |
| 3554 | } |
| 3555 | |
| 3556 | rval = QLA_SUCCESS; |
| 3557 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3558 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 3560 | (fcport->d_id.b24 & mask) != d_id.b24 || |
| 3561 | fcport->port_type == FCT_BROADCAST) |
| 3562 | continue; |
| 3563 | |
| 3564 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3565 | if (format != 3 || |
| 3566 | fcport->port_type != FCT_INITIATOR) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3567 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3568 | 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | } |
| 3570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3571 | } |
| 3572 | } |
| 3573 | return (rval); |
| 3574 | } |
| 3575 | |
| 3576 | /* |
| 3577 | * qla2x00_fabric_dev_login |
| 3578 | * Login fabric target device and update FC port database. |
| 3579 | * |
| 3580 | * Input: |
| 3581 | * ha: adapter state pointer. |
| 3582 | * fcport: port structure list pointer. |
| 3583 | * next_loopid: contains value of a new loop ID that can be used |
| 3584 | * by the next login attempt. |
| 3585 | * |
| 3586 | * Returns: |
| 3587 | * qla2x00 local function return status code. |
| 3588 | * |
| 3589 | * Context: |
| 3590 | * Kernel context. |
| 3591 | */ |
| 3592 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3593 | 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] | 3594 | uint16_t *next_loopid) |
| 3595 | { |
| 3596 | int rval; |
| 3597 | int retry; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3598 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3599 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | |
| 3601 | rval = QLA_SUCCESS; |
| 3602 | retry = 0; |
| 3603 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3604 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3605 | if (fcport->flags & FCF_ASYNC_SENT) |
| 3606 | return rval; |
| 3607 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3608 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
| 3609 | if (!rval) |
| 3610 | return rval; |
| 3611 | } |
| 3612 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3613 | fcport->flags &= ~FCF_ASYNC_SENT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3614 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3616 | /* Send an ADISC to FCP2 devices.*/ |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3617 | opts = 0; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3618 | if (fcport->flags & FCF_FCP2_DEVICE) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3619 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3620 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3621 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3622 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3623 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3624 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3625 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3627 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | } |
| 3629 | } |
| 3630 | |
| 3631 | return (rval); |
| 3632 | } |
| 3633 | |
| 3634 | /* |
| 3635 | * qla2x00_fabric_login |
| 3636 | * Issue fabric login command. |
| 3637 | * |
| 3638 | * Input: |
| 3639 | * ha = adapter block pointer. |
| 3640 | * device = pointer to FC device type structure. |
| 3641 | * |
| 3642 | * Returns: |
| 3643 | * 0 - Login successfully |
| 3644 | * 1 - Login failed |
| 3645 | * 2 - Initiator device |
| 3646 | * 3 - Fatal error |
| 3647 | */ |
| 3648 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3649 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | uint16_t *next_loopid) |
| 3651 | { |
| 3652 | int rval; |
| 3653 | int retry; |
| 3654 | uint16_t tmp_loopid; |
| 3655 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3656 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | |
| 3658 | retry = 0; |
| 3659 | tmp_loopid = 0; |
| 3660 | |
| 3661 | for (;;) { |
| 3662 | DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x " |
| 3663 | "for port %02x%02x%02x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3664 | vha->host_no, fcport->loop_id, fcport->d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3665 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3666 | |
| 3667 | /* Login fcport on switch. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3668 | ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3670 | fcport->d_id.b.al_pa, mb, BIT_0); |
| 3671 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3672 | /* |
| 3673 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3674 | * recommends the driver perform an implicit login with |
| 3675 | * the specified ID again. The ID we just used is save |
| 3676 | * here so we return with an ID that can be tried by |
| 3677 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3678 | */ |
| 3679 | retry++; |
| 3680 | tmp_loopid = fcport->loop_id; |
| 3681 | fcport->loop_id = mb[1]; |
| 3682 | |
| 3683 | DEBUG(printk("Fabric Login: port in use - next " |
| 3684 | "loop id=0x%04x, port Id=%02x%02x%02x.\n", |
| 3685 | fcport->loop_id, fcport->d_id.b.domain, |
| 3686 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3687 | |
| 3688 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3689 | /* |
| 3690 | * Login succeeded. |
| 3691 | */ |
| 3692 | if (retry) { |
| 3693 | /* A retry occurred before. */ |
| 3694 | *next_loopid = tmp_loopid; |
| 3695 | } else { |
| 3696 | /* |
| 3697 | * No retry occurred before. Just increment the |
| 3698 | * ID value for next login. |
| 3699 | */ |
| 3700 | *next_loopid = (fcport->loop_id + 1); |
| 3701 | } |
| 3702 | |
| 3703 | if (mb[1] & BIT_0) { |
| 3704 | fcport->port_type = FCT_INITIATOR; |
| 3705 | } else { |
| 3706 | fcport->port_type = FCT_TARGET; |
| 3707 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 3708 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3709 | } |
| 3710 | } |
| 3711 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3712 | if (mb[10] & BIT_0) |
| 3713 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3714 | if (mb[10] & BIT_1) |
| 3715 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3716 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | rval = QLA_SUCCESS; |
| 3718 | break; |
| 3719 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3720 | /* |
| 3721 | * Loop ID already used, try next loop ID. |
| 3722 | */ |
| 3723 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3724 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3725 | if (rval != QLA_SUCCESS) { |
| 3726 | /* Ran out of loop IDs to use */ |
| 3727 | break; |
| 3728 | } |
| 3729 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3730 | /* |
| 3731 | * Firmware possibly timed out during login. If NO |
| 3732 | * retries are left to do then the device is declared |
| 3733 | * dead. |
| 3734 | */ |
| 3735 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3736 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3737 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3738 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3739 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | |
| 3741 | rval = 1; |
| 3742 | break; |
| 3743 | } else { |
| 3744 | /* |
| 3745 | * unrecoverable / not handled error |
| 3746 | */ |
| 3747 | DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x " |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3748 | "loop_id=%x jiffies=%lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3749 | __func__, vha->host_no, mb[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3751 | fcport->d_id.b.al_pa, fcport->loop_id, jiffies)); |
| 3752 | |
| 3753 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3754 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3755 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3756 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3757 | fcport->loop_id = FC_NO_LOOP_ID; |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3758 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | |
| 3760 | rval = 3; |
| 3761 | break; |
| 3762 | } |
| 3763 | } |
| 3764 | |
| 3765 | return (rval); |
| 3766 | } |
| 3767 | |
| 3768 | /* |
| 3769 | * qla2x00_local_device_login |
| 3770 | * Issue local device login command. |
| 3771 | * |
| 3772 | * Input: |
| 3773 | * ha = adapter block pointer. |
| 3774 | * loop_id = loop id of device to login to. |
| 3775 | * |
| 3776 | * Returns (Where's the #define!!!!): |
| 3777 | * 0 - Login successfully |
| 3778 | * 1 - Login failed |
| 3779 | * 3 - Fatal error |
| 3780 | */ |
| 3781 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3782 | 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] | 3783 | { |
| 3784 | int rval; |
| 3785 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3786 | |
| 3787 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3788 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3789 | if (rval == QLA_SUCCESS) { |
| 3790 | /* Interrogate mailbox registers for any errors */ |
| 3791 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3792 | rval = 1; |
| 3793 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3794 | /* device not in PCB table */ |
| 3795 | rval = 3; |
| 3796 | } |
| 3797 | |
| 3798 | return (rval); |
| 3799 | } |
| 3800 | |
| 3801 | /* |
| 3802 | * qla2x00_loop_resync |
| 3803 | * Resync with fibre channel devices. |
| 3804 | * |
| 3805 | * Input: |
| 3806 | * ha = adapter block pointer. |
| 3807 | * |
| 3808 | * Returns: |
| 3809 | * 0 = success |
| 3810 | */ |
| 3811 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3812 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3813 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3814 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3815 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3816 | struct req_que *req; |
| 3817 | struct rsp_que *rsp; |
| 3818 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 3819 | if (vha->hw->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3820 | req = vha->hw->req_q_map[0]; |
| 3821 | else |
| 3822 | req = vha->req; |
| 3823 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3825 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
| 3826 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 3827 | if (vha->flags.online) { |
| 3828 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3829 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3830 | wait_time = 256; |
| 3831 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3832 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3834 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3835 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 3836 | MK_SYNC_ALL); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3837 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | |
| 3839 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3840 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3841 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3842 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3844 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3845 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3846 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3847 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3848 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3849 | } |
| 3850 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3851 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3852 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3853 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3854 | if (rval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3855 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3856 | |
| 3857 | return (rval); |
| 3858 | } |
| 3859 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3860 | /* |
| 3861 | * qla2x00_perform_loop_resync |
| 3862 | * Description: This function will set the appropriate flags and call |
| 3863 | * qla2x00_loop_resync. If successful loop will be resynced |
| 3864 | * Arguments : scsi_qla_host_t pointer |
| 3865 | * returm : Success or Failure |
| 3866 | */ |
| 3867 | |
| 3868 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 3869 | { |
| 3870 | int32_t rval = 0; |
| 3871 | |
| 3872 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 3873 | /*Configure the flags so that resync happens properly*/ |
| 3874 | atomic_set(&ha->loop_down_timer, 0); |
| 3875 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 3876 | atomic_set(&ha->loop_state, LOOP_UP); |
| 3877 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 3878 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 3879 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3880 | |
| 3881 | rval = qla2x00_loop_resync(ha); |
| 3882 | } else |
| 3883 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 3884 | |
| 3885 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 3886 | } |
| 3887 | |
| 3888 | return rval; |
| 3889 | } |
| 3890 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3891 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3892 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3893 | { |
| 3894 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3895 | struct scsi_qla_host *vha; |
| 3896 | struct qla_hw_data *ha = base_vha->hw; |
| 3897 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3898 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3899 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3900 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3901 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 3902 | atomic_inc(&vha->vref_count); |
| 3903 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 3904 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3905 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 3906 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3907 | |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3908 | qla2x00_rport_del(fcport); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3909 | |
| 3910 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3911 | } |
| 3912 | } |
| 3913 | atomic_dec(&vha->vref_count); |
| 3914 | } |
| 3915 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3916 | } |
| 3917 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3918 | /* |
| 3919 | * qla82xx_quiescent_state_cleanup |
| 3920 | * Description: This function will block the new I/Os |
| 3921 | * Its not aborting any I/Os as context |
| 3922 | * is not destroyed during quiescence |
| 3923 | * Arguments: scsi_qla_host_t |
| 3924 | * return : void |
| 3925 | */ |
| 3926 | void |
| 3927 | qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha) |
| 3928 | { |
| 3929 | struct qla_hw_data *ha = vha->hw; |
| 3930 | struct scsi_qla_host *vp; |
| 3931 | |
| 3932 | qla_printk(KERN_INFO, ha, |
| 3933 | "Performing ISP error recovery - ha= %p.\n", ha); |
| 3934 | |
| 3935 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 3936 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 3937 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 3938 | qla2x00_mark_all_devices_lost(vha, 0); |
| 3939 | list_for_each_entry(vp, &ha->vp_list, list) |
| 3940 | qla2x00_mark_all_devices_lost(vha, 0); |
| 3941 | } else { |
| 3942 | if (!atomic_read(&vha->loop_down_timer)) |
| 3943 | atomic_set(&vha->loop_down_timer, |
| 3944 | LOOP_DOWN_TIME); |
| 3945 | } |
| 3946 | /* Wait for pending cmds to complete */ |
| 3947 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 3948 | } |
| 3949 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3950 | void |
| 3951 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 3952 | { |
| 3953 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3954 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3955 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 3956 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3957 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 3958 | /* For ISP82XX, driver waits for completion of the commands. |
| 3959 | * online flag should be set. |
| 3960 | */ |
| 3961 | if (!IS_QLA82XX(ha)) |
| 3962 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3963 | ha->flags.chip_reset_done = 0; |
| 3964 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3965 | ha->qla_stats.total_isp_aborts++; |
| 3966 | |
| 3967 | qla_printk(KERN_INFO, ha, |
| 3968 | "Performing ISP error recovery - ha= %p.\n", ha); |
| 3969 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 3970 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 3971 | * Driver waits for the completion of the commands. |
| 3972 | * the interrupts need to be enabled. |
| 3973 | */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3974 | if (!IS_QLA82XX(ha)) |
| 3975 | ha->isp_ops->reset_chip(vha); |
| 3976 | |
| 3977 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 3978 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 3979 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 3980 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3981 | |
| 3982 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3983 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3984 | atomic_inc(&vp->vref_count); |
| 3985 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3986 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3987 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3988 | |
| 3989 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3990 | atomic_dec(&vp->vref_count); |
| 3991 | } |
| 3992 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3993 | } else { |
| 3994 | if (!atomic_read(&vha->loop_down_timer)) |
| 3995 | atomic_set(&vha->loop_down_timer, |
| 3996 | LOOP_DOWN_TIME); |
| 3997 | } |
| 3998 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 3999 | /* Clear all async request states across all VPs. */ |
| 4000 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 4001 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4002 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4003 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4004 | atomic_inc(&vp->vref_count); |
| 4005 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4006 | |
| 4007 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 4008 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 4009 | |
| 4010 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4011 | atomic_dec(&vp->vref_count); |
| 4012 | } |
| 4013 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4014 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4015 | if (!ha->flags.eeh_busy) { |
| 4016 | /* Make sure for ISP 82XX IO DMA is complete */ |
| 4017 | if (IS_QLA82XX(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 4018 | qla82xx_chip_reset_cleanup(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4019 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame] | 4020 | /* Done waiting for pending commands. |
| 4021 | * Reset the online flag. |
| 4022 | */ |
| 4023 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4024 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4025 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4026 | /* Requeue all commands in outstanding command list. */ |
| 4027 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 4028 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4029 | } |
| 4030 | |
| 4031 | /* |
| 4032 | * qla2x00_abort_isp |
| 4033 | * Resets ISP and aborts all outstanding commands. |
| 4034 | * |
| 4035 | * Input: |
| 4036 | * ha = adapter block pointer. |
| 4037 | * |
| 4038 | * Returns: |
| 4039 | * 0 = success |
| 4040 | */ |
| 4041 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4042 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4044 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4046 | struct qla_hw_data *ha = vha->hw; |
| 4047 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4048 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4049 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4051 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4052 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4053 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4054 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 4055 | ha->flags.pci_channel_io_perm_failure)) { |
| 4056 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4057 | status = 0; |
| 4058 | return status; |
| 4059 | } |
| 4060 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4061 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 4062 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4063 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4065 | if (!qla2x00_restart_isp(vha)) { |
| 4066 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4068 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | /* |
| 4070 | * Issue marker command only when we are going |
| 4071 | * to start the I/O . |
| 4072 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4073 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | } |
| 4075 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4076 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4078 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4079 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4080 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4081 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4082 | |
Lalit Chandivade | 29c5397 | 2009-10-13 15:16:47 -0700 | [diff] [blame] | 4083 | if (IS_QLA81XX(ha)) |
| 4084 | qla2x00_get_fw_version(vha, |
| 4085 | &ha->fw_major_version, |
| 4086 | &ha->fw_minor_version, |
| 4087 | &ha->fw_subminor_version, |
| 4088 | &ha->fw_attributes, &ha->fw_memory_size, |
| 4089 | ha->mpi_version, &ha->mpi_capabilities, |
| 4090 | ha->phy_version); |
| 4091 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4092 | if (ha->fce) { |
| 4093 | ha->flags.fce_enabled = 1; |
| 4094 | memset(ha->fce, 0, |
| 4095 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4096 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4097 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 4098 | &ha->fce_bufs); |
| 4099 | if (rval) { |
| 4100 | qla_printk(KERN_WARNING, ha, |
| 4101 | "Unable to reinitialize FCE " |
| 4102 | "(%d).\n", rval); |
| 4103 | ha->flags.fce_enabled = 0; |
| 4104 | } |
| 4105 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4106 | |
| 4107 | if (ha->eft) { |
| 4108 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4109 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4110 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 4111 | if (rval) { |
| 4112 | qla_printk(KERN_WARNING, ha, |
| 4113 | "Unable to reinitialize EFT " |
| 4114 | "(%d).\n", rval); |
| 4115 | } |
| 4116 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4117 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4118 | vha->flags.online = 1; |
| 4119 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | if (ha->isp_abort_cnt == 0) { |
| 4121 | qla_printk(KERN_WARNING, ha, |
| 4122 | "ISP error recovery failed - " |
| 4123 | "board disabled\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4124 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4125 | * The next call disables the board |
| 4126 | * completely. |
| 4127 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4128 | ha->isp_ops->reset_adapter(vha); |
| 4129 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4131 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | status = 0; |
| 4133 | } else { /* schedule another ISP abort */ |
| 4134 | ha->isp_abort_cnt--; |
| 4135 | DEBUG(printk("qla%ld: ISP abort - " |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4136 | "retry remaining %d\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4137 | vha->host_no, ha->isp_abort_cnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | status = 1; |
| 4139 | } |
| 4140 | } else { |
| 4141 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
| 4142 | DEBUG(printk("qla2x00(%ld): ISP error recovery " |
| 4143 | "- retrying (%d) more times\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4144 | vha->host_no, ha->isp_abort_cnt)); |
| 4145 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4146 | status = 1; |
| 4147 | } |
| 4148 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4149 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4150 | } |
| 4151 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4152 | if (!status) { |
| 4153 | DEBUG(printk(KERN_INFO |
| 4154 | "qla2x00_abort_isp(%ld): succeeded.\n", |
| 4155 | vha->host_no)); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4156 | |
| 4157 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4158 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4159 | if (vp->vp_idx) { |
| 4160 | atomic_inc(&vp->vref_count); |
| 4161 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4162 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4163 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4164 | |
| 4165 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4166 | atomic_dec(&vp->vref_count); |
| 4167 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4168 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4169 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4170 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4171 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4172 | qla_printk(KERN_INFO, ha, |
| 4173 | "qla2x00_abort_isp: **** FAILED ****\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4174 | } |
| 4175 | |
| 4176 | return(status); |
| 4177 | } |
| 4178 | |
| 4179 | /* |
| 4180 | * qla2x00_restart_isp |
| 4181 | * restarts the ISP after a reset |
| 4182 | * |
| 4183 | * Input: |
| 4184 | * ha = adapter block pointer. |
| 4185 | * |
| 4186 | * Returns: |
| 4187 | * 0 = success |
| 4188 | */ |
| 4189 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4190 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4191 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4192 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | uint32_t wait_time; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4194 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4195 | struct req_que *req = ha->req_q_map[0]; |
| 4196 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4197 | |
| 4198 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4199 | if (qla2x00_isp_firmware(vha)) { |
| 4200 | vha->flags.online = 0; |
| 4201 | status = ha->isp_ops->chip_diag(vha); |
| 4202 | if (!status) |
| 4203 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | } |
| 4205 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4206 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 4207 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4208 | ha->flags.chip_reset_done = 1; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4209 | /* Initialize the queues in use */ |
| 4210 | qla25xx_init_queues(ha); |
| 4211 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4212 | status = qla2x00_fw_ready(vha); |
| 4213 | if (!status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4214 | DEBUG(printk("%s(): Start configure loop, " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 4215 | "status = %d\n", __func__, status)); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4216 | |
| 4217 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4218 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4219 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4220 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 4222 | wait_time = 256; |
| 4223 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4224 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4225 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4227 | } while (!atomic_read(&vha->loop_down_timer) && |
| 4228 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 4229 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 4230 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | } |
| 4232 | |
| 4233 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4234 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4235 | status = 0; |
| 4236 | |
| 4237 | DEBUG(printk("%s(): Configure loop done, status = 0x%x\n", |
| 4238 | __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 4239 | status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4240 | } |
| 4241 | return (status); |
| 4242 | } |
| 4243 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4244 | static int |
| 4245 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 4246 | { |
| 4247 | struct rsp_que *rsp = NULL; |
| 4248 | struct req_que *req = NULL; |
| 4249 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 4250 | int ret = -1; |
| 4251 | int i; |
| 4252 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4253 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4254 | rsp = ha->rsp_q_map[i]; |
| 4255 | if (rsp) { |
| 4256 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4257 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4258 | if (ret != QLA_SUCCESS) |
| 4259 | DEBUG2_17(printk(KERN_WARNING |
| 4260 | "%s Rsp que:%d init failed\n", __func__, |
| 4261 | rsp->id)); |
| 4262 | else |
| 4263 | DEBUG2_17(printk(KERN_INFO |
| 4264 | "%s Rsp que:%d inited\n", __func__, |
| 4265 | rsp->id)); |
| 4266 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4267 | } |
| 4268 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4269 | req = ha->req_q_map[i]; |
| 4270 | if (req) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4271 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4272 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4273 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4274 | if (ret != QLA_SUCCESS) |
| 4275 | DEBUG2_17(printk(KERN_WARNING |
| 4276 | "%s Req que:%d init failed\n", __func__, |
| 4277 | req->id)); |
| 4278 | else |
| 4279 | DEBUG2_17(printk(KERN_WARNING |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4280 | "%s Req que:%d inited\n", __func__, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4281 | req->id)); |
| 4282 | } |
| 4283 | } |
| 4284 | return ret; |
| 4285 | } |
| 4286 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4287 | /* |
| 4288 | * qla2x00_reset_adapter |
| 4289 | * Reset adapter. |
| 4290 | * |
| 4291 | * Input: |
| 4292 | * ha = adapter block pointer. |
| 4293 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4294 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4295 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4296 | { |
| 4297 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4298 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4299 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4300 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4301 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4302 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4305 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 4306 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4307 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 4308 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4309 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4310 | } |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4311 | |
| 4312 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4313 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4314 | { |
| 4315 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4316 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4317 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 4318 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4319 | if (IS_QLA82XX(ha)) |
| 4320 | return; |
| 4321 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4322 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4323 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4324 | |
| 4325 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4326 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 4327 | RD_REG_DWORD(®->hccr); |
| 4328 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 4329 | RD_REG_DWORD(®->hccr); |
| 4330 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 4331 | |
| 4332 | if (IS_NOPOLLING_TYPE(ha)) |
| 4333 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4334 | } |
| 4335 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4336 | /* On sparc systems, obtain port and node WWN from firmware |
| 4337 | * properties. |
| 4338 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4339 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 4340 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4341 | { |
| 4342 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4343 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4344 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4345 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4346 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4347 | int len; |
| 4348 | |
| 4349 | val = of_get_property(dp, "port-wwn", &len); |
| 4350 | if (val && len >= WWN_SIZE) |
| 4351 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4352 | |
| 4353 | val = of_get_property(dp, "node-wwn", &len); |
| 4354 | if (val && len >= WWN_SIZE) |
| 4355 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4356 | #endif |
| 4357 | } |
| 4358 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4359 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4360 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4361 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4362 | int rval; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4363 | struct init_cb_24xx *icb; |
| 4364 | struct nvram_24xx *nv; |
| 4365 | uint32_t *dptr; |
| 4366 | uint8_t *dptr1, *dptr2; |
| 4367 | uint32_t chksum; |
| 4368 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4369 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4370 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4371 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4372 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4373 | nv = ha->nvram; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4374 | |
| 4375 | /* Determine NVRAM starting address. */ |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4376 | if (ha->flags.port0) { |
| 4377 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 4378 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 4379 | } else { |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4380 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 4381 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 4382 | } |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4383 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 4384 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4385 | if (IS_QLA82XX(ha)) |
| 4386 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4387 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4388 | /* Get VPD data into cache */ |
| 4389 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4390 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4391 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 4392 | |
| 4393 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4394 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4395 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4396 | ha->nvram_size); |
| 4397 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 4398 | chksum += le32_to_cpu(*dptr++); |
| 4399 | |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 4400 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4401 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4402 | |
| 4403 | /* Bad NVRAM data, set defaults parameters. */ |
| 4404 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 4405 | || nv->id[3] != ' ' || |
| 4406 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 4407 | /* Reset NVRAM data. */ |
| 4408 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 4409 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 4410 | le16_to_cpu(nv->nvram_version)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4411 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 4412 | "invalid -- WWPN) defaults.\n"); |
| 4413 | |
| 4414 | /* |
| 4415 | * Set default initialization control block. |
| 4416 | */ |
| 4417 | memset(nv, 0, ha->nvram_size); |
| 4418 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 4419 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 4420 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 4421 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4422 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 4423 | nv->hard_address = __constant_cpu_to_le16(124); |
| 4424 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4425 | nv->port_name[1] = 0x00 + ha->port_no; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4426 | nv->port_name[2] = 0x00; |
| 4427 | nv->port_name[3] = 0xe0; |
| 4428 | nv->port_name[4] = 0x8b; |
| 4429 | nv->port_name[5] = 0x1c; |
| 4430 | nv->port_name[6] = 0x55; |
| 4431 | nv->port_name[7] = 0x86; |
| 4432 | nv->node_name[0] = 0x20; |
| 4433 | nv->node_name[1] = 0x00; |
| 4434 | nv->node_name[2] = 0x00; |
| 4435 | nv->node_name[3] = 0xe0; |
| 4436 | nv->node_name[4] = 0x8b; |
| 4437 | nv->node_name[5] = 0x1c; |
| 4438 | nv->node_name[6] = 0x55; |
| 4439 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4440 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4441 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 4442 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 4443 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 4444 | nv->firmware_options_1 = |
| 4445 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 4446 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 4447 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 4448 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 4449 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 4450 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 4451 | nv->reset_delay = 5; |
| 4452 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 4453 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 4454 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 4455 | |
| 4456 | rval = 1; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4457 | } |
| 4458 | |
| 4459 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4460 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4461 | |
| 4462 | /* Copy 1st segment. */ |
| 4463 | dptr1 = (uint8_t *)icb; |
| 4464 | dptr2 = (uint8_t *)&nv->version; |
| 4465 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 4466 | while (cnt--) |
| 4467 | *dptr1++ = *dptr2++; |
| 4468 | |
| 4469 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 4470 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4471 | |
| 4472 | /* Copy 2nd segment. */ |
| 4473 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 4474 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 4475 | cnt = (uint8_t *)&icb->reserved_3 - |
| 4476 | (uint8_t *)&icb->interrupt_delay_timer; |
| 4477 | while (cnt--) |
| 4478 | *dptr1++ = *dptr2++; |
| 4479 | |
| 4480 | /* |
| 4481 | * Setup driver NVRAM options. |
| 4482 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4483 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4484 | "QLA2462"); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4485 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4486 | /* Use alternate WWN? */ |
| 4487 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 4488 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4489 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4490 | } |
| 4491 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4492 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4493 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4494 | /* |
| 4495 | * Firmware will apply the following mask if the nodename was |
| 4496 | * not provided. |
| 4497 | */ |
| 4498 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4499 | icb->node_name[0] &= 0xF0; |
| 4500 | } |
| 4501 | |
| 4502 | /* Set host adapter parameters. */ |
| 4503 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 4504 | ha->flags.enable_lip_reset = 0; |
| 4505 | ha->flags.enable_lip_full_login = |
| 4506 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 4507 | ha->flags.enable_target_reset = |
| 4508 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4509 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4510 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4511 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4512 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 4513 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4514 | |
| 4515 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 4516 | sizeof(ha->fw_seriallink_options24)); |
| 4517 | |
| 4518 | /* save HBA serial number */ |
| 4519 | ha->serial0 = icb->port_name[5]; |
| 4520 | ha->serial1 = icb->port_name[6]; |
| 4521 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4522 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4523 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4524 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 4525 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4526 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4527 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 4528 | |
| 4529 | /* Set minimum login_timeout to 4 seconds. */ |
| 4530 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 4531 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 4532 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 4533 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 4534 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 4535 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4536 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4537 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4538 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4539 | |
| 4540 | ha->loop_reset_delay = nv->reset_delay; |
| 4541 | |
| 4542 | /* Link Down Timeout = 0: |
| 4543 | * |
| 4544 | * When Port Down timer expires we will start returning |
| 4545 | * I/O's to OS with "DID_NO_CONNECT". |
| 4546 | * |
| 4547 | * Link Down Timeout != 0: |
| 4548 | * |
| 4549 | * The driver waits for the link to come up after link down |
| 4550 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 4551 | */ |
| 4552 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 4553 | ha->loop_down_abort_time = |
| 4554 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 4555 | } else { |
| 4556 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 4557 | ha->loop_down_abort_time = |
| 4558 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 4559 | } |
| 4560 | |
| 4561 | /* Need enough time to try and get the port back. */ |
| 4562 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 4563 | if (qlport_down_retry) |
| 4564 | ha->port_down_retry_count = qlport_down_retry; |
| 4565 | |
| 4566 | /* Set login_retry_count */ |
| 4567 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 4568 | if (ha->port_down_retry_count == |
| 4569 | le16_to_cpu(nv->port_down_retry_count) && |
| 4570 | ha->port_down_retry_count > 3) |
| 4571 | ha->login_retry_count = ha->port_down_retry_count; |
| 4572 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4573 | ha->login_retry_count = ha->port_down_retry_count; |
| 4574 | if (ql2xloginretrycount) |
| 4575 | ha->login_retry_count = ql2xloginretrycount; |
| 4576 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4577 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4578 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4579 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 4580 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4581 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 4582 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 4583 | } |
| 4584 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 4585 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4586 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4587 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4588 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4589 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4590 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4591 | "(%d us).\n", vha->host_no, ha->zio_mode, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4592 | ha->zio_timer * 100)); |
| 4593 | qla_printk(KERN_INFO, ha, |
| 4594 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4595 | ha->zio_mode, ha->zio_timer * 100); |
| 4596 | |
| 4597 | icb->firmware_options_2 |= cpu_to_le32( |
| 4598 | (uint32_t)ha->zio_mode); |
| 4599 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4600 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4601 | } |
| 4602 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4603 | if (rval) { |
| 4604 | DEBUG2_3(printk(KERN_WARNING |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4605 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4606 | } |
| 4607 | return (rval); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4608 | } |
| 4609 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 4610 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4611 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 4612 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4613 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4614 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4615 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4616 | uint32_t *dcode, dlen; |
| 4617 | uint32_t risc_addr; |
| 4618 | uint32_t risc_size; |
| 4619 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4620 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4621 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4622 | |
| 4623 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4624 | "FW: Loading from flash (%x)...\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4625 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4626 | rval = QLA_SUCCESS; |
| 4627 | |
| 4628 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4629 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4630 | *srisc_addr = 0; |
| 4631 | |
| 4632 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4633 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4634 | for (i = 0; i < 4; i++) |
| 4635 | dcode[i] = be32_to_cpu(dcode[i]); |
| 4636 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 4637 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 4638 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 4639 | dcode[3] == 0)) { |
| 4640 | qla_printk(KERN_WARNING, ha, |
| 4641 | "Unable to verify integrity of flash firmware image!\n"); |
| 4642 | qla_printk(KERN_WARNING, ha, |
| 4643 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 4644 | dcode[1], dcode[2], dcode[3]); |
| 4645 | |
| 4646 | return QLA_FUNCTION_FAILED; |
| 4647 | } |
| 4648 | |
| 4649 | while (segments && rval == QLA_SUCCESS) { |
| 4650 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4651 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4652 | |
| 4653 | risc_addr = be32_to_cpu(dcode[2]); |
| 4654 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 4655 | risc_size = be32_to_cpu(dcode[3]); |
| 4656 | |
| 4657 | fragment = 0; |
| 4658 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4659 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 4660 | if (dlen > risc_size) |
| 4661 | dlen = risc_size; |
| 4662 | |
| 4663 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
| 4664 | "addr %x, number of dwords 0x%x, offset 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4665 | vha->host_no, risc_addr, dlen, faddr)); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4666 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4667 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4668 | for (i = 0; i < dlen; i++) |
| 4669 | dcode[i] = swab32(dcode[i]); |
| 4670 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4671 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4672 | dlen); |
| 4673 | if (rval) { |
| 4674 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4675 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4676 | fragment)); |
| 4677 | qla_printk(KERN_WARNING, ha, |
| 4678 | "[ERROR] Failed to load segment %d of " |
| 4679 | "firmware\n", fragment); |
| 4680 | break; |
| 4681 | } |
| 4682 | |
| 4683 | faddr += dlen; |
| 4684 | risc_addr += dlen; |
| 4685 | risc_size -= dlen; |
| 4686 | fragment++; |
| 4687 | } |
| 4688 | |
| 4689 | /* Next segment. */ |
| 4690 | segments--; |
| 4691 | } |
| 4692 | |
| 4693 | return rval; |
| 4694 | } |
| 4695 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4696 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" |
| 4697 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4698 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4699 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4700 | { |
| 4701 | int rval; |
| 4702 | int i, fragment; |
| 4703 | uint16_t *wcode, *fwcode; |
| 4704 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 4705 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4706 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4707 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4708 | |
| 4709 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4710 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4711 | if (!blob) { |
| 4712 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4713 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 4714 | "from: " QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4715 | return QLA_FUNCTION_FAILED; |
| 4716 | } |
| 4717 | |
| 4718 | rval = QLA_SUCCESS; |
| 4719 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4720 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4721 | *srisc_addr = 0; |
| 4722 | fwcode = (uint16_t *)blob->fw->data; |
| 4723 | fwclen = 0; |
| 4724 | |
| 4725 | /* Validate firmware image by checking version. */ |
| 4726 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
| 4727 | qla_printk(KERN_WARNING, ha, |
| 4728 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 4729 | blob->fw->size); |
| 4730 | goto fail_fw_integrity; |
| 4731 | } |
| 4732 | for (i = 0; i < 4; i++) |
| 4733 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 4734 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 4735 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 4736 | wcode[2] == 0 && wcode[3] == 0)) { |
| 4737 | qla_printk(KERN_WARNING, ha, |
| 4738 | "Unable to verify integrity of firmware image!\n"); |
| 4739 | qla_printk(KERN_WARNING, ha, |
| 4740 | "Firmware data: %04x %04x %04x %04x!\n", wcode[0], |
| 4741 | wcode[1], wcode[2], wcode[3]); |
| 4742 | goto fail_fw_integrity; |
| 4743 | } |
| 4744 | |
| 4745 | seg = blob->segs; |
| 4746 | while (*seg && rval == QLA_SUCCESS) { |
| 4747 | risc_addr = *seg; |
| 4748 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 4749 | risc_size = be16_to_cpu(fwcode[3]); |
| 4750 | |
| 4751 | /* Validate firmware image size. */ |
| 4752 | fwclen += risc_size * sizeof(uint16_t); |
| 4753 | if (blob->fw->size < fwclen) { |
| 4754 | qla_printk(KERN_WARNING, ha, |
| 4755 | "Unable to verify integrity of firmware image " |
| 4756 | "(%Zd)!\n", blob->fw->size); |
| 4757 | goto fail_fw_integrity; |
| 4758 | } |
| 4759 | |
| 4760 | fragment = 0; |
| 4761 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4762 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 4763 | if (wlen > risc_size) |
| 4764 | wlen = risc_size; |
| 4765 | |
| 4766 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4767 | "addr %x, number of words 0x%x.\n", vha->host_no, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4768 | risc_addr, wlen)); |
| 4769 | |
| 4770 | for (i = 0; i < wlen; i++) |
| 4771 | wcode[i] = swab16(fwcode[i]); |
| 4772 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4773 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4774 | wlen); |
| 4775 | if (rval) { |
| 4776 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4777 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4778 | fragment)); |
| 4779 | qla_printk(KERN_WARNING, ha, |
| 4780 | "[ERROR] Failed to load segment %d of " |
| 4781 | "firmware\n", fragment); |
| 4782 | break; |
| 4783 | } |
| 4784 | |
| 4785 | fwcode += wlen; |
| 4786 | risc_addr += wlen; |
| 4787 | risc_size -= wlen; |
| 4788 | fragment++; |
| 4789 | } |
| 4790 | |
| 4791 | /* Next segment. */ |
| 4792 | seg++; |
| 4793 | } |
| 4794 | return rval; |
| 4795 | |
| 4796 | fail_fw_integrity: |
| 4797 | return QLA_FUNCTION_FAILED; |
| 4798 | } |
| 4799 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4800 | static int |
| 4801 | qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4802 | { |
| 4803 | int rval; |
| 4804 | int segments, fragment; |
| 4805 | uint32_t *dcode, dlen; |
| 4806 | uint32_t risc_addr; |
| 4807 | uint32_t risc_size; |
| 4808 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4809 | struct fw_blob *blob; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4810 | uint32_t *fwcode, fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4811 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4812 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4813 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4814 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4815 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4816 | if (!blob) { |
| 4817 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4818 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 4819 | "from: " QLA_FW_URL ".\n"); |
| 4820 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4821 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4822 | } |
| 4823 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4824 | qla_printk(KERN_INFO, ha, |
| 4825 | "FW: Loading via request-firmware...\n"); |
| 4826 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4827 | rval = QLA_SUCCESS; |
| 4828 | |
| 4829 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4830 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4831 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4832 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4833 | fwclen = 0; |
| 4834 | |
| 4835 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4836 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4837 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4838 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 4839 | blob->fw->size); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4840 | goto fail_fw_integrity; |
| 4841 | } |
| 4842 | for (i = 0; i < 4; i++) |
| 4843 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 4844 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 4845 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 4846 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 4847 | dcode[3] == 0)) { |
| 4848 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4849 | "Unable to verify integrity of firmware image!\n"); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4850 | qla_printk(KERN_WARNING, ha, |
| 4851 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 4852 | dcode[1], dcode[2], dcode[3]); |
| 4853 | goto fail_fw_integrity; |
| 4854 | } |
| 4855 | |
| 4856 | while (segments && rval == QLA_SUCCESS) { |
| 4857 | risc_addr = be32_to_cpu(fwcode[2]); |
| 4858 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 4859 | risc_size = be32_to_cpu(fwcode[3]); |
| 4860 | |
| 4861 | /* Validate firmware image size. */ |
| 4862 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4863 | if (blob->fw->size < fwclen) { |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4864 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4865 | "Unable to verify integrity of firmware image " |
| 4866 | "(%Zd)!\n", blob->fw->size); |
| 4867 | |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4868 | goto fail_fw_integrity; |
| 4869 | } |
| 4870 | |
| 4871 | fragment = 0; |
| 4872 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4873 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 4874 | if (dlen > risc_size) |
| 4875 | dlen = risc_size; |
| 4876 | |
| 4877 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4878 | "addr %x, number of dwords 0x%x.\n", vha->host_no, |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4879 | risc_addr, dlen)); |
| 4880 | |
| 4881 | for (i = 0; i < dlen; i++) |
| 4882 | dcode[i] = swab32(fwcode[i]); |
| 4883 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4884 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 4885 | dlen); |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4886 | if (rval) { |
| 4887 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4888 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4889 | fragment)); |
| 4890 | qla_printk(KERN_WARNING, ha, |
| 4891 | "[ERROR] Failed to load segment %d of " |
| 4892 | "firmware\n", fragment); |
| 4893 | break; |
| 4894 | } |
| 4895 | |
| 4896 | fwcode += dlen; |
| 4897 | risc_addr += dlen; |
| 4898 | risc_size -= dlen; |
| 4899 | fragment++; |
| 4900 | } |
| 4901 | |
| 4902 | /* Next segment. */ |
| 4903 | segments--; |
| 4904 | } |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4905 | return rval; |
| 4906 | |
| 4907 | fail_fw_integrity: |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4908 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109 | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4909 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4910 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4911 | int |
| 4912 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 4913 | { |
| 4914 | int rval; |
| 4915 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4916 | if (ql2xfwloadbin == 1) |
| 4917 | return qla81xx_load_risc(vha, srisc_addr); |
| 4918 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4919 | /* |
| 4920 | * FW Load priority: |
| 4921 | * 1) Firmware via request-firmware interface (.bin file). |
| 4922 | * 2) Firmware residing in flash. |
| 4923 | */ |
| 4924 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 4925 | if (rval == QLA_SUCCESS) |
| 4926 | return rval; |
| 4927 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4928 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 4929 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4930 | } |
| 4931 | |
| 4932 | int |
| 4933 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 4934 | { |
| 4935 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4936 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4937 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4938 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4939 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4940 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4941 | /* |
| 4942 | * FW Load priority: |
| 4943 | * 1) Firmware residing in flash. |
| 4944 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4945 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4946 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4947 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4948 | if (rval == QLA_SUCCESS) |
| 4949 | return rval; |
| 4950 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4951 | try_blob_fw: |
| 4952 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 4953 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 4954 | return rval; |
| 4955 | |
| 4956 | qla_printk(KERN_ERR, ha, |
| 4957 | "FW: Attempting to fallback to golden firmware...\n"); |
| 4958 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 4959 | if (rval != QLA_SUCCESS) |
| 4960 | return rval; |
| 4961 | |
| 4962 | qla_printk(KERN_ERR, ha, |
| 4963 | "FW: Please update operational firmware...\n"); |
| 4964 | ha->flags.running_gold_fw = 1; |
| 4965 | |
| 4966 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4967 | } |
| 4968 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4969 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4970 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4971 | { |
| 4972 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4973 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4974 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4975 | if (ha->flags.pci_channel_io_perm_failure) |
| 4976 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4977 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4978 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 4979 | if (!ha->fw_major_version) |
| 4980 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4981 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4982 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 4983 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 4984 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4985 | ha->isp_ops->reset_chip(vha); |
| 4986 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4987 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4988 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4989 | continue; |
| 4990 | qla_printk(KERN_INFO, ha, |
| 4991 | "Attempting retry of stop-firmware command...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4992 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4993 | } |
| 4994 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4995 | |
| 4996 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4997 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4998 | { |
| 4999 | int rval = QLA_SUCCESS; |
| 5000 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5001 | struct qla_hw_data *ha = vha->hw; |
| 5002 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5003 | struct req_que *req; |
| 5004 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5005 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5006 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5007 | return -EINVAL; |
| 5008 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5009 | rval = qla2x00_fw_ready(base_vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 5010 | if (ha->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5011 | req = ha->req_q_map[0]; |
| 5012 | else |
| 5013 | req = vha->req; |
| 5014 | rsp = req->rsp; |
| 5015 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5016 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5017 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5018 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5019 | } |
| 5020 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5021 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5022 | |
| 5023 | /* Login to SNS first */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5024 | 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] | 5025 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 5026 | DEBUG15(qla_printk(KERN_INFO, ha, |
| 5027 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 5028 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS, |
| 5029 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 5030 | return (QLA_FUNCTION_FAILED); |
| 5031 | } |
| 5032 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5033 | atomic_set(&vha->loop_down_timer, 0); |
| 5034 | atomic_set(&vha->loop_state, LOOP_UP); |
| 5035 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5036 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5037 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5038 | |
| 5039 | return rval; |
| 5040 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5041 | |
| 5042 | /* 84XX Support **************************************************************/ |
| 5043 | |
| 5044 | static LIST_HEAD(qla_cs84xx_list); |
| 5045 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 5046 | |
| 5047 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5048 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5049 | { |
| 5050 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5051 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5052 | |
| 5053 | mutex_lock(&qla_cs84xx_mutex); |
| 5054 | |
| 5055 | /* Find any shared 84xx chip. */ |
| 5056 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 5057 | if (cs84xx->bus == ha->pdev->bus) { |
| 5058 | kref_get(&cs84xx->kref); |
| 5059 | goto done; |
| 5060 | } |
| 5061 | } |
| 5062 | |
| 5063 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 5064 | if (!cs84xx) |
| 5065 | goto done; |
| 5066 | |
| 5067 | kref_init(&cs84xx->kref); |
| 5068 | spin_lock_init(&cs84xx->access_lock); |
| 5069 | mutex_init(&cs84xx->fw_update_mutex); |
| 5070 | cs84xx->bus = ha->pdev->bus; |
| 5071 | |
| 5072 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 5073 | done: |
| 5074 | mutex_unlock(&qla_cs84xx_mutex); |
| 5075 | return cs84xx; |
| 5076 | } |
| 5077 | |
| 5078 | static void |
| 5079 | __qla84xx_chip_release(struct kref *kref) |
| 5080 | { |
| 5081 | struct qla_chip_state_84xx *cs84xx = |
| 5082 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 5083 | |
| 5084 | mutex_lock(&qla_cs84xx_mutex); |
| 5085 | list_del(&cs84xx->list); |
| 5086 | mutex_unlock(&qla_cs84xx_mutex); |
| 5087 | kfree(cs84xx); |
| 5088 | } |
| 5089 | |
| 5090 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5091 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5092 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5093 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5094 | if (ha->cs84xx) |
| 5095 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 5096 | } |
| 5097 | |
| 5098 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5099 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5100 | { |
| 5101 | int rval; |
| 5102 | uint16_t status[2]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5103 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5104 | |
| 5105 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 5106 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5107 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5108 | |
| 5109 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 5110 | |
| 5111 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 5112 | QLA_SUCCESS; |
| 5113 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5114 | |
| 5115 | /* 81XX Support **************************************************************/ |
| 5116 | |
| 5117 | int |
| 5118 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 5119 | { |
| 5120 | int rval; |
| 5121 | struct init_cb_81xx *icb; |
| 5122 | struct nvram_81xx *nv; |
| 5123 | uint32_t *dptr; |
| 5124 | uint8_t *dptr1, *dptr2; |
| 5125 | uint32_t chksum; |
| 5126 | uint16_t cnt; |
| 5127 | struct qla_hw_data *ha = vha->hw; |
| 5128 | |
| 5129 | rval = QLA_SUCCESS; |
| 5130 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 5131 | nv = ha->nvram; |
| 5132 | |
| 5133 | /* Determine NVRAM starting address. */ |
| 5134 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5135 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5136 | |
| 5137 | /* Get VPD data into cache */ |
| 5138 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038 | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5139 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 5140 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5141 | |
| 5142 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038 | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5143 | 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] | 5144 | ha->nvram_size); |
Andrew Vasquez | 3d79038 | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5145 | dptr = (uint32_t *)nv; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5146 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 5147 | chksum += le32_to_cpu(*dptr++); |
| 5148 | |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 5149 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5150 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
| 5151 | |
| 5152 | /* Bad NVRAM data, set defaults parameters. */ |
| 5153 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5154 | || nv->id[3] != ' ' || |
| 5155 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 5156 | /* Reset NVRAM data. */ |
| 5157 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 5158 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 5159 | le16_to_cpu(nv->nvram_version)); |
| 5160 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 5161 | "invalid -- WWPN) defaults.\n"); |
| 5162 | |
| 5163 | /* |
| 5164 | * Set default initialization control block. |
| 5165 | */ |
| 5166 | memset(nv, 0, ha->nvram_size); |
| 5167 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 5168 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 5169 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 5170 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5171 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 5172 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5173 | nv->port_name[1] = 0x00 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5174 | nv->port_name[2] = 0x00; |
| 5175 | nv->port_name[3] = 0xe0; |
| 5176 | nv->port_name[4] = 0x8b; |
| 5177 | nv->port_name[5] = 0x1c; |
| 5178 | nv->port_name[6] = 0x55; |
| 5179 | nv->port_name[7] = 0x86; |
| 5180 | nv->node_name[0] = 0x20; |
| 5181 | nv->node_name[1] = 0x00; |
| 5182 | nv->node_name[2] = 0x00; |
| 5183 | nv->node_name[3] = 0xe0; |
| 5184 | nv->node_name[4] = 0x8b; |
| 5185 | nv->node_name[5] = 0x1c; |
| 5186 | nv->node_name[6] = 0x55; |
| 5187 | nv->node_name[7] = 0x86; |
| 5188 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 5189 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 5190 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 5191 | nv->firmware_options_1 = |
| 5192 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5193 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 5194 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 5195 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 5196 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 5197 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 5198 | nv->reset_delay = 5; |
| 5199 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 5200 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 5201 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 5202 | nv->enode_mac[0] = 0x00; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5203 | nv->enode_mac[1] = 0x02; |
| 5204 | nv->enode_mac[2] = 0x03; |
| 5205 | nv->enode_mac[3] = 0x04; |
| 5206 | nv->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5207 | nv->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5208 | |
| 5209 | rval = 1; |
| 5210 | } |
| 5211 | |
| 5212 | /* Reset Initialization control block */ |
Andrew Vasquez | 773120e | 2011-05-10 11:30:14 -0700 | [diff] [blame] | 5213 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5214 | |
| 5215 | /* Copy 1st segment. */ |
| 5216 | dptr1 = (uint8_t *)icb; |
| 5217 | dptr2 = (uint8_t *)&nv->version; |
| 5218 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5219 | while (cnt--) |
| 5220 | *dptr1++ = *dptr2++; |
| 5221 | |
| 5222 | icb->login_retry_count = nv->login_retry_count; |
| 5223 | |
| 5224 | /* Copy 2nd segment. */ |
| 5225 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 5226 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 5227 | cnt = (uint8_t *)&icb->reserved_5 - |
| 5228 | (uint8_t *)&icb->interrupt_delay_timer; |
| 5229 | while (cnt--) |
| 5230 | *dptr1++ = *dptr2++; |
| 5231 | |
| 5232 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 5233 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 5234 | if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) { |
| 5235 | icb->enode_mac[0] = 0x01; |
| 5236 | icb->enode_mac[1] = 0x02; |
| 5237 | icb->enode_mac[2] = 0x03; |
| 5238 | icb->enode_mac[3] = 0x04; |
| 5239 | icb->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5240 | icb->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5241 | } |
| 5242 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 5243 | /* Use extended-initialization control block. */ |
| 5244 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 5245 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5246 | /* |
| 5247 | * Setup driver NVRAM options. |
| 5248 | */ |
| 5249 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5250 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5251 | |
| 5252 | /* Use alternate WWN? */ |
| 5253 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 5254 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 5255 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 5256 | } |
| 5257 | |
| 5258 | /* Prepare nodename */ |
| 5259 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
| 5260 | /* |
| 5261 | * Firmware will apply the following mask if the nodename was |
| 5262 | * not provided. |
| 5263 | */ |
| 5264 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 5265 | icb->node_name[0] &= 0xF0; |
| 5266 | } |
| 5267 | |
| 5268 | /* Set host adapter parameters. */ |
| 5269 | ha->flags.disable_risc_code_load = 0; |
| 5270 | ha->flags.enable_lip_reset = 0; |
| 5271 | ha->flags.enable_lip_full_login = |
| 5272 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 5273 | ha->flags.enable_target_reset = |
| 5274 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 5275 | ha->flags.enable_led_scheme = 0; |
| 5276 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 5277 | |
| 5278 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 5279 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 5280 | |
| 5281 | /* save HBA serial number */ |
| 5282 | ha->serial0 = icb->port_name[5]; |
| 5283 | ha->serial1 = icb->port_name[6]; |
| 5284 | ha->serial2 = icb->port_name[7]; |
| 5285 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 5286 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 5287 | |
| 5288 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5289 | |
| 5290 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 5291 | |
| 5292 | /* Set minimum login_timeout to 4 seconds. */ |
| 5293 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 5294 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 5295 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 5296 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 5297 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
| 5298 | icb->login_timeout = nv->login_timeout; |
| 5299 | |
| 5300 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 5301 | ha->r_a_tov = 100; |
| 5302 | |
| 5303 | ha->loop_reset_delay = nv->reset_delay; |
| 5304 | |
| 5305 | /* Link Down Timeout = 0: |
| 5306 | * |
| 5307 | * When Port Down timer expires we will start returning |
| 5308 | * I/O's to OS with "DID_NO_CONNECT". |
| 5309 | * |
| 5310 | * Link Down Timeout != 0: |
| 5311 | * |
| 5312 | * The driver waits for the link to come up after link down |
| 5313 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 5314 | */ |
| 5315 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 5316 | ha->loop_down_abort_time = |
| 5317 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 5318 | } else { |
| 5319 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 5320 | ha->loop_down_abort_time = |
| 5321 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 5322 | } |
| 5323 | |
| 5324 | /* Need enough time to try and get the port back. */ |
| 5325 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 5326 | if (qlport_down_retry) |
| 5327 | ha->port_down_retry_count = qlport_down_retry; |
| 5328 | |
| 5329 | /* Set login_retry_count */ |
| 5330 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 5331 | if (ha->port_down_retry_count == |
| 5332 | le16_to_cpu(nv->port_down_retry_count) && |
| 5333 | ha->port_down_retry_count > 3) |
| 5334 | ha->login_retry_count = ha->port_down_retry_count; |
| 5335 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 5336 | ha->login_retry_count = ha->port_down_retry_count; |
| 5337 | if (ql2xloginretrycount) |
| 5338 | ha->login_retry_count = ql2xloginretrycount; |
| 5339 | |
| 5340 | /* Enable ZIO. */ |
| 5341 | if (!vha->flags.init_done) { |
| 5342 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5343 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5344 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5345 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5346 | } |
| 5347 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 5348 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 5349 | vha->flags.process_response_queue = 0; |
| 5350 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 5351 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5352 | |
| 5353 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
| 5354 | "(%d us).\n", vha->host_no, ha->zio_mode, |
| 5355 | ha->zio_timer * 100)); |
| 5356 | qla_printk(KERN_INFO, ha, |
| 5357 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 5358 | ha->zio_mode, ha->zio_timer * 100); |
| 5359 | |
| 5360 | icb->firmware_options_2 |= cpu_to_le32( |
| 5361 | (uint32_t)ha->zio_mode); |
| 5362 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 5363 | vha->flags.process_response_queue = 1; |
| 5364 | } |
| 5365 | |
| 5366 | if (rval) { |
| 5367 | DEBUG2_3(printk(KERN_WARNING |
| 5368 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
| 5369 | } |
| 5370 | return (rval); |
| 5371 | } |
| 5372 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5373 | int |
| 5374 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 5375 | { |
| 5376 | int status, rval; |
| 5377 | uint32_t wait_time; |
| 5378 | struct qla_hw_data *ha = vha->hw; |
| 5379 | struct req_que *req = ha->req_q_map[0]; |
| 5380 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 5381 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5382 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5383 | |
| 5384 | status = qla2x00_init_rings(vha); |
| 5385 | if (!status) { |
| 5386 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5387 | ha->flags.chip_reset_done = 1; |
| 5388 | |
| 5389 | status = qla2x00_fw_ready(vha); |
| 5390 | if (!status) { |
| 5391 | qla_printk(KERN_INFO, ha, |
| 5392 | "%s(): Start configure loop, " |
| 5393 | "status = %d\n", __func__, status); |
| 5394 | |
| 5395 | /* Issue a marker after FW becomes ready. */ |
| 5396 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
| 5397 | |
| 5398 | vha->flags.online = 1; |
| 5399 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5400 | wait_time = 256; |
| 5401 | do { |
| 5402 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5403 | qla2x00_configure_loop(vha); |
| 5404 | wait_time--; |
| 5405 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5406 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && |
| 5407 | wait_time && |
| 5408 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); |
| 5409 | } |
| 5410 | |
| 5411 | /* if no cable then assume it's good */ |
| 5412 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 5413 | status = 0; |
| 5414 | |
| 5415 | qla_printk(KERN_INFO, ha, |
| 5416 | "%s(): Configure loop done, status = 0x%x\n", |
| 5417 | __func__, status); |
| 5418 | } |
| 5419 | |
| 5420 | if (!status) { |
| 5421 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5422 | |
| 5423 | if (!atomic_read(&vha->loop_down_timer)) { |
| 5424 | /* |
| 5425 | * Issue marker command only when we are going |
| 5426 | * to start the I/O . |
| 5427 | */ |
| 5428 | vha->marker_needed = 1; |
| 5429 | } |
| 5430 | |
| 5431 | vha->flags.online = 1; |
| 5432 | |
| 5433 | ha->isp_ops->enable_intrs(ha); |
| 5434 | |
| 5435 | ha->isp_abort_cnt = 0; |
| 5436 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5437 | |
Saurav Kashyap | 5329678 | 2011-05-10 11:30:06 -0700 | [diff] [blame] | 5438 | /* Update the firmware version */ |
| 5439 | qla2x00_get_fw_version(vha, &ha->fw_major_version, |
| 5440 | &ha->fw_minor_version, &ha->fw_subminor_version, |
| 5441 | &ha->fw_attributes, &ha->fw_memory_size, |
| 5442 | ha->mpi_version, &ha->mpi_capabilities, |
| 5443 | ha->phy_version); |
| 5444 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5445 | if (ha->fce) { |
| 5446 | ha->flags.fce_enabled = 1; |
| 5447 | memset(ha->fce, 0, |
| 5448 | fce_calc_size(ha->fce_bufs)); |
| 5449 | rval = qla2x00_enable_fce_trace(vha, |
| 5450 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5451 | &ha->fce_bufs); |
| 5452 | if (rval) { |
| 5453 | qla_printk(KERN_WARNING, ha, |
| 5454 | "Unable to reinitialize FCE " |
| 5455 | "(%d).\n", rval); |
| 5456 | ha->flags.fce_enabled = 0; |
| 5457 | } |
| 5458 | } |
| 5459 | |
| 5460 | if (ha->eft) { |
| 5461 | memset(ha->eft, 0, EFT_SIZE); |
| 5462 | rval = qla2x00_enable_eft_trace(vha, |
| 5463 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5464 | if (rval) { |
| 5465 | qla_printk(KERN_WARNING, ha, |
| 5466 | "Unable to reinitialize EFT " |
| 5467 | "(%d).\n", rval); |
| 5468 | } |
| 5469 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5470 | } |
| 5471 | |
| 5472 | if (!status) { |
| 5473 | DEBUG(printk(KERN_INFO |
| 5474 | "qla82xx_restart_isp(%ld): succeeded.\n", |
| 5475 | vha->host_no)); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5476 | |
| 5477 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5478 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5479 | if (vp->vp_idx) { |
| 5480 | atomic_inc(&vp->vref_count); |
| 5481 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5482 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5483 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5484 | |
| 5485 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5486 | atomic_dec(&vp->vref_count); |
| 5487 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5488 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5489 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5490 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5491 | } else { |
| 5492 | qla_printk(KERN_INFO, ha, |
| 5493 | "qla82xx_restart_isp: **** FAILED ****\n"); |
| 5494 | } |
| 5495 | |
| 5496 | return status; |
| 5497 | } |
| 5498 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5499 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5500 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5501 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5502 | struct qla_hw_data *ha = vha->hw; |
| 5503 | |
| 5504 | if (!ql2xetsenable) |
| 5505 | return; |
| 5506 | |
| 5507 | /* Enable ETS Burst. */ |
| 5508 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 5509 | ha->fw_options[2] |= BIT_9; |
| 5510 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5511 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5512 | |
| 5513 | /* |
| 5514 | * qla24xx_get_fcp_prio |
| 5515 | * Gets the fcp cmd priority value for the logged in port. |
| 5516 | * Looks for a match of the port descriptors within |
| 5517 | * each of the fcp prio config entries. If a match is found, |
| 5518 | * the tag (priority) value is returned. |
| 5519 | * |
| 5520 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5521 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5522 | * fcport = port structure pointer. |
| 5523 | * |
| 5524 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 5525 | * non-zero (if found) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5526 | * -1 (if not found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5527 | * |
| 5528 | * Context: |
| 5529 | * Kernel context |
| 5530 | */ |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5531 | static int |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5532 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 5533 | { |
| 5534 | int i, entries; |
| 5535 | uint8_t pid_match, wwn_match; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5536 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5537 | uint32_t pid1, pid2; |
| 5538 | uint64_t wwn1, wwn2; |
| 5539 | struct qla_fcp_prio_entry *pri_entry; |
| 5540 | struct qla_hw_data *ha = vha->hw; |
| 5541 | |
| 5542 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5543 | return -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5544 | |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5545 | priority = -1; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5546 | entries = ha->fcp_prio_cfg->num_entries; |
| 5547 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 5548 | |
| 5549 | for (i = 0; i < entries; i++) { |
| 5550 | pid_match = wwn_match = 0; |
| 5551 | |
| 5552 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 5553 | pri_entry++; |
| 5554 | continue; |
| 5555 | } |
| 5556 | |
| 5557 | /* check source pid for a match */ |
| 5558 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 5559 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 5560 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 5561 | if (pid1 == INVALID_PORT_ID) |
| 5562 | pid_match++; |
| 5563 | else if (pid1 == pid2) |
| 5564 | pid_match++; |
| 5565 | } |
| 5566 | |
| 5567 | /* check destination pid for a match */ |
| 5568 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 5569 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 5570 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 5571 | if (pid1 == INVALID_PORT_ID) |
| 5572 | pid_match++; |
| 5573 | else if (pid1 == pid2) |
| 5574 | pid_match++; |
| 5575 | } |
| 5576 | |
| 5577 | /* check source WWN for a match */ |
| 5578 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 5579 | wwn1 = wwn_to_u64(vha->port_name); |
| 5580 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 5581 | if (wwn2 == (uint64_t)-1) |
| 5582 | wwn_match++; |
| 5583 | else if (wwn1 == wwn2) |
| 5584 | wwn_match++; |
| 5585 | } |
| 5586 | |
| 5587 | /* check destination WWN for a match */ |
| 5588 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 5589 | wwn1 = wwn_to_u64(fcport->port_name); |
| 5590 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 5591 | if (wwn2 == (uint64_t)-1) |
| 5592 | wwn_match++; |
| 5593 | else if (wwn1 == wwn2) |
| 5594 | wwn_match++; |
| 5595 | } |
| 5596 | |
| 5597 | if (pid_match == 2 || wwn_match == 2) { |
| 5598 | /* Found a matching entry */ |
| 5599 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 5600 | priority = pri_entry->tag; |
| 5601 | break; |
| 5602 | } |
| 5603 | |
| 5604 | pri_entry++; |
| 5605 | } |
| 5606 | |
| 5607 | return priority; |
| 5608 | } |
| 5609 | |
| 5610 | /* |
| 5611 | * qla24xx_update_fcport_fcp_prio |
| 5612 | * Activates fcp priority for the logged in fc port |
| 5613 | * |
| 5614 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5615 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5616 | * fcp = port structure pointer. |
| 5617 | * |
| 5618 | * Return: |
| 5619 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5620 | * |
| 5621 | * Context: |
| 5622 | * Kernel context. |
| 5623 | */ |
| 5624 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5625 | qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5626 | { |
| 5627 | int ret; |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5628 | int priority; |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5629 | uint16_t mb[5]; |
| 5630 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5631 | if (fcport->port_type != FCT_TARGET || |
| 5632 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5633 | return QLA_FUNCTION_FAILED; |
| 5634 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5635 | priority = qla24xx_get_fcp_prio(vha, fcport); |
Andrew Vasquez | f28a0a9 | 2011-03-30 11:46:18 -0700 | [diff] [blame] | 5636 | if (priority < 0) |
| 5637 | return QLA_FUNCTION_FAILED; |
| 5638 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5639 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5640 | if (ret == QLA_SUCCESS) |
| 5641 | fcport->fcp_prio = priority; |
| 5642 | else |
| 5643 | DEBUG2(printk(KERN_WARNING |
| 5644 | "scsi(%ld): Unable to activate fcp priority, " |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5645 | " ret=0x%x\n", vha->host_no, ret)); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5646 | |
| 5647 | return ret; |
| 5648 | } |
| 5649 | |
| 5650 | /* |
| 5651 | * qla24xx_update_all_fcp_prio |
| 5652 | * Activates fcp priority for all the logged in ports |
| 5653 | * |
| 5654 | * Input: |
| 5655 | * ha = adapter block pointer. |
| 5656 | * |
| 5657 | * Return: |
| 5658 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5659 | * |
| 5660 | * Context: |
| 5661 | * Kernel context. |
| 5662 | */ |
| 5663 | int |
| 5664 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 5665 | { |
| 5666 | int ret; |
| 5667 | fc_port_t *fcport; |
| 5668 | |
| 5669 | ret = QLA_FUNCTION_FAILED; |
| 5670 | /* We need to set priority for all logged in ports */ |
| 5671 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5672 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 5673 | |
| 5674 | return ret; |
| 5675 | } |