Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 2 | * QLogic Fibre Channel HBA Driver |
Giridhar Malavali | de7c5d0 | 2010-07-23 15:28:36 +0500 | [diff] [blame] | 3 | * Copyright (c) 2003-2010 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6 | */ |
| 7 | #include "qla_def.h" |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 8 | #include "qla_gbl.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <linux/delay.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 11 | #include <linux/slab.h> |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 12 | #include <linux/vmalloc.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | |
| 14 | #include "qla_devtbl.h" |
| 15 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 16 | #ifdef CONFIG_SPARC |
| 17 | #include <asm/prom.h> |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 18 | #endif |
| 19 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | /* |
| 21 | * QLogic ISP2x00 Hardware Support Function Prototypes. |
| 22 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | static int qla2x00_isp_firmware(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | static int qla2x00_setup_chip(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | static int qla2x00_init_rings(scsi_qla_host_t *); |
| 26 | static int qla2x00_fw_ready(scsi_qla_host_t *); |
| 27 | static int qla2x00_configure_hba(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | static int qla2x00_configure_loop(scsi_qla_host_t *); |
| 29 | static int qla2x00_configure_local_loop(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | static int qla2x00_configure_fabric(scsi_qla_host_t *); |
| 31 | static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *, struct list_head *); |
| 32 | static int qla2x00_device_resync(scsi_qla_host_t *); |
| 33 | static int qla2x00_fabric_dev_login(scsi_qla_host_t *, fc_port_t *, |
| 34 | uint16_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | static int qla2x00_restart_isp(scsi_qla_host_t *); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 38 | static int qla2x00_find_new_loop_id(scsi_qla_host_t *, fc_port_t *); |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 39 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 40 | static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *); |
| 41 | static int qla84xx_init_chip(scsi_qla_host_t *); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 42 | static int qla25xx_init_queues(struct qla_hw_data *); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 43 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 44 | /* SRB Extensions ---------------------------------------------------------- */ |
| 45 | |
| 46 | static void |
| 47 | qla2x00_ctx_sp_timeout(unsigned long __data) |
| 48 | { |
| 49 | srb_t *sp = (srb_t *)__data; |
| 50 | struct srb_ctx *ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 51 | struct srb_iocb *iocb; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 52 | fc_port_t *fcport = sp->fcport; |
| 53 | struct qla_hw_data *ha = fcport->vha->hw; |
| 54 | struct req_que *req; |
| 55 | unsigned long flags; |
| 56 | |
| 57 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 58 | req = ha->req_q_map[0]; |
| 59 | req->outstanding_cmds[sp->handle] = NULL; |
| 60 | ctx = sp->ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 61 | iocb = ctx->u.iocb_cmd; |
| 62 | iocb->timeout(sp); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 63 | iocb->free(sp); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 64 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 65 | } |
| 66 | |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 67 | static void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 68 | qla2x00_ctx_sp_free(srb_t *sp) |
| 69 | { |
| 70 | struct srb_ctx *ctx = sp->ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 71 | struct srb_iocb *iocb = ctx->u.iocb_cmd; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 72 | struct scsi_qla_host *vha = sp->fcport->vha; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 73 | |
Chad Dupuis | 4d97cc5 | 2010-10-15 11:27:41 -0700 | [diff] [blame] | 74 | del_timer(&iocb->timer); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 75 | kfree(iocb); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 76 | kfree(ctx); |
| 77 | mempool_free(sp, sp->fcport->vha->hw->srb_mempool); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 78 | |
| 79 | QLA_VHA_MARK_NOT_BUSY(vha); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | inline srb_t * |
| 83 | qla2x00_get_ctx_sp(scsi_qla_host_t *vha, fc_port_t *fcport, size_t size, |
| 84 | unsigned long tmo) |
| 85 | { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 86 | srb_t *sp = NULL; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 87 | struct qla_hw_data *ha = vha->hw; |
| 88 | struct srb_ctx *ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 89 | struct srb_iocb *iocb; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 90 | uint8_t bail; |
| 91 | |
| 92 | QLA_VHA_MARK_BUSY(vha, bail); |
| 93 | if (bail) |
| 94 | return NULL; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 95 | |
| 96 | sp = mempool_alloc(ha->srb_mempool, GFP_KERNEL); |
| 97 | if (!sp) |
| 98 | goto done; |
| 99 | ctx = kzalloc(size, GFP_KERNEL); |
| 100 | if (!ctx) { |
| 101 | mempool_free(sp, ha->srb_mempool); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 102 | sp = NULL; |
| 103 | goto done; |
| 104 | } |
| 105 | iocb = kzalloc(sizeof(struct srb_iocb), GFP_KERNEL); |
| 106 | if (!iocb) { |
| 107 | mempool_free(sp, ha->srb_mempool); |
| 108 | sp = NULL; |
| 109 | kfree(ctx); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 110 | goto done; |
| 111 | } |
| 112 | |
| 113 | memset(sp, 0, sizeof(*sp)); |
| 114 | sp->fcport = fcport; |
| 115 | sp->ctx = ctx; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 116 | ctx->u.iocb_cmd = iocb; |
| 117 | iocb->free = qla2x00_ctx_sp_free; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 118 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 119 | init_timer(&iocb->timer); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 120 | if (!tmo) |
| 121 | goto done; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 122 | iocb->timer.expires = jiffies + tmo * HZ; |
| 123 | iocb->timer.data = (unsigned long)sp; |
| 124 | iocb->timer.function = qla2x00_ctx_sp_timeout; |
| 125 | add_timer(&iocb->timer); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 126 | done: |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 127 | if (!sp) |
| 128 | QLA_VHA_MARK_NOT_BUSY(vha); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 129 | return sp; |
| 130 | } |
| 131 | |
| 132 | /* Asynchronous Login/Logout Routines -------------------------------------- */ |
| 133 | |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 134 | static inline unsigned long |
| 135 | qla2x00_get_async_timeout(struct scsi_qla_host *vha) |
| 136 | { |
| 137 | unsigned long tmo; |
| 138 | struct qla_hw_data *ha = vha->hw; |
| 139 | |
| 140 | /* Firmware should use switch negotiated r_a_tov for timeout. */ |
| 141 | tmo = ha->r_a_tov / 10 * 2; |
| 142 | if (!IS_FWI2_CAPABLE(ha)) { |
| 143 | /* |
| 144 | * Except for earlier ISPs where the timeout is seeded from the |
| 145 | * initialization control block. |
| 146 | */ |
| 147 | tmo = ha->login_timeout; |
| 148 | } |
| 149 | return tmo; |
| 150 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 151 | |
| 152 | static void |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 153 | qla2x00_async_iocb_timeout(srb_t *sp) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 154 | { |
| 155 | fc_port_t *fcport = sp->fcport; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 156 | struct srb_ctx *ctx = sp->ctx; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 157 | |
| 158 | DEBUG2(printk(KERN_WARNING |
Andrew Vasquez | d3fa9e7 | 2010-05-28 15:08:16 -0700 | [diff] [blame] | 159 | "scsi(%ld:%x): Async-%s timeout - portid=%02x%02x%02x.\n", |
| 160 | fcport->vha->host_no, sp->handle, |
| 161 | ctx->name, fcport->d_id.b.domain, |
| 162 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 163 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 164 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 165 | if (ctx->type == SRB_LOGIN_CMD) { |
| 166 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 167 | qla2x00_post_async_logout_work(fcport->vha, fcport, NULL); |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 168 | /* Retry as needed. */ |
| 169 | lio->u.logio.data[0] = MBS_COMMAND_ERROR; |
| 170 | lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ? |
| 171 | QLA_LOGIO_LOGIN_RETRIED : 0; |
| 172 | qla2x00_post_async_login_done_work(fcport->vha, fcport, |
| 173 | lio->u.logio.data); |
| 174 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 177 | static void |
| 178 | qla2x00_async_login_ctx_done(srb_t *sp) |
| 179 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 180 | struct srb_ctx *ctx = sp->ctx; |
| 181 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 182 | |
| 183 | qla2x00_post_async_login_done_work(sp->fcport->vha, sp->fcport, |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 184 | lio->u.logio.data); |
| 185 | lio->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 186 | } |
| 187 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 188 | int |
| 189 | qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 190 | uint16_t *data) |
| 191 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 192 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 193 | struct srb_ctx *ctx; |
| 194 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 195 | int rval; |
| 196 | |
| 197 | rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 198 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 199 | qla2x00_get_async_timeout(vha) + 2); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 200 | if (!sp) |
| 201 | goto done; |
| 202 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 203 | ctx = sp->ctx; |
| 204 | ctx->type = SRB_LOGIN_CMD; |
| 205 | ctx->name = "login"; |
| 206 | lio = ctx->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 207 | lio->timeout = qla2x00_async_iocb_timeout; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 208 | lio->done = qla2x00_async_login_ctx_done; |
| 209 | lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 210 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 211 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 212 | rval = qla2x00_start_sp(sp); |
| 213 | if (rval != QLA_SUCCESS) |
| 214 | goto done_free_sp; |
| 215 | |
| 216 | DEBUG2(printk(KERN_DEBUG |
| 217 | "scsi(%ld:%x): Async-login - loop-id=%x portid=%02x%02x%02x " |
| 218 | "retries=%d.\n", fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 219 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa, |
| 220 | fcport->login_retry)); |
| 221 | return rval; |
| 222 | |
| 223 | done_free_sp: |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 224 | lio->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 225 | done: |
| 226 | return rval; |
| 227 | } |
| 228 | |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 229 | static void |
| 230 | qla2x00_async_logout_ctx_done(srb_t *sp) |
| 231 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 232 | struct srb_ctx *ctx = sp->ctx; |
| 233 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 234 | |
| 235 | qla2x00_post_async_logout_done_work(sp->fcport->vha, sp->fcport, |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 236 | lio->u.logio.data); |
| 237 | lio->free(sp); |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 240 | int |
| 241 | qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport) |
| 242 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 243 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 244 | struct srb_ctx *ctx; |
| 245 | struct srb_iocb *lio; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 246 | int rval; |
| 247 | |
| 248 | rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 249 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 250 | qla2x00_get_async_timeout(vha) + 2); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 251 | if (!sp) |
| 252 | goto done; |
| 253 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 254 | ctx = sp->ctx; |
| 255 | ctx->type = SRB_LOGOUT_CMD; |
| 256 | ctx->name = "logout"; |
| 257 | lio = ctx->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 258 | lio->timeout = qla2x00_async_iocb_timeout; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 259 | lio->done = qla2x00_async_logout_ctx_done; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 260 | rval = qla2x00_start_sp(sp); |
| 261 | if (rval != QLA_SUCCESS) |
| 262 | goto done_free_sp; |
| 263 | |
| 264 | DEBUG2(printk(KERN_DEBUG |
| 265 | "scsi(%ld:%x): Async-logout - loop-id=%x portid=%02x%02x%02x.\n", |
| 266 | fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 267 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 268 | return rval; |
| 269 | |
| 270 | done_free_sp: |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 271 | lio->free(sp); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 272 | done: |
| 273 | return rval; |
| 274 | } |
| 275 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 276 | static void |
| 277 | qla2x00_async_adisc_ctx_done(srb_t *sp) |
| 278 | { |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 279 | struct srb_ctx *ctx = sp->ctx; |
| 280 | struct srb_iocb *lio = ctx->u.iocb_cmd; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 281 | |
| 282 | qla2x00_post_async_adisc_done_work(sp->fcport->vha, sp->fcport, |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 283 | lio->u.logio.data); |
| 284 | lio->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | int |
| 288 | qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 289 | uint16_t *data) |
| 290 | { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 291 | srb_t *sp; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 292 | struct srb_ctx *ctx; |
| 293 | struct srb_iocb *lio; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 294 | int rval; |
| 295 | |
| 296 | rval = QLA_FUNCTION_FAILED; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 297 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 298 | qla2x00_get_async_timeout(vha) + 2); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 299 | if (!sp) |
| 300 | goto done; |
| 301 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 302 | ctx = sp->ctx; |
| 303 | ctx->type = SRB_ADISC_CMD; |
| 304 | ctx->name = "adisc"; |
| 305 | lio = ctx->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 306 | lio->timeout = qla2x00_async_iocb_timeout; |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 307 | lio->done = qla2x00_async_adisc_ctx_done; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 308 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 309 | lio->u.logio.flags |= SRB_LOGIN_RETRIED; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 310 | rval = qla2x00_start_sp(sp); |
| 311 | if (rval != QLA_SUCCESS) |
| 312 | goto done_free_sp; |
| 313 | |
| 314 | DEBUG2(printk(KERN_DEBUG |
| 315 | "scsi(%ld:%x): Async-adisc - loop-id=%x portid=%02x%02x%02x.\n", |
| 316 | fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 317 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 318 | |
| 319 | return rval; |
| 320 | |
| 321 | done_free_sp: |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 322 | lio->free(sp); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 323 | done: |
| 324 | return rval; |
| 325 | } |
| 326 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 327 | static void |
| 328 | qla2x00_async_tm_cmd_ctx_done(srb_t *sp) |
| 329 | { |
| 330 | struct srb_ctx *ctx = sp->ctx; |
| 331 | struct srb_iocb *iocb = (struct srb_iocb *)ctx->u.iocb_cmd; |
| 332 | |
| 333 | qla2x00_async_tm_cmd_done(sp->fcport->vha, sp->fcport, iocb); |
| 334 | iocb->free(sp); |
| 335 | } |
| 336 | |
| 337 | int |
| 338 | qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun, |
| 339 | uint32_t tag) |
| 340 | { |
| 341 | struct scsi_qla_host *vha = fcport->vha; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 342 | srb_t *sp; |
| 343 | struct srb_ctx *ctx; |
| 344 | struct srb_iocb *tcf; |
| 345 | int rval; |
| 346 | |
| 347 | rval = QLA_FUNCTION_FAILED; |
| 348 | sp = qla2x00_get_ctx_sp(vha, fcport, sizeof(struct srb_ctx), |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 349 | qla2x00_get_async_timeout(vha) + 2); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 350 | if (!sp) |
| 351 | goto done; |
| 352 | |
| 353 | ctx = sp->ctx; |
| 354 | ctx->type = SRB_TM_CMD; |
| 355 | ctx->name = "tmf"; |
| 356 | tcf = ctx->u.iocb_cmd; |
| 357 | tcf->u.tmf.flags = flags; |
| 358 | tcf->u.tmf.lun = lun; |
| 359 | tcf->u.tmf.data = tag; |
| 360 | tcf->timeout = qla2x00_async_iocb_timeout; |
| 361 | tcf->done = qla2x00_async_tm_cmd_ctx_done; |
| 362 | |
| 363 | rval = qla2x00_start_sp(sp); |
| 364 | if (rval != QLA_SUCCESS) |
| 365 | goto done_free_sp; |
| 366 | |
| 367 | DEBUG2(printk(KERN_DEBUG |
| 368 | "scsi(%ld:%x): Async-tmf - loop-id=%x portid=%02x%02x%02x.\n", |
| 369 | fcport->vha->host_no, sp->handle, fcport->loop_id, |
| 370 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 371 | |
| 372 | return rval; |
| 373 | |
| 374 | done_free_sp: |
| 375 | tcf->free(sp); |
| 376 | done: |
| 377 | return rval; |
| 378 | } |
| 379 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 380 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 381 | qla2x00_async_login_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 382 | uint16_t *data) |
| 383 | { |
| 384 | int rval; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 385 | |
| 386 | switch (data[0]) { |
| 387 | case MBS_COMMAND_COMPLETE: |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 388 | if (fcport->flags & FCF_FCP2_DEVICE) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 389 | fcport->flags |= FCF_ASYNC_SENT; |
| 390 | qla2x00_post_async_adisc_work(vha, fcport, data); |
| 391 | break; |
Andrew Vasquez | 99b0bec | 2010-05-04 15:01:25 -0700 | [diff] [blame] | 392 | } |
| 393 | qla2x00_update_fcport(vha, fcport); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 394 | break; |
| 395 | case MBS_COMMAND_ERROR: |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 396 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 397 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 398 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 399 | else |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 400 | qla2x00_mark_device_lost(vha, fcport, 1, 1); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 401 | break; |
| 402 | case MBS_PORT_ID_USED: |
| 403 | fcport->loop_id = data[1]; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 404 | qla2x00_post_async_logout_work(vha, fcport, NULL); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 405 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 406 | break; |
| 407 | case MBS_LOOP_ID_USED: |
| 408 | fcport->loop_id++; |
| 409 | rval = qla2x00_find_new_loop_id(vha, fcport); |
| 410 | if (rval != QLA_SUCCESS) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 411 | fcport->flags &= ~FCF_ASYNC_SENT; |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 412 | qla2x00_mark_device_lost(vha, fcport, 1, 1); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 413 | break; |
| 414 | } |
| 415 | qla2x00_post_async_login_work(vha, fcport, NULL); |
| 416 | break; |
| 417 | } |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 418 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 419 | } |
| 420 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 421 | void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 422 | qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 423 | uint16_t *data) |
| 424 | { |
| 425 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 426 | return; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 429 | void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 430 | qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 431 | uint16_t *data) |
| 432 | { |
| 433 | if (data[0] == MBS_COMMAND_COMPLETE) { |
| 434 | qla2x00_update_fcport(vha, fcport); |
| 435 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 436 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | /* Retry login. */ |
| 440 | fcport->flags &= ~FCF_ASYNC_SENT; |
| 441 | if (data[1] & QLA_LOGIO_LOGIN_RETRIED) |
| 442 | set_bit(RELOGIN_NEEDED, &vha->dpc_flags); |
| 443 | else |
Andrew Vasquez | 6ac5260 | 2010-05-28 15:08:19 -0700 | [diff] [blame] | 444 | qla2x00_mark_device_lost(vha, fcport, 1, 1); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 445 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 446 | return; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 447 | } |
| 448 | |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 449 | void |
| 450 | qla2x00_async_tm_cmd_done(struct scsi_qla_host *vha, fc_port_t *fcport, |
| 451 | struct srb_iocb *iocb) |
| 452 | { |
| 453 | int rval; |
| 454 | uint32_t flags; |
| 455 | uint16_t lun; |
| 456 | |
| 457 | flags = iocb->u.tmf.flags; |
| 458 | lun = (uint16_t)iocb->u.tmf.lun; |
| 459 | |
| 460 | /* Issue Marker IOCB */ |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 461 | rval = qla2x00_marker(vha, vha->hw->req_q_map[0], |
| 462 | vha->hw->rsp_q_map[0], fcport->loop_id, lun, |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 463 | flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID); |
| 464 | |
| 465 | if ((rval != QLA_SUCCESS) || iocb->u.tmf.data) { |
| 466 | DEBUG2_3_11(printk(KERN_WARNING |
| 467 | "%s(%ld): TM IOCB failed (%x).\n", |
| 468 | __func__, vha->host_no, rval)); |
| 469 | } |
| 470 | |
| 471 | return; |
| 472 | } |
| 473 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | /****************************************************************************/ |
| 475 | /* QLogic ISP2x00 Hardware Support Functions. */ |
| 476 | /****************************************************************************/ |
| 477 | |
| 478 | /* |
| 479 | * qla2x00_initialize_adapter |
| 480 | * Initialize board. |
| 481 | * |
| 482 | * Input: |
| 483 | * ha = adapter block pointer. |
| 484 | * |
| 485 | * Returns: |
| 486 | * 0 = success |
| 487 | */ |
| 488 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 489 | qla2x00_initialize_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | { |
| 491 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 492 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 493 | struct req_que *req = ha->req_q_map[0]; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | /* Clear adapter flags. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 496 | vha->flags.online = 0; |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 497 | ha->flags.chip_reset_done = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 498 | vha->flags.reset_active = 0; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 499 | ha->flags.pci_channel_io_perm_failure = 0; |
| 500 | ha->flags.eeh_busy = 0; |
Andrew Vasquez | 794a569 | 2010-12-21 16:00:21 -0800 | [diff] [blame] | 501 | ha->flags.thermal_supported = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 502 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 503 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 504 | vha->device_flags = DFLG_NO_CABLE; |
| 505 | vha->dpc_flags = 0; |
| 506 | vha->flags.management_server_logged_in = 0; |
| 507 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | ha->isp_abort_cnt = 0; |
| 509 | ha->beacon_blink_led = 0; |
| 510 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 511 | set_bit(0, ha->req_qid_map); |
| 512 | set_bit(0, ha->rsp_qid_map); |
| 513 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 514 | qla_printk(KERN_INFO, ha, "Configuring PCI space...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 515 | rval = ha->isp_ops->pci_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | if (rval) { |
Andrew Vasquez | 7c98a04 | 2007-01-29 10:22:29 -0800 | [diff] [blame] | 517 | DEBUG2(printk("scsi(%ld): Unable to configure PCI space.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 518 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | return (rval); |
| 520 | } |
| 521 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 522 | ha->isp_ops->reset_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 523 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 524 | rval = qla2xxx_get_flash_info(vha); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 525 | if (rval) { |
| 526 | DEBUG2(printk("scsi(%ld): Unable to validate FLASH data.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 527 | vha->host_no)); |
Andrew Vasquez | c00d899 | 2008-09-11 21:22:49 -0700 | [diff] [blame] | 528 | return (rval); |
| 529 | } |
| 530 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 531 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 532 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | qla_printk(KERN_INFO, ha, "Configure NVRAM parameters...\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 534 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 535 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 537 | if (ha->flags.disable_serdes) { |
| 538 | /* Mask HBA via NVRAM settings? */ |
| 539 | qla_printk(KERN_INFO, ha, "Masking HBA WWPN " |
| 540 | "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 541 | vha->port_name[0], vha->port_name[1], |
| 542 | vha->port_name[2], vha->port_name[3], |
| 543 | vha->port_name[4], vha->port_name[5], |
| 544 | vha->port_name[6], vha->port_name[7]); |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 545 | return QLA_FUNCTION_FAILED; |
| 546 | } |
| 547 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | qla_printk(KERN_INFO, ha, "Verifying loaded RISC code...\n"); |
| 549 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 550 | if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) { |
| 551 | rval = ha->isp_ops->chip_diag(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 552 | if (rval) |
| 553 | return (rval); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 554 | rval = qla2x00_setup_chip(vha); |
Andrew Vasquez | d19044c | 2006-11-22 08:22:19 -0800 | [diff] [blame] | 555 | if (rval) |
| 556 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 558 | |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 559 | if (IS_QLA84XX(ha)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 560 | ha->cs84xx = qla84xx_get_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 561 | if (!ha->cs84xx) { |
| 562 | qla_printk(KERN_ERR, ha, |
| 563 | "Unable to configure ISP84XX.\n"); |
| 564 | return QLA_FUNCTION_FAILED; |
| 565 | } |
| 566 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 567 | rval = qla2x00_init_rings(vha); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 568 | ha->flags.chip_reset_done = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 570 | if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) { |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 571 | /* Issue verify 84xx FW IOCB to complete 84xx initialization */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 572 | rval = qla84xx_init_chip(vha); |
| 573 | if (rval != QLA_SUCCESS) { |
| 574 | qla_printk(KERN_ERR, ha, |
| 575 | "Unable to initialize ISP84XX.\n"); |
| 576 | qla84xx_put_chip(vha); |
| 577 | } |
| 578 | } |
| 579 | |
Madhuranath Iyengar | 2f0f3f4 | 2010-07-23 15:28:24 +0500 | [diff] [blame] | 580 | if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha)) |
| 581 | qla24xx_read_fcp_prio_cfg(vha); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | return (rval); |
| 584 | } |
| 585 | |
| 586 | /** |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 587 | * qla2100_pci_config() - Setup ISP21xx PCI configuration registers. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 588 | * @ha: HA context |
| 589 | * |
| 590 | * Returns 0 on success. |
| 591 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 592 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 593 | qla2100_pci_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 594 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 595 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 596 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 597 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 598 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 599 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 601 | pci_try_set_mwi(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 604 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 606 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 607 | pci_disable_rom(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 609 | /* Get PCI bus information. */ |
| 610 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 611 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 612 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 613 | |
| 614 | return QLA_SUCCESS; |
| 615 | } |
| 616 | |
| 617 | /** |
| 618 | * qla2300_pci_config() - Setup ISP23xx PCI configuration registers. |
| 619 | * @ha: HA context |
| 620 | * |
| 621 | * Returns 0 on success. |
| 622 | */ |
| 623 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 624 | qla2300_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 625 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 626 | uint16_t w; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 627 | unsigned long flags = 0; |
| 628 | uint32_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 629 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 630 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 631 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 632 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 633 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 634 | |
| 635 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 636 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 637 | |
| 638 | if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 639 | w &= ~PCI_COMMAND_INTX_DISABLE; |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 640 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 641 | |
| 642 | /* |
| 643 | * If this is a 2300 card and not 2312, reset the |
| 644 | * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately, |
| 645 | * the 2310 also reports itself as a 2300 so we need to get the |
| 646 | * fb revision level -- a 6 indicates it really is a 2300 and |
| 647 | * not a 2310. |
| 648 | */ |
| 649 | if (IS_QLA2300(ha)) { |
| 650 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 651 | |
| 652 | /* Pause RISC. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 653 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 654 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 655 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 656 | break; |
| 657 | |
| 658 | udelay(10); |
| 659 | } |
| 660 | |
| 661 | /* Select FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 662 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 663 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 664 | |
| 665 | /* Get the fb rev level */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 666 | ha->fb_rev = RD_FB_CMD_REG(ha, reg); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 667 | |
| 668 | if (ha->fb_rev == FPM_2300) |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 669 | pci_clear_mwi(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 670 | |
| 671 | /* Deselect FPM registers. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 672 | WRT_REG_WORD(®->ctrl_status, 0x0); |
| 673 | RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 674 | |
| 675 | /* Release RISC module. */ |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 676 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 677 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 678 | if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 679 | break; |
| 680 | |
| 681 | udelay(10); |
| 682 | } |
| 683 | |
| 684 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 685 | } |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 686 | |
| 687 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 688 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 689 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 690 | |
| 691 | /* Get PCI bus information. */ |
| 692 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 693 | ha->pci_attr = RD_REG_WORD(®->ctrl_status); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 694 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 695 | |
| 696 | return QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 700 | * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers. |
| 701 | * @ha: HA context |
| 702 | * |
| 703 | * Returns 0 on success. |
| 704 | */ |
| 705 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 706 | qla24xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 707 | { |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 708 | uint16_t w; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 709 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 710 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 711 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 712 | |
| 713 | pci_set_master(ha->pdev); |
Andrew Vasquez | af6177d | 2007-07-19 15:06:02 -0700 | [diff] [blame] | 714 | pci_try_set_mwi(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 715 | |
| 716 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
Andrew Vasquez | a157b10 | 2007-05-07 07:43:01 -0700 | [diff] [blame] | 717 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 718 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 719 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 720 | |
| 721 | pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80); |
| 722 | |
| 723 | /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 724 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX)) |
| 725 | pcix_set_mmrbc(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 726 | |
| 727 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
Andrew Vasquez | f85ec18 | 2007-07-19 15:06:01 -0700 | [diff] [blame] | 728 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 729 | pcie_set_readrq(ha->pdev, 2048); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 730 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 731 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 732 | |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 733 | ha->chip_revision = ha->pdev->revision; |
Andrew Vasquez | a8488ab | 2007-01-29 10:22:19 -0800 | [diff] [blame] | 734 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 735 | /* Get PCI bus information. */ |
| 736 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 737 | ha->pci_attr = RD_REG_DWORD(®->ctrl_status); |
| 738 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 739 | |
| 740 | return QLA_SUCCESS; |
| 741 | } |
| 742 | |
| 743 | /** |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 744 | * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers. |
| 745 | * @ha: HA context |
| 746 | * |
| 747 | * Returns 0 on success. |
| 748 | */ |
| 749 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 750 | qla25xx_pci_config(scsi_qla_host_t *vha) |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 751 | { |
| 752 | uint16_t w; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 753 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 754 | |
| 755 | pci_set_master(ha->pdev); |
| 756 | pci_try_set_mwi(ha->pdev); |
| 757 | |
| 758 | pci_read_config_word(ha->pdev, PCI_COMMAND, &w); |
| 759 | w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR); |
| 760 | w &= ~PCI_COMMAND_INTX_DISABLE; |
| 761 | pci_write_config_word(ha->pdev, PCI_COMMAND, w); |
| 762 | |
| 763 | /* PCIe -- adjust Maximum Read Request Size (2048). */ |
| 764 | if (pci_find_capability(ha->pdev, PCI_CAP_ID_EXP)) |
| 765 | pcie_set_readrq(ha->pdev, 2048); |
| 766 | |
Andrew Vasquez | 737faec | 2008-10-24 15:13:45 -0700 | [diff] [blame] | 767 | pci_disable_rom(ha->pdev); |
Andrew Vasquez | c3a2f0d | 2007-07-19 20:37:34 -0700 | [diff] [blame] | 768 | |
| 769 | ha->chip_revision = ha->pdev->revision; |
| 770 | |
| 771 | return QLA_SUCCESS; |
| 772 | } |
| 773 | |
| 774 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | * qla2x00_isp_firmware() - Choose firmware image. |
| 776 | * @ha: HA context |
| 777 | * |
| 778 | * Returns 0 on success. |
| 779 | */ |
| 780 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 781 | qla2x00_isp_firmware(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | { |
| 783 | int rval; |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 784 | uint16_t loop_id, topo, sw_cap; |
| 785 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 786 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | |
| 788 | /* Assume loading risc code */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 789 | rval = QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | if (ha->flags.disable_risc_code_load) { |
| 792 | DEBUG2(printk("scsi(%ld): RISC CODE NOT loaded\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 793 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 794 | qla_printk(KERN_INFO, ha, "RISC CODE NOT loaded\n"); |
| 795 | |
| 796 | /* Verify checksum of loaded RISC code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 797 | rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address); |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 798 | if (rval == QLA_SUCCESS) { |
| 799 | /* And, verify we are not in ROM code. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 800 | rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa, |
Andrew Vasquez | 42e421b | 2008-07-10 16:56:01 -0700 | [diff] [blame] | 801 | &area, &domain, &topo, &sw_cap); |
| 802 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | } |
| 804 | |
| 805 | if (rval) { |
| 806 | DEBUG2_3(printk("scsi(%ld): **** Load RISC code ****\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 807 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 808 | } |
| 809 | |
| 810 | return (rval); |
| 811 | } |
| 812 | |
| 813 | /** |
| 814 | * qla2x00_reset_chip() - Reset ISP chip. |
| 815 | * @ha: HA context |
| 816 | * |
| 817 | * Returns 0 on success. |
| 818 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 819 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 820 | qla2x00_reset_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | { |
| 822 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 823 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 824 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | uint32_t cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | uint16_t cmd; |
| 827 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 828 | if (unlikely(pci_channel_offline(ha->pdev))) |
| 829 | return; |
| 830 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 831 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | |
| 833 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 834 | |
| 835 | /* Turn off master enable */ |
| 836 | cmd = 0; |
| 837 | pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd); |
| 838 | cmd &= ~PCI_COMMAND_MASTER; |
| 839 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 840 | |
| 841 | if (!IS_QLA2100(ha)) { |
| 842 | /* Pause RISC. */ |
| 843 | WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC); |
| 844 | if (IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 845 | for (cnt = 0; cnt < 30000; cnt++) { |
| 846 | if ((RD_REG_WORD(®->hccr) & |
| 847 | HCCR_RISC_PAUSE) != 0) |
| 848 | break; |
| 849 | udelay(100); |
| 850 | } |
| 851 | } else { |
| 852 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 853 | udelay(10); |
| 854 | } |
| 855 | |
| 856 | /* Select FPM registers. */ |
| 857 | WRT_REG_WORD(®->ctrl_status, 0x20); |
| 858 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 859 | |
| 860 | /* FPM Soft Reset. */ |
| 861 | WRT_REG_WORD(®->fpm_diag_config, 0x100); |
| 862 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 863 | |
| 864 | /* Toggle Fpm Reset. */ |
| 865 | if (!IS_QLA2200(ha)) { |
| 866 | WRT_REG_WORD(®->fpm_diag_config, 0x0); |
| 867 | RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */ |
| 868 | } |
| 869 | |
| 870 | /* Select frame buffer registers. */ |
| 871 | WRT_REG_WORD(®->ctrl_status, 0x10); |
| 872 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 873 | |
| 874 | /* Reset frame buffer FIFOs. */ |
| 875 | if (IS_QLA2200(ha)) { |
| 876 | WRT_FB_CMD_REG(ha, reg, 0xa000); |
| 877 | RD_FB_CMD_REG(ha, reg); /* PCI Posting. */ |
| 878 | } else { |
| 879 | WRT_FB_CMD_REG(ha, reg, 0x00fc); |
| 880 | |
| 881 | /* Read back fb_cmd until zero or 3 seconds max */ |
| 882 | for (cnt = 0; cnt < 3000; cnt++) { |
| 883 | if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0) |
| 884 | break; |
| 885 | udelay(100); |
| 886 | } |
| 887 | } |
| 888 | |
| 889 | /* Select RISC module registers. */ |
| 890 | WRT_REG_WORD(®->ctrl_status, 0); |
| 891 | RD_REG_WORD(®->ctrl_status); /* PCI Posting. */ |
| 892 | |
| 893 | /* Reset RISC processor. */ |
| 894 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 895 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 896 | |
| 897 | /* Release RISC processor. */ |
| 898 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 899 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 900 | } |
| 901 | |
| 902 | WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT); |
| 903 | WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT); |
| 904 | |
| 905 | /* Reset ISP chip. */ |
| 906 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 907 | |
| 908 | /* Wait for RISC to recover from reset. */ |
| 909 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 910 | /* |
| 911 | * It is necessary to for a delay here since the card doesn't |
| 912 | * respond to PCI reads during a reset. On some architectures |
| 913 | * this will result in an MCA. |
| 914 | */ |
| 915 | udelay(20); |
| 916 | for (cnt = 30000; cnt; cnt--) { |
| 917 | if ((RD_REG_WORD(®->ctrl_status) & |
| 918 | CSR_ISP_SOFT_RESET) == 0) |
| 919 | break; |
| 920 | udelay(100); |
| 921 | } |
| 922 | } else |
| 923 | udelay(10); |
| 924 | |
| 925 | /* Reset RISC processor. */ |
| 926 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 927 | |
| 928 | WRT_REG_WORD(®->semaphore, 0); |
| 929 | |
| 930 | /* Release RISC processor. */ |
| 931 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 932 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 933 | |
| 934 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 935 | for (cnt = 0; cnt < 30000; cnt++) { |
Andrew Vasquez | ffb39f0 | 2006-05-17 15:09:06 -0700 | [diff] [blame] | 936 | if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | |
| 939 | udelay(100); |
| 940 | } |
| 941 | } else |
| 942 | udelay(100); |
| 943 | |
| 944 | /* Turn on master enable */ |
| 945 | cmd |= PCI_COMMAND_MASTER; |
| 946 | pci_write_config_word(ha->pdev, PCI_COMMAND, cmd); |
| 947 | |
| 948 | /* Disable RISC pause on FPM parity error. */ |
| 949 | if (!IS_QLA2100(ha)) { |
| 950 | WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE); |
| 951 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 952 | } |
| 953 | |
| 954 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 955 | } |
| 956 | |
| 957 | /** |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 958 | * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC. |
| 959 | * |
| 960 | * Returns 0 on success. |
| 961 | */ |
| 962 | int |
| 963 | qla81xx_reset_mpi(scsi_qla_host_t *vha) |
| 964 | { |
| 965 | uint16_t mb[4] = {0x1010, 0, 1, 0}; |
| 966 | |
| 967 | return qla81xx_write_mpi_register(vha, mb); |
| 968 | } |
| 969 | |
| 970 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 971 | * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC. |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 972 | * @ha: HA context |
| 973 | * |
| 974 | * Returns 0 on success. |
| 975 | */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 976 | static inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 977 | qla24xx_reset_risc(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 978 | { |
| 979 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 980 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 981 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 982 | uint32_t cnt, d2; |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 983 | uint16_t wd; |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 984 | static int abts_cnt; /* ISP abort retry counts */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 985 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 986 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 987 | |
| 988 | /* Reset RISC. */ |
| 989 | WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
| 990 | for (cnt = 0; cnt < 30000; cnt++) { |
| 991 | if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0) |
| 992 | break; |
| 993 | |
| 994 | udelay(10); |
| 995 | } |
| 996 | |
| 997 | WRT_REG_DWORD(®->ctrl_status, |
| 998 | CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES); |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 999 | pci_read_config_word(ha->pdev, PCI_COMMAND, &wd); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1000 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1001 | udelay(100); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1002 | /* Wait for firmware to complete NVRAM accesses. */ |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1003 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1004 | for (cnt = 10000 ; cnt && d2; cnt--) { |
| 1005 | udelay(5); |
| 1006 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1007 | barrier(); |
| 1008 | } |
| 1009 | |
Andrew Vasquez | 335a1cc | 2005-11-08 14:37:48 -0800 | [diff] [blame] | 1010 | /* Wait for soft-reset to complete. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1011 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1012 | for (cnt = 6000000 ; cnt && (d2 & CSRX_ISP_SOFT_RESET); cnt--) { |
| 1013 | udelay(5); |
| 1014 | d2 = RD_REG_DWORD(®->ctrl_status); |
| 1015 | barrier(); |
| 1016 | } |
| 1017 | |
Madhuranath Iyengar | b1d46989 | 2010-09-03 15:20:54 -0700 | [diff] [blame] | 1018 | /* If required, do an MPI FW reset now */ |
| 1019 | if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) { |
| 1020 | if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) { |
| 1021 | if (++abts_cnt < 5) { |
| 1022 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 1023 | set_bit(MPI_RESET_NEEDED, &vha->dpc_flags); |
| 1024 | } else { |
| 1025 | /* |
| 1026 | * We exhausted the ISP abort retries. We have to |
| 1027 | * set the board offline. |
| 1028 | */ |
| 1029 | abts_cnt = 0; |
| 1030 | vha->flags.online = 0; |
| 1031 | } |
| 1032 | } |
| 1033 | } |
| 1034 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1035 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 1036 | RD_REG_DWORD(®->hccr); |
| 1037 | |
| 1038 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 1039 | RD_REG_DWORD(®->hccr); |
| 1040 | |
| 1041 | WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET); |
| 1042 | RD_REG_DWORD(®->hccr); |
| 1043 | |
| 1044 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1045 | for (cnt = 6000000 ; cnt && d2; cnt--) { |
| 1046 | udelay(5); |
| 1047 | d2 = (uint32_t) RD_REG_WORD(®->mailbox0); |
| 1048 | barrier(); |
| 1049 | } |
| 1050 | |
| 1051 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 124f85e | 2009-01-05 11:18:06 -0800 | [diff] [blame] | 1052 | |
| 1053 | if (IS_NOPOLLING_TYPE(ha)) |
| 1054 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1055 | } |
| 1056 | |
| 1057 | /** |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1058 | * qla24xx_reset_chip() - Reset ISP24xx chip. |
| 1059 | * @ha: HA context |
| 1060 | * |
| 1061 | * Returns 0 on success. |
| 1062 | */ |
| 1063 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1064 | qla24xx_reset_chip(scsi_qla_host_t *vha) |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1065 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1066 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 1067 | |
| 1068 | if (pci_channel_offline(ha->pdev) && |
| 1069 | ha->flags.pci_channel_io_perm_failure) { |
| 1070 | return; |
| 1071 | } |
| 1072 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 1073 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1074 | |
| 1075 | /* Perform RISC reset. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1076 | qla24xx_reset_risc(vha); |
Andrew Vasquez | 88c2666 | 2005-07-08 17:59:26 -0700 | [diff] [blame] | 1077 | } |
| 1078 | |
| 1079 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | * qla2x00_chip_diag() - Test chip for proper operation. |
| 1081 | * @ha: HA context |
| 1082 | * |
| 1083 | * Returns 0 on success. |
| 1084 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1085 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1086 | qla2x00_chip_diag(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | { |
| 1088 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1089 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1090 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | unsigned long flags = 0; |
| 1092 | uint16_t data; |
| 1093 | uint32_t cnt; |
| 1094 | uint16_t mb[5]; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1095 | struct req_que *req = ha->req_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1096 | |
| 1097 | /* Assume a failed state */ |
| 1098 | rval = QLA_FUNCTION_FAILED; |
| 1099 | |
| 1100 | DEBUG3(printk("scsi(%ld): Testing device at %lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1101 | vha->host_no, (u_long)®->flash_address)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | |
| 1103 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1104 | |
| 1105 | /* Reset ISP chip. */ |
| 1106 | WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET); |
| 1107 | |
| 1108 | /* |
| 1109 | * We need to have a delay here since the card will not respond while |
| 1110 | * in reset causing an MCA on some architectures. |
| 1111 | */ |
| 1112 | udelay(20); |
| 1113 | data = qla2x00_debounce_register(®->ctrl_status); |
| 1114 | for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) { |
| 1115 | udelay(5); |
| 1116 | data = RD_REG_WORD(®->ctrl_status); |
| 1117 | barrier(); |
| 1118 | } |
| 1119 | |
| 1120 | if (!cnt) |
| 1121 | goto chip_diag_failed; |
| 1122 | |
| 1123 | DEBUG3(printk("scsi(%ld): Reset register cleared by chip reset\n", |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 1124 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | |
| 1126 | /* Reset RISC processor. */ |
| 1127 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 1128 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 1129 | |
| 1130 | /* Workaround for QLA2312 PCI parity error */ |
| 1131 | if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) { |
| 1132 | data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0)); |
| 1133 | for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) { |
| 1134 | udelay(5); |
| 1135 | data = RD_MAILBOX_REG(ha, reg, 0); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1136 | barrier(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | } |
| 1138 | } else |
| 1139 | udelay(10); |
| 1140 | |
| 1141 | if (!cnt) |
| 1142 | goto chip_diag_failed; |
| 1143 | |
| 1144 | /* Check product ID of chip */ |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 1145 | 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] | 1146 | |
| 1147 | mb[1] = RD_MAILBOX_REG(ha, reg, 1); |
| 1148 | mb[2] = RD_MAILBOX_REG(ha, reg, 2); |
| 1149 | mb[3] = RD_MAILBOX_REG(ha, reg, 3); |
| 1150 | mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4)); |
| 1151 | if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) || |
| 1152 | mb[3] != PROD_ID_3) { |
| 1153 | qla_printk(KERN_WARNING, ha, |
| 1154 | "Wrong product ID = 0x%x,0x%x,0x%x\n", mb[1], mb[2], mb[3]); |
| 1155 | |
| 1156 | goto chip_diag_failed; |
| 1157 | } |
| 1158 | ha->product_id[0] = mb[1]; |
| 1159 | ha->product_id[1] = mb[2]; |
| 1160 | ha->product_id[2] = mb[3]; |
| 1161 | ha->product_id[3] = mb[4]; |
| 1162 | |
| 1163 | /* Adjust fw RISC transfer size */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1164 | if (req->length > 1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1165 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024; |
| 1166 | else |
| 1167 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1168 | req->length; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | |
| 1170 | if (IS_QLA2200(ha) && |
| 1171 | RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) { |
| 1172 | /* Limit firmware transfer size with a 2200A */ |
| 1173 | DEBUG3(printk("scsi(%ld): Found QLA2200A chip.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1174 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
andrew.vasquez@qlogic.com | ea5b638 | 2006-03-09 14:27:08 -0800 | [diff] [blame] | 1176 | ha->device_type |= DT_ISP2200A; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | ha->fw_transfer_size = 128; |
| 1178 | } |
| 1179 | |
| 1180 | /* Wrap Incoming Mailboxes Test. */ |
| 1181 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1182 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1183 | DEBUG3(printk("scsi(%ld): Checking mailboxes.\n", vha->host_no)); |
| 1184 | rval = qla2x00_mbx_reg_test(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | if (rval) { |
| 1186 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1187 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1188 | qla_printk(KERN_WARNING, ha, |
| 1189 | "Failed mailbox send register test\n"); |
| 1190 | } |
| 1191 | else { |
| 1192 | /* Flag a successful rval */ |
| 1193 | rval = QLA_SUCCESS; |
| 1194 | } |
| 1195 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1196 | |
| 1197 | chip_diag_failed: |
| 1198 | if (rval) |
| 1199 | DEBUG2_3(printk("scsi(%ld): Chip diagnostics **** FAILED " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1200 | "****\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
| 1202 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1203 | |
| 1204 | return (rval); |
| 1205 | } |
| 1206 | |
| 1207 | /** |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1208 | * qla24xx_chip_diag() - Test ISP24xx for proper operation. |
| 1209 | * @ha: HA context |
| 1210 | * |
| 1211 | * Returns 0 on success. |
| 1212 | */ |
| 1213 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1214 | qla24xx_chip_diag(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1215 | { |
| 1216 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1217 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1218 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1219 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1220 | if (IS_QLA82XX(ha)) |
| 1221 | return QLA_SUCCESS; |
| 1222 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1223 | ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1224 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1225 | rval = qla2x00_mbx_reg_test(vha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1226 | if (rval) { |
| 1227 | DEBUG(printk("scsi(%ld): Failed mailbox send register test\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1228 | vha->host_no)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1229 | qla_printk(KERN_WARNING, ha, |
| 1230 | "Failed mailbox send register test\n"); |
| 1231 | } else { |
| 1232 | /* Flag a successful rval */ |
| 1233 | rval = QLA_SUCCESS; |
| 1234 | } |
| 1235 | |
| 1236 | return rval; |
| 1237 | } |
| 1238 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1239 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1240 | qla2x00_alloc_fw_dump(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1241 | { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1242 | int rval; |
| 1243 | 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] | 1244 | eft_size, fce_size, mq_size; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1245 | dma_addr_t tc_dma; |
| 1246 | void *tc; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1247 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1248 | struct req_que *req = ha->req_q_map[0]; |
| 1249 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1250 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1251 | if (ha->fw_dump) { |
| 1252 | qla_printk(KERN_WARNING, ha, |
| 1253 | "Firmware dump previously allocated.\n"); |
| 1254 | return; |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1255 | } |
| 1256 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1257 | ha->fw_dumped = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1258 | fixed_size = mem_size = eft_size = fce_size = mq_size = 0; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1259 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 1260 | fixed_size = sizeof(struct qla2100_fw_dump); |
| 1261 | } else if (IS_QLA23XX(ha)) { |
| 1262 | fixed_size = offsetof(struct qla2300_fw_dump, data_ram); |
| 1263 | mem_size = (ha->fw_memory_size - 0x11000 + 1) * |
| 1264 | sizeof(uint16_t); |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 1265 | } else if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1266 | if (IS_QLA81XX(ha)) |
| 1267 | fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem); |
| 1268 | else if (IS_QLA25XX(ha)) |
| 1269 | fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem); |
| 1270 | else |
| 1271 | fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1272 | mem_size = (ha->fw_memory_size - 0x100000 + 1) * |
| 1273 | sizeof(uint32_t); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1274 | if (ha->mqenable) |
| 1275 | mq_size = sizeof(struct qla2xxx_mq_chain); |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1276 | /* Allocate memory for Fibre Channel Event Buffer. */ |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1277 | if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)) |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1278 | goto try_eft; |
| 1279 | |
| 1280 | tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma, |
| 1281 | GFP_KERNEL); |
| 1282 | if (!tc) { |
| 1283 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 1284 | "(%d KB) for FCE.\n", FCE_SIZE / 1024); |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1285 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
| 1288 | memset(tc, 0, FCE_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1289 | rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1290 | ha->fce_mb, &ha->fce_bufs); |
| 1291 | if (rval) { |
| 1292 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 1293 | "FCE (%d).\n", rval); |
| 1294 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, |
| 1295 | tc_dma); |
| 1296 | ha->flags.fce_enabled = 0; |
Anirban Chakraborty | 17d9863 | 2008-12-18 10:06:15 -0800 | [diff] [blame] | 1297 | goto try_eft; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1298 | } |
| 1299 | |
| 1300 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for FCE...\n", |
| 1301 | FCE_SIZE / 1024); |
| 1302 | |
Giridhar Malavali | 7d9dade | 2009-03-24 09:07:58 -0700 | [diff] [blame] | 1303 | fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE; |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 1304 | ha->flags.fce_enabled = 1; |
| 1305 | ha->fce_dma = tc_dma; |
| 1306 | ha->fce = tc; |
| 1307 | try_eft: |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1308 | /* Allocate memory for Extended Trace Buffer. */ |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1309 | tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma, |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1310 | GFP_KERNEL); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1311 | if (!tc) { |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1312 | qla_printk(KERN_WARNING, ha, "Unable to allocate " |
| 1313 | "(%d KB) for EFT.\n", EFT_SIZE / 1024); |
| 1314 | goto cont_alloc; |
| 1315 | } |
| 1316 | |
Andrew Vasquez | fc44765 | 2008-01-17 09:02:18 -0800 | [diff] [blame] | 1317 | memset(tc, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1318 | rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1319 | if (rval) { |
| 1320 | qla_printk(KERN_WARNING, ha, "Unable to initialize " |
| 1321 | "EFT (%d).\n", rval); |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1322 | dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, |
| 1323 | tc_dma); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1324 | goto cont_alloc; |
| 1325 | } |
| 1326 | |
| 1327 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for EFT...\n", |
| 1328 | EFT_SIZE / 1024); |
| 1329 | |
| 1330 | eft_size = EFT_SIZE; |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 1331 | ha->eft_dma = tc_dma; |
| 1332 | ha->eft = tc; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1333 | } |
| 1334 | cont_alloc: |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1335 | req_q_size = req->length * sizeof(request_t); |
| 1336 | rsp_q_size = rsp->length * sizeof(response_t); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1337 | |
| 1338 | dump_size = offsetof(struct qla2xxx_fw_dump, isp); |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1339 | 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] | 1340 | ha->chain_offset = dump_size; |
| 1341 | dump_size += mq_size + fce_size; |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1342 | |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1343 | ha->fw_dump = vmalloc(dump_size); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1344 | if (!ha->fw_dump) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1345 | qla_printk(KERN_WARNING, ha, "Unable to allocate (%d KB) for " |
Andrew Vasquez | d4e3e04 | 2006-05-17 15:09:50 -0700 | [diff] [blame] | 1346 | "firmware dump!!!\n", dump_size / 1024); |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1347 | |
Madhuranath Iyengar | e30d175 | 2010-10-15 11:27:46 -0700 | [diff] [blame] | 1348 | if (ha->fce) { |
| 1349 | dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce, |
| 1350 | ha->fce_dma); |
| 1351 | ha->fce = NULL; |
| 1352 | ha->fce_dma = 0; |
| 1353 | } |
| 1354 | |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1355 | if (ha->eft) { |
| 1356 | dma_free_coherent(&ha->pdev->dev, eft_size, ha->eft, |
| 1357 | ha->eft_dma); |
| 1358 | ha->eft = NULL; |
| 1359 | ha->eft_dma = 0; |
| 1360 | } |
| 1361 | return; |
| 1362 | } |
Andrew Vasquez | a7a167b | 2006-06-23 16:10:29 -0700 | [diff] [blame] | 1363 | qla_printk(KERN_INFO, ha, "Allocated (%d KB) for firmware dump...\n", |
| 1364 | dump_size / 1024); |
| 1365 | |
| 1366 | ha->fw_dump_len = dump_size; |
| 1367 | ha->fw_dump->signature[0] = 'Q'; |
| 1368 | ha->fw_dump->signature[1] = 'L'; |
| 1369 | ha->fw_dump->signature[2] = 'G'; |
| 1370 | ha->fw_dump->signature[3] = 'C'; |
| 1371 | ha->fw_dump->version = __constant_htonl(1); |
| 1372 | |
| 1373 | ha->fw_dump->fixed_size = htonl(fixed_size); |
| 1374 | ha->fw_dump->mem_size = htonl(mem_size); |
| 1375 | ha->fw_dump->req_q_size = htonl(req_q_size); |
| 1376 | ha->fw_dump->rsp_q_size = htonl(rsp_q_size); |
| 1377 | |
| 1378 | ha->fw_dump->eft_size = htonl(eft_size); |
| 1379 | ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma)); |
| 1380 | ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma)); |
| 1381 | |
| 1382 | ha->fw_dump->header_size = |
| 1383 | htonl(offsetof(struct qla2xxx_fw_dump, isp)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1384 | } |
| 1385 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1386 | static int |
| 1387 | qla81xx_mpi_sync(scsi_qla_host_t *vha) |
| 1388 | { |
| 1389 | #define MPS_MASK 0xe0 |
| 1390 | int rval; |
| 1391 | uint16_t dc; |
| 1392 | uint32_t dw; |
| 1393 | struct qla_hw_data *ha = vha->hw; |
| 1394 | |
| 1395 | if (!IS_QLA81XX(vha->hw)) |
| 1396 | return QLA_SUCCESS; |
| 1397 | |
| 1398 | rval = qla2x00_write_ram_word(vha, 0x7c00, 1); |
| 1399 | if (rval != QLA_SUCCESS) { |
| 1400 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1401 | "Sync-MPI: Unable to acquire semaphore.\n")); |
| 1402 | goto done; |
| 1403 | } |
| 1404 | |
| 1405 | pci_read_config_word(vha->hw->pdev, 0x54, &dc); |
| 1406 | rval = qla2x00_read_ram_word(vha, 0x7a15, &dw); |
| 1407 | if (rval != QLA_SUCCESS) { |
| 1408 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1409 | "Sync-MPI: Unable to read sync.\n")); |
| 1410 | goto done_release; |
| 1411 | } |
| 1412 | |
| 1413 | dc &= MPS_MASK; |
| 1414 | if (dc == (dw & MPS_MASK)) |
| 1415 | goto done_release; |
| 1416 | |
| 1417 | dw &= ~MPS_MASK; |
| 1418 | dw |= dc; |
| 1419 | rval = qla2x00_write_ram_word(vha, 0x7a15, dw); |
| 1420 | if (rval != QLA_SUCCESS) { |
| 1421 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1422 | "Sync-MPI: Unable to gain sync.\n")); |
| 1423 | } |
| 1424 | |
| 1425 | done_release: |
| 1426 | rval = qla2x00_write_ram_word(vha, 0x7c00, 0); |
| 1427 | if (rval != QLA_SUCCESS) { |
| 1428 | DEBUG2(qla_printk(KERN_WARNING, ha, |
| 1429 | "Sync-MPI: Unable to release semaphore.\n")); |
| 1430 | } |
| 1431 | |
| 1432 | done: |
| 1433 | return rval; |
| 1434 | } |
| 1435 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1436 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | * qla2x00_setup_chip() - Load and start RISC firmware. |
| 1438 | * @ha: HA context |
| 1439 | * |
| 1440 | * Returns 0 on success. |
| 1441 | */ |
| 1442 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1443 | qla2x00_setup_chip(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1445 | int rval; |
| 1446 | uint32_t srisc_address = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1447 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1448 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
| 1449 | unsigned long flags; |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1450 | uint16_t fw_major_version; |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1451 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1452 | if (IS_QLA82XX(ha)) { |
| 1453 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1454 | if (rval == QLA_SUCCESS) { |
| 1455 | qla2x00_stop_firmware(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1456 | goto enable_82xx_npiv; |
Andrew Vasquez | 14e303d | 2010-07-23 15:28:29 +0500 | [diff] [blame] | 1457 | } else |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1458 | goto failed; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1459 | } |
| 1460 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1461 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1462 | /* Disable SRAM, Instruction RAM and GP RAM parity. */ |
| 1463 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1464 | WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0)); |
| 1465 | RD_REG_WORD(®->hccr); |
| 1466 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1467 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1468 | |
Andrew Vasquez | 18e7555 | 2009-06-03 09:55:30 -0700 | [diff] [blame] | 1469 | qla81xx_mpi_sync(vha); |
| 1470 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1471 | /* Load firmware sequences */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1472 | rval = ha->isp_ops->load_risc(vha, &srisc_address); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1473 | if (rval == QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1474 | DEBUG(printk("scsi(%ld): Verifying Checksum of loaded RISC " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1475 | "code.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1476 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1477 | rval = qla2x00_verify_checksum(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | if (rval == QLA_SUCCESS) { |
| 1479 | /* Start firmware execution. */ |
| 1480 | DEBUG(printk("scsi(%ld): Checksum OK, start " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1481 | "firmware.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1483 | rval = qla2x00_execute_fw(vha, srisc_address); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | /* Retrieve firmware information. */ |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1485 | if (rval == QLA_SUCCESS) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1486 | enable_82xx_npiv: |
Andrew Vasquez | dda772e | 2009-03-24 09:08:00 -0700 | [diff] [blame] | 1487 | fw_major_version = ha->fw_major_version; |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1488 | rval = qla2x00_get_fw_version(vha, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | &ha->fw_major_version, |
| 1490 | &ha->fw_minor_version, |
| 1491 | &ha->fw_subminor_version, |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 1492 | &ha->fw_attributes, &ha->fw_memory_size, |
Andrew Vasquez | 55a9615 | 2009-03-24 09:08:03 -0700 | [diff] [blame] | 1493 | ha->mpi_version, &ha->mpi_capabilities, |
| 1494 | ha->phy_version); |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1495 | if (rval != QLA_SUCCESS) |
| 1496 | goto failed; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1497 | ha->flags.npiv_supported = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1498 | if (IS_QLA2XXX_MIDTYPE(ha) && |
Mike Hernandez | 946fb89 | 2008-08-13 21:36:59 -0700 | [diff] [blame] | 1499 | (ha->fw_attributes & BIT_2)) { |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1500 | ha->flags.npiv_supported = 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1501 | if ((!ha->max_npiv_vports) || |
| 1502 | ((ha->max_npiv_vports + 1) % |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1503 | MIN_MULTI_ID_FABRIC)) |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1504 | ha->max_npiv_vports = |
Andrew Vasquez | eb66dc6 | 2007-11-12 10:30:58 -0800 | [diff] [blame] | 1505 | MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | 4d0ea24 | 2007-09-20 14:07:43 -0700 | [diff] [blame] | 1506 | } |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1507 | qla2x00_get_resource_cnts(vha, NULL, |
| 1508 | &ha->fw_xcb_count, NULL, NULL, |
Andrew Vasquez | f3a0a77 | 2009-10-13 15:16:49 -0700 | [diff] [blame] | 1509 | &ha->max_npiv_vports, NULL); |
Andrew Vasquez | d743de6 | 2009-03-24 09:08:15 -0700 | [diff] [blame] | 1510 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1511 | if (!fw_major_version && ql2xallocfwdump) { |
| 1512 | if (!IS_QLA82XX(ha)) |
| 1513 | qla2x00_alloc_fw_dump(vha); |
| 1514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | } |
| 1516 | } else { |
| 1517 | DEBUG2(printk(KERN_INFO |
| 1518 | "scsi(%ld): ISP Firmware failed checksum.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1519 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | } |
| 1521 | } |
| 1522 | |
Andrew Vasquez | 3db0652 | 2008-01-31 12:33:49 -0800 | [diff] [blame] | 1523 | if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) { |
| 1524 | /* Enable proper parity. */ |
| 1525 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1526 | if (IS_QLA2300(ha)) |
| 1527 | /* SRAM parity */ |
| 1528 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1); |
| 1529 | else |
| 1530 | /* SRAM, Instruction RAM and GP RAM parity */ |
| 1531 | WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7); |
| 1532 | RD_REG_WORD(®->hccr); |
| 1533 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1534 | } |
| 1535 | |
Joe Carnuccio | 1d2874d | 2009-03-24 09:08:06 -0700 | [diff] [blame] | 1536 | if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) { |
| 1537 | uint32_t size; |
| 1538 | |
| 1539 | rval = qla81xx_fac_get_sector_size(vha, &size); |
| 1540 | if (rval == QLA_SUCCESS) { |
| 1541 | ha->flags.fac_supported = 1; |
| 1542 | ha->fdt_block_size = size << 2; |
| 1543 | } else { |
| 1544 | qla_printk(KERN_ERR, ha, |
| 1545 | "Unsupported FAC firmware (%d.%02d.%02d).\n", |
| 1546 | ha->fw_major_version, ha->fw_minor_version, |
| 1547 | ha->fw_subminor_version); |
| 1548 | } |
| 1549 | } |
Andrew Vasquez | ca9e9c3 | 2009-06-03 09:55:20 -0700 | [diff] [blame] | 1550 | failed: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | if (rval) { |
| 1552 | DEBUG2_3(printk("scsi(%ld): Setup chip **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1553 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | } |
| 1555 | |
| 1556 | return (rval); |
| 1557 | } |
| 1558 | |
| 1559 | /** |
| 1560 | * qla2x00_init_response_q_entries() - Initializes response queue entries. |
| 1561 | * @ha: HA context |
| 1562 | * |
| 1563 | * Beginning of request ring has initialization control block already built |
| 1564 | * by nvram config routine. |
| 1565 | * |
| 1566 | * Returns 0 on success. |
| 1567 | */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1568 | void |
| 1569 | qla2x00_init_response_q_entries(struct rsp_que *rsp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
| 1571 | uint16_t cnt; |
| 1572 | response_t *pkt; |
| 1573 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1574 | rsp->ring_ptr = rsp->ring; |
| 1575 | rsp->ring_index = 0; |
| 1576 | rsp->status_srb = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1577 | pkt = rsp->ring_ptr; |
| 1578 | for (cnt = 0; cnt < rsp->length; cnt++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | pkt->signature = RESPONSE_PROCESSED; |
| 1580 | pkt++; |
| 1581 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | } |
| 1583 | |
| 1584 | /** |
| 1585 | * qla2x00_update_fw_options() - Read and process firmware options. |
| 1586 | * @ha: HA context |
| 1587 | * |
| 1588 | * Returns 0 on success. |
| 1589 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1590 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1591 | qla2x00_update_fw_options(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | { |
| 1593 | uint16_t swing, emphasis, tx_sens, rx_sens; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1594 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1595 | |
| 1596 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1597 | qla2x00_get_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1598 | |
| 1599 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
| 1600 | return; |
| 1601 | |
| 1602 | /* Serial Link options. */ |
| 1603 | DEBUG3(printk("scsi(%ld): Serial link options:\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1604 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | DEBUG3(qla2x00_dump_buffer((uint8_t *)&ha->fw_seriallink_options, |
| 1606 | sizeof(ha->fw_seriallink_options))); |
| 1607 | |
| 1608 | ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING; |
| 1609 | if (ha->fw_seriallink_options[3] & BIT_2) { |
| 1610 | ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING; |
| 1611 | |
| 1612 | /* 1G settings */ |
| 1613 | swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0); |
| 1614 | emphasis = (ha->fw_seriallink_options[2] & |
| 1615 | (BIT_4 | BIT_3)) >> 3; |
| 1616 | tx_sens = ha->fw_seriallink_options[0] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1617 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | rx_sens = (ha->fw_seriallink_options[0] & |
| 1619 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1620 | ha->fw_options[10] = (emphasis << 14) | (swing << 8); |
| 1621 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1622 | if (rx_sens == 0x0) |
| 1623 | rx_sens = 0x3; |
| 1624 | ha->fw_options[10] |= (tx_sens << 4) | rx_sens; |
| 1625 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1626 | ha->fw_options[10] |= BIT_5 | |
| 1627 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1628 | (tx_sens & (BIT_1 | BIT_0)); |
| 1629 | |
| 1630 | /* 2G settings */ |
| 1631 | swing = (ha->fw_seriallink_options[2] & |
| 1632 | (BIT_7 | BIT_6 | BIT_5)) >> 5; |
| 1633 | emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0); |
| 1634 | tx_sens = ha->fw_seriallink_options[1] & |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1635 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1636 | rx_sens = (ha->fw_seriallink_options[1] & |
| 1637 | (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 1638 | ha->fw_options[11] = (emphasis << 14) | (swing << 8); |
| 1639 | if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) { |
| 1640 | if (rx_sens == 0x0) |
| 1641 | rx_sens = 0x3; |
| 1642 | ha->fw_options[11] |= (tx_sens << 4) | rx_sens; |
| 1643 | } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) |
| 1644 | ha->fw_options[11] |= BIT_5 | |
| 1645 | ((rx_sens & (BIT_1 | BIT_0)) << 2) | |
| 1646 | (tx_sens & (BIT_1 | BIT_0)); |
| 1647 | } |
| 1648 | |
| 1649 | /* FCP2 options. */ |
| 1650 | /* Return command IOCBs without waiting for an ABTS to complete. */ |
| 1651 | ha->fw_options[3] |= BIT_13; |
| 1652 | |
| 1653 | /* LED scheme. */ |
| 1654 | if (ha->flags.enable_led_scheme) |
| 1655 | ha->fw_options[2] |= BIT_12; |
| 1656 | |
andrew.vasquez@qlogic.com | 48c02fd | 2006-03-09 14:27:18 -0800 | [diff] [blame] | 1657 | /* Detect ISP6312. */ |
| 1658 | if (IS_QLA6312(ha)) |
| 1659 | ha->fw_options[2] |= BIT_13; |
| 1660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1661 | /* Update firmware options. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1662 | qla2x00_set_fw_options(vha, ha->fw_options); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1663 | } |
| 1664 | |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1665 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1666 | qla24xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1667 | { |
| 1668 | int rval; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1669 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1670 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 1671 | if (IS_QLA82XX(ha)) |
| 1672 | return; |
| 1673 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1674 | /* Update Serial Link options. */ |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1675 | if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1676 | return; |
| 1677 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1678 | rval = qla2x00_set_serdes_params(vha, |
andrew.vasquez@qlogic.com | f94097e | 2006-01-13 17:05:32 -0800 | [diff] [blame] | 1679 | le16_to_cpu(ha->fw_seriallink_options24[1]), |
| 1680 | le16_to_cpu(ha->fw_seriallink_options24[2]), |
| 1681 | le16_to_cpu(ha->fw_seriallink_options24[3])); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1682 | if (rval != QLA_SUCCESS) { |
| 1683 | qla_printk(KERN_WARNING, ha, |
| 1684 | "Unable to update Serial Link options (%x).\n", rval); |
| 1685 | } |
| 1686 | } |
| 1687 | |
| 1688 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1689 | qla2x00_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1690 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1691 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 1692 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1693 | struct req_que *req = ha->req_q_map[0]; |
| 1694 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 1695 | |
| 1696 | /* Setup ring parameters in initialization control block. */ |
| 1697 | ha->init_cb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1698 | ha->init_cb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1699 | ha->init_cb->request_q_length = cpu_to_le16(req->length); |
| 1700 | ha->init_cb->response_q_length = cpu_to_le16(rsp->length); |
| 1701 | ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1702 | ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1703 | ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1704 | 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] | 1705 | |
| 1706 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0); |
| 1707 | WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0); |
| 1708 | WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0); |
| 1709 | WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0); |
| 1710 | RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */ |
| 1711 | } |
| 1712 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1713 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1714 | qla24xx_config_rings(struct scsi_qla_host *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1715 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1716 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1717 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, 0); |
| 1718 | struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp; |
| 1719 | struct qla_msix_entry *msix; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1720 | struct init_cb_24xx *icb; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1721 | uint16_t rid = 0; |
| 1722 | struct req_que *req = ha->req_q_map[0]; |
| 1723 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1724 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1725 | /* Setup ring parameters in initialization control block. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1726 | icb = (struct init_cb_24xx *)ha->init_cb; |
| 1727 | icb->request_q_outpointer = __constant_cpu_to_le16(0); |
| 1728 | icb->response_q_inpointer = __constant_cpu_to_le16(0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1729 | icb->request_q_length = cpu_to_le16(req->length); |
| 1730 | icb->response_q_length = cpu_to_le16(rsp->length); |
| 1731 | icb->request_q_address[0] = cpu_to_le32(LSD(req->dma)); |
| 1732 | icb->request_q_address[1] = cpu_to_le32(MSD(req->dma)); |
| 1733 | icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma)); |
| 1734 | icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1735 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1736 | if (ha->mqenable) { |
| 1737 | icb->qos = __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS); |
| 1738 | icb->rid = __constant_cpu_to_le16(rid); |
| 1739 | if (ha->flags.msix_enabled) { |
| 1740 | msix = &ha->msix_entries[1]; |
| 1741 | DEBUG2_17(printk(KERN_INFO |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1742 | "Registering vector 0x%x for base que\n", msix->entry)); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1743 | icb->msix = cpu_to_le16(msix->entry); |
| 1744 | } |
| 1745 | /* Use alternate PCI bus number */ |
| 1746 | if (MSB(rid)) |
| 1747 | icb->firmware_options_2 |= |
| 1748 | __constant_cpu_to_le32(BIT_19); |
| 1749 | /* Use alternate PCI devfn */ |
| 1750 | if (LSB(rid)) |
| 1751 | icb->firmware_options_2 |= |
| 1752 | __constant_cpu_to_le32(BIT_18); |
| 1753 | |
Anirban Chakraborty | 3155754 | 2009-12-02 10:36:55 -0800 | [diff] [blame] | 1754 | /* Use Disable MSIX Handshake mode for capable adapters */ |
| 1755 | if (IS_MSIX_NACK_CAPABLE(ha)) { |
| 1756 | icb->firmware_options_2 &= |
| 1757 | __constant_cpu_to_le32(~BIT_22); |
| 1758 | ha->flags.disable_msix_handshake = 1; |
| 1759 | qla_printk(KERN_INFO, ha, |
| 1760 | "MSIX Handshake Disable Mode turned on\n"); |
| 1761 | } else { |
| 1762 | icb->firmware_options_2 |= |
| 1763 | __constant_cpu_to_le32(BIT_22); |
| 1764 | } |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1765 | icb->firmware_options_2 |= __constant_cpu_to_le32(BIT_23); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1766 | |
| 1767 | WRT_REG_DWORD(®->isp25mq.req_q_in, 0); |
| 1768 | WRT_REG_DWORD(®->isp25mq.req_q_out, 0); |
| 1769 | WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0); |
| 1770 | WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0); |
| 1771 | } else { |
| 1772 | WRT_REG_DWORD(®->isp24.req_q_in, 0); |
| 1773 | WRT_REG_DWORD(®->isp24.req_q_out, 0); |
| 1774 | WRT_REG_DWORD(®->isp24.rsp_q_in, 0); |
| 1775 | WRT_REG_DWORD(®->isp24.rsp_q_out, 0); |
| 1776 | } |
| 1777 | /* PCI posting */ |
| 1778 | RD_REG_DWORD(&ioreg->hccr); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1781 | /** |
| 1782 | * qla2x00_init_rings() - Initializes firmware. |
| 1783 | * @ha: HA context |
| 1784 | * |
| 1785 | * Beginning of request ring has initialization control block already built |
| 1786 | * by nvram config routine. |
| 1787 | * |
| 1788 | * Returns 0 on success. |
| 1789 | */ |
| 1790 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1791 | qla2x00_init_rings(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1792 | { |
| 1793 | int rval; |
| 1794 | unsigned long flags = 0; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1795 | int cnt, que; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1796 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1797 | struct req_que *req; |
| 1798 | struct rsp_que *rsp; |
| 1799 | struct scsi_qla_host *vp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1800 | struct mid_init_cb_24xx *mid_init_cb = |
| 1801 | (struct mid_init_cb_24xx *) ha->init_cb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1802 | |
| 1803 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1804 | |
| 1805 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1806 | for (que = 0; que < ha->max_req_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1807 | req = ha->req_q_map[que]; |
| 1808 | if (!req) |
| 1809 | continue; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1810 | for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1811 | req->outstanding_cmds[cnt] = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1813 | req->current_outstanding_cmd = 1; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1814 | |
| 1815 | /* Initialize firmware. */ |
| 1816 | req->ring_ptr = req->ring; |
| 1817 | req->ring_index = 0; |
| 1818 | req->cnt = req->length; |
| 1819 | } |
| 1820 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1821 | for (que = 0; que < ha->max_rsp_queues; que++) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1822 | rsp = ha->rsp_q_map[que]; |
| 1823 | if (!rsp) |
| 1824 | continue; |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1825 | /* Initialize response queue entries */ |
| 1826 | qla2x00_init_response_q_entries(rsp); |
| 1827 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1828 | |
Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1829 | spin_lock(&ha->vport_slock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | /* Clear RSCN queue. */ |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 1831 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 1832 | vp->rscn_in_ptr = 0; |
| 1833 | vp->rscn_out_ptr = 0; |
| 1834 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1835 | |
Dan Carpenter | 542bce1 | 2010-10-15 11:27:38 -0700 | [diff] [blame] | 1836 | spin_unlock(&ha->vport_slock); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 1837 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1838 | ha->isp_ops->config_rings(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1839 | |
| 1840 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1841 | |
| 1842 | /* Update any ISP specific firmware options before initialization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1843 | ha->isp_ops->update_fw_options(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1845 | DEBUG(printk("scsi(%ld): Issue init firmware.\n", vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1846 | |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1847 | if (ha->flags.npiv_supported) { |
| 1848 | if (ha->operating_mode == LOOP) |
| 1849 | ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1; |
Seokmann Ju | c48339d | 2008-01-17 09:02:19 -0800 | [diff] [blame] | 1850 | mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports); |
Lalit Chandivade | 605aa2b | 2009-03-05 11:07:01 -0800 | [diff] [blame] | 1851 | } |
| 1852 | |
Andrew Vasquez | 24a0813 | 2009-03-24 09:08:16 -0700 | [diff] [blame] | 1853 | if (IS_FWI2_CAPABLE(ha)) { |
| 1854 | mid_init_cb->options = __constant_cpu_to_le16(BIT_1); |
| 1855 | mid_init_cb->init_cb.execution_throttle = |
| 1856 | cpu_to_le16(ha->fw_xcb_count); |
| 1857 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1858 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1859 | rval = qla2x00_init_firmware(vha, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | if (rval) { |
| 1861 | DEBUG2_3(printk("scsi(%ld): Init firmware **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1862 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | } else { |
| 1864 | DEBUG3(printk("scsi(%ld): Init firmware -- success.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1865 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1866 | } |
| 1867 | |
| 1868 | return (rval); |
| 1869 | } |
| 1870 | |
| 1871 | /** |
| 1872 | * qla2x00_fw_ready() - Waits for firmware ready. |
| 1873 | * @ha: HA context |
| 1874 | * |
| 1875 | * Returns 0 on success. |
| 1876 | */ |
| 1877 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1878 | qla2x00_fw_ready(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | { |
| 1880 | int rval; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1881 | unsigned long wtime, mtime, cs84xx_time; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | uint16_t min_wait; /* Minimum wait time if loop is down */ |
| 1883 | uint16_t wait_time; /* Wait time if loop is coming ready */ |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1884 | uint16_t state[5]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1885 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | |
| 1887 | rval = QLA_SUCCESS; |
| 1888 | |
| 1889 | /* 20 seconds for loop down. */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1890 | min_wait = 20; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | |
| 1892 | /* |
| 1893 | * Firmware should take at most one RATOV to login, plus 5 seconds for |
| 1894 | * our own processing. |
| 1895 | */ |
| 1896 | if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) { |
| 1897 | wait_time = min_wait; |
| 1898 | } |
| 1899 | |
| 1900 | /* Min wait time if loop down */ |
| 1901 | mtime = jiffies + (min_wait * HZ); |
| 1902 | |
| 1903 | /* wait time before firmware ready */ |
| 1904 | wtime = jiffies + (wait_time * HZ); |
| 1905 | |
| 1906 | /* Wait for ISP to finish LIP */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1907 | if (!vha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1908 | qla_printk(KERN_INFO, ha, "Waiting for LIP to complete...\n"); |
| 1909 | |
| 1910 | DEBUG3(printk("scsi(%ld): Waiting for LIP to complete...\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1911 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | |
| 1913 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1914 | rval = qla2x00_get_firmware_state(vha, state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | if (rval == QLA_SUCCESS) { |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1916 | if (state[0] < FSTATE_LOSS_OF_SYNC) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1917 | vha->device_flags &= ~DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1919 | if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) { |
| 1920 | DEBUG16(printk("scsi(%ld): fw_state=%x " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1921 | "84xx=%x.\n", vha->host_no, state[0], |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1922 | state[2])); |
| 1923 | if ((state[2] & FSTATE_LOGGED_IN) && |
| 1924 | (state[2] & FSTATE_WAITING_FOR_VERIFY)) { |
| 1925 | DEBUG16(printk("scsi(%ld): Sending " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1926 | "verify iocb.\n", vha->host_no)); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1927 | |
| 1928 | cs84xx_time = jiffies; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1929 | rval = qla84xx_init_chip(vha); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1930 | if (rval != QLA_SUCCESS) |
| 1931 | break; |
| 1932 | |
| 1933 | /* Add time taken to initialize. */ |
| 1934 | cs84xx_time = jiffies - cs84xx_time; |
| 1935 | wtime += cs84xx_time; |
| 1936 | mtime += cs84xx_time; |
| 1937 | DEBUG16(printk("scsi(%ld): Increasing " |
| 1938 | "wait time by %ld. New time %ld\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1939 | vha->host_no, cs84xx_time, wtime)); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1940 | } |
| 1941 | } else if (state[0] == FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1942 | DEBUG(printk("scsi(%ld): F/W Ready - OK \n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1943 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1944 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1945 | qla2x00_get_retry_cnt(vha, &ha->retry_count, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | &ha->login_timeout, &ha->r_a_tov); |
| 1947 | |
| 1948 | rval = QLA_SUCCESS; |
| 1949 | break; |
| 1950 | } |
| 1951 | |
| 1952 | rval = QLA_FUNCTION_FAILED; |
| 1953 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1954 | if (atomic_read(&vha->loop_down_timer) && |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 1955 | state[0] != FSTATE_READY) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1956 | /* Loop down. Timeout on min_wait for states |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 1957 | * other than Wait for Login. |
| 1958 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | if (time_after_eq(jiffies, mtime)) { |
| 1960 | qla_printk(KERN_INFO, ha, |
| 1961 | "Cable is unplugged...\n"); |
| 1962 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1963 | vha->device_flags |= DFLG_NO_CABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | break; |
| 1965 | } |
| 1966 | } |
| 1967 | } else { |
| 1968 | /* Mailbox cmd failed. Timeout on min_wait. */ |
Santosh Vernekar | cdbb0a4f | 2010-05-28 15:08:25 -0700 | [diff] [blame] | 1969 | if (time_after_eq(jiffies, mtime) || |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 1970 | ha->flags.isp82xx_fw_hung) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | break; |
| 1972 | } |
| 1973 | |
| 1974 | if (time_after_eq(jiffies, wtime)) |
| 1975 | break; |
| 1976 | |
| 1977 | /* Delay for a while */ |
| 1978 | msleep(500); |
| 1979 | |
| 1980 | DEBUG3(printk("scsi(%ld): fw_state=%x curr time=%lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1981 | vha->host_no, state[0], jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | } while (1); |
| 1983 | |
Andrew Vasquez | 656e891 | 2009-06-03 09:55:29 -0700 | [diff] [blame] | 1984 | DEBUG(printk("scsi(%ld): fw_state=%x (%x, %x, %x, %x) curr time=%lx.\n", |
| 1985 | vha->host_no, state[0], state[1], state[2], state[3], state[4], |
| 1986 | jiffies)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1987 | |
| 1988 | if (rval) { |
| 1989 | DEBUG2_3(printk("scsi(%ld): Firmware ready **** FAILED ****.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1990 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | } |
| 1992 | |
| 1993 | return (rval); |
| 1994 | } |
| 1995 | |
| 1996 | /* |
| 1997 | * qla2x00_configure_hba |
| 1998 | * Setup adapter context. |
| 1999 | * |
| 2000 | * Input: |
| 2001 | * ha = adapter state pointer. |
| 2002 | * |
| 2003 | * Returns: |
| 2004 | * 0 = success |
| 2005 | * |
| 2006 | * Context: |
| 2007 | * Kernel context. |
| 2008 | */ |
| 2009 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2010 | qla2x00_configure_hba(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | { |
| 2012 | int rval; |
| 2013 | uint16_t loop_id; |
| 2014 | uint16_t topo; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2015 | uint16_t sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | uint8_t al_pa; |
| 2017 | uint8_t area; |
| 2018 | uint8_t domain; |
| 2019 | char connect_type[22]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2020 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
| 2022 | /* Get host addresses. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2023 | rval = qla2x00_get_adapter_id(vha, |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2024 | &loop_id, &al_pa, &area, &domain, &topo, &sw_cap); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2026 | if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) || |
Andrew Vasquez | 7a44b86 | 2010-12-21 16:00:23 -0800 | [diff] [blame] | 2027 | IS_QLA8XXX_TYPE(ha) || |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2028 | (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) { |
| 2029 | DEBUG2(printk("%s(%ld) Loop is in a transition state\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2030 | __func__, vha->host_no)); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2031 | } else { |
| 2032 | qla_printk(KERN_WARNING, ha, |
| 2033 | "ERROR -- Unable to get host loop ID.\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2034 | set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
Ravi Anand | 33135aa | 2005-11-08 14:37:20 -0800 | [diff] [blame] | 2035 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | return (rval); |
| 2037 | } |
| 2038 | |
| 2039 | if (topo == 4) { |
| 2040 | qla_printk(KERN_INFO, ha, |
| 2041 | "Cannot get topology - retrying.\n"); |
| 2042 | return (QLA_FUNCTION_FAILED); |
| 2043 | } |
| 2044 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2045 | vha->loop_id = loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | |
| 2047 | /* initialize */ |
| 2048 | ha->min_external_loopid = SNS_FIRST_LOOP_ID; |
| 2049 | ha->operating_mode = LOOP; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2050 | ha->switch_cap = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | |
| 2052 | switch (topo) { |
| 2053 | case 0: |
| 2054 | DEBUG3(printk("scsi(%ld): HBA in NL topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2055 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | ha->current_topology = ISP_CFG_NL; |
| 2057 | strcpy(connect_type, "(Loop)"); |
| 2058 | break; |
| 2059 | |
| 2060 | case 1: |
| 2061 | DEBUG3(printk("scsi(%ld): HBA in FL topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2062 | vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2063 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | ha->current_topology = ISP_CFG_FL; |
| 2065 | strcpy(connect_type, "(FL_Port)"); |
| 2066 | break; |
| 2067 | |
| 2068 | case 2: |
| 2069 | DEBUG3(printk("scsi(%ld): HBA in N P2P topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2070 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | ha->operating_mode = P2P; |
| 2072 | ha->current_topology = ISP_CFG_N; |
| 2073 | strcpy(connect_type, "(N_Port-to-N_Port)"); |
| 2074 | break; |
| 2075 | |
| 2076 | case 3: |
| 2077 | DEBUG3(printk("scsi(%ld): HBA in F P2P topology.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2078 | vha->host_no)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2079 | ha->switch_cap = sw_cap; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2080 | ha->operating_mode = P2P; |
| 2081 | ha->current_topology = ISP_CFG_F; |
| 2082 | strcpy(connect_type, "(F_Port)"); |
| 2083 | break; |
| 2084 | |
| 2085 | default: |
| 2086 | DEBUG3(printk("scsi(%ld): HBA in unknown topology %x. " |
| 2087 | "Using NL.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2088 | vha->host_no, topo)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2089 | ha->current_topology = ISP_CFG_NL; |
| 2090 | strcpy(connect_type, "(Loop)"); |
| 2091 | break; |
| 2092 | } |
| 2093 | |
| 2094 | /* Save Host port and loop ID. */ |
| 2095 | /* byte order - Big Endian */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2096 | vha->d_id.b.domain = domain; |
| 2097 | vha->d_id.b.area = area; |
| 2098 | vha->d_id.b.al_pa = al_pa; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2099 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2100 | if (!vha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2101 | qla_printk(KERN_INFO, ha, |
| 2102 | "Topology - %s, Host Loop address 0x%x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2103 | connect_type, vha->loop_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | |
| 2105 | if (rval) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2106 | DEBUG2_3(printk("scsi(%ld): FAILED.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2108 | DEBUG3(printk("scsi(%ld): exiting normally.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | } |
| 2110 | |
| 2111 | return(rval); |
| 2112 | } |
| 2113 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2114 | inline void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2115 | qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len, |
| 2116 | char *def) |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2117 | { |
| 2118 | char *st, *en; |
| 2119 | uint16_t index; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2120 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ab67114 | 2009-08-25 11:36:17 -0700 | [diff] [blame] | 2121 | int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) && |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 2122 | !IS_QLA8XXX_TYPE(ha); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2123 | |
| 2124 | if (memcmp(model, BINZERO, len) != 0) { |
| 2125 | strncpy(ha->model_number, model, len); |
| 2126 | st = en = ha->model_number; |
| 2127 | en += len - 1; |
| 2128 | while (en > st) { |
| 2129 | if (*en != 0x20 && *en != 0x00) |
| 2130 | break; |
| 2131 | *en-- = '\0'; |
| 2132 | } |
| 2133 | |
| 2134 | index = (ha->pdev->subsystem_device & 0xff); |
Andrew Vasquez | 7d0dba1 | 2009-04-06 22:33:45 -0700 | [diff] [blame] | 2135 | if (use_tbl && |
| 2136 | ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC && |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2137 | index < QLA_MODEL_NAMES) |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2138 | strncpy(ha->model_desc, |
| 2139 | qla2x00_model_name[index * 2 + 1], |
| 2140 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2141 | } else { |
| 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) { |
| 2146 | strcpy(ha->model_number, |
| 2147 | qla2x00_model_name[index * 2]); |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2148 | strncpy(ha->model_desc, |
| 2149 | qla2x00_model_name[index * 2 + 1], |
| 2150 | sizeof(ha->model_desc) - 1); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2151 | } else { |
| 2152 | strcpy(ha->model_number, def); |
| 2153 | } |
| 2154 | } |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2155 | if (IS_FWI2_CAPABLE(ha)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2156 | qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc, |
Joe Carnuccio | 1ee2714 | 2008-07-10 16:55:53 -0700 | [diff] [blame] | 2157 | sizeof(ha->model_desc)); |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2158 | } |
| 2159 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2160 | /* On sparc systems, obtain port and node WWN from firmware |
| 2161 | * properties. |
| 2162 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2163 | 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] | 2164 | { |
| 2165 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2166 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2167 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 2168 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 2169 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2170 | int len; |
| 2171 | |
| 2172 | val = of_get_property(dp, "port-wwn", &len); |
| 2173 | if (val && len >= WWN_SIZE) |
| 2174 | memcpy(nv->port_name, val, WWN_SIZE); |
| 2175 | |
| 2176 | val = of_get_property(dp, "node-wwn", &len); |
| 2177 | if (val && len >= WWN_SIZE) |
| 2178 | memcpy(nv->node_name, val, WWN_SIZE); |
| 2179 | #endif |
| 2180 | } |
| 2181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | /* |
| 2183 | * NVRAM configuration for ISP 2xxx |
| 2184 | * |
| 2185 | * Input: |
| 2186 | * ha = adapter block pointer. |
| 2187 | * |
| 2188 | * Output: |
| 2189 | * initialization control block in response_ring |
| 2190 | * host adapters parameters in host adapter block |
| 2191 | * |
| 2192 | * Returns: |
| 2193 | * 0 = success. |
| 2194 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2195 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2196 | qla2x00_nvram_config(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2197 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2198 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2199 | uint8_t chksum = 0; |
| 2200 | uint16_t cnt; |
| 2201 | uint8_t *dptr1, *dptr2; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2202 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2203 | init_cb_t *icb = ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2204 | nvram_t *nv = ha->nvram; |
| 2205 | uint8_t *ptr = ha->nvram; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 2206 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2208 | rval = QLA_SUCCESS; |
| 2209 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2210 | /* Determine NVRAM starting address. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2211 | ha->nvram_size = sizeof(nvram_t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | ha->nvram_base = 0; |
| 2213 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha)) |
| 2214 | if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1) |
| 2215 | ha->nvram_base = 0x80; |
| 2216 | |
| 2217 | /* Get NVRAM data and calculate checksum. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2218 | ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2219 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++) |
| 2220 | chksum += *ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2222 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 2223 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | |
| 2225 | /* Bad NVRAM data, set defaults parameters. */ |
| 2226 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || |
| 2227 | nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) { |
| 2228 | /* Reset NVRAM data. */ |
| 2229 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 2230 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 2231 | nv->nvram_version); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2232 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 2233 | "invalid -- WWPN) defaults.\n"); |
| 2234 | |
| 2235 | /* |
| 2236 | * Set default initialization control block. |
| 2237 | */ |
| 2238 | memset(nv, 0, ha->nvram_size); |
| 2239 | nv->parameter_block_version = ICB_VERSION; |
| 2240 | |
| 2241 | if (IS_QLA23XX(ha)) { |
| 2242 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2243 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2244 | nv->add_firmware_options[0] = BIT_5; |
| 2245 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2246 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2247 | nv->special_options[1] = BIT_7; |
| 2248 | } else if (IS_QLA2200(ha)) { |
| 2249 | nv->firmware_options[0] = BIT_2 | BIT_1; |
| 2250 | nv->firmware_options[1] = BIT_7 | BIT_5; |
| 2251 | nv->add_firmware_options[0] = BIT_5; |
| 2252 | nv->add_firmware_options[1] = BIT_5 | BIT_4; |
| 2253 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2254 | } else if (IS_QLA2100(ha)) { |
| 2255 | nv->firmware_options[0] = BIT_3 | BIT_1; |
| 2256 | nv->firmware_options[1] = BIT_5; |
| 2257 | nv->frame_payload_size = __constant_cpu_to_le16(1024); |
| 2258 | } |
| 2259 | |
| 2260 | nv->max_iocb_allocation = __constant_cpu_to_le16(256); |
| 2261 | nv->execution_throttle = __constant_cpu_to_le16(16); |
| 2262 | nv->retry_count = 8; |
| 2263 | nv->retry_delay = 1; |
| 2264 | |
| 2265 | nv->port_name[0] = 33; |
| 2266 | nv->port_name[3] = 224; |
| 2267 | nv->port_name[4] = 139; |
| 2268 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2269 | qla2xxx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2270 | |
| 2271 | nv->login_timeout = 4; |
| 2272 | |
| 2273 | /* |
| 2274 | * Set default host adapter parameters |
| 2275 | */ |
| 2276 | nv->host_p[1] = BIT_2; |
| 2277 | nv->reset_delay = 5; |
| 2278 | nv->port_down_retry_count = 8; |
| 2279 | nv->max_luns_per_target = __constant_cpu_to_le16(8); |
| 2280 | nv->link_down_timeout = 60; |
| 2281 | |
| 2282 | rval = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2283 | } |
| 2284 | |
| 2285 | #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2) |
| 2286 | /* |
| 2287 | * The SN2 does not provide BIOS emulation which means you can't change |
| 2288 | * potentially bogus BIOS settings. Force the use of default settings |
| 2289 | * for link rate and frame size. Hope that the rest of the settings |
| 2290 | * are valid. |
| 2291 | */ |
| 2292 | if (ia64_platform_is("sn2")) { |
| 2293 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 2294 | if (IS_QLA23XX(ha)) |
| 2295 | nv->special_options[1] = BIT_7; |
| 2296 | } |
| 2297 | #endif |
| 2298 | |
| 2299 | /* Reset Initialization control block */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2300 | memset(icb, 0, ha->init_cb_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2301 | |
| 2302 | /* |
| 2303 | * Setup driver NVRAM options. |
| 2304 | */ |
| 2305 | nv->firmware_options[0] |= (BIT_6 | BIT_1); |
| 2306 | nv->firmware_options[0] &= ~(BIT_5 | BIT_4); |
| 2307 | nv->firmware_options[1] |= (BIT_5 | BIT_0); |
| 2308 | nv->firmware_options[1] &= ~BIT_4; |
| 2309 | |
| 2310 | if (IS_QLA23XX(ha)) { |
| 2311 | nv->firmware_options[0] |= BIT_2; |
| 2312 | nv->firmware_options[0] &= ~BIT_3; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2313 | nv->firmware_options[0] &= ~BIT_6; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2314 | nv->add_firmware_options[1] |= BIT_5 | BIT_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2315 | |
| 2316 | if (IS_QLA2300(ha)) { |
| 2317 | if (ha->fb_rev == FPM_2310) { |
| 2318 | strcpy(ha->model_number, "QLA2310"); |
| 2319 | } else { |
| 2320 | strcpy(ha->model_number, "QLA2300"); |
| 2321 | } |
| 2322 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2323 | qla2x00_set_model_info(vha, nv->model_number, |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 2324 | sizeof(nv->model_number), "QLA23xx"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2325 | } |
| 2326 | } else if (IS_QLA2200(ha)) { |
| 2327 | nv->firmware_options[0] |= BIT_2; |
| 2328 | /* |
| 2329 | * 'Point-to-point preferred, else loop' is not a safe |
| 2330 | * connection mode setting. |
| 2331 | */ |
| 2332 | if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) == |
| 2333 | (BIT_5 | BIT_4)) { |
| 2334 | /* Force 'loop preferred, else point-to-point'. */ |
| 2335 | nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4); |
| 2336 | nv->add_firmware_options[0] |= BIT_5; |
| 2337 | } |
| 2338 | strcpy(ha->model_number, "QLA22xx"); |
| 2339 | } else /*if (IS_QLA2100(ha))*/ { |
| 2340 | strcpy(ha->model_number, "QLA2100"); |
| 2341 | } |
| 2342 | |
| 2343 | /* |
| 2344 | * Copy over NVRAM RISC parameter block to initialization control block. |
| 2345 | */ |
| 2346 | dptr1 = (uint8_t *)icb; |
| 2347 | dptr2 = (uint8_t *)&nv->parameter_block_version; |
| 2348 | cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version; |
| 2349 | while (cnt--) |
| 2350 | *dptr1++ = *dptr2++; |
| 2351 | |
| 2352 | /* Copy 2nd half. */ |
| 2353 | dptr1 = (uint8_t *)icb->add_firmware_options; |
| 2354 | cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options; |
| 2355 | while (cnt--) |
| 2356 | *dptr1++ = *dptr2++; |
| 2357 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 2358 | /* Use alternate WWN? */ |
| 2359 | if (nv->host_p[1] & BIT_7) { |
| 2360 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 2361 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 2362 | } |
| 2363 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | /* Prepare nodename */ |
| 2365 | if ((icb->firmware_options[1] & BIT_6) == 0) { |
| 2366 | /* |
| 2367 | * Firmware will apply the following mask if the nodename was |
| 2368 | * not provided. |
| 2369 | */ |
| 2370 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 2371 | icb->node_name[0] &= 0xF0; |
| 2372 | } |
| 2373 | |
| 2374 | /* |
| 2375 | * Set host adapter parameters. |
| 2376 | */ |
Andrew Vasquez | 0181944 | 2006-06-23 16:11:10 -0700 | [diff] [blame] | 2377 | if (nv->host_p[0] & BIT_7) |
Andrew Vasquez | 11010fe | 2006-10-06 09:54:59 -0700 | [diff] [blame] | 2378 | ql2xextended_error_logging = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2379 | ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0); |
| 2380 | /* Always load RISC code on non ISP2[12]00 chips. */ |
| 2381 | if (!IS_QLA2100(ha) && !IS_QLA2200(ha)) |
| 2382 | ha->flags.disable_risc_code_load = 0; |
| 2383 | ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0); |
| 2384 | ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0); |
| 2385 | 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] | 2386 | 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] | 2387 | ha->flags.disable_serdes = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2388 | |
| 2389 | ha->operating_mode = |
| 2390 | (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 2391 | |
| 2392 | memcpy(ha->fw_seriallink_options, nv->seriallink_options, |
| 2393 | sizeof(ha->fw_seriallink_options)); |
| 2394 | |
| 2395 | /* save HBA serial number */ |
| 2396 | ha->serial0 = icb->port_name[5]; |
| 2397 | ha->serial1 = icb->port_name[6]; |
| 2398 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2399 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 2400 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | |
| 2402 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 2403 | |
| 2404 | ha->retry_count = nv->retry_count; |
| 2405 | |
| 2406 | /* Set minimum login_timeout to 4 seconds. */ |
Andrew Vasquez | 5b91490 | 2010-05-28 15:08:30 -0700 | [diff] [blame] | 2407 | if (nv->login_timeout != ql2xlogintimeout) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | nv->login_timeout = ql2xlogintimeout; |
| 2409 | if (nv->login_timeout < 4) |
| 2410 | nv->login_timeout = 4; |
| 2411 | ha->login_timeout = nv->login_timeout; |
| 2412 | icb->login_timeout = nv->login_timeout; |
| 2413 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 2414 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 2415 | ha->r_a_tov = 100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | ha->loop_reset_delay = nv->reset_delay; |
| 2418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2419 | /* Link Down Timeout = 0: |
| 2420 | * |
| 2421 | * When Port Down timer expires we will start returning |
| 2422 | * I/O's to OS with "DID_NO_CONNECT". |
| 2423 | * |
| 2424 | * Link Down Timeout != 0: |
| 2425 | * |
| 2426 | * The driver waits for the link to come up after link down |
| 2427 | * before returning I/Os to OS with "DID_NO_CONNECT". |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 2428 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2429 | if (nv->link_down_timeout == 0) { |
| 2430 | ha->loop_down_abort_time = |
Andrew Vasquez | 354d6b2 | 2005-04-23 02:47:27 -0400 | [diff] [blame] | 2431 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | } else { |
| 2433 | ha->link_down_timeout = nv->link_down_timeout; |
| 2434 | ha->loop_down_abort_time = |
| 2435 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2438 | /* |
| 2439 | * Need enough time to try and get the port back. |
| 2440 | */ |
| 2441 | ha->port_down_retry_count = nv->port_down_retry_count; |
| 2442 | if (qlport_down_retry) |
| 2443 | ha->port_down_retry_count = qlport_down_retry; |
| 2444 | /* Set login_retry_count */ |
| 2445 | ha->login_retry_count = nv->retry_count; |
| 2446 | if (ha->port_down_retry_count == nv->port_down_retry_count && |
| 2447 | ha->port_down_retry_count > 3) |
| 2448 | ha->login_retry_count = ha->port_down_retry_count; |
| 2449 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 2450 | ha->login_retry_count = ha->port_down_retry_count; |
| 2451 | if (ql2xloginretrycount) |
| 2452 | ha->login_retry_count = ql2xloginretrycount; |
| 2453 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2454 | icb->lun_enables = __constant_cpu_to_le16(0); |
| 2455 | icb->command_resource_count = 0; |
| 2456 | icb->immediate_notify_resource_count = 0; |
| 2457 | icb->timeout = __constant_cpu_to_le16(0); |
| 2458 | |
| 2459 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) { |
| 2460 | /* Enable RIO */ |
| 2461 | icb->firmware_options[0] &= ~BIT_3; |
| 2462 | icb->add_firmware_options[0] &= |
| 2463 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2464 | icb->add_firmware_options[0] |= BIT_2; |
| 2465 | icb->response_accumulation_timer = 3; |
| 2466 | icb->interrupt_delay_timer = 5; |
| 2467 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2468 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | } else { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2470 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2471 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2472 | ha->zio_mode = icb->add_firmware_options[0] & |
| 2473 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 2474 | ha->zio_timer = icb->interrupt_delay_timer ? |
| 2475 | icb->interrupt_delay_timer: 2; |
| 2476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2477 | icb->add_firmware_options[0] &= |
| 2478 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2479 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2480 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 2481 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 2482 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2483 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2484 | "delay (%d us).\n", vha->host_no, ha->zio_mode, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2485 | ha->zio_timer * 100)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2486 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2487 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 2488 | ha->zio_mode, ha->zio_timer * 100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2489 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 2490 | icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode; |
| 2491 | icb->interrupt_delay_timer = (uint8_t)ha->zio_timer; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2492 | vha->flags.process_response_queue = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2493 | } |
| 2494 | } |
| 2495 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2496 | if (rval) { |
| 2497 | DEBUG2_3(printk(KERN_WARNING |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2498 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 2499 | } |
| 2500 | return (rval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2501 | } |
| 2502 | |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2503 | static void |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2504 | qla2x00_rport_del(void *data) |
| 2505 | { |
| 2506 | fc_port_t *fcport = data; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2507 | struct fc_rport *rport; |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2508 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2509 | spin_lock_irq(fcport->vha->host->host_lock); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2510 | rport = fcport->drport ? fcport->drport: fcport->rport; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2511 | fcport->drport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2512 | spin_unlock_irq(fcport->vha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2513 | if (rport) |
| 2514 | fc_remote_port_delete(rport); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2515 | } |
| 2516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | /** |
| 2518 | * qla2x00_alloc_fcport() - Allocate a generic fcport. |
| 2519 | * @ha: HA context |
| 2520 | * @flags: allocation flags |
| 2521 | * |
| 2522 | * Returns a pointer to the allocated fcport, or NULL, if none available. |
| 2523 | */ |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2524 | fc_port_t * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2525 | qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | { |
| 2527 | fc_port_t *fcport; |
| 2528 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2529 | fcport = kzalloc(sizeof(fc_port_t), flags); |
| 2530 | if (!fcport) |
| 2531 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2532 | |
| 2533 | /* Setup fcport template structure. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2534 | fcport->vha = vha; |
| 2535 | fcport->vp_idx = vha->vp_idx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | fcport->port_type = FCT_UNKNOWN; |
| 2537 | fcport->loop_id = FC_NO_LOOP_ID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | atomic_set(&fcport->state, FCS_UNCONFIGURED); |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2539 | fcport->supported_classes = FC_COS_UNSPECIFIED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2540 | |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 2541 | return fcport; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2542 | } |
| 2543 | |
| 2544 | /* |
| 2545 | * qla2x00_configure_loop |
| 2546 | * Updates Fibre Channel Device Database with what is actually on loop. |
| 2547 | * |
| 2548 | * Input: |
| 2549 | * ha = adapter block pointer. |
| 2550 | * |
| 2551 | * Returns: |
| 2552 | * 0 = success. |
| 2553 | * 1 = error. |
| 2554 | * 2 = database was full and device was not configured. |
| 2555 | */ |
| 2556 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2557 | qla2x00_configure_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2558 | { |
| 2559 | int rval; |
| 2560 | unsigned long flags, save_flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2561 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | rval = QLA_SUCCESS; |
| 2563 | |
| 2564 | /* Get Initiator ID */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2565 | if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) { |
| 2566 | rval = qla2x00_configure_hba(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | if (rval != QLA_SUCCESS) { |
| 2568 | DEBUG(printk("scsi(%ld): Unable to configure HBA.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2569 | vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | return (rval); |
| 2571 | } |
| 2572 | } |
| 2573 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2574 | save_flags = flags = vha->dpc_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2575 | DEBUG(printk("scsi(%ld): Configure loop -- dpc flags =0x%lx\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2576 | vha->host_no, flags)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | |
| 2578 | /* |
| 2579 | * If we have both an RSCN and PORT UPDATE pending then handle them |
| 2580 | * both at the same time. |
| 2581 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2582 | clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 2583 | clear_bit(RSCN_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2584 | |
Michael Hernandez | 3064ff3 | 2009-12-15 21:29:44 -0800 | [diff] [blame] | 2585 | qla2x00_get_data_rate(vha); |
| 2586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2587 | /* Determine what we need to do */ |
| 2588 | if (ha->current_topology == ISP_CFG_FL && |
| 2589 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2590 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2591 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | set_bit(RSCN_UPDATE, &flags); |
| 2593 | |
| 2594 | } else if (ha->current_topology == ISP_CFG_F && |
| 2595 | (test_bit(LOCAL_LOOP_UPDATE, &flags))) { |
| 2596 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2597 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | set_bit(RSCN_UPDATE, &flags); |
| 2599 | clear_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2600 | |
Andrew Vasquez | 21333b4 | 2006-05-17 15:09:56 -0700 | [diff] [blame] | 2601 | } else if (ha->current_topology == ISP_CFG_N) { |
| 2602 | clear_bit(RSCN_UPDATE, &flags); |
| 2603 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2604 | } else if (!vha->flags.online || |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2605 | (test_bit(ABORT_ISP_ACTIVE, &flags))) { |
| 2606 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2607 | vha->flags.rscn_queue_overflow = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2608 | set_bit(RSCN_UPDATE, &flags); |
| 2609 | set_bit(LOCAL_LOOP_UPDATE, &flags); |
| 2610 | } |
| 2611 | |
| 2612 | if (test_bit(LOCAL_LOOP_UPDATE, &flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2613 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2614 | rval = QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2615 | else |
| 2616 | rval = qla2x00_configure_local_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | } |
| 2618 | |
| 2619 | if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2620 | if (LOOP_TRANSITION(vha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2621 | rval = QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2622 | else |
| 2623 | rval = qla2x00_configure_fabric(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
| 2626 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2627 | if (atomic_read(&vha->loop_down_timer) || |
| 2628 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | rval = QLA_FUNCTION_FAILED; |
| 2630 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2631 | atomic_set(&vha->loop_state, LOOP_READY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2632 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2633 | DEBUG(printk("scsi(%ld): LOOP READY\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2634 | } |
| 2635 | } |
| 2636 | |
| 2637 | if (rval) { |
| 2638 | DEBUG2_3(printk("%s(%ld): *** FAILED ***\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2639 | __func__, vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2640 | } else { |
| 2641 | DEBUG3(printk("%s: exiting normally\n", __func__)); |
| 2642 | } |
| 2643 | |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 2644 | /* Restore state if a resync event occurred during processing */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2645 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | if (test_bit(LOCAL_LOOP_UPDATE, &save_flags)) |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2647 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2648 | if (test_bit(RSCN_UPDATE, &save_flags)) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2649 | set_bit(RSCN_UPDATE, &vha->dpc_flags); |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 2650 | if (!IS_ALOGIO_CAPABLE(ha)) |
| 2651 | vha->flags.rscn_queue_overflow = 1; |
Andrew Vasquez | f4658b6 | 2009-06-03 09:55:21 -0700 | [diff] [blame] | 2652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | } |
| 2654 | |
| 2655 | return (rval); |
| 2656 | } |
| 2657 | |
| 2658 | |
| 2659 | |
| 2660 | /* |
| 2661 | * qla2x00_configure_local_loop |
| 2662 | * Updates Fibre Channel Device Database with local loop devices. |
| 2663 | * |
| 2664 | * Input: |
| 2665 | * ha = adapter block pointer. |
| 2666 | * |
| 2667 | * Returns: |
| 2668 | * 0 = success. |
| 2669 | */ |
| 2670 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2671 | qla2x00_configure_local_loop(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2672 | { |
| 2673 | int rval, rval2; |
| 2674 | int found_devs; |
| 2675 | int found; |
| 2676 | fc_port_t *fcport, *new_fcport; |
| 2677 | |
| 2678 | uint16_t index; |
| 2679 | uint16_t entries; |
| 2680 | char *id_iter; |
| 2681 | uint16_t loop_id; |
| 2682 | uint8_t domain, area, al_pa; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2683 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | |
| 2685 | found_devs = 0; |
| 2686 | new_fcport = NULL; |
| 2687 | entries = MAX_FIBRE_DEVICES; |
| 2688 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2689 | DEBUG3(printk("scsi(%ld): Getting FCAL position map\n", vha->host_no)); |
| 2690 | DEBUG3(qla2x00_get_fcal_position_map(vha, NULL)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | |
| 2692 | /* Get list of logged in devices. */ |
| 2693 | memset(ha->gid_list, 0, GID_LIST_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2694 | 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] | 2695 | &entries); |
| 2696 | if (rval != QLA_SUCCESS) |
| 2697 | goto cleanup_allocation; |
| 2698 | |
| 2699 | DEBUG3(printk("scsi(%ld): Entries in ID list (%d)\n", |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 2700 | vha->host_no, entries)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | DEBUG3(qla2x00_dump_buffer((uint8_t *)ha->gid_list, |
| 2702 | entries * sizeof(struct gid_list_info))); |
| 2703 | |
| 2704 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2705 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2706 | if (new_fcport == NULL) { |
| 2707 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2708 | goto cleanup_allocation; |
| 2709 | } |
| 2710 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2711 | |
| 2712 | /* |
| 2713 | * Mark local devices that were present with FCF_DEVICE_LOST for now. |
| 2714 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2715 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | if (atomic_read(&fcport->state) == FCS_ONLINE && |
| 2717 | fcport->port_type != FCT_BROADCAST && |
| 2718 | (fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 2719 | |
| 2720 | DEBUG(printk("scsi(%ld): Marking port lost, " |
| 2721 | "loop_id=0x%04x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2722 | vha->host_no, fcport->loop_id)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2723 | |
| 2724 | atomic_set(&fcport->state, FCS_DEVICE_LOST); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2725 | } |
| 2726 | } |
| 2727 | |
| 2728 | /* Add devices to port list. */ |
| 2729 | id_iter = (char *)ha->gid_list; |
| 2730 | for (index = 0; index < entries; index++) { |
| 2731 | domain = ((struct gid_list_info *)id_iter)->domain; |
| 2732 | area = ((struct gid_list_info *)id_iter)->area; |
| 2733 | al_pa = ((struct gid_list_info *)id_iter)->al_pa; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2734 | if (IS_QLA2100(ha) || IS_QLA2200(ha)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | loop_id = (uint16_t) |
| 2736 | ((struct gid_list_info *)id_iter)->loop_id_2100; |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2737 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | loop_id = le16_to_cpu( |
| 2739 | ((struct gid_list_info *)id_iter)->loop_id); |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2740 | id_iter += ha->gid_list_info_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | |
| 2742 | /* Bypass reserved domain fields. */ |
| 2743 | if ((domain & 0xf0) == 0xf0) |
| 2744 | continue; |
| 2745 | |
| 2746 | /* Bypass if not same domain and area of adapter. */ |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 2747 | if (area && domain && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2748 | (area != vha->d_id.b.area || domain != vha->d_id.b.domain)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2749 | continue; |
| 2750 | |
| 2751 | /* Bypass invalid local loop ID. */ |
| 2752 | if (loop_id > LAST_LOCAL_LOOP_ID) |
| 2753 | continue; |
| 2754 | |
| 2755 | /* Fill in member data. */ |
| 2756 | new_fcport->d_id.b.domain = domain; |
| 2757 | new_fcport->d_id.b.area = area; |
| 2758 | new_fcport->d_id.b.al_pa = al_pa; |
| 2759 | new_fcport->loop_id = loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2760 | new_fcport->vp_idx = vha->vp_idx; |
| 2761 | rval2 = qla2x00_get_port_database(vha, new_fcport, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | if (rval2 != QLA_SUCCESS) { |
| 2763 | DEBUG2(printk("scsi(%ld): Failed to retrieve fcport " |
| 2764 | "information -- get_port_database=%x, " |
| 2765 | "loop_id=0x%04x\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2766 | vha->host_no, rval2, new_fcport->loop_id)); |
andrew.vasquez@qlogic.com | c9d02ac | 2006-01-13 17:05:26 -0800 | [diff] [blame] | 2767 | DEBUG2(printk("scsi(%ld): Scheduling resync...\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2768 | vha->host_no)); |
| 2769 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2770 | continue; |
| 2771 | } |
| 2772 | |
| 2773 | /* Check for matching device in port list. */ |
| 2774 | found = 0; |
| 2775 | fcport = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2776 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2777 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 2778 | WWN_SIZE)) |
| 2779 | continue; |
| 2780 | |
Shyam Sundar | ddb9b12 | 2009-03-24 09:08:10 -0700 | [diff] [blame] | 2781 | fcport->flags &= ~FCF_FABRIC_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2782 | fcport->loop_id = new_fcport->loop_id; |
| 2783 | fcport->port_type = new_fcport->port_type; |
| 2784 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 2785 | memcpy(fcport->node_name, new_fcport->node_name, |
| 2786 | WWN_SIZE); |
| 2787 | |
| 2788 | found++; |
| 2789 | break; |
| 2790 | } |
| 2791 | |
| 2792 | if (!found) { |
| 2793 | /* New device, add to fcports list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2794 | if (vha->vp_idx) { |
| 2795 | new_fcport->vha = vha; |
| 2796 | new_fcport->vp_idx = vha->vp_idx; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 2797 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2798 | list_add_tail(&new_fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | |
| 2800 | /* Allocate a new replacement fcport. */ |
| 2801 | fcport = new_fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2802 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2803 | if (new_fcport == NULL) { |
| 2804 | rval = QLA_MEMORY_ALLOC_FAILED; |
| 2805 | goto cleanup_allocation; |
| 2806 | } |
| 2807 | new_fcport->flags &= ~FCF_FABRIC_DEVICE; |
| 2808 | } |
| 2809 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2810 | /* Base iIDMA settings on HBA port speed. */ |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2811 | fcport->fp_speed = ha->link_data_rate; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2812 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2813 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | |
| 2815 | found_devs++; |
| 2816 | } |
| 2817 | |
| 2818 | cleanup_allocation: |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 2819 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2820 | |
| 2821 | if (rval != QLA_SUCCESS) { |
| 2822 | DEBUG2(printk("scsi(%ld): Configure local loop error exit: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2823 | "rval=%x\n", vha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2824 | } |
| 2825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2826 | return (rval); |
| 2827 | } |
| 2828 | |
| 2829 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2830 | qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2831 | { |
| 2832 | #define LS_UNKNOWN 2 |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2833 | static char *link_speeds[] = { "1", "2", "?", "4", "8", "10" }; |
| 2834 | char *link_speed; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2835 | int rval; |
Harish Zunjarrao | 1bb3954 | 2009-06-17 10:30:29 -0700 | [diff] [blame] | 2836 | uint16_t mb[4]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2837 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2838 | |
Andrew Vasquez | c76f2c0 | 2007-07-19 15:05:57 -0700 | [diff] [blame] | 2839 | if (!IS_IIDMA_CAPABLE(ha)) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2840 | return; |
| 2841 | |
Giridhar Malavali | c9afb9a | 2010-09-03 15:20:48 -0700 | [diff] [blame] | 2842 | if (atomic_read(&fcport->state) != FCS_ONLINE) |
| 2843 | return; |
| 2844 | |
Andrew Vasquez | 39bd962 | 2007-09-20 14:07:34 -0700 | [diff] [blame] | 2845 | if (fcport->fp_speed == PORT_SPEED_UNKNOWN || |
| 2846 | fcport->fp_speed > ha->link_data_rate) |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2847 | return; |
| 2848 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2849 | rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2850 | mb); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2851 | if (rval != QLA_SUCCESS) { |
| 2852 | DEBUG2(printk("scsi(%ld): Unable to adjust iIDMA " |
| 2853 | "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x %04x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2854 | vha->host_no, fcport->port_name[0], fcport->port_name[1], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2855 | fcport->port_name[2], fcport->port_name[3], |
| 2856 | fcport->port_name[4], fcport->port_name[5], |
| 2857 | fcport->port_name[6], fcport->port_name[7], rval, |
Andrew Vasquez | a3cbdfa | 2007-08-13 10:13:18 -0700 | [diff] [blame] | 2858 | fcport->fp_speed, mb[0], mb[1])); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2859 | } else { |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2860 | link_speed = link_speeds[LS_UNKNOWN]; |
| 2861 | if (fcport->fp_speed < 5) |
| 2862 | link_speed = link_speeds[fcport->fp_speed]; |
| 2863 | else if (fcport->fp_speed == 0x13) |
| 2864 | link_speed = link_speeds[5]; |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2865 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 2866 | "iIDMA adjusted to %s GB/s on " |
| 2867 | "%02x%02x%02x%02x%02x%02x%02x%02x.\n", |
Andrew Vasquez | 9f8fdde | 2009-06-03 09:55:22 -0700 | [diff] [blame] | 2868 | link_speed, fcport->port_name[0], |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 2869 | fcport->port_name[1], fcport->port_name[2], |
| 2870 | fcport->port_name[3], fcport->port_name[4], |
| 2871 | fcport->port_name[5], fcport->port_name[6], |
| 2872 | fcport->port_name[7])); |
| 2873 | } |
| 2874 | } |
| 2875 | |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2876 | static void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2877 | qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2878 | { |
| 2879 | struct fc_rport_identifiers rport_ids; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 2880 | struct fc_rport *rport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2881 | struct qla_hw_data *ha = vha->hw; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2882 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2883 | qla2x00_rport_del(fcport); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2884 | |
Andrew Vasquez | f8b02a8 | 2005-08-31 15:21:20 -0700 | [diff] [blame] | 2885 | rport_ids.node_name = wwn_to_u64(fcport->node_name); |
| 2886 | rport_ids.port_name = wwn_to_u64(fcport->port_name); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2887 | rport_ids.port_id = fcport->d_id.b.domain << 16 | |
| 2888 | fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa; |
| 2889 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2890 | fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids); |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2891 | if (!rport) { |
| 2892 | qla_printk(KERN_WARNING, ha, |
| 2893 | "Unable to allocate fc remote port!\n"); |
| 2894 | return; |
| 2895 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2896 | spin_lock_irq(fcport->vha->host->host_lock); |
James.Smart@Emulex.Com | 19a7b4a | 2005-10-18 12:03:35 -0400 | [diff] [blame] | 2897 | *((fc_port_t **)rport->dd_data) = fcport; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2898 | spin_unlock_irq(fcport->vha->host->host_lock); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 2899 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 2900 | rport->supported_classes = fcport->supported_classes; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2901 | |
| 2902 | rport_ids.roles = FC_RPORT_ROLE_UNKNOWN; |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2903 | if (fcport->port_type == FCT_INITIATOR) |
| 2904 | rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR; |
| 2905 | if (fcport->port_type == FCT_TARGET) |
| 2906 | rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET; |
Andrew Vasquez | 77d7414 | 2005-07-08 18:00:36 -0700 | [diff] [blame] | 2907 | fc_remote_port_rolechg(rport, rport_ids.roles); |
| 8482e118 | 2005-04-17 15:04:54 -0500 | [diff] [blame] | 2908 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2909 | |
| 2910 | /* |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2911 | * qla2x00_update_fcport |
| 2912 | * Updates device on list. |
| 2913 | * |
| 2914 | * Input: |
| 2915 | * ha = adapter block pointer. |
| 2916 | * fcport = port structure pointer. |
| 2917 | * |
| 2918 | * Return: |
| 2919 | * 0 - Success |
| 2920 | * BIT_0 - error |
| 2921 | * |
| 2922 | * Context: |
| 2923 | * Kernel context. |
| 2924 | */ |
| 2925 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2926 | qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport) |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2927 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2928 | fcport->vha = vha; |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2929 | fcport->login_retry = 0; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2930 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2931 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2932 | qla2x00_iidma_fcport(vha, fcport); |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 2933 | qla24xx_update_fcport_fcp_prio(vha, fcport); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2934 | qla2x00_reg_remote_port(vha, fcport); |
Giridhar Malavali | 38170fa | 2010-10-15 11:27:49 -0700 | [diff] [blame] | 2935 | atomic_set(&fcport->state, FCS_ONLINE); |
Adrian Bunk | 23be331 | 2006-11-24 02:46:01 +0100 | [diff] [blame] | 2936 | } |
| 2937 | |
| 2938 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2939 | * qla2x00_configure_fabric |
| 2940 | * Setup SNS devices with loop ID's. |
| 2941 | * |
| 2942 | * Input: |
| 2943 | * ha = adapter block pointer. |
| 2944 | * |
| 2945 | * Returns: |
| 2946 | * 0 = success. |
| 2947 | * BIT_0 = error |
| 2948 | */ |
| 2949 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2950 | qla2x00_configure_fabric(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2951 | { |
| 2952 | int rval, rval2; |
| 2953 | fc_port_t *fcport, *fcptemp; |
| 2954 | uint16_t next_loopid; |
| 2955 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2956 | uint16_t loop_id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | LIST_HEAD(new_fcports); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2958 | struct qla_hw_data *ha = vha->hw; |
| 2959 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2960 | |
| 2961 | /* If FL port exists, then SNS is present */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2962 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2963 | loop_id = NPH_F_PORT; |
| 2964 | else |
| 2965 | loop_id = SNS_FL_PORT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2966 | 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] | 2967 | if (rval != QLA_SUCCESS) { |
| 2968 | DEBUG2(printk("scsi(%ld): MBC_GET_PORT_NAME Failed, No FL " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2969 | "Port\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2970 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2971 | vha->device_flags &= ~SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2972 | return (QLA_SUCCESS); |
| 2973 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2974 | vha->device_flags |= SWITCH_FOUND; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2975 | |
| 2976 | /* Mark devices that need re-synchronization. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2977 | rval2 = qla2x00_device_resync(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2978 | if (rval2 == QLA_RSCNS_HANDLED) { |
| 2979 | /* No point doing the scan, just continue. */ |
| 2980 | return (QLA_SUCCESS); |
| 2981 | } |
| 2982 | do { |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2983 | /* FDMI support. */ |
| 2984 | if (ql2xfdmienable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2985 | test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags)) |
| 2986 | qla2x00_fdmi_register(vha); |
Andrew Vasquez | cca5335 | 2005-08-26 19:08:30 -0700 | [diff] [blame] | 2987 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | /* Ensure we are logged into the SNS. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 2989 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2990 | loop_id = NPH_SNS; |
| 2991 | else |
| 2992 | loop_id = SIMPLE_NAME_SERVER; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 2993 | ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff, |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 2994 | 0xfc, mb, BIT_1 | BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2995 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 2996 | DEBUG2(qla_printk(KERN_INFO, ha, |
| 2997 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 2998 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 3000 | return (QLA_SUCCESS); |
| 3001 | } |
| 3002 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3003 | if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) { |
| 3004 | if (qla2x00_rft_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3005 | /* EMPTY */ |
| 3006 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3007 | "TYPE failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3009 | if (qla2x00_rff_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3010 | /* EMPTY */ |
| 3011 | DEBUG2(printk("scsi(%ld): Register FC-4 " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3012 | "Features failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3014 | if (qla2x00_rnn_id(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3015 | /* EMPTY */ |
| 3016 | DEBUG2(printk("scsi(%ld): Register Node Name " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3017 | "failed.\n", vha->host_no)); |
| 3018 | } else if (qla2x00_rsnn_nn(vha)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | /* EMPTY */ |
| 3020 | DEBUG2(printk("scsi(%ld): Register Symbolic " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3021 | "Node Name failed.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | } |
| 3023 | } |
| 3024 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3025 | rval = qla2x00_find_all_fabric_devs(vha, &new_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3026 | if (rval != QLA_SUCCESS) |
| 3027 | break; |
| 3028 | |
| 3029 | /* |
| 3030 | * Logout all previous fabric devices marked lost, except |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3031 | * FCP2 devices. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3032 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3033 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3034 | if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | break; |
| 3036 | |
| 3037 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) |
| 3038 | continue; |
| 3039 | |
| 3040 | if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3041 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3042 | ql2xplogiabsentdevice, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3043 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3044 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3045 | fcport->port_type != FCT_INITIATOR && |
| 3046 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3047 | ha->isp_ops->fabric_logout(vha, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3048 | fcport->loop_id, |
| 3049 | fcport->d_id.b.domain, |
| 3050 | fcport->d_id.b.area, |
| 3051 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3052 | fcport->loop_id = FC_NO_LOOP_ID; |
| 3053 | } |
| 3054 | } |
| 3055 | } |
| 3056 | |
| 3057 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3058 | next_loopid = ha->min_external_loopid; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3059 | |
| 3060 | /* |
| 3061 | * Scan through our port list and login entries that need to be |
| 3062 | * logged in. |
| 3063 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3064 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
| 3065 | if (atomic_read(&vha->loop_down_timer) || |
| 3066 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3067 | break; |
| 3068 | |
| 3069 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 3070 | (fcport->flags & FCF_LOGIN_NEEDED) == 0) |
| 3071 | continue; |
| 3072 | |
| 3073 | if (fcport->loop_id == FC_NO_LOOP_ID) { |
| 3074 | fcport->loop_id = next_loopid; |
Seokmann Ju | d4486fd6 | 2008-04-03 13:13:28 -0700 | [diff] [blame] | 3075 | rval = qla2x00_find_new_loop_id( |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3076 | base_vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3077 | if (rval != QLA_SUCCESS) { |
| 3078 | /* Ran out of IDs to use */ |
| 3079 | break; |
| 3080 | } |
| 3081 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3082 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3083 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | /* Exit if out of loop IDs. */ |
| 3087 | if (rval != QLA_SUCCESS) { |
| 3088 | break; |
| 3089 | } |
| 3090 | |
| 3091 | /* |
| 3092 | * Login and add the new devices to our port list. |
| 3093 | */ |
| 3094 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3095 | if (atomic_read(&vha->loop_down_timer) || |
| 3096 | test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3097 | break; |
| 3098 | |
| 3099 | /* Find a new loop ID to use. */ |
| 3100 | fcport->loop_id = next_loopid; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3101 | rval = qla2x00_find_new_loop_id(base_vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3102 | if (rval != QLA_SUCCESS) { |
| 3103 | /* Ran out of IDs to use */ |
| 3104 | break; |
| 3105 | } |
| 3106 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 3107 | /* Login and update database */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3108 | qla2x00_fabric_dev_login(vha, fcport, &next_loopid); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3109 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3110 | if (vha->vp_idx) { |
| 3111 | fcport->vha = vha; |
| 3112 | fcport->vp_idx = vha->vp_idx; |
| 3113 | } |
| 3114 | list_move_tail(&fcport->list, &vha->vp_fcports); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3115 | } |
| 3116 | } while (0); |
| 3117 | |
| 3118 | /* Free all new device structures not processed. */ |
| 3119 | list_for_each_entry_safe(fcport, fcptemp, &new_fcports, list) { |
| 3120 | list_del(&fcport->list); |
| 3121 | kfree(fcport); |
| 3122 | } |
| 3123 | |
| 3124 | if (rval) { |
| 3125 | DEBUG2(printk("scsi(%ld): Configure fabric error exit: " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3126 | "rval=%d\n", vha->host_no, rval)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3127 | } |
| 3128 | |
| 3129 | return (rval); |
| 3130 | } |
| 3131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3132 | /* |
| 3133 | * qla2x00_find_all_fabric_devs |
| 3134 | * |
| 3135 | * Input: |
| 3136 | * ha = adapter block pointer. |
| 3137 | * dev = database device entry pointer. |
| 3138 | * |
| 3139 | * Returns: |
| 3140 | * 0 = success. |
| 3141 | * |
| 3142 | * Context: |
| 3143 | * Kernel context. |
| 3144 | */ |
| 3145 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3146 | qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha, |
| 3147 | struct list_head *new_fcports) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | { |
| 3149 | int rval; |
| 3150 | uint16_t loop_id; |
| 3151 | fc_port_t *fcport, *new_fcport, *fcptemp; |
| 3152 | int found; |
| 3153 | |
| 3154 | sw_info_t *swl; |
| 3155 | int swl_idx; |
| 3156 | int first_dev, last_dev; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3157 | port_id_t wrap = {}, nxt_d_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3158 | struct qla_hw_data *ha = vha->hw; |
| 3159 | struct scsi_qla_host *vp, *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3160 | struct scsi_qla_host *tvp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3161 | |
| 3162 | rval = QLA_SUCCESS; |
| 3163 | |
| 3164 | /* Try GID_PT to get device list, else GAN. */ |
Andrew Vasquez | 4b89258 | 2008-09-11 21:22:48 -0700 | [diff] [blame] | 3165 | swl = kcalloc(MAX_FIBRE_DEVICES, sizeof(sw_info_t), GFP_KERNEL); |
Mariusz Kozlowski | bbfbbbc | 2007-08-11 10:13:24 +0200 | [diff] [blame] | 3166 | if (!swl) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3167 | /*EMPTY*/ |
| 3168 | DEBUG2(printk("scsi(%ld): GID_PT allocations failed, fallback " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3169 | "on GA_NXT\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3170 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3171 | if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3172 | kfree(swl); |
| 3173 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3174 | } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3175 | kfree(swl); |
| 3176 | swl = NULL; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3177 | } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3178 | kfree(swl); |
| 3179 | swl = NULL; |
Andrew Vasquez | e5896bd | 2008-07-10 16:55:52 -0700 | [diff] [blame] | 3180 | } else if (ql2xiidmaenable && |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3181 | qla2x00_gfpn_id(vha, swl) == QLA_SUCCESS) { |
| 3182 | qla2x00_gpsc(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3183 | } |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3184 | |
| 3185 | /* If other queries succeeded probe for FC-4 type */ |
| 3186 | if (swl) |
| 3187 | qla2x00_gff_id(vha, swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3188 | } |
| 3189 | swl_idx = 0; |
| 3190 | |
| 3191 | /* Allocate temporary fcport for any new fcports discovered. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3192 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3193 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3194 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3195 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3196 | } |
| 3197 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3198 | /* Set start port ID scan at adapter ID. */ |
| 3199 | first_dev = 1; |
| 3200 | last_dev = 0; |
| 3201 | |
| 3202 | /* Starting free loop ID. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3203 | loop_id = ha->min_external_loopid; |
| 3204 | for (; loop_id <= ha->max_loop_id; loop_id++) { |
| 3205 | if (qla2x00_is_reserved_id(vha, loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3206 | continue; |
| 3207 | |
Giridhar Malavali | 3a6478d | 2010-05-28 15:08:20 -0700 | [diff] [blame] | 3208 | if (ha->current_topology == ISP_CFG_FL && |
| 3209 | (atomic_read(&vha->loop_down_timer) || |
| 3210 | LOOP_TRANSITION(vha))) { |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3211 | atomic_set(&vha->loop_down_timer, 0); |
| 3212 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 3213 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3214 | break; |
Andrew Vasquez | bb2d52b | 2010-02-18 10:07:27 -0800 | [diff] [blame] | 3215 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3216 | |
| 3217 | if (swl != NULL) { |
| 3218 | if (last_dev) { |
| 3219 | wrap.b24 = new_fcport->d_id.b24; |
| 3220 | } else { |
| 3221 | new_fcport->d_id.b24 = swl[swl_idx].d_id.b24; |
| 3222 | memcpy(new_fcport->node_name, |
| 3223 | swl[swl_idx].node_name, WWN_SIZE); |
| 3224 | memcpy(new_fcport->port_name, |
| 3225 | swl[swl_idx].port_name, WWN_SIZE); |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3226 | memcpy(new_fcport->fabric_port_name, |
| 3227 | swl[swl_idx].fabric_port_name, WWN_SIZE); |
| 3228 | new_fcport->fp_speed = swl[swl_idx].fp_speed; |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3229 | new_fcport->fc4_type = swl[swl_idx].fc4_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3230 | |
| 3231 | if (swl[swl_idx].d_id.b.rsvd_1 != 0) { |
| 3232 | last_dev = 1; |
| 3233 | } |
| 3234 | swl_idx++; |
| 3235 | } |
| 3236 | } else { |
| 3237 | /* Send GA_NXT to the switch */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3238 | rval = qla2x00_ga_nxt(vha, new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | if (rval != QLA_SUCCESS) { |
| 3240 | qla_printk(KERN_WARNING, ha, |
| 3241 | "SNS scan failed -- assuming zero-entry " |
| 3242 | "result...\n"); |
| 3243 | list_for_each_entry_safe(fcport, fcptemp, |
| 3244 | new_fcports, list) { |
| 3245 | list_del(&fcport->list); |
| 3246 | kfree(fcport); |
| 3247 | } |
| 3248 | rval = QLA_SUCCESS; |
| 3249 | break; |
| 3250 | } |
| 3251 | } |
| 3252 | |
| 3253 | /* If wrap on switch device list, exit. */ |
| 3254 | if (first_dev) { |
| 3255 | wrap.b24 = new_fcport->d_id.b24; |
| 3256 | first_dev = 0; |
| 3257 | } else if (new_fcport->d_id.b24 == wrap.b24) { |
| 3258 | DEBUG2(printk("scsi(%ld): device wrap (%02x%02x%02x)\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3259 | vha->host_no, new_fcport->d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3260 | new_fcport->d_id.b.area, new_fcport->d_id.b.al_pa)); |
| 3261 | break; |
| 3262 | } |
| 3263 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3264 | /* Bypass if same physical adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3265 | if (new_fcport->d_id.b24 == base_vha->d_id.b24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3266 | continue; |
| 3267 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3268 | /* Bypass virtual ports of the same host. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3269 | found = 0; |
| 3270 | if (ha->num_vhosts) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3271 | unsigned long flags; |
| 3272 | |
| 3273 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3274 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3275 | if (new_fcport->d_id.b24 == vp->d_id.b24) { |
| 3276 | found = 1; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3277 | break; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3278 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3279 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3280 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3281 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3282 | if (found) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 3283 | continue; |
| 3284 | } |
| 3285 | |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3286 | /* Bypass if same domain and area of adapter. */ |
| 3287 | if (((new_fcport->d_id.b24 & 0xffff00) == |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3288 | (vha->d_id.b24 & 0xffff00)) && ha->current_topology == |
Andrew Vasquez | f7d289f | 2005-08-26 19:08:40 -0700 | [diff] [blame] | 3289 | ISP_CFG_FL) |
| 3290 | continue; |
| 3291 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | /* Bypass reserved domain fields. */ |
| 3293 | if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0) |
| 3294 | continue; |
| 3295 | |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3296 | /* Bypass ports whose FCP-4 type is not FCP_SCSI */ |
Chad Dupuis | 4da26e1 | 2010-10-15 11:27:40 -0700 | [diff] [blame] | 3297 | if (ql2xgffidenable && |
| 3298 | (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI && |
| 3299 | new_fcport->fc4_type != FC4_TYPE_UNKNOWN)) |
Chad Dupuis | e8c72ba | 2010-07-23 15:28:25 +0500 | [diff] [blame] | 3300 | continue; |
| 3301 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | /* Locate matching device in database. */ |
| 3303 | found = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3304 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | if (memcmp(new_fcport->port_name, fcport->port_name, |
| 3306 | WWN_SIZE)) |
| 3307 | continue; |
| 3308 | |
| 3309 | found++; |
| 3310 | |
Andrew Vasquez | d8b4521 | 2006-10-02 12:00:43 -0700 | [diff] [blame] | 3311 | /* Update port state. */ |
| 3312 | memcpy(fcport->fabric_port_name, |
| 3313 | new_fcport->fabric_port_name, WWN_SIZE); |
| 3314 | fcport->fp_speed = new_fcport->fp_speed; |
| 3315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | /* |
| 3317 | * If address the same and state FCS_ONLINE, nothing |
| 3318 | * changed. |
| 3319 | */ |
| 3320 | if (fcport->d_id.b24 == new_fcport->d_id.b24 && |
| 3321 | atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3322 | break; |
| 3323 | } |
| 3324 | |
| 3325 | /* |
| 3326 | * If device was not a fabric device before. |
| 3327 | */ |
| 3328 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) { |
| 3329 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3330 | fcport->loop_id = FC_NO_LOOP_ID; |
| 3331 | fcport->flags |= (FCF_FABRIC_DEVICE | |
| 3332 | FCF_LOGIN_NEEDED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3333 | break; |
| 3334 | } |
| 3335 | |
| 3336 | /* |
| 3337 | * Port ID changed or device was marked to be updated; |
| 3338 | * Log it out if still logged in and mark it for |
| 3339 | * relogin later. |
| 3340 | */ |
| 3341 | fcport->d_id.b24 = new_fcport->d_id.b24; |
| 3342 | fcport->flags |= FCF_LOGIN_NEEDED; |
| 3343 | if (fcport->loop_id != FC_NO_LOOP_ID && |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3344 | (fcport->flags & FCF_FCP2_DEVICE) == 0 && |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3345 | fcport->port_type != FCT_INITIATOR && |
| 3346 | fcport->port_type != FCT_BROADCAST) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3347 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3348 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3349 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3350 | fcport->loop_id = FC_NO_LOOP_ID; |
| 3351 | } |
| 3352 | |
| 3353 | break; |
| 3354 | } |
| 3355 | |
| 3356 | if (found) |
| 3357 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3358 | /* If device was not in our fcports list, then add it. */ |
| 3359 | list_add_tail(&new_fcport->list, new_fcports); |
| 3360 | |
| 3361 | /* Allocate a new replacement fcport. */ |
| 3362 | nxt_d_id.b24 = new_fcport->d_id.b24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3363 | new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3364 | if (new_fcport == NULL) { |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3365 | kfree(swl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3366 | return (QLA_MEMORY_ALLOC_FAILED); |
| 3367 | } |
| 3368 | new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED); |
| 3369 | new_fcport->d_id.b24 = nxt_d_id.b24; |
| 3370 | } |
| 3371 | |
Jesper Juhl | c9475cb | 2005-11-07 01:01:26 -0800 | [diff] [blame] | 3372 | kfree(swl); |
| 3373 | kfree(new_fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3374 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3375 | return (rval); |
| 3376 | } |
| 3377 | |
| 3378 | /* |
| 3379 | * qla2x00_find_new_loop_id |
| 3380 | * Scan through our port list and find a new usable loop ID. |
| 3381 | * |
| 3382 | * Input: |
| 3383 | * ha: adapter state pointer. |
| 3384 | * dev: port structure pointer. |
| 3385 | * |
| 3386 | * Returns: |
| 3387 | * qla2x00 local function return status code. |
| 3388 | * |
| 3389 | * Context: |
| 3390 | * Kernel context. |
| 3391 | */ |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 3392 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3393 | 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] | 3394 | { |
| 3395 | int rval; |
| 3396 | int found; |
| 3397 | fc_port_t *fcport; |
| 3398 | uint16_t first_loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3399 | struct qla_hw_data *ha = vha->hw; |
| 3400 | struct scsi_qla_host *vp; |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3401 | struct scsi_qla_host *tvp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3402 | unsigned long flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3403 | |
| 3404 | rval = QLA_SUCCESS; |
| 3405 | |
| 3406 | /* Save starting loop ID. */ |
| 3407 | first_loop_id = dev->loop_id; |
| 3408 | |
| 3409 | for (;;) { |
| 3410 | /* Skip loop ID if already used by adapter. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3411 | if (dev->loop_id == vha->loop_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3412 | dev->loop_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | |
| 3414 | /* Skip reserved loop IDs. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3415 | while (qla2x00_is_reserved_id(vha, dev->loop_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | dev->loop_id++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | |
| 3418 | /* Reset loop ID if passed the end. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3419 | if (dev->loop_id > ha->max_loop_id) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | /* first loop ID. */ |
| 3421 | dev->loop_id = ha->min_external_loopid; |
| 3422 | } |
| 3423 | |
| 3424 | /* Check for loop ID being already in use. */ |
| 3425 | found = 0; |
| 3426 | fcport = NULL; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3427 | |
| 3428 | spin_lock_irqsave(&ha->vport_slock, flags); |
Anirban Chakraborty | ee546b6 | 2009-03-05 11:07:02 -0800 | [diff] [blame] | 3429 | list_for_each_entry_safe(vp, tvp, &ha->vp_list, list) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3430 | list_for_each_entry(fcport, &vp->vp_fcports, list) { |
| 3431 | if (fcport->loop_id == dev->loop_id && |
| 3432 | fcport != dev) { |
| 3433 | /* ID possibly in use */ |
| 3434 | found++; |
| 3435 | break; |
| 3436 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3438 | if (found) |
| 3439 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3440 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3441 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | |
| 3443 | /* If not in use then it is free to use. */ |
| 3444 | if (!found) { |
| 3445 | break; |
| 3446 | } |
| 3447 | |
| 3448 | /* ID in use. Try next value. */ |
| 3449 | dev->loop_id++; |
| 3450 | |
| 3451 | /* If wrap around. No free ID to use. */ |
| 3452 | if (dev->loop_id == first_loop_id) { |
| 3453 | dev->loop_id = FC_NO_LOOP_ID; |
| 3454 | rval = QLA_FUNCTION_FAILED; |
| 3455 | break; |
| 3456 | } |
| 3457 | } |
| 3458 | |
| 3459 | return (rval); |
| 3460 | } |
| 3461 | |
| 3462 | /* |
| 3463 | * qla2x00_device_resync |
| 3464 | * Marks devices in the database that needs resynchronization. |
| 3465 | * |
| 3466 | * Input: |
| 3467 | * ha = adapter block pointer. |
| 3468 | * |
| 3469 | * Context: |
| 3470 | * Kernel context. |
| 3471 | */ |
| 3472 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3473 | qla2x00_device_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | { |
| 3475 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3476 | uint32_t mask; |
| 3477 | fc_port_t *fcport; |
| 3478 | uint32_t rscn_entry; |
| 3479 | uint8_t rscn_out_iter; |
| 3480 | uint8_t format; |
Mike Waychison | 1516ef4 | 2010-05-04 15:01:31 -0700 | [diff] [blame] | 3481 | port_id_t d_id = {}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3482 | |
| 3483 | rval = QLA_RSCNS_HANDLED; |
| 3484 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3485 | while (vha->rscn_out_ptr != vha->rscn_in_ptr || |
| 3486 | vha->flags.rscn_queue_overflow) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3487 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3488 | rscn_entry = vha->rscn_queue[vha->rscn_out_ptr]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | format = MSB(MSW(rscn_entry)); |
| 3490 | d_id.b.domain = LSB(MSW(rscn_entry)); |
| 3491 | d_id.b.area = MSB(LSW(rscn_entry)); |
| 3492 | d_id.b.al_pa = LSB(LSW(rscn_entry)); |
| 3493 | |
| 3494 | DEBUG(printk("scsi(%ld): RSCN queue entry[%d] = " |
| 3495 | "[%02x/%02x%02x%02x].\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3496 | vha->host_no, vha->rscn_out_ptr, format, d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3497 | d_id.b.area, d_id.b.al_pa)); |
| 3498 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3499 | vha->rscn_out_ptr++; |
| 3500 | if (vha->rscn_out_ptr == MAX_RSCN_COUNT) |
| 3501 | vha->rscn_out_ptr = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3502 | |
| 3503 | /* Skip duplicate entries. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3504 | for (rscn_out_iter = vha->rscn_out_ptr; |
| 3505 | !vha->flags.rscn_queue_overflow && |
| 3506 | rscn_out_iter != vha->rscn_in_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3507 | rscn_out_iter = (rscn_out_iter == |
| 3508 | (MAX_RSCN_COUNT - 1)) ? 0: rscn_out_iter + 1) { |
| 3509 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3510 | if (rscn_entry != vha->rscn_queue[rscn_out_iter]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3511 | break; |
| 3512 | |
| 3513 | DEBUG(printk("scsi(%ld): Skipping duplicate RSCN queue " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3514 | "entry found at [%d].\n", vha->host_no, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | rscn_out_iter)); |
| 3516 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3517 | vha->rscn_out_ptr = rscn_out_iter; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3518 | } |
| 3519 | |
| 3520 | /* Queue overflow, set switch default case. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3521 | if (vha->flags.rscn_queue_overflow) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3522 | DEBUG(printk("scsi(%ld): device_resync: rscn " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3523 | "overflow.\n", vha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | |
| 3525 | format = 3; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3526 | vha->flags.rscn_queue_overflow = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3527 | } |
| 3528 | |
| 3529 | switch (format) { |
| 3530 | case 0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3531 | mask = 0xffffff; |
| 3532 | break; |
| 3533 | case 1: |
| 3534 | mask = 0xffff00; |
| 3535 | break; |
| 3536 | case 2: |
| 3537 | mask = 0xff0000; |
| 3538 | break; |
| 3539 | default: |
| 3540 | mask = 0x0; |
| 3541 | d_id.b24 = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3542 | vha->rscn_out_ptr = vha->rscn_in_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3543 | break; |
| 3544 | } |
| 3545 | |
| 3546 | rval = QLA_SUCCESS; |
| 3547 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3548 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 || |
| 3550 | (fcport->d_id.b24 & mask) != d_id.b24 || |
| 3551 | fcport->port_type == FCT_BROADCAST) |
| 3552 | continue; |
| 3553 | |
| 3554 | if (atomic_read(&fcport->state) == FCS_ONLINE) { |
| 3555 | if (format != 3 || |
| 3556 | fcport->port_type != FCT_INITIATOR) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3557 | qla2x00_mark_device_lost(vha, fcport, |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3558 | 0, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | } |
| 3560 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3561 | } |
| 3562 | } |
| 3563 | return (rval); |
| 3564 | } |
| 3565 | |
| 3566 | /* |
| 3567 | * qla2x00_fabric_dev_login |
| 3568 | * Login fabric target device and update FC port database. |
| 3569 | * |
| 3570 | * Input: |
| 3571 | * ha: adapter state pointer. |
| 3572 | * fcport: port structure list pointer. |
| 3573 | * next_loopid: contains value of a new loop ID that can be used |
| 3574 | * by the next login attempt. |
| 3575 | * |
| 3576 | * Returns: |
| 3577 | * qla2x00 local function return status code. |
| 3578 | * |
| 3579 | * Context: |
| 3580 | * Kernel context. |
| 3581 | */ |
| 3582 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3583 | 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] | 3584 | uint16_t *next_loopid) |
| 3585 | { |
| 3586 | int rval; |
| 3587 | int retry; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3588 | uint8_t opts; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3589 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3590 | |
| 3591 | rval = QLA_SUCCESS; |
| 3592 | retry = 0; |
| 3593 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3594 | if (IS_ALOGIO_CAPABLE(ha)) { |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3595 | if (fcport->flags & FCF_ASYNC_SENT) |
| 3596 | return rval; |
| 3597 | fcport->flags |= FCF_ASYNC_SENT; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3598 | rval = qla2x00_post_async_login_work(vha, fcport, NULL); |
| 3599 | if (!rval) |
| 3600 | return rval; |
| 3601 | } |
| 3602 | |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3603 | fcport->flags &= ~FCF_ASYNC_SENT; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3604 | rval = qla2x00_fabric_login(vha, fcport, next_loopid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3605 | if (rval == QLA_SUCCESS) { |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3606 | /* Send an ADISC to FCP2 devices.*/ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3607 | opts = 0; |
Andrew Vasquez | f08b725 | 2010-01-12 12:59:48 -0800 | [diff] [blame] | 3608 | if (fcport->flags & FCF_FCP2_DEVICE) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3609 | opts |= BIT_1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3610 | rval = qla2x00_get_port_database(vha, fcport, opts); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3611 | if (rval != QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3612 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3613 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3614 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3615 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3616 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3617 | qla2x00_update_fcport(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | } |
| 3619 | } |
| 3620 | |
| 3621 | return (rval); |
| 3622 | } |
| 3623 | |
| 3624 | /* |
| 3625 | * qla2x00_fabric_login |
| 3626 | * Issue fabric login command. |
| 3627 | * |
| 3628 | * Input: |
| 3629 | * ha = adapter block pointer. |
| 3630 | * device = pointer to FC device type structure. |
| 3631 | * |
| 3632 | * Returns: |
| 3633 | * 0 - Login successfully |
| 3634 | * 1 - Login failed |
| 3635 | * 2 - Initiator device |
| 3636 | * 3 - Fatal error |
| 3637 | */ |
| 3638 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3639 | qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3640 | uint16_t *next_loopid) |
| 3641 | { |
| 3642 | int rval; |
| 3643 | int retry; |
| 3644 | uint16_t tmp_loopid; |
| 3645 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3646 | struct qla_hw_data *ha = vha->hw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | |
| 3648 | retry = 0; |
| 3649 | tmp_loopid = 0; |
| 3650 | |
| 3651 | for (;;) { |
| 3652 | DEBUG(printk("scsi(%ld): Trying Fabric Login w/loop id 0x%04x " |
| 3653 | "for port %02x%02x%02x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3654 | vha->host_no, fcport->loop_id, fcport->d_id.b.domain, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3656 | |
| 3657 | /* Login fcport on switch. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3658 | ha->isp_ops->fabric_login(vha, fcport->loop_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3660 | fcport->d_id.b.al_pa, mb, BIT_0); |
| 3661 | if (mb[0] == MBS_PORT_ID_USED) { |
| 3662 | /* |
| 3663 | * Device has another loop ID. The firmware team |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3664 | * recommends the driver perform an implicit login with |
| 3665 | * the specified ID again. The ID we just used is save |
| 3666 | * here so we return with an ID that can be tried by |
| 3667 | * the next login. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3668 | */ |
| 3669 | retry++; |
| 3670 | tmp_loopid = fcport->loop_id; |
| 3671 | fcport->loop_id = mb[1]; |
| 3672 | |
| 3673 | DEBUG(printk("Fabric Login: port in use - next " |
| 3674 | "loop id=0x%04x, port Id=%02x%02x%02x.\n", |
| 3675 | fcport->loop_id, fcport->d_id.b.domain, |
| 3676 | fcport->d_id.b.area, fcport->d_id.b.al_pa)); |
| 3677 | |
| 3678 | } else if (mb[0] == MBS_COMMAND_COMPLETE) { |
| 3679 | /* |
| 3680 | * Login succeeded. |
| 3681 | */ |
| 3682 | if (retry) { |
| 3683 | /* A retry occurred before. */ |
| 3684 | *next_loopid = tmp_loopid; |
| 3685 | } else { |
| 3686 | /* |
| 3687 | * No retry occurred before. Just increment the |
| 3688 | * ID value for next login. |
| 3689 | */ |
| 3690 | *next_loopid = (fcport->loop_id + 1); |
| 3691 | } |
| 3692 | |
| 3693 | if (mb[1] & BIT_0) { |
| 3694 | fcport->port_type = FCT_INITIATOR; |
| 3695 | } else { |
| 3696 | fcport->port_type = FCT_TARGET; |
| 3697 | if (mb[1] & BIT_1) { |
Santosh Vernekar | 8474f3a | 2009-08-25 11:36:16 -0700 | [diff] [blame] | 3698 | fcport->flags |= FCF_FCP2_DEVICE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | } |
| 3700 | } |
| 3701 | |
Andrew Vasquez | ad3e0ed | 2005-08-26 19:08:10 -0700 | [diff] [blame] | 3702 | if (mb[10] & BIT_0) |
| 3703 | fcport->supported_classes |= FC_COS_CLASS2; |
| 3704 | if (mb[10] & BIT_1) |
| 3705 | fcport->supported_classes |= FC_COS_CLASS3; |
| 3706 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | rval = QLA_SUCCESS; |
| 3708 | break; |
| 3709 | } else if (mb[0] == MBS_LOOP_ID_USED) { |
| 3710 | /* |
| 3711 | * Loop ID already used, try next loop ID. |
| 3712 | */ |
| 3713 | fcport->loop_id++; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3714 | rval = qla2x00_find_new_loop_id(vha, fcport); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3715 | if (rval != QLA_SUCCESS) { |
| 3716 | /* Ran out of loop IDs to use */ |
| 3717 | break; |
| 3718 | } |
| 3719 | } else if (mb[0] == MBS_COMMAND_ERROR) { |
| 3720 | /* |
| 3721 | * Firmware possibly timed out during login. If NO |
| 3722 | * retries are left to do then the device is declared |
| 3723 | * dead. |
| 3724 | */ |
| 3725 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3726 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3727 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3728 | fcport->d_id.b.al_pa); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3729 | qla2x00_mark_device_lost(vha, fcport, 1, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3730 | |
| 3731 | rval = 1; |
| 3732 | break; |
| 3733 | } else { |
| 3734 | /* |
| 3735 | * unrecoverable / not handled error |
| 3736 | */ |
| 3737 | DEBUG2(printk("%s(%ld): failed=%x port_id=%02x%02x%02x " |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 3738 | "loop_id=%x jiffies=%lx.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3739 | __func__, vha->host_no, mb[0], |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3740 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3741 | fcport->d_id.b.al_pa, fcport->loop_id, jiffies)); |
| 3742 | |
| 3743 | *next_loopid = fcport->loop_id; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3744 | ha->isp_ops->fabric_logout(vha, fcport->loop_id, |
Andrew Vasquez | 1c7c635 | 2005-07-06 10:30:57 -0700 | [diff] [blame] | 3745 | fcport->d_id.b.domain, fcport->d_id.b.area, |
| 3746 | fcport->d_id.b.al_pa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | fcport->loop_id = FC_NO_LOOP_ID; |
Andrew Vasquez | 0eedfcf | 2005-10-27 11:09:38 -0700 | [diff] [blame] | 3748 | fcport->login_retry = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3749 | |
| 3750 | rval = 3; |
| 3751 | break; |
| 3752 | } |
| 3753 | } |
| 3754 | |
| 3755 | return (rval); |
| 3756 | } |
| 3757 | |
| 3758 | /* |
| 3759 | * qla2x00_local_device_login |
| 3760 | * Issue local device login command. |
| 3761 | * |
| 3762 | * Input: |
| 3763 | * ha = adapter block pointer. |
| 3764 | * loop_id = loop id of device to login to. |
| 3765 | * |
| 3766 | * Returns (Where's the #define!!!!): |
| 3767 | * 0 - Login successfully |
| 3768 | * 1 - Login failed |
| 3769 | * 3 - Fatal error |
| 3770 | */ |
| 3771 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3772 | 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] | 3773 | { |
| 3774 | int rval; |
| 3775 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
| 3776 | |
| 3777 | memset(mb, 0, sizeof(mb)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3778 | rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3779 | if (rval == QLA_SUCCESS) { |
| 3780 | /* Interrogate mailbox registers for any errors */ |
| 3781 | if (mb[0] == MBS_COMMAND_ERROR) |
| 3782 | rval = 1; |
| 3783 | else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR) |
| 3784 | /* device not in PCB table */ |
| 3785 | rval = 3; |
| 3786 | } |
| 3787 | |
| 3788 | return (rval); |
| 3789 | } |
| 3790 | |
| 3791 | /* |
| 3792 | * qla2x00_loop_resync |
| 3793 | * Resync with fibre channel devices. |
| 3794 | * |
| 3795 | * Input: |
| 3796 | * ha = adapter block pointer. |
| 3797 | * |
| 3798 | * Returns: |
| 3799 | * 0 = success |
| 3800 | */ |
| 3801 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3802 | qla2x00_loop_resync(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3803 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3804 | int rval = QLA_SUCCESS; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3805 | uint32_t wait_time; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3806 | struct req_que *req; |
| 3807 | struct rsp_que *rsp; |
| 3808 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 3809 | if (vha->hw->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 3810 | req = vha->hw->req_q_map[0]; |
| 3811 | else |
| 3812 | req = vha->req; |
| 3813 | rsp = req->rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3814 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3815 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
| 3816 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 3817 | if (vha->flags.online) { |
| 3818 | if (!(rval = qla2x00_fw_ready(vha))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3819 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 3820 | wait_time = 256; |
| 3821 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3822 | atomic_set(&vha->loop_state, LOOP_UPDATE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3823 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 3824 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 3825 | qla2x00_marker(vha, req, rsp, 0, 0, |
| 3826 | MK_SYNC_ALL); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3827 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3828 | |
| 3829 | /* Remap devices on Loop. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3830 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3831 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3832 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3833 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3834 | } while (!atomic_read(&vha->loop_down_timer) && |
| 3835 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 3836 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 3837 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3838 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3839 | } |
| 3840 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3841 | if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3842 | return (QLA_FUNCTION_FAILED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3843 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 3844 | if (rval) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3845 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3846 | |
| 3847 | return (rval); |
| 3848 | } |
| 3849 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3850 | /* |
| 3851 | * qla2x00_perform_loop_resync |
| 3852 | * Description: This function will set the appropriate flags and call |
| 3853 | * qla2x00_loop_resync. If successful loop will be resynced |
| 3854 | * Arguments : scsi_qla_host_t pointer |
| 3855 | * returm : Success or Failure |
| 3856 | */ |
| 3857 | |
| 3858 | int qla2x00_perform_loop_resync(scsi_qla_host_t *ha) |
| 3859 | { |
| 3860 | int32_t rval = 0; |
| 3861 | |
| 3862 | if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) { |
| 3863 | /*Configure the flags so that resync happens properly*/ |
| 3864 | atomic_set(&ha->loop_down_timer, 0); |
| 3865 | if (!(ha->device_flags & DFLG_NO_CABLE)) { |
| 3866 | atomic_set(&ha->loop_state, LOOP_UP); |
| 3867 | set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags); |
| 3868 | set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags); |
| 3869 | set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags); |
| 3870 | |
| 3871 | rval = qla2x00_loop_resync(ha); |
| 3872 | } else |
| 3873 | atomic_set(&ha->loop_state, LOOP_DEAD); |
| 3874 | |
| 3875 | clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags); |
| 3876 | } |
| 3877 | |
| 3878 | return rval; |
| 3879 | } |
| 3880 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3881 | void |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3882 | qla2x00_update_fcports(scsi_qla_host_t *base_vha) |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3883 | { |
| 3884 | fc_port_t *fcport; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3885 | struct scsi_qla_host *vha; |
| 3886 | struct qla_hw_data *ha = base_vha->hw; |
| 3887 | unsigned long flags; |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3888 | |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3889 | spin_lock_irqsave(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3890 | /* Go with deferred removal of rport references. */ |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3891 | list_for_each_entry(vha, &base_vha->hw->vp_list, list) { |
| 3892 | atomic_inc(&vha->vref_count); |
| 3893 | list_for_each_entry(fcport, &vha->vp_fcports, list) { |
Dan Carpenter | 8ae598d | 2010-12-21 16:00:15 -0800 | [diff] [blame] | 3894 | if (fcport->drport && |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3895 | atomic_read(&fcport->state) != FCS_UNCONFIGURED) { |
| 3896 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3897 | |
Andrew Vasquez | 67becc0 | 2009-08-25 11:36:20 -0700 | [diff] [blame] | 3898 | qla2x00_rport_del(fcport); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3899 | |
| 3900 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3901 | } |
| 3902 | } |
| 3903 | atomic_dec(&vha->vref_count); |
| 3904 | } |
| 3905 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
andrew.vasquez@qlogic.com | d97994d | 2006-01-20 14:53:13 -0800 | [diff] [blame] | 3906 | } |
| 3907 | |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3908 | /* |
| 3909 | * qla82xx_quiescent_state_cleanup |
| 3910 | * Description: This function will block the new I/Os |
| 3911 | * Its not aborting any I/Os as context |
| 3912 | * is not destroyed during quiescence |
| 3913 | * Arguments: scsi_qla_host_t |
| 3914 | * return : void |
| 3915 | */ |
| 3916 | void |
| 3917 | qla82xx_quiescent_state_cleanup(scsi_qla_host_t *vha) |
| 3918 | { |
| 3919 | struct qla_hw_data *ha = vha->hw; |
| 3920 | struct scsi_qla_host *vp; |
| 3921 | |
| 3922 | qla_printk(KERN_INFO, ha, |
| 3923 | "Performing ISP error recovery - ha= %p.\n", ha); |
| 3924 | |
| 3925 | atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME); |
| 3926 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 3927 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 3928 | qla2x00_mark_all_devices_lost(vha, 0); |
| 3929 | list_for_each_entry(vp, &ha->vp_list, list) |
| 3930 | qla2x00_mark_all_devices_lost(vha, 0); |
| 3931 | } else { |
| 3932 | if (!atomic_read(&vha->loop_down_timer)) |
| 3933 | atomic_set(&vha->loop_down_timer, |
| 3934 | LOOP_DOWN_TIME); |
| 3935 | } |
| 3936 | /* Wait for pending cmds to complete */ |
| 3937 | qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST); |
| 3938 | } |
| 3939 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3940 | void |
| 3941 | qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha) |
| 3942 | { |
| 3943 | struct qla_hw_data *ha = vha->hw; |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3944 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3945 | unsigned long flags; |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 3946 | fc_port_t *fcport; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3947 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame^] | 3948 | /* For ISP82XX, driver waits for completion of the commands. |
| 3949 | * online flag should be set. |
| 3950 | */ |
| 3951 | if (!IS_QLA82XX(ha)) |
| 3952 | vha->flags.online = 0; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3953 | ha->flags.chip_reset_done = 0; |
| 3954 | clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags); |
| 3955 | ha->qla_stats.total_isp_aborts++; |
| 3956 | |
| 3957 | qla_printk(KERN_INFO, ha, |
| 3958 | "Performing ISP error recovery - ha= %p.\n", ha); |
| 3959 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame^] | 3960 | /* For ISP82XX, reset_chip is just disabling interrupts. |
| 3961 | * Driver waits for the completion of the commands. |
| 3962 | * the interrupts need to be enabled. |
| 3963 | */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3964 | if (!IS_QLA82XX(ha)) |
| 3965 | ha->isp_ops->reset_chip(vha); |
| 3966 | |
| 3967 | atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME); |
| 3968 | if (atomic_read(&vha->loop_state) != LOOP_DOWN) { |
| 3969 | atomic_set(&vha->loop_state, LOOP_DOWN); |
| 3970 | qla2x00_mark_all_devices_lost(vha, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3971 | |
| 3972 | spin_lock_irqsave(&ha->vport_slock, flags); |
Saurav Kashyap | 579d12b | 2010-12-21 16:00:14 -0800 | [diff] [blame] | 3973 | list_for_each_entry(vp, &ha->vp_list, list) { |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3974 | atomic_inc(&vp->vref_count); |
| 3975 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3976 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3977 | qla2x00_mark_all_devices_lost(vp, 0); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 3978 | |
| 3979 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3980 | atomic_dec(&vp->vref_count); |
| 3981 | } |
| 3982 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 3983 | } else { |
| 3984 | if (!atomic_read(&vha->loop_down_timer)) |
| 3985 | atomic_set(&vha->loop_down_timer, |
| 3986 | LOOP_DOWN_TIME); |
| 3987 | } |
| 3988 | |
Andrew Vasquez | 6aef87b | 2011-02-23 15:27:13 -0800 | [diff] [blame] | 3989 | /* Clear all async request states across all VPs. */ |
| 3990 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 3991 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 3992 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 3993 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 3994 | atomic_inc(&vp->vref_count); |
| 3995 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 3996 | |
| 3997 | list_for_each_entry(fcport, &vp->vp_fcports, list) |
| 3998 | fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT); |
| 3999 | |
| 4000 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4001 | atomic_dec(&vp->vref_count); |
| 4002 | } |
| 4003 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4004 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4005 | if (!ha->flags.eeh_busy) { |
| 4006 | /* Make sure for ISP 82XX IO DMA is complete */ |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame^] | 4007 | if (IS_QLA82XX(ha)) { |
Giridhar Malavali | 7190575 | 2011-02-23 15:27:10 -0800 | [diff] [blame] | 4008 | qla82xx_chip_reset_cleanup(vha); |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4009 | |
Saurav Kashyap | e46ef00 | 2011-02-23 15:27:16 -0800 | [diff] [blame^] | 4010 | /* Done waiting for pending commands. |
| 4011 | * Reset the online flag. |
| 4012 | */ |
| 4013 | vha->flags.online = 0; |
| 4014 | } |
| 4015 | |
Lalit Chandivade | bddd2d6 | 2010-09-03 15:20:53 -0700 | [diff] [blame] | 4016 | /* Requeue all commands in outstanding command list. */ |
| 4017 | qla2x00_abort_all_cmds(vha, DID_RESET << 16); |
| 4018 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4019 | } |
| 4020 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | /* |
| 4022 | * qla2x00_abort_isp |
| 4023 | * Resets ISP and aborts all outstanding commands. |
| 4024 | * |
| 4025 | * Input: |
| 4026 | * ha = adapter block pointer. |
| 4027 | * |
| 4028 | * Returns: |
| 4029 | * 0 = success |
| 4030 | */ |
| 4031 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4032 | qla2x00_abort_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | { |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4034 | int rval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | uint8_t status = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4036 | struct qla_hw_data *ha = vha->hw; |
| 4037 | struct scsi_qla_host *vp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4038 | struct req_que *req = ha->req_q_map[0]; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4039 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4041 | if (vha->flags.online) { |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4042 | qla2x00_abort_isp_cleanup(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4043 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4044 | if (unlikely(pci_channel_offline(ha->pdev) && |
| 4045 | ha->flags.pci_channel_io_perm_failure)) { |
| 4046 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 4047 | status = 0; |
| 4048 | return status; |
| 4049 | } |
| 4050 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4051 | ha->isp_ops->get_flash_version(vha, req->ring); |
Andrew Vasquez | 30c4766 | 2007-01-29 10:22:21 -0800 | [diff] [blame] | 4052 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4053 | ha->isp_ops->nvram_config(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4054 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4055 | if (!qla2x00_restart_isp(vha)) { |
| 4056 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4058 | if (!atomic_read(&vha->loop_down_timer)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | /* |
| 4060 | * Issue marker command only when we are going |
| 4061 | * to start the I/O . |
| 4062 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4063 | vha->marker_needed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4064 | } |
| 4065 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4066 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4067 | |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4068 | ha->isp_ops->enable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4070 | ha->isp_abort_cnt = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4071 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Andrew Vasquez | 476e897 | 2006-08-23 14:54:55 -0700 | [diff] [blame] | 4072 | |
Lalit Chandivade | 29c5397 | 2009-10-13 15:16:47 -0700 | [diff] [blame] | 4073 | if (IS_QLA81XX(ha)) |
| 4074 | qla2x00_get_fw_version(vha, |
| 4075 | &ha->fw_major_version, |
| 4076 | &ha->fw_minor_version, |
| 4077 | &ha->fw_subminor_version, |
| 4078 | &ha->fw_attributes, &ha->fw_memory_size, |
| 4079 | ha->mpi_version, &ha->mpi_capabilities, |
| 4080 | ha->phy_version); |
| 4081 | |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4082 | if (ha->fce) { |
| 4083 | ha->flags.fce_enabled = 1; |
| 4084 | memset(ha->fce, 0, |
| 4085 | fce_calc_size(ha->fce_bufs)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4086 | rval = qla2x00_enable_fce_trace(vha, |
Andrew Vasquez | df613b9 | 2008-01-17 09:02:17 -0800 | [diff] [blame] | 4087 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 4088 | &ha->fce_bufs); |
| 4089 | if (rval) { |
| 4090 | qla_printk(KERN_WARNING, ha, |
| 4091 | "Unable to reinitialize FCE " |
| 4092 | "(%d).\n", rval); |
| 4093 | ha->flags.fce_enabled = 0; |
| 4094 | } |
| 4095 | } |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4096 | |
| 4097 | if (ha->eft) { |
| 4098 | memset(ha->eft, 0, EFT_SIZE); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4099 | rval = qla2x00_enable_eft_trace(vha, |
Andrew Vasquez | 436a7b1 | 2008-07-10 16:55:54 -0700 | [diff] [blame] | 4100 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 4101 | if (rval) { |
| 4102 | qla_printk(KERN_WARNING, ha, |
| 4103 | "Unable to reinitialize EFT " |
| 4104 | "(%d).\n", rval); |
| 4105 | } |
| 4106 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | } else { /* failed the ISP abort */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4108 | vha->flags.online = 1; |
| 4109 | if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4110 | if (ha->isp_abort_cnt == 0) { |
| 4111 | qla_printk(KERN_WARNING, ha, |
| 4112 | "ISP error recovery failed - " |
| 4113 | "board disabled\n"); |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4114 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4115 | * The next call disables the board |
| 4116 | * completely. |
| 4117 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4118 | ha->isp_ops->reset_adapter(vha); |
| 4119 | vha->flags.online = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4120 | clear_bit(ISP_ABORT_RETRY, |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4121 | &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4122 | status = 0; |
| 4123 | } else { /* schedule another ISP abort */ |
| 4124 | ha->isp_abort_cnt--; |
| 4125 | DEBUG(printk("qla%ld: ISP abort - " |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4126 | "retry remaining %d\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4127 | vha->host_no, ha->isp_abort_cnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4128 | status = 1; |
| 4129 | } |
| 4130 | } else { |
| 4131 | ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT; |
| 4132 | DEBUG(printk("qla2x00(%ld): ISP error recovery " |
| 4133 | "- retrying (%d) more times\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4134 | vha->host_no, ha->isp_abort_cnt)); |
| 4135 | set_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4136 | status = 1; |
| 4137 | } |
| 4138 | } |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 4139 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4140 | } |
| 4141 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4142 | if (!status) { |
| 4143 | DEBUG(printk(KERN_INFO |
| 4144 | "qla2x00_abort_isp(%ld): succeeded.\n", |
| 4145 | vha->host_no)); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4146 | |
| 4147 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4148 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 4149 | if (vp->vp_idx) { |
| 4150 | atomic_inc(&vp->vref_count); |
| 4151 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4152 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4153 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4154 | |
| 4155 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 4156 | atomic_dec(&vp->vref_count); |
| 4157 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4158 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 4159 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 4160 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4161 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | qla_printk(KERN_INFO, ha, |
| 4163 | "qla2x00_abort_isp: **** FAILED ****\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4164 | } |
| 4165 | |
| 4166 | return(status); |
| 4167 | } |
| 4168 | |
| 4169 | /* |
| 4170 | * qla2x00_restart_isp |
| 4171 | * restarts the ISP after a reset |
| 4172 | * |
| 4173 | * Input: |
| 4174 | * ha = adapter block pointer. |
| 4175 | * |
| 4176 | * Returns: |
| 4177 | * 0 = success |
| 4178 | */ |
| 4179 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4180 | qla2x00_restart_isp(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4181 | { |
Andrew Vasquez | c6b2fca | 2009-03-05 11:07:03 -0800 | [diff] [blame] | 4182 | int status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4183 | uint32_t wait_time; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4184 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4185 | struct req_que *req = ha->req_q_map[0]; |
| 4186 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4187 | |
| 4188 | /* If firmware needs to be loaded */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4189 | if (qla2x00_isp_firmware(vha)) { |
| 4190 | vha->flags.online = 0; |
| 4191 | status = ha->isp_ops->chip_diag(vha); |
| 4192 | if (!status) |
| 4193 | status = qla2x00_setup_chip(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4194 | } |
| 4195 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4196 | if (!status && !(status = qla2x00_init_rings(vha))) { |
| 4197 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Lalit Chandivade | 2533cf6 | 2009-03-24 09:08:07 -0700 | [diff] [blame] | 4198 | ha->flags.chip_reset_done = 1; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4199 | /* Initialize the queues in use */ |
| 4200 | qla25xx_init_queues(ha); |
| 4201 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4202 | status = qla2x00_fw_ready(vha); |
| 4203 | if (!status) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4204 | DEBUG(printk("%s(): Start configure loop, " |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 4205 | "status = %d\n", __func__, status)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4206 | |
| 4207 | /* Issue a marker after FW becomes ready. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4208 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4209 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4210 | vha->flags.online = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4211 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 4212 | wait_time = 256; |
| 4213 | do { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4214 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 4215 | qla2x00_configure_loop(vha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4216 | wait_time--; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4217 | } while (!atomic_read(&vha->loop_down_timer) && |
| 4218 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) |
| 4219 | && wait_time && (test_bit(LOOP_RESYNC_NEEDED, |
| 4220 | &vha->dpc_flags))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4221 | } |
| 4222 | |
| 4223 | /* if no cable then assume it's good */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4224 | if ((vha->device_flags & DFLG_NO_CABLE)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | status = 0; |
| 4226 | |
| 4227 | DEBUG(printk("%s(): Configure loop done, status = 0x%x\n", |
| 4228 | __func__, |
Andrew Vasquez | 744f11fd | 2006-06-23 16:11:05 -0700 | [diff] [blame] | 4229 | status)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4230 | } |
| 4231 | return (status); |
| 4232 | } |
| 4233 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4234 | static int |
| 4235 | qla25xx_init_queues(struct qla_hw_data *ha) |
| 4236 | { |
| 4237 | struct rsp_que *rsp = NULL; |
| 4238 | struct req_que *req = NULL; |
| 4239 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
| 4240 | int ret = -1; |
| 4241 | int i; |
| 4242 | |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4243 | for (i = 1; i < ha->max_rsp_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4244 | rsp = ha->rsp_q_map[i]; |
| 4245 | if (rsp) { |
| 4246 | rsp->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4247 | ret = qla25xx_init_rsp_que(base_vha, rsp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4248 | if (ret != QLA_SUCCESS) |
| 4249 | DEBUG2_17(printk(KERN_WARNING |
| 4250 | "%s Rsp que:%d init failed\n", __func__, |
| 4251 | rsp->id)); |
| 4252 | else |
| 4253 | DEBUG2_17(printk(KERN_INFO |
| 4254 | "%s Rsp que:%d inited\n", __func__, |
| 4255 | rsp->id)); |
| 4256 | } |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 4257 | } |
| 4258 | for (i = 1; i < ha->max_req_queues; i++) { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4259 | req = ha->req_q_map[i]; |
| 4260 | if (req) { |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4261 | /* Clear outstanding commands array. */ |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4262 | req->options &= ~BIT_0; |
Anirban Chakraborty | 618a752 | 2009-02-08 20:50:11 -0800 | [diff] [blame] | 4263 | ret = qla25xx_init_req_que(base_vha, req); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4264 | if (ret != QLA_SUCCESS) |
| 4265 | DEBUG2_17(printk(KERN_WARNING |
| 4266 | "%s Req que:%d init failed\n", __func__, |
| 4267 | req->id)); |
| 4268 | else |
| 4269 | DEBUG2_17(printk(KERN_WARNING |
Anirban Chakraborty | 29bdccb | 2009-01-08 15:41:08 -0800 | [diff] [blame] | 4270 | "%s Req que:%d inited\n", __func__, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4271 | req->id)); |
| 4272 | } |
| 4273 | } |
| 4274 | return ret; |
| 4275 | } |
| 4276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4277 | /* |
| 4278 | * qla2x00_reset_adapter |
| 4279 | * Reset adapter. |
| 4280 | * |
| 4281 | * Input: |
| 4282 | * ha = adapter block pointer. |
| 4283 | */ |
Andrew Vasquez | abbd887 | 2005-07-06 10:30:05 -0700 | [diff] [blame] | 4284 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4285 | qla2x00_reset_adapter(scsi_qla_host_t *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4286 | { |
| 4287 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4288 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 4289 | struct device_reg_2xxx __iomem *reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4290 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4291 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4292 | ha->isp_ops->disable_intrs(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4293 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4294 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4295 | WRT_REG_WORD(®->hccr, HCCR_RESET_RISC); |
| 4296 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4297 | WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC); |
| 4298 | RD_REG_WORD(®->hccr); /* PCI Posting. */ |
| 4299 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 4300 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4301 | |
| 4302 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4303 | qla24xx_reset_adapter(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4304 | { |
| 4305 | unsigned long flags = 0; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4306 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4307 | struct device_reg_24xx __iomem *reg = &ha->iobase->isp24; |
| 4308 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4309 | if (IS_QLA82XX(ha)) |
| 4310 | return; |
| 4311 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4312 | vha->flags.online = 0; |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 4313 | ha->isp_ops->disable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4314 | |
| 4315 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 4316 | WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET); |
| 4317 | RD_REG_DWORD(®->hccr); |
| 4318 | WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE); |
| 4319 | RD_REG_DWORD(®->hccr); |
| 4320 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 09ff36d | 2009-01-22 09:45:30 -0800 | [diff] [blame] | 4321 | |
| 4322 | if (IS_NOPOLLING_TYPE(ha)) |
| 4323 | ha->isp_ops->enable_intrs(ha); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4324 | } |
| 4325 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4326 | /* On sparc systems, obtain port and node WWN from firmware |
| 4327 | * properties. |
| 4328 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4329 | static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, |
| 4330 | struct nvram_24xx *nv) |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4331 | { |
| 4332 | #ifdef CONFIG_SPARC |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4333 | struct qla_hw_data *ha = vha->hw; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4334 | struct pci_dev *pdev = ha->pdev; |
David S. Miller | 15576bc | 2007-05-08 00:36:49 -0700 | [diff] [blame] | 4335 | struct device_node *dp = pci_device_to_OF_node(pdev); |
| 4336 | const u8 *val; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4337 | int len; |
| 4338 | |
| 4339 | val = of_get_property(dp, "port-wwn", &len); |
| 4340 | if (val && len >= WWN_SIZE) |
| 4341 | memcpy(nv->port_name, val, WWN_SIZE); |
| 4342 | |
| 4343 | val = of_get_property(dp, "node-wwn", &len); |
| 4344 | if (val && len >= WWN_SIZE) |
| 4345 | memcpy(nv->node_name, val, WWN_SIZE); |
| 4346 | #endif |
| 4347 | } |
| 4348 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4349 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4350 | qla24xx_nvram_config(scsi_qla_host_t *vha) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4351 | { |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4352 | int rval; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4353 | struct init_cb_24xx *icb; |
| 4354 | struct nvram_24xx *nv; |
| 4355 | uint32_t *dptr; |
| 4356 | uint8_t *dptr1, *dptr2; |
| 4357 | uint32_t chksum; |
| 4358 | uint16_t cnt; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4359 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4360 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4361 | rval = QLA_SUCCESS; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4362 | icb = (struct init_cb_24xx *)ha->init_cb; |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4363 | nv = ha->nvram; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4364 | |
| 4365 | /* Determine NVRAM starting address. */ |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4366 | if (ha->flags.port0) { |
| 4367 | ha->nvram_base = FA_NVRAM_FUNC0_ADDR; |
| 4368 | ha->vpd_base = FA_NVRAM_VPD0_ADDR; |
| 4369 | } else { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4370 | ha->nvram_base = FA_NVRAM_FUNC1_ADDR; |
andrew.vasquez@qlogic.com | 6f64179 | 2006-03-09 14:27:34 -0800 | [diff] [blame] | 4371 | ha->vpd_base = FA_NVRAM_VPD1_ADDR; |
| 4372 | } |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4373 | ha->nvram_size = sizeof(struct nvram_24xx); |
| 4374 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 4375 | if (IS_QLA82XX(ha)) |
| 4376 | ha->vpd_size = FA_VPD_SIZE_82XX; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4377 | |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4378 | /* Get VPD data into cache */ |
| 4379 | ha->vpd = ha->nvram + VPD_OFFSET; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4380 | ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd, |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4381 | ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4); |
| 4382 | |
| 4383 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4384 | dptr = (uint32_t *)nv; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4385 | ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4386 | ha->nvram_size); |
| 4387 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 4388 | chksum += le32_to_cpu(*dptr++); |
| 4389 | |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 4390 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
Seokmann Ju | 281afe1 | 2007-07-26 13:43:34 -0700 | [diff] [blame] | 4391 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4392 | |
| 4393 | /* Bad NVRAM data, set defaults parameters. */ |
| 4394 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 4395 | || nv->id[3] != ' ' || |
| 4396 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 4397 | /* Reset NVRAM data. */ |
| 4398 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 4399 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 4400 | le16_to_cpu(nv->nvram_version)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4401 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 4402 | "invalid -- WWPN) defaults.\n"); |
| 4403 | |
| 4404 | /* |
| 4405 | * Set default initialization control block. |
| 4406 | */ |
| 4407 | memset(nv, 0, ha->nvram_size); |
| 4408 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 4409 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 4410 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 4411 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4412 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 4413 | nv->hard_address = __constant_cpu_to_le16(124); |
| 4414 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 4415 | nv->port_name[1] = 0x00 + ha->port_no; |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4416 | nv->port_name[2] = 0x00; |
| 4417 | nv->port_name[3] = 0xe0; |
| 4418 | nv->port_name[4] = 0x8b; |
| 4419 | nv->port_name[5] = 0x1c; |
| 4420 | nv->port_name[6] = 0x55; |
| 4421 | nv->port_name[7] = 0x86; |
| 4422 | nv->node_name[0] = 0x20; |
| 4423 | nv->node_name[1] = 0x00; |
| 4424 | nv->node_name[2] = 0x00; |
| 4425 | nv->node_name[3] = 0xe0; |
| 4426 | nv->node_name[4] = 0x8b; |
| 4427 | nv->node_name[5] = 0x1c; |
| 4428 | nv->node_name[6] = 0x55; |
| 4429 | nv->node_name[7] = 0x86; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4430 | qla24xx_nvram_wwn_from_ofw(vha, nv); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4431 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 4432 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 4433 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 4434 | nv->firmware_options_1 = |
| 4435 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 4436 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 4437 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 4438 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 4439 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 4440 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 4441 | nv->reset_delay = 5; |
| 4442 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 4443 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 4444 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
| 4445 | |
| 4446 | rval = 1; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4447 | } |
| 4448 | |
| 4449 | /* Reset Initialization control block */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4450 | memset(icb, 0, ha->init_cb_size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4451 | |
| 4452 | /* Copy 1st segment. */ |
| 4453 | dptr1 = (uint8_t *)icb; |
| 4454 | dptr2 = (uint8_t *)&nv->version; |
| 4455 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 4456 | while (cnt--) |
| 4457 | *dptr1++ = *dptr2++; |
| 4458 | |
| 4459 | icb->login_retry_count = nv->login_retry_count; |
Andrew Vasquez | 3ea66e2 | 2006-06-23 16:11:27 -0700 | [diff] [blame] | 4460 | icb->link_down_on_nos = nv->link_down_on_nos; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4461 | |
| 4462 | /* Copy 2nd segment. */ |
| 4463 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 4464 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 4465 | cnt = (uint8_t *)&icb->reserved_3 - |
| 4466 | (uint8_t *)&icb->interrupt_delay_timer; |
| 4467 | while (cnt--) |
| 4468 | *dptr1++ = *dptr2++; |
| 4469 | |
| 4470 | /* |
| 4471 | * Setup driver NVRAM options. |
| 4472 | */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4473 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Andrew Vasquez | 9bb9fcf | 2007-01-29 10:22:24 -0800 | [diff] [blame] | 4474 | "QLA2462"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4475 | |
Andrew Vasquez | 5341e86 | 2006-05-17 15:09:16 -0700 | [diff] [blame] | 4476 | /* Use alternate WWN? */ |
| 4477 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 4478 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 4479 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 4480 | } |
| 4481 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4482 | /* Prepare nodename */ |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4483 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4484 | /* |
| 4485 | * Firmware will apply the following mask if the nodename was |
| 4486 | * not provided. |
| 4487 | */ |
| 4488 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 4489 | icb->node_name[0] &= 0xF0; |
| 4490 | } |
| 4491 | |
| 4492 | /* Set host adapter parameters. */ |
| 4493 | ha->flags.disable_risc_code_load = 0; |
Andrew Vasquez | 0c8c39a | 2006-12-13 19:20:30 -0800 | [diff] [blame] | 4494 | ha->flags.enable_lip_reset = 0; |
| 4495 | ha->flags.enable_lip_full_login = |
| 4496 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 4497 | ha->flags.enable_target_reset = |
| 4498 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4499 | ha->flags.enable_led_scheme = 0; |
Andrew Vasquez | d4c760c | 2006-06-23 16:10:39 -0700 | [diff] [blame] | 4500 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4501 | |
Andrew Vasquez | fd0e7e4 | 2006-05-17 15:09:11 -0700 | [diff] [blame] | 4502 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 4503 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4504 | |
| 4505 | memcpy(ha->fw_seriallink_options24, nv->seriallink_options, |
| 4506 | sizeof(ha->fw_seriallink_options24)); |
| 4507 | |
| 4508 | /* save HBA serial number */ |
| 4509 | ha->serial0 = icb->port_name[5]; |
| 4510 | ha->serial1 = icb->port_name[6]; |
| 4511 | ha->serial2 = icb->port_name[7]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4512 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 4513 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4514 | |
andrew.vasquez@qlogic.com | bc8fb3c | 2006-01-13 17:05:42 -0800 | [diff] [blame] | 4515 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 4516 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4517 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 4518 | |
| 4519 | /* Set minimum login_timeout to 4 seconds. */ |
| 4520 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 4521 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 4522 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 4523 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 4524 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
Seokmann Ju | c6852c4 | 2008-04-24 15:21:29 -0700 | [diff] [blame] | 4525 | icb->login_timeout = nv->login_timeout; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4526 | |
Andrew Vasquez | 00a537b | 2008-02-28 14:06:11 -0800 | [diff] [blame] | 4527 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 4528 | ha->r_a_tov = 100; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4529 | |
| 4530 | ha->loop_reset_delay = nv->reset_delay; |
| 4531 | |
| 4532 | /* Link Down Timeout = 0: |
| 4533 | * |
| 4534 | * When Port Down timer expires we will start returning |
| 4535 | * I/O's to OS with "DID_NO_CONNECT". |
| 4536 | * |
| 4537 | * Link Down Timeout != 0: |
| 4538 | * |
| 4539 | * The driver waits for the link to come up after link down |
| 4540 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 4541 | */ |
| 4542 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 4543 | ha->loop_down_abort_time = |
| 4544 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 4545 | } else { |
| 4546 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 4547 | ha->loop_down_abort_time = |
| 4548 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 4549 | } |
| 4550 | |
| 4551 | /* Need enough time to try and get the port back. */ |
| 4552 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 4553 | if (qlport_down_retry) |
| 4554 | ha->port_down_retry_count = qlport_down_retry; |
| 4555 | |
| 4556 | /* Set login_retry_count */ |
| 4557 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 4558 | if (ha->port_down_retry_count == |
| 4559 | le16_to_cpu(nv->port_down_retry_count) && |
| 4560 | ha->port_down_retry_count > 3) |
| 4561 | ha->login_retry_count = ha->port_down_retry_count; |
| 4562 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 4563 | ha->login_retry_count = ha->port_down_retry_count; |
| 4564 | if (ql2xloginretrycount) |
| 4565 | ha->login_retry_count = ql2xloginretrycount; |
| 4566 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4567 | /* Enable ZIO. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4568 | if (!vha->flags.init_done) { |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4569 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 4570 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 4571 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 4572 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 4573 | } |
| 4574 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 4575 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4576 | vha->flags.process_response_queue = 0; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4577 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
andrew.vasquez@qlogic.com | 4a59f71 | 2006-03-09 14:27:39 -0800 | [diff] [blame] | 4578 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 4579 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4580 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4581 | "(%d us).\n", vha->host_no, ha->zio_mode, |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4582 | ha->zio_timer * 100)); |
| 4583 | qla_printk(KERN_INFO, ha, |
| 4584 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 4585 | ha->zio_mode, ha->zio_timer * 100); |
| 4586 | |
| 4587 | icb->firmware_options_2 |= cpu_to_le32( |
| 4588 | (uint32_t)ha->zio_mode); |
| 4589 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4590 | vha->flags.process_response_queue = 1; |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 4591 | } |
| 4592 | |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4593 | if (rval) { |
| 4594 | DEBUG2_3(printk(KERN_WARNING |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4595 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
David Miller | 4e08df3 | 2007-04-16 12:37:43 -0700 | [diff] [blame] | 4596 | } |
| 4597 | return (rval); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4598 | } |
| 4599 | |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 4600 | static int |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4601 | qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr, |
| 4602 | uint32_t faddr) |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4603 | { |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4604 | int rval = QLA_SUCCESS; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4605 | int segments, fragment; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4606 | uint32_t *dcode, dlen; |
| 4607 | uint32_t risc_addr; |
| 4608 | uint32_t risc_size; |
| 4609 | uint32_t i; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4610 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4611 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4612 | |
| 4613 | qla_printk(KERN_INFO, ha, |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4614 | "FW: Loading from flash (%x)...\n", faddr); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4615 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4616 | rval = QLA_SUCCESS; |
| 4617 | |
| 4618 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4619 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4620 | *srisc_addr = 0; |
| 4621 | |
| 4622 | /* Validate firmware image by checking version. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4623 | qla24xx_read_flash_data(vha, dcode, faddr + 4, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4624 | for (i = 0; i < 4; i++) |
| 4625 | dcode[i] = be32_to_cpu(dcode[i]); |
| 4626 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 4627 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 4628 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 4629 | dcode[3] == 0)) { |
| 4630 | qla_printk(KERN_WARNING, ha, |
| 4631 | "Unable to verify integrity of flash firmware image!\n"); |
| 4632 | qla_printk(KERN_WARNING, ha, |
| 4633 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 4634 | dcode[1], dcode[2], dcode[3]); |
| 4635 | |
| 4636 | return QLA_FUNCTION_FAILED; |
| 4637 | } |
| 4638 | |
| 4639 | while (segments && rval == QLA_SUCCESS) { |
| 4640 | /* Read segment's load information. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4641 | qla24xx_read_flash_data(vha, dcode, faddr, 4); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4642 | |
| 4643 | risc_addr = be32_to_cpu(dcode[2]); |
| 4644 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 4645 | risc_size = be32_to_cpu(dcode[3]); |
| 4646 | |
| 4647 | fragment = 0; |
| 4648 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4649 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 4650 | if (dlen > risc_size) |
| 4651 | dlen = risc_size; |
| 4652 | |
| 4653 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
| 4654 | "addr %x, number of dwords 0x%x, offset 0x%x.\n", |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4655 | vha->host_no, risc_addr, dlen, faddr)); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4656 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4657 | qla24xx_read_flash_data(vha, dcode, faddr, dlen); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4658 | for (i = 0; i < dlen; i++) |
| 4659 | dcode[i] = swab32(dcode[i]); |
| 4660 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4661 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4662 | dlen); |
| 4663 | if (rval) { |
| 4664 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4665 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4666 | fragment)); |
| 4667 | qla_printk(KERN_WARNING, ha, |
| 4668 | "[ERROR] Failed to load segment %d of " |
| 4669 | "firmware\n", fragment); |
| 4670 | break; |
| 4671 | } |
| 4672 | |
| 4673 | faddr += dlen; |
| 4674 | risc_addr += dlen; |
| 4675 | risc_size -= dlen; |
| 4676 | fragment++; |
| 4677 | } |
| 4678 | |
| 4679 | /* Next segment. */ |
| 4680 | segments--; |
| 4681 | } |
| 4682 | |
| 4683 | return rval; |
| 4684 | } |
| 4685 | |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4686 | #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/" |
| 4687 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4688 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4689 | qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4690 | { |
| 4691 | int rval; |
| 4692 | int i, fragment; |
| 4693 | uint16_t *wcode, *fwcode; |
| 4694 | uint32_t risc_addr, risc_size, fwclen, wlen, *seg; |
| 4695 | struct fw_blob *blob; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4696 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4697 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4698 | |
| 4699 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4700 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4701 | if (!blob) { |
| 4702 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4703 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 4704 | "from: " QLA_FW_URL ".\n"); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4705 | return QLA_FUNCTION_FAILED; |
| 4706 | } |
| 4707 | |
| 4708 | rval = QLA_SUCCESS; |
| 4709 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4710 | wcode = (uint16_t *)req->ring; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4711 | *srisc_addr = 0; |
| 4712 | fwcode = (uint16_t *)blob->fw->data; |
| 4713 | fwclen = 0; |
| 4714 | |
| 4715 | /* Validate firmware image by checking version. */ |
| 4716 | if (blob->fw->size < 8 * sizeof(uint16_t)) { |
| 4717 | qla_printk(KERN_WARNING, ha, |
| 4718 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 4719 | blob->fw->size); |
| 4720 | goto fail_fw_integrity; |
| 4721 | } |
| 4722 | for (i = 0; i < 4; i++) |
| 4723 | wcode[i] = be16_to_cpu(fwcode[i + 4]); |
| 4724 | if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff && |
| 4725 | wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 && |
| 4726 | wcode[2] == 0 && wcode[3] == 0)) { |
| 4727 | qla_printk(KERN_WARNING, ha, |
| 4728 | "Unable to verify integrity of firmware image!\n"); |
| 4729 | qla_printk(KERN_WARNING, ha, |
| 4730 | "Firmware data: %04x %04x %04x %04x!\n", wcode[0], |
| 4731 | wcode[1], wcode[2], wcode[3]); |
| 4732 | goto fail_fw_integrity; |
| 4733 | } |
| 4734 | |
| 4735 | seg = blob->segs; |
| 4736 | while (*seg && rval == QLA_SUCCESS) { |
| 4737 | risc_addr = *seg; |
| 4738 | *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr; |
| 4739 | risc_size = be16_to_cpu(fwcode[3]); |
| 4740 | |
| 4741 | /* Validate firmware image size. */ |
| 4742 | fwclen += risc_size * sizeof(uint16_t); |
| 4743 | if (blob->fw->size < fwclen) { |
| 4744 | qla_printk(KERN_WARNING, ha, |
| 4745 | "Unable to verify integrity of firmware image " |
| 4746 | "(%Zd)!\n", blob->fw->size); |
| 4747 | goto fail_fw_integrity; |
| 4748 | } |
| 4749 | |
| 4750 | fragment = 0; |
| 4751 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4752 | wlen = (uint16_t)(ha->fw_transfer_size >> 1); |
| 4753 | if (wlen > risc_size) |
| 4754 | wlen = risc_size; |
| 4755 | |
| 4756 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4757 | "addr %x, number of words 0x%x.\n", vha->host_no, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4758 | risc_addr, wlen)); |
| 4759 | |
| 4760 | for (i = 0; i < wlen; i++) |
| 4761 | wcode[i] = swab16(fwcode[i]); |
| 4762 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4763 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4764 | wlen); |
| 4765 | if (rval) { |
| 4766 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4767 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4768 | fragment)); |
| 4769 | qla_printk(KERN_WARNING, ha, |
| 4770 | "[ERROR] Failed to load segment %d of " |
| 4771 | "firmware\n", fragment); |
| 4772 | break; |
| 4773 | } |
| 4774 | |
| 4775 | fwcode += wlen; |
| 4776 | risc_addr += wlen; |
| 4777 | risc_size -= wlen; |
| 4778 | fragment++; |
| 4779 | } |
| 4780 | |
| 4781 | /* Next segment. */ |
| 4782 | seg++; |
| 4783 | } |
| 4784 | return rval; |
| 4785 | |
| 4786 | fail_fw_integrity: |
| 4787 | return QLA_FUNCTION_FAILED; |
| 4788 | } |
| 4789 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4790 | static int |
| 4791 | qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4792 | { |
| 4793 | int rval; |
| 4794 | int segments, fragment; |
| 4795 | uint32_t *dcode, dlen; |
| 4796 | uint32_t risc_addr; |
| 4797 | uint32_t risc_size; |
| 4798 | uint32_t i; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4799 | struct fw_blob *blob; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4800 | uint32_t *fwcode, fwclen; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4801 | struct qla_hw_data *ha = vha->hw; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4802 | struct req_que *req = ha->req_q_map[0]; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4803 | |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4804 | /* Load firmware blob. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4805 | blob = qla2x00_request_firmware(vha); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4806 | if (!blob) { |
| 4807 | qla_printk(KERN_ERR, ha, "Firmware image unavailable.\n"); |
Andrew Vasquez | d1c6190 | 2006-05-17 15:09:00 -0700 | [diff] [blame] | 4808 | qla_printk(KERN_ERR, ha, "Firmware images can be retrieved " |
| 4809 | "from: " QLA_FW_URL ".\n"); |
| 4810 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4811 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4812 | } |
| 4813 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4814 | qla_printk(KERN_INFO, ha, |
| 4815 | "FW: Loading via request-firmware...\n"); |
| 4816 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4817 | rval = QLA_SUCCESS; |
| 4818 | |
| 4819 | segments = FA_RISC_CODE_SEGMENTS; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4820 | dcode = (uint32_t *)req->ring; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4821 | *srisc_addr = 0; |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4822 | fwcode = (uint32_t *)blob->fw->data; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4823 | fwclen = 0; |
| 4824 | |
| 4825 | /* Validate firmware image by checking version. */ |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4826 | if (blob->fw->size < 8 * sizeof(uint32_t)) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4827 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4828 | "Unable to verify integrity of firmware image (%Zd)!\n", |
| 4829 | blob->fw->size); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4830 | goto fail_fw_integrity; |
| 4831 | } |
| 4832 | for (i = 0; i < 4; i++) |
| 4833 | dcode[i] = be32_to_cpu(fwcode[i + 4]); |
| 4834 | if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff && |
| 4835 | dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) || |
| 4836 | (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 && |
| 4837 | dcode[3] == 0)) { |
| 4838 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4839 | "Unable to verify integrity of firmware image!\n"); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4840 | qla_printk(KERN_WARNING, ha, |
| 4841 | "Firmware data: %08x %08x %08x %08x!\n", dcode[0], |
| 4842 | dcode[1], dcode[2], dcode[3]); |
| 4843 | goto fail_fw_integrity; |
| 4844 | } |
| 4845 | |
| 4846 | while (segments && rval == QLA_SUCCESS) { |
| 4847 | risc_addr = be32_to_cpu(fwcode[2]); |
| 4848 | *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr; |
| 4849 | risc_size = be32_to_cpu(fwcode[3]); |
| 4850 | |
| 4851 | /* Validate firmware image size. */ |
| 4852 | fwclen += risc_size * sizeof(uint32_t); |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4853 | if (blob->fw->size < fwclen) { |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4854 | qla_printk(KERN_WARNING, ha, |
Andrew Vasquez | 5433383 | 2005-11-09 15:49:04 -0800 | [diff] [blame] | 4855 | "Unable to verify integrity of firmware image " |
| 4856 | "(%Zd)!\n", blob->fw->size); |
| 4857 | |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4858 | goto fail_fw_integrity; |
| 4859 | } |
| 4860 | |
| 4861 | fragment = 0; |
| 4862 | while (risc_size > 0 && rval == QLA_SUCCESS) { |
| 4863 | dlen = (uint32_t)(ha->fw_transfer_size >> 2); |
| 4864 | if (dlen > risc_size) |
| 4865 | dlen = risc_size; |
| 4866 | |
| 4867 | DEBUG7(printk("scsi(%ld): Loading risc segment@ risc " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4868 | "addr %x, number of dwords 0x%x.\n", vha->host_no, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4869 | risc_addr, dlen)); |
| 4870 | |
| 4871 | for (i = 0; i < dlen; i++) |
| 4872 | dcode[i] = swab32(fwcode[i]); |
| 4873 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 4874 | rval = qla2x00_load_ram(vha, req->dma, risc_addr, |
andrew.vasquez@qlogic.com | 590f98e | 2006-01-13 17:05:37 -0800 | [diff] [blame] | 4875 | dlen); |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4876 | if (rval) { |
| 4877 | DEBUG(printk("scsi(%ld):[ERROR] Failed to load " |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4878 | "segment %d of firmware\n", vha->host_no, |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4879 | fragment)); |
| 4880 | qla_printk(KERN_WARNING, ha, |
| 4881 | "[ERROR] Failed to load segment %d of " |
| 4882 | "firmware\n", fragment); |
| 4883 | break; |
| 4884 | } |
| 4885 | |
| 4886 | fwcode += dlen; |
| 4887 | risc_addr += dlen; |
| 4888 | risc_size -= dlen; |
| 4889 | fragment++; |
| 4890 | } |
| 4891 | |
| 4892 | /* Next segment. */ |
| 4893 | segments--; |
| 4894 | } |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4895 | return rval; |
| 4896 | |
| 4897 | fail_fw_integrity: |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4898 | return QLA_FUNCTION_FAILED; |
Andrew Vasquez | 0107109e | 2005-07-06 10:31:37 -0700 | [diff] [blame] | 4899 | } |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4900 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4901 | int |
| 4902 | qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 4903 | { |
| 4904 | int rval; |
| 4905 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4906 | if (ql2xfwloadbin == 1) |
| 4907 | return qla81xx_load_risc(vha, srisc_addr); |
| 4908 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4909 | /* |
| 4910 | * FW Load priority: |
| 4911 | * 1) Firmware via request-firmware interface (.bin file). |
| 4912 | * 2) Firmware residing in flash. |
| 4913 | */ |
| 4914 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 4915 | if (rval == QLA_SUCCESS) |
| 4916 | return rval; |
| 4917 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4918 | return qla24xx_load_risc_flash(vha, srisc_addr, |
| 4919 | vha->hw->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4920 | } |
| 4921 | |
| 4922 | int |
| 4923 | qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr) |
| 4924 | { |
| 4925 | int rval; |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4926 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4927 | |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4928 | if (ql2xfwloadbin == 2) |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4929 | goto try_blob_fw; |
Andrew Vasquez | e337d90 | 2009-04-06 22:33:49 -0700 | [diff] [blame] | 4930 | |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4931 | /* |
| 4932 | * FW Load priority: |
| 4933 | * 1) Firmware residing in flash. |
| 4934 | * 2) Firmware via request-firmware interface (.bin file). |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4935 | * 3) Golden-Firmware residing in flash -- limited operation. |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4936 | */ |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4937 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw); |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4938 | if (rval == QLA_SUCCESS) |
| 4939 | return rval; |
| 4940 | |
Andrew Vasquez | cbc8eb6 | 2009-06-03 09:55:17 -0700 | [diff] [blame] | 4941 | try_blob_fw: |
| 4942 | rval = qla24xx_load_risc_blob(vha, srisc_addr); |
| 4943 | if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw) |
| 4944 | return rval; |
| 4945 | |
| 4946 | qla_printk(KERN_ERR, ha, |
| 4947 | "FW: Attempting to fallback to golden firmware...\n"); |
| 4948 | rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw); |
| 4949 | if (rval != QLA_SUCCESS) |
| 4950 | return rval; |
| 4951 | |
| 4952 | qla_printk(KERN_ERR, ha, |
| 4953 | "FW: Please update operational firmware...\n"); |
| 4954 | ha->flags.running_gold_fw = 1; |
| 4955 | |
| 4956 | return rval; |
Andrew Vasquez | eaac30b | 2009-01-22 09:45:32 -0800 | [diff] [blame] | 4957 | } |
| 4958 | |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4959 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4960 | qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4961 | { |
| 4962 | int ret, retries; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4963 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4964 | |
Andrew Vasquez | 8588080 | 2009-12-15 21:29:46 -0800 | [diff] [blame] | 4965 | if (ha->flags.pci_channel_io_perm_failure) |
| 4966 | return; |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 4967 | if (!IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4968 | return; |
Andrew Vasquez | 75edf81 | 2007-05-07 07:43:00 -0700 | [diff] [blame] | 4969 | if (!ha->fw_major_version) |
| 4970 | return; |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4971 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4972 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 7c7f1f2 | 2008-02-28 14:06:09 -0800 | [diff] [blame] | 4973 | for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT && |
Andrew Vasquez | b469a7c | 2009-04-06 22:33:48 -0700 | [diff] [blame] | 4974 | ret != QLA_INVALID_COMMAND && retries ; retries--) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4975 | ha->isp_ops->reset_chip(vha); |
| 4976 | if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4977 | continue; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4978 | if (qla2x00_setup_chip(vha) != QLA_SUCCESS) |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4979 | continue; |
| 4980 | qla_printk(KERN_INFO, ha, |
| 4981 | "Attempting retry of stop-firmware command...\n"); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4982 | ret = qla2x00_stop_firmware(vha); |
Andrew Vasquez | 18c6c12 | 2006-10-13 09:33:38 -0700 | [diff] [blame] | 4983 | } |
| 4984 | } |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4985 | |
| 4986 | int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4987 | qla24xx_configure_vhba(scsi_qla_host_t *vha) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4988 | { |
| 4989 | int rval = QLA_SUCCESS; |
| 4990 | uint16_t mb[MAILBOX_REGISTER_COUNT]; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4991 | struct qla_hw_data *ha = vha->hw; |
| 4992 | struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev); |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 4993 | struct req_que *req; |
| 4994 | struct rsp_que *rsp; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4995 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4996 | if (!vha->vp_idx) |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 4997 | return -EINVAL; |
| 4998 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 4999 | rval = qla2x00_fw_ready(base_vha); |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 5000 | if (ha->flags.cpu_affinity_enabled) |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 5001 | req = ha->req_q_map[0]; |
| 5002 | else |
| 5003 | req = vha->req; |
| 5004 | rsp = req->rsp; |
| 5005 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5006 | if (rval == QLA_SUCCESS) { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5007 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 5008 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5009 | } |
| 5010 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5011 | vha->flags.management_server_logged_in = 0; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5012 | |
| 5013 | /* Login to SNS first */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5014 | 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] | 5015 | if (mb[0] != MBS_COMMAND_COMPLETE) { |
| 5016 | DEBUG15(qla_printk(KERN_INFO, ha, |
| 5017 | "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x " |
| 5018 | "mb[2]=%x mb[6]=%x mb[7]=%x\n", NPH_SNS, |
| 5019 | mb[0], mb[1], mb[2], mb[6], mb[7])); |
| 5020 | return (QLA_FUNCTION_FAILED); |
| 5021 | } |
| 5022 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5023 | atomic_set(&vha->loop_down_timer, 0); |
| 5024 | atomic_set(&vha->loop_state, LOOP_UP); |
| 5025 | set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5026 | set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags); |
| 5027 | rval = qla2x00_loop_resync(base_vha); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 5028 | |
| 5029 | return rval; |
| 5030 | } |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5031 | |
| 5032 | /* 84XX Support **************************************************************/ |
| 5033 | |
| 5034 | static LIST_HEAD(qla_cs84xx_list); |
| 5035 | static DEFINE_MUTEX(qla_cs84xx_mutex); |
| 5036 | |
| 5037 | static struct qla_chip_state_84xx * |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5038 | qla84xx_get_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5039 | { |
| 5040 | struct qla_chip_state_84xx *cs84xx; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5041 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5042 | |
| 5043 | mutex_lock(&qla_cs84xx_mutex); |
| 5044 | |
| 5045 | /* Find any shared 84xx chip. */ |
| 5046 | list_for_each_entry(cs84xx, &qla_cs84xx_list, list) { |
| 5047 | if (cs84xx->bus == ha->pdev->bus) { |
| 5048 | kref_get(&cs84xx->kref); |
| 5049 | goto done; |
| 5050 | } |
| 5051 | } |
| 5052 | |
| 5053 | cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL); |
| 5054 | if (!cs84xx) |
| 5055 | goto done; |
| 5056 | |
| 5057 | kref_init(&cs84xx->kref); |
| 5058 | spin_lock_init(&cs84xx->access_lock); |
| 5059 | mutex_init(&cs84xx->fw_update_mutex); |
| 5060 | cs84xx->bus = ha->pdev->bus; |
| 5061 | |
| 5062 | list_add_tail(&cs84xx->list, &qla_cs84xx_list); |
| 5063 | done: |
| 5064 | mutex_unlock(&qla_cs84xx_mutex); |
| 5065 | return cs84xx; |
| 5066 | } |
| 5067 | |
| 5068 | static void |
| 5069 | __qla84xx_chip_release(struct kref *kref) |
| 5070 | { |
| 5071 | struct qla_chip_state_84xx *cs84xx = |
| 5072 | container_of(kref, struct qla_chip_state_84xx, kref); |
| 5073 | |
| 5074 | mutex_lock(&qla_cs84xx_mutex); |
| 5075 | list_del(&cs84xx->list); |
| 5076 | mutex_unlock(&qla_cs84xx_mutex); |
| 5077 | kfree(cs84xx); |
| 5078 | } |
| 5079 | |
| 5080 | void |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5081 | qla84xx_put_chip(struct scsi_qla_host *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5082 | { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5083 | struct qla_hw_data *ha = vha->hw; |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5084 | if (ha->cs84xx) |
| 5085 | kref_put(&ha->cs84xx->kref, __qla84xx_chip_release); |
| 5086 | } |
| 5087 | |
| 5088 | static int |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5089 | qla84xx_init_chip(scsi_qla_host_t *vha) |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5090 | { |
| 5091 | int rval; |
| 5092 | uint16_t status[2]; |
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 | |
| 5095 | mutex_lock(&ha->cs84xx->fw_update_mutex); |
| 5096 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 5097 | rval = qla84xx_verify_chip(vha, status); |
Harihara Kadayam | 4d4df19 | 2008-04-03 13:13:26 -0700 | [diff] [blame] | 5098 | |
| 5099 | mutex_unlock(&ha->cs84xx->fw_update_mutex); |
| 5100 | |
| 5101 | return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED: |
| 5102 | QLA_SUCCESS; |
| 5103 | } |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5104 | |
| 5105 | /* 81XX Support **************************************************************/ |
| 5106 | |
| 5107 | int |
| 5108 | qla81xx_nvram_config(scsi_qla_host_t *vha) |
| 5109 | { |
| 5110 | int rval; |
| 5111 | struct init_cb_81xx *icb; |
| 5112 | struct nvram_81xx *nv; |
| 5113 | uint32_t *dptr; |
| 5114 | uint8_t *dptr1, *dptr2; |
| 5115 | uint32_t chksum; |
| 5116 | uint16_t cnt; |
| 5117 | struct qla_hw_data *ha = vha->hw; |
| 5118 | |
| 5119 | rval = QLA_SUCCESS; |
| 5120 | icb = (struct init_cb_81xx *)ha->init_cb; |
| 5121 | nv = ha->nvram; |
| 5122 | |
| 5123 | /* Determine NVRAM starting address. */ |
| 5124 | ha->nvram_size = sizeof(struct nvram_81xx); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5125 | ha->vpd_size = FA_NVRAM_VPD_SIZE; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5126 | |
| 5127 | /* Get VPD data into cache */ |
| 5128 | ha->vpd = ha->nvram + VPD_OFFSET; |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5129 | ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2, |
| 5130 | ha->vpd_size); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5131 | |
| 5132 | /* Get NVRAM data into cache and calculate checksum. */ |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5133 | 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] | 5134 | ha->nvram_size); |
Andrew Vasquez | 3d79038f | 2009-03-24 09:08:14 -0700 | [diff] [blame] | 5135 | dptr = (uint32_t *)nv; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5136 | for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++) |
| 5137 | chksum += le32_to_cpu(*dptr++); |
| 5138 | |
Andrew Vasquez | 7640335 | 2009-04-06 22:33:39 -0700 | [diff] [blame] | 5139 | DEBUG5(printk("scsi(%ld): Contents of NVRAM\n", vha->host_no)); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5140 | DEBUG5(qla2x00_dump_buffer((uint8_t *)nv, ha->nvram_size)); |
| 5141 | |
| 5142 | /* Bad NVRAM data, set defaults parameters. */ |
| 5143 | if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P' |
| 5144 | || nv->id[3] != ' ' || |
| 5145 | nv->nvram_version < __constant_cpu_to_le16(ICB_VERSION)) { |
| 5146 | /* Reset NVRAM data. */ |
| 5147 | qla_printk(KERN_WARNING, ha, "Inconsistent NVRAM detected: " |
| 5148 | "checksum=0x%x id=%c version=0x%x.\n", chksum, nv->id[0], |
| 5149 | le16_to_cpu(nv->nvram_version)); |
| 5150 | qla_printk(KERN_WARNING, ha, "Falling back to functioning (yet " |
| 5151 | "invalid -- WWPN) defaults.\n"); |
| 5152 | |
| 5153 | /* |
| 5154 | * Set default initialization control block. |
| 5155 | */ |
| 5156 | memset(nv, 0, ha->nvram_size); |
| 5157 | nv->nvram_version = __constant_cpu_to_le16(ICB_VERSION); |
| 5158 | nv->version = __constant_cpu_to_le16(ICB_VERSION); |
| 5159 | nv->frame_payload_size = __constant_cpu_to_le16(2048); |
| 5160 | nv->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5161 | nv->exchange_count = __constant_cpu_to_le16(0); |
| 5162 | nv->port_name[0] = 0x21; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5163 | nv->port_name[1] = 0x00 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5164 | nv->port_name[2] = 0x00; |
| 5165 | nv->port_name[3] = 0xe0; |
| 5166 | nv->port_name[4] = 0x8b; |
| 5167 | nv->port_name[5] = 0x1c; |
| 5168 | nv->port_name[6] = 0x55; |
| 5169 | nv->port_name[7] = 0x86; |
| 5170 | nv->node_name[0] = 0x20; |
| 5171 | nv->node_name[1] = 0x00; |
| 5172 | nv->node_name[2] = 0x00; |
| 5173 | nv->node_name[3] = 0xe0; |
| 5174 | nv->node_name[4] = 0x8b; |
| 5175 | nv->node_name[5] = 0x1c; |
| 5176 | nv->node_name[6] = 0x55; |
| 5177 | nv->node_name[7] = 0x86; |
| 5178 | nv->login_retry_count = __constant_cpu_to_le16(8); |
| 5179 | nv->interrupt_delay_timer = __constant_cpu_to_le16(0); |
| 5180 | nv->login_timeout = __constant_cpu_to_le16(0); |
| 5181 | nv->firmware_options_1 = |
| 5182 | __constant_cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1); |
| 5183 | nv->firmware_options_2 = __constant_cpu_to_le32(2 << 4); |
| 5184 | nv->firmware_options_2 |= __constant_cpu_to_le32(BIT_12); |
| 5185 | nv->firmware_options_3 = __constant_cpu_to_le32(2 << 13); |
| 5186 | nv->host_p = __constant_cpu_to_le32(BIT_11|BIT_10); |
| 5187 | nv->efi_parameters = __constant_cpu_to_le32(0); |
| 5188 | nv->reset_delay = 5; |
| 5189 | nv->max_luns_per_target = __constant_cpu_to_le16(128); |
| 5190 | nv->port_down_retry_count = __constant_cpu_to_le16(30); |
| 5191 | nv->link_down_timeout = __constant_cpu_to_le16(30); |
Andrew Vasquez | eeebcc9 | 2009-06-03 09:55:24 -0700 | [diff] [blame] | 5192 | nv->enode_mac[0] = 0x00; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5193 | nv->enode_mac[1] = 0x02; |
| 5194 | nv->enode_mac[2] = 0x03; |
| 5195 | nv->enode_mac[3] = 0x04; |
| 5196 | nv->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5197 | nv->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5198 | |
| 5199 | rval = 1; |
| 5200 | } |
| 5201 | |
| 5202 | /* Reset Initialization control block */ |
| 5203 | memset(icb, 0, sizeof(struct init_cb_81xx)); |
| 5204 | |
| 5205 | /* Copy 1st segment. */ |
| 5206 | dptr1 = (uint8_t *)icb; |
| 5207 | dptr2 = (uint8_t *)&nv->version; |
| 5208 | cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version; |
| 5209 | while (cnt--) |
| 5210 | *dptr1++ = *dptr2++; |
| 5211 | |
| 5212 | icb->login_retry_count = nv->login_retry_count; |
| 5213 | |
| 5214 | /* Copy 2nd segment. */ |
| 5215 | dptr1 = (uint8_t *)&icb->interrupt_delay_timer; |
| 5216 | dptr2 = (uint8_t *)&nv->interrupt_delay_timer; |
| 5217 | cnt = (uint8_t *)&icb->reserved_5 - |
| 5218 | (uint8_t *)&icb->interrupt_delay_timer; |
| 5219 | while (cnt--) |
| 5220 | *dptr1++ = *dptr2++; |
| 5221 | |
| 5222 | memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac)); |
| 5223 | /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */ |
| 5224 | if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) { |
| 5225 | icb->enode_mac[0] = 0x01; |
| 5226 | icb->enode_mac[1] = 0x02; |
| 5227 | icb->enode_mac[2] = 0x03; |
| 5228 | icb->enode_mac[3] = 0x04; |
| 5229 | icb->enode_mac[4] = 0x05; |
Anirban Chakraborty | e5b68a6 | 2009-04-06 22:33:50 -0700 | [diff] [blame] | 5230 | icb->enode_mac[5] = 0x06 + ha->port_no; |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5231 | } |
| 5232 | |
Andrew Vasquez | b64b0e8 | 2009-03-24 09:08:01 -0700 | [diff] [blame] | 5233 | /* Use extended-initialization control block. */ |
| 5234 | memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb)); |
| 5235 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5236 | /* |
| 5237 | * Setup driver NVRAM options. |
| 5238 | */ |
| 5239 | qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name), |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5240 | "QLE8XXX"); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5241 | |
| 5242 | /* Use alternate WWN? */ |
| 5243 | if (nv->host_p & __constant_cpu_to_le32(BIT_15)) { |
| 5244 | memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE); |
| 5245 | memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE); |
| 5246 | } |
| 5247 | |
| 5248 | /* Prepare nodename */ |
| 5249 | if ((icb->firmware_options_1 & __constant_cpu_to_le32(BIT_14)) == 0) { |
| 5250 | /* |
| 5251 | * Firmware will apply the following mask if the nodename was |
| 5252 | * not provided. |
| 5253 | */ |
| 5254 | memcpy(icb->node_name, icb->port_name, WWN_SIZE); |
| 5255 | icb->node_name[0] &= 0xF0; |
| 5256 | } |
| 5257 | |
| 5258 | /* Set host adapter parameters. */ |
| 5259 | ha->flags.disable_risc_code_load = 0; |
| 5260 | ha->flags.enable_lip_reset = 0; |
| 5261 | ha->flags.enable_lip_full_login = |
| 5262 | le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0; |
| 5263 | ha->flags.enable_target_reset = |
| 5264 | le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0; |
| 5265 | ha->flags.enable_led_scheme = 0; |
| 5266 | ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0; |
| 5267 | |
| 5268 | ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) & |
| 5269 | (BIT_6 | BIT_5 | BIT_4)) >> 4; |
| 5270 | |
| 5271 | /* save HBA serial number */ |
| 5272 | ha->serial0 = icb->port_name[5]; |
| 5273 | ha->serial1 = icb->port_name[6]; |
| 5274 | ha->serial2 = icb->port_name[7]; |
| 5275 | memcpy(vha->node_name, icb->node_name, WWN_SIZE); |
| 5276 | memcpy(vha->port_name, icb->port_name, WWN_SIZE); |
| 5277 | |
| 5278 | icb->execution_throttle = __constant_cpu_to_le16(0xFFFF); |
| 5279 | |
| 5280 | ha->retry_count = le16_to_cpu(nv->login_retry_count); |
| 5281 | |
| 5282 | /* Set minimum login_timeout to 4 seconds. */ |
| 5283 | if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout) |
| 5284 | nv->login_timeout = cpu_to_le16(ql2xlogintimeout); |
| 5285 | if (le16_to_cpu(nv->login_timeout) < 4) |
| 5286 | nv->login_timeout = __constant_cpu_to_le16(4); |
| 5287 | ha->login_timeout = le16_to_cpu(nv->login_timeout); |
| 5288 | icb->login_timeout = nv->login_timeout; |
| 5289 | |
| 5290 | /* Set minimum RATOV to 100 tenths of a second. */ |
| 5291 | ha->r_a_tov = 100; |
| 5292 | |
| 5293 | ha->loop_reset_delay = nv->reset_delay; |
| 5294 | |
| 5295 | /* Link Down Timeout = 0: |
| 5296 | * |
| 5297 | * When Port Down timer expires we will start returning |
| 5298 | * I/O's to OS with "DID_NO_CONNECT". |
| 5299 | * |
| 5300 | * Link Down Timeout != 0: |
| 5301 | * |
| 5302 | * The driver waits for the link to come up after link down |
| 5303 | * before returning I/Os to OS with "DID_NO_CONNECT". |
| 5304 | */ |
| 5305 | if (le16_to_cpu(nv->link_down_timeout) == 0) { |
| 5306 | ha->loop_down_abort_time = |
| 5307 | (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT); |
| 5308 | } else { |
| 5309 | ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout); |
| 5310 | ha->loop_down_abort_time = |
| 5311 | (LOOP_DOWN_TIME - ha->link_down_timeout); |
| 5312 | } |
| 5313 | |
| 5314 | /* Need enough time to try and get the port back. */ |
| 5315 | ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count); |
| 5316 | if (qlport_down_retry) |
| 5317 | ha->port_down_retry_count = qlport_down_retry; |
| 5318 | |
| 5319 | /* Set login_retry_count */ |
| 5320 | ha->login_retry_count = le16_to_cpu(nv->login_retry_count); |
| 5321 | if (ha->port_down_retry_count == |
| 5322 | le16_to_cpu(nv->port_down_retry_count) && |
| 5323 | ha->port_down_retry_count > 3) |
| 5324 | ha->login_retry_count = ha->port_down_retry_count; |
| 5325 | else if (ha->port_down_retry_count > (int)ha->login_retry_count) |
| 5326 | ha->login_retry_count = ha->port_down_retry_count; |
| 5327 | if (ql2xloginretrycount) |
| 5328 | ha->login_retry_count = ql2xloginretrycount; |
| 5329 | |
| 5330 | /* Enable ZIO. */ |
| 5331 | if (!vha->flags.init_done) { |
| 5332 | ha->zio_mode = le32_to_cpu(icb->firmware_options_2) & |
| 5333 | (BIT_3 | BIT_2 | BIT_1 | BIT_0); |
| 5334 | ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ? |
| 5335 | le16_to_cpu(icb->interrupt_delay_timer): 2; |
| 5336 | } |
| 5337 | icb->firmware_options_2 &= __constant_cpu_to_le32( |
| 5338 | ~(BIT_3 | BIT_2 | BIT_1 | BIT_0)); |
| 5339 | vha->flags.process_response_queue = 0; |
| 5340 | if (ha->zio_mode != QLA_ZIO_DISABLED) { |
| 5341 | ha->zio_mode = QLA_ZIO_MODE_6; |
| 5342 | |
| 5343 | DEBUG2(printk("scsi(%ld): ZIO mode %d enabled; timer delay " |
| 5344 | "(%d us).\n", vha->host_no, ha->zio_mode, |
| 5345 | ha->zio_timer * 100)); |
| 5346 | qla_printk(KERN_INFO, ha, |
| 5347 | "ZIO mode %d enabled; timer delay (%d us).\n", |
| 5348 | ha->zio_mode, ha->zio_timer * 100); |
| 5349 | |
| 5350 | icb->firmware_options_2 |= cpu_to_le32( |
| 5351 | (uint32_t)ha->zio_mode); |
| 5352 | icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer); |
| 5353 | vha->flags.process_response_queue = 1; |
| 5354 | } |
| 5355 | |
| 5356 | if (rval) { |
| 5357 | DEBUG2_3(printk(KERN_WARNING |
| 5358 | "scsi(%ld): NVRAM configuration failed!\n", vha->host_no)); |
| 5359 | } |
| 5360 | return (rval); |
| 5361 | } |
| 5362 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5363 | int |
| 5364 | qla82xx_restart_isp(scsi_qla_host_t *vha) |
| 5365 | { |
| 5366 | int status, rval; |
| 5367 | uint32_t wait_time; |
| 5368 | struct qla_hw_data *ha = vha->hw; |
| 5369 | struct req_que *req = ha->req_q_map[0]; |
| 5370 | struct rsp_que *rsp = ha->rsp_q_map[0]; |
| 5371 | struct scsi_qla_host *vp; |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5372 | unsigned long flags; |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5373 | |
| 5374 | status = qla2x00_init_rings(vha); |
| 5375 | if (!status) { |
| 5376 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5377 | ha->flags.chip_reset_done = 1; |
| 5378 | |
| 5379 | status = qla2x00_fw_ready(vha); |
| 5380 | if (!status) { |
| 5381 | qla_printk(KERN_INFO, ha, |
| 5382 | "%s(): Start configure loop, " |
| 5383 | "status = %d\n", __func__, status); |
| 5384 | |
| 5385 | /* Issue a marker after FW becomes ready. */ |
| 5386 | qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL); |
| 5387 | |
| 5388 | vha->flags.online = 1; |
| 5389 | /* Wait at most MAX_TARGET RSCNs for a stable link. */ |
| 5390 | wait_time = 256; |
| 5391 | do { |
| 5392 | clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags); |
| 5393 | qla2x00_configure_loop(vha); |
| 5394 | wait_time--; |
| 5395 | } while (!atomic_read(&vha->loop_down_timer) && |
| 5396 | !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags)) && |
| 5397 | wait_time && |
| 5398 | (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))); |
| 5399 | } |
| 5400 | |
| 5401 | /* if no cable then assume it's good */ |
| 5402 | if ((vha->device_flags & DFLG_NO_CABLE)) |
| 5403 | status = 0; |
| 5404 | |
| 5405 | qla_printk(KERN_INFO, ha, |
| 5406 | "%s(): Configure loop done, status = 0x%x\n", |
| 5407 | __func__, status); |
| 5408 | } |
| 5409 | |
| 5410 | if (!status) { |
| 5411 | clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags); |
| 5412 | |
| 5413 | if (!atomic_read(&vha->loop_down_timer)) { |
| 5414 | /* |
| 5415 | * Issue marker command only when we are going |
| 5416 | * to start the I/O . |
| 5417 | */ |
| 5418 | vha->marker_needed = 1; |
| 5419 | } |
| 5420 | |
| 5421 | vha->flags.online = 1; |
| 5422 | |
| 5423 | ha->isp_ops->enable_intrs(ha); |
| 5424 | |
| 5425 | ha->isp_abort_cnt = 0; |
| 5426 | clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags); |
| 5427 | |
| 5428 | if (ha->fce) { |
| 5429 | ha->flags.fce_enabled = 1; |
| 5430 | memset(ha->fce, 0, |
| 5431 | fce_calc_size(ha->fce_bufs)); |
| 5432 | rval = qla2x00_enable_fce_trace(vha, |
| 5433 | ha->fce_dma, ha->fce_bufs, ha->fce_mb, |
| 5434 | &ha->fce_bufs); |
| 5435 | if (rval) { |
| 5436 | qla_printk(KERN_WARNING, ha, |
| 5437 | "Unable to reinitialize FCE " |
| 5438 | "(%d).\n", rval); |
| 5439 | ha->flags.fce_enabled = 0; |
| 5440 | } |
| 5441 | } |
| 5442 | |
| 5443 | if (ha->eft) { |
| 5444 | memset(ha->eft, 0, EFT_SIZE); |
| 5445 | rval = qla2x00_enable_eft_trace(vha, |
| 5446 | ha->eft_dma, EFT_NUM_BUFFERS); |
| 5447 | if (rval) { |
| 5448 | qla_printk(KERN_WARNING, ha, |
| 5449 | "Unable to reinitialize EFT " |
| 5450 | "(%d).\n", rval); |
| 5451 | } |
| 5452 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5453 | } |
| 5454 | |
| 5455 | if (!status) { |
| 5456 | DEBUG(printk(KERN_INFO |
| 5457 | "qla82xx_restart_isp(%ld): succeeded.\n", |
| 5458 | vha->host_no)); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5459 | |
| 5460 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5461 | list_for_each_entry(vp, &ha->vp_list, list) { |
| 5462 | if (vp->vp_idx) { |
| 5463 | atomic_inc(&vp->vref_count); |
| 5464 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5465 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5466 | qla2x00_vp_abort_isp(vp); |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5467 | |
| 5468 | spin_lock_irqsave(&ha->vport_slock, flags); |
| 5469 | atomic_dec(&vp->vref_count); |
| 5470 | } |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5471 | } |
Arun Easi | feafb7b | 2010-09-03 14:57:00 -0700 | [diff] [blame] | 5472 | spin_unlock_irqrestore(&ha->vport_slock, flags); |
| 5473 | |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 5474 | } else { |
| 5475 | qla_printk(KERN_INFO, ha, |
| 5476 | "qla82xx_restart_isp: **** FAILED ****\n"); |
| 5477 | } |
| 5478 | |
| 5479 | return status; |
| 5480 | } |
| 5481 | |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5482 | void |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5483 | qla81xx_update_fw_options(scsi_qla_host_t *vha) |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5484 | { |
Andrew Vasquez | ae97c91 | 2010-02-18 10:07:28 -0800 | [diff] [blame] | 5485 | struct qla_hw_data *ha = vha->hw; |
| 5486 | |
| 5487 | if (!ql2xetsenable) |
| 5488 | return; |
| 5489 | |
| 5490 | /* Enable ETS Burst. */ |
| 5491 | memset(ha->fw_options, 0, sizeof(ha->fw_options)); |
| 5492 | ha->fw_options[2] |= BIT_9; |
| 5493 | qla2x00_set_fw_options(vha, ha->fw_options); |
Andrew Vasquez | 3a03eb7 | 2009-01-05 11:18:11 -0800 | [diff] [blame] | 5494 | } |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5495 | |
| 5496 | /* |
| 5497 | * qla24xx_get_fcp_prio |
| 5498 | * Gets the fcp cmd priority value for the logged in port. |
| 5499 | * Looks for a match of the port descriptors within |
| 5500 | * each of the fcp prio config entries. If a match is found, |
| 5501 | * the tag (priority) value is returned. |
| 5502 | * |
| 5503 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5504 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5505 | * fcport = port structure pointer. |
| 5506 | * |
| 5507 | * Return: |
Andrew Vasquez | 6c452a4 | 2010-03-19 17:04:02 -0700 | [diff] [blame] | 5508 | * non-zero (if found) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5509 | * 0 (if not found) |
| 5510 | * |
| 5511 | * Context: |
| 5512 | * Kernel context |
| 5513 | */ |
| 5514 | uint8_t |
| 5515 | qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport) |
| 5516 | { |
| 5517 | int i, entries; |
| 5518 | uint8_t pid_match, wwn_match; |
| 5519 | uint8_t priority; |
| 5520 | uint32_t pid1, pid2; |
| 5521 | uint64_t wwn1, wwn2; |
| 5522 | struct qla_fcp_prio_entry *pri_entry; |
| 5523 | struct qla_hw_data *ha = vha->hw; |
| 5524 | |
| 5525 | if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled) |
| 5526 | return 0; |
| 5527 | |
| 5528 | priority = 0; |
| 5529 | entries = ha->fcp_prio_cfg->num_entries; |
| 5530 | pri_entry = &ha->fcp_prio_cfg->entry[0]; |
| 5531 | |
| 5532 | for (i = 0; i < entries; i++) { |
| 5533 | pid_match = wwn_match = 0; |
| 5534 | |
| 5535 | if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) { |
| 5536 | pri_entry++; |
| 5537 | continue; |
| 5538 | } |
| 5539 | |
| 5540 | /* check source pid for a match */ |
| 5541 | if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) { |
| 5542 | pid1 = pri_entry->src_pid & INVALID_PORT_ID; |
| 5543 | pid2 = vha->d_id.b24 & INVALID_PORT_ID; |
| 5544 | if (pid1 == INVALID_PORT_ID) |
| 5545 | pid_match++; |
| 5546 | else if (pid1 == pid2) |
| 5547 | pid_match++; |
| 5548 | } |
| 5549 | |
| 5550 | /* check destination pid for a match */ |
| 5551 | if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) { |
| 5552 | pid1 = pri_entry->dst_pid & INVALID_PORT_ID; |
| 5553 | pid2 = fcport->d_id.b24 & INVALID_PORT_ID; |
| 5554 | if (pid1 == INVALID_PORT_ID) |
| 5555 | pid_match++; |
| 5556 | else if (pid1 == pid2) |
| 5557 | pid_match++; |
| 5558 | } |
| 5559 | |
| 5560 | /* check source WWN for a match */ |
| 5561 | if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) { |
| 5562 | wwn1 = wwn_to_u64(vha->port_name); |
| 5563 | wwn2 = wwn_to_u64(pri_entry->src_wwpn); |
| 5564 | if (wwn2 == (uint64_t)-1) |
| 5565 | wwn_match++; |
| 5566 | else if (wwn1 == wwn2) |
| 5567 | wwn_match++; |
| 5568 | } |
| 5569 | |
| 5570 | /* check destination WWN for a match */ |
| 5571 | if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) { |
| 5572 | wwn1 = wwn_to_u64(fcport->port_name); |
| 5573 | wwn2 = wwn_to_u64(pri_entry->dst_wwpn); |
| 5574 | if (wwn2 == (uint64_t)-1) |
| 5575 | wwn_match++; |
| 5576 | else if (wwn1 == wwn2) |
| 5577 | wwn_match++; |
| 5578 | } |
| 5579 | |
| 5580 | if (pid_match == 2 || wwn_match == 2) { |
| 5581 | /* Found a matching entry */ |
| 5582 | if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID) |
| 5583 | priority = pri_entry->tag; |
| 5584 | break; |
| 5585 | } |
| 5586 | |
| 5587 | pri_entry++; |
| 5588 | } |
| 5589 | |
| 5590 | return priority; |
| 5591 | } |
| 5592 | |
| 5593 | /* |
| 5594 | * qla24xx_update_fcport_fcp_prio |
| 5595 | * Activates fcp priority for the logged in fc port |
| 5596 | * |
| 5597 | * Input: |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5598 | * vha = scsi host structure pointer. |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5599 | * fcp = port structure pointer. |
| 5600 | * |
| 5601 | * Return: |
| 5602 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5603 | * |
| 5604 | * Context: |
| 5605 | * Kernel context. |
| 5606 | */ |
| 5607 | int |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5608 | 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] | 5609 | { |
| 5610 | int ret; |
| 5611 | uint8_t priority; |
| 5612 | uint16_t mb[5]; |
| 5613 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5614 | if (fcport->port_type != FCT_TARGET || |
| 5615 | fcport->loop_id == FC_NO_LOOP_ID) |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5616 | return QLA_FUNCTION_FAILED; |
| 5617 | |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5618 | priority = qla24xx_get_fcp_prio(vha, fcport); |
| 5619 | ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5620 | if (ret == QLA_SUCCESS) |
| 5621 | fcport->fcp_prio = priority; |
| 5622 | else |
| 5623 | DEBUG2(printk(KERN_WARNING |
| 5624 | "scsi(%ld): Unable to activate fcp priority, " |
Madhuranath Iyengar | 21090cb | 2010-12-21 16:00:18 -0800 | [diff] [blame] | 5625 | " ret=0x%x\n", vha->host_no, ret)); |
Sarang Radke | 09ff701 | 2010-03-19 17:03:59 -0700 | [diff] [blame] | 5626 | |
| 5627 | return ret; |
| 5628 | } |
| 5629 | |
| 5630 | /* |
| 5631 | * qla24xx_update_all_fcp_prio |
| 5632 | * Activates fcp priority for all the logged in ports |
| 5633 | * |
| 5634 | * Input: |
| 5635 | * ha = adapter block pointer. |
| 5636 | * |
| 5637 | * Return: |
| 5638 | * QLA_SUCCESS or QLA_FUNCTION_FAILED |
| 5639 | * |
| 5640 | * Context: |
| 5641 | * Kernel context. |
| 5642 | */ |
| 5643 | int |
| 5644 | qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha) |
| 5645 | { |
| 5646 | int ret; |
| 5647 | fc_port_t *fcport; |
| 5648 | |
| 5649 | ret = QLA_FUNCTION_FAILED; |
| 5650 | /* We need to set priority for all logged in ports */ |
| 5651 | list_for_each_entry(fcport, &vha->vp_fcports, list) |
| 5652 | ret = qla24xx_update_fcport_fcp_prio(vha, fcport); |
| 5653 | |
| 5654 | return ret; |
| 5655 | } |