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