Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 07e264b | 2011-03-30 11:46:23 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2011 QLogic Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | * |
Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 5 | * See LICENSE.qla2xxx for copyright and licensing details. |
| 6 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | #include "qla_def.h" |
| 8 | |
| 9 | #include <linux/blkdev.h> |
| 10 | #include <linux/delay.h> |
| 11 | |
| 12 | #include <scsi/scsi_tcq.h> |
| 13 | |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 14 | static void qla25xx_set_que(srb_t *, struct rsp_que **); |
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); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 26 | struct scsi_qla_host *vha = sp->fcport->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); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 34 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | cflags = CF_READ; |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 36 | vha->qla_stats.input_bytes += scsi_bufflen(cmd); |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 37 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | return (cflags); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and |
| 43 | * Continuation Type 0 IOCBs to allocate. |
| 44 | * |
| 45 | * @dsds: number of data segment decriptors needed |
| 46 | * |
| 47 | * Returns the number of IOCB entries needed to store @dsds. |
| 48 | */ |
| 49 | uint16_t |
| 50 | qla2x00_calc_iocbs_32(uint16_t dsds) |
| 51 | { |
| 52 | uint16_t iocbs; |
| 53 | |
| 54 | iocbs = 1; |
| 55 | if (dsds > 3) { |
| 56 | iocbs += (dsds - 3) / 7; |
| 57 | if ((dsds - 3) % 7) |
| 58 | iocbs++; |
| 59 | } |
| 60 | return (iocbs); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and |
| 65 | * Continuation Type 1 IOCBs to allocate. |
| 66 | * |
| 67 | * @dsds: number of data segment decriptors needed |
| 68 | * |
| 69 | * Returns the number of IOCB entries needed to store @dsds. |
| 70 | */ |
| 71 | uint16_t |
| 72 | qla2x00_calc_iocbs_64(uint16_t dsds) |
| 73 | { |
| 74 | uint16_t iocbs; |
| 75 | |
| 76 | iocbs = 1; |
| 77 | if (dsds > 2) { |
| 78 | iocbs += (dsds - 2) / 5; |
| 79 | if ((dsds - 2) % 5) |
| 80 | iocbs++; |
| 81 | } |
| 82 | return (iocbs); |
| 83 | } |
| 84 | |
| 85 | /** |
| 86 | * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB. |
| 87 | * @ha: HA context |
| 88 | * |
| 89 | * Returns a pointer to the Continuation Type 0 IOCB packet. |
| 90 | */ |
| 91 | static inline cont_entry_t * |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 92 | qla2x00_prep_cont_type0_iocb(struct scsi_qla_host *vha) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | { |
| 94 | cont_entry_t *cont_pkt; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 95 | struct req_que *req = vha->req; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 97 | req->ring_index++; |
| 98 | if (req->ring_index == req->length) { |
| 99 | req->ring_index = 0; |
| 100 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 102 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
| 104 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 105 | cont_pkt = (cont_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | /* Load packet defaults. */ |
| 108 | *((uint32_t *)(&cont_pkt->entry_type)) = |
| 109 | __constant_cpu_to_le32(CONTINUE_TYPE); |
| 110 | |
| 111 | return (cont_pkt); |
| 112 | } |
| 113 | |
| 114 | /** |
| 115 | * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB. |
| 116 | * @ha: HA context |
| 117 | * |
| 118 | * Returns a pointer to the continuation type 1 IOCB packet. |
| 119 | */ |
| 120 | static inline cont_a64_entry_t * |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 121 | 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] | 122 | { |
| 123 | cont_a64_entry_t *cont_pkt; |
| 124 | |
| 125 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 126 | req->ring_index++; |
| 127 | if (req->ring_index == req->length) { |
| 128 | req->ring_index = 0; |
| 129 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | } else { |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 131 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 134 | cont_pkt = (cont_a64_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | /* Load packet defaults. */ |
| 137 | *((uint32_t *)(&cont_pkt->entry_type)) = |
| 138 | __constant_cpu_to_le32(CONTINUE_A64_TYPE); |
| 139 | |
| 140 | return (cont_pkt); |
| 141 | } |
| 142 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 143 | static inline int |
| 144 | qla24xx_configure_prot_mode(srb_t *sp, uint16_t *fw_prot_opts) |
| 145 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 146 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
| 147 | uint8_t guard = scsi_host_get_guard(cmd->device->host); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 148 | |
| 149 | /* We only support T10 DIF right now */ |
| 150 | if (guard != SHOST_DIX_GUARD_CRC) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 151 | ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3007, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 152 | "Unsupported guard: %d for cmd=%p.\n", guard, cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 153 | return 0; |
| 154 | } |
| 155 | |
| 156 | /* We always use DIFF Bundling for best performance */ |
| 157 | *fw_prot_opts = 0; |
| 158 | |
| 159 | /* Translate SCSI opcode to a protection opcode */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 160 | switch (scsi_get_prot_op(cmd)) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 161 | case SCSI_PROT_READ_STRIP: |
| 162 | *fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 163 | break; |
| 164 | case SCSI_PROT_WRITE_INSERT: |
| 165 | *fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 166 | break; |
| 167 | case SCSI_PROT_READ_INSERT: |
| 168 | *fw_prot_opts |= PO_MODE_DIF_INSERT; |
| 169 | break; |
| 170 | case SCSI_PROT_WRITE_STRIP: |
| 171 | *fw_prot_opts |= PO_MODE_DIF_REMOVE; |
| 172 | break; |
| 173 | case SCSI_PROT_READ_PASS: |
| 174 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
| 175 | break; |
| 176 | case SCSI_PROT_WRITE_PASS: |
| 177 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
| 178 | break; |
| 179 | default: /* Normal Request */ |
| 180 | *fw_prot_opts |= PO_MODE_DIF_PASS; |
| 181 | break; |
| 182 | } |
| 183 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 184 | return scsi_prot_sg_count(cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit |
| 189 | * capable IOCB types. |
| 190 | * |
| 191 | * @sp: SRB command to process |
| 192 | * @cmd_pkt: Command type 2 IOCB |
| 193 | * @tot_dsds: Total number of segments to transfer |
| 194 | */ |
| 195 | void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 196 | uint16_t tot_dsds) |
| 197 | { |
| 198 | uint16_t avail_dsds; |
| 199 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 200 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 202 | struct scatterlist *sg; |
| 203 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 205 | cmd = GET_CMD_SP(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | |
| 207 | /* Update entry type to indicate Command Type 2 IOCB */ |
| 208 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 209 | __constant_cpu_to_le32(COMMAND_TYPE); |
| 210 | |
| 211 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 212 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 214 | return; |
| 215 | } |
| 216 | |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 217 | vha = sp->fcport->vha; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 218 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | /* Three DSDs are available in the Command Type 2 IOCB */ |
| 221 | avail_dsds = 3; |
| 222 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 223 | |
| 224 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 225 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 226 | cont_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 228 | /* Allocate additional continuation packets? */ |
| 229 | if (avail_dsds == 0) { |
| 230 | /* |
| 231 | * Seven DSDs are available in the Continuation |
| 232 | * Type 0 IOCB. |
| 233 | */ |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 234 | cont_pkt = qla2x00_prep_cont_type0_iocb(vha); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 235 | cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address; |
| 236 | avail_dsds = 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 238 | |
| 239 | *cur_dsd++ = cpu_to_le32(sg_dma_address(sg)); |
| 240 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 241 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | } |
| 243 | } |
| 244 | |
| 245 | /** |
| 246 | * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit |
| 247 | * capable IOCB types. |
| 248 | * |
| 249 | * @sp: SRB command to process |
| 250 | * @cmd_pkt: Command type 3 IOCB |
| 251 | * @tot_dsds: Total number of segments to transfer |
| 252 | */ |
| 253 | void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 254 | uint16_t tot_dsds) |
| 255 | { |
| 256 | uint16_t avail_dsds; |
| 257 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 258 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 260 | struct scatterlist *sg; |
| 261 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 263 | cmd = GET_CMD_SP(sp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | |
| 265 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 266 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 267 | __constant_cpu_to_le32(COMMAND_A64_TYPE); |
| 268 | |
| 269 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 270 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 272 | return; |
| 273 | } |
| 274 | |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 275 | vha = sp->fcport->vha; |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 276 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(sp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | |
| 278 | /* Two DSDs are available in the Command Type 3 IOCB */ |
| 279 | avail_dsds = 2; |
| 280 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 281 | |
| 282 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 283 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 284 | dma_addr_t sle_dma; |
| 285 | cont_a64_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 287 | /* Allocate additional continuation packets? */ |
| 288 | if (avail_dsds == 0) { |
| 289 | /* |
| 290 | * Five DSDs are available in the Continuation |
| 291 | * Type 1 IOCB. |
| 292 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 293 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 294 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 295 | avail_dsds = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 297 | |
| 298 | sle_dma = sg_dma_address(sg); |
| 299 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 300 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 301 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 302 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | } |
| 304 | } |
| 305 | |
| 306 | /** |
| 307 | * qla2x00_start_scsi() - Send a SCSI command to the ISP |
| 308 | * @sp: command to send to the ISP |
| 309 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 310 | * Returns non-zero if a failure occurred, else zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 311 | */ |
| 312 | int |
| 313 | qla2x00_start_scsi(srb_t *sp) |
| 314 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 315 | int ret, nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | unsigned long flags; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 317 | scsi_qla_host_t *vha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | struct scsi_cmnd *cmd; |
| 319 | uint32_t *clr_ptr; |
| 320 | uint32_t index; |
| 321 | uint32_t handle; |
| 322 | cmd_entry_t *cmd_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | uint16_t cnt; |
| 324 | uint16_t req_cnt; |
| 325 | uint16_t tot_dsds; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 326 | struct device_reg_2xxx __iomem *reg; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 327 | struct qla_hw_data *ha; |
| 328 | struct req_que *req; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 329 | struct rsp_que *rsp; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 330 | char tag[2]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | /* Setup device pointers. */ |
| 333 | ret = 0; |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 334 | vha = sp->fcport->vha; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 335 | ha = vha->hw; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 336 | reg = &ha->iobase->isp; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 337 | cmd = GET_CMD_SP(sp); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 338 | req = ha->req_q_map[0]; |
| 339 | rsp = ha->rsp_q_map[0]; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 340 | /* So we know we haven't pci_map'ed anything yet */ |
| 341 | tot_dsds = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | |
| 343 | /* Send marker if required */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 344 | if (vha->marker_needed != 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 345 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 346 | QLA_SUCCESS) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | return (QLA_FUNCTION_FAILED); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 348 | } |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 349 | vha->marker_needed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | /* Acquire ring specific lock */ |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 353 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | |
| 355 | /* Check for room in outstanding command list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 356 | handle = req->current_outstanding_cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 358 | handle++; |
| 359 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 360 | handle = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 361 | if (!req->outstanding_cmds[handle]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 362 | break; |
| 363 | } |
| 364 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 365 | goto queuing_error; |
| 366 | |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 367 | /* 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] | 368 | if (scsi_sg_count(cmd)) { |
| 369 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 370 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 371 | if (unlikely(!nseg)) |
| 372 | goto queuing_error; |
| 373 | } else |
| 374 | nseg = 0; |
| 375 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 376 | tot_dsds = nseg; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 377 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | /* Calculate the number of request entries needed. */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 379 | req_cnt = ha->isp_ops->calc_req_entries(tot_dsds); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 380 | if (req->cnt < (req_cnt + 2)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 382 | if (req->ring_index < cnt) |
| 383 | req->cnt = cnt - req->ring_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 385 | req->cnt = req->length - |
| 386 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 387 | /* If still no head room then bail out */ |
| 388 | if (req->cnt < (req_cnt + 2)) |
| 389 | goto queuing_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | /* Build command packet */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 393 | req->current_outstanding_cmd = handle; |
| 394 | req->outstanding_cmds[handle] = sp; |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 395 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 396 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 397 | req->cnt -= req_cnt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 399 | cmd_pkt = (cmd_entry_t *)req->ring_ptr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | cmd_pkt->handle = handle; |
| 401 | /* Zero out remaining portion of packet. */ |
| 402 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 403 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 404 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 405 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 406 | /* Set target ID and LUN number*/ |
| 407 | SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 408 | cmd_pkt->lun = cpu_to_le16(cmd->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
| 410 | /* Update tagged queuing modifier */ |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 411 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 412 | switch (tag[0]) { |
| 413 | case HEAD_OF_QUEUE_TAG: |
| 414 | cmd_pkt->control_flags = |
| 415 | __constant_cpu_to_le16(CF_HEAD_TAG); |
| 416 | break; |
| 417 | case ORDERED_QUEUE_TAG: |
| 418 | cmd_pkt->control_flags = |
| 419 | __constant_cpu_to_le16(CF_ORDERED_TAG); |
| 420 | break; |
| 421 | default: |
| 422 | cmd_pkt->control_flags = |
| 423 | __constant_cpu_to_le16(CF_SIMPLE_TAG); |
| 424 | break; |
| 425 | } |
| 426 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | /* Load SCSI command packet. */ |
| 429 | memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 430 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | |
| 432 | /* Build IOCB segments */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 433 | ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | /* Set total data segment count. */ |
| 436 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 437 | wmb(); |
| 438 | |
| 439 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 440 | req->ring_index++; |
| 441 | if (req->ring_index == req->length) { |
| 442 | req->ring_index = 0; |
| 443 | req->ring_ptr = req->ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 445 | req->ring_ptr++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | sp->flags |= SRB_DMA_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | /* Set chip new ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 450 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), req->ring_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */ |
| 452 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 453 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 454 | if (vha->flags.process_response_queue && |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 455 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 456 | qla2x00_process_response_queue(rsp); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 457 | |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 458 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | return (QLA_SUCCESS); |
| 460 | |
| 461 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 462 | if (tot_dsds) |
| 463 | scsi_dma_unmap(cmd); |
| 464 | |
Andrew Vasquez | c9c5ced | 2008-07-24 08:31:49 -0700 | [diff] [blame] | 465 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | return (QLA_FUNCTION_FAILED); |
| 468 | } |
| 469 | |
| 470 | /** |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 471 | * qla2x00_start_iocbs() - Execute the IOCB command |
| 472 | */ |
| 473 | static void |
| 474 | qla2x00_start_iocbs(struct scsi_qla_host *vha, struct req_que *req) |
| 475 | { |
| 476 | struct qla_hw_data *ha = vha->hw; |
| 477 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 478 | |
| 479 | if (IS_QLA82XX(ha)) { |
| 480 | qla82xx_start_iocbs(vha); |
| 481 | } else { |
| 482 | /* Adjust ring index. */ |
| 483 | req->ring_index++; |
| 484 | if (req->ring_index == req->length) { |
| 485 | req->ring_index = 0; |
| 486 | req->ring_ptr = req->ring; |
| 487 | } else |
| 488 | req->ring_ptr++; |
| 489 | |
| 490 | /* Set chip new ring index. */ |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 491 | if (ha->mqenable || IS_QLA83XX(ha)) { |
| 492 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
Arun Easi | 98878a1 | 2012-02-09 11:15:59 -0800 | [diff] [blame] | 493 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 494 | } else if (IS_FWI2_CAPABLE(ha)) { |
| 495 | WRT_REG_DWORD(®->isp24.req_q_in, req->ring_index); |
| 496 | RD_REG_DWORD_RELAXED(®->isp24.req_q_in); |
| 497 | } else { |
| 498 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp), |
| 499 | req->ring_index); |
| 500 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp)); |
| 501 | } |
| 502 | } |
| 503 | } |
| 504 | |
| 505 | /** |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 506 | * qla2x00_marker() - Send a marker IOCB to the firmware. |
| 507 | * @ha: HA context |
| 508 | * @loop_id: loop ID |
| 509 | * @lun: LUN |
| 510 | * @type: marker modifier |
| 511 | * |
| 512 | * Can be called from both normal and interrupt context. |
| 513 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 514 | * Returns non-zero if a failure occurred, else zero. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | */ |
Andrew Vasquez | 3dbe756 | 2010-07-23 15:28:37 +0500 | [diff] [blame] | 516 | static int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 517 | __qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req, |
| 518 | struct rsp_que *rsp, uint16_t loop_id, |
| 519 | uint16_t lun, uint8_t type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 521 | mrk_entry_t *mrk; |
| 522 | struct mrk_entry_24xx *mrk24; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 523 | struct qla_hw_data *ha = vha->hw; |
| 524 | scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 526 | mrk24 = NULL; |
Giridhar Malavali | 99b8212 | 2011-11-18 09:03:17 -0800 | [diff] [blame] | 527 | req = ha->req_q_map[0]; |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 528 | mrk = (mrk_entry_t *)qla2x00_alloc_iocbs(vha, 0); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 529 | if (mrk == NULL) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 530 | ql_log(ql_log_warn, base_vha, 0x3026, |
| 531 | "Failed to allocate Marker IOCB.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | return (QLA_FUNCTION_FAILED); |
| 534 | } |
| 535 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 536 | mrk->entry_type = MARKER_TYPE; |
| 537 | mrk->modifier = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | if (type != MK_SYNC_ALL) { |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 539 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 540 | mrk24 = (struct mrk_entry_24xx *) mrk; |
| 541 | mrk24->nport_handle = cpu_to_le16(loop_id); |
| 542 | mrk24->lun[1] = LSB(lun); |
| 543 | mrk24->lun[2] = MSB(lun); |
Shyam Sundar | b797b6d | 2006-08-01 13:48:13 -0700 | [diff] [blame] | 544 | host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun)); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 545 | mrk24->vp_index = vha->vp_idx; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 546 | mrk24->handle = MAKE_HANDLE(req->id, mrk24->handle); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 547 | } else { |
| 548 | SET_TARGET_ID(ha, mrk->target, loop_id); |
| 549 | mrk->lun = cpu_to_le16(lun); |
| 550 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | } |
| 552 | wmb(); |
| 553 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 554 | qla2x00_start_iocbs(vha, req); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | |
| 556 | return (QLA_SUCCESS); |
| 557 | } |
| 558 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 559 | int |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 560 | qla2x00_marker(struct scsi_qla_host *vha, struct req_que *req, |
| 561 | struct rsp_que *rsp, uint16_t loop_id, uint16_t lun, |
| 562 | uint8_t type) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | { |
| 564 | int ret; |
| 565 | unsigned long flags = 0; |
| 566 | |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 567 | spin_lock_irqsave(&vha->hw->hardware_lock, flags); |
| 568 | ret = __qla2x00_marker(vha, req, rsp, loop_id, lun, type); |
| 569 | spin_unlock_irqrestore(&vha->hw->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | return (ret); |
| 572 | } |
| 573 | |
| 574 | /** |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 575 | * qla24xx_calc_iocbs() - Determine number of Command Type 3 and |
| 576 | * Continuation Type 1 IOCBs to allocate. |
| 577 | * |
| 578 | * @dsds: number of data segment decriptors needed |
| 579 | * |
| 580 | * Returns the number of IOCB entries needed to store @dsds. |
| 581 | */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 582 | inline uint16_t |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 583 | qla24xx_calc_iocbs(scsi_qla_host_t *vha, uint16_t dsds) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 584 | { |
| 585 | uint16_t iocbs; |
| 586 | |
| 587 | iocbs = 1; |
| 588 | if (dsds > 1) { |
| 589 | iocbs += (dsds - 1) / 5; |
| 590 | if ((dsds - 1) % 5) |
| 591 | iocbs++; |
| 592 | } |
| 593 | return iocbs; |
| 594 | } |
| 595 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 596 | static inline int |
| 597 | qla24xx_build_scsi_type_6_iocbs(srb_t *sp, struct cmd_type_6 *cmd_pkt, |
| 598 | uint16_t tot_dsds) |
| 599 | { |
| 600 | uint32_t *cur_dsd = NULL; |
| 601 | scsi_qla_host_t *vha; |
| 602 | struct qla_hw_data *ha; |
| 603 | struct scsi_cmnd *cmd; |
| 604 | struct scatterlist *cur_seg; |
| 605 | uint32_t *dsd_seg; |
| 606 | void *next_dsd; |
| 607 | uint8_t avail_dsds; |
| 608 | uint8_t first_iocb = 1; |
| 609 | uint32_t dsd_list_len; |
| 610 | struct dsd_dma *dsd_ptr; |
| 611 | struct ct6_dsd *ctx; |
| 612 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 613 | cmd = GET_CMD_SP(sp); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 614 | |
| 615 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 616 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 617 | __constant_cpu_to_le32(COMMAND_TYPE_6); |
| 618 | |
| 619 | /* No data transfer */ |
| 620 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
| 621 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 622 | return 0; |
| 623 | } |
| 624 | |
| 625 | vha = sp->fcport->vha; |
| 626 | ha = vha->hw; |
| 627 | |
| 628 | /* Set transfer direction */ |
| 629 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
| 630 | cmd_pkt->control_flags = |
| 631 | __constant_cpu_to_le16(CF_WRITE_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 632 | vha->qla_stats.output_bytes += scsi_bufflen(cmd); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 633 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
| 634 | cmd_pkt->control_flags = |
| 635 | __constant_cpu_to_le16(CF_READ_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 636 | vha->qla_stats.input_bytes += scsi_bufflen(cmd); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 637 | } |
| 638 | |
| 639 | cur_seg = scsi_sglist(cmd); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 640 | ctx = GET_CMD_CTX_SP(sp); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 641 | |
| 642 | while (tot_dsds) { |
| 643 | avail_dsds = (tot_dsds > QLA_DSDS_PER_IOCB) ? |
| 644 | QLA_DSDS_PER_IOCB : tot_dsds; |
| 645 | tot_dsds -= avail_dsds; |
| 646 | dsd_list_len = (avail_dsds + 1) * QLA_DSD_SIZE; |
| 647 | |
| 648 | dsd_ptr = list_first_entry(&ha->gbl_dsd_list, |
| 649 | struct dsd_dma, list); |
| 650 | next_dsd = dsd_ptr->dsd_addr; |
| 651 | list_del(&dsd_ptr->list); |
| 652 | ha->gbl_dsd_avail--; |
| 653 | list_add_tail(&dsd_ptr->list, &ctx->dsd_list); |
| 654 | ctx->dsd_use_cnt++; |
| 655 | ha->gbl_dsd_inuse++; |
| 656 | |
| 657 | if (first_iocb) { |
| 658 | first_iocb = 0; |
| 659 | dsd_seg = (uint32_t *)&cmd_pkt->fcp_data_dseg_address; |
| 660 | *dsd_seg++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 661 | *dsd_seg++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 662 | cmd_pkt->fcp_data_dseg_len = cpu_to_le32(dsd_list_len); |
| 663 | } else { |
| 664 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 665 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 666 | *cur_dsd++ = cpu_to_le32(dsd_list_len); |
| 667 | } |
| 668 | cur_dsd = (uint32_t *)next_dsd; |
| 669 | while (avail_dsds) { |
| 670 | dma_addr_t sle_dma; |
| 671 | |
| 672 | sle_dma = sg_dma_address(cur_seg); |
| 673 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 674 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 675 | *cur_dsd++ = cpu_to_le32(sg_dma_len(cur_seg)); |
| 676 | cur_seg = sg_next(cur_seg); |
| 677 | avail_dsds--; |
| 678 | } |
| 679 | } |
| 680 | |
| 681 | /* Null termination */ |
| 682 | *cur_dsd++ = 0; |
| 683 | *cur_dsd++ = 0; |
| 684 | *cur_dsd++ = 0; |
| 685 | cmd_pkt->control_flags |= CF_DATA_SEG_DESCR_ENABLE; |
| 686 | return 0; |
| 687 | } |
| 688 | |
| 689 | /* |
| 690 | * qla24xx_calc_dsd_lists() - Determine number of DSD list required |
| 691 | * for Command Type 6. |
| 692 | * |
| 693 | * @dsds: number of data segment decriptors needed |
| 694 | * |
| 695 | * Returns the number of dsd list needed to store @dsds. |
| 696 | */ |
| 697 | inline uint16_t |
| 698 | qla24xx_calc_dsd_lists(uint16_t dsds) |
| 699 | { |
| 700 | uint16_t dsd_lists = 0; |
| 701 | |
| 702 | dsd_lists = (dsds/QLA_DSDS_PER_IOCB); |
| 703 | if (dsds % QLA_DSDS_PER_IOCB) |
| 704 | dsd_lists++; |
| 705 | return dsd_lists; |
| 706 | } |
| 707 | |
| 708 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 709 | /** |
| 710 | * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7 |
| 711 | * IOCB types. |
| 712 | * |
| 713 | * @sp: SRB command to process |
| 714 | * @cmd_pkt: Command type 3 IOCB |
| 715 | * @tot_dsds: Total number of segments to transfer |
| 716 | */ |
Giridhar Malavali | a908301 | 2010-04-12 17:59:55 -0700 | [diff] [blame] | 717 | inline void |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 718 | qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt, |
| 719 | uint16_t tot_dsds) |
| 720 | { |
| 721 | uint16_t avail_dsds; |
| 722 | uint32_t *cur_dsd; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 723 | scsi_qla_host_t *vha; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 724 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 725 | struct scatterlist *sg; |
| 726 | int i; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 727 | struct req_que *req; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 728 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 729 | cmd = GET_CMD_SP(sp); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 730 | |
| 731 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 732 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 733 | __constant_cpu_to_le32(COMMAND_TYPE_7); |
| 734 | |
| 735 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 736 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 737 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 738 | return; |
| 739 | } |
| 740 | |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 741 | vha = sp->fcport->vha; |
Anirban Chakraborty | 67c2e93 | 2009-04-06 22:33:42 -0700 | [diff] [blame] | 742 | req = vha->req; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 743 | |
| 744 | /* Set transfer direction */ |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 745 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 746 | cmd_pkt->task_mgmt_flags = |
| 747 | __constant_cpu_to_le16(TMF_WRITE_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 748 | vha->qla_stats.output_bytes += scsi_bufflen(cmd); |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 749 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 750 | cmd_pkt->task_mgmt_flags = |
| 751 | __constant_cpu_to_le16(TMF_READ_DATA); |
Saurav Kashyap | 2be21fa | 2012-05-15 14:34:16 -0400 | [diff] [blame] | 752 | vha->qla_stats.input_bytes += scsi_bufflen(cmd); |
Harish Zunjarrao | 49fd462 | 2008-09-11 21:22:47 -0700 | [diff] [blame] | 753 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 754 | |
| 755 | /* One DSD is available in the Command Type 3 IOCB */ |
| 756 | avail_dsds = 1; |
| 757 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 758 | |
| 759 | /* Load data segments */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 760 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 761 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 762 | dma_addr_t sle_dma; |
| 763 | cont_a64_entry_t *cont_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 764 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 765 | /* Allocate additional continuation packets? */ |
| 766 | if (avail_dsds == 0) { |
| 767 | /* |
| 768 | * Five DSDs are available in the Continuation |
| 769 | * Type 1 IOCB. |
| 770 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 771 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, vha->req); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 772 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 773 | avail_dsds = 5; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 774 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 775 | |
| 776 | sle_dma = sg_dma_address(sg); |
| 777 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 778 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 779 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 780 | avail_dsds--; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 781 | } |
| 782 | } |
| 783 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 784 | struct fw_dif_context { |
| 785 | uint32_t ref_tag; |
| 786 | uint16_t app_tag; |
| 787 | uint8_t ref_tag_mask[4]; /* Validation/Replacement Mask*/ |
| 788 | uint8_t app_tag_mask[2]; /* Validation/Replacement Mask*/ |
| 789 | }; |
| 790 | |
| 791 | /* |
| 792 | * qla24xx_set_t10dif_tags_from_cmd - Extract Ref and App tags from SCSI command |
| 793 | * |
| 794 | */ |
| 795 | static inline void |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 796 | qla24xx_set_t10dif_tags(srb_t *sp, struct fw_dif_context *pkt, |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 797 | unsigned int protcnt) |
| 798 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 799 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 800 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 801 | |
| 802 | switch (scsi_get_prot_type(cmd)) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 803 | case SCSI_PROT_DIF_TYPE0: |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 804 | /* |
| 805 | * No check for ql2xenablehba_err_chk, as it would be an |
| 806 | * I/O error if hba tag generation is not done. |
| 807 | */ |
| 808 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 809 | (0xffffffff & scsi_get_lba(cmd))); |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 810 | |
| 811 | if (!qla2x00_hba_err_chk_enabled(sp)) |
| 812 | break; |
| 813 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 814 | pkt->ref_tag_mask[0] = 0xff; |
| 815 | pkt->ref_tag_mask[1] = 0xff; |
| 816 | pkt->ref_tag_mask[2] = 0xff; |
| 817 | pkt->ref_tag_mask[3] = 0xff; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 818 | break; |
| 819 | |
| 820 | /* |
| 821 | * For TYPE 2 protection: 16 bit GUARD + 32 bit REF tag has to |
| 822 | * match LBA in CDB + N |
| 823 | */ |
| 824 | case SCSI_PROT_DIF_TYPE2: |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 825 | pkt->app_tag = __constant_cpu_to_le16(0); |
| 826 | pkt->app_tag_mask[0] = 0x0; |
| 827 | pkt->app_tag_mask[1] = 0x0; |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 828 | |
| 829 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 830 | (0xffffffff & scsi_get_lba(cmd))); |
| 831 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 832 | if (!qla2x00_hba_err_chk_enabled(sp)) |
| 833 | break; |
| 834 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 835 | /* enable ALL bytes of the ref tag */ |
| 836 | pkt->ref_tag_mask[0] = 0xff; |
| 837 | pkt->ref_tag_mask[1] = 0xff; |
| 838 | pkt->ref_tag_mask[2] = 0xff; |
| 839 | pkt->ref_tag_mask[3] = 0xff; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 840 | break; |
| 841 | |
| 842 | /* For Type 3 protection: 16 bit GUARD only */ |
| 843 | case SCSI_PROT_DIF_TYPE3: |
| 844 | pkt->ref_tag_mask[0] = pkt->ref_tag_mask[1] = |
| 845 | pkt->ref_tag_mask[2] = pkt->ref_tag_mask[3] = |
| 846 | 0x00; |
| 847 | break; |
| 848 | |
| 849 | /* |
| 850 | * For TYpe 1 protection: 16 bit GUARD tag, 32 bit REF tag, and |
| 851 | * 16 bit app tag. |
| 852 | */ |
| 853 | case SCSI_PROT_DIF_TYPE1: |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 854 | pkt->ref_tag = cpu_to_le32((uint32_t) |
| 855 | (0xffffffff & scsi_get_lba(cmd))); |
| 856 | pkt->app_tag = __constant_cpu_to_le16(0); |
| 857 | pkt->app_tag_mask[0] = 0x0; |
| 858 | pkt->app_tag_mask[1] = 0x0; |
| 859 | |
| 860 | if (!qla2x00_hba_err_chk_enabled(sp)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 861 | break; |
| 862 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 863 | /* enable ALL bytes of the ref tag */ |
| 864 | pkt->ref_tag_mask[0] = 0xff; |
| 865 | pkt->ref_tag_mask[1] = 0xff; |
| 866 | pkt->ref_tag_mask[2] = 0xff; |
| 867 | pkt->ref_tag_mask[3] = 0xff; |
| 868 | break; |
| 869 | } |
| 870 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 871 | ql_dbg(ql_dbg_io, vha, 0x3009, |
| 872 | "Setting protection Tags: (BIG) ref tag = 0x%x, app tag = 0x%x, " |
| 873 | "prot SG count %d, cmd lba 0x%x, prot_type=%u cmd=%p.\n", |
| 874 | pkt->ref_tag, pkt->app_tag, protcnt, (int)scsi_get_lba(cmd), |
| 875 | scsi_get_prot_type(cmd), cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 876 | } |
| 877 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 878 | struct qla2_sgx { |
| 879 | dma_addr_t dma_addr; /* OUT */ |
| 880 | uint32_t dma_len; /* OUT */ |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 881 | |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 882 | uint32_t tot_bytes; /* IN */ |
| 883 | struct scatterlist *cur_sg; /* IN */ |
| 884 | |
| 885 | /* for book keeping, bzero on initial invocation */ |
| 886 | uint32_t bytes_consumed; |
| 887 | uint32_t num_bytes; |
| 888 | uint32_t tot_partial; |
| 889 | |
| 890 | /* for debugging */ |
| 891 | uint32_t num_sg; |
| 892 | srb_t *sp; |
| 893 | }; |
| 894 | |
| 895 | static int |
| 896 | qla24xx_get_one_block_sg(uint32_t blk_sz, struct qla2_sgx *sgx, |
| 897 | uint32_t *partial) |
| 898 | { |
| 899 | struct scatterlist *sg; |
| 900 | uint32_t cumulative_partial, sg_len; |
| 901 | dma_addr_t sg_dma_addr; |
| 902 | |
| 903 | if (sgx->num_bytes == sgx->tot_bytes) |
| 904 | return 0; |
| 905 | |
| 906 | sg = sgx->cur_sg; |
| 907 | cumulative_partial = sgx->tot_partial; |
| 908 | |
| 909 | sg_dma_addr = sg_dma_address(sg); |
| 910 | sg_len = sg_dma_len(sg); |
| 911 | |
| 912 | sgx->dma_addr = sg_dma_addr + sgx->bytes_consumed; |
| 913 | |
| 914 | if ((cumulative_partial + (sg_len - sgx->bytes_consumed)) >= blk_sz) { |
| 915 | sgx->dma_len = (blk_sz - cumulative_partial); |
| 916 | sgx->tot_partial = 0; |
| 917 | sgx->num_bytes += blk_sz; |
| 918 | *partial = 0; |
| 919 | } else { |
| 920 | sgx->dma_len = sg_len - sgx->bytes_consumed; |
| 921 | sgx->tot_partial += sgx->dma_len; |
| 922 | *partial = 1; |
| 923 | } |
| 924 | |
| 925 | sgx->bytes_consumed += sgx->dma_len; |
| 926 | |
| 927 | if (sg_len == sgx->bytes_consumed) { |
| 928 | sg = sg_next(sg); |
| 929 | sgx->num_sg++; |
| 930 | sgx->cur_sg = sg; |
| 931 | sgx->bytes_consumed = 0; |
| 932 | } |
| 933 | |
| 934 | return 1; |
| 935 | } |
| 936 | |
| 937 | static int |
| 938 | qla24xx_walk_and_build_sglist_no_difb(struct qla_hw_data *ha, srb_t *sp, |
| 939 | uint32_t *dsd, uint16_t tot_dsds) |
| 940 | { |
| 941 | void *next_dsd; |
| 942 | uint8_t avail_dsds = 0; |
| 943 | uint32_t dsd_list_len; |
| 944 | struct dsd_dma *dsd_ptr; |
| 945 | struct scatterlist *sg_prot; |
| 946 | uint32_t *cur_dsd = dsd; |
| 947 | uint16_t used_dsds = tot_dsds; |
| 948 | |
| 949 | uint32_t prot_int; |
| 950 | uint32_t partial; |
| 951 | struct qla2_sgx sgx; |
| 952 | dma_addr_t sle_dma; |
| 953 | uint32_t sle_dma_len, tot_prot_dma_len = 0; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 954 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 955 | |
| 956 | prot_int = cmd->device->sector_size; |
| 957 | |
| 958 | memset(&sgx, 0, sizeof(struct qla2_sgx)); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 959 | sgx.tot_bytes = scsi_bufflen(cmd); |
| 960 | sgx.cur_sg = scsi_sglist(cmd); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 961 | sgx.sp = sp; |
| 962 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 963 | sg_prot = scsi_prot_sglist(cmd); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 964 | |
| 965 | while (qla24xx_get_one_block_sg(prot_int, &sgx, &partial)) { |
| 966 | |
| 967 | sle_dma = sgx.dma_addr; |
| 968 | sle_dma_len = sgx.dma_len; |
| 969 | alloc_and_fill: |
| 970 | /* Allocate additional continuation packets? */ |
| 971 | if (avail_dsds == 0) { |
| 972 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 973 | QLA_DSDS_PER_IOCB : used_dsds; |
| 974 | dsd_list_len = (avail_dsds + 1) * 12; |
| 975 | used_dsds -= avail_dsds; |
| 976 | |
| 977 | /* allocate tracking DS */ |
| 978 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 979 | if (!dsd_ptr) |
| 980 | return 1; |
| 981 | |
| 982 | /* allocate new list */ |
| 983 | dsd_ptr->dsd_addr = next_dsd = |
| 984 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 985 | &dsd_ptr->dsd_list_dma); |
| 986 | |
| 987 | if (!next_dsd) { |
| 988 | /* |
| 989 | * Need to cleanup only this dsd_ptr, rest |
| 990 | * will be done by sp_free_dma() |
| 991 | */ |
| 992 | kfree(dsd_ptr); |
| 993 | return 1; |
| 994 | } |
| 995 | |
| 996 | list_add_tail(&dsd_ptr->list, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 997 | &((struct crc_context *)sp->u.scmd.ctx)->dsd_list); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 998 | |
| 999 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 1000 | |
| 1001 | /* add new list to cmd iocb or last list */ |
| 1002 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 1003 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 1004 | *cur_dsd++ = dsd_list_len; |
| 1005 | cur_dsd = (uint32_t *)next_dsd; |
| 1006 | } |
| 1007 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 1008 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 1009 | *cur_dsd++ = cpu_to_le32(sle_dma_len); |
| 1010 | avail_dsds--; |
| 1011 | |
| 1012 | if (partial == 0) { |
| 1013 | /* Got a full protection interval */ |
| 1014 | sle_dma = sg_dma_address(sg_prot) + tot_prot_dma_len; |
| 1015 | sle_dma_len = 8; |
| 1016 | |
| 1017 | tot_prot_dma_len += sle_dma_len; |
| 1018 | if (tot_prot_dma_len == sg_dma_len(sg_prot)) { |
| 1019 | tot_prot_dma_len = 0; |
| 1020 | sg_prot = sg_next(sg_prot); |
| 1021 | } |
| 1022 | |
| 1023 | partial = 1; /* So as to not re-enter this block */ |
| 1024 | goto alloc_and_fill; |
| 1025 | } |
| 1026 | } |
| 1027 | /* Null termination */ |
| 1028 | *cur_dsd++ = 0; |
| 1029 | *cur_dsd++ = 0; |
| 1030 | *cur_dsd++ = 0; |
| 1031 | return 0; |
| 1032 | } |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 1033 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1034 | static int |
| 1035 | qla24xx_walk_and_build_sglist(struct qla_hw_data *ha, srb_t *sp, uint32_t *dsd, |
| 1036 | uint16_t tot_dsds) |
| 1037 | { |
| 1038 | void *next_dsd; |
| 1039 | uint8_t avail_dsds = 0; |
| 1040 | uint32_t dsd_list_len; |
| 1041 | struct dsd_dma *dsd_ptr; |
| 1042 | struct scatterlist *sg; |
| 1043 | uint32_t *cur_dsd = dsd; |
| 1044 | int i; |
| 1045 | uint16_t used_dsds = tot_dsds; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1046 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
| 1047 | scsi_qla_host_t *vha = shost_priv(cmd->device->host); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1048 | |
| 1049 | uint8_t *cp; |
| 1050 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1051 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1052 | dma_addr_t sle_dma; |
| 1053 | |
| 1054 | /* Allocate additional continuation packets? */ |
| 1055 | if (avail_dsds == 0) { |
| 1056 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 1057 | QLA_DSDS_PER_IOCB : used_dsds; |
| 1058 | dsd_list_len = (avail_dsds + 1) * 12; |
| 1059 | used_dsds -= avail_dsds; |
| 1060 | |
| 1061 | /* allocate tracking DS */ |
| 1062 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 1063 | if (!dsd_ptr) |
| 1064 | return 1; |
| 1065 | |
| 1066 | /* allocate new list */ |
| 1067 | dsd_ptr->dsd_addr = next_dsd = |
| 1068 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 1069 | &dsd_ptr->dsd_list_dma); |
| 1070 | |
| 1071 | if (!next_dsd) { |
| 1072 | /* |
| 1073 | * Need to cleanup only this dsd_ptr, rest |
| 1074 | * will be done by sp_free_dma() |
| 1075 | */ |
| 1076 | kfree(dsd_ptr); |
| 1077 | return 1; |
| 1078 | } |
| 1079 | |
| 1080 | list_add_tail(&dsd_ptr->list, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1081 | &((struct crc_context *)sp->u.scmd.ctx)->dsd_list); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1082 | |
| 1083 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 1084 | |
| 1085 | /* add new list to cmd iocb or last list */ |
| 1086 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 1087 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 1088 | *cur_dsd++ = dsd_list_len; |
| 1089 | cur_dsd = (uint32_t *)next_dsd; |
| 1090 | } |
| 1091 | sle_dma = sg_dma_address(sg); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1092 | ql_dbg(ql_dbg_io, vha, 0x300a, |
| 1093 | "sg entry %d - addr=0x%x 0x%x, " "len=%d for cmd=%p.\n", |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1094 | i, LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg), cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1095 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 1096 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 1097 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 1098 | avail_dsds--; |
| 1099 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1100 | if (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_PASS) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1101 | cp = page_address(sg_page(sg)) + sg->offset; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1102 | ql_dbg(ql_dbg_io, vha, 0x300b, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1103 | "User data buffer=%p for cmd=%p.\n", cp, cmd); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1104 | } |
| 1105 | } |
| 1106 | /* Null termination */ |
| 1107 | *cur_dsd++ = 0; |
| 1108 | *cur_dsd++ = 0; |
| 1109 | *cur_dsd++ = 0; |
| 1110 | return 0; |
| 1111 | } |
| 1112 | |
| 1113 | static int |
| 1114 | qla24xx_walk_and_build_prot_sglist(struct qla_hw_data *ha, srb_t *sp, |
| 1115 | uint32_t *dsd, |
| 1116 | uint16_t tot_dsds) |
| 1117 | { |
| 1118 | void *next_dsd; |
| 1119 | uint8_t avail_dsds = 0; |
| 1120 | uint32_t dsd_list_len; |
| 1121 | struct dsd_dma *dsd_ptr; |
| 1122 | struct scatterlist *sg; |
| 1123 | int i; |
| 1124 | struct scsi_cmnd *cmd; |
| 1125 | uint32_t *cur_dsd = dsd; |
| 1126 | uint16_t used_dsds = tot_dsds; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1127 | scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1128 | uint8_t *cp; |
| 1129 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1130 | cmd = GET_CMD_SP(sp); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1131 | scsi_for_each_prot_sg(cmd, sg, tot_dsds, i) { |
| 1132 | dma_addr_t sle_dma; |
| 1133 | |
| 1134 | /* Allocate additional continuation packets? */ |
| 1135 | if (avail_dsds == 0) { |
| 1136 | avail_dsds = (used_dsds > QLA_DSDS_PER_IOCB) ? |
| 1137 | QLA_DSDS_PER_IOCB : used_dsds; |
| 1138 | dsd_list_len = (avail_dsds + 1) * 12; |
| 1139 | used_dsds -= avail_dsds; |
| 1140 | |
| 1141 | /* allocate tracking DS */ |
| 1142 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 1143 | if (!dsd_ptr) |
| 1144 | return 1; |
| 1145 | |
| 1146 | /* allocate new list */ |
| 1147 | dsd_ptr->dsd_addr = next_dsd = |
| 1148 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, |
| 1149 | &dsd_ptr->dsd_list_dma); |
| 1150 | |
| 1151 | if (!next_dsd) { |
| 1152 | /* |
| 1153 | * Need to cleanup only this dsd_ptr, rest |
| 1154 | * will be done by sp_free_dma() |
| 1155 | */ |
| 1156 | kfree(dsd_ptr); |
| 1157 | return 1; |
| 1158 | } |
| 1159 | |
| 1160 | list_add_tail(&dsd_ptr->list, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1161 | &((struct crc_context *)sp->u.scmd.ctx)->dsd_list); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1162 | |
| 1163 | sp->flags |= SRB_CRC_CTX_DSD_VALID; |
| 1164 | |
| 1165 | /* add new list to cmd iocb or last list */ |
| 1166 | *cur_dsd++ = cpu_to_le32(LSD(dsd_ptr->dsd_list_dma)); |
| 1167 | *cur_dsd++ = cpu_to_le32(MSD(dsd_ptr->dsd_list_dma)); |
| 1168 | *cur_dsd++ = dsd_list_len; |
| 1169 | cur_dsd = (uint32_t *)next_dsd; |
| 1170 | } |
| 1171 | sle_dma = sg_dma_address(sg); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1172 | if (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_PASS) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1173 | ql_dbg(ql_dbg_io, vha, 0x3027, |
| 1174 | "%s(): %p, sg_entry %d - " |
| 1175 | "addr=0x%x0x%x, len=%d.\n", |
| 1176 | __func__, cur_dsd, i, |
| 1177 | LSD(sle_dma), MSD(sle_dma), sg_dma_len(sg)); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1178 | } |
| 1179 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 1180 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 1181 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 1182 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1183 | if (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_PASS) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1184 | cp = page_address(sg_page(sg)) + sg->offset; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1185 | ql_dbg(ql_dbg_io, vha, 0x3028, |
| 1186 | "%s(): Protection Data buffer = %p.\n", __func__, |
| 1187 | cp); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1188 | } |
| 1189 | avail_dsds--; |
| 1190 | } |
| 1191 | /* Null termination */ |
| 1192 | *cur_dsd++ = 0; |
| 1193 | *cur_dsd++ = 0; |
| 1194 | *cur_dsd++ = 0; |
| 1195 | return 0; |
| 1196 | } |
| 1197 | |
| 1198 | /** |
| 1199 | * qla24xx_build_scsi_crc_2_iocbs() - Build IOCB command utilizing Command |
| 1200 | * Type 6 IOCB types. |
| 1201 | * |
| 1202 | * @sp: SRB command to process |
| 1203 | * @cmd_pkt: Command type 3 IOCB |
| 1204 | * @tot_dsds: Total number of segments to transfer |
| 1205 | */ |
| 1206 | static inline int |
| 1207 | qla24xx_build_scsi_crc_2_iocbs(srb_t *sp, struct cmd_type_crc_2 *cmd_pkt, |
| 1208 | uint16_t tot_dsds, uint16_t tot_prot_dsds, uint16_t fw_prot_opts) |
| 1209 | { |
| 1210 | uint32_t *cur_dsd, *fcp_dl; |
| 1211 | scsi_qla_host_t *vha; |
| 1212 | struct scsi_cmnd *cmd; |
| 1213 | struct scatterlist *cur_seg; |
| 1214 | int sgc; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1215 | uint32_t total_bytes = 0; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1216 | uint32_t data_bytes; |
| 1217 | uint32_t dif_bytes; |
| 1218 | uint8_t bundling = 1; |
| 1219 | uint16_t blk_size; |
| 1220 | uint8_t *clr_ptr; |
| 1221 | struct crc_context *crc_ctx_pkt = NULL; |
| 1222 | struct qla_hw_data *ha; |
| 1223 | uint8_t additional_fcpcdb_len; |
| 1224 | uint16_t fcp_cmnd_len; |
| 1225 | struct fcp_cmnd *fcp_cmnd; |
| 1226 | dma_addr_t crc_ctx_dma; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1227 | char tag[2]; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1228 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1229 | cmd = GET_CMD_SP(sp); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1230 | |
| 1231 | sgc = 0; |
| 1232 | /* Update entry type to indicate Command Type CRC_2 IOCB */ |
| 1233 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 1234 | __constant_cpu_to_le32(COMMAND_TYPE_CRC_2); |
| 1235 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1236 | vha = sp->fcport->vha; |
| 1237 | ha = vha->hw; |
| 1238 | |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1239 | /* No data transfer */ |
| 1240 | data_bytes = scsi_bufflen(cmd); |
| 1241 | if (!data_bytes || cmd->sc_data_direction == DMA_NONE) { |
| 1242 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 1243 | return QLA_SUCCESS; |
| 1244 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1245 | |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1246 | cmd_pkt->vp_index = sp->fcport->vha->vp_idx; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1247 | |
| 1248 | /* Set transfer direction */ |
| 1249 | if (cmd->sc_data_direction == DMA_TO_DEVICE) { |
| 1250 | cmd_pkt->control_flags = |
| 1251 | __constant_cpu_to_le16(CF_WRITE_DATA); |
| 1252 | } else if (cmd->sc_data_direction == DMA_FROM_DEVICE) { |
| 1253 | cmd_pkt->control_flags = |
| 1254 | __constant_cpu_to_le16(CF_READ_DATA); |
| 1255 | } |
| 1256 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1257 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1258 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP) || |
| 1259 | (scsi_get_prot_op(cmd) == SCSI_PROT_READ_STRIP) || |
| 1260 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_INSERT)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1261 | bundling = 0; |
| 1262 | |
| 1263 | /* Allocate CRC context from global pool */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1264 | crc_ctx_pkt = sp->u.scmd.ctx = |
| 1265 | dma_pool_alloc(ha->dl_dma_pool, GFP_ATOMIC, &crc_ctx_dma); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1266 | |
| 1267 | if (!crc_ctx_pkt) |
| 1268 | goto crc_queuing_error; |
| 1269 | |
| 1270 | /* Zero out CTX area. */ |
| 1271 | clr_ptr = (uint8_t *)crc_ctx_pkt; |
| 1272 | memset(clr_ptr, 0, sizeof(*crc_ctx_pkt)); |
| 1273 | |
| 1274 | crc_ctx_pkt->crc_ctx_dma = crc_ctx_dma; |
| 1275 | |
| 1276 | sp->flags |= SRB_CRC_CTX_DMA_VALID; |
| 1277 | |
| 1278 | /* Set handle */ |
| 1279 | crc_ctx_pkt->handle = cmd_pkt->handle; |
| 1280 | |
| 1281 | INIT_LIST_HEAD(&crc_ctx_pkt->dsd_list); |
| 1282 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 1283 | qla24xx_set_t10dif_tags(sp, (struct fw_dif_context *) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1284 | &crc_ctx_pkt->ref_tag, tot_prot_dsds); |
| 1285 | |
| 1286 | cmd_pkt->crc_context_address[0] = cpu_to_le32(LSD(crc_ctx_dma)); |
| 1287 | cmd_pkt->crc_context_address[1] = cpu_to_le32(MSD(crc_ctx_dma)); |
| 1288 | cmd_pkt->crc_context_len = CRC_CONTEXT_LEN_FW; |
| 1289 | |
| 1290 | /* Determine SCSI command length -- align to 4 byte boundary */ |
| 1291 | if (cmd->cmd_len > 16) { |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1292 | additional_fcpcdb_len = cmd->cmd_len - 16; |
| 1293 | if ((cmd->cmd_len % 4) != 0) { |
| 1294 | /* SCSI cmd > 16 bytes must be multiple of 4 */ |
| 1295 | goto crc_queuing_error; |
| 1296 | } |
| 1297 | fcp_cmnd_len = 12 + cmd->cmd_len + 4; |
| 1298 | } else { |
| 1299 | additional_fcpcdb_len = 0; |
| 1300 | fcp_cmnd_len = 12 + 16 + 4; |
| 1301 | } |
| 1302 | |
| 1303 | fcp_cmnd = &crc_ctx_pkt->fcp_cmnd; |
| 1304 | |
| 1305 | fcp_cmnd->additional_cdb_len = additional_fcpcdb_len; |
| 1306 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 1307 | fcp_cmnd->additional_cdb_len |= 1; |
| 1308 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 1309 | fcp_cmnd->additional_cdb_len |= 2; |
| 1310 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1311 | int_to_scsilun(cmd->device->lun, &fcp_cmnd->lun); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1312 | memcpy(fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len); |
| 1313 | cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(fcp_cmnd_len); |
| 1314 | cmd_pkt->fcp_cmnd_dseg_address[0] = cpu_to_le32( |
| 1315 | LSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); |
| 1316 | cmd_pkt->fcp_cmnd_dseg_address[1] = cpu_to_le32( |
| 1317 | MSD(crc_ctx_dma + CRC_CONTEXT_FCPCMND_OFF)); |
Uwe Kleine-König | 65155b3 | 2010-06-11 12:17:01 +0200 | [diff] [blame] | 1318 | fcp_cmnd->task_management = 0; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1319 | |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1320 | /* |
| 1321 | * Update tagged queuing modifier if using command tag queuing |
| 1322 | */ |
| 1323 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 1324 | switch (tag[0]) { |
| 1325 | case HEAD_OF_QUEUE_TAG: |
| 1326 | fcp_cmnd->task_attribute = TSK_HEAD_OF_QUEUE; |
| 1327 | break; |
| 1328 | case ORDERED_QUEUE_TAG: |
| 1329 | fcp_cmnd->task_attribute = TSK_ORDERED; |
| 1330 | break; |
| 1331 | default: |
| 1332 | fcp_cmnd->task_attribute = 0; |
| 1333 | break; |
| 1334 | } |
| 1335 | } else { |
| 1336 | fcp_cmnd->task_attribute = 0; |
| 1337 | } |
| 1338 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1339 | cmd_pkt->fcp_rsp_dseg_len = 0; /* Let response come in status iocb */ |
| 1340 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1341 | /* Compute dif len and adjust data len to incude protection */ |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1342 | dif_bytes = 0; |
| 1343 | blk_size = cmd->device->sector_size; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1344 | dif_bytes = (data_bytes / blk_size) * 8; |
| 1345 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1346 | switch (scsi_get_prot_op(GET_CMD_SP(sp))) { |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1347 | case SCSI_PROT_READ_INSERT: |
| 1348 | case SCSI_PROT_WRITE_STRIP: |
| 1349 | total_bytes = data_bytes; |
| 1350 | data_bytes += dif_bytes; |
| 1351 | break; |
| 1352 | |
| 1353 | case SCSI_PROT_READ_STRIP: |
| 1354 | case SCSI_PROT_WRITE_INSERT: |
| 1355 | case SCSI_PROT_READ_PASS: |
| 1356 | case SCSI_PROT_WRITE_PASS: |
| 1357 | total_bytes = data_bytes + dif_bytes; |
| 1358 | break; |
| 1359 | default: |
| 1360 | BUG(); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1361 | } |
| 1362 | |
Arun Easi | e02587d | 2011-08-16 11:29:23 -0700 | [diff] [blame] | 1363 | if (!qla2x00_hba_err_chk_enabled(sp)) |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1364 | fw_prot_opts |= 0x10; /* Disable Guard tag checking */ |
| 1365 | |
| 1366 | if (!bundling) { |
| 1367 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.nobundling.data_address; |
| 1368 | } else { |
| 1369 | /* |
| 1370 | * Configure Bundling if we need to fetch interlaving |
| 1371 | * protection PCI accesses |
| 1372 | */ |
| 1373 | fw_prot_opts |= PO_ENABLE_DIF_BUNDLING; |
| 1374 | crc_ctx_pkt->u.bundling.dif_byte_count = cpu_to_le32(dif_bytes); |
| 1375 | crc_ctx_pkt->u.bundling.dseg_count = cpu_to_le16(tot_dsds - |
| 1376 | tot_prot_dsds); |
| 1377 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.data_address; |
| 1378 | } |
| 1379 | |
| 1380 | /* Finish the common fields of CRC pkt */ |
| 1381 | crc_ctx_pkt->blk_size = cpu_to_le16(blk_size); |
| 1382 | crc_ctx_pkt->prot_opts = cpu_to_le16(fw_prot_opts); |
| 1383 | crc_ctx_pkt->byte_count = cpu_to_le32(data_bytes); |
| 1384 | crc_ctx_pkt->guard_seed = __constant_cpu_to_le16(0); |
| 1385 | /* Fibre channel byte count */ |
| 1386 | cmd_pkt->byte_count = cpu_to_le32(total_bytes); |
| 1387 | fcp_dl = (uint32_t *)(crc_ctx_pkt->fcp_cmnd.cdb + 16 + |
| 1388 | additional_fcpcdb_len); |
| 1389 | *fcp_dl = htonl(total_bytes); |
| 1390 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1391 | if (!data_bytes || cmd->sc_data_direction == DMA_NONE) { |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1392 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 1393 | return QLA_SUCCESS; |
| 1394 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1395 | /* Walks data segments */ |
| 1396 | |
| 1397 | cmd_pkt->control_flags |= |
| 1398 | __constant_cpu_to_le16(CF_DATA_SEG_DESCR_ENABLE); |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1399 | |
| 1400 | if (!bundling && tot_prot_dsds) { |
| 1401 | if (qla24xx_walk_and_build_sglist_no_difb(ha, sp, |
| 1402 | cur_dsd, tot_dsds)) |
| 1403 | goto crc_queuing_error; |
| 1404 | } else if (qla24xx_walk_and_build_sglist(ha, sp, cur_dsd, |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1405 | (tot_dsds - tot_prot_dsds))) |
| 1406 | goto crc_queuing_error; |
| 1407 | |
| 1408 | if (bundling && tot_prot_dsds) { |
| 1409 | /* Walks dif segments */ |
| 1410 | cur_seg = scsi_prot_sglist(cmd); |
| 1411 | cmd_pkt->control_flags |= |
| 1412 | __constant_cpu_to_le16(CF_DIF_SEG_DESCR_ENABLE); |
| 1413 | cur_dsd = (uint32_t *) &crc_ctx_pkt->u.bundling.dif_address; |
| 1414 | if (qla24xx_walk_and_build_prot_sglist(ha, sp, cur_dsd, |
| 1415 | tot_prot_dsds)) |
| 1416 | goto crc_queuing_error; |
| 1417 | } |
| 1418 | return QLA_SUCCESS; |
| 1419 | |
| 1420 | crc_queuing_error: |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1421 | /* Cleanup will be performed by the caller */ |
| 1422 | |
| 1423 | return QLA_FUNCTION_FAILED; |
| 1424 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1425 | |
| 1426 | /** |
| 1427 | * qla24xx_start_scsi() - Send a SCSI command to the ISP |
| 1428 | * @sp: command to send to the ISP |
| 1429 | * |
Bjorn Helgaas | cc3ef7b | 2008-09-11 21:22:51 -0700 | [diff] [blame] | 1430 | * Returns non-zero if a failure occurred, else zero. |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1431 | */ |
| 1432 | int |
| 1433 | qla24xx_start_scsi(srb_t *sp) |
| 1434 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1435 | int ret, nseg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1436 | unsigned long flags; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1437 | uint32_t *clr_ptr; |
| 1438 | uint32_t index; |
| 1439 | uint32_t handle; |
| 1440 | struct cmd_type_7 *cmd_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1441 | uint16_t cnt; |
| 1442 | uint16_t req_cnt; |
| 1443 | uint16_t tot_dsds; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1444 | struct req_que *req = NULL; |
| 1445 | struct rsp_que *rsp = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1446 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Andrew Vasquez | 444786d | 2009-01-05 11:18:10 -0800 | [diff] [blame] | 1447 | struct scsi_qla_host *vha = sp->fcport->vha; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1448 | struct qla_hw_data *ha = vha->hw; |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1449 | char tag[2]; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1450 | |
| 1451 | /* Setup device pointers. */ |
| 1452 | ret = 0; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1453 | |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1454 | qla25xx_set_que(sp, &rsp); |
| 1455 | req = vha->req; |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1456 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1457 | /* So we know we haven't pci_map'ed anything yet */ |
| 1458 | tot_dsds = 0; |
| 1459 | |
| 1460 | /* Send marker if required */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1461 | if (vha->marker_needed != 0) { |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1462 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1463 | QLA_SUCCESS) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1464 | return QLA_FUNCTION_FAILED; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1465 | vha->marker_needed = 0; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1466 | } |
| 1467 | |
| 1468 | /* Acquire ring specific lock */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1469 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1470 | |
| 1471 | /* Check for room in outstanding command list. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1472 | handle = req->current_outstanding_cmd; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1473 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 1474 | handle++; |
| 1475 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 1476 | handle = 1; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1477 | if (!req->outstanding_cmds[handle]) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1478 | break; |
| 1479 | } |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1480 | if (index == MAX_OUTSTANDING_COMMANDS) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1481 | goto queuing_error; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1482 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1483 | |
| 1484 | /* 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] | 1485 | if (scsi_sg_count(cmd)) { |
| 1486 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1487 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1488 | if (unlikely(!nseg)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1489 | goto queuing_error; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 1490 | } else |
| 1491 | nseg = 0; |
| 1492 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1493 | tot_dsds = nseg; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1494 | req_cnt = qla24xx_calc_iocbs(vha, tot_dsds); |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1495 | if (req->cnt < (req_cnt + 2)) { |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 1496 | cnt = RD_REG_DWORD_RELAXED(req->req_q_out); |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1497 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1498 | if (req->ring_index < cnt) |
| 1499 | req->cnt = cnt - req->ring_index; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1500 | else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1501 | req->cnt = req->length - |
| 1502 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 1503 | if (req->cnt < (req_cnt + 2)) |
| 1504 | goto queuing_error; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1505 | } |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1506 | |
| 1507 | /* Build command packet. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1508 | req->current_outstanding_cmd = handle; |
| 1509 | req->outstanding_cmds[handle] = sp; |
Andrew Vasquez | cf53b06 | 2009-08-20 11:06:04 -0700 | [diff] [blame] | 1510 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1511 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1512 | req->cnt -= req_cnt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1513 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1514 | cmd_pkt = (struct cmd_type_7 *)req->ring_ptr; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1515 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1516 | |
| 1517 | /* Zero out remaining portion of packet. */ |
James Bottomley | 72df832 | 2005-10-28 14:41:19 -0500 | [diff] [blame] | 1518 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1519 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 1520 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 1521 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 1522 | |
| 1523 | /* Set NPORT-ID and LUN number*/ |
| 1524 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1525 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1526 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 1527 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1528 | cmd_pkt->vp_index = sp->fcport->vha->vp_idx; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1529 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1530 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
andrew.vasquez@qlogic.com | 0d4be12 | 2006-02-07 08:45:35 -0800 | [diff] [blame] | 1531 | 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] | 1532 | |
Andrew Vasquez | ff2fc42 | 2011-02-23 15:27:15 -0800 | [diff] [blame] | 1533 | /* Update tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
| 1534 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 1535 | switch (tag[0]) { |
| 1536 | case HEAD_OF_QUEUE_TAG: |
| 1537 | cmd_pkt->task = TSK_HEAD_OF_QUEUE; |
| 1538 | break; |
| 1539 | case ORDERED_QUEUE_TAG: |
| 1540 | cmd_pkt->task = TSK_ORDERED; |
| 1541 | break; |
| 1542 | } |
| 1543 | } |
| 1544 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1545 | /* Load SCSI command packet. */ |
| 1546 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 1547 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 1548 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1549 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1550 | |
| 1551 | /* Build IOCB segments */ |
| 1552 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds); |
| 1553 | |
| 1554 | /* Set total data segment count. */ |
| 1555 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1556 | /* Specify response queue number where completion should happen */ |
| 1557 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1558 | wmb(); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1559 | /* Adjust ring index. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1560 | req->ring_index++; |
| 1561 | if (req->ring_index == req->length) { |
| 1562 | req->ring_index = 0; |
| 1563 | req->ring_ptr = req->ring; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1564 | } else |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1565 | req->ring_ptr++; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1566 | |
| 1567 | sp->flags |= SRB_DMA_VALID; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1568 | |
| 1569 | /* Set chip new ring index. */ |
Andrew Vasquez | 0802999 | 2009-03-24 09:07:55 -0700 | [diff] [blame] | 1570 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 1571 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1572 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1573 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1574 | if (vha->flags.process_response_queue && |
Anirban Chakraborty | 73208df | 2008-12-09 16:45:39 -0800 | [diff] [blame] | 1575 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
Anirban Chakraborty | 2afa19a | 2009-04-06 22:33:40 -0700 | [diff] [blame] | 1576 | qla24xx_process_response_queue(vha, rsp); |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 1577 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1578 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1579 | return QLA_SUCCESS; |
| 1580 | |
| 1581 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 1582 | if (tot_dsds) |
| 1583 | scsi_dma_unmap(cmd); |
| 1584 | |
Anirban Chakraborty | e315cd2 | 2008-11-06 10:40:51 -0800 | [diff] [blame] | 1585 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 1586 | |
| 1587 | return QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | } |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1589 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1590 | |
| 1591 | /** |
| 1592 | * qla24xx_dif_start_scsi() - Send a SCSI command to the ISP |
| 1593 | * @sp: command to send to the ISP |
| 1594 | * |
| 1595 | * Returns non-zero if a failure occurred, else zero. |
| 1596 | */ |
| 1597 | int |
| 1598 | qla24xx_dif_start_scsi(srb_t *sp) |
| 1599 | { |
| 1600 | int nseg; |
| 1601 | unsigned long flags; |
| 1602 | uint32_t *clr_ptr; |
| 1603 | uint32_t index; |
| 1604 | uint32_t handle; |
| 1605 | uint16_t cnt; |
| 1606 | uint16_t req_cnt = 0; |
| 1607 | uint16_t tot_dsds; |
| 1608 | uint16_t tot_prot_dsds; |
| 1609 | uint16_t fw_prot_opts = 0; |
| 1610 | struct req_que *req = NULL; |
| 1611 | struct rsp_que *rsp = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1612 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1613 | struct scsi_qla_host *vha = sp->fcport->vha; |
| 1614 | struct qla_hw_data *ha = vha->hw; |
| 1615 | struct cmd_type_crc_2 *cmd_pkt; |
| 1616 | uint32_t status = 0; |
| 1617 | |
| 1618 | #define QDSS_GOT_Q_SPACE BIT_0 |
| 1619 | |
Arun Easi | 0c47087 | 2010-07-23 15:28:38 +0500 | [diff] [blame] | 1620 | /* Only process protection or >16 cdb in this routine */ |
| 1621 | if (scsi_get_prot_op(cmd) == SCSI_PROT_NORMAL) { |
| 1622 | if (cmd->cmd_len <= 16) |
| 1623 | return qla24xx_start_scsi(sp); |
| 1624 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1625 | |
| 1626 | /* Setup device pointers. */ |
| 1627 | |
| 1628 | qla25xx_set_que(sp, &rsp); |
| 1629 | req = vha->req; |
| 1630 | |
| 1631 | /* So we know we haven't pci_map'ed anything yet */ |
| 1632 | tot_dsds = 0; |
| 1633 | |
| 1634 | /* Send marker if required */ |
| 1635 | if (vha->marker_needed != 0) { |
| 1636 | if (qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL) != |
| 1637 | QLA_SUCCESS) |
| 1638 | return QLA_FUNCTION_FAILED; |
| 1639 | vha->marker_needed = 0; |
| 1640 | } |
| 1641 | |
| 1642 | /* Acquire ring specific lock */ |
| 1643 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 1644 | |
| 1645 | /* Check for room in outstanding command list. */ |
| 1646 | handle = req->current_outstanding_cmd; |
| 1647 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 1648 | handle++; |
| 1649 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 1650 | handle = 1; |
| 1651 | if (!req->outstanding_cmds[handle]) |
| 1652 | break; |
| 1653 | } |
| 1654 | |
| 1655 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 1656 | goto queuing_error; |
| 1657 | |
| 1658 | /* Compute number of required data segments */ |
| 1659 | /* Map the sg table so we have an accurate count of sg entries needed */ |
| 1660 | if (scsi_sg_count(cmd)) { |
| 1661 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 1662 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 1663 | if (unlikely(!nseg)) |
| 1664 | goto queuing_error; |
| 1665 | else |
| 1666 | sp->flags |= SRB_DMA_VALID; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1667 | |
| 1668 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1669 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 1670 | struct qla2_sgx sgx; |
| 1671 | uint32_t partial; |
| 1672 | |
| 1673 | memset(&sgx, 0, sizeof(struct qla2_sgx)); |
| 1674 | sgx.tot_bytes = scsi_bufflen(cmd); |
| 1675 | sgx.cur_sg = scsi_sglist(cmd); |
| 1676 | sgx.sp = sp; |
| 1677 | |
| 1678 | nseg = 0; |
| 1679 | while (qla24xx_get_one_block_sg( |
| 1680 | cmd->device->sector_size, &sgx, &partial)) |
| 1681 | nseg++; |
| 1682 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1683 | } else |
| 1684 | nseg = 0; |
| 1685 | |
| 1686 | /* number of required data segments */ |
| 1687 | tot_dsds = nseg; |
| 1688 | |
| 1689 | /* Compute number of required protection segments */ |
| 1690 | if (qla24xx_configure_prot_mode(sp, &fw_prot_opts)) { |
| 1691 | nseg = dma_map_sg(&ha->pdev->dev, scsi_prot_sglist(cmd), |
| 1692 | scsi_prot_sg_count(cmd), cmd->sc_data_direction); |
| 1693 | if (unlikely(!nseg)) |
| 1694 | goto queuing_error; |
| 1695 | else |
| 1696 | sp->flags |= SRB_CRC_PROT_DMA_VALID; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1697 | |
| 1698 | if ((scsi_get_prot_op(cmd) == SCSI_PROT_READ_INSERT) || |
| 1699 | (scsi_get_prot_op(cmd) == SCSI_PROT_WRITE_STRIP)) { |
| 1700 | nseg = scsi_bufflen(cmd) / cmd->device->sector_size; |
| 1701 | } |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1702 | } else { |
| 1703 | nseg = 0; |
| 1704 | } |
| 1705 | |
| 1706 | req_cnt = 1; |
| 1707 | /* Total Data and protection sg segment(s) */ |
| 1708 | tot_prot_dsds = nseg; |
| 1709 | tot_dsds += nseg; |
| 1710 | if (req->cnt < (req_cnt + 2)) { |
| 1711 | cnt = RD_REG_DWORD_RELAXED(req->req_q_out); |
| 1712 | |
| 1713 | if (req->ring_index < cnt) |
| 1714 | req->cnt = cnt - req->ring_index; |
| 1715 | else |
| 1716 | req->cnt = req->length - |
| 1717 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 1718 | if (req->cnt < (req_cnt + 2)) |
| 1719 | goto queuing_error; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1720 | } |
| 1721 | |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1722 | status |= QDSS_GOT_Q_SPACE; |
| 1723 | |
| 1724 | /* Build header part of command packet (excluding the OPCODE). */ |
| 1725 | req->current_outstanding_cmd = handle; |
| 1726 | req->outstanding_cmds[handle] = sp; |
Arun Easi | 8cb2049 | 2011-08-16 11:29:22 -0700 | [diff] [blame] | 1727 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1728 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1729 | req->cnt -= req_cnt; |
| 1730 | |
| 1731 | /* Fill-in common area */ |
| 1732 | cmd_pkt = (struct cmd_type_crc_2 *)req->ring_ptr; |
| 1733 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 1734 | |
| 1735 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 1736 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 1737 | |
| 1738 | /* Set NPORT-ID and LUN number*/ |
| 1739 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1740 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1741 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 1742 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
| 1743 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1744 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1745 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
| 1746 | |
| 1747 | /* Total Data and protection segment(s) */ |
| 1748 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 1749 | |
| 1750 | /* Build IOCB segments and adjust for data protection segments */ |
| 1751 | if (qla24xx_build_scsi_crc_2_iocbs(sp, (struct cmd_type_crc_2 *) |
| 1752 | req->ring_ptr, tot_dsds, tot_prot_dsds, fw_prot_opts) != |
| 1753 | QLA_SUCCESS) |
| 1754 | goto queuing_error; |
| 1755 | |
| 1756 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 1757 | /* Specify response queue number where completion should happen */ |
| 1758 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
| 1759 | cmd_pkt->timeout = __constant_cpu_to_le16(0); |
| 1760 | wmb(); |
| 1761 | |
| 1762 | /* Adjust ring index. */ |
| 1763 | req->ring_index++; |
| 1764 | if (req->ring_index == req->length) { |
| 1765 | req->ring_index = 0; |
| 1766 | req->ring_ptr = req->ring; |
| 1767 | } else |
| 1768 | req->ring_ptr++; |
| 1769 | |
| 1770 | /* Set chip new ring index. */ |
| 1771 | WRT_REG_DWORD(req->req_q_in, req->ring_index); |
| 1772 | RD_REG_DWORD_RELAXED(&ha->iobase->isp24.hccr); |
| 1773 | |
| 1774 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 1775 | if (vha->flags.process_response_queue && |
| 1776 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 1777 | qla24xx_process_response_queue(vha, rsp); |
| 1778 | |
| 1779 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 1780 | |
| 1781 | return QLA_SUCCESS; |
| 1782 | |
| 1783 | queuing_error: |
| 1784 | if (status & QDSS_GOT_Q_SPACE) { |
| 1785 | req->outstanding_cmds[handle] = NULL; |
| 1786 | req->cnt += req_cnt; |
| 1787 | } |
| 1788 | /* Cleanup will be performed by the caller (queuecommand) */ |
| 1789 | |
| 1790 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
Arun Easi | bad7500 | 2010-05-04 15:01:30 -0700 | [diff] [blame] | 1791 | return QLA_FUNCTION_FAILED; |
| 1792 | } |
| 1793 | |
| 1794 | |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1795 | static void qla25xx_set_que(srb_t *sp, struct rsp_que **rsp) |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1796 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1797 | struct scsi_cmnd *cmd = GET_CMD_SP(sp); |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1798 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 1799 | int affinity = cmd->request->cpu; |
| 1800 | |
Anirban Chakraborty | 7163ea8 | 2009-08-05 09:18:40 -0700 | [diff] [blame] | 1801 | if (ha->flags.cpu_affinity_enabled && affinity >= 0 && |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1802 | affinity < ha->max_rsp_queues - 1) |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1803 | *rsp = ha->rsp_q_map[affinity + 1]; |
Anirban Chakraborty | 59e0b8b | 2009-06-03 09:55:19 -0700 | [diff] [blame] | 1804 | else |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1805 | *rsp = ha->rsp_q_map[0]; |
Anirban Chakraborty | 68ca949 | 2009-04-06 22:33:41 -0700 | [diff] [blame] | 1806 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1807 | |
| 1808 | /* Generic Control-SRB manipulation functions. */ |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1809 | void * |
| 1810 | qla2x00_alloc_iocbs(scsi_qla_host_t *vha, srb_t *sp) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1811 | { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1812 | struct qla_hw_data *ha = vha->hw; |
| 1813 | struct req_que *req = ha->req_q_map[0]; |
| 1814 | device_reg_t __iomem *reg = ISP_QUE_REG(ha, req->id); |
| 1815 | uint32_t index, handle; |
| 1816 | request_t *pkt; |
| 1817 | uint16_t cnt, req_cnt; |
| 1818 | |
| 1819 | pkt = NULL; |
| 1820 | req_cnt = 1; |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1821 | handle = 0; |
| 1822 | |
| 1823 | if (!sp) |
| 1824 | goto skip_cmd_array; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1825 | |
| 1826 | /* Check for room in outstanding command list. */ |
| 1827 | handle = req->current_outstanding_cmd; |
| 1828 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 1829 | handle++; |
| 1830 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 1831 | handle = 1; |
| 1832 | if (!req->outstanding_cmds[handle]) |
| 1833 | break; |
| 1834 | } |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1835 | if (index == MAX_OUTSTANDING_COMMANDS) { |
| 1836 | ql_log(ql_log_warn, vha, 0x700b, |
| 1837 | "No room on oustanding cmd array.\n"); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1838 | goto queuing_error; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 1839 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1840 | |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1841 | /* Prep command array. */ |
| 1842 | req->current_outstanding_cmd = handle; |
| 1843 | req->outstanding_cmds[handle] = sp; |
| 1844 | sp->handle = handle; |
| 1845 | |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 1846 | /* Adjust entry-counts as needed. */ |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1847 | if (sp->type != SRB_SCSI_CMD) |
| 1848 | req_cnt = sp->iocbs; |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 1849 | |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1850 | skip_cmd_array: |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1851 | /* Check for room on request queue. */ |
| 1852 | if (req->cnt < req_cnt) { |
Giridhar Malavali | 6246b8a | 2012-02-09 11:15:34 -0800 | [diff] [blame] | 1853 | if (ha->mqenable || IS_QLA83XX(ha)) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1854 | cnt = RD_REG_DWORD(®->isp25mq.req_q_out); |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 1855 | else if (IS_QLA82XX(ha)) |
| 1856 | cnt = RD_REG_DWORD(®->isp82.req_q_out); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1857 | else if (IS_FWI2_CAPABLE(ha)) |
| 1858 | cnt = RD_REG_DWORD(®->isp24.req_q_out); |
| 1859 | else |
| 1860 | cnt = qla2x00_debounce_register( |
| 1861 | ISP_REQ_Q_OUT(ha, ®->isp)); |
| 1862 | |
| 1863 | if (req->ring_index < cnt) |
| 1864 | req->cnt = cnt - req->ring_index; |
| 1865 | else |
| 1866 | req->cnt = req->length - |
| 1867 | (req->ring_index - cnt); |
| 1868 | } |
| 1869 | if (req->cnt < req_cnt) |
| 1870 | goto queuing_error; |
| 1871 | |
| 1872 | /* Prep packet */ |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1873 | req->cnt -= req_cnt; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1874 | pkt = req->ring_ptr; |
| 1875 | memset(pkt, 0, REQUEST_ENTRY_SIZE); |
| 1876 | pkt->entry_count = req_cnt; |
| 1877 | pkt->handle = handle; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1878 | |
| 1879 | queuing_error: |
| 1880 | return pkt; |
| 1881 | } |
| 1882 | |
| 1883 | static void |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1884 | qla24xx_login_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 1885 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1886 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1887 | |
| 1888 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1889 | logio->control_flags = cpu_to_le16(LCF_COMMAND_PLOGI); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1890 | if (lio->u.logio.flags & SRB_LOGIN_COND_PLOGI) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1891 | logio->control_flags |= cpu_to_le16(LCF_COND_PLOGI); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1892 | if (lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI) |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1893 | logio->control_flags |= cpu_to_le16(LCF_SKIP_PRLI); |
| 1894 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1895 | logio->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1896 | logio->port_id[1] = sp->fcport->d_id.b.area; |
| 1897 | logio->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1898 | logio->vp_index = sp->fcport->vha->vp_idx; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1899 | } |
| 1900 | |
| 1901 | static void |
| 1902 | qla2x00_login_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 1903 | { |
| 1904 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1905 | struct srb_iocb *lio = &sp->u.iocb_cmd; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1906 | uint16_t opts; |
| 1907 | |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1908 | mbx->entry_type = MBX_IOCB_TYPE; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1909 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 1910 | mbx->mb0 = cpu_to_le16(MBC_LOGIN_FABRIC_PORT); |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 1911 | opts = lio->u.logio.flags & SRB_LOGIN_COND_PLOGI ? BIT_0 : 0; |
| 1912 | opts |= lio->u.logio.flags & SRB_LOGIN_SKIP_PRLI ? BIT_1 : 0; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1913 | if (HAS_EXTENDED_IDS(ha)) { |
| 1914 | mbx->mb1 = cpu_to_le16(sp->fcport->loop_id); |
| 1915 | mbx->mb10 = cpu_to_le16(opts); |
| 1916 | } else { |
| 1917 | mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | opts); |
| 1918 | } |
| 1919 | mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain); |
| 1920 | mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 | |
| 1921 | sp->fcport->d_id.b.al_pa); |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1922 | mbx->mb9 = cpu_to_le16(sp->fcport->vha->vp_idx); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1923 | } |
| 1924 | |
| 1925 | static void |
| 1926 | qla24xx_logout_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 1927 | { |
| 1928 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1929 | logio->control_flags = |
| 1930 | cpu_to_le16(LCF_COMMAND_LOGO|LCF_IMPL_LOGO); |
| 1931 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 1932 | logio->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 1933 | logio->port_id[1] = sp->fcport->d_id.b.area; |
| 1934 | logio->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1935 | logio->vp_index = sp->fcport->vha->vp_idx; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1936 | } |
| 1937 | |
| 1938 | static void |
| 1939 | qla2x00_logout_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 1940 | { |
| 1941 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 1942 | |
Giridhar Malavali | b963752 | 2010-05-28 15:08:15 -0700 | [diff] [blame] | 1943 | mbx->entry_type = MBX_IOCB_TYPE; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1944 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 1945 | mbx->mb0 = cpu_to_le16(MBC_LOGOUT_FABRIC_PORT); |
| 1946 | mbx->mb1 = HAS_EXTENDED_IDS(ha) ? |
| 1947 | cpu_to_le16(sp->fcport->loop_id): |
| 1948 | cpu_to_le16(sp->fcport->loop_id << 8); |
| 1949 | mbx->mb2 = cpu_to_le16(sp->fcport->d_id.b.domain); |
| 1950 | mbx->mb3 = cpu_to_le16(sp->fcport->d_id.b.area << 8 | |
| 1951 | sp->fcport->d_id.b.al_pa); |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1952 | mbx->mb9 = cpu_to_le16(sp->fcport->vha->vp_idx); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 1953 | /* Implicit: mbx->mbx10 = 0. */ |
| 1954 | } |
| 1955 | |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 1956 | static void |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1957 | qla24xx_adisc_iocb(srb_t *sp, struct logio_entry_24xx *logio) |
| 1958 | { |
| 1959 | logio->entry_type = LOGINOUT_PORT_IOCB_TYPE; |
| 1960 | logio->control_flags = cpu_to_le16(LCF_COMMAND_ADISC); |
| 1961 | logio->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1962 | logio->vp_index = sp->fcport->vha->vp_idx; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | static void |
| 1966 | qla2x00_adisc_iocb(srb_t *sp, struct mbx_entry *mbx) |
| 1967 | { |
| 1968 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 1969 | |
| 1970 | mbx->entry_type = MBX_IOCB_TYPE; |
| 1971 | SET_TARGET_ID(ha, mbx->loop_id, sp->fcport->loop_id); |
| 1972 | mbx->mb0 = cpu_to_le16(MBC_GET_PORT_DATABASE); |
| 1973 | if (HAS_EXTENDED_IDS(ha)) { |
| 1974 | mbx->mb1 = cpu_to_le16(sp->fcport->loop_id); |
| 1975 | mbx->mb10 = cpu_to_le16(BIT_0); |
| 1976 | } else { |
| 1977 | mbx->mb1 = cpu_to_le16((sp->fcport->loop_id << 8) | BIT_0); |
| 1978 | } |
| 1979 | mbx->mb2 = cpu_to_le16(MSW(ha->async_pd_dma)); |
| 1980 | mbx->mb3 = cpu_to_le16(LSW(ha->async_pd_dma)); |
| 1981 | mbx->mb6 = cpu_to_le16(MSW(MSD(ha->async_pd_dma))); |
| 1982 | mbx->mb7 = cpu_to_le16(LSW(MSD(ha->async_pd_dma))); |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 1983 | mbx->mb9 = cpu_to_le16(sp->fcport->vha->vp_idx); |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 1984 | } |
| 1985 | |
| 1986 | static void |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1987 | qla24xx_tm_iocb(srb_t *sp, struct tsk_mgmt_entry *tsk) |
| 1988 | { |
| 1989 | uint32_t flags; |
| 1990 | unsigned int lun; |
| 1991 | struct fc_port *fcport = sp->fcport; |
| 1992 | scsi_qla_host_t *vha = fcport->vha; |
| 1993 | struct qla_hw_data *ha = vha->hw; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 1994 | struct srb_iocb *iocb = &sp->u.iocb_cmd; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 1995 | struct req_que *req = vha->req; |
| 1996 | |
| 1997 | flags = iocb->u.tmf.flags; |
| 1998 | lun = iocb->u.tmf.lun; |
| 1999 | |
| 2000 | tsk->entry_type = TSK_MGMT_IOCB_TYPE; |
| 2001 | tsk->entry_count = 1; |
| 2002 | tsk->handle = MAKE_HANDLE(req->id, tsk->handle); |
| 2003 | tsk->nport_handle = cpu_to_le16(fcport->loop_id); |
| 2004 | tsk->timeout = cpu_to_le16(ha->r_a_tov / 10 * 2); |
| 2005 | tsk->control_flags = cpu_to_le32(flags); |
| 2006 | tsk->port_id[0] = fcport->d_id.b.al_pa; |
| 2007 | tsk->port_id[1] = fcport->d_id.b.area; |
| 2008 | tsk->port_id[2] = fcport->d_id.b.domain; |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 2009 | tsk->vp_index = fcport->vha->vp_idx; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 2010 | |
| 2011 | if (flags == TCF_LUN_RESET) { |
| 2012 | int_to_scsilun(lun, &tsk->lun); |
| 2013 | host_to_fcp_swap((uint8_t *)&tsk->lun, |
| 2014 | sizeof(tsk->lun)); |
| 2015 | } |
| 2016 | } |
| 2017 | |
| 2018 | static void |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2019 | qla24xx_els_iocb(srb_t *sp, struct els_entry_24xx *els_iocb) |
| 2020 | { |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2021 | struct fc_bsg_job *bsg_job = sp->u.bsg_job; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2022 | |
| 2023 | els_iocb->entry_type = ELS_IOCB_TYPE; |
| 2024 | els_iocb->entry_count = 1; |
| 2025 | els_iocb->sys_define = 0; |
| 2026 | els_iocb->entry_status = 0; |
| 2027 | els_iocb->handle = sp->handle; |
| 2028 | els_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2029 | els_iocb->tx_dsd_count = __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt); |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 2030 | els_iocb->vp_index = sp->fcport->vha->vp_idx; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2031 | els_iocb->sof_type = EST_SOFI3; |
| 2032 | els_iocb->rx_dsd_count = __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt); |
| 2033 | |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 2034 | els_iocb->opcode = |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2035 | sp->type == SRB_ELS_CMD_RPT ? |
Madhuranath Iyengar | 4916392 | 2010-05-04 15:01:28 -0700 | [diff] [blame] | 2036 | bsg_job->request->rqst_data.r_els.els_code : |
| 2037 | bsg_job->request->rqst_data.h_els.command_code; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2038 | els_iocb->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2039 | els_iocb->port_id[1] = sp->fcport->d_id.b.area; |
| 2040 | els_iocb->port_id[2] = sp->fcport->d_id.b.domain; |
| 2041 | els_iocb->control_flags = 0; |
| 2042 | els_iocb->rx_byte_count = |
| 2043 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2044 | els_iocb->tx_byte_count = |
| 2045 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2046 | |
| 2047 | els_iocb->tx_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2048 | (bsg_job->request_payload.sg_list))); |
| 2049 | els_iocb->tx_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2050 | (bsg_job->request_payload.sg_list))); |
| 2051 | els_iocb->tx_len = cpu_to_le32(sg_dma_len |
| 2052 | (bsg_job->request_payload.sg_list)); |
| 2053 | |
| 2054 | els_iocb->rx_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2055 | (bsg_job->reply_payload.sg_list))); |
| 2056 | els_iocb->rx_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2057 | (bsg_job->reply_payload.sg_list))); |
| 2058 | els_iocb->rx_len = cpu_to_le32(sg_dma_len |
| 2059 | (bsg_job->reply_payload.sg_list)); |
| 2060 | } |
| 2061 | |
| 2062 | static void |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2063 | qla2x00_ct_iocb(srb_t *sp, ms_iocb_entry_t *ct_iocb) |
| 2064 | { |
| 2065 | uint16_t avail_dsds; |
| 2066 | uint32_t *cur_dsd; |
| 2067 | struct scatterlist *sg; |
| 2068 | int index; |
| 2069 | uint16_t tot_dsds; |
| 2070 | scsi_qla_host_t *vha = sp->fcport->vha; |
| 2071 | struct qla_hw_data *ha = vha->hw; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2072 | struct fc_bsg_job *bsg_job = sp->u.bsg_job; |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2073 | int loop_iterartion = 0; |
| 2074 | int cont_iocb_prsnt = 0; |
| 2075 | int entry_count = 1; |
| 2076 | |
| 2077 | memset(ct_iocb, 0, sizeof(ms_iocb_entry_t)); |
| 2078 | ct_iocb->entry_type = CT_IOCB_TYPE; |
| 2079 | ct_iocb->entry_status = 0; |
| 2080 | ct_iocb->handle1 = sp->handle; |
| 2081 | SET_TARGET_ID(ha, ct_iocb->loop_id, sp->fcport->loop_id); |
| 2082 | ct_iocb->status = __constant_cpu_to_le16(0); |
| 2083 | ct_iocb->control_flags = __constant_cpu_to_le16(0); |
| 2084 | ct_iocb->timeout = 0; |
| 2085 | ct_iocb->cmd_dsd_count = |
| 2086 | __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt); |
| 2087 | ct_iocb->total_dsd_count = |
| 2088 | __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt + 1); |
| 2089 | ct_iocb->req_bytecount = |
| 2090 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2091 | ct_iocb->rsp_bytecount = |
| 2092 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2093 | |
| 2094 | ct_iocb->dseg_req_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2095 | (bsg_job->request_payload.sg_list))); |
| 2096 | ct_iocb->dseg_req_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2097 | (bsg_job->request_payload.sg_list))); |
| 2098 | ct_iocb->dseg_req_length = ct_iocb->req_bytecount; |
| 2099 | |
| 2100 | ct_iocb->dseg_rsp_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2101 | (bsg_job->reply_payload.sg_list))); |
| 2102 | ct_iocb->dseg_rsp_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2103 | (bsg_job->reply_payload.sg_list))); |
| 2104 | ct_iocb->dseg_rsp_length = ct_iocb->rsp_bytecount; |
| 2105 | |
| 2106 | avail_dsds = 1; |
| 2107 | cur_dsd = (uint32_t *)ct_iocb->dseg_rsp_address; |
| 2108 | index = 0; |
| 2109 | tot_dsds = bsg_job->reply_payload.sg_cnt; |
| 2110 | |
| 2111 | for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) { |
| 2112 | dma_addr_t sle_dma; |
| 2113 | cont_a64_entry_t *cont_pkt; |
| 2114 | |
| 2115 | /* Allocate additional continuation packets? */ |
| 2116 | if (avail_dsds == 0) { |
| 2117 | /* |
| 2118 | * Five DSDs are available in the Cont. |
| 2119 | * Type 1 IOCB. |
| 2120 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2121 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, |
| 2122 | vha->hw->req_q_map[0]); |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2123 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 2124 | avail_dsds = 5; |
| 2125 | cont_iocb_prsnt = 1; |
| 2126 | entry_count++; |
| 2127 | } |
| 2128 | |
| 2129 | sle_dma = sg_dma_address(sg); |
| 2130 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 2131 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 2132 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 2133 | loop_iterartion++; |
| 2134 | avail_dsds--; |
| 2135 | } |
| 2136 | ct_iocb->entry_count = entry_count; |
| 2137 | } |
| 2138 | |
| 2139 | static void |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2140 | qla24xx_ct_iocb(srb_t *sp, struct ct_entry_24xx *ct_iocb) |
| 2141 | { |
| 2142 | uint16_t avail_dsds; |
| 2143 | uint32_t *cur_dsd; |
| 2144 | struct scatterlist *sg; |
| 2145 | int index; |
| 2146 | uint16_t tot_dsds; |
| 2147 | scsi_qla_host_t *vha = sp->fcport->vha; |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2148 | struct qla_hw_data *ha = vha->hw; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2149 | struct fc_bsg_job *bsg_job = sp->u.bsg_job; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2150 | int loop_iterartion = 0; |
| 2151 | int cont_iocb_prsnt = 0; |
| 2152 | int entry_count = 1; |
| 2153 | |
| 2154 | ct_iocb->entry_type = CT_IOCB_TYPE; |
| 2155 | ct_iocb->entry_status = 0; |
| 2156 | ct_iocb->sys_define = 0; |
| 2157 | ct_iocb->handle = sp->handle; |
| 2158 | |
| 2159 | ct_iocb->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 2160 | ct_iocb->vp_index = sp->fcport->vha->vp_idx; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2161 | ct_iocb->comp_status = __constant_cpu_to_le16(0); |
| 2162 | |
| 2163 | ct_iocb->cmd_dsd_count = |
| 2164 | __constant_cpu_to_le16(bsg_job->request_payload.sg_cnt); |
| 2165 | ct_iocb->timeout = 0; |
| 2166 | ct_iocb->rsp_dsd_count = |
| 2167 | __constant_cpu_to_le16(bsg_job->reply_payload.sg_cnt); |
| 2168 | ct_iocb->rsp_byte_count = |
| 2169 | cpu_to_le32(bsg_job->reply_payload.payload_len); |
| 2170 | ct_iocb->cmd_byte_count = |
| 2171 | cpu_to_le32(bsg_job->request_payload.payload_len); |
| 2172 | ct_iocb->dseg_0_address[0] = cpu_to_le32(LSD(sg_dma_address |
| 2173 | (bsg_job->request_payload.sg_list))); |
| 2174 | ct_iocb->dseg_0_address[1] = cpu_to_le32(MSD(sg_dma_address |
| 2175 | (bsg_job->request_payload.sg_list))); |
| 2176 | ct_iocb->dseg_0_len = cpu_to_le32(sg_dma_len |
| 2177 | (bsg_job->request_payload.sg_list)); |
| 2178 | |
| 2179 | avail_dsds = 1; |
| 2180 | cur_dsd = (uint32_t *)ct_iocb->dseg_1_address; |
| 2181 | index = 0; |
| 2182 | tot_dsds = bsg_job->reply_payload.sg_cnt; |
| 2183 | |
| 2184 | for_each_sg(bsg_job->reply_payload.sg_list, sg, tot_dsds, index) { |
| 2185 | dma_addr_t sle_dma; |
| 2186 | cont_a64_entry_t *cont_pkt; |
| 2187 | |
| 2188 | /* Allocate additional continuation packets? */ |
| 2189 | if (avail_dsds == 0) { |
| 2190 | /* |
| 2191 | * Five DSDs are available in the Cont. |
| 2192 | * Type 1 IOCB. |
| 2193 | */ |
Giridhar Malavali | 0d2aa38 | 2011-11-18 09:02:21 -0800 | [diff] [blame] | 2194 | cont_pkt = qla2x00_prep_cont_type1_iocb(vha, |
| 2195 | ha->req_q_map[0]); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2196 | cur_dsd = (uint32_t *) cont_pkt->dseg_0_address; |
| 2197 | avail_dsds = 5; |
| 2198 | cont_iocb_prsnt = 1; |
| 2199 | entry_count++; |
| 2200 | } |
| 2201 | |
| 2202 | sle_dma = sg_dma_address(sg); |
| 2203 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 2204 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 2205 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 2206 | loop_iterartion++; |
| 2207 | avail_dsds--; |
| 2208 | } |
| 2209 | ct_iocb->entry_count = entry_count; |
| 2210 | } |
| 2211 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2212 | /* |
| 2213 | * qla82xx_start_scsi() - Send a SCSI command to the ISP |
| 2214 | * @sp: command to send to the ISP |
| 2215 | * |
| 2216 | * Returns non-zero if a failure occurred, else zero. |
| 2217 | */ |
| 2218 | int |
| 2219 | qla82xx_start_scsi(srb_t *sp) |
| 2220 | { |
| 2221 | int ret, nseg; |
| 2222 | unsigned long flags; |
| 2223 | struct scsi_cmnd *cmd; |
| 2224 | uint32_t *clr_ptr; |
| 2225 | uint32_t index; |
| 2226 | uint32_t handle; |
| 2227 | uint16_t cnt; |
| 2228 | uint16_t req_cnt; |
| 2229 | uint16_t tot_dsds; |
| 2230 | struct device_reg_82xx __iomem *reg; |
| 2231 | uint32_t dbval; |
| 2232 | uint32_t *fcp_dl; |
| 2233 | uint8_t additional_cdb_len; |
| 2234 | struct ct6_dsd *ctx; |
| 2235 | struct scsi_qla_host *vha = sp->fcport->vha; |
| 2236 | struct qla_hw_data *ha = vha->hw; |
| 2237 | struct req_que *req = NULL; |
| 2238 | struct rsp_que *rsp = NULL; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2239 | char tag[2]; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2240 | |
| 2241 | /* Setup device pointers. */ |
| 2242 | ret = 0; |
| 2243 | reg = &ha->iobase->isp82; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2244 | cmd = GET_CMD_SP(sp); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2245 | req = vha->req; |
| 2246 | rsp = ha->rsp_q_map[0]; |
| 2247 | |
| 2248 | /* So we know we haven't pci_map'ed anything yet */ |
| 2249 | tot_dsds = 0; |
| 2250 | |
| 2251 | dbval = 0x04 | (ha->portnum << 5); |
| 2252 | |
| 2253 | /* Send marker if required */ |
| 2254 | if (vha->marker_needed != 0) { |
| 2255 | if (qla2x00_marker(vha, req, |
| 2256 | rsp, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) { |
| 2257 | ql_log(ql_log_warn, vha, 0x300c, |
| 2258 | "qla2x00_marker failed for cmd=%p.\n", cmd); |
| 2259 | return QLA_FUNCTION_FAILED; |
| 2260 | } |
| 2261 | vha->marker_needed = 0; |
| 2262 | } |
| 2263 | |
| 2264 | /* Acquire ring specific lock */ |
| 2265 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 2266 | |
| 2267 | /* Check for room in outstanding command list. */ |
| 2268 | handle = req->current_outstanding_cmd; |
| 2269 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 2270 | handle++; |
| 2271 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 2272 | handle = 1; |
| 2273 | if (!req->outstanding_cmds[handle]) |
| 2274 | break; |
| 2275 | } |
| 2276 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 2277 | goto queuing_error; |
| 2278 | |
| 2279 | /* Map the sg table so we have an accurate count of sg entries needed */ |
| 2280 | if (scsi_sg_count(cmd)) { |
| 2281 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 2282 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 2283 | if (unlikely(!nseg)) |
| 2284 | goto queuing_error; |
| 2285 | } else |
| 2286 | nseg = 0; |
| 2287 | |
| 2288 | tot_dsds = nseg; |
| 2289 | |
| 2290 | if (tot_dsds > ql2xshiftctondsd) { |
| 2291 | struct cmd_type_6 *cmd_pkt; |
| 2292 | uint16_t more_dsd_lists = 0; |
| 2293 | struct dsd_dma *dsd_ptr; |
| 2294 | uint16_t i; |
| 2295 | |
| 2296 | more_dsd_lists = qla24xx_calc_dsd_lists(tot_dsds); |
| 2297 | if ((more_dsd_lists + ha->gbl_dsd_inuse) >= NUM_DSD_CHAIN) { |
| 2298 | ql_dbg(ql_dbg_io, vha, 0x300d, |
| 2299 | "Num of DSD list %d is than %d for cmd=%p.\n", |
| 2300 | more_dsd_lists + ha->gbl_dsd_inuse, NUM_DSD_CHAIN, |
| 2301 | cmd); |
| 2302 | goto queuing_error; |
| 2303 | } |
| 2304 | |
| 2305 | if (more_dsd_lists <= ha->gbl_dsd_avail) |
| 2306 | goto sufficient_dsds; |
| 2307 | else |
| 2308 | more_dsd_lists -= ha->gbl_dsd_avail; |
| 2309 | |
| 2310 | for (i = 0; i < more_dsd_lists; i++) { |
| 2311 | dsd_ptr = kzalloc(sizeof(struct dsd_dma), GFP_ATOMIC); |
| 2312 | if (!dsd_ptr) { |
| 2313 | ql_log(ql_log_fatal, vha, 0x300e, |
| 2314 | "Failed to allocate memory for dsd_dma " |
| 2315 | "for cmd=%p.\n", cmd); |
| 2316 | goto queuing_error; |
| 2317 | } |
| 2318 | |
| 2319 | dsd_ptr->dsd_addr = dma_pool_alloc(ha->dl_dma_pool, |
| 2320 | GFP_ATOMIC, &dsd_ptr->dsd_list_dma); |
| 2321 | if (!dsd_ptr->dsd_addr) { |
| 2322 | kfree(dsd_ptr); |
| 2323 | ql_log(ql_log_fatal, vha, 0x300f, |
| 2324 | "Failed to allocate memory for dsd_addr " |
| 2325 | "for cmd=%p.\n", cmd); |
| 2326 | goto queuing_error; |
| 2327 | } |
| 2328 | list_add_tail(&dsd_ptr->list, &ha->gbl_dsd_list); |
| 2329 | ha->gbl_dsd_avail++; |
| 2330 | } |
| 2331 | |
| 2332 | sufficient_dsds: |
| 2333 | req_cnt = 1; |
| 2334 | |
| 2335 | if (req->cnt < (req_cnt + 2)) { |
| 2336 | cnt = (uint16_t)RD_REG_DWORD_RELAXED( |
| 2337 | ®->req_q_out[0]); |
| 2338 | if (req->ring_index < cnt) |
| 2339 | req->cnt = cnt - req->ring_index; |
| 2340 | else |
| 2341 | req->cnt = req->length - |
| 2342 | (req->ring_index - cnt); |
Chetan Loke | a6eb3c9 | 2012-05-15 14:34:09 -0400 | [diff] [blame] | 2343 | if (req->cnt < (req_cnt + 2)) |
| 2344 | goto queuing_error; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2345 | } |
| 2346 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2347 | ctx = sp->u.scmd.ctx = |
| 2348 | mempool_alloc(ha->ctx_mempool, GFP_ATOMIC); |
| 2349 | if (!ctx) { |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2350 | ql_log(ql_log_fatal, vha, 0x3010, |
| 2351 | "Failed to allocate ctx for cmd=%p.\n", cmd); |
| 2352 | goto queuing_error; |
| 2353 | } |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2354 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2355 | memset(ctx, 0, sizeof(struct ct6_dsd)); |
| 2356 | ctx->fcp_cmnd = dma_pool_alloc(ha->fcp_cmnd_dma_pool, |
| 2357 | GFP_ATOMIC, &ctx->fcp_cmnd_dma); |
| 2358 | if (!ctx->fcp_cmnd) { |
| 2359 | ql_log(ql_log_fatal, vha, 0x3011, |
| 2360 | "Failed to allocate fcp_cmnd for cmd=%p.\n", cmd); |
| 2361 | goto queuing_error_fcp_cmnd; |
| 2362 | } |
| 2363 | |
| 2364 | /* Initialize the DSD list and dma handle */ |
| 2365 | INIT_LIST_HEAD(&ctx->dsd_list); |
| 2366 | ctx->dsd_use_cnt = 0; |
| 2367 | |
| 2368 | if (cmd->cmd_len > 16) { |
| 2369 | additional_cdb_len = cmd->cmd_len - 16; |
| 2370 | if ((cmd->cmd_len % 4) != 0) { |
| 2371 | /* SCSI command bigger than 16 bytes must be |
| 2372 | * multiple of 4 |
| 2373 | */ |
| 2374 | ql_log(ql_log_warn, vha, 0x3012, |
| 2375 | "scsi cmd len %d not multiple of 4 " |
| 2376 | "for cmd=%p.\n", cmd->cmd_len, cmd); |
| 2377 | goto queuing_error_fcp_cmnd; |
| 2378 | } |
| 2379 | ctx->fcp_cmnd_len = 12 + cmd->cmd_len + 4; |
| 2380 | } else { |
| 2381 | additional_cdb_len = 0; |
| 2382 | ctx->fcp_cmnd_len = 12 + 16 + 4; |
| 2383 | } |
| 2384 | |
| 2385 | cmd_pkt = (struct cmd_type_6 *)req->ring_ptr; |
| 2386 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 2387 | |
| 2388 | /* Zero out remaining portion of packet. */ |
| 2389 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
| 2390 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 2391 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 2392 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 2393 | |
| 2394 | /* Set NPORT-ID and LUN number*/ |
| 2395 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2396 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2397 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 2398 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 2399 | cmd_pkt->vp_index = sp->fcport->vha->vp_idx; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2400 | |
| 2401 | /* Build IOCB segments */ |
| 2402 | if (qla24xx_build_scsi_type_6_iocbs(sp, cmd_pkt, tot_dsds)) |
| 2403 | goto queuing_error_fcp_cmnd; |
| 2404 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2405 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2406 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, sizeof(cmd_pkt->lun)); |
| 2407 | |
| 2408 | /* build FCP_CMND IU */ |
| 2409 | memset(ctx->fcp_cmnd, 0, sizeof(struct fcp_cmnd)); |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2410 | int_to_scsilun(cmd->device->lun, &ctx->fcp_cmnd->lun); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2411 | ctx->fcp_cmnd->additional_cdb_len = additional_cdb_len; |
| 2412 | |
| 2413 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 2414 | ctx->fcp_cmnd->additional_cdb_len |= 1; |
| 2415 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 2416 | ctx->fcp_cmnd->additional_cdb_len |= 2; |
| 2417 | |
| 2418 | /* |
| 2419 | * Update tagged queuing modifier -- default is TSK_SIMPLE (0). |
| 2420 | */ |
| 2421 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 2422 | switch (tag[0]) { |
| 2423 | case HEAD_OF_QUEUE_TAG: |
| 2424 | ctx->fcp_cmnd->task_attribute = |
| 2425 | TSK_HEAD_OF_QUEUE; |
| 2426 | break; |
| 2427 | case ORDERED_QUEUE_TAG: |
| 2428 | ctx->fcp_cmnd->task_attribute = |
| 2429 | TSK_ORDERED; |
| 2430 | break; |
| 2431 | } |
| 2432 | } |
| 2433 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 2434 | /* Populate the FCP_PRIO. */ |
| 2435 | if (ha->flags.fcp_prio_enabled) |
| 2436 | ctx->fcp_cmnd->task_attribute |= |
| 2437 | sp->fcport->fcp_prio << 3; |
| 2438 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2439 | memcpy(ctx->fcp_cmnd->cdb, cmd->cmnd, cmd->cmd_len); |
| 2440 | |
| 2441 | fcp_dl = (uint32_t *)(ctx->fcp_cmnd->cdb + 16 + |
| 2442 | additional_cdb_len); |
| 2443 | *fcp_dl = htonl((uint32_t)scsi_bufflen(cmd)); |
| 2444 | |
| 2445 | cmd_pkt->fcp_cmnd_dseg_len = cpu_to_le16(ctx->fcp_cmnd_len); |
| 2446 | cmd_pkt->fcp_cmnd_dseg_address[0] = |
| 2447 | cpu_to_le32(LSD(ctx->fcp_cmnd_dma)); |
| 2448 | cmd_pkt->fcp_cmnd_dseg_address[1] = |
| 2449 | cpu_to_le32(MSD(ctx->fcp_cmnd_dma)); |
| 2450 | |
| 2451 | sp->flags |= SRB_FCP_CMND_DMA_VALID; |
| 2452 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
| 2453 | /* Set total data segment count. */ |
| 2454 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 2455 | /* Specify response queue number where |
| 2456 | * completion should happen |
| 2457 | */ |
| 2458 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
| 2459 | } else { |
| 2460 | struct cmd_type_7 *cmd_pkt; |
| 2461 | req_cnt = qla24xx_calc_iocbs(vha, tot_dsds); |
| 2462 | if (req->cnt < (req_cnt + 2)) { |
| 2463 | cnt = (uint16_t)RD_REG_DWORD_RELAXED( |
| 2464 | ®->req_q_out[0]); |
| 2465 | if (req->ring_index < cnt) |
| 2466 | req->cnt = cnt - req->ring_index; |
| 2467 | else |
| 2468 | req->cnt = req->length - |
| 2469 | (req->ring_index - cnt); |
| 2470 | } |
| 2471 | if (req->cnt < (req_cnt + 2)) |
| 2472 | goto queuing_error; |
| 2473 | |
| 2474 | cmd_pkt = (struct cmd_type_7 *)req->ring_ptr; |
| 2475 | cmd_pkt->handle = MAKE_HANDLE(req->id, handle); |
| 2476 | |
| 2477 | /* Zero out remaining portion of packet. */ |
| 2478 | /* tagged queuing modifier -- default is TSK_SIMPLE (0).*/ |
| 2479 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 2480 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 2481 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 2482 | |
| 2483 | /* Set NPORT-ID and LUN number*/ |
| 2484 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 2485 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 2486 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 2487 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Joe Carnuccio | c6d39e2 | 2012-05-15 14:34:20 -0400 | [diff] [blame^] | 2488 | cmd_pkt->vp_index = sp->fcport->vha->vp_idx; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2489 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2490 | int_to_scsilun(cmd->device->lun, &cmd_pkt->lun); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2491 | host_to_fcp_swap((uint8_t *)&cmd_pkt->lun, |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2492 | sizeof(cmd_pkt->lun)); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2493 | |
| 2494 | /* |
| 2495 | * Update tagged queuing modifier -- default is TSK_SIMPLE (0). |
| 2496 | */ |
| 2497 | if (scsi_populate_tag_msg(cmd, tag)) { |
| 2498 | switch (tag[0]) { |
| 2499 | case HEAD_OF_QUEUE_TAG: |
| 2500 | cmd_pkt->task = TSK_HEAD_OF_QUEUE; |
| 2501 | break; |
| 2502 | case ORDERED_QUEUE_TAG: |
| 2503 | cmd_pkt->task = TSK_ORDERED; |
| 2504 | break; |
| 2505 | } |
| 2506 | } |
| 2507 | |
Saurav Kashyap | a00f629 | 2011-11-18 09:03:19 -0800 | [diff] [blame] | 2508 | /* Populate the FCP_PRIO. */ |
| 2509 | if (ha->flags.fcp_prio_enabled) |
| 2510 | cmd_pkt->task |= sp->fcport->fcp_prio << 3; |
| 2511 | |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2512 | /* Load SCSI command packet. */ |
| 2513 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 2514 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 2515 | |
| 2516 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
| 2517 | |
| 2518 | /* Build IOCB segments */ |
| 2519 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds); |
| 2520 | |
| 2521 | /* Set total data segment count. */ |
| 2522 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 2523 | /* Specify response queue number where |
| 2524 | * completion should happen. |
| 2525 | */ |
| 2526 | cmd_pkt->entry_status = (uint8_t) rsp->id; |
| 2527 | |
| 2528 | } |
| 2529 | /* Build command packet. */ |
| 2530 | req->current_outstanding_cmd = handle; |
| 2531 | req->outstanding_cmds[handle] = sp; |
| 2532 | sp->handle = handle; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2533 | cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2534 | req->cnt -= req_cnt; |
| 2535 | wmb(); |
| 2536 | |
| 2537 | /* Adjust ring index. */ |
| 2538 | req->ring_index++; |
| 2539 | if (req->ring_index == req->length) { |
| 2540 | req->ring_index = 0; |
| 2541 | req->ring_ptr = req->ring; |
| 2542 | } else |
| 2543 | req->ring_ptr++; |
| 2544 | |
| 2545 | sp->flags |= SRB_DMA_VALID; |
| 2546 | |
| 2547 | /* Set chip new ring index. */ |
| 2548 | /* write, read and verify logic */ |
| 2549 | dbval = dbval | (req->id << 8) | (req->ring_index << 16); |
| 2550 | if (ql2xdbwr) |
| 2551 | qla82xx_wr_32(ha, ha->nxdb_wr_ptr, dbval); |
| 2552 | else { |
| 2553 | WRT_REG_DWORD( |
| 2554 | (unsigned long __iomem *)ha->nxdb_wr_ptr, |
| 2555 | dbval); |
| 2556 | wmb(); |
| 2557 | while (RD_REG_DWORD(ha->nxdb_rd_ptr) != dbval) { |
| 2558 | WRT_REG_DWORD( |
| 2559 | (unsigned long __iomem *)ha->nxdb_wr_ptr, |
| 2560 | dbval); |
| 2561 | wmb(); |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 2566 | if (vha->flags.process_response_queue && |
| 2567 | rsp->ring_ptr->signature != RESPONSE_PROCESSED) |
| 2568 | qla24xx_process_response_queue(vha, rsp); |
| 2569 | |
| 2570 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2571 | return QLA_SUCCESS; |
| 2572 | |
| 2573 | queuing_error_fcp_cmnd: |
| 2574 | dma_pool_free(ha->fcp_cmnd_dma_pool, ctx->fcp_cmnd, ctx->fcp_cmnd_dma); |
| 2575 | queuing_error: |
| 2576 | if (tot_dsds) |
| 2577 | scsi_dma_unmap(cmd); |
| 2578 | |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2579 | if (sp->u.scmd.ctx) { |
| 2580 | mempool_free(sp->u.scmd.ctx, ha->ctx_mempool); |
| 2581 | sp->u.scmd.ctx = NULL; |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2582 | } |
| 2583 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2584 | |
| 2585 | return QLA_FUNCTION_FAILED; |
| 2586 | } |
| 2587 | |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2588 | int |
| 2589 | qla2x00_start_sp(srb_t *sp) |
| 2590 | { |
| 2591 | int rval; |
| 2592 | struct qla_hw_data *ha = sp->fcport->vha->hw; |
| 2593 | void *pkt; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2594 | unsigned long flags; |
| 2595 | |
| 2596 | rval = QLA_FUNCTION_FAILED; |
| 2597 | spin_lock_irqsave(&ha->hardware_lock, flags); |
Giridhar Malavali | d94d10e | 2010-07-23 15:28:23 +0500 | [diff] [blame] | 2598 | pkt = qla2x00_alloc_iocbs(sp->fcport->vha, sp); |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2599 | if (!pkt) { |
| 2600 | ql_log(ql_log_warn, sp->fcport->vha, 0x700c, |
| 2601 | "qla2x00_alloc_iocbs failed.\n"); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2602 | goto done; |
Saurav Kashyap | 7c3df13 | 2011-07-14 12:00:13 -0700 | [diff] [blame] | 2603 | } |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2604 | |
| 2605 | rval = QLA_SUCCESS; |
Giridhar Malavali | 9ba56b9 | 2012-02-09 11:15:36 -0800 | [diff] [blame] | 2606 | switch (sp->type) { |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2607 | case SRB_LOGIN_CMD: |
| 2608 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2609 | qla24xx_login_iocb(sp, pkt) : |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2610 | qla2x00_login_iocb(sp, pkt); |
| 2611 | break; |
| 2612 | case SRB_LOGOUT_CMD: |
| 2613 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2614 | qla24xx_logout_iocb(sp, pkt) : |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2615 | qla2x00_logout_iocb(sp, pkt); |
| 2616 | break; |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2617 | case SRB_ELS_CMD_RPT: |
| 2618 | case SRB_ELS_CMD_HST: |
| 2619 | qla24xx_els_iocb(sp, pkt); |
| 2620 | break; |
| 2621 | case SRB_CT_CMD: |
Harish Zunjarrao | 9bc4f4f | 2010-07-23 15:28:32 +0500 | [diff] [blame] | 2622 | IS_FWI2_CAPABLE(ha) ? |
Andrew Vasquez | 5780790 | 2011-11-18 09:03:20 -0800 | [diff] [blame] | 2623 | qla24xx_ct_iocb(sp, pkt) : |
| 2624 | qla2x00_ct_iocb(sp, pkt); |
Giridhar Malavali | 9a069e1 | 2010-01-12 13:02:47 -0800 | [diff] [blame] | 2625 | break; |
Andrew Vasquez | 5ff1d58 | 2010-05-04 15:01:26 -0700 | [diff] [blame] | 2626 | case SRB_ADISC_CMD: |
| 2627 | IS_FWI2_CAPABLE(ha) ? |
| 2628 | qla24xx_adisc_iocb(sp, pkt) : |
| 2629 | qla2x00_adisc_iocb(sp, pkt); |
| 2630 | break; |
Madhuranath Iyengar | 3822263 | 2010-05-04 15:01:29 -0700 | [diff] [blame] | 2631 | case SRB_TM_CMD: |
| 2632 | qla24xx_tm_iocb(sp, pkt); |
| 2633 | break; |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2634 | default: |
| 2635 | break; |
| 2636 | } |
| 2637 | |
| 2638 | wmb(); |
Giridhar Malavali | 5162cf0 | 2011-11-18 09:03:18 -0800 | [diff] [blame] | 2639 | qla2x00_start_iocbs(sp->fcport->vha, ha->req_q_map[0]); |
Andrew Vasquez | ac280b6 | 2009-08-20 11:06:05 -0700 | [diff] [blame] | 2640 | done: |
| 2641 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 2642 | return rval; |
| 2643 | } |