Thomas Gleixner | e3976af | 2020-09-08 14:34:47 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 2 | /* |
| 3 | * QLogic iSCSI HBA Driver |
Vikas Chaudhary | 4a4f51e | 2013-08-16 07:03:04 -0400 | [diff] [blame] | 4 | * Copyright (c) 2003-2013 QLogic Corporation |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include "ql4_def.h" |
David C Somayajulu | e08c182 | 2007-05-23 18:14:34 -0700 | [diff] [blame] | 8 | #include "ql4_glbl.h" |
| 9 | #include "ql4_dbg.h" |
| 10 | #include "ql4_inline.h" |
| 11 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 12 | #include <scsi/scsi_tcq.h> |
| 13 | |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 14 | static int |
| 15 | qla4xxx_space_in_req_ring(struct scsi_qla_host *ha, uint16_t req_cnt) |
| 16 | { |
| 17 | uint16_t cnt; |
| 18 | |
| 19 | /* Calculate number of free request entries. */ |
| 20 | if ((req_cnt + 2) >= ha->req_q_count) { |
Vikas Chaudhary | b173a132 | 2010-07-30 14:26:08 +0530 | [diff] [blame] | 21 | cnt = (uint16_t) ha->isp_ops->rd_shdw_req_q_out(ha); |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 22 | if (ha->request_in < cnt) |
| 23 | ha->req_q_count = cnt - ha->request_in; |
| 24 | else |
| 25 | ha->req_q_count = REQUEST_QUEUE_DEPTH - |
| 26 | (ha->request_in - cnt); |
| 27 | } |
| 28 | |
| 29 | /* Check if room for request in request ring. */ |
| 30 | if ((req_cnt + 2) < ha->req_q_count) |
| 31 | return 1; |
| 32 | else |
| 33 | return 0; |
| 34 | } |
| 35 | |
| 36 | static void qla4xxx_advance_req_ring_ptr(struct scsi_qla_host *ha) |
| 37 | { |
| 38 | /* Advance request queue pointer */ |
| 39 | if (ha->request_in == (REQUEST_QUEUE_DEPTH - 1)) { |
| 40 | ha->request_in = 0; |
| 41 | ha->request_ptr = ha->request_ring; |
| 42 | } else { |
| 43 | ha->request_in++; |
| 44 | ha->request_ptr++; |
| 45 | } |
| 46 | } |
| 47 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 48 | /** |
| 49 | * qla4xxx_get_req_pkt - returns a valid entry in request queue. |
| 50 | * @ha: Pointer to host adapter structure. |
| 51 | * @queue_entry: Pointer to pointer to queue entry structure |
| 52 | * |
| 53 | * This routine performs the following tasks: |
| 54 | * - returns the current request_in pointer (if queue not full) |
| 55 | * - advances the request_in pointer |
| 56 | * - checks for queue full |
| 57 | **/ |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 58 | static int qla4xxx_get_req_pkt(struct scsi_qla_host *ha, |
| 59 | struct queue_entry **queue_entry) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 60 | { |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 61 | uint16_t req_cnt = 1; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 62 | |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 63 | if (qla4xxx_space_in_req_ring(ha, req_cnt)) { |
| 64 | *queue_entry = ha->request_ptr; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 65 | memset(*queue_entry, 0, sizeof(**queue_entry)); |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 66 | |
| 67 | qla4xxx_advance_req_ring_ptr(ha); |
| 68 | ha->req_q_count -= req_cnt; |
| 69 | return QLA_SUCCESS; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 70 | } |
| 71 | |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 72 | return QLA_ERROR; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | /** |
| 76 | * qla4xxx_send_marker_iocb - issues marker iocb to HBA |
| 77 | * @ha: Pointer to host adapter structure. |
| 78 | * @ddb_entry: Pointer to device database entry |
| 79 | * @lun: SCSI LUN |
Lee Jones | 67b8b93 | 2020-07-21 17:41:30 +0100 | [diff] [blame] | 80 | * @mrkr_mod: marker identifier |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 81 | * |
| 82 | * This routine issues a marker IOCB. |
| 83 | **/ |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 84 | int qla4xxx_send_marker_iocb(struct scsi_qla_host *ha, |
Hannes Reinecke | 9cb78c1 | 2014-06-25 15:27:36 +0200 | [diff] [blame] | 85 | struct ddb_entry *ddb_entry, uint64_t lun, uint16_t mrkr_mod) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 86 | { |
Mathieu Desnoyers | 1c3f0b8 | 2007-10-18 23:41:04 -0700 | [diff] [blame] | 87 | struct qla4_marker_entry *marker_entry; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 88 | unsigned long flags = 0; |
| 89 | uint8_t status = QLA_SUCCESS; |
| 90 | |
| 91 | /* Acquire hardware specific lock */ |
| 92 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 93 | |
| 94 | /* Get pointer to the queue entry for the marker */ |
| 95 | if (qla4xxx_get_req_pkt(ha, (struct queue_entry **) &marker_entry) != |
| 96 | QLA_SUCCESS) { |
| 97 | status = QLA_ERROR; |
| 98 | goto exit_send_marker; |
| 99 | } |
| 100 | |
| 101 | /* Put the marker in the request queue */ |
| 102 | marker_entry->hdr.entryType = ET_MARKER; |
| 103 | marker_entry->hdr.entryCount = 1; |
| 104 | marker_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index); |
David C Somayajulu | 9d56291 | 2008-03-19 11:23:03 -0700 | [diff] [blame] | 105 | marker_entry->modifier = cpu_to_le16(mrkr_mod); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 106 | int_to_scsilun(lun, &marker_entry->lun); |
| 107 | wmb(); |
| 108 | |
| 109 | /* Tell ISP it's got a new I/O request */ |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 110 | ha->isp_ops->queue_iocb(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 111 | |
| 112 | exit_send_marker: |
| 113 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 114 | return status; |
| 115 | } |
| 116 | |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 117 | static struct continuation_t1_entry * |
| 118 | qla4xxx_alloc_cont_entry(struct scsi_qla_host *ha) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 119 | { |
| 120 | struct continuation_t1_entry *cont_entry; |
| 121 | |
| 122 | cont_entry = (struct continuation_t1_entry *)ha->request_ptr; |
| 123 | |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 124 | qla4xxx_advance_req_ring_ptr(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 125 | |
| 126 | /* Load packet defaults */ |
| 127 | cont_entry->hdr.entryType = ET_CONTINUE; |
| 128 | cont_entry->hdr.entryCount = 1; |
| 129 | cont_entry->hdr.systemDefined = (uint8_t) cpu_to_le16(ha->request_in); |
| 130 | |
| 131 | return cont_entry; |
| 132 | } |
| 133 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 134 | static uint16_t qla4xxx_calc_request_entries(uint16_t dsds) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 135 | { |
| 136 | uint16_t iocbs; |
| 137 | |
| 138 | iocbs = 1; |
| 139 | if (dsds > COMMAND_SEG) { |
| 140 | iocbs += (dsds - COMMAND_SEG) / CONTINUE_SEG; |
| 141 | if ((dsds - COMMAND_SEG) % CONTINUE_SEG) |
| 142 | iocbs++; |
| 143 | } |
| 144 | return iocbs; |
| 145 | } |
| 146 | |
Adrian Bunk | 4797547 | 2007-04-26 00:35:16 -0700 | [diff] [blame] | 147 | static void qla4xxx_build_scsi_iocbs(struct srb *srb, |
| 148 | struct command_t3_entry *cmd_entry, |
| 149 | uint16_t tot_dsds) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 150 | { |
| 151 | struct scsi_qla_host *ha; |
| 152 | uint16_t avail_dsds; |
| 153 | struct data_seg_a64 *cur_dsd; |
| 154 | struct scsi_cmnd *cmd; |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 155 | struct scatterlist *sg; |
| 156 | int i; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 157 | |
| 158 | cmd = srb->cmd; |
| 159 | ha = srb->ha; |
| 160 | |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 161 | if (!scsi_bufflen(cmd) || cmd->sc_data_direction == DMA_NONE) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 162 | /* No data being transferred */ |
Dwaipayan Ray | 3352901 | 2021-07-16 16:58:52 +0530 | [diff] [blame] | 163 | cmd_entry->ttlByteCnt = cpu_to_le32(0); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 164 | return; |
| 165 | } |
| 166 | |
| 167 | avail_dsds = COMMAND_SEG; |
| 168 | cur_dsd = (struct data_seg_a64 *) & (cmd_entry->dataseg[0]); |
| 169 | |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 170 | scsi_for_each_sg(cmd, sg, tot_dsds, i) { |
| 171 | dma_addr_t sle_dma; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 172 | |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 173 | /* Allocate additional continuation packets? */ |
| 174 | if (avail_dsds == 0) { |
| 175 | struct continuation_t1_entry *cont_entry; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 176 | |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 177 | cont_entry = qla4xxx_alloc_cont_entry(ha); |
| 178 | cur_dsd = |
| 179 | (struct data_seg_a64 *) |
| 180 | &cont_entry->dataseg[0]; |
| 181 | avail_dsds = CONTINUE_SEG; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 182 | } |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 183 | |
| 184 | sle_dma = sg_dma_address(sg); |
| 185 | cur_dsd->base.addrLow = cpu_to_le32(LSDW(sle_dma)); |
| 186 | cur_dsd->base.addrHigh = cpu_to_le32(MSDW(sle_dma)); |
| 187 | cur_dsd->count = cpu_to_le32(sg_dma_len(sg)); |
| 188 | avail_dsds--; |
| 189 | |
| 190 | cur_dsd++; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 191 | } |
| 192 | } |
| 193 | |
Vikas Chaudhary | 6e7b429 | 2012-08-22 07:55:08 -0400 | [diff] [blame] | 194 | void qla4_83xx_queue_iocb(struct scsi_qla_host *ha) |
| 195 | { |
| 196 | writel(ha->request_in, &ha->qla4_83xx_reg->req_q_in); |
| 197 | readl(&ha->qla4_83xx_reg->req_q_in); |
| 198 | } |
| 199 | |
| 200 | void qla4_83xx_complete_iocb(struct scsi_qla_host *ha) |
| 201 | { |
| 202 | writel(ha->response_out, &ha->qla4_83xx_reg->rsp_q_out); |
| 203 | readl(&ha->qla4_83xx_reg->rsp_q_out); |
| 204 | } |
| 205 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 206 | /** |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 207 | * qla4_82xx_queue_iocb - Tell ISP it's got new request(s) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 208 | * @ha: pointer to host adapter structure. |
| 209 | * |
| 210 | * This routine notifies the ISP that one or more new request |
| 211 | * queue entries have been placed on the request queue. |
| 212 | **/ |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 213 | void qla4_82xx_queue_iocb(struct scsi_qla_host *ha) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 214 | { |
| 215 | uint32_t dbval = 0; |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 216 | |
| 217 | dbval = 0x14 | (ha->func_num << 5); |
| 218 | dbval = dbval | (0 << 8) | (ha->request_in << 16); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 219 | |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 220 | qla4_82xx_wr_32(ha, ha->nx_db_wr_ptr, ha->request_in); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | /** |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 224 | * qla4_82xx_complete_iocb - Tell ISP we're done with response(s) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 225 | * @ha: pointer to host adapter structure. |
| 226 | * |
| 227 | * This routine notifies the ISP that one or more response/completion |
| 228 | * queue entries have been processed by the driver. |
| 229 | * This also clears the interrupt. |
| 230 | **/ |
Vikas Chaudhary | f8086f4 | 2012-08-22 07:54:59 -0400 | [diff] [blame] | 231 | void qla4_82xx_complete_iocb(struct scsi_qla_host *ha) |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 232 | { |
Vikas Chaudhary | 7664a1f | 2012-08-22 07:55:00 -0400 | [diff] [blame] | 233 | writel(ha->response_out, &ha->qla4_82xx_reg->rsp_q_out); |
| 234 | readl(&ha->qla4_82xx_reg->rsp_q_out); |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 235 | } |
| 236 | |
| 237 | /** |
| 238 | * qla4xxx_queue_iocb - Tell ISP it's got new request(s) |
| 239 | * @ha: pointer to host adapter structure. |
| 240 | * |
| 241 | * This routine is notifies the ISP that one or more new request |
| 242 | * queue entries have been placed on the request queue. |
| 243 | **/ |
| 244 | void qla4xxx_queue_iocb(struct scsi_qla_host *ha) |
| 245 | { |
| 246 | writel(ha->request_in, &ha->reg->req_q_in); |
| 247 | readl(&ha->reg->req_q_in); |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * qla4xxx_complete_iocb - Tell ISP we're done with response(s) |
| 252 | * @ha: pointer to host adapter structure. |
| 253 | * |
| 254 | * This routine is notifies the ISP that one or more response/completion |
| 255 | * queue entries have been processed by the driver. |
| 256 | * This also clears the interrupt. |
| 257 | **/ |
| 258 | void qla4xxx_complete_iocb(struct scsi_qla_host *ha) |
| 259 | { |
| 260 | writel(ha->response_out, &ha->reg->rsp_q_out); |
| 261 | readl(&ha->reg->rsp_q_out); |
| 262 | } |
| 263 | |
| 264 | /** |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 265 | * qla4xxx_send_command_to_isp - issues command to HBA |
| 266 | * @ha: pointer to host adapter structure. |
| 267 | * @srb: pointer to SCSI Request Block to be sent to ISP |
| 268 | * |
| 269 | * This routine is called by qla4xxx_queuecommand to build an ISP |
| 270 | * command and pass it to the ISP for execution. |
| 271 | **/ |
| 272 | int qla4xxx_send_command_to_isp(struct scsi_qla_host *ha, struct srb * srb) |
| 273 | { |
| 274 | struct scsi_cmnd *cmd = srb->cmd; |
| 275 | struct ddb_entry *ddb_entry; |
| 276 | struct command_t3_entry *cmd_entry; |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 277 | int nseg; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 278 | uint16_t tot_dsds; |
| 279 | uint16_t req_cnt; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 280 | unsigned long flags; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 281 | uint32_t index; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 282 | |
| 283 | /* Get real lun and adapter */ |
| 284 | ddb_entry = srb->ddb; |
| 285 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 286 | tot_dsds = 0; |
| 287 | |
| 288 | /* Acquire hardware specific lock */ |
| 289 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 290 | |
Bart Van Assche | 924b3d7 | 2021-08-09 16:03:42 -0700 | [diff] [blame] | 291 | index = scsi_cmd_to_rq(cmd)->tag; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 292 | |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 293 | /* |
| 294 | * Check to see if adapter is online before placing request on |
| 295 | * request queue. If a reset occurs and a request is in the queue, |
| 296 | * the firmware will still attempt to process the request, retrieving |
| 297 | * garbage for pointers. |
| 298 | */ |
| 299 | if (!test_bit(AF_ONLINE, &ha->flags)) { |
| 300 | DEBUG2(printk("scsi%ld: %s: Adapter OFFLINE! " |
| 301 | "Do not issue command.\n", |
| 302 | ha->host_no, __func__)); |
| 303 | goto queuing_error; |
| 304 | } |
| 305 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 306 | /* Calculate the number of request entries needed. */ |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 307 | nseg = scsi_dma_map(cmd); |
| 308 | if (nseg < 0) |
| 309 | goto queuing_error; |
| 310 | tot_dsds = nseg; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 311 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 312 | req_cnt = qla4xxx_calc_request_entries(tot_dsds); |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 313 | if (!qla4xxx_space_in_req_ring(ha, req_cnt)) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 314 | goto queuing_error; |
| 315 | |
| 316 | /* total iocbs active */ |
Karen Higgins | 5b1c1bf | 2013-01-20 23:51:00 -0500 | [diff] [blame] | 317 | if ((ha->iocb_cnt + req_cnt) >= ha->iocb_hiwat) |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 318 | goto queuing_error; |
| 319 | |
| 320 | /* Build command packet */ |
| 321 | cmd_entry = (struct command_t3_entry *) ha->request_ptr; |
| 322 | memset(cmd_entry, 0, sizeof(struct command_t3_entry)); |
| 323 | cmd_entry->hdr.entryType = ET_COMMAND; |
| 324 | cmd_entry->handle = cpu_to_le32(index); |
| 325 | cmd_entry->target = cpu_to_le16(ddb_entry->fw_ddb_index); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 326 | |
| 327 | int_to_scsilun(cmd->device->lun, &cmd_entry->lun); |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 328 | cmd_entry->ttlByteCnt = cpu_to_le32(scsi_bufflen(cmd)); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 329 | memcpy(cmd_entry->cdb, cmd->cmnd, cmd->cmd_len); |
| 330 | cmd_entry->dataSegCnt = cpu_to_le16(tot_dsds); |
| 331 | cmd_entry->hdr.entryCount = req_cnt; |
| 332 | |
| 333 | /* Set data transfer direction control flags |
| 334 | * NOTE: Look at data_direction bits iff there is data to be |
| 335 | * transferred, as the data direction bit is sometimed filled |
| 336 | * in when there is no data to be transferred */ |
| 337 | cmd_entry->control_flags = CF_NO_DATA; |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 338 | if (scsi_bufflen(cmd)) { |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 339 | if (cmd->sc_data_direction == DMA_TO_DEVICE) |
| 340 | cmd_entry->control_flags = CF_WRITE; |
| 341 | else if (cmd->sc_data_direction == DMA_FROM_DEVICE) |
| 342 | cmd_entry->control_flags = CF_READ; |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 343 | |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 344 | ha->bytes_xfered += scsi_bufflen(cmd); |
David C Somayajulu | d915058 | 2006-11-15 17:38:40 -0800 | [diff] [blame] | 345 | if (ha->bytes_xfered & ~0xFFFFF){ |
| 346 | ha->total_mbytes_xferred += ha->bytes_xfered >> 20; |
| 347 | ha->bytes_xfered &= 0xFFFFF; |
| 348 | } |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | /* Set tagged queueing control flags */ |
| 352 | cmd_entry->control_flags |= CF_SIMPLE_TAG; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 353 | |
Karen Higgins | 16ed55f | 2009-07-15 15:03:02 -0500 | [diff] [blame] | 354 | qla4xxx_advance_req_ring_ptr(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 355 | qla4xxx_build_scsi_iocbs(srb, cmd_entry, tot_dsds); |
| 356 | wmb(); |
| 357 | |
Vikas Chaudhary | 5369887 | 2010-04-28 11:41:59 +0530 | [diff] [blame] | 358 | srb->cmd->host_scribble = (unsigned char *)(unsigned long)index; |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 359 | |
| 360 | /* update counters */ |
| 361 | srb->state = SRB_ACTIVE_STATE; |
| 362 | srb->flags |= SRB_DMA_VALID; |
| 363 | |
| 364 | /* Track IOCB used */ |
| 365 | ha->iocb_cnt += req_cnt; |
| 366 | srb->iocb_cnt = req_cnt; |
| 367 | ha->req_q_count -= req_cnt; |
| 368 | |
Vikas Chaudhary | f4f5df23 | 2010-07-28 15:53:44 +0530 | [diff] [blame] | 369 | ha->isp_ops->queue_iocb(ha); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 370 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 371 | |
| 372 | return QLA_SUCCESS; |
| 373 | |
| 374 | queuing_error: |
FUJITA Tomonori | 5f7186c | 2007-05-26 14:08:20 +0900 | [diff] [blame] | 375 | if (tot_dsds) |
| 376 | scsi_dma_unmap(cmd); |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 377 | |
David Somayajulu | afaf5a2 | 2006-09-19 10:28:00 -0700 | [diff] [blame] | 378 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 379 | |
| 380 | return QLA_ERROR; |
| 381 | } |
| 382 | |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 383 | int qla4xxx_send_passthru0(struct iscsi_task *task) |
| 384 | { |
| 385 | struct passthru0 *passthru_iocb; |
| 386 | struct iscsi_session *sess = task->conn->session; |
| 387 | struct ddb_entry *ddb_entry = sess->dd_data; |
| 388 | struct scsi_qla_host *ha = ddb_entry->ha; |
| 389 | struct ql4_task_data *task_data = task->dd_data; |
| 390 | uint16_t ctrl_flags = 0; |
| 391 | unsigned long flags; |
| 392 | int ret = QLA_ERROR; |
| 393 | |
| 394 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 395 | task_data->iocb_req_cnt = 1; |
| 396 | /* Put the IOCB on the request queue */ |
| 397 | if (!qla4xxx_space_in_req_ring(ha, task_data->iocb_req_cnt)) |
| 398 | goto queuing_error; |
| 399 | |
| 400 | passthru_iocb = (struct passthru0 *) ha->request_ptr; |
| 401 | |
| 402 | memset(passthru_iocb, 0, sizeof(struct passthru0)); |
| 403 | passthru_iocb->hdr.entryType = ET_PASSTHRU0; |
| 404 | passthru_iocb->hdr.systemDefined = SD_ISCSI_PDU; |
| 405 | passthru_iocb->hdr.entryCount = task_data->iocb_req_cnt; |
| 406 | passthru_iocb->handle = task->itt; |
| 407 | passthru_iocb->target = cpu_to_le16(ddb_entry->fw_ddb_index); |
| 408 | passthru_iocb->timeout = cpu_to_le16(PT_DEFAULT_TIMEOUT); |
| 409 | |
| 410 | /* Setup the out & in DSDs */ |
Manish Rangankar | 69ca216 | 2011-10-07 16:55:50 -0700 | [diff] [blame] | 411 | if (task_data->req_len) { |
Manish Rangankar | b3a271a | 2011-07-25 13:48:53 -0500 | [diff] [blame] | 412 | memcpy((uint8_t *)task_data->req_buffer + |
| 413 | sizeof(struct iscsi_hdr), task->data, task->data_count); |
| 414 | ctrl_flags |= PT_FLAG_SEND_BUFFER; |
| 415 | passthru_iocb->out_dsd.base.addrLow = |
| 416 | cpu_to_le32(LSDW(task_data->req_dma)); |
| 417 | passthru_iocb->out_dsd.base.addrHigh = |
| 418 | cpu_to_le32(MSDW(task_data->req_dma)); |
| 419 | passthru_iocb->out_dsd.count = |
| 420 | cpu_to_le32(task->data_count + |
| 421 | sizeof(struct iscsi_hdr)); |
| 422 | } |
| 423 | if (task_data->resp_len) { |
| 424 | passthru_iocb->in_dsd.base.addrLow = |
| 425 | cpu_to_le32(LSDW(task_data->resp_dma)); |
| 426 | passthru_iocb->in_dsd.base.addrHigh = |
| 427 | cpu_to_le32(MSDW(task_data->resp_dma)); |
| 428 | passthru_iocb->in_dsd.count = |
| 429 | cpu_to_le32(task_data->resp_len); |
| 430 | } |
| 431 | |
| 432 | ctrl_flags |= (PT_FLAG_ISCSI_PDU | PT_FLAG_WAIT_4_RESPONSE); |
| 433 | passthru_iocb->control_flags = cpu_to_le16(ctrl_flags); |
| 434 | |
| 435 | /* Update the request pointer */ |
| 436 | qla4xxx_advance_req_ring_ptr(ha); |
| 437 | wmb(); |
| 438 | |
| 439 | /* Track IOCB used */ |
| 440 | ha->iocb_cnt += task_data->iocb_req_cnt; |
| 441 | ha->req_q_count -= task_data->iocb_req_cnt; |
| 442 | ha->isp_ops->queue_iocb(ha); |
| 443 | ret = QLA_SUCCESS; |
| 444 | |
| 445 | queuing_error: |
| 446 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 447 | return ret; |
| 448 | } |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 449 | |
| 450 | static struct mrb *qla4xxx_get_new_mrb(struct scsi_qla_host *ha) |
| 451 | { |
| 452 | struct mrb *mrb; |
| 453 | |
| 454 | mrb = kzalloc(sizeof(*mrb), GFP_KERNEL); |
| 455 | if (!mrb) |
| 456 | return mrb; |
| 457 | |
| 458 | mrb->ha = ha; |
| 459 | return mrb; |
| 460 | } |
| 461 | |
Vikas Chaudhary | a7380a6 | 2012-02-27 03:08:56 -0800 | [diff] [blame] | 462 | static int qla4xxx_send_mbox_iocb(struct scsi_qla_host *ha, struct mrb *mrb, |
| 463 | uint32_t *in_mbox) |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 464 | { |
| 465 | int rval = QLA_SUCCESS; |
| 466 | uint32_t i; |
| 467 | unsigned long flags; |
| 468 | uint32_t index = 0; |
| 469 | |
| 470 | /* Acquire hardware specific lock */ |
| 471 | spin_lock_irqsave(&ha->hardware_lock, flags); |
| 472 | |
| 473 | /* Get pointer to the queue entry for the marker */ |
| 474 | rval = qla4xxx_get_req_pkt(ha, (struct queue_entry **) &(mrb->mbox)); |
| 475 | if (rval != QLA_SUCCESS) |
| 476 | goto exit_mbox_iocb; |
| 477 | |
| 478 | index = ha->mrb_index; |
| 479 | /* get valid mrb index*/ |
| 480 | for (i = 0; i < MAX_MRB; i++) { |
| 481 | index++; |
| 482 | if (index == MAX_MRB) |
| 483 | index = 1; |
| 484 | if (ha->active_mrb_array[index] == NULL) { |
| 485 | ha->mrb_index = index; |
| 486 | break; |
| 487 | } |
| 488 | } |
| 489 | |
| 490 | mrb->iocb_cnt = 1; |
| 491 | ha->active_mrb_array[index] = mrb; |
| 492 | mrb->mbox->handle = index; |
| 493 | mrb->mbox->hdr.entryType = ET_MBOX_CMD; |
| 494 | mrb->mbox->hdr.entryCount = mrb->iocb_cnt; |
| 495 | memcpy(mrb->mbox->in_mbox, in_mbox, 32); |
| 496 | mrb->mbox_cmd = in_mbox[0]; |
| 497 | wmb(); |
| 498 | |
Vikas Chaudhary | d522844 | 2013-05-02 03:42:10 -0400 | [diff] [blame] | 499 | ha->iocb_cnt += mrb->iocb_cnt; |
Vikas Chaudhary | c0b9d3f | 2012-02-13 18:30:49 +0530 | [diff] [blame] | 500 | ha->isp_ops->queue_iocb(ha); |
| 501 | exit_mbox_iocb: |
| 502 | spin_unlock_irqrestore(&ha->hardware_lock, flags); |
| 503 | return rval; |
| 504 | } |
| 505 | |
| 506 | int qla4xxx_ping_iocb(struct scsi_qla_host *ha, uint32_t options, |
| 507 | uint32_t payload_size, uint32_t pid, uint8_t *ipaddr) |
| 508 | { |
| 509 | uint32_t in_mbox[8]; |
| 510 | struct mrb *mrb = NULL; |
| 511 | int rval = QLA_SUCCESS; |
| 512 | |
| 513 | memset(in_mbox, 0, sizeof(in_mbox)); |
| 514 | |
| 515 | mrb = qla4xxx_get_new_mrb(ha); |
| 516 | if (!mrb) { |
| 517 | DEBUG2(ql4_printk(KERN_WARNING, ha, "%s: fail to get new mrb\n", |
| 518 | __func__)); |
| 519 | rval = QLA_ERROR; |
| 520 | goto exit_ping; |
| 521 | } |
| 522 | |
| 523 | in_mbox[0] = MBOX_CMD_PING; |
| 524 | in_mbox[1] = options; |
| 525 | memcpy(&in_mbox[2], &ipaddr[0], 4); |
| 526 | memcpy(&in_mbox[3], &ipaddr[4], 4); |
| 527 | memcpy(&in_mbox[4], &ipaddr[8], 4); |
| 528 | memcpy(&in_mbox[5], &ipaddr[12], 4); |
| 529 | in_mbox[6] = payload_size; |
| 530 | |
| 531 | mrb->pid = pid; |
| 532 | rval = qla4xxx_send_mbox_iocb(ha, mrb, in_mbox); |
| 533 | |
| 534 | if (rval != QLA_SUCCESS) |
| 535 | goto exit_ping; |
| 536 | |
| 537 | return rval; |
| 538 | exit_ping: |
| 539 | kfree(mrb); |
| 540 | return rval; |
| 541 | } |