Andrew Vasquez | fa90c54 | 2005-10-27 11:10:08 -0700 | [diff] [blame] | 1 | /* |
| 2 | * QLogic Fibre Channel HBA Driver |
Andrew Vasquez | 01e58d8 | 2008-04-03 13:13:13 -0700 | [diff] [blame] | 3 | * Copyright (c) 2003-2008 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | static request_t *qla2x00_req_pkt(scsi_qla_host_t *ha); |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 15 | static void qla2x00_isp_cmd(scsi_qla_host_t *ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | |
| 17 | /** |
| 18 | * qla2x00_get_cmd_direction() - Determine control_flag data direction. |
| 19 | * @cmd: SCSI command |
| 20 | * |
| 21 | * Returns the proper CF_* direction based on CDB. |
| 22 | */ |
| 23 | static inline uint16_t |
| 24 | qla2x00_get_cmd_direction(struct scsi_cmnd *cmd) |
| 25 | { |
| 26 | uint16_t cflags; |
| 27 | |
| 28 | cflags = 0; |
| 29 | |
| 30 | /* Set transfer direction */ |
| 31 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 32 | cflags = CF_WRITE; |
| 33 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 34 | cflags = CF_READ; |
| 35 | return (cflags); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * qla2x00_calc_iocbs_32() - Determine number of Command Type 2 and |
| 40 | * Continuation Type 0 IOCBs to allocate. |
| 41 | * |
| 42 | * @dsds: number of data segment decriptors needed |
| 43 | * |
| 44 | * Returns the number of IOCB entries needed to store @dsds. |
| 45 | */ |
| 46 | uint16_t |
| 47 | qla2x00_calc_iocbs_32(uint16_t dsds) |
| 48 | { |
| 49 | uint16_t iocbs; |
| 50 | |
| 51 | iocbs = 1; |
| 52 | if (dsds > 3) { |
| 53 | iocbs += (dsds - 3) / 7; |
| 54 | if ((dsds - 3) % 7) |
| 55 | iocbs++; |
| 56 | } |
| 57 | return (iocbs); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * qla2x00_calc_iocbs_64() - Determine number of Command Type 3 and |
| 62 | * Continuation Type 1 IOCBs to allocate. |
| 63 | * |
| 64 | * @dsds: number of data segment decriptors needed |
| 65 | * |
| 66 | * Returns the number of IOCB entries needed to store @dsds. |
| 67 | */ |
| 68 | uint16_t |
| 69 | qla2x00_calc_iocbs_64(uint16_t dsds) |
| 70 | { |
| 71 | uint16_t iocbs; |
| 72 | |
| 73 | iocbs = 1; |
| 74 | if (dsds > 2) { |
| 75 | iocbs += (dsds - 2) / 5; |
| 76 | if ((dsds - 2) % 5) |
| 77 | iocbs++; |
| 78 | } |
| 79 | return (iocbs); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * qla2x00_prep_cont_type0_iocb() - Initialize a Continuation Type 0 IOCB. |
| 84 | * @ha: HA context |
| 85 | * |
| 86 | * Returns a pointer to the Continuation Type 0 IOCB packet. |
| 87 | */ |
| 88 | static inline cont_entry_t * |
| 89 | qla2x00_prep_cont_type0_iocb(scsi_qla_host_t *ha) |
| 90 | { |
| 91 | cont_entry_t *cont_pkt; |
| 92 | |
| 93 | /* Adjust ring index. */ |
| 94 | ha->req_ring_index++; |
| 95 | if (ha->req_ring_index == ha->request_q_length) { |
| 96 | ha->req_ring_index = 0; |
| 97 | ha->request_ring_ptr = ha->request_ring; |
| 98 | } else { |
| 99 | ha->request_ring_ptr++; |
| 100 | } |
| 101 | |
| 102 | cont_pkt = (cont_entry_t *)ha->request_ring_ptr; |
| 103 | |
| 104 | /* Load packet defaults. */ |
| 105 | *((uint32_t *)(&cont_pkt->entry_type)) = |
| 106 | __constant_cpu_to_le32(CONTINUE_TYPE); |
| 107 | |
| 108 | return (cont_pkt); |
| 109 | } |
| 110 | |
| 111 | /** |
| 112 | * qla2x00_prep_cont_type1_iocb() - Initialize a Continuation Type 1 IOCB. |
| 113 | * @ha: HA context |
| 114 | * |
| 115 | * Returns a pointer to the continuation type 1 IOCB packet. |
| 116 | */ |
| 117 | static inline cont_a64_entry_t * |
| 118 | qla2x00_prep_cont_type1_iocb(scsi_qla_host_t *ha) |
| 119 | { |
| 120 | cont_a64_entry_t *cont_pkt; |
| 121 | |
| 122 | /* Adjust ring index. */ |
| 123 | ha->req_ring_index++; |
| 124 | if (ha->req_ring_index == ha->request_q_length) { |
| 125 | ha->req_ring_index = 0; |
| 126 | ha->request_ring_ptr = ha->request_ring; |
| 127 | } else { |
| 128 | ha->request_ring_ptr++; |
| 129 | } |
| 130 | |
| 131 | cont_pkt = (cont_a64_entry_t *)ha->request_ring_ptr; |
| 132 | |
| 133 | /* Load packet defaults. */ |
| 134 | *((uint32_t *)(&cont_pkt->entry_type)) = |
| 135 | __constant_cpu_to_le32(CONTINUE_A64_TYPE); |
| 136 | |
| 137 | return (cont_pkt); |
| 138 | } |
| 139 | |
| 140 | /** |
| 141 | * qla2x00_build_scsi_iocbs_32() - Build IOCB command utilizing 32bit |
| 142 | * capable IOCB types. |
| 143 | * |
| 144 | * @sp: SRB command to process |
| 145 | * @cmd_pkt: Command type 2 IOCB |
| 146 | * @tot_dsds: Total number of segments to transfer |
| 147 | */ |
| 148 | void qla2x00_build_scsi_iocbs_32(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 149 | uint16_t tot_dsds) |
| 150 | { |
| 151 | uint16_t avail_dsds; |
| 152 | uint32_t *cur_dsd; |
| 153 | scsi_qla_host_t *ha; |
| 154 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 155 | struct scatterlist *sg; |
| 156 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 157 | |
| 158 | cmd = sp->cmd; |
| 159 | |
| 160 | /* Update entry type to indicate Command Type 2 IOCB */ |
| 161 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 162 | __constant_cpu_to_le32(COMMAND_TYPE); |
| 163 | |
| 164 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 165 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 167 | return; |
| 168 | } |
| 169 | |
| 170 | ha = sp->ha; |
| 171 | |
| 172 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(cmd)); |
| 173 | |
| 174 | /* Three DSDs are available in the Command Type 2 IOCB */ |
| 175 | avail_dsds = 3; |
| 176 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 177 | |
| 178 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 179 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 180 | cont_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 182 | /* Allocate additional continuation packets? */ |
| 183 | if (avail_dsds == 0) { |
| 184 | /* |
| 185 | * Seven DSDs are available in the Continuation |
| 186 | * Type 0 IOCB. |
| 187 | */ |
| 188 | cont_pkt = qla2x00_prep_cont_type0_iocb(ha); |
| 189 | cur_dsd = (uint32_t *)&cont_pkt->dseg_0_address; |
| 190 | avail_dsds = 7; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 192 | |
| 193 | *cur_dsd++ = cpu_to_le32(sg_dma_address(sg)); |
| 194 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 195 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | } |
| 197 | } |
| 198 | |
| 199 | /** |
| 200 | * qla2x00_build_scsi_iocbs_64() - Build IOCB command utilizing 64bit |
| 201 | * capable IOCB types. |
| 202 | * |
| 203 | * @sp: SRB command to process |
| 204 | * @cmd_pkt: Command type 3 IOCB |
| 205 | * @tot_dsds: Total number of segments to transfer |
| 206 | */ |
| 207 | void qla2x00_build_scsi_iocbs_64(srb_t *sp, cmd_entry_t *cmd_pkt, |
| 208 | uint16_t tot_dsds) |
| 209 | { |
| 210 | uint16_t avail_dsds; |
| 211 | uint32_t *cur_dsd; |
| 212 | scsi_qla_host_t *ha; |
| 213 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 214 | struct scatterlist *sg; |
| 215 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | cmd = sp->cmd; |
| 218 | |
| 219 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 220 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 221 | __constant_cpu_to_le32(COMMAND_A64_TYPE); |
| 222 | |
| 223 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 224 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 226 | return; |
| 227 | } |
| 228 | |
| 229 | ha = sp->ha; |
| 230 | |
| 231 | cmd_pkt->control_flags |= cpu_to_le16(qla2x00_get_cmd_direction(cmd)); |
| 232 | |
| 233 | /* Two DSDs are available in the Command Type 3 IOCB */ |
| 234 | avail_dsds = 2; |
| 235 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 236 | |
| 237 | /* Load data segments */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 238 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 239 | dma_addr_t sle_dma; |
| 240 | cont_a64_entry_t *cont_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 242 | /* Allocate additional continuation packets? */ |
| 243 | if (avail_dsds == 0) { |
| 244 | /* |
| 245 | * Five DSDs are available in the Continuation |
| 246 | * Type 1 IOCB. |
| 247 | */ |
| 248 | cont_pkt = qla2x00_prep_cont_type1_iocb(ha); |
| 249 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 250 | avail_dsds = 5; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 252 | |
| 253 | sle_dma = sg_dma_address(sg); |
| 254 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 255 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 256 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 257 | avail_dsds--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | } |
| 259 | } |
| 260 | |
| 261 | /** |
| 262 | * qla2x00_start_scsi() - Send a SCSI command to the ISP |
| 263 | * @sp: command to send to the ISP |
| 264 | * |
| 265 | * Returns non-zero if a failure occured, else zero. |
| 266 | */ |
| 267 | int |
| 268 | qla2x00_start_scsi(srb_t *sp) |
| 269 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 270 | int ret, nseg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | unsigned long flags; |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 272 | scsi_qla_host_t *ha, *pha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | struct scsi_cmnd *cmd; |
| 274 | uint32_t *clr_ptr; |
| 275 | uint32_t index; |
| 276 | uint32_t handle; |
| 277 | cmd_entry_t *cmd_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | uint16_t cnt; |
| 279 | uint16_t req_cnt; |
| 280 | uint16_t tot_dsds; |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 281 | struct device_reg_2xxx __iomem *reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 282 | |
| 283 | /* Setup device pointers. */ |
| 284 | ret = 0; |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 285 | ha = sp->ha; |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 286 | pha = to_qla_parent(ha); |
Andrew Vasquez | 3d71644 | 2005-07-06 10:30:26 -0700 | [diff] [blame] | 287 | reg = &ha->iobase->isp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | cmd = sp->cmd; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 289 | /* So we know we haven't pci_map'ed anything yet */ |
| 290 | tot_dsds = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | /* Send marker if required */ |
| 293 | if (ha->marker_needed != 0) { |
| 294 | if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) { |
| 295 | return (QLA_FUNCTION_FAILED); |
| 296 | } |
| 297 | ha->marker_needed = 0; |
| 298 | } |
| 299 | |
| 300 | /* Acquire ring specific lock */ |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 301 | spin_lock_irqsave(&pha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | |
| 303 | /* Check for room in outstanding command list. */ |
| 304 | handle = ha->current_outstanding_cmd; |
| 305 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 306 | handle++; |
| 307 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 308 | handle = 1; |
Andrew Vasquez | 700ca0e | 2007-09-20 14:07:46 -0700 | [diff] [blame] | 309 | if (!ha->outstanding_cmds[handle]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | break; |
| 311 | } |
| 312 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 313 | goto queuing_error; |
| 314 | |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 315 | /* 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] | 316 | if (scsi_sg_count(cmd)) { |
| 317 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 318 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 319 | if (unlikely(!nseg)) |
| 320 | goto queuing_error; |
| 321 | } else |
| 322 | nseg = 0; |
| 323 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 324 | tot_dsds = nseg; |
| 8302192 | 2005-04-17 15:10:41 -0500 | [diff] [blame] | 325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | /* Calculate the number of request entries needed. */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 327 | req_cnt = ha->isp_ops->calc_req_entries(tot_dsds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | if (ha->req_q_cnt < (req_cnt + 2)) { |
| 329 | cnt = RD_REG_WORD_RELAXED(ISP_REQ_Q_OUT(ha, reg)); |
| 330 | if (ha->req_ring_index < cnt) |
| 331 | ha->req_q_cnt = cnt - ha->req_ring_index; |
| 332 | else |
| 333 | ha->req_q_cnt = ha->request_q_length - |
| 334 | (ha->req_ring_index - cnt); |
| 335 | } |
| 336 | if (ha->req_q_cnt < (req_cnt + 2)) |
| 337 | goto queuing_error; |
| 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* Build command packet */ |
| 340 | ha->current_outstanding_cmd = handle; |
| 341 | ha->outstanding_cmds[handle] = sp; |
| 342 | sp->ha = ha; |
| 343 | sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
| 344 | ha->req_q_cnt -= req_cnt; |
| 345 | |
| 346 | cmd_pkt = (cmd_entry_t *)ha->request_ring_ptr; |
| 347 | cmd_pkt->handle = handle; |
| 348 | /* Zero out remaining portion of packet. */ |
| 349 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 350 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 351 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 352 | |
| bdf7962 | 2005-04-17 15:06:53 -0500 | [diff] [blame] | 353 | /* Set target ID and LUN number*/ |
| 354 | SET_TARGET_ID(ha, cmd_pkt->target, sp->fcport->loop_id); |
| 355 | cmd_pkt->lun = cpu_to_le16(sp->cmd->device->lun); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | |
| 357 | /* Update tagged queuing modifier */ |
| 358 | cmd_pkt->control_flags = __constant_cpu_to_le16(CF_SIMPLE_TAG); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | /* Load SCSI command packet. */ |
| 361 | memcpy(cmd_pkt->scsi_cdb, cmd->cmnd, cmd->cmd_len); |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 362 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
| 364 | /* Build IOCB segments */ |
Andrew Vasquez | fd34f55 | 2007-07-19 15:06:00 -0700 | [diff] [blame] | 365 | ha->isp_ops->build_iocbs(sp, cmd_pkt, tot_dsds); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | |
| 367 | /* Set total data segment count. */ |
| 368 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 369 | wmb(); |
| 370 | |
| 371 | /* Adjust ring index. */ |
| 372 | ha->req_ring_index++; |
| 373 | if (ha->req_ring_index == ha->request_q_length) { |
| 374 | ha->req_ring_index = 0; |
| 375 | ha->request_ring_ptr = ha->request_ring; |
| 376 | } else |
| 377 | ha->request_ring_ptr++; |
| 378 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | sp->flags |= SRB_DMA_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 380 | |
| 381 | /* Set chip new ring index. */ |
| 382 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), ha->req_ring_index); |
| 383 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, reg)); /* PCI Posting. */ |
| 384 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 385 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 386 | if (ha->flags.process_response_queue && |
| 387 | ha->response_ring_ptr->signature != RESPONSE_PROCESSED) |
| 388 | qla2x00_process_response_queue(ha); |
| 389 | |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 390 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | return (QLA_SUCCESS); |
| 392 | |
| 393 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 394 | if (tot_dsds) |
| 395 | scsi_dma_unmap(cmd); |
| 396 | |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 397 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | return (QLA_FUNCTION_FAILED); |
| 400 | } |
| 401 | |
| 402 | /** |
| 403 | * qla2x00_marker() - Send a marker IOCB to the firmware. |
| 404 | * @ha: HA context |
| 405 | * @loop_id: loop ID |
| 406 | * @lun: LUN |
| 407 | * @type: marker modifier |
| 408 | * |
| 409 | * Can be called from both normal and interrupt context. |
| 410 | * |
| 411 | * Returns non-zero if a failure occured, else zero. |
| 412 | */ |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 413 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | __qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun, |
| 415 | uint8_t type) |
| 416 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 417 | mrk_entry_t *mrk; |
| 418 | struct mrk_entry_24xx *mrk24; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 419 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 421 | mrk24 = NULL; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 422 | mrk = (mrk_entry_t *)qla2x00_req_pkt(pha); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 423 | if (mrk == NULL) { |
| 424 | DEBUG2_3(printk("%s(%ld): failed to allocate Marker IOCB.\n", |
| 425 | __func__, ha->host_no)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | |
| 427 | return (QLA_FUNCTION_FAILED); |
| 428 | } |
| 429 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 430 | mrk->entry_type = MARKER_TYPE; |
| 431 | mrk->modifier = type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | if (type != MK_SYNC_ALL) { |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 433 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 434 | mrk24 = (struct mrk_entry_24xx *) mrk; |
| 435 | mrk24->nport_handle = cpu_to_le16(loop_id); |
| 436 | mrk24->lun[1] = LSB(lun); |
| 437 | mrk24->lun[2] = MSB(lun); |
Shyam Sundar | b797b6d | 2006-08-01 13:48:13 -0700 | [diff] [blame] | 438 | host_to_fcp_swap(mrk24->lun, sizeof(mrk24->lun)); |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 439 | mrk24->vp_index = ha->vp_idx; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 440 | } else { |
| 441 | SET_TARGET_ID(ha, mrk->target, loop_id); |
| 442 | mrk->lun = cpu_to_le16(lun); |
| 443 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | } |
| 445 | wmb(); |
| 446 | |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 447 | qla2x00_isp_cmd(pha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | return (QLA_SUCCESS); |
| 450 | } |
| 451 | |
Andrew Vasquez | fa2a1ce | 2005-07-06 10:32:07 -0700 | [diff] [blame] | 452 | int |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 453 | qla2x00_marker(scsi_qla_host_t *ha, uint16_t loop_id, uint16_t lun, |
| 454 | uint8_t type) |
| 455 | { |
| 456 | int ret; |
| 457 | unsigned long flags = 0; |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 458 | scsi_qla_host_t *pha = to_qla_parent(ha); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 460 | spin_lock_irqsave(&pha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | ret = __qla2x00_marker(ha, loop_id, lun, type); |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 462 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | |
| 464 | return (ret); |
| 465 | } |
| 466 | |
| 467 | /** |
| 468 | * qla2x00_req_pkt() - Retrieve a request packet from the request ring. |
| 469 | * @ha: HA context |
| 470 | * |
| 471 | * Note: The caller must hold the hardware lock before calling this routine. |
| 472 | * |
| 473 | * Returns NULL if function failed, else, a pointer to the request packet. |
| 474 | */ |
| 475 | static request_t * |
| 476 | qla2x00_req_pkt(scsi_qla_host_t *ha) |
| 477 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 478 | device_reg_t __iomem *reg = ha->iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 479 | request_t *pkt = NULL; |
| 480 | uint16_t cnt; |
| 481 | uint32_t *dword_ptr; |
| 482 | uint32_t timer; |
| 483 | uint16_t req_cnt = 1; |
| 484 | |
| 485 | /* Wait 1 second for slot. */ |
| 486 | for (timer = HZ; timer; timer--) { |
| 487 | if ((req_cnt + 2) >= ha->req_q_cnt) { |
| 488 | /* Calculate number of free request entries. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 489 | if (IS_FWI2_CAPABLE(ha)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 490 | cnt = (uint16_t)RD_REG_DWORD( |
| 491 | ®->isp24.req_q_out); |
| 492 | else |
| 493 | cnt = qla2x00_debounce_register( |
| 494 | ISP_REQ_Q_OUT(ha, ®->isp)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | if (ha->req_ring_index < cnt) |
| 496 | ha->req_q_cnt = cnt - ha->req_ring_index; |
| 497 | else |
| 498 | ha->req_q_cnt = ha->request_q_length - |
| 499 | (ha->req_ring_index - cnt); |
| 500 | } |
| 501 | /* If room for request in request ring. */ |
| 502 | if ((req_cnt + 2) < ha->req_q_cnt) { |
| 503 | ha->req_q_cnt--; |
| 504 | pkt = ha->request_ring_ptr; |
| 505 | |
| 506 | /* Zero out packet. */ |
| 507 | dword_ptr = (uint32_t *)pkt; |
| 508 | for (cnt = 0; cnt < REQUEST_ENTRY_SIZE / 4; cnt++) |
| 509 | *dword_ptr++ = 0; |
| 510 | |
| 511 | /* Set system defined field. */ |
| 512 | pkt->sys_define = (uint8_t)ha->req_ring_index; |
| 513 | |
| 514 | /* Set entry count. */ |
| 515 | pkt->entry_count = 1; |
| 516 | |
| 517 | break; |
| 518 | } |
| 519 | |
| 520 | /* Release ring specific lock */ |
| 521 | spin_unlock(&ha->hardware_lock); |
| 522 | |
| 523 | udelay(2); /* 2 us */ |
| 524 | |
| 525 | /* Check for pending interrupts. */ |
| 526 | /* During init we issue marker directly */ |
Andrew Vasquez | a3a63d5 | 2007-10-19 15:59:14 -0700 | [diff] [blame] | 527 | if (!ha->marker_needed && !ha->flags.init_done) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | qla2x00_poll(ha); |
| 529 | |
| 530 | spin_lock_irq(&ha->hardware_lock); |
| 531 | } |
| 532 | if (!pkt) { |
| 533 | DEBUG2_3(printk("%s(): **** FAILED ****\n", __func__)); |
| 534 | } |
| 535 | |
| 536 | return (pkt); |
| 537 | } |
| 538 | |
| 539 | /** |
| 540 | * qla2x00_isp_cmd() - Modify the request ring pointer. |
| 541 | * @ha: HA context |
| 542 | * |
| 543 | * Note: The caller must hold the hardware lock before calling this routine. |
| 544 | */ |
Adrian Bunk | 413975a | 2006-06-30 02:33:06 -0700 | [diff] [blame] | 545 | static void |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | qla2x00_isp_cmd(scsi_qla_host_t *ha) |
| 547 | { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 548 | device_reg_t __iomem *reg = ha->iobase; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
| 550 | DEBUG5(printk("%s(): IOCB data:\n", __func__)); |
| 551 | DEBUG5(qla2x00_dump_buffer( |
| 552 | (uint8_t *)ha->request_ring_ptr, REQUEST_ENTRY_SIZE)); |
| 553 | |
| 554 | /* Adjust ring index. */ |
| 555 | ha->req_ring_index++; |
| 556 | if (ha->req_ring_index == ha->request_q_length) { |
| 557 | ha->req_ring_index = 0; |
| 558 | ha->request_ring_ptr = ha->request_ring; |
| 559 | } else |
| 560 | ha->request_ring_ptr++; |
| 561 | |
| 562 | /* Set chip new ring index. */ |
Andrew Vasquez | e428924 | 2007-07-19 15:05:56 -0700 | [diff] [blame] | 563 | if (IS_FWI2_CAPABLE(ha)) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 564 | WRT_REG_DWORD(®->isp24.req_q_in, ha->req_ring_index); |
| 565 | RD_REG_DWORD_RELAXED(®->isp24.req_q_in); |
| 566 | } else { |
| 567 | WRT_REG_WORD(ISP_REQ_Q_IN(ha, ®->isp), ha->req_ring_index); |
| 568 | RD_REG_WORD_RELAXED(ISP_REQ_Q_IN(ha, ®->isp)); |
| 569 | } |
| 570 | |
| 571 | } |
| 572 | |
| 573 | /** |
| 574 | * qla24xx_calc_iocbs() - Determine number of Command Type 3 and |
| 575 | * Continuation Type 1 IOCBs to allocate. |
| 576 | * |
| 577 | * @dsds: number of data segment decriptors needed |
| 578 | * |
| 579 | * Returns the number of IOCB entries needed to store @dsds. |
| 580 | */ |
| 581 | static inline uint16_t |
| 582 | qla24xx_calc_iocbs(uint16_t dsds) |
| 583 | { |
| 584 | uint16_t iocbs; |
| 585 | |
| 586 | iocbs = 1; |
| 587 | if (dsds > 1) { |
| 588 | iocbs += (dsds - 1) / 5; |
| 589 | if ((dsds - 1) % 5) |
| 590 | iocbs++; |
| 591 | } |
| 592 | return iocbs; |
| 593 | } |
| 594 | |
| 595 | /** |
| 596 | * qla24xx_build_scsi_iocbs() - Build IOCB command utilizing Command Type 7 |
| 597 | * IOCB types. |
| 598 | * |
| 599 | * @sp: SRB command to process |
| 600 | * @cmd_pkt: Command type 3 IOCB |
| 601 | * @tot_dsds: Total number of segments to transfer |
| 602 | */ |
| 603 | static inline void |
| 604 | qla24xx_build_scsi_iocbs(srb_t *sp, struct cmd_type_7 *cmd_pkt, |
| 605 | uint16_t tot_dsds) |
| 606 | { |
| 607 | uint16_t avail_dsds; |
| 608 | uint32_t *cur_dsd; |
| 609 | scsi_qla_host_t *ha; |
| 610 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 611 | struct scatterlist *sg; |
| 612 | int i; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 613 | |
| 614 | cmd = sp->cmd; |
| 615 | |
| 616 | /* Update entry type to indicate Command Type 3 IOCB */ |
| 617 | *((uint32_t *)(&cmd_pkt->entry_type)) = |
| 618 | __constant_cpu_to_le32(COMMAND_TYPE_7); |
| 619 | |
| 620 | /* No data transfer */ |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 621 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 622 | cmd_pkt->byte_count = __constant_cpu_to_le32(0); |
| 623 | return; |
| 624 | } |
| 625 | |
| 626 | ha = sp->ha; |
| 627 | |
| 628 | /* Set transfer direction */ |
| 629 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 630 | cmd_pkt->task_mgmt_flags = |
| 631 | __constant_cpu_to_le16(TMF_WRITE_DATA); |
| 632 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 633 | cmd_pkt->task_mgmt_flags = |
| 634 | __constant_cpu_to_le16(TMF_READ_DATA); |
| 635 | |
| 636 | /* One DSD is available in the Command Type 3 IOCB */ |
| 637 | avail_dsds = 1; |
| 638 | cur_dsd = (uint32_t *)&cmd_pkt->dseg_0_address; |
| 639 | |
| 640 | /* Load data segments */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 641 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 642 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 643 | dma_addr_t sle_dma; |
| 644 | cont_a64_entry_t *cont_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 645 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 646 | /* Allocate additional continuation packets? */ |
| 647 | if (avail_dsds == 0) { |
| 648 | /* |
| 649 | * Five DSDs are available in the Continuation |
| 650 | * Type 1 IOCB. |
| 651 | */ |
| 652 | cont_pkt = qla2x00_prep_cont_type1_iocb(ha); |
| 653 | cur_dsd = (uint32_t *)cont_pkt->dseg_0_address; |
| 654 | avail_dsds = 5; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 655 | } |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 656 | |
| 657 | sle_dma = sg_dma_address(sg); |
| 658 | *cur_dsd++ = cpu_to_le32(LSD(sle_dma)); |
| 659 | *cur_dsd++ = cpu_to_le32(MSD(sle_dma)); |
| 660 | *cur_dsd++ = cpu_to_le32(sg_dma_len(sg)); |
| 661 | avail_dsds--; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 662 | } |
| 663 | } |
| 664 | |
| 665 | |
| 666 | /** |
| 667 | * qla24xx_start_scsi() - Send a SCSI command to the ISP |
| 668 | * @sp: command to send to the ISP |
| 669 | * |
| 670 | * Returns non-zero if a failure occured, else zero. |
| 671 | */ |
| 672 | int |
| 673 | qla24xx_start_scsi(srb_t *sp) |
| 674 | { |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 675 | int ret, nseg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 676 | unsigned long flags; |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 677 | scsi_qla_host_t *ha, *pha; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 678 | struct scsi_cmnd *cmd; |
| 679 | uint32_t *clr_ptr; |
| 680 | uint32_t index; |
| 681 | uint32_t handle; |
| 682 | struct cmd_type_7 *cmd_pkt; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 683 | uint16_t cnt; |
| 684 | uint16_t req_cnt; |
| 685 | uint16_t tot_dsds; |
Linus Torvalds | db776a1 | 2005-07-26 14:50:02 -0700 | [diff] [blame] | 686 | struct device_reg_24xx __iomem *reg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 687 | |
| 688 | /* Setup device pointers. */ |
| 689 | ret = 0; |
| 690 | ha = sp->ha; |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 691 | pha = to_qla_parent(ha); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 692 | reg = &ha->iobase->isp24; |
| 693 | cmd = sp->cmd; |
| 694 | /* So we know we haven't pci_map'ed anything yet */ |
| 695 | tot_dsds = 0; |
| 696 | |
| 697 | /* Send marker if required */ |
| 698 | if (ha->marker_needed != 0) { |
| 699 | if (qla2x00_marker(ha, 0, 0, MK_SYNC_ALL) != QLA_SUCCESS) { |
| 700 | return QLA_FUNCTION_FAILED; |
| 701 | } |
| 702 | ha->marker_needed = 0; |
| 703 | } |
| 704 | |
| 705 | /* Acquire ring specific lock */ |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 706 | spin_lock_irqsave(&pha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 707 | |
| 708 | /* Check for room in outstanding command list. */ |
| 709 | handle = ha->current_outstanding_cmd; |
| 710 | for (index = 1; index < MAX_OUTSTANDING_COMMANDS; index++) { |
| 711 | handle++; |
| 712 | if (handle == MAX_OUTSTANDING_COMMANDS) |
| 713 | handle = 1; |
Andrew Vasquez | 700ca0e | 2007-09-20 14:07:46 -0700 | [diff] [blame] | 714 | if (!ha->outstanding_cmds[handle]) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 715 | break; |
| 716 | } |
| 717 | if (index == MAX_OUTSTANDING_COMMANDS) |
| 718 | goto queuing_error; |
| 719 | |
| 720 | /* 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] | 721 | if (scsi_sg_count(cmd)) { |
| 722 | nseg = dma_map_sg(&ha->pdev->dev, scsi_sglist(cmd), |
| 723 | scsi_sg_count(cmd), cmd->sc_data_direction); |
| 724 | if (unlikely(!nseg)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 725 | goto queuing_error; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 726 | } else |
| 727 | nseg = 0; |
| 728 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 729 | tot_dsds = nseg; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 730 | |
| 731 | req_cnt = qla24xx_calc_iocbs(tot_dsds); |
| 732 | if (ha->req_q_cnt < (req_cnt + 2)) { |
| 733 | cnt = (uint16_t)RD_REG_DWORD_RELAXED(®->req_q_out); |
| 734 | if (ha->req_ring_index < cnt) |
| 735 | ha->req_q_cnt = cnt - ha->req_ring_index; |
| 736 | else |
| 737 | ha->req_q_cnt = ha->request_q_length - |
| 738 | (ha->req_ring_index - cnt); |
| 739 | } |
Andrew Vasquez | 131736d | 2005-08-26 19:09:20 -0700 | [diff] [blame] | 740 | if (ha->req_q_cnt < (req_cnt + 2)) |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 741 | goto queuing_error; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 742 | |
| 743 | /* Build command packet. */ |
| 744 | ha->current_outstanding_cmd = handle; |
| 745 | ha->outstanding_cmds[handle] = sp; |
| 746 | sp->ha = ha; |
| 747 | sp->cmd->host_scribble = (unsigned char *)(unsigned long)handle; |
| 748 | ha->req_q_cnt -= req_cnt; |
| 749 | |
| 750 | cmd_pkt = (struct cmd_type_7 *)ha->request_ring_ptr; |
| 751 | cmd_pkt->handle = handle; |
| 752 | |
| 753 | /* Zero out remaining portion of packet. */ |
James Bottomley | 72df832 | 2005-10-28 14:41:19 -0500 | [diff] [blame] | 754 | /* tagged queuing modifier -- default is TSK_SIMPLE (0). */ |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 755 | clr_ptr = (uint32_t *)cmd_pkt + 2; |
| 756 | memset(clr_ptr, 0, REQUEST_ENTRY_SIZE - 8); |
| 757 | cmd_pkt->dseg_count = cpu_to_le16(tot_dsds); |
| 758 | |
| 759 | /* Set NPORT-ID and LUN number*/ |
| 760 | cmd_pkt->nport_handle = cpu_to_le16(sp->fcport->loop_id); |
| 761 | cmd_pkt->port_id[0] = sp->fcport->d_id.b.al_pa; |
| 762 | cmd_pkt->port_id[1] = sp->fcport->d_id.b.area; |
| 763 | cmd_pkt->port_id[2] = sp->fcport->d_id.b.domain; |
Seokmann Ju | 2c3dfe3 | 2007-07-05 13:16:51 -0700 | [diff] [blame] | 764 | cmd_pkt->vp_index = sp->fcport->vp_idx; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 765 | |
Andrew Vasquez | 661c3f6 | 2005-10-27 11:09:58 -0700 | [diff] [blame] | 766 | int_to_scsilun(sp->cmd->device->lun, &cmd_pkt->lun); |
andrew.vasquez@qlogic.com | 0d4be12 | 2006-02-07 08:45:35 -0800 | [diff] [blame] | 767 | 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] | 768 | |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 769 | /* Load SCSI command packet. */ |
| 770 | memcpy(cmd_pkt->fcp_cdb, cmd->cmnd, cmd->cmd_len); |
| 771 | host_to_fcp_swap(cmd_pkt->fcp_cdb, sizeof(cmd_pkt->fcp_cdb)); |
| 772 | |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 773 | cmd_pkt->byte_count = cpu_to_le32((uint32_t)scsi_bufflen(cmd)); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 774 | |
| 775 | /* Build IOCB segments */ |
| 776 | qla24xx_build_scsi_iocbs(sp, cmd_pkt, tot_dsds); |
| 777 | |
| 778 | /* Set total data segment count. */ |
| 779 | cmd_pkt->entry_count = (uint8_t)req_cnt; |
| 780 | wmb(); |
| 781 | |
| 782 | /* Adjust ring index. */ |
| 783 | ha->req_ring_index++; |
| 784 | if (ha->req_ring_index == ha->request_q_length) { |
| 785 | ha->req_ring_index = 0; |
| 786 | ha->request_ring_ptr = ha->request_ring; |
| 787 | } else |
| 788 | ha->request_ring_ptr++; |
| 789 | |
| 790 | sp->flags |= SRB_DMA_VALID; |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 791 | |
| 792 | /* Set chip new ring index. */ |
| 793 | WRT_REG_DWORD(®->req_q_in, ha->req_ring_index); |
| 794 | RD_REG_DWORD_RELAXED(®->req_q_in); /* PCI Posting. */ |
| 795 | |
Andrew Vasquez | 4fdfefe | 2005-10-27 11:09:48 -0700 | [diff] [blame] | 796 | /* Manage unprocessed RIO/ZIO commands in response queue. */ |
| 797 | if (ha->flags.process_response_queue && |
| 798 | ha->response_ring_ptr->signature != RESPONSE_PROCESSED) |
| 799 | qla24xx_process_response_queue(ha); |
| 800 | |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 801 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 802 | return QLA_SUCCESS; |
| 803 | |
| 804 | queuing_error: |
FUJITA Tomonori | 385d70b | 2007-05-26 01:55:38 +0900 | [diff] [blame] | 805 | if (tot_dsds) |
| 806 | scsi_dma_unmap(cmd); |
| 807 | |
Seokmann Ju | 246de42 | 2008-07-10 16:55:55 -0700 | [diff] [blame] | 808 | spin_unlock_irqrestore(&pha->hardware_lock, flags); |
Andrew Vasquez | 2b6c0ce | 2005-07-06 10:31:17 -0700 | [diff] [blame] | 809 | |
| 810 | return QLA_FUNCTION_FAILED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | } |