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