Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
Armen Baloyan | bd21eaf | 2014-04-11 16:54:24 -0400 | [diff] [blame] | 3 | * Copyright (c) 2003-2014 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. |
| 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "qla_def.h" |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 8 | #include "qla_target.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
| 10 | #include <linux/blkdev.h> |
| 11 | #include <linux/delay.h> |
| 12 | |
| 13 | #include <scsi/scsi_tcq.h> |
| 14 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | /** |
| 16 | * qla2x00_get_cmd_direction() - Determine control_flag data direction. |
| 17 | * @cmd: SCSI command |
| 18 | * |
| 19 | * Returns the proper CF_* direction based on CDB. |
| 20 | */ |
| 21 | static inline uint16_t |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 22 | qla2x00_get_cmd_direction(srb_t *sp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | { |
| 24 | uint16_t cflags; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 25 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 26 | struct scsi_qla_host *vha = sp->vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | cflags = 0; |
| 29 | |
| 30 | /* Set transfer direction */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 31 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | cflags = CF_WRITE; |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 33 | vha->qla_stats.output_bytes += scsi_bufflen(cmd); |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 34 | vha->qla_stats.output_requests++; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 35 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | cflags = CF_READ; |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 37 | vha->qla_stats.input_bytes += scsi_bufflen(cmd); |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 38 | vha->qla_stats.input_requests++; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 39 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | return (cflags); |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and |
| 45 | * Continuation Type 0 IOCBs to allocate. |
| 46 | * |
| 47 | * @dsds: number of data segment decriptors needed |
| 48 | * |
| 49 | * Returns the number of IOCB entries needed to store @dsds. |
| 50 | */ |
| 51 | uint16_t |
| 52 | qla2x00_calc_iocbs_32(uint16_t dsds) |
| 53 | { |
| 54 | uint16_t iocbs; |
| 55 | |
| 56 | iocbs = 1; |
| 57 | if (dsds > 3) { |
| 58 | iocbs += (dsds - 3) / 7; |
| 59 | if ((dsds - 3) % 7) |
| 60 | iocbs++; |
| 61 | } |
| 62 | return (iocbs); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and |
| 67 | * Continuation Type 1 IOCBs to allocate. |
| 68 | * |
| 69 | * @dsds: number of data segment decriptors needed |
| 70 | * |
| 71 | * Returns the number of IOCB entries needed to store @dsds. |
| 72 | */ |
| 73 | uint16_t |
| 74 | qla2x00_calc_iocbs_64(uint16_t dsds) |
| 75 | { |
| 76 | uint16_t iocbs; |
| 77 | |
| 78 | iocbs = 1; |
| 79 | if (dsds > 2) { |
| 80 | iocbs += (dsds - 2) / 5; |
| 81 | if ((dsds - 2) % 5) |
| 82 | iocbs++; |
| 83 | } |
| 84 | return (iocbs); |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB. |
| 89 | * @ha: HA context |
| 90 | * |
| 91 | * Returns a pointer to the Continuation Type 0 IOCB packet. |
| 92 | */ |
| 93 | static inline cont_entry_t * |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 94 | qla2x00_prep_cont_type0_iocb(struct scsi_qla_host *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | cont_entry_t *cont_pkt; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 97 | struct req_que *req = vha->req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 99 | req->ring_index++; |
| 100 | if (req->ring_index == req->length) { |
| 101 | req->ring_index = 0; |
| 102 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 104 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | } |
| 106 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 107 | cont_pkt = (cont_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | /* Load packet defaults. */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 110 | *((uint32_t *)(&cont_pkt->entry_type)) = cpu_to_le32(CONTINUE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | return (cont_pkt); |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB. |
| 117 | * @ha: HA context |
| 118 | * |
| 119 | * Returns a pointer to the continuation type 1 IOCB packet. |
| 120 | */ |
| 121 | static inline cont_a64_entry_t * |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 122 | qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *vha, struct req_que *req) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | { |
| 124 | cont_a64_entry_t *cont_pkt; |
| 125 | |
| 126 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 127 | req->ring_index++; |
| 128 | if (req->ring_index == req->length) { |
| 129 | req->ring_index = 0; |
| 130 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 132 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | } |
| 134 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 135 | cont_pkt = (cont_a64_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | |
| 137 | /* Load packet defaults. */ |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 138 | *((uint32_t *)(&cont_pkt->entry_type)) = IS_QLAFX00(vha->hw) ? |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 139 | cpu_to_le32(CONTINUE_A64_TYPE_FX00) : |
| 140 | cpu_to_le32(CONTINUE_A64_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | return (cont_pkt); |
| 143 | } |
| 144 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 145 | inline int |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 146 | qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts) |
| 147 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 148 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
| 149 | uint8_t guard = scsi_host_get_guard(cmd->device->host); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 150 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 151 | /* We always use DIFF Bundling for best performance */ |
| 152 | *fw_prot_opts = 0; |
| 153 | |
| 154 | /* Translate SCSI opcode to a protection opcode */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 155 | switch (scsi_get_prot_op(cmd)) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 156 | case SCSI_PROT_READ_STRIP: |
| 157 | *fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 158 | break; |
| 159 | case SCSI_PROT_WRITE_INSERT: |
| 160 | *fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 161 | break; |
| 162 | case SCSI_PROT_READ_INSERT: |
| 163 | *fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 164 | break; |
| 165 | case SCSI_PROT_WRITE_STRIP: |
| 166 | *fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 167 | break; |
| 168 | case SCSI_PROT_READ_PASS: |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 169 | case SCSI_PROT_WRITE_PASS: |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 170 | if (guard & SHOST_DIX_GUARD_IP) |
| 171 | *fw_prot_opts |= PO_MODE_DIF_TCP_CKSUM; |
| 172 | else |
| 173 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 174 | break; |
| 175 | default: /* Normal Request */ |
| 176 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
| 177 | break; |
| 178 | } |
| 179 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 180 | return scsi_prot_sg_count(cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit |
| 185 | * capable IOCB types. |
| 186 | * |
| 187 | * @sp: SRB command to process |
| 188 | * @cmd_pkt: Command type 2 IOCB |
| 189 | * @tot_dsds: Total number of segments to transfer |
| 190 | */ |
| 191 | void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 192 | uint16_t tot_dsds) |
| 193 | { |
| 194 | uint16_t avail_dsds; |
| 195 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 196 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 198 | struct scatterlist *sg; |
| 199 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 201 | cmd = GET_CMD_SP(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
| 203 | /* Update entry type to indicate Command Type 2 IOCB */ |
| 204 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 205 | cpu_to_le32(COMMAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 208 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 209 | cmd_pkt->byte_count = cpu_to_le32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | return; |
| 211 | } |
| 212 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 213 | vha = sp->vha; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 214 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
| 216 | /* Three DSDs are available in the Command Type 2 IOCB */ |
| 217 | avail_dsds = 3; |
| 218 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 219 | |
| 220 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 221 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 222 | cont_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 224 | /* Allocate additional continuation packets? */ |
| 225 | if (avail_dsds == 0) { |
| 226 | /* |
| 227 | * Seven DSDs are available in the Continuation |
| 228 | * Type 0 IOCB. |
| 229 | */ |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 230 | cont_pkt = qla2x00_prep_cont_type0_iocb(vha); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 231 | cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address; |
| 232 | avail_dsds = 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 234 | |
| 235 | *cur_dsd++ = cpu_to_le32(sg_dma_address(sg)); |
| 236 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 237 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | |
| 241 | /** |
| 242 | * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit |
| 243 | * capable IOCB types. |
| 244 | * |
| 245 | * @sp: SRB command to process |
| 246 | * @cmd_pkt: Command type 3 IOCB |
| 247 | * @tot_dsds: Total number of segments to transfer |
| 248 | */ |
| 249 | void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 250 | uint16_t tot_dsds) |
| 251 | { |
| 252 | uint16_t avail_dsds; |
| 253 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 254 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 256 | struct scatterlist *sg; |
| 257 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 259 | cmd = GET_CMD_SP(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | |
| 261 | /* Update entry type to indicate Command Type 3 IOCB */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 262 | *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_A64_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | |
| 264 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 265 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 266 | cmd_pkt->byte_count = cpu_to_le32(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | return; |
| 268 | } |
| 269 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 270 | vha = sp->vha; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 271 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | |
| 273 | /* Two DSDs are available in the Command Type 3 IOCB */ |
| 274 | avail_dsds = 2; |
| 275 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 276 | |
| 277 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 278 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 279 | dma_addr_t sle_dma; |
| 280 | cont_a64_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 282 | /* Allocate additional continuation packets? */ |
| 283 | if (avail_dsds == 0) { |
| 284 | /* |
| 285 | * Five DSDs are available in the Continuation |
| 286 | * Type 1 IOCB. |
| 287 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 288 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 289 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 290 | avail_dsds = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 292 | |
| 293 | sle_dma = sg_dma_address(sg); |
| 294 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 295 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 296 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 297 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } |
| 299 | } |
| 300 | |
| 301 | /** |
| 302 | * qla2x00_start_scsi() - Send a SCSI command to the ISP |
| 303 | * @sp: command to send to the ISP |
| 304 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 305 | * Returns non-zero if a failure occurred, else zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | */ |
| 307 | int |
| 308 | qla2x00_start_scsi(srb_t *sp) |
| 309 | { |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 310 | int nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 312 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | struct scsi_cmnd *cmd; |
| 314 | uint32_t *clr_ptr; |
| 315 | uint32_t index; |
| 316 | uint32_t handle; |
| 317 | cmd_entry_t *cmd_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | uint16_t cnt; |
| 319 | uint16_t req_cnt; |
| 320 | uint16_t tot_dsds; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 321 | struct device_reg_2xxx __iomem *reg; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 322 | struct qla_hw_data *ha; |
| 323 | struct req_que *req; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 324 | struct rsp_que *rsp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | |
| 326 | /* Setup device pointers. */ |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 327 | vha = sp->vha; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 328 | ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 329 | reg = &ha->iobase->isp; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 330 | cmd = GET_CMD_SP(sp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 331 | req = ha->req_q_map[0]; |
| 332 | rsp = ha->rsp_q_map[0]; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 333 | /* So we know we haven't pci_map'ed anything yet */ |
| 334 | tot_dsds = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | |
| 336 | /* Send marker if required */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 337 | if (vha->marker_needed != 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 338 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 339 | QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | return (QLA_FUNCTION_FAILED); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 341 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 342 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | } |
| 344 | |
| 345 | /* Acquire ring specific lock */ |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 346 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | |
| 348 | /* Check for room in outstanding command list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 349 | handle = req->current_outstanding_cmd; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 350 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | handle++; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 352 | if (handle == req->num_outstanding_cmds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | handle = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 354 | if (!req->outstanding_cmds[handle]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | break; |
| 356 | } |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 357 | if (index == req->num_outstanding_cmds) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | goto queuing_error; |
| 359 | |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 360 | /* Map the sg table so we have an accurate count of sg entries needed */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 361 | if (scsi_sg_count(cmd)) { |
| 362 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 363 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 364 | if (unlikely(!nseg)) |
| 365 | goto queuing_error; |
| 366 | } else |
| 367 | nseg = 0; |
| 368 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 369 | tot_dsds = nseg; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 370 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | /* Calculate the number of request entries needed. */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 372 | req_cnt = ha->isp_ops->calc_req_entries(tot_dsds); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 373 | if (req->cnt < (req_cnt + 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 375 | if (req->ring_index < cnt) |
| 376 | req->cnt = cnt - req->ring_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 378 | req->cnt = req->length - |
| 379 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 380 | /* If still no head room then bail out */ |
| 381 | if (req->cnt < (req_cnt + 2)) |
| 382 | goto queuing_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | /* Build command packet */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 386 | req->current_outstanding_cmd = handle; |
| 387 | req->outstanding_cmds[handle] = sp; |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 388 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 389 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 390 | req->cnt -= req_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 392 | cmd_pkt = (cmd_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | cmd_pkt->handle = handle; |
| 394 | /* Zero out remaining portion of packet. */ |
| 395 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 396 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 397 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 398 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 399 | /* Set target ID and LUN number*/ |
| 400 | SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 401 | cmd_pkt->lun = cpu_to_le16(cmd->device->lun); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 402 | cmd_pkt->control_flags = cpu_to_le16(CF_SIMPLE_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | /* Load SCSI command packet. */ |
| 405 | memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 406 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | |
| 408 | /* Build IOCB segments */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 409 | ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | |
| 411 | /* Set total data segment count. */ |
| 412 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 413 | wmb(); |
| 414 | |
| 415 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 416 | req->ring_index++; |
| 417 | if (req->ring_index == req->length) { |
| 418 | req->ring_index = 0; |
| 419 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 421 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | sp->flags |= SRB_DMA_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
| 425 | /* Set chip new ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 426 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), req->ring_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */ |
| 428 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 429 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 430 | if (vha->flags.process_response_queue && |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 431 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 432 | qla2x00_process_response_queue(rsp); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 433 | |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 434 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | return (QLA_SUCCESS); |
| 436 | |
| 437 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 438 | if (tot_dsds) |
| 439 | scsi_dma_unmap(cmd); |
| 440 | |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 441 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | |
| 443 | return (QLA_FUNCTION_FAILED); |
| 444 | } |
| 445 | |
| 446 | /** |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 447 | * qla2x00_start_iocbs() - Execute the IOCB command |
| 448 | */ |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 449 | void |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 450 | qla2x00_start_iocbs(struct scsi_qla_host *vha, struct req_que *req) |
| 451 | { |
| 452 | struct qla_hw_data *ha = vha->hw; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 453 | device_reg_t *reg = ISP_QUE_REG(ha, req->id); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 454 | |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 455 | if (IS_P3P_TYPE(ha)) { |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 456 | qla82xx_start_iocbs(vha); |
| 457 | } else { |
| 458 | /* Adjust ring index. */ |
| 459 | req->ring_index++; |
| 460 | if (req->ring_index == req->length) { |
| 461 | req->ring_index = 0; |
| 462 | req->ring_ptr = req->ring; |
| 463 | } else |
| 464 | req->ring_ptr++; |
| 465 | |
| 466 | /* Set chip new ring index. */ |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 467 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 468 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
Arun Easi | 98878a1 | 2012-02-09 11:15:59 -0800 | [diff] [blame] | 469 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 470 | } else if (IS_QLAFX00(ha)) { |
| 471 | WRT_REG_DWORD(®->ispfx00.req_q_in, req->ring_index); |
| 472 | RD_REG_DWORD_RELAXED(®->ispfx00.req_q_in); |
| 473 | QLAFX00_SET_HST_INTR(ha, ha->rqstq_intr_code); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 474 | } else if (IS_FWI2_CAPABLE(ha)) { |
| 475 | WRT_REG_DWORD(®->isp24.req_q_in, req->ring_index); |
| 476 | RD_REG_DWORD_RELAXED(®->isp24.req_q_in); |
| 477 | } else { |
| 478 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp), |
| 479 | req->ring_index); |
| 480 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp)); |
| 481 | } |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | * qla2x00_marker() - Send a marker IOCB to the firmware. |
| 487 | * @ha: HA context |
| 488 | * @loop_id: loop ID |
| 489 | * @lun: LUN |
| 490 | * @type: marker modifier |
| 491 | * |
| 492 | * Can be called from both normal and interrupt context. |
| 493 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 494 | * Returns non-zero if a failure occurred, else zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | */ |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 496 | static int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 497 | __qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req, |
| 498 | struct rsp_que *rsp, uint16_t loop_id, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 499 | uint64_t lun, uint8_t type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 501 | mrk_entry_t *mrk; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 502 | struct mrk_entry_24xx *mrk24 = NULL; |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 503 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 504 | struct qla_hw_data *ha = vha->hw; |
| 505 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | |
Giridhar Malavali | 99b8212 | 2011-11-18 09:03:17 -0800 | [diff] [blame] | 507 | req = ha->req_q_map[0]; |
Saurav Kashyap | fa49263 | 2012-11-21 02:40:29 -0500 | [diff] [blame] | 508 | mrk = (mrk_entry_t *)qla2x00_alloc_iocbs(vha, NULL); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 509 | if (mrk == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 510 | ql_log(ql_log_warn, base_vha, 0x3026, |
| 511 | "Failed to allocate Marker IOCB.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | |
| 513 | return (QLA_FUNCTION_FAILED); |
| 514 | } |
| 515 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 516 | mrk->entry_type = MARKER_TYPE; |
| 517 | mrk->modifier = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | if (type != MK_SYNC_ALL) { |
Armen Baloyan | bfd7334 | 2014-02-26 04:15:07 -0500 | [diff] [blame] | 519 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 520 | mrk24 = (struct mrk_entry_24xx *) mrk; |
| 521 | mrk24->nport_handle = cpu_to_le16(loop_id); |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 522 | int_to_scsilun(lun, (struct scsi_lun *)&mrk24->lun); |
Shyam Sundar | b797b6d | 2006-08-01 13:48:13 -0700 | [diff] [blame] | 523 | host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 524 | mrk24->vp_index = vha->vp_idx; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 525 | mrk24->handle = MAKE_HANDLE(req->id, mrk24->handle); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 526 | } else { |
| 527 | SET_TARGET_ID(ha, mrk->target, loop_id); |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 528 | mrk->lun = cpu_to_le16((uint16_t)lun); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 529 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | wmb(); |
| 532 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 533 | qla2x00_start_iocbs(vha, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | return (QLA_SUCCESS); |
| 536 | } |
| 537 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 538 | int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 539 | qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 540 | struct rsp_que *rsp, uint16_t loop_id, uint64_t lun, |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 541 | uint8_t type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | { |
| 543 | int ret; |
| 544 | unsigned long flags = 0; |
| 545 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 546 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 547 | ret = __qla2x00_marker(vha, req, rsp, loop_id, lun, type); |
| 548 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
| 550 | return (ret); |
| 551 | } |
| 552 | |
Nicholas Bellinger | 2d70c10 | 2012-05-15 14:34:28 -0400 | [diff] [blame] | 553 | /* |
| 554 | * qla2x00_issue_marker |
| 555 | * |
| 556 | * Issue marker |
| 557 | * Caller CAN have hardware lock held as specified by ha_locked parameter. |
| 558 | * Might release it, then reaquire. |
| 559 | */ |
| 560 | int qla2x00_issue_marker(scsi_qla_host_t *vha, int ha_locked) |
| 561 | { |
| 562 | if (ha_locked) { |
| 563 | if (__qla2x00_marker(vha, vha->req, vha->req->rsp, 0, 0, |
| 564 | MK_SYNC_ALL) != QLA_SUCCESS) |
| 565 | return QLA_FUNCTION_FAILED; |
| 566 | } else { |
| 567 | if (qla2x00_marker(vha, vha->req, vha->req->rsp, 0, 0, |
| 568 | MK_SYNC_ALL) != QLA_SUCCESS) |
| 569 | return QLA_FUNCTION_FAILED; |
| 570 | } |
| 571 | vha->marker_needed = 0; |
| 572 | |
| 573 | return QLA_SUCCESS; |
| 574 | } |
| 575 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 576 | static inline int |
| 577 | qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt, |
| 578 | uint16_t tot_dsds) |
| 579 | { |
| 580 | uint32_t *cur_dsd = NULL; |
| 581 | scsi_qla_host_t *vha; |
| 582 | struct qla_hw_data *ha; |
| 583 | struct scsi_cmnd *cmd; |
| 584 | struct scatterlist *cur_seg; |
| 585 | uint32_t *dsd_seg; |
| 586 | void *next_dsd; |
| 587 | uint8_t avail_dsds; |
| 588 | uint8_t first_iocb = 1; |
| 589 | uint32_t dsd_list_len; |
| 590 | struct dsd_dma *dsd_ptr; |
| 591 | struct ct6_dsd *ctx; |
| 592 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 593 | cmd = GET_CMD_SP(sp); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 594 | |
| 595 | /* Update entry type to indicate Command Type 3 IOCB */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 596 | *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_TYPE_6); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 597 | |
| 598 | /* No data transfer */ |
| 599 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 600 | cmd_pkt->byte_count = cpu_to_le32(0); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 601 | return 0; |
| 602 | } |
| 603 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 604 | vha = sp->vha; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 605 | ha = vha->hw; |
| 606 | |
| 607 | /* Set transfer direction */ |
| 608 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 609 | cmd_pkt->control_flags = cpu_to_le16(CF_WRITE_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 610 | vha->qla_stats.output_bytes += scsi_bufflen(cmd); |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 611 | vha->qla_stats.output_requests++; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 612 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 613 | cmd_pkt->control_flags = cpu_to_le16(CF_READ_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 614 | vha->qla_stats.input_bytes += scsi_bufflen(cmd); |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 615 | vha->qla_stats.input_requests++; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | cur_seg = scsi_sglist(cmd); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 619 | ctx = GET_CMD_CTX_SP(sp); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 620 | |
| 621 | while (tot_dsds) { |
| 622 | avail_dsds = (tot_dsds > QLA_DSDS_PER_IOCB) ? |
| 623 | QLA_DSDS_PER_IOCB : tot_dsds; |
| 624 | tot_dsds -= avail_dsds; |
| 625 | dsd_list_len = (avail_dsds + 1) * QLA_DSD_SIZE; |
| 626 | |
| 627 | dsd_ptr = list_first_entry(&ha->gbl_dsd_list, |
| 628 | struct dsd_dma, list); |
| 629 | next_dsd = dsd_ptr->dsd_addr; |
| 630 | list_del(&dsd_ptr->list); |
| 631 | ha->gbl_dsd_avail--; |
| 632 | list_add_tail(&dsd_ptr->list, &ctx->dsd_list); |
| 633 | ctx->dsd_use_cnt++; |
| 634 | ha->gbl_dsd_inuse++; |
| 635 | |
| 636 | if (first_iocb) { |
| 637 | first_iocb = 0; |
| 638 | dsd_seg = (uint32_t *)&cmd_pkt->fcp_data_dseg_address; |
| 639 | *dsd_seg++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 640 | *dsd_seg++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 641 | cmd_pkt->fcp_data_dseg_len = cpu_to_le32(dsd_list_len); |
| 642 | } else { |
| 643 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 644 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 645 | *cur_dsd++ = cpu_to_le32(dsd_list_len); |
| 646 | } |
| 647 | cur_dsd = (uint32_t *)next_dsd; |
| 648 | while (avail_dsds) { |
| 649 | dma_addr_t sle_dma; |
| 650 | |
| 651 | sle_dma = sg_dma_address(cur_seg); |
| 652 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 653 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 654 | *cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg)); |
| 655 | cur_seg = sg_next(cur_seg); |
| 656 | avail_dsds--; |
| 657 | } |
| 658 | } |
| 659 | |
| 660 | /* Null termination */ |
| 661 | *cur_dsd++ = 0; |
| 662 | *cur_dsd++ = 0; |
| 663 | *cur_dsd++ = 0; |
| 664 | cmd_pkt->control_flags |= CF_DATA_SEG_DESCR_ENABLE; |
| 665 | return 0; |
| 666 | } |
| 667 | |
| 668 | /* |
| 669 | * qla24xx_calc_dsd_lists() - Determine number of DSD list required |
| 670 | * for Command Type 6. |
| 671 | * |
| 672 | * @dsds: number of data segment decriptors needed |
| 673 | * |
| 674 | * Returns the number of dsd list needed to store @dsds. |
| 675 | */ |
Bart Van Assche | 2374dd2 | 2015-07-09 07:23:02 -0700 | [diff] [blame] | 676 | static inline uint16_t |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 677 | qla24xx_calc_dsd_lists(uint16_t dsds) |
| 678 | { |
| 679 | uint16_t dsd_lists = 0; |
| 680 | |
| 681 | dsd_lists = (dsds/QLA_DSDS_PER_IOCB); |
| 682 | if (dsds % QLA_DSDS_PER_IOCB) |
| 683 | dsd_lists++; |
| 684 | return dsd_lists; |
| 685 | } |
| 686 | |
| 687 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 688 | /** |
| 689 | * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7 |
| 690 | * IOCB types. |
| 691 | * |
| 692 | * @sp: SRB command to process |
| 693 | * @cmd_pkt: Command type 3 IOCB |
| 694 | * @tot_dsds: Total number of segments to transfer |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 695 | * @req: pointer to request queue |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 696 | */ |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 697 | inline void |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 698 | qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt, |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 699 | uint16_t tot_dsds, struct req_que *req) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 700 | { |
| 701 | uint16_t avail_dsds; |
| 702 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 703 | scsi_qla_host_t *vha; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 704 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 705 | struct scatterlist *sg; |
| 706 | int i; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 707 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 708 | cmd = GET_CMD_SP(sp); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 709 | |
| 710 | /* Update entry type to indicate Command Type 3 IOCB */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 711 | *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_TYPE_7); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 712 | |
| 713 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 714 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 715 | cmd_pkt->byte_count = cpu_to_le32(0); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 716 | return; |
| 717 | } |
| 718 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 719 | vha = sp->vha; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 720 | |
| 721 | /* Set transfer direction */ |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 722 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 723 | cmd_pkt->task_mgmt_flags = cpu_to_le16(TMF_WRITE_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 724 | vha->qla_stats.output_bytes += scsi_bufflen(cmd); |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 725 | vha->qla_stats.output_requests++; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 726 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 727 | cmd_pkt->task_mgmt_flags = cpu_to_le16(TMF_READ_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 728 | vha->qla_stats.input_bytes += scsi_bufflen(cmd); |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 729 | vha->qla_stats.input_requests++; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 730 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 731 | |
| 732 | /* One DSD is available in the Command Type 3 IOCB */ |
| 733 | avail_dsds = 1; |
| 734 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 735 | |
| 736 | /* Load data segments */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 737 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 738 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 739 | dma_addr_t sle_dma; |
| 740 | cont_a64_entry_t *cont_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 741 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 742 | /* Allocate additional continuation packets? */ |
| 743 | if (avail_dsds == 0) { |
| 744 | /* |
| 745 | * Five DSDs are available in the Continuation |
| 746 | * Type 1 IOCB. |
| 747 | */ |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 748 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, req); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 749 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 750 | avail_dsds = 5; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 751 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 752 | |
| 753 | sle_dma = sg_dma_address(sg); |
| 754 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 755 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 756 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 757 | avail_dsds--; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 758 | } |
| 759 | } |
| 760 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 761 | struct fw_dif_context { |
| 762 | uint32_t ref_tag; |
| 763 | uint16_t app_tag; |
| 764 | uint8_t ref_tag_mask[4]; /* Validation/Replacement Mask*/ |
| 765 | uint8_t app_tag_mask[2]; /* Validation/Replacement Mask*/ |
| 766 | }; |
| 767 | |
| 768 | /* |
| 769 | * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command |
| 770 | * |
| 771 | */ |
| 772 | static inline void |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 773 | qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt, |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 774 | unsigned int protcnt) |
| 775 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 776 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 777 | |
| 778 | switch (scsi_get_prot_type(cmd)) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 779 | case SCSI_PROT_DIF_TYPE0: |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 780 | /* |
| 781 | * No check for ql2xenablehba_err_chk, as it would be an |
| 782 | * I/O error if hba tag generation is not done. |
| 783 | */ |
| 784 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 785 | (0xffffffff & scsi_get_lba(cmd))); |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 786 | |
| 787 | if (!qla2x00_hba_err_chk_enabled(sp)) |
| 788 | break; |
| 789 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 790 | pkt->ref_tag_mask[0] = 0xff; |
| 791 | pkt->ref_tag_mask[1] = 0xff; |
| 792 | pkt->ref_tag_mask[2] = 0xff; |
| 793 | pkt->ref_tag_mask[3] = 0xff; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 794 | break; |
| 795 | |
| 796 | /* |
| 797 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to |
| 798 | * match LBA in CDB + N |
| 799 | */ |
| 800 | case SCSI_PROT_DIF_TYPE2: |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 801 | pkt->app_tag = cpu_to_le16(0); |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 802 | pkt->app_tag_mask[0] = 0x0; |
| 803 | pkt->app_tag_mask[1] = 0x0; |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 804 | |
| 805 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 806 | (0xffffffff & scsi_get_lba(cmd))); |
| 807 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 808 | if (!qla2x00_hba_err_chk_enabled(sp)) |
| 809 | break; |
| 810 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 811 | /* enable ALL bytes of the ref tag */ |
| 812 | pkt->ref_tag_mask[0] = 0xff; |
| 813 | pkt->ref_tag_mask[1] = 0xff; |
| 814 | pkt->ref_tag_mask[2] = 0xff; |
| 815 | pkt->ref_tag_mask[3] = 0xff; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 816 | break; |
| 817 | |
| 818 | /* For Type 3 protection: 16 bit GUARD only */ |
| 819 | case SCSI_PROT_DIF_TYPE3: |
| 820 | pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] = |
| 821 | pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] = |
| 822 | 0x00; |
| 823 | break; |
| 824 | |
| 825 | /* |
| 826 | * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and |
| 827 | * 16 bit app tag. |
| 828 | */ |
| 829 | case SCSI_PROT_DIF_TYPE1: |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 830 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 831 | (0xffffffff & scsi_get_lba(cmd))); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 832 | pkt->app_tag = cpu_to_le16(0); |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 833 | pkt->app_tag_mask[0] = 0x0; |
| 834 | pkt->app_tag_mask[1] = 0x0; |
| 835 | |
| 836 | if (!qla2x00_hba_err_chk_enabled(sp)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 837 | break; |
| 838 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 839 | /* enable ALL bytes of the ref tag */ |
| 840 | pkt->ref_tag_mask[0] = 0xff; |
| 841 | pkt->ref_tag_mask[1] = 0xff; |
| 842 | pkt->ref_tag_mask[2] = 0xff; |
| 843 | pkt->ref_tag_mask[3] = 0xff; |
| 844 | break; |
| 845 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 846 | } |
| 847 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 848 | int |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 849 | qla24xx_get_one_block_sg(uint32_t blk_sz, struct qla2_sgx *sgx, |
| 850 | uint32_t *partial) |
| 851 | { |
| 852 | struct scatterlist *sg; |
| 853 | uint32_t cumulative_partial, sg_len; |
| 854 | dma_addr_t sg_dma_addr; |
| 855 | |
| 856 | if (sgx->num_bytes == sgx->tot_bytes) |
| 857 | return 0; |
| 858 | |
| 859 | sg = sgx->cur_sg; |
| 860 | cumulative_partial = sgx->tot_partial; |
| 861 | |
| 862 | sg_dma_addr = sg_dma_address(sg); |
| 863 | sg_len = sg_dma_len(sg); |
| 864 | |
| 865 | sgx->dma_addr = sg_dma_addr + sgx->bytes_consumed; |
| 866 | |
| 867 | if ((cumulative_partial + (sg_len - sgx->bytes_consumed)) >= blk_sz) { |
| 868 | sgx->dma_len = (blk_sz - cumulative_partial); |
| 869 | sgx->tot_partial = 0; |
| 870 | sgx->num_bytes += blk_sz; |
| 871 | *partial = 0; |
| 872 | } else { |
| 873 | sgx->dma_len = sg_len - sgx->bytes_consumed; |
| 874 | sgx->tot_partial += sgx->dma_len; |
| 875 | *partial = 1; |
| 876 | } |
| 877 | |
| 878 | sgx->bytes_consumed += sgx->dma_len; |
| 879 | |
| 880 | if (sg_len == sgx->bytes_consumed) { |
| 881 | sg = sg_next(sg); |
| 882 | sgx->num_sg++; |
| 883 | sgx->cur_sg = sg; |
| 884 | sgx->bytes_consumed = 0; |
| 885 | } |
| 886 | |
| 887 | return 1; |
| 888 | } |
| 889 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 890 | int |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 891 | qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 892 | uint32_t *dsd, uint16_t tot_dsds, struct qla_tc_param *tc) |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 893 | { |
| 894 | void *next_dsd; |
| 895 | uint8_t avail_dsds = 0; |
| 896 | uint32_t dsd_list_len; |
| 897 | struct dsd_dma *dsd_ptr; |
| 898 | struct scatterlist *sg_prot; |
| 899 | uint32_t *cur_dsd = dsd; |
| 900 | uint16_t used_dsds = tot_dsds; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 901 | uint32_t prot_int; /* protection interval */ |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 902 | uint32_t partial; |
| 903 | struct qla2_sgx sgx; |
| 904 | dma_addr_t sle_dma; |
| 905 | uint32_t sle_dma_len, tot_prot_dma_len = 0; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 906 | struct scsi_cmnd *cmd; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 907 | |
| 908 | memset(&sgx, 0, sizeof(struct qla2_sgx)); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 909 | if (sp) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 910 | cmd = GET_CMD_SP(sp); |
| 911 | prot_int = cmd->device->sector_size; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 912 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 913 | sgx.tot_bytes = scsi_bufflen(cmd); |
| 914 | sgx.cur_sg = scsi_sglist(cmd); |
| 915 | sgx.sp = sp; |
| 916 | |
| 917 | sg_prot = scsi_prot_sglist(cmd); |
| 918 | } else if (tc) { |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 919 | prot_int = tc->blk_sz; |
| 920 | sgx.tot_bytes = tc->bufflen; |
| 921 | sgx.cur_sg = tc->sg; |
| 922 | sg_prot = tc->prot_sg; |
| 923 | } else { |
| 924 | BUG(); |
| 925 | return 1; |
| 926 | } |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 927 | |
| 928 | while (qla24xx_get_one_block_sg(prot_int, &sgx, &partial)) { |
| 929 | |
| 930 | sle_dma = sgx.dma_addr; |
| 931 | sle_dma_len = sgx.dma_len; |
| 932 | alloc_and_fill: |
| 933 | /* Allocate additional continuation packets? */ |
| 934 | if (avail_dsds == 0) { |
| 935 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 936 | QLA_DSDS_PER_IOCB : used_dsds; |
| 937 | dsd_list_len = (avail_dsds + 1) * 12; |
| 938 | used_dsds -= avail_dsds; |
| 939 | |
| 940 | /* allocate tracking DS */ |
| 941 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 942 | if (!dsd_ptr) |
| 943 | return 1; |
| 944 | |
| 945 | /* allocate new list */ |
| 946 | dsd_ptr->dsd_addr = next_dsd = |
| 947 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 948 | &dsd_ptr->dsd_list_dma); |
| 949 | |
| 950 | if (!next_dsd) { |
| 951 | /* |
| 952 | * Need to cleanup only this dsd_ptr, rest |
| 953 | * will be done by sp_free_dma() |
| 954 | */ |
| 955 | kfree(dsd_ptr); |
| 956 | return 1; |
| 957 | } |
| 958 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 959 | if (sp) { |
| 960 | list_add_tail(&dsd_ptr->list, |
| 961 | &((struct crc_context *) |
| 962 | sp->u.scmd.ctx)->dsd_list); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 963 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 964 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 965 | } else { |
| 966 | list_add_tail(&dsd_ptr->list, |
| 967 | &(tc->ctx->dsd_list)); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 968 | *tc->ctx_dsd_alloced = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 969 | } |
| 970 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 971 | |
| 972 | /* add new list to cmd iocb or last list */ |
| 973 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 974 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 975 | *cur_dsd++ = dsd_list_len; |
| 976 | cur_dsd = (uint32_t *)next_dsd; |
| 977 | } |
| 978 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 979 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 980 | *cur_dsd++ = cpu_to_le32(sle_dma_len); |
| 981 | avail_dsds--; |
| 982 | |
| 983 | if (partial == 0) { |
| 984 | /* Got a full protection interval */ |
| 985 | sle_dma = sg_dma_address(sg_prot) + tot_prot_dma_len; |
| 986 | sle_dma_len = 8; |
| 987 | |
| 988 | tot_prot_dma_len += sle_dma_len; |
| 989 | if (tot_prot_dma_len == sg_dma_len(sg_prot)) { |
| 990 | tot_prot_dma_len = 0; |
| 991 | sg_prot = sg_next(sg_prot); |
| 992 | } |
| 993 | |
| 994 | partial = 1; /* So as to not re-enter this block */ |
| 995 | goto alloc_and_fill; |
| 996 | } |
| 997 | } |
| 998 | /* Null termination */ |
| 999 | *cur_dsd++ = 0; |
| 1000 | *cur_dsd++ = 0; |
| 1001 | *cur_dsd++ = 0; |
| 1002 | return 0; |
| 1003 | } |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 1004 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1005 | int |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1006 | qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp, uint32_t *dsd, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 1007 | uint16_t tot_dsds, struct qla_tc_param *tc) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1008 | { |
| 1009 | void *next_dsd; |
| 1010 | uint8_t avail_dsds = 0; |
| 1011 | uint32_t dsd_list_len; |
| 1012 | struct dsd_dma *dsd_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1013 | struct scatterlist *sg, *sgl; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1014 | uint32_t *cur_dsd = dsd; |
| 1015 | int i; |
| 1016 | uint16_t used_dsds = tot_dsds; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1017 | struct scsi_cmnd *cmd; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1018 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1019 | if (sp) { |
| 1020 | cmd = GET_CMD_SP(sp); |
| 1021 | sgl = scsi_sglist(cmd); |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1022 | } else if (tc) { |
| 1023 | sgl = tc->sg; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1024 | } else { |
| 1025 | BUG(); |
| 1026 | return 1; |
| 1027 | } |
| 1028 | |
| 1029 | |
| 1030 | for_each_sg(sgl, sg, tot_dsds, i) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1031 | dma_addr_t sle_dma; |
| 1032 | |
| 1033 | /* Allocate additional continuation packets? */ |
| 1034 | if (avail_dsds == 0) { |
| 1035 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 1036 | QLA_DSDS_PER_IOCB : used_dsds; |
| 1037 | dsd_list_len = (avail_dsds + 1) * 12; |
| 1038 | used_dsds -= avail_dsds; |
| 1039 | |
| 1040 | /* allocate tracking DS */ |
| 1041 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 1042 | if (!dsd_ptr) |
| 1043 | return 1; |
| 1044 | |
| 1045 | /* allocate new list */ |
| 1046 | dsd_ptr->dsd_addr = next_dsd = |
| 1047 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 1048 | &dsd_ptr->dsd_list_dma); |
| 1049 | |
| 1050 | if (!next_dsd) { |
| 1051 | /* |
| 1052 | * Need to cleanup only this dsd_ptr, rest |
| 1053 | * will be done by sp_free_dma() |
| 1054 | */ |
| 1055 | kfree(dsd_ptr); |
| 1056 | return 1; |
| 1057 | } |
| 1058 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1059 | if (sp) { |
| 1060 | list_add_tail(&dsd_ptr->list, |
| 1061 | &((struct crc_context *) |
| 1062 | sp->u.scmd.ctx)->dsd_list); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1063 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1064 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 1065 | } else { |
| 1066 | list_add_tail(&dsd_ptr->list, |
| 1067 | &(tc->ctx->dsd_list)); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 1068 | *tc->ctx_dsd_alloced = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1069 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1070 | |
| 1071 | /* add new list to cmd iocb or last list */ |
| 1072 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 1073 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 1074 | *cur_dsd++ = dsd_list_len; |
| 1075 | cur_dsd = (uint32_t *)next_dsd; |
| 1076 | } |
| 1077 | sle_dma = sg_dma_address(sg); |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 1078 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1079 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 1080 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 1081 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 1082 | avail_dsds--; |
| 1083 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1084 | } |
| 1085 | /* Null termination */ |
| 1086 | *cur_dsd++ = 0; |
| 1087 | *cur_dsd++ = 0; |
| 1088 | *cur_dsd++ = 0; |
| 1089 | return 0; |
| 1090 | } |
| 1091 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1092 | int |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1093 | qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp, |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 1094 | uint32_t *dsd, uint16_t tot_dsds, struct qla_tc_param *tc) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1095 | { |
| 1096 | void *next_dsd; |
| 1097 | uint8_t avail_dsds = 0; |
| 1098 | uint32_t dsd_list_len; |
| 1099 | struct dsd_dma *dsd_ptr; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1100 | struct scatterlist *sg, *sgl; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1101 | int i; |
| 1102 | struct scsi_cmnd *cmd; |
| 1103 | uint32_t *cur_dsd = dsd; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1104 | uint16_t used_dsds = tot_dsds; |
| 1105 | struct scsi_qla_host *vha; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1106 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1107 | if (sp) { |
| 1108 | cmd = GET_CMD_SP(sp); |
| 1109 | sgl = scsi_prot_sglist(cmd); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1110 | vha = sp->vha; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1111 | } else if (tc) { |
| 1112 | vha = tc->vha; |
| 1113 | sgl = tc->prot_sg; |
| 1114 | } else { |
| 1115 | BUG(); |
| 1116 | return 1; |
| 1117 | } |
| 1118 | |
| 1119 | ql_dbg(ql_dbg_tgt, vha, 0xe021, |
| 1120 | "%s: enter\n", __func__); |
| 1121 | |
| 1122 | for_each_sg(sgl, sg, tot_dsds, i) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1123 | dma_addr_t sle_dma; |
| 1124 | |
| 1125 | /* Allocate additional continuation packets? */ |
| 1126 | if (avail_dsds == 0) { |
| 1127 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 1128 | QLA_DSDS_PER_IOCB : used_dsds; |
| 1129 | dsd_list_len = (avail_dsds + 1) * 12; |
| 1130 | used_dsds -= avail_dsds; |
| 1131 | |
| 1132 | /* allocate tracking DS */ |
| 1133 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 1134 | if (!dsd_ptr) |
| 1135 | return 1; |
| 1136 | |
| 1137 | /* allocate new list */ |
| 1138 | dsd_ptr->dsd_addr = next_dsd = |
| 1139 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 1140 | &dsd_ptr->dsd_list_dma); |
| 1141 | |
| 1142 | if (!next_dsd) { |
| 1143 | /* |
| 1144 | * Need to cleanup only this dsd_ptr, rest |
| 1145 | * will be done by sp_free_dma() |
| 1146 | */ |
| 1147 | kfree(dsd_ptr); |
| 1148 | return 1; |
| 1149 | } |
| 1150 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1151 | if (sp) { |
| 1152 | list_add_tail(&dsd_ptr->list, |
| 1153 | &((struct crc_context *) |
| 1154 | sp->u.scmd.ctx)->dsd_list); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1155 | |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1156 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 1157 | } else { |
| 1158 | list_add_tail(&dsd_ptr->list, |
| 1159 | &(tc->ctx->dsd_list)); |
Quinn Tran | be25152 | 2017-03-15 09:48:49 -0700 | [diff] [blame] | 1160 | *tc->ctx_dsd_alloced = 1; |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1161 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1162 | |
| 1163 | /* add new list to cmd iocb or last list */ |
| 1164 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 1165 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 1166 | *cur_dsd++ = dsd_list_len; |
| 1167 | cur_dsd = (uint32_t *)next_dsd; |
| 1168 | } |
| 1169 | sle_dma = sg_dma_address(sg); |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 1170 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1171 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 1172 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 1173 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 1174 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1175 | avail_dsds--; |
| 1176 | } |
| 1177 | /* Null termination */ |
| 1178 | *cur_dsd++ = 0; |
| 1179 | *cur_dsd++ = 0; |
| 1180 | *cur_dsd++ = 0; |
| 1181 | return 0; |
| 1182 | } |
| 1183 | |
| 1184 | /** |
| 1185 | * qla24xx_build_scsi_crc_2_iocbs() - Build IOCB command utilizing Command |
| 1186 | * Type 6 IOCB types. |
| 1187 | * |
| 1188 | * @sp: SRB command to process |
| 1189 | * @cmd_pkt: Command type 3 IOCB |
| 1190 | * @tot_dsds: Total number of segments to transfer |
| 1191 | */ |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1192 | inline int |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1193 | qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, |
| 1194 | uint16_t tot_dsds, uint16_t tot_prot_dsds, uint16_t fw_prot_opts) |
| 1195 | { |
| 1196 | uint32_t *cur_dsd, *fcp_dl; |
| 1197 | scsi_qla_host_t *vha; |
| 1198 | struct scsi_cmnd *cmd; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1199 | uint32_t total_bytes = 0; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1200 | uint32_t data_bytes; |
| 1201 | uint32_t dif_bytes; |
| 1202 | uint8_t bundling = 1; |
| 1203 | uint16_t blk_size; |
| 1204 | uint8_t *clr_ptr; |
| 1205 | struct crc_context *crc_ctx_pkt = NULL; |
| 1206 | struct qla_hw_data *ha; |
| 1207 | uint8_t additional_fcpcdb_len; |
| 1208 | uint16_t fcp_cmnd_len; |
| 1209 | struct fcp_cmnd *fcp_cmnd; |
| 1210 | dma_addr_t crc_ctx_dma; |
| 1211 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1212 | cmd = GET_CMD_SP(sp); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1213 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1214 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1215 | *((uint32_t *)(&cmd_pkt->entry_type)) = cpu_to_le32(COMMAND_TYPE_CRC_2); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1216 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1217 | vha = sp->vha; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1218 | ha = vha->hw; |
| 1219 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1220 | /* No data transfer */ |
| 1221 | data_bytes = scsi_bufflen(cmd); |
| 1222 | if (!data_bytes || cmd->sc_data_direction == DMA_NONE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1223 | cmd_pkt->byte_count = cpu_to_le32(0); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1224 | return QLA_SUCCESS; |
| 1225 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1226 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1227 | cmd_pkt->vp_index = sp->vha->vp_idx; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1228 | |
| 1229 | /* Set transfer direction */ |
| 1230 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
| 1231 | cmd_pkt->control_flags = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1232 | cpu_to_le16(CF_WRITE_DATA); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1233 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
| 1234 | cmd_pkt->control_flags = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1235 | cpu_to_le16(CF_READ_DATA); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1236 | } |
| 1237 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1238 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1239 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP) || |
| 1240 | (scsi_get_prot_op(cmd) == SCSI_PROT_READ_STRIP) || |
| 1241 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_INSERT)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1242 | bundling = 0; |
| 1243 | |
| 1244 | /* Allocate CRC context from global pool */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1245 | crc_ctx_pkt = sp->u.scmd.ctx = |
| 1246 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1247 | |
| 1248 | if (!crc_ctx_pkt) |
| 1249 | goto crc_queuing_error; |
| 1250 | |
| 1251 | /* Zero out CTX area. */ |
| 1252 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 1253 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 1254 | |
| 1255 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 1256 | |
| 1257 | sp->flags |= SRB_CRC_CTX_DMA_VALID; |
| 1258 | |
| 1259 | /* Set handle */ |
| 1260 | crc_ctx_pkt->handle = cmd_pkt->handle; |
| 1261 | |
| 1262 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 1263 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 1264 | qla24xx_set_t10dif_tags(sp, (struct fw_dif_context *) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1265 | &crc_ctx_pkt->ref_tag, tot_prot_dsds); |
| 1266 | |
| 1267 | cmd_pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 1268 | cmd_pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 1269 | cmd_pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 1270 | |
| 1271 | /* Determine SCSI command length -- align to 4 byte boundary */ |
| 1272 | if (cmd->cmd_len > 16) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1273 | additional_fcpcdb_len = cmd->cmd_len - 16; |
| 1274 | if ((cmd->cmd_len % 4) != 0) { |
| 1275 | /* SCSI cmd > 16 bytes must be multiple of 4 */ |
| 1276 | goto crc_queuing_error; |
| 1277 | } |
| 1278 | fcp_cmnd_len = 12 + cmd->cmd_len + 4; |
| 1279 | } else { |
| 1280 | additional_fcpcdb_len = 0; |
| 1281 | fcp_cmnd_len = 12 + 16 + 4; |
| 1282 | } |
| 1283 | |
| 1284 | fcp_cmnd = &crc_ctx_pkt->fcp_cmnd; |
| 1285 | |
| 1286 | fcp_cmnd->additional_cdb_len = additional_fcpcdb_len; |
| 1287 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 1288 | fcp_cmnd->additional_cdb_len |= 1; |
| 1289 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 1290 | fcp_cmnd->additional_cdb_len |= 2; |
| 1291 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1292 | int_to_scsilun(cmd->device->lun, &fcp_cmnd->lun); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1293 | memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len); |
| 1294 | cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len); |
| 1295 | cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32( |
| 1296 | LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); |
| 1297 | cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32( |
| 1298 | MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 1299 | fcp_cmnd->task_management = 0; |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 1300 | fcp_cmnd->task_attribute = TSK_SIMPLE; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1301 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1302 | cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */ |
| 1303 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1304 | /* Compute dif len and adjust data len to incude protection */ |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1305 | dif_bytes = 0; |
| 1306 | blk_size = cmd->device->sector_size; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1307 | dif_bytes = (data_bytes / blk_size) * 8; |
| 1308 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1309 | switch (scsi_get_prot_op(GET_CMD_SP(sp))) { |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1310 | case SCSI_PROT_READ_INSERT: |
| 1311 | case SCSI_PROT_WRITE_STRIP: |
| 1312 | total_bytes = data_bytes; |
| 1313 | data_bytes += dif_bytes; |
| 1314 | break; |
| 1315 | |
| 1316 | case SCSI_PROT_READ_STRIP: |
| 1317 | case SCSI_PROT_WRITE_INSERT: |
| 1318 | case SCSI_PROT_READ_PASS: |
| 1319 | case SCSI_PROT_WRITE_PASS: |
| 1320 | total_bytes = data_bytes + dif_bytes; |
| 1321 | break; |
| 1322 | default: |
| 1323 | BUG(); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 1326 | if (!qla2x00_hba_err_chk_enabled(sp)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1327 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
Arun Easi | 9e522cd | 2012-08-22 14:21:31 -0400 | [diff] [blame] | 1328 | /* HBA error checking enabled */ |
| 1329 | else if (IS_PI_UNINIT_CAPABLE(ha)) { |
| 1330 | if ((scsi_get_prot_type(GET_CMD_SP(sp)) == SCSI_PROT_DIF_TYPE1) |
| 1331 | || (scsi_get_prot_type(GET_CMD_SP(sp)) == |
| 1332 | SCSI_PROT_DIF_TYPE2)) |
| 1333 | fw_prot_opts |= BIT_10; |
| 1334 | else if (scsi_get_prot_type(GET_CMD_SP(sp)) == |
| 1335 | SCSI_PROT_DIF_TYPE3) |
| 1336 | fw_prot_opts |= BIT_11; |
| 1337 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1338 | |
| 1339 | if (!bundling) { |
| 1340 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 1341 | } else { |
| 1342 | /* |
| 1343 | * Configure Bundling if we need to fetch interlaving |
| 1344 | * protection PCI accesses |
| 1345 | */ |
| 1346 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 1347 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 1348 | crc_ctx_pkt->u.bundling.dseg_count = cpu_to_le16(tot_dsds - |
| 1349 | tot_prot_dsds); |
| 1350 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 1351 | } |
| 1352 | |
| 1353 | /* Finish the common fields of CRC pkt */ |
| 1354 | crc_ctx_pkt->blk_size = cpu_to_le16(blk_size); |
| 1355 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 1356 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1357 | crc_ctx_pkt->guard_seed = cpu_to_le16(0); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1358 | /* Fibre channel byte count */ |
| 1359 | cmd_pkt->byte_count = cpu_to_le32(total_bytes); |
| 1360 | fcp_dl = (uint32_t *)(crc_ctx_pkt->fcp_cmnd.cdb + 16 + |
| 1361 | additional_fcpcdb_len); |
| 1362 | *fcp_dl = htonl(total_bytes); |
| 1363 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1364 | if (!data_bytes || cmd->sc_data_direction == DMA_NONE) { |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1365 | cmd_pkt->byte_count = cpu_to_le32(0); |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1366 | return QLA_SUCCESS; |
| 1367 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1368 | /* Walks data segments */ |
| 1369 | |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1370 | cmd_pkt->control_flags |= cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1371 | |
| 1372 | if (!bundling && tot_prot_dsds) { |
| 1373 | if (qla24xx_walk_and_build_sglist_no_difb(ha, sp, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1374 | cur_dsd, tot_dsds, NULL)) |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1375 | goto crc_queuing_error; |
| 1376 | } else if (qla24xx_walk_and_build_sglist(ha, sp, cur_dsd, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1377 | (tot_dsds - tot_prot_dsds), NULL)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1378 | goto crc_queuing_error; |
| 1379 | |
| 1380 | if (bundling && tot_prot_dsds) { |
| 1381 | /* Walks dif segments */ |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1382 | cmd_pkt->control_flags |= cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1383 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 1384 | if (qla24xx_walk_and_build_prot_sglist(ha, sp, cur_dsd, |
Quinn Tran | f83adb6 | 2014-04-11 16:54:43 -0400 | [diff] [blame] | 1385 | tot_prot_dsds, NULL)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1386 | goto crc_queuing_error; |
| 1387 | } |
| 1388 | return QLA_SUCCESS; |
| 1389 | |
| 1390 | crc_queuing_error: |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1391 | /* Cleanup will be performed by the caller */ |
| 1392 | |
| 1393 | return QLA_FUNCTION_FAILED; |
| 1394 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1395 | |
| 1396 | /** |
| 1397 | * qla24xx_start_scsi() - Send a SCSI command to the ISP |
| 1398 | * @sp: command to send to the ISP |
| 1399 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 1400 | * Returns non-zero if a failure occurred, else zero. |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1401 | */ |
| 1402 | int |
| 1403 | qla24xx_start_scsi(srb_t *sp) |
| 1404 | { |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 1405 | int nseg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1406 | unsigned long flags; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1407 | uint32_t *clr_ptr; |
| 1408 | uint32_t index; |
| 1409 | uint32_t handle; |
| 1410 | struct cmd_type_7 *cmd_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1411 | uint16_t cnt; |
| 1412 | uint16_t req_cnt; |
| 1413 | uint16_t tot_dsds; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1414 | struct req_que *req = NULL; |
| 1415 | struct rsp_que *rsp = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1416 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1417 | struct scsi_qla_host *vha = sp->vha; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1418 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1419 | |
| 1420 | /* Setup device pointers. */ |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1421 | req = vha->req; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1422 | rsp = req->rsp; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1423 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1424 | /* So we know we haven't pci_map'ed anything yet */ |
| 1425 | tot_dsds = 0; |
| 1426 | |
| 1427 | /* Send marker if required */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1428 | if (vha->marker_needed != 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1429 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1430 | QLA_SUCCESS) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1431 | return QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1432 | vha->marker_needed = 0; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | /* Acquire ring specific lock */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1436 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1437 | |
| 1438 | /* Check for room in outstanding command list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1439 | handle = req->current_outstanding_cmd; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1440 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1441 | handle++; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1442 | if (handle == req->num_outstanding_cmds) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1443 | handle = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1444 | if (!req->outstanding_cmds[handle]) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1445 | break; |
| 1446 | } |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1447 | if (index == req->num_outstanding_cmds) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1448 | goto queuing_error; |
| 1449 | |
| 1450 | /* Map the sg table so we have an accurate count of sg entries needed */ |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1451 | if (scsi_sg_count(cmd)) { |
| 1452 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1453 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1454 | if (unlikely(!nseg)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1455 | goto queuing_error; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1456 | } else |
| 1457 | nseg = 0; |
| 1458 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1459 | tot_dsds = nseg; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1460 | req_cnt = qla24xx_calc_iocbs(vha, tot_dsds); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1461 | if (req->cnt < (req_cnt + 2)) { |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 1462 | cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr : |
| 1463 | RD_REG_DWORD_RELAXED(req->req_q_out); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1464 | if (req->ring_index < cnt) |
| 1465 | req->cnt = cnt - req->ring_index; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1466 | else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1467 | req->cnt = req->length - |
| 1468 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 1469 | if (req->cnt < (req_cnt + 2)) |
| 1470 | goto queuing_error; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1471 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1472 | |
| 1473 | /* Build command packet. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1474 | req->current_outstanding_cmd = handle; |
| 1475 | req->outstanding_cmds[handle] = sp; |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 1476 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1477 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1478 | req->cnt -= req_cnt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1479 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1480 | cmd_pkt = (struct cmd_type_7 *)req->ring_ptr; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1481 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1482 | |
| 1483 | /* Zero out remaining portion of packet. */ |
James Bottomley | 72df832 | 2005-10-28 14:41:19 -0500 | [diff] [blame] | 1484 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1485 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 1486 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 1487 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 1488 | |
| 1489 | /* Set NPORT-ID and LUN number*/ |
| 1490 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1491 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1492 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 1493 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1494 | cmd_pkt->vp_index = sp->vha->vp_idx; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1495 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1496 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
andrew.vasquez@qlogic.com | 0d4be12 | 2006-02-07 08:45:35 -0800 | [diff] [blame] | 1497 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1498 | |
Christoph Hellwig | 5066863 | 2014-10-30 14:30:06 +0100 | [diff] [blame] | 1499 | cmd_pkt->task = TSK_SIMPLE; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1500 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1501 | /* Load SCSI command packet. */ |
| 1502 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 1503 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 1504 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1505 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1506 | |
| 1507 | /* Build IOCB segments */ |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1508 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds, req); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1509 | |
| 1510 | /* Set total data segment count. */ |
| 1511 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 1512 | wmb(); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1513 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1514 | req->ring_index++; |
| 1515 | if (req->ring_index == req->length) { |
| 1516 | req->ring_index = 0; |
| 1517 | req->ring_ptr = req->ring; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1518 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1519 | req->ring_ptr++; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1520 | |
| 1521 | sp->flags |= SRB_DMA_VALID; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1522 | |
| 1523 | /* Set chip new ring index. */ |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 1524 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 1525 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1526 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1527 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1528 | if (vha->flags.process_response_queue && |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1529 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1530 | qla24xx_process_response_queue(vha, rsp); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1531 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1532 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1533 | return QLA_SUCCESS; |
| 1534 | |
| 1535 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1536 | if (tot_dsds) |
| 1537 | scsi_dma_unmap(cmd); |
| 1538 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1539 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1540 | |
| 1541 | return QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1542 | } |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1543 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1544 | /** |
| 1545 | * qla24xx_dif_start_scsi() - Send a SCSI command to the ISP |
| 1546 | * @sp: command to send to the ISP |
| 1547 | * |
| 1548 | * Returns non-zero if a failure occurred, else zero. |
| 1549 | */ |
| 1550 | int |
| 1551 | qla24xx_dif_start_scsi(srb_t *sp) |
| 1552 | { |
| 1553 | int nseg; |
| 1554 | unsigned long flags; |
| 1555 | uint32_t *clr_ptr; |
| 1556 | uint32_t index; |
| 1557 | uint32_t handle; |
| 1558 | uint16_t cnt; |
| 1559 | uint16_t req_cnt = 0; |
| 1560 | uint16_t tot_dsds; |
| 1561 | uint16_t tot_prot_dsds; |
| 1562 | uint16_t fw_prot_opts = 0; |
| 1563 | struct req_que *req = NULL; |
| 1564 | struct rsp_que *rsp = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1565 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 1566 | struct scsi_qla_host *vha = sp->vha; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1567 | struct qla_hw_data *ha = vha->hw; |
| 1568 | struct cmd_type_crc_2 *cmd_pkt; |
| 1569 | uint32_t status = 0; |
| 1570 | |
| 1571 | #define QDSS_GOT_Q_SPACE BIT_0 |
| 1572 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1573 | /* Only process protection or >16 cdb in this routine */ |
| 1574 | if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL) { |
| 1575 | if (cmd->cmd_len <= 16) |
| 1576 | return qla24xx_start_scsi(sp); |
| 1577 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1578 | |
| 1579 | /* Setup device pointers. */ |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1580 | req = vha->req; |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1581 | rsp = req->rsp; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1582 | |
| 1583 | /* So we know we haven't pci_map'ed anything yet */ |
| 1584 | tot_dsds = 0; |
| 1585 | |
| 1586 | /* Send marker if required */ |
| 1587 | if (vha->marker_needed != 0) { |
| 1588 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1589 | QLA_SUCCESS) |
| 1590 | return QLA_FUNCTION_FAILED; |
| 1591 | vha->marker_needed = 0; |
| 1592 | } |
| 1593 | |
| 1594 | /* Acquire ring specific lock */ |
| 1595 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1596 | |
| 1597 | /* Check for room in outstanding command list. */ |
| 1598 | handle = req->current_outstanding_cmd; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1599 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1600 | handle++; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1601 | if (handle == req->num_outstanding_cmds) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1602 | handle = 1; |
| 1603 | if (!req->outstanding_cmds[handle]) |
| 1604 | break; |
| 1605 | } |
| 1606 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 1607 | if (index == req->num_outstanding_cmds) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1608 | goto queuing_error; |
| 1609 | |
| 1610 | /* Compute number of required data segments */ |
| 1611 | /* Map the sg table so we have an accurate count of sg entries needed */ |
| 1612 | if (scsi_sg_count(cmd)) { |
| 1613 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1614 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1615 | if (unlikely(!nseg)) |
| 1616 | goto queuing_error; |
| 1617 | else |
| 1618 | sp->flags |= SRB_DMA_VALID; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1619 | |
| 1620 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1621 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 1622 | struct qla2_sgx sgx; |
| 1623 | uint32_t partial; |
| 1624 | |
| 1625 | memset(&sgx, 0, sizeof(struct qla2_sgx)); |
| 1626 | sgx.tot_bytes = scsi_bufflen(cmd); |
| 1627 | sgx.cur_sg = scsi_sglist(cmd); |
| 1628 | sgx.sp = sp; |
| 1629 | |
| 1630 | nseg = 0; |
| 1631 | while (qla24xx_get_one_block_sg( |
| 1632 | cmd->device->sector_size, &sgx, &partial)) |
| 1633 | nseg++; |
| 1634 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1635 | } else |
| 1636 | nseg = 0; |
| 1637 | |
| 1638 | /* number of required data segments */ |
| 1639 | tot_dsds = nseg; |
| 1640 | |
| 1641 | /* Compute number of required protection segments */ |
| 1642 | if (qla24xx_configure_prot_mode(sp, &fw_prot_opts)) { |
| 1643 | nseg = dma_map_sg(&ha->pdev->dev, scsi_prot_sglist(cmd), |
| 1644 | scsi_prot_sg_count(cmd), cmd->sc_data_direction); |
| 1645 | if (unlikely(!nseg)) |
| 1646 | goto queuing_error; |
| 1647 | else |
| 1648 | sp->flags |= SRB_CRC_PROT_DMA_VALID; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1649 | |
| 1650 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1651 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 1652 | nseg = scsi_bufflen(cmd) / cmd->device->sector_size; |
| 1653 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1654 | } else { |
| 1655 | nseg = 0; |
| 1656 | } |
| 1657 | |
| 1658 | req_cnt = 1; |
| 1659 | /* Total Data and protection sg segment(s) */ |
| 1660 | tot_prot_dsds = nseg; |
| 1661 | tot_dsds += nseg; |
| 1662 | if (req->cnt < (req_cnt + 2)) { |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 1663 | cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr : |
| 1664 | RD_REG_DWORD_RELAXED(req->req_q_out); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1665 | if (req->ring_index < cnt) |
| 1666 | req->cnt = cnt - req->ring_index; |
| 1667 | else |
| 1668 | req->cnt = req->length - |
| 1669 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 1670 | if (req->cnt < (req_cnt + 2)) |
| 1671 | goto queuing_error; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1672 | } |
| 1673 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1674 | status |= QDSS_GOT_Q_SPACE; |
| 1675 | |
| 1676 | /* Build header part of command packet (excluding the OPCODE). */ |
| 1677 | req->current_outstanding_cmd = handle; |
| 1678 | req->outstanding_cmds[handle] = sp; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1679 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1680 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1681 | req->cnt -= req_cnt; |
| 1682 | |
| 1683 | /* Fill-in common area */ |
| 1684 | cmd_pkt = (struct cmd_type_crc_2 *)req->ring_ptr; |
| 1685 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 1686 | |
| 1687 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 1688 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 1689 | |
| 1690 | /* Set NPORT-ID and LUN number*/ |
| 1691 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1692 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1693 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 1694 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
| 1695 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1696 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1697 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
| 1698 | |
| 1699 | /* Total Data and protection segment(s) */ |
| 1700 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 1701 | |
| 1702 | /* Build IOCB segments and adjust for data protection segments */ |
| 1703 | if (qla24xx_build_scsi_crc_2_iocbs(sp, (struct cmd_type_crc_2 *) |
| 1704 | req->ring_ptr, tot_dsds, tot_prot_dsds, fw_prot_opts) != |
| 1705 | QLA_SUCCESS) |
| 1706 | goto queuing_error; |
| 1707 | |
| 1708 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 1709 | /* Specify response queue number where completion should happen */ |
| 1710 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 1711 | cmd_pkt->timeout = cpu_to_le16(0); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1712 | wmb(); |
| 1713 | |
| 1714 | /* Adjust ring index. */ |
| 1715 | req->ring_index++; |
| 1716 | if (req->ring_index == req->length) { |
| 1717 | req->ring_index = 0; |
| 1718 | req->ring_ptr = req->ring; |
| 1719 | } else |
| 1720 | req->ring_ptr++; |
| 1721 | |
| 1722 | /* Set chip new ring index. */ |
| 1723 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 1724 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
| 1725 | |
| 1726 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 1727 | if (vha->flags.process_response_queue && |
| 1728 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 1729 | qla24xx_process_response_queue(vha, rsp); |
| 1730 | |
| 1731 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1732 | |
| 1733 | return QLA_SUCCESS; |
| 1734 | |
| 1735 | queuing_error: |
| 1736 | if (status & QDSS_GOT_Q_SPACE) { |
| 1737 | req->outstanding_cmds[handle] = NULL; |
| 1738 | req->cnt += req_cnt; |
| 1739 | } |
| 1740 | /* Cleanup will be performed by the caller (queuecommand) */ |
| 1741 | |
| 1742 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1743 | return QLA_FUNCTION_FAILED; |
| 1744 | } |
| 1745 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1746 | /** |
| 1747 | * qla2xxx_start_scsi_mq() - Send a SCSI command to the ISP |
| 1748 | * @sp: command to send to the ISP |
| 1749 | * |
| 1750 | * Returns non-zero if a failure occurred, else zero. |
| 1751 | */ |
| 1752 | static int |
| 1753 | qla2xxx_start_scsi_mq(srb_t *sp) |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1754 | { |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1755 | int nseg; |
| 1756 | unsigned long flags; |
| 1757 | uint32_t *clr_ptr; |
| 1758 | uint32_t index; |
| 1759 | uint32_t handle; |
| 1760 | struct cmd_type_7 *cmd_pkt; |
| 1761 | uint16_t cnt; |
| 1762 | uint16_t req_cnt; |
| 1763 | uint16_t tot_dsds; |
| 1764 | struct req_que *req = NULL; |
| 1765 | struct rsp_que *rsp = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1766 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1767 | struct scsi_qla_host *vha = sp->fcport->vha; |
| 1768 | struct qla_hw_data *ha = vha->hw; |
| 1769 | struct qla_qpair *qpair = sp->qpair; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1770 | |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 1771 | /* Setup qpair pointers */ |
| 1772 | rsp = qpair->rsp; |
| 1773 | req = qpair->req; |
| 1774 | |
| 1775 | /* So we know we haven't pci_map'ed anything yet */ |
| 1776 | tot_dsds = 0; |
| 1777 | |
| 1778 | /* Send marker if required */ |
| 1779 | if (vha->marker_needed != 0) { |
| 1780 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1781 | QLA_SUCCESS) |
| 1782 | return QLA_FUNCTION_FAILED; |
| 1783 | vha->marker_needed = 0; |
| 1784 | } |
| 1785 | |
| 1786 | /* Acquire qpair specific lock */ |
| 1787 | spin_lock_irqsave(&qpair->qp_lock, flags); |
| 1788 | |
| 1789 | /* Check for room in outstanding command list. */ |
| 1790 | handle = req->current_outstanding_cmd; |
| 1791 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 1792 | handle++; |
| 1793 | if (handle == req->num_outstanding_cmds) |
| 1794 | handle = 1; |
| 1795 | if (!req->outstanding_cmds[handle]) |
| 1796 | break; |
| 1797 | } |
| 1798 | if (index == req->num_outstanding_cmds) |
| 1799 | goto queuing_error; |
| 1800 | |
| 1801 | /* Map the sg table so we have an accurate count of sg entries needed */ |
| 1802 | if (scsi_sg_count(cmd)) { |
| 1803 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1804 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1805 | if (unlikely(!nseg)) |
| 1806 | goto queuing_error; |
| 1807 | } else |
| 1808 | nseg = 0; |
| 1809 | |
| 1810 | tot_dsds = nseg; |
| 1811 | req_cnt = qla24xx_calc_iocbs(vha, tot_dsds); |
| 1812 | if (req->cnt < (req_cnt + 2)) { |
| 1813 | cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr : |
| 1814 | RD_REG_DWORD_RELAXED(req->req_q_out); |
| 1815 | if (req->ring_index < cnt) |
| 1816 | req->cnt = cnt - req->ring_index; |
| 1817 | else |
| 1818 | req->cnt = req->length - |
| 1819 | (req->ring_index - cnt); |
| 1820 | if (req->cnt < (req_cnt + 2)) |
| 1821 | goto queuing_error; |
| 1822 | } |
| 1823 | |
| 1824 | /* Build command packet. */ |
| 1825 | req->current_outstanding_cmd = handle; |
| 1826 | req->outstanding_cmds[handle] = sp; |
| 1827 | sp->handle = handle; |
| 1828 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
| 1829 | req->cnt -= req_cnt; |
| 1830 | |
| 1831 | cmd_pkt = (struct cmd_type_7 *)req->ring_ptr; |
| 1832 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 1833 | |
| 1834 | /* Zero out remaining portion of packet. */ |
| 1835 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
| 1836 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 1837 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 1838 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 1839 | |
| 1840 | /* Set NPORT-ID and LUN number*/ |
| 1841 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1842 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1843 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 1844 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
| 1845 | cmd_pkt->vp_index = sp->fcport->vha->vp_idx; |
| 1846 | |
| 1847 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
| 1848 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
| 1849 | |
| 1850 | cmd_pkt->task = TSK_SIMPLE; |
| 1851 | |
| 1852 | /* Load SCSI command packet. */ |
| 1853 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 1854 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 1855 | |
| 1856 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
| 1857 | |
| 1858 | /* Build IOCB segments */ |
| 1859 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds, req); |
| 1860 | |
| 1861 | /* Set total data segment count. */ |
| 1862 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 1863 | wmb(); |
| 1864 | /* Adjust ring index. */ |
| 1865 | req->ring_index++; |
| 1866 | if (req->ring_index == req->length) { |
| 1867 | req->ring_index = 0; |
| 1868 | req->ring_ptr = req->ring; |
| 1869 | } else |
| 1870 | req->ring_ptr++; |
| 1871 | |
| 1872 | sp->flags |= SRB_DMA_VALID; |
| 1873 | |
| 1874 | /* Set chip new ring index. */ |
| 1875 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 1876 | |
| 1877 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 1878 | if (vha->flags.process_response_queue && |
| 1879 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 1880 | qla24xx_process_response_queue(vha, rsp); |
| 1881 | |
| 1882 | spin_unlock_irqrestore(&qpair->qp_lock, flags); |
| 1883 | return QLA_SUCCESS; |
| 1884 | |
| 1885 | queuing_error: |
| 1886 | if (tot_dsds) |
| 1887 | scsi_dma_unmap(cmd); |
| 1888 | |
| 1889 | spin_unlock_irqrestore(&qpair->qp_lock, flags); |
| 1890 | |
| 1891 | return QLA_FUNCTION_FAILED; |
| 1892 | } |
| 1893 | |
| 1894 | |
| 1895 | /** |
| 1896 | * qla2xxx_dif_start_scsi_mq() - Send a SCSI command to the ISP |
| 1897 | * @sp: command to send to the ISP |
| 1898 | * |
| 1899 | * Returns non-zero if a failure occurred, else zero. |
| 1900 | */ |
| 1901 | int |
| 1902 | qla2xxx_dif_start_scsi_mq(srb_t *sp) |
| 1903 | { |
| 1904 | int nseg; |
| 1905 | unsigned long flags; |
| 1906 | uint32_t *clr_ptr; |
| 1907 | uint32_t index; |
| 1908 | uint32_t handle; |
| 1909 | uint16_t cnt; |
| 1910 | uint16_t req_cnt = 0; |
| 1911 | uint16_t tot_dsds; |
| 1912 | uint16_t tot_prot_dsds; |
| 1913 | uint16_t fw_prot_opts = 0; |
| 1914 | struct req_que *req = NULL; |
| 1915 | struct rsp_que *rsp = NULL; |
| 1916 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
| 1917 | struct scsi_qla_host *vha = sp->fcport->vha; |
| 1918 | struct qla_hw_data *ha = vha->hw; |
| 1919 | struct cmd_type_crc_2 *cmd_pkt; |
| 1920 | uint32_t status = 0; |
| 1921 | struct qla_qpair *qpair = sp->qpair; |
| 1922 | |
| 1923 | #define QDSS_GOT_Q_SPACE BIT_0 |
| 1924 | |
| 1925 | /* Check for host side state */ |
| 1926 | if (!qpair->online) { |
| 1927 | cmd->result = DID_NO_CONNECT << 16; |
| 1928 | return QLA_INTERFACE_ERROR; |
| 1929 | } |
| 1930 | |
| 1931 | if (!qpair->difdix_supported && |
| 1932 | scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) { |
| 1933 | cmd->result = DID_NO_CONNECT << 16; |
| 1934 | return QLA_INTERFACE_ERROR; |
| 1935 | } |
| 1936 | |
| 1937 | /* Only process protection or >16 cdb in this routine */ |
| 1938 | if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL) { |
| 1939 | if (cmd->cmd_len <= 16) |
| 1940 | return qla2xxx_start_scsi_mq(sp); |
| 1941 | } |
| 1942 | |
| 1943 | /* Setup qpair pointers */ |
| 1944 | rsp = qpair->rsp; |
| 1945 | req = qpair->req; |
| 1946 | |
| 1947 | /* So we know we haven't pci_map'ed anything yet */ |
| 1948 | tot_dsds = 0; |
| 1949 | |
| 1950 | /* Send marker if required */ |
| 1951 | if (vha->marker_needed != 0) { |
| 1952 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1953 | QLA_SUCCESS) |
| 1954 | return QLA_FUNCTION_FAILED; |
| 1955 | vha->marker_needed = 0; |
| 1956 | } |
| 1957 | |
| 1958 | /* Acquire ring specific lock */ |
| 1959 | spin_lock_irqsave(&qpair->qp_lock, flags); |
| 1960 | |
| 1961 | /* Check for room in outstanding command list. */ |
| 1962 | handle = req->current_outstanding_cmd; |
| 1963 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
| 1964 | handle++; |
| 1965 | if (handle == req->num_outstanding_cmds) |
| 1966 | handle = 1; |
| 1967 | if (!req->outstanding_cmds[handle]) |
| 1968 | break; |
| 1969 | } |
| 1970 | |
| 1971 | if (index == req->num_outstanding_cmds) |
| 1972 | goto queuing_error; |
| 1973 | |
| 1974 | /* Compute number of required data segments */ |
| 1975 | /* Map the sg table so we have an accurate count of sg entries needed */ |
| 1976 | if (scsi_sg_count(cmd)) { |
| 1977 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1978 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1979 | if (unlikely(!nseg)) |
| 1980 | goto queuing_error; |
| 1981 | else |
| 1982 | sp->flags |= SRB_DMA_VALID; |
| 1983 | |
| 1984 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1985 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 1986 | struct qla2_sgx sgx; |
| 1987 | uint32_t partial; |
| 1988 | |
| 1989 | memset(&sgx, 0, sizeof(struct qla2_sgx)); |
| 1990 | sgx.tot_bytes = scsi_bufflen(cmd); |
| 1991 | sgx.cur_sg = scsi_sglist(cmd); |
| 1992 | sgx.sp = sp; |
| 1993 | |
| 1994 | nseg = 0; |
| 1995 | while (qla24xx_get_one_block_sg( |
| 1996 | cmd->device->sector_size, &sgx, &partial)) |
| 1997 | nseg++; |
| 1998 | } |
| 1999 | } else |
| 2000 | nseg = 0; |
| 2001 | |
| 2002 | /* number of required data segments */ |
| 2003 | tot_dsds = nseg; |
| 2004 | |
| 2005 | /* Compute number of required protection segments */ |
| 2006 | if (qla24xx_configure_prot_mode(sp, &fw_prot_opts)) { |
| 2007 | nseg = dma_map_sg(&ha->pdev->dev, scsi_prot_sglist(cmd), |
| 2008 | scsi_prot_sg_count(cmd), cmd->sc_data_direction); |
| 2009 | if (unlikely(!nseg)) |
| 2010 | goto queuing_error; |
| 2011 | else |
| 2012 | sp->flags |= SRB_CRC_PROT_DMA_VALID; |
| 2013 | |
| 2014 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 2015 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 2016 | nseg = scsi_bufflen(cmd) / cmd->device->sector_size; |
| 2017 | } |
| 2018 | } else { |
| 2019 | nseg = 0; |
| 2020 | } |
| 2021 | |
| 2022 | req_cnt = 1; |
| 2023 | /* Total Data and protection sg segment(s) */ |
| 2024 | tot_prot_dsds = nseg; |
| 2025 | tot_dsds += nseg; |
| 2026 | if (req->cnt < (req_cnt + 2)) { |
| 2027 | cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr : |
| 2028 | RD_REG_DWORD_RELAXED(req->req_q_out); |
| 2029 | if (req->ring_index < cnt) |
| 2030 | req->cnt = cnt - req->ring_index; |
| 2031 | else |
| 2032 | req->cnt = req->length - |
| 2033 | (req->ring_index - cnt); |
| 2034 | if (req->cnt < (req_cnt + 2)) |
| 2035 | goto queuing_error; |
| 2036 | } |
| 2037 | |
| 2038 | status |= QDSS_GOT_Q_SPACE; |
| 2039 | |
| 2040 | /* Build header part of command packet (excluding the OPCODE). */ |
| 2041 | req->current_outstanding_cmd = handle; |
| 2042 | req->outstanding_cmds[handle] = sp; |
| 2043 | sp->handle = handle; |
| 2044 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
| 2045 | req->cnt -= req_cnt; |
| 2046 | |
| 2047 | /* Fill-in common area */ |
| 2048 | cmd_pkt = (struct cmd_type_crc_2 *)req->ring_ptr; |
| 2049 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 2050 | |
| 2051 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 2052 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 2053 | |
| 2054 | /* Set NPORT-ID and LUN number*/ |
| 2055 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2056 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2057 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 2058 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
| 2059 | |
| 2060 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
| 2061 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
| 2062 | |
| 2063 | /* Total Data and protection segment(s) */ |
| 2064 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 2065 | |
| 2066 | /* Build IOCB segments and adjust for data protection segments */ |
| 2067 | if (qla24xx_build_scsi_crc_2_iocbs(sp, (struct cmd_type_crc_2 *) |
| 2068 | req->ring_ptr, tot_dsds, tot_prot_dsds, fw_prot_opts) != |
| 2069 | QLA_SUCCESS) |
| 2070 | goto queuing_error; |
| 2071 | |
| 2072 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 2073 | cmd_pkt->timeout = cpu_to_le16(0); |
| 2074 | wmb(); |
| 2075 | |
| 2076 | /* Adjust ring index. */ |
| 2077 | req->ring_index++; |
| 2078 | if (req->ring_index == req->length) { |
| 2079 | req->ring_index = 0; |
| 2080 | req->ring_ptr = req->ring; |
| 2081 | } else |
| 2082 | req->ring_ptr++; |
| 2083 | |
| 2084 | /* Set chip new ring index. */ |
| 2085 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 2086 | |
| 2087 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 2088 | if (vha->flags.process_response_queue && |
| 2089 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 2090 | qla24xx_process_response_queue(vha, rsp); |
| 2091 | |
| 2092 | spin_unlock_irqrestore(&qpair->qp_lock, flags); |
| 2093 | |
| 2094 | return QLA_SUCCESS; |
| 2095 | |
| 2096 | queuing_error: |
| 2097 | if (status & QDSS_GOT_Q_SPACE) { |
| 2098 | req->outstanding_cmds[handle] = NULL; |
| 2099 | req->cnt += req_cnt; |
| 2100 | } |
| 2101 | /* Cleanup will be performed by the caller (queuecommand) */ |
| 2102 | |
| 2103 | spin_unlock_irqrestore(&qpair->qp_lock, flags); |
| 2104 | return QLA_FUNCTION_FAILED; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 2105 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2106 | |
| 2107 | /* Generic Control-SRB manipulation functions. */ |
Arun Easi | b6a029e | 2014-09-25 06:14:52 -0400 | [diff] [blame] | 2108 | |
| 2109 | /* hardware_lock assumed to be held. */ |
| 2110 | void * |
| 2111 | qla2x00_alloc_iocbs_ready(scsi_qla_host_t *vha, srb_t *sp) |
| 2112 | { |
| 2113 | if (qla2x00_reset_active(vha)) |
| 2114 | return NULL; |
| 2115 | |
| 2116 | return qla2x00_alloc_iocbs(vha, sp); |
| 2117 | } |
| 2118 | |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 2119 | void * |
| 2120 | qla2x00_alloc_iocbs(scsi_qla_host_t *vha, srb_t *sp) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2121 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2122 | struct qla_hw_data *ha = vha->hw; |
| 2123 | struct req_que *req = ha->req_q_map[0]; |
Bart Van Assche | 118e2ef | 2015-07-09 07:24:27 -0700 | [diff] [blame] | 2124 | device_reg_t *reg = ISP_QUE_REG(ha, req->id); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2125 | uint32_t index, handle; |
| 2126 | request_t *pkt; |
| 2127 | uint16_t cnt, req_cnt; |
| 2128 | |
| 2129 | pkt = NULL; |
| 2130 | req_cnt = 1; |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 2131 | handle = 0; |
| 2132 | |
| 2133 | if (!sp) |
| 2134 | goto skip_cmd_array; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2135 | |
| 2136 | /* Check for room in outstanding command list. */ |
| 2137 | handle = req->current_outstanding_cmd; |
Chad Dupuis | 4b4f30c | 2014-03-07 02:43:52 -0500 | [diff] [blame] | 2138 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2139 | handle++; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2140 | if (handle == req->num_outstanding_cmds) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2141 | handle = 1; |
| 2142 | if (!req->outstanding_cmds[handle]) |
| 2143 | break; |
| 2144 | } |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2145 | if (index == req->num_outstanding_cmds) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2146 | ql_log(ql_log_warn, vha, 0x700b, |
Masanari Iida | d6a0358 | 2012-08-22 14:20:58 -0400 | [diff] [blame] | 2147 | "No room on outstanding cmd array.\n"); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2148 | goto queuing_error; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2149 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2150 | |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 2151 | /* Prep command array. */ |
| 2152 | req->current_outstanding_cmd = handle; |
| 2153 | req->outstanding_cmds[handle] = sp; |
| 2154 | sp->handle = handle; |
| 2155 | |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 2156 | /* Adjust entry-counts as needed. */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2157 | if (sp->type != SRB_SCSI_CMD) |
| 2158 | req_cnt = sp->iocbs; |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 2159 | |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 2160 | skip_cmd_array: |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2161 | /* Check for room on request queue. */ |
Himanshu Madhani | 9400703 | 2014-09-25 06:14:46 -0400 | [diff] [blame] | 2162 | if (req->cnt < req_cnt + 2) { |
Chad Dupuis | f73cb69 | 2014-02-26 04:15:06 -0500 | [diff] [blame] | 2163 | if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2164 | cnt = RD_REG_DWORD(®->isp25mq.req_q_out); |
Atul Deshmukh | 7ec0eff | 2013-08-27 01:37:28 -0400 | [diff] [blame] | 2165 | else if (IS_P3P_TYPE(ha)) |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 2166 | cnt = RD_REG_DWORD(®->isp82.req_q_out); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2167 | else if (IS_FWI2_CAPABLE(ha)) |
| 2168 | cnt = RD_REG_DWORD(®->isp24.req_q_out); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2169 | else if (IS_QLAFX00(ha)) |
| 2170 | cnt = RD_REG_DWORD(®->ispfx00.req_q_out); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2171 | else |
| 2172 | cnt = qla2x00_debounce_register( |
| 2173 | ISP_REQ_Q_OUT(ha, ®->isp)); |
| 2174 | |
| 2175 | if (req->ring_index < cnt) |
| 2176 | req->cnt = cnt - req->ring_index; |
| 2177 | else |
| 2178 | req->cnt = req->length - |
| 2179 | (req->ring_index - cnt); |
| 2180 | } |
Himanshu Madhani | 9400703 | 2014-09-25 06:14:46 -0400 | [diff] [blame] | 2181 | if (req->cnt < req_cnt + 2) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2182 | goto queuing_error; |
| 2183 | |
| 2184 | /* Prep packet */ |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2185 | req->cnt -= req_cnt; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2186 | pkt = req->ring_ptr; |
| 2187 | memset(pkt, 0, REQUEST_ENTRY_SIZE); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2188 | if (IS_QLAFX00(ha)) { |
Saurav Kashyap | 1f8deef | 2013-06-25 11:27:21 -0400 | [diff] [blame] | 2189 | WRT_REG_BYTE((void __iomem *)&pkt->entry_count, req_cnt); |
| 2190 | WRT_REG_WORD((void __iomem *)&pkt->handle, handle); |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 2191 | } else { |
| 2192 | pkt->entry_count = req_cnt; |
| 2193 | pkt->handle = handle; |
| 2194 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2195 | |
| 2196 | queuing_error: |
Himanshu Madhani | ce1025c | 2015-12-17 14:56:58 -0500 | [diff] [blame] | 2197 | vha->tgt_counters.num_alloc_iocb_failed++; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2198 | return pkt; |
| 2199 | } |
| 2200 | |
| 2201 | static void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2202 | qla24xx_login_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 2203 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2204 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2205 | |
| 2206 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 2207 | logio->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 2208 | if (lio->u.logio.flags & SRB_LOGIN_COND_PLOGI) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2209 | logio->control_flags |= cpu_to_le16(LCF_COND_PLOGI); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 2210 | if (lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2211 | logio->control_flags |= cpu_to_le16(LCF_SKIP_PRLI); |
| 2212 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2213 | logio->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2214 | logio->port_id[1] = sp->fcport->d_id.b.area; |
| 2215 | logio->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2216 | logio->vp_index = sp->vha->vp_idx; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | static void |
| 2220 | qla2x00_login_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 2221 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2222 | struct qla_hw_data *ha = sp->vha->hw; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2223 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2224 | uint16_t opts; |
| 2225 | |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 2226 | mbx->entry_type = MBX_IOCB_TYPE; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2227 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 2228 | mbx->mb0 = cpu_to_le16(MBC_LOGIN_FABRIC_PORT); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 2229 | opts = lio->u.logio.flags & SRB_LOGIN_COND_PLOGI ? BIT_0 : 0; |
| 2230 | opts |= lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI ? BIT_1 : 0; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2231 | if (HAS_EXTENDED_IDS(ha)) { |
| 2232 | mbx->mb1 = cpu_to_le16(sp->fcport->loop_id); |
| 2233 | mbx->mb10 = cpu_to_le16(opts); |
| 2234 | } else { |
| 2235 | mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | opts); |
| 2236 | } |
| 2237 | mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain); |
| 2238 | mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 | |
| 2239 | sp->fcport->d_id.b.al_pa); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2240 | mbx->mb9 = cpu_to_le16(sp->vha->vp_idx); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | static void |
| 2244 | qla24xx_logout_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 2245 | { |
| 2246 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 2247 | logio->control_flags = |
| 2248 | cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 2249 | if (!sp->fcport->se_sess || |
Quinn Tran | 5d96483 | 2017-01-19 22:27:59 -0800 | [diff] [blame] | 2250 | !sp->fcport->keep_nport_handle) |
Alexei Potashnik | a6ca887 | 2015-07-14 16:00:44 -0400 | [diff] [blame] | 2251 | logio->control_flags |= cpu_to_le16(LCF_FREE_NPORT); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2252 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2253 | logio->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2254 | logio->port_id[1] = sp->fcport->d_id.b.area; |
| 2255 | logio->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2256 | logio->vp_index = sp->vha->vp_idx; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2257 | } |
| 2258 | |
| 2259 | static void |
| 2260 | qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 2261 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2262 | struct qla_hw_data *ha = sp->vha->hw; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2263 | |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 2264 | mbx->entry_type = MBX_IOCB_TYPE; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2265 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 2266 | mbx->mb0 = cpu_to_le16(MBC_LOGOUT_FABRIC_PORT); |
| 2267 | mbx->mb1 = HAS_EXTENDED_IDS(ha) ? |
| 2268 | cpu_to_le16(sp->fcport->loop_id): |
| 2269 | cpu_to_le16(sp->fcport->loop_id << 8); |
| 2270 | mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain); |
| 2271 | mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 | |
| 2272 | sp->fcport->d_id.b.al_pa); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2273 | mbx->mb9 = cpu_to_le16(sp->vha->vp_idx); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2274 | /* Implicit: mbx->mbx10 = 0. */ |
| 2275 | } |
| 2276 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2277 | static void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2278 | qla24xx_adisc_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 2279 | { |
| 2280 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 2281 | logio->control_flags = cpu_to_le16(LCF_COMMAND_ADISC); |
| 2282 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2283 | logio->vp_index = sp->vha->vp_idx; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
| 2286 | static void |
| 2287 | qla2x00_adisc_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 2288 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2289 | struct qla_hw_data *ha = sp->vha->hw; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2290 | |
| 2291 | mbx->entry_type = MBX_IOCB_TYPE; |
| 2292 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 2293 | mbx->mb0 = cpu_to_le16(MBC_GET_PORT_DATABASE); |
| 2294 | if (HAS_EXTENDED_IDS(ha)) { |
| 2295 | mbx->mb1 = cpu_to_le16(sp->fcport->loop_id); |
| 2296 | mbx->mb10 = cpu_to_le16(BIT_0); |
| 2297 | } else { |
| 2298 | mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | BIT_0); |
| 2299 | } |
| 2300 | mbx->mb2 = cpu_to_le16(MSW(ha->async_pd_dma)); |
| 2301 | mbx->mb3 = cpu_to_le16(LSW(ha->async_pd_dma)); |
| 2302 | mbx->mb6 = cpu_to_le16(MSW(MSD(ha->async_pd_dma))); |
| 2303 | mbx->mb7 = cpu_to_le16(LSW(MSD(ha->async_pd_dma))); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2304 | mbx->mb9 = cpu_to_le16(sp->vha->vp_idx); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2305 | } |
| 2306 | |
| 2307 | static void |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 2308 | qla24xx_tm_iocb(srb_t *sp, struct tsk_mgmt_entry *tsk) |
| 2309 | { |
| 2310 | uint32_t flags; |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 2311 | uint64_t lun; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 2312 | struct fc_port *fcport = sp->fcport; |
| 2313 | scsi_qla_host_t *vha = fcport->vha; |
| 2314 | struct qla_hw_data *ha = vha->hw; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2315 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 2316 | struct req_que *req = vha->req; |
| 2317 | |
| 2318 | flags = iocb->u.tmf.flags; |
| 2319 | lun = iocb->u.tmf.lun; |
| 2320 | |
| 2321 | tsk->entry_type = TSK_MGMT_IOCB_TYPE; |
| 2322 | tsk->entry_count = 1; |
| 2323 | tsk->handle = MAKE_HANDLE(req->id, tsk->handle); |
| 2324 | tsk->nport_handle = cpu_to_le16(fcport->loop_id); |
| 2325 | tsk->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
| 2326 | tsk->control_flags = cpu_to_le32(flags); |
| 2327 | tsk->port_id[0] = fcport->d_id.b.al_pa; |
| 2328 | tsk->port_id[1] = fcport->d_id.b.area; |
| 2329 | tsk->port_id[2] = fcport->d_id.b.domain; |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame] | 2330 | tsk->vp_index = fcport->vha->vp_idx; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 2331 | |
| 2332 | if (flags == TCF_LUN_RESET) { |
| 2333 | int_to_scsilun(lun, &tsk->lun); |
| 2334 | host_to_fcp_swap((uint8_t *)&tsk->lun, |
| 2335 | sizeof(tsk->lun)); |
| 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2340 | qla2x00_els_dcmd_sp_free(void *data) |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2341 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2342 | srb_t *sp = data; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2343 | struct srb_iocb *elsio = &sp->u.iocb_cmd; |
| 2344 | |
| 2345 | kfree(sp->fcport); |
| 2346 | |
| 2347 | if (elsio->u.els_logo.els_logo_pyld) |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2348 | dma_free_coherent(&sp->vha->hw->pdev->dev, DMA_POOL_SIZE, |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2349 | elsio->u.els_logo.els_logo_pyld, |
| 2350 | elsio->u.els_logo.els_logo_pyld_dma); |
| 2351 | |
| 2352 | del_timer(&elsio->timer); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2353 | qla2x00_rel_sp(sp); |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2354 | } |
| 2355 | |
| 2356 | static void |
| 2357 | qla2x00_els_dcmd_iocb_timeout(void *data) |
| 2358 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2359 | srb_t *sp = data; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2360 | fc_port_t *fcport = sp->fcport; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2361 | struct scsi_qla_host *vha = sp->vha; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2362 | struct qla_hw_data *ha = vha->hw; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2363 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2364 | unsigned long flags = 0; |
| 2365 | |
| 2366 | ql_dbg(ql_dbg_io, vha, 0x3069, |
| 2367 | "%s Timeout, hdl=%x, portid=%02x%02x%02x\n", |
| 2368 | sp->name, sp->handle, fcport->d_id.b.domain, fcport->d_id.b.area, |
| 2369 | fcport->d_id.b.al_pa); |
| 2370 | |
| 2371 | /* Abort the exchange */ |
| 2372 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2373 | if (ha->isp_ops->abort_command(sp)) { |
| 2374 | ql_dbg(ql_dbg_io, vha, 0x3070, |
| 2375 | "mbx abort_command failed.\n"); |
| 2376 | } else { |
| 2377 | ql_dbg(ql_dbg_io, vha, 0x3071, |
| 2378 | "mbx abort_command success.\n"); |
| 2379 | } |
| 2380 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2381 | |
| 2382 | complete(&lio->u.els_logo.comp); |
| 2383 | } |
| 2384 | |
| 2385 | static void |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2386 | qla2x00_els_dcmd_sp_done(void *ptr, int res) |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2387 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2388 | srb_t *sp = ptr; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2389 | fc_port_t *fcport = sp->fcport; |
| 2390 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2391 | struct scsi_qla_host *vha = sp->vha; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2392 | |
| 2393 | ql_dbg(ql_dbg_io, vha, 0x3072, |
| 2394 | "%s hdl=%x, portid=%02x%02x%02x done\n", |
| 2395 | sp->name, sp->handle, fcport->d_id.b.domain, |
| 2396 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
| 2397 | |
| 2398 | complete(&lio->u.els_logo.comp); |
| 2399 | } |
| 2400 | |
| 2401 | int |
| 2402 | qla24xx_els_dcmd_iocb(scsi_qla_host_t *vha, int els_opcode, |
| 2403 | port_id_t remote_did) |
| 2404 | { |
| 2405 | srb_t *sp; |
| 2406 | fc_port_t *fcport = NULL; |
| 2407 | struct srb_iocb *elsio = NULL; |
| 2408 | struct qla_hw_data *ha = vha->hw; |
| 2409 | struct els_logo_payload logo_pyld; |
| 2410 | int rval = QLA_SUCCESS; |
| 2411 | |
| 2412 | fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL); |
| 2413 | if (!fcport) { |
| 2414 | ql_log(ql_log_info, vha, 0x70e5, "fcport allocation failed\n"); |
| 2415 | return -ENOMEM; |
| 2416 | } |
| 2417 | |
| 2418 | /* Alloc SRB structure */ |
| 2419 | sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL); |
| 2420 | if (!sp) { |
| 2421 | kfree(fcport); |
| 2422 | ql_log(ql_log_info, vha, 0x70e6, |
| 2423 | "SRB allocation failed\n"); |
| 2424 | return -ENOMEM; |
| 2425 | } |
| 2426 | |
| 2427 | elsio = &sp->u.iocb_cmd; |
| 2428 | fcport->loop_id = 0xFFFF; |
| 2429 | fcport->d_id.b.domain = remote_did.b.domain; |
| 2430 | fcport->d_id.b.area = remote_did.b.area; |
| 2431 | fcport->d_id.b.al_pa = remote_did.b.al_pa; |
| 2432 | |
| 2433 | ql_dbg(ql_dbg_io, vha, 0x3073, "portid=%02x%02x%02x done\n", |
| 2434 | fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa); |
| 2435 | |
| 2436 | sp->type = SRB_ELS_DCMD; |
| 2437 | sp->name = "ELS_DCMD"; |
| 2438 | sp->fcport = fcport; |
| 2439 | qla2x00_init_timer(sp, ELS_DCMD_TIMEOUT); |
| 2440 | elsio->timeout = qla2x00_els_dcmd_iocb_timeout; |
| 2441 | sp->done = qla2x00_els_dcmd_sp_done; |
| 2442 | sp->free = qla2x00_els_dcmd_sp_free; |
| 2443 | |
| 2444 | elsio->u.els_logo.els_logo_pyld = dma_alloc_coherent(&ha->pdev->dev, |
| 2445 | DMA_POOL_SIZE, &elsio->u.els_logo.els_logo_pyld_dma, |
| 2446 | GFP_KERNEL); |
| 2447 | |
| 2448 | if (!elsio->u.els_logo.els_logo_pyld) { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2449 | sp->free(sp); |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2450 | return QLA_FUNCTION_FAILED; |
| 2451 | } |
| 2452 | |
| 2453 | memset(&logo_pyld, 0, sizeof(struct els_logo_payload)); |
| 2454 | |
| 2455 | elsio->u.els_logo.els_cmd = els_opcode; |
| 2456 | logo_pyld.opcode = els_opcode; |
| 2457 | logo_pyld.s_id[0] = vha->d_id.b.al_pa; |
| 2458 | logo_pyld.s_id[1] = vha->d_id.b.area; |
| 2459 | logo_pyld.s_id[2] = vha->d_id.b.domain; |
| 2460 | host_to_fcp_swap(logo_pyld.s_id, sizeof(uint32_t)); |
| 2461 | memcpy(&logo_pyld.wwpn, vha->port_name, WWN_SIZE); |
| 2462 | |
| 2463 | memcpy(elsio->u.els_logo.els_logo_pyld, &logo_pyld, |
| 2464 | sizeof(struct els_logo_payload)); |
| 2465 | |
| 2466 | rval = qla2x00_start_sp(sp); |
| 2467 | if (rval != QLA_SUCCESS) { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2468 | sp->free(sp); |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2469 | return QLA_FUNCTION_FAILED; |
| 2470 | } |
| 2471 | |
| 2472 | ql_dbg(ql_dbg_io, vha, 0x3074, |
| 2473 | "%s LOGO sent, hdl=%x, loopid=%x, portid=%02x%02x%02x.\n", |
| 2474 | sp->name, sp->handle, fcport->loop_id, fcport->d_id.b.domain, |
| 2475 | fcport->d_id.b.area, fcport->d_id.b.al_pa); |
| 2476 | |
| 2477 | wait_for_completion(&elsio->u.els_logo.comp); |
| 2478 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2479 | sp->free(sp); |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2480 | return rval; |
| 2481 | } |
| 2482 | |
| 2483 | static void |
| 2484 | qla24xx_els_logo_iocb(srb_t *sp, struct els_entry_24xx *els_iocb) |
| 2485 | { |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2486 | scsi_qla_host_t *vha = sp->vha; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2487 | struct srb_iocb *elsio = &sp->u.iocb_cmd; |
| 2488 | |
| 2489 | els_iocb->entry_type = ELS_IOCB_TYPE; |
| 2490 | els_iocb->entry_count = 1; |
| 2491 | els_iocb->sys_define = 0; |
| 2492 | els_iocb->entry_status = 0; |
| 2493 | els_iocb->handle = sp->handle; |
| 2494 | els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2495 | els_iocb->tx_dsd_count = 1; |
| 2496 | els_iocb->vp_index = vha->vp_idx; |
| 2497 | els_iocb->sof_type = EST_SOFI3; |
| 2498 | els_iocb->rx_dsd_count = 0; |
| 2499 | els_iocb->opcode = elsio->u.els_logo.els_cmd; |
| 2500 | |
| 2501 | els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2502 | els_iocb->port_id[1] = sp->fcport->d_id.b.area; |
| 2503 | els_iocb->port_id[2] = sp->fcport->d_id.b.domain; |
| 2504 | els_iocb->control_flags = 0; |
| 2505 | |
| 2506 | els_iocb->tx_byte_count = sizeof(struct els_logo_payload); |
| 2507 | els_iocb->tx_address[0] = |
| 2508 | cpu_to_le32(LSD(elsio->u.els_logo.els_logo_pyld_dma)); |
| 2509 | els_iocb->tx_address[1] = |
| 2510 | cpu_to_le32(MSD(elsio->u.els_logo.els_logo_pyld_dma)); |
| 2511 | els_iocb->tx_len = cpu_to_le32(sizeof(struct els_logo_payload)); |
| 2512 | |
| 2513 | els_iocb->rx_byte_count = 0; |
| 2514 | els_iocb->rx_address[0] = 0; |
| 2515 | els_iocb->rx_address[1] = 0; |
| 2516 | els_iocb->rx_len = 0; |
| 2517 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2518 | sp->vha->qla_stats.control_requests++; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 2519 | } |
| 2520 | |
| 2521 | static void |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2522 | qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb) |
| 2523 | { |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 2524 | struct bsg_job *bsg_job = sp->u.bsg_job; |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 2525 | struct fc_bsg_request *bsg_request = bsg_job->request; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2526 | |
| 2527 | els_iocb->entry_type = ELS_IOCB_TYPE; |
| 2528 | els_iocb->entry_count = 1; |
| 2529 | els_iocb->sys_define = 0; |
| 2530 | els_iocb->entry_status = 0; |
| 2531 | els_iocb->handle = sp->handle; |
| 2532 | els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2533 | els_iocb->tx_dsd_count = cpu_to_le16(bsg_job->request_payload.sg_cnt); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2534 | els_iocb->vp_index = sp->vha->vp_idx; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2535 | els_iocb->sof_type = EST_SOFI3; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2536 | els_iocb->rx_dsd_count = cpu_to_le16(bsg_job->reply_payload.sg_cnt); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2537 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 2538 | els_iocb->opcode = |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2539 | sp->type == SRB_ELS_CMD_RPT ? |
Johannes Thumshirn | 01e0e15 | 2016-11-17 10:31:12 +0100 | [diff] [blame] | 2540 | bsg_request->rqst_data.r_els.els_code : |
| 2541 | bsg_request->rqst_data.h_els.command_code; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2542 | els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2543 | els_iocb->port_id[1] = sp->fcport->d_id.b.area; |
| 2544 | els_iocb->port_id[2] = sp->fcport->d_id.b.domain; |
| 2545 | els_iocb->control_flags = 0; |
| 2546 | els_iocb->rx_byte_count = |
| 2547 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2548 | els_iocb->tx_byte_count = |
| 2549 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2550 | |
| 2551 | els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2552 | (bsg_job->request_payload.sg_list))); |
| 2553 | els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2554 | (bsg_job->request_payload.sg_list))); |
| 2555 | els_iocb->tx_len = cpu_to_le32(sg_dma_len |
| 2556 | (bsg_job->request_payload.sg_list)); |
| 2557 | |
| 2558 | els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2559 | (bsg_job->reply_payload.sg_list))); |
| 2560 | els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2561 | (bsg_job->reply_payload.sg_list))); |
| 2562 | els_iocb->rx_len = cpu_to_le32(sg_dma_len |
| 2563 | (bsg_job->reply_payload.sg_list)); |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 2564 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2565 | sp->vha->qla_stats.control_requests++; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2566 | } |
| 2567 | |
| 2568 | static void |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2569 | qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb) |
| 2570 | { |
| 2571 | uint16_t avail_dsds; |
| 2572 | uint32_t *cur_dsd; |
| 2573 | struct scatterlist *sg; |
| 2574 | int index; |
| 2575 | uint16_t tot_dsds; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2576 | scsi_qla_host_t *vha = sp->vha; |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2577 | struct qla_hw_data *ha = vha->hw; |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 2578 | struct bsg_job *bsg_job = sp->u.bsg_job; |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2579 | int loop_iterartion = 0; |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2580 | int entry_count = 1; |
| 2581 | |
| 2582 | memset(ct_iocb, 0, sizeof(ms_iocb_entry_t)); |
| 2583 | ct_iocb->entry_type = CT_IOCB_TYPE; |
| 2584 | ct_iocb->entry_status = 0; |
| 2585 | ct_iocb->handle1 = sp->handle; |
| 2586 | SET_TARGET_ID(ha, ct_iocb->loop_id, sp->fcport->loop_id); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2587 | ct_iocb->status = cpu_to_le16(0); |
| 2588 | ct_iocb->control_flags = cpu_to_le16(0); |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2589 | ct_iocb->timeout = 0; |
| 2590 | ct_iocb->cmd_dsd_count = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2591 | cpu_to_le16(bsg_job->request_payload.sg_cnt); |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2592 | ct_iocb->total_dsd_count = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2593 | cpu_to_le16(bsg_job->request_payload.sg_cnt + 1); |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2594 | ct_iocb->req_bytecount = |
| 2595 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2596 | ct_iocb->rsp_bytecount = |
| 2597 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2598 | |
| 2599 | ct_iocb->dseg_req_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2600 | (bsg_job->request_payload.sg_list))); |
| 2601 | ct_iocb->dseg_req_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2602 | (bsg_job->request_payload.sg_list))); |
| 2603 | ct_iocb->dseg_req_length = ct_iocb->req_bytecount; |
| 2604 | |
| 2605 | ct_iocb->dseg_rsp_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2606 | (bsg_job->reply_payload.sg_list))); |
| 2607 | ct_iocb->dseg_rsp_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2608 | (bsg_job->reply_payload.sg_list))); |
| 2609 | ct_iocb->dseg_rsp_length = ct_iocb->rsp_bytecount; |
| 2610 | |
| 2611 | avail_dsds = 1; |
| 2612 | cur_dsd = (uint32_t *)ct_iocb->dseg_rsp_address; |
| 2613 | index = 0; |
| 2614 | tot_dsds = bsg_job->reply_payload.sg_cnt; |
| 2615 | |
| 2616 | for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) { |
| 2617 | dma_addr_t sle_dma; |
| 2618 | cont_a64_entry_t *cont_pkt; |
| 2619 | |
| 2620 | /* Allocate additional continuation packets? */ |
| 2621 | if (avail_dsds == 0) { |
| 2622 | /* |
| 2623 | * Five DSDs are available in the Cont. |
| 2624 | * Type 1 IOCB. |
| 2625 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2626 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, |
| 2627 | vha->hw->req_q_map[0]); |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2628 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 2629 | avail_dsds = 5; |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2630 | entry_count++; |
| 2631 | } |
| 2632 | |
| 2633 | sle_dma = sg_dma_address(sg); |
| 2634 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 2635 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 2636 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 2637 | loop_iterartion++; |
| 2638 | avail_dsds--; |
| 2639 | } |
| 2640 | ct_iocb->entry_count = entry_count; |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 2641 | |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2642 | sp->vha->qla_stats.control_requests++; |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2643 | } |
| 2644 | |
| 2645 | static void |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2646 | qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb) |
| 2647 | { |
| 2648 | uint16_t avail_dsds; |
| 2649 | uint32_t *cur_dsd; |
| 2650 | struct scatterlist *sg; |
| 2651 | int index; |
| 2652 | uint16_t tot_dsds; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2653 | scsi_qla_host_t *vha = sp->vha; |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2654 | struct qla_hw_data *ha = vha->hw; |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 2655 | struct bsg_job *bsg_job = sp->u.bsg_job; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2656 | int loop_iterartion = 0; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2657 | int entry_count = 1; |
| 2658 | |
| 2659 | ct_iocb->entry_type = CT_IOCB_TYPE; |
| 2660 | ct_iocb->entry_status = 0; |
| 2661 | ct_iocb->sys_define = 0; |
| 2662 | ct_iocb->handle = sp->handle; |
| 2663 | |
| 2664 | ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2665 | ct_iocb->vp_index = sp->vha->vp_idx; |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2666 | ct_iocb->comp_status = cpu_to_le16(0); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2667 | |
| 2668 | ct_iocb->cmd_dsd_count = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2669 | cpu_to_le16(bsg_job->request_payload.sg_cnt); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2670 | ct_iocb->timeout = 0; |
| 2671 | ct_iocb->rsp_dsd_count = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 2672 | cpu_to_le16(bsg_job->reply_payload.sg_cnt); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2673 | ct_iocb->rsp_byte_count = |
| 2674 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2675 | ct_iocb->cmd_byte_count = |
| 2676 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2677 | ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2678 | (bsg_job->request_payload.sg_list))); |
| 2679 | ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2680 | (bsg_job->request_payload.sg_list))); |
| 2681 | ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len |
| 2682 | (bsg_job->request_payload.sg_list)); |
| 2683 | |
| 2684 | avail_dsds = 1; |
| 2685 | cur_dsd = (uint32_t *)ct_iocb->dseg_1_address; |
| 2686 | index = 0; |
| 2687 | tot_dsds = bsg_job->reply_payload.sg_cnt; |
| 2688 | |
| 2689 | for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) { |
| 2690 | dma_addr_t sle_dma; |
| 2691 | cont_a64_entry_t *cont_pkt; |
| 2692 | |
| 2693 | /* Allocate additional continuation packets? */ |
| 2694 | if (avail_dsds == 0) { |
| 2695 | /* |
| 2696 | * Five DSDs are available in the Cont. |
| 2697 | * Type 1 IOCB. |
| 2698 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2699 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, |
| 2700 | ha->req_q_map[0]); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2701 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 2702 | avail_dsds = 5; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2703 | entry_count++; |
| 2704 | } |
| 2705 | |
| 2706 | sle_dma = sg_dma_address(sg); |
| 2707 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 2708 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 2709 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 2710 | loop_iterartion++; |
| 2711 | avail_dsds--; |
| 2712 | } |
| 2713 | ct_iocb->entry_count = entry_count; |
| 2714 | } |
| 2715 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2716 | /* |
| 2717 | * qla82xx_start_scsi() - Send a SCSI command to the ISP |
| 2718 | * @sp: command to send to the ISP |
| 2719 | * |
| 2720 | * Returns non-zero if a failure occurred, else zero. |
| 2721 | */ |
| 2722 | int |
| 2723 | qla82xx_start_scsi(srb_t *sp) |
| 2724 | { |
Bart Van Assche | 52c8282 | 2015-07-09 07:23:26 -0700 | [diff] [blame] | 2725 | int nseg; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2726 | unsigned long flags; |
| 2727 | struct scsi_cmnd *cmd; |
| 2728 | uint32_t *clr_ptr; |
| 2729 | uint32_t index; |
| 2730 | uint32_t handle; |
| 2731 | uint16_t cnt; |
| 2732 | uint16_t req_cnt; |
| 2733 | uint16_t tot_dsds; |
| 2734 | struct device_reg_82xx __iomem *reg; |
| 2735 | uint32_t dbval; |
| 2736 | uint32_t *fcp_dl; |
| 2737 | uint8_t additional_cdb_len; |
| 2738 | struct ct6_dsd *ctx; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2739 | struct scsi_qla_host *vha = sp->vha; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2740 | struct qla_hw_data *ha = vha->hw; |
| 2741 | struct req_que *req = NULL; |
| 2742 | struct rsp_que *rsp = NULL; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2743 | |
| 2744 | /* Setup device pointers. */ |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2745 | reg = &ha->iobase->isp82; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2746 | cmd = GET_CMD_SP(sp); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2747 | req = vha->req; |
| 2748 | rsp = ha->rsp_q_map[0]; |
| 2749 | |
| 2750 | /* So we know we haven't pci_map'ed anything yet */ |
| 2751 | tot_dsds = 0; |
| 2752 | |
| 2753 | dbval = 0x04 | (ha->portnum << 5); |
| 2754 | |
| 2755 | /* Send marker if required */ |
| 2756 | if (vha->marker_needed != 0) { |
| 2757 | if (qla2x00_marker(vha, req, |
| 2758 | rsp, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) { |
| 2759 | ql_log(ql_log_warn, vha, 0x300c, |
| 2760 | "qla2x00_marker failed for cmd=%p.\n", cmd); |
| 2761 | return QLA_FUNCTION_FAILED; |
| 2762 | } |
| 2763 | vha->marker_needed = 0; |
| 2764 | } |
| 2765 | |
| 2766 | /* Acquire ring specific lock */ |
| 2767 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2768 | |
| 2769 | /* Check for room in outstanding command list. */ |
| 2770 | handle = req->current_outstanding_cmd; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2771 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2772 | handle++; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2773 | if (handle == req->num_outstanding_cmds) |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2774 | handle = 1; |
| 2775 | if (!req->outstanding_cmds[handle]) |
| 2776 | break; |
| 2777 | } |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 2778 | if (index == req->num_outstanding_cmds) |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2779 | goto queuing_error; |
| 2780 | |
| 2781 | /* Map the sg table so we have an accurate count of sg entries needed */ |
| 2782 | if (scsi_sg_count(cmd)) { |
| 2783 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 2784 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 2785 | if (unlikely(!nseg)) |
| 2786 | goto queuing_error; |
| 2787 | } else |
| 2788 | nseg = 0; |
| 2789 | |
| 2790 | tot_dsds = nseg; |
| 2791 | |
| 2792 | if (tot_dsds > ql2xshiftctondsd) { |
| 2793 | struct cmd_type_6 *cmd_pkt; |
| 2794 | uint16_t more_dsd_lists = 0; |
| 2795 | struct dsd_dma *dsd_ptr; |
| 2796 | uint16_t i; |
| 2797 | |
| 2798 | more_dsd_lists = qla24xx_calc_dsd_lists(tot_dsds); |
| 2799 | if ((more_dsd_lists + ha->gbl_dsd_inuse) >= NUM_DSD_CHAIN) { |
| 2800 | ql_dbg(ql_dbg_io, vha, 0x300d, |
| 2801 | "Num of DSD list %d is than %d for cmd=%p.\n", |
| 2802 | more_dsd_lists + ha->gbl_dsd_inuse, NUM_DSD_CHAIN, |
| 2803 | cmd); |
| 2804 | goto queuing_error; |
| 2805 | } |
| 2806 | |
| 2807 | if (more_dsd_lists <= ha->gbl_dsd_avail) |
| 2808 | goto sufficient_dsds; |
| 2809 | else |
| 2810 | more_dsd_lists -= ha->gbl_dsd_avail; |
| 2811 | |
| 2812 | for (i = 0; i < more_dsd_lists; i++) { |
| 2813 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 2814 | if (!dsd_ptr) { |
| 2815 | ql_log(ql_log_fatal, vha, 0x300e, |
| 2816 | "Failed to allocate memory for dsd_dma " |
| 2817 | "for cmd=%p.\n", cmd); |
| 2818 | goto queuing_error; |
| 2819 | } |
| 2820 | |
| 2821 | dsd_ptr->dsd_addr = dma_pool_alloc(ha->dl_dma_pool, |
| 2822 | GFP_ATOMIC, &dsd_ptr->dsd_list_dma); |
| 2823 | if (!dsd_ptr->dsd_addr) { |
| 2824 | kfree(dsd_ptr); |
| 2825 | ql_log(ql_log_fatal, vha, 0x300f, |
| 2826 | "Failed to allocate memory for dsd_addr " |
| 2827 | "for cmd=%p.\n", cmd); |
| 2828 | goto queuing_error; |
| 2829 | } |
| 2830 | list_add_tail(&dsd_ptr->list, &ha->gbl_dsd_list); |
| 2831 | ha->gbl_dsd_avail++; |
| 2832 | } |
| 2833 | |
| 2834 | sufficient_dsds: |
| 2835 | req_cnt = 1; |
| 2836 | |
| 2837 | if (req->cnt < (req_cnt + 2)) { |
| 2838 | cnt = (uint16_t)RD_REG_DWORD_RELAXED( |
| 2839 | ®->req_q_out[0]); |
| 2840 | if (req->ring_index < cnt) |
| 2841 | req->cnt = cnt - req->ring_index; |
| 2842 | else |
| 2843 | req->cnt = req->length - |
| 2844 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 2845 | if (req->cnt < (req_cnt + 2)) |
| 2846 | goto queuing_error; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2847 | } |
| 2848 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2849 | ctx = sp->u.scmd.ctx = |
| 2850 | mempool_alloc(ha->ctx_mempool, GFP_ATOMIC); |
| 2851 | if (!ctx) { |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2852 | ql_log(ql_log_fatal, vha, 0x3010, |
| 2853 | "Failed to allocate ctx for cmd=%p.\n", cmd); |
| 2854 | goto queuing_error; |
| 2855 | } |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2856 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2857 | memset(ctx, 0, sizeof(struct ct6_dsd)); |
| 2858 | ctx->fcp_cmnd = dma_pool_alloc(ha->fcp_cmnd_dma_pool, |
| 2859 | GFP_ATOMIC, &ctx->fcp_cmnd_dma); |
| 2860 | if (!ctx->fcp_cmnd) { |
| 2861 | ql_log(ql_log_fatal, vha, 0x3011, |
| 2862 | "Failed to allocate fcp_cmnd for cmd=%p.\n", cmd); |
Dan Carpenter | 841f97b | 2012-05-17 10:13:40 +0300 | [diff] [blame] | 2863 | goto queuing_error; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2864 | } |
| 2865 | |
| 2866 | /* Initialize the DSD list and dma handle */ |
| 2867 | INIT_LIST_HEAD(&ctx->dsd_list); |
| 2868 | ctx->dsd_use_cnt = 0; |
| 2869 | |
| 2870 | if (cmd->cmd_len > 16) { |
| 2871 | additional_cdb_len = cmd->cmd_len - 16; |
| 2872 | if ((cmd->cmd_len % 4) != 0) { |
| 2873 | /* SCSI command bigger than 16 bytes must be |
| 2874 | * multiple of 4 |
| 2875 | */ |
| 2876 | ql_log(ql_log_warn, vha, 0x3012, |
| 2877 | "scsi cmd len %d not multiple of 4 " |
| 2878 | "for cmd=%p.\n", cmd->cmd_len, cmd); |
| 2879 | goto queuing_error_fcp_cmnd; |
| 2880 | } |
| 2881 | ctx->fcp_cmnd_len = 12 + cmd->cmd_len + 4; |
| 2882 | } else { |
| 2883 | additional_cdb_len = 0; |
| 2884 | ctx->fcp_cmnd_len = 12 + 16 + 4; |
| 2885 | } |
| 2886 | |
| 2887 | cmd_pkt = (struct cmd_type_6 *)req->ring_ptr; |
| 2888 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 2889 | |
| 2890 | /* Zero out remaining portion of packet. */ |
| 2891 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
| 2892 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 2893 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 2894 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 2895 | |
| 2896 | /* Set NPORT-ID and LUN number*/ |
| 2897 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2898 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2899 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 2900 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2901 | cmd_pkt->vp_index = sp->vha->vp_idx; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2902 | |
| 2903 | /* Build IOCB segments */ |
| 2904 | if (qla24xx_build_scsi_type_6_iocbs(sp, cmd_pkt, tot_dsds)) |
| 2905 | goto queuing_error_fcp_cmnd; |
| 2906 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2907 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2908 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
| 2909 | |
| 2910 | /* build FCP_CMND IU */ |
| 2911 | memset(ctx->fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2912 | int_to_scsilun(cmd->device->lun, &ctx->fcp_cmnd->lun); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2913 | ctx->fcp_cmnd->additional_cdb_len = additional_cdb_len; |
| 2914 | |
| 2915 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 2916 | ctx->fcp_cmnd->additional_cdb_len |= 1; |
| 2917 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 2918 | ctx->fcp_cmnd->additional_cdb_len |= 2; |
| 2919 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 2920 | /* Populate the FCP_PRIO. */ |
| 2921 | if (ha->flags.fcp_prio_enabled) |
| 2922 | ctx->fcp_cmnd->task_attribute |= |
| 2923 | sp->fcport->fcp_prio << 3; |
| 2924 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2925 | memcpy(ctx->fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len); |
| 2926 | |
| 2927 | fcp_dl = (uint32_t *)(ctx->fcp_cmnd->cdb + 16 + |
| 2928 | additional_cdb_len); |
| 2929 | *fcp_dl = htonl((uint32_t)scsi_bufflen(cmd)); |
| 2930 | |
| 2931 | cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(ctx->fcp_cmnd_len); |
| 2932 | cmd_pkt->fcp_cmnd_dseg_address[0] = |
| 2933 | cpu_to_le32(LSD(ctx->fcp_cmnd_dma)); |
| 2934 | cmd_pkt->fcp_cmnd_dseg_address[1] = |
| 2935 | cpu_to_le32(MSD(ctx->fcp_cmnd_dma)); |
| 2936 | |
| 2937 | sp->flags |= SRB_FCP_CMND_DMA_VALID; |
| 2938 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
| 2939 | /* Set total data segment count. */ |
| 2940 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 2941 | /* Specify response queue number where |
| 2942 | * completion should happen |
| 2943 | */ |
| 2944 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
| 2945 | } else { |
| 2946 | struct cmd_type_7 *cmd_pkt; |
| 2947 | req_cnt = qla24xx_calc_iocbs(vha, tot_dsds); |
| 2948 | if (req->cnt < (req_cnt + 2)) { |
| 2949 | cnt = (uint16_t)RD_REG_DWORD_RELAXED( |
| 2950 | ®->req_q_out[0]); |
| 2951 | if (req->ring_index < cnt) |
| 2952 | req->cnt = cnt - req->ring_index; |
| 2953 | else |
| 2954 | req->cnt = req->length - |
| 2955 | (req->ring_index - cnt); |
| 2956 | } |
| 2957 | if (req->cnt < (req_cnt + 2)) |
| 2958 | goto queuing_error; |
| 2959 | |
| 2960 | cmd_pkt = (struct cmd_type_7 *)req->ring_ptr; |
| 2961 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 2962 | |
| 2963 | /* Zero out remaining portion of packet. */ |
| 2964 | /* tagged queuing modifier -- default is TSK_SIMPLE (0).*/ |
| 2965 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 2966 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 2967 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 2968 | |
| 2969 | /* Set NPORT-ID and LUN number*/ |
| 2970 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2971 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2972 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 2973 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 2974 | cmd_pkt->vp_index = sp->vha->vp_idx; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2975 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2976 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2977 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2978 | sizeof(cmd_pkt->lun)); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2979 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 2980 | /* Populate the FCP_PRIO. */ |
| 2981 | if (ha->flags.fcp_prio_enabled) |
| 2982 | cmd_pkt->task |= sp->fcport->fcp_prio << 3; |
| 2983 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2984 | /* Load SCSI command packet. */ |
| 2985 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 2986 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 2987 | |
| 2988 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
| 2989 | |
| 2990 | /* Build IOCB segments */ |
Michael Hernandez | d745952 | 2016-12-12 14:40:07 -0800 | [diff] [blame] | 2991 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds, req); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2992 | |
| 2993 | /* Set total data segment count. */ |
| 2994 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 2995 | /* Specify response queue number where |
| 2996 | * completion should happen. |
| 2997 | */ |
| 2998 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
| 2999 | |
| 3000 | } |
| 3001 | /* Build command packet. */ |
| 3002 | req->current_outstanding_cmd = handle; |
| 3003 | req->outstanding_cmds[handle] = sp; |
| 3004 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 3005 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 3006 | req->cnt -= req_cnt; |
| 3007 | wmb(); |
| 3008 | |
| 3009 | /* Adjust ring index. */ |
| 3010 | req->ring_index++; |
| 3011 | if (req->ring_index == req->length) { |
| 3012 | req->ring_index = 0; |
| 3013 | req->ring_ptr = req->ring; |
| 3014 | } else |
| 3015 | req->ring_ptr++; |
| 3016 | |
| 3017 | sp->flags |= SRB_DMA_VALID; |
| 3018 | |
| 3019 | /* Set chip new ring index. */ |
| 3020 | /* write, read and verify logic */ |
| 3021 | dbval = dbval | (req->id << 8) | (req->ring_index << 16); |
| 3022 | if (ql2xdbwr) |
Bart Van Assche | 8dfa4b5a | 2015-07-09 07:24:50 -0700 | [diff] [blame] | 3023 | qla82xx_wr_32(ha, (uintptr_t __force)ha->nxdb_wr_ptr, dbval); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 3024 | else { |
Bart Van Assche | 8dfa4b5a | 2015-07-09 07:24:50 -0700 | [diff] [blame] | 3025 | WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 3026 | wmb(); |
Bart Van Assche | 8dfa4b5a | 2015-07-09 07:24:50 -0700 | [diff] [blame] | 3027 | while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) { |
| 3028 | WRT_REG_DWORD(ha->nxdb_wr_ptr, dbval); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 3029 | wmb(); |
| 3030 | } |
| 3031 | } |
| 3032 | |
| 3033 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 3034 | if (vha->flags.process_response_queue && |
| 3035 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 3036 | qla24xx_process_response_queue(vha, rsp); |
| 3037 | |
| 3038 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3039 | return QLA_SUCCESS; |
| 3040 | |
| 3041 | queuing_error_fcp_cmnd: |
| 3042 | dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd, ctx->fcp_cmnd_dma); |
| 3043 | queuing_error: |
| 3044 | if (tot_dsds) |
| 3045 | scsi_dma_unmap(cmd); |
| 3046 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 3047 | if (sp->u.scmd.ctx) { |
| 3048 | mempool_free(sp->u.scmd.ctx, ha->ctx_mempool); |
| 3049 | sp->u.scmd.ctx = NULL; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 3050 | } |
| 3051 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3052 | |
| 3053 | return QLA_FUNCTION_FAILED; |
| 3054 | } |
| 3055 | |
Joe Carnuccio | 6d78e55 | 2014-09-25 05:17:05 -0400 | [diff] [blame] | 3056 | static void |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 3057 | qla24xx_abort_iocb(srb_t *sp, struct abort_entry_24xx *abt_iocb) |
| 3058 | { |
| 3059 | struct srb_iocb *aio = &sp->u.iocb_cmd; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 3060 | scsi_qla_host_t *vha = sp->vha; |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 3061 | struct req_que *req = vha->req; |
| 3062 | |
| 3063 | memset(abt_iocb, 0, sizeof(struct abort_entry_24xx)); |
| 3064 | abt_iocb->entry_type = ABORT_IOCB_TYPE; |
| 3065 | abt_iocb->entry_count = 1; |
| 3066 | abt_iocb->handle = cpu_to_le32(MAKE_HANDLE(req->id, sp->handle)); |
| 3067 | abt_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 3068 | abt_iocb->handle_to_abort = |
| 3069 | cpu_to_le32(MAKE_HANDLE(req->id, aio->u.abt.cmd_hndl)); |
| 3070 | abt_iocb->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 3071 | abt_iocb->port_id[1] = sp->fcport->d_id.b.area; |
| 3072 | abt_iocb->port_id[2] = sp->fcport->d_id.b.domain; |
| 3073 | abt_iocb->vp_index = vha->vp_idx; |
| 3074 | abt_iocb->req_que_no = cpu_to_le16(req->id); |
| 3075 | /* Send the command to the firmware */ |
| 3076 | wmb(); |
| 3077 | } |
| 3078 | |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3079 | static void |
| 3080 | qla2x00_mb_iocb(srb_t *sp, struct mbx_24xx_entry *mbx) |
| 3081 | { |
| 3082 | int i, sz; |
| 3083 | |
| 3084 | mbx->entry_type = MBX_IOCB_TYPE; |
| 3085 | mbx->handle = sp->handle; |
| 3086 | sz = min(ARRAY_SIZE(mbx->mb), ARRAY_SIZE(sp->u.iocb_cmd.u.mbx.out_mb)); |
| 3087 | |
| 3088 | for (i = 0; i < sz; i++) |
| 3089 | mbx->mb[i] = cpu_to_le16(sp->u.iocb_cmd.u.mbx.out_mb[i]); |
| 3090 | } |
| 3091 | |
| 3092 | static void |
| 3093 | qla2x00_ctpthru_cmd_iocb(srb_t *sp, struct ct_entry_24xx *ct_pkt) |
| 3094 | { |
| 3095 | sp->u.iocb_cmd.u.ctarg.iocb = ct_pkt; |
| 3096 | qla24xx_prep_ms_iocb(sp->vha, &sp->u.iocb_cmd.u.ctarg); |
| 3097 | ct_pkt->handle = sp->handle; |
| 3098 | } |
| 3099 | |
| 3100 | static void qla2x00_send_notify_ack_iocb(srb_t *sp, |
| 3101 | struct nack_to_isp *nack) |
| 3102 | { |
| 3103 | struct imm_ntfy_from_isp *ntfy = sp->u.iocb_cmd.u.nack.ntfy; |
| 3104 | |
| 3105 | nack->entry_type = NOTIFY_ACK_TYPE; |
| 3106 | nack->entry_count = 1; |
| 3107 | nack->ox_id = ntfy->ox_id; |
| 3108 | |
| 3109 | nack->u.isp24.handle = sp->handle; |
| 3110 | nack->u.isp24.nport_handle = ntfy->u.isp24.nport_handle; |
| 3111 | if (le16_to_cpu(ntfy->u.isp24.status) == IMM_NTFY_ELS) { |
| 3112 | nack->u.isp24.flags = ntfy->u.isp24.flags & |
| 3113 | cpu_to_le32(NOTIFY24XX_FLAGS_PUREX_IOCB); |
| 3114 | } |
| 3115 | nack->u.isp24.srr_rx_id = ntfy->u.isp24.srr_rx_id; |
| 3116 | nack->u.isp24.status = ntfy->u.isp24.status; |
| 3117 | nack->u.isp24.status_subcode = ntfy->u.isp24.status_subcode; |
| 3118 | nack->u.isp24.fw_handle = ntfy->u.isp24.fw_handle; |
| 3119 | nack->u.isp24.exchange_address = ntfy->u.isp24.exchange_address; |
| 3120 | nack->u.isp24.srr_rel_offs = ntfy->u.isp24.srr_rel_offs; |
| 3121 | nack->u.isp24.srr_ui = ntfy->u.isp24.srr_ui; |
| 3122 | nack->u.isp24.srr_flags = 0; |
| 3123 | nack->u.isp24.srr_reject_code = 0; |
| 3124 | nack->u.isp24.srr_reject_code_expl = 0; |
| 3125 | nack->u.isp24.vp_index = ntfy->u.isp24.vp_index; |
| 3126 | } |
| 3127 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3128 | int |
| 3129 | qla2x00_start_sp(srb_t *sp) |
| 3130 | { |
| 3131 | int rval; |
Joe Carnuccio | 25ff6af | 2017-01-19 22:28:04 -0800 | [diff] [blame] | 3132 | scsi_qla_host_t *vha = sp->vha; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3133 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3134 | void *pkt; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3135 | unsigned long flags; |
| 3136 | |
| 3137 | rval = QLA_FUNCTION_FAILED; |
| 3138 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3139 | pkt = qla2x00_alloc_iocbs(vha, sp); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3140 | if (!pkt) { |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3141 | ql_log(ql_log_warn, vha, 0x700c, |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3142 | "qla2x00_alloc_iocbs failed.\n"); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3143 | goto done; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 3144 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3145 | |
| 3146 | rval = QLA_SUCCESS; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 3147 | switch (sp->type) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3148 | case SRB_LOGIN_CMD: |
| 3149 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3150 | qla24xx_login_iocb(sp, pkt) : |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3151 | qla2x00_login_iocb(sp, pkt); |
| 3152 | break; |
| 3153 | case SRB_LOGOUT_CMD: |
| 3154 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3155 | qla24xx_logout_iocb(sp, pkt) : |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3156 | qla2x00_logout_iocb(sp, pkt); |
| 3157 | break; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 3158 | case SRB_ELS_CMD_RPT: |
| 3159 | case SRB_ELS_CMD_HST: |
| 3160 | qla24xx_els_iocb(sp, pkt); |
| 3161 | break; |
| 3162 | case SRB_CT_CMD: |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 3163 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 3164 | qla24xx_ct_iocb(sp, pkt) : |
| 3165 | qla2x00_ct_iocb(sp, pkt); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 3166 | break; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 3167 | case SRB_ADISC_CMD: |
| 3168 | IS_FWI2_CAPABLE(ha) ? |
| 3169 | qla24xx_adisc_iocb(sp, pkt) : |
| 3170 | qla2x00_adisc_iocb(sp, pkt); |
| 3171 | break; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 3172 | case SRB_TM_CMD: |
Giridhar Malavali | 8ae6d9c | 2013-03-28 08:21:23 -0400 | [diff] [blame] | 3173 | IS_QLAFX00(ha) ? |
| 3174 | qlafx00_tm_iocb(sp, pkt) : |
| 3175 | qla24xx_tm_iocb(sp, pkt); |
| 3176 | break; |
| 3177 | case SRB_FXIOCB_DCMD: |
| 3178 | case SRB_FXIOCB_BCMD: |
| 3179 | qlafx00_fxdisc_iocb(sp, pkt); |
| 3180 | break; |
| 3181 | case SRB_ABT_CMD: |
Armen Baloyan | 4440e46 | 2014-02-26 04:15:18 -0500 | [diff] [blame] | 3182 | IS_QLAFX00(ha) ? |
| 3183 | qlafx00_abort_iocb(sp, pkt) : |
| 3184 | qla24xx_abort_iocb(sp, pkt); |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 3185 | break; |
Himanshu Madhani | 6eb5471 | 2015-12-17 14:57:00 -0500 | [diff] [blame] | 3186 | case SRB_ELS_DCMD: |
| 3187 | qla24xx_els_logo_iocb(sp, pkt); |
| 3188 | break; |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3189 | case SRB_CT_PTHRU_CMD: |
| 3190 | qla2x00_ctpthru_cmd_iocb(sp, pkt); |
| 3191 | break; |
| 3192 | case SRB_MB_IOCB: |
| 3193 | qla2x00_mb_iocb(sp, pkt); |
| 3194 | break; |
| 3195 | case SRB_NACK_PLOGI: |
| 3196 | case SRB_NACK_PRLI: |
| 3197 | case SRB_NACK_LOGO: |
| 3198 | qla2x00_send_notify_ack_iocb(sp, pkt); |
| 3199 | break; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3200 | default: |
| 3201 | break; |
| 3202 | } |
| 3203 | |
| 3204 | wmb(); |
Quinn Tran | 726b854 | 2017-01-19 22:28:00 -0800 | [diff] [blame] | 3205 | qla2x00_start_iocbs(vha, ha->req_q_map[0]); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 3206 | done: |
| 3207 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3208 | return rval; |
| 3209 | } |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3210 | |
| 3211 | static void |
| 3212 | qla25xx_build_bidir_iocb(srb_t *sp, struct scsi_qla_host *vha, |
| 3213 | struct cmd_bidir *cmd_pkt, uint32_t tot_dsds) |
| 3214 | { |
| 3215 | uint16_t avail_dsds; |
| 3216 | uint32_t *cur_dsd; |
| 3217 | uint32_t req_data_len = 0; |
| 3218 | uint32_t rsp_data_len = 0; |
| 3219 | struct scatterlist *sg; |
| 3220 | int index; |
| 3221 | int entry_count = 1; |
Johannes Thumshirn | 75cc8cf | 2016-11-17 10:31:19 +0100 | [diff] [blame] | 3222 | struct bsg_job *bsg_job = sp->u.bsg_job; |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3223 | |
| 3224 | /*Update entry type to indicate bidir command */ |
| 3225 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3226 | cpu_to_le32(COMMAND_BIDIRECTIONAL); |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3227 | |
| 3228 | /* Set the transfer direction, in this set both flags |
| 3229 | * Also set the BD_WRAP_BACK flag, firmware will take care |
| 3230 | * assigning DID=SID for outgoing pkts. |
| 3231 | */ |
| 3232 | cmd_pkt->wr_dseg_count = cpu_to_le16(bsg_job->request_payload.sg_cnt); |
| 3233 | cmd_pkt->rd_dseg_count = cpu_to_le16(bsg_job->reply_payload.sg_cnt); |
Bart Van Assche | ad95036 | 2015-07-09 07:24:08 -0700 | [diff] [blame] | 3234 | cmd_pkt->control_flags = cpu_to_le16(BD_WRITE_DATA | BD_READ_DATA | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3235 | BD_WRAP_BACK); |
| 3236 | |
| 3237 | req_data_len = rsp_data_len = bsg_job->request_payload.payload_len; |
| 3238 | cmd_pkt->wr_byte_count = cpu_to_le32(req_data_len); |
| 3239 | cmd_pkt->rd_byte_count = cpu_to_le32(rsp_data_len); |
| 3240 | cmd_pkt->timeout = cpu_to_le16(qla2x00_get_async_timeout(vha) + 2); |
| 3241 | |
| 3242 | vha->bidi_stats.transfer_bytes += req_data_len; |
| 3243 | vha->bidi_stats.io_count++; |
| 3244 | |
Joe Carnuccio | fabbb8d | 2013-08-27 01:37:40 -0400 | [diff] [blame] | 3245 | vha->qla_stats.output_bytes += req_data_len; |
| 3246 | vha->qla_stats.output_requests++; |
| 3247 | |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3248 | /* Only one dsd is available for bidirectional IOCB, remaining dsds |
| 3249 | * are bundled in continuation iocb |
| 3250 | */ |
| 3251 | avail_dsds = 1; |
| 3252 | cur_dsd = (uint32_t *)&cmd_pkt->fcp_data_dseg_address; |
| 3253 | |
| 3254 | index = 0; |
| 3255 | |
| 3256 | for_each_sg(bsg_job->request_payload.sg_list, sg, |
| 3257 | bsg_job->request_payload.sg_cnt, index) { |
| 3258 | dma_addr_t sle_dma; |
| 3259 | cont_a64_entry_t *cont_pkt; |
| 3260 | |
| 3261 | /* Allocate additional continuation packets */ |
| 3262 | if (avail_dsds == 0) { |
| 3263 | /* Continuation type 1 IOCB can accomodate |
| 3264 | * 5 DSDS |
| 3265 | */ |
| 3266 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req); |
| 3267 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 3268 | avail_dsds = 5; |
| 3269 | entry_count++; |
| 3270 | } |
| 3271 | sle_dma = sg_dma_address(sg); |
| 3272 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 3273 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 3274 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 3275 | avail_dsds--; |
| 3276 | } |
| 3277 | /* For read request DSD will always goes to continuation IOCB |
| 3278 | * and follow the write DSD. If there is room on the current IOCB |
| 3279 | * then it is added to that IOCB else new continuation IOCB is |
| 3280 | * allocated. |
| 3281 | */ |
| 3282 | for_each_sg(bsg_job->reply_payload.sg_list, sg, |
| 3283 | bsg_job->reply_payload.sg_cnt, index) { |
| 3284 | dma_addr_t sle_dma; |
| 3285 | cont_a64_entry_t *cont_pkt; |
| 3286 | |
| 3287 | /* Allocate additional continuation packets */ |
| 3288 | if (avail_dsds == 0) { |
| 3289 | /* Continuation type 1 IOCB can accomodate |
| 3290 | * 5 DSDS |
| 3291 | */ |
| 3292 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req); |
| 3293 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 3294 | avail_dsds = 5; |
| 3295 | entry_count++; |
| 3296 | } |
| 3297 | sle_dma = sg_dma_address(sg); |
| 3298 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 3299 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 3300 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 3301 | avail_dsds--; |
| 3302 | } |
| 3303 | /* This value should be same as number of IOCB required for this cmd */ |
| 3304 | cmd_pkt->entry_count = entry_count; |
| 3305 | } |
| 3306 | |
| 3307 | int |
| 3308 | qla2x00_start_bidir(srb_t *sp, struct scsi_qla_host *vha, uint32_t tot_dsds) |
| 3309 | { |
| 3310 | |
| 3311 | struct qla_hw_data *ha = vha->hw; |
| 3312 | unsigned long flags; |
| 3313 | uint32_t handle; |
| 3314 | uint32_t index; |
| 3315 | uint16_t req_cnt; |
| 3316 | uint16_t cnt; |
| 3317 | uint32_t *clr_ptr; |
| 3318 | struct cmd_bidir *cmd_pkt = NULL; |
| 3319 | struct rsp_que *rsp; |
| 3320 | struct req_que *req; |
| 3321 | int rval = EXT_STATUS_OK; |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3322 | |
| 3323 | rval = QLA_SUCCESS; |
| 3324 | |
| 3325 | rsp = ha->rsp_q_map[0]; |
| 3326 | req = vha->req; |
| 3327 | |
| 3328 | /* Send marker if required */ |
| 3329 | if (vha->marker_needed != 0) { |
| 3330 | if (qla2x00_marker(vha, req, |
| 3331 | rsp, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) |
| 3332 | return EXT_STATUS_MAILBOX; |
| 3333 | vha->marker_needed = 0; |
| 3334 | } |
| 3335 | |
| 3336 | /* Acquire ring specific lock */ |
| 3337 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 3338 | |
| 3339 | /* Check for room in outstanding command list. */ |
| 3340 | handle = req->current_outstanding_cmd; |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3341 | for (index = 1; index < req->num_outstanding_cmds; index++) { |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3342 | handle++; |
Bart Van Assche | 8d2b21d | 2015-06-04 15:58:09 -0700 | [diff] [blame] | 3343 | if (handle == req->num_outstanding_cmds) |
| 3344 | handle = 1; |
| 3345 | if (!req->outstanding_cmds[handle]) |
| 3346 | break; |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3347 | } |
| 3348 | |
Chad Dupuis | 8d93f55 | 2013-01-30 03:34:37 -0500 | [diff] [blame] | 3349 | if (index == req->num_outstanding_cmds) { |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3350 | rval = EXT_STATUS_BUSY; |
| 3351 | goto queuing_error; |
| 3352 | } |
| 3353 | |
| 3354 | /* Calculate number of IOCB required */ |
| 3355 | req_cnt = qla24xx_calc_iocbs(vha, tot_dsds); |
| 3356 | |
| 3357 | /* Check for room on request queue. */ |
| 3358 | if (req->cnt < req_cnt + 2) { |
Joe Carnuccio | 7c6300e | 2014-04-11 16:54:37 -0400 | [diff] [blame] | 3359 | cnt = IS_SHADOW_REG_CAPABLE(ha) ? *req->out_ptr : |
| 3360 | RD_REG_DWORD_RELAXED(req->req_q_out); |
Saurav Kashyap | a9b6f72 | 2012-08-22 14:21:01 -0400 | [diff] [blame] | 3361 | if (req->ring_index < cnt) |
| 3362 | req->cnt = cnt - req->ring_index; |
| 3363 | else |
| 3364 | req->cnt = req->length - |
| 3365 | (req->ring_index - cnt); |
| 3366 | } |
| 3367 | if (req->cnt < req_cnt + 2) { |
| 3368 | rval = EXT_STATUS_BUSY; |
| 3369 | goto queuing_error; |
| 3370 | } |
| 3371 | |
| 3372 | cmd_pkt = (struct cmd_bidir *)req->ring_ptr; |
| 3373 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 3374 | |
| 3375 | /* Zero out remaining portion of packet. */ |
| 3376 | /* tagged queuing modifier -- default is TSK_SIMPLE (0).*/ |
| 3377 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 3378 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 3379 | |
| 3380 | /* Set NPORT-ID (of vha)*/ |
| 3381 | cmd_pkt->nport_handle = cpu_to_le16(vha->self_login_loop_id); |
| 3382 | cmd_pkt->port_id[0] = vha->d_id.b.al_pa; |
| 3383 | cmd_pkt->port_id[1] = vha->d_id.b.area; |
| 3384 | cmd_pkt->port_id[2] = vha->d_id.b.domain; |
| 3385 | |
| 3386 | qla25xx_build_bidir_iocb(sp, vha, cmd_pkt, tot_dsds); |
| 3387 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
| 3388 | /* Build command packet. */ |
| 3389 | req->current_outstanding_cmd = handle; |
| 3390 | req->outstanding_cmds[handle] = sp; |
| 3391 | sp->handle = handle; |
| 3392 | req->cnt -= req_cnt; |
| 3393 | |
| 3394 | /* Send the command to the firmware */ |
| 3395 | wmb(); |
| 3396 | qla2x00_start_iocbs(vha, req); |
| 3397 | queuing_error: |
| 3398 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 3399 | return rval; |
| 3400 | } |