Thomas Gleixner | a61127c | 2019-05-29 16:57:49 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-only |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2010 Cisco Systems, Inc. |
| 4 | * |
| 5 | * Portions based on tcm_loop_fabric_scsi.c and libfc/fc_fcp.c |
| 6 | * |
| 7 | * Copyright (c) 2007 Intel Corporation. All rights reserved. |
| 8 | * Copyright (c) 2008 Red Hat, Inc. All rights reserved. |
| 9 | * Copyright (c) 2008 Mike Christie |
| 10 | * Copyright (c) 2009 Rising Tide, Inc. |
| 11 | * Copyright (c) 2009 Linux-iSCSI.org |
| 12 | * Copyright (c) 2009 Nicholas A. Bellinger <nab@linux-iscsi.org> |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 13 | */ |
| 14 | |
| 15 | /* XXX TBD some includes may be extraneous */ |
| 16 | |
| 17 | #include <linux/module.h> |
| 18 | #include <linux/moduleparam.h> |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 19 | #include <linux/utsname.h> |
| 20 | #include <linux/init.h> |
| 21 | #include <linux/slab.h> |
| 22 | #include <linux/kthread.h> |
| 23 | #include <linux/types.h> |
| 24 | #include <linux/string.h> |
| 25 | #include <linux/configfs.h> |
| 26 | #include <linux/ctype.h> |
| 27 | #include <linux/hash.h> |
Andy Grover | 6708bb2 | 2011-06-08 10:36:43 -0700 | [diff] [blame] | 28 | #include <linux/ratelimit.h> |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 29 | #include <asm/unaligned.h> |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 30 | #include <scsi/libfc.h> |
| 31 | #include <scsi/fc_encode.h> |
| 32 | |
| 33 | #include <target/target_core_base.h> |
Christoph Hellwig | c4795fb | 2011-11-16 09:46:48 -0500 | [diff] [blame] | 34 | #include <target/target_core_fabric.h> |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 35 | |
| 36 | #include "tcm_fc.h" |
| 37 | |
| 38 | /* |
| 39 | * Deliver read data back to initiator. |
| 40 | * XXX TBD handle resource problems later. |
| 41 | */ |
| 42 | int ft_queue_data_in(struct se_cmd *se_cmd) |
| 43 | { |
| 44 | struct ft_cmd *cmd = container_of(se_cmd, struct ft_cmd, se_cmd); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 45 | struct fc_frame *fp = NULL; |
| 46 | struct fc_exch *ep; |
| 47 | struct fc_lport *lport; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 48 | struct scatterlist *sg = NULL; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 49 | size_t remaining; |
| 50 | u32 f_ctl = FC_FC_EX_CTX | FC_FC_REL_OFF; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 51 | u32 mem_off = 0; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 52 | u32 fh_off = 0; |
| 53 | u32 frame_off = 0; |
| 54 | size_t frame_len = 0; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 55 | size_t mem_len = 0; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 56 | size_t tlen; |
| 57 | size_t off_in_page; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 58 | struct page *page = NULL; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 59 | int use_sg; |
| 60 | int error; |
| 61 | void *page_addr; |
| 62 | void *from; |
| 63 | void *to = NULL; |
| 64 | |
Mark Rustad | e1c4038 | 2012-04-03 10:24:41 -0700 | [diff] [blame] | 65 | if (cmd->aborted) |
| 66 | return 0; |
Nicholas Bellinger | b3e5fe1 | 2014-06-05 16:27:53 -0700 | [diff] [blame] | 67 | |
| 68 | if (se_cmd->scsi_status == SAM_STAT_TASK_SET_FULL) |
| 69 | goto queue_status; |
| 70 | |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 71 | ep = fc_seq_exch(cmd->seq); |
| 72 | lport = ep->lp; |
Hannes Reinecke | c6865b3 | 2016-10-18 10:01:51 +0200 | [diff] [blame] | 73 | cmd->seq = fc_seq_start_next(cmd->seq); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 74 | |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 75 | remaining = se_cmd->data_length; |
| 76 | |
| 77 | /* |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 78 | * Setup to use first mem list entry, unless no data. |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 79 | */ |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 80 | BUG_ON(remaining && !se_cmd->t_data_sg); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 81 | if (remaining) { |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 82 | sg = se_cmd->t_data_sg; |
| 83 | mem_len = sg->length; |
| 84 | mem_off = sg->offset; |
| 85 | page = sg_page(sg); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | /* no scatter/gather in skb for odd word length due to fc_seq_send() */ |
| 89 | use_sg = !(remaining % 4); |
| 90 | |
| 91 | while (remaining) { |
Mark Rustad | d3682b1 | 2013-04-22 09:49:55 -0700 | [diff] [blame] | 92 | struct fc_seq *seq = cmd->seq; |
| 93 | |
| 94 | if (!seq) { |
| 95 | pr_debug("%s: Command aborted, xid 0x%x\n", |
| 96 | __func__, ep->xid); |
| 97 | break; |
| 98 | } |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 99 | if (!mem_len) { |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 100 | sg = sg_next(sg); |
| 101 | mem_len = min((size_t)sg->length, remaining); |
| 102 | mem_off = sg->offset; |
| 103 | page = sg_page(sg); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 104 | } |
| 105 | if (!frame_len) { |
| 106 | /* |
| 107 | * If lport's has capability of Large Send Offload LSO) |
| 108 | * , then allow 'frame_len' to be as big as 'lso_max' |
| 109 | * if indicated transfer length is >= lport->lso_max |
| 110 | */ |
| 111 | frame_len = (lport->seq_offload) ? lport->lso_max : |
| 112 | cmd->sess->max_frame; |
| 113 | frame_len = min(frame_len, remaining); |
| 114 | fp = fc_frame_alloc(lport, use_sg ? 0 : frame_len); |
| 115 | if (!fp) |
| 116 | return -ENOMEM; |
| 117 | to = fc_frame_payload_get(fp, 0); |
| 118 | fh_off = frame_off; |
| 119 | frame_off += frame_len; |
| 120 | /* |
| 121 | * Setup the frame's max payload which is used by base |
| 122 | * driver to indicate HW about max frame size, so that |
| 123 | * HW can do fragmentation appropriately based on |
| 124 | * "gso_max_size" of underline netdev. |
| 125 | */ |
| 126 | fr_max_payload(fp) = cmd->sess->max_frame; |
| 127 | } |
| 128 | tlen = min(mem_len, frame_len); |
| 129 | |
| 130 | if (use_sg) { |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 131 | off_in_page = mem_off; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 132 | BUG_ON(!page); |
| 133 | get_page(page); |
| 134 | skb_fill_page_desc(fp_skb(fp), |
| 135 | skb_shinfo(fp_skb(fp))->nr_frags, |
| 136 | page, off_in_page, tlen); |
| 137 | fr_len(fp) += tlen; |
| 138 | fp_skb(fp)->data_len += tlen; |
| 139 | fp_skb(fp)->truesize += |
| 140 | PAGE_SIZE << compound_order(page); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 141 | } else { |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 142 | BUG_ON(!page); |
Cong Wang | ca747d6 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 143 | from = kmap_atomic(page + (mem_off >> PAGE_SHIFT)); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 144 | page_addr = from; |
Geliang Tang | b75d806 | 2015-11-25 21:49:27 +0800 | [diff] [blame] | 145 | from += offset_in_page(mem_off); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 146 | tlen = min(tlen, (size_t)(PAGE_SIZE - |
Geliang Tang | b75d806 | 2015-11-25 21:49:27 +0800 | [diff] [blame] | 147 | offset_in_page(mem_off))); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 148 | memcpy(to, from, tlen); |
Cong Wang | ca747d6 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 149 | kunmap_atomic(page_addr); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 150 | to += tlen; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | mem_off += tlen; |
| 154 | mem_len -= tlen; |
| 155 | frame_len -= tlen; |
| 156 | remaining -= tlen; |
| 157 | |
| 158 | if (frame_len && |
| 159 | (skb_shinfo(fp_skb(fp))->nr_frags < FC_FRAME_SG_LEN)) |
| 160 | continue; |
| 161 | if (!remaining) |
| 162 | f_ctl |= FC_FC_END_SEQ; |
| 163 | fc_fill_fc_hdr(fp, FC_RCTL_DD_SOL_DATA, ep->did, ep->sid, |
| 164 | FC_TYPE_FCP, f_ctl, fh_off); |
Hannes Reinecke | 0cac937 | 2016-10-18 10:01:48 +0200 | [diff] [blame] | 165 | error = fc_seq_send(lport, seq, fp); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 166 | if (error) { |
Nicholas Bellinger | b3e5fe1 | 2014-06-05 16:27:53 -0700 | [diff] [blame] | 167 | pr_info_ratelimited("%s: Failed to send frame %p, " |
Nicholas Bellinger | 95efa28 | 2011-06-23 23:28:46 +0000 | [diff] [blame] | 168 | "xid <0x%x>, remaining %zu, " |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 169 | "lso_max <0x%x>\n", |
| 170 | __func__, fp, ep->xid, |
| 171 | remaining, lport->lso_max); |
Nicholas Bellinger | b3e5fe1 | 2014-06-05 16:27:53 -0700 | [diff] [blame] | 172 | /* |
| 173 | * Go ahead and set TASK_SET_FULL status ignoring the |
| 174 | * rest of the DataIN, and immediately attempt to |
| 175 | * send the response via ft_queue_status() in order |
| 176 | * to notify the initiator that it should reduce it's |
| 177 | * per LUN queue_depth. |
| 178 | */ |
| 179 | se_cmd->scsi_status = SAM_STAT_TASK_SET_FULL; |
| 180 | break; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 181 | } |
| 182 | } |
Nicholas Bellinger | b3e5fe1 | 2014-06-05 16:27:53 -0700 | [diff] [blame] | 183 | queue_status: |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 184 | return ft_queue_status(se_cmd); |
| 185 | } |
| 186 | |
Christoph Hellwig | b8b2253 | 2012-07-08 15:58:45 -0400 | [diff] [blame] | 187 | static void ft_execute_work(struct work_struct *work) |
| 188 | { |
| 189 | struct ft_cmd *cmd = container_of(work, struct ft_cmd, work); |
| 190 | |
| 191 | target_execute_cmd(&cmd->se_cmd); |
| 192 | } |
| 193 | |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 194 | /* |
| 195 | * Receive write data frame. |
| 196 | */ |
| 197 | void ft_recv_write_data(struct ft_cmd *cmd, struct fc_frame *fp) |
| 198 | { |
| 199 | struct se_cmd *se_cmd = &cmd->se_cmd; |
| 200 | struct fc_seq *seq = cmd->seq; |
| 201 | struct fc_exch *ep; |
| 202 | struct fc_lport *lport; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 203 | struct fc_frame_header *fh; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 204 | struct scatterlist *sg = NULL; |
| 205 | u32 mem_off = 0; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 206 | u32 rel_off; |
| 207 | size_t frame_len; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 208 | size_t mem_len = 0; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 209 | size_t tlen; |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 210 | struct page *page = NULL; |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 211 | void *page_addr; |
| 212 | void *from; |
| 213 | void *to; |
| 214 | u32 f_ctl; |
| 215 | void *buf; |
| 216 | |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 217 | fh = fc_frame_header_get(fp); |
| 218 | if (!(ntoh24(fh->fh_f_ctl) & FC_FC_REL_OFF)) |
| 219 | goto drop; |
| 220 | |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 221 | f_ctl = ntoh24(fh->fh_f_ctl); |
| 222 | ep = fc_seq_exch(seq); |
| 223 | lport = ep->lp; |
| 224 | if (cmd->was_ddp_setup) { |
| 225 | BUG_ON(!ep); |
| 226 | BUG_ON(!lport); |
Kiran Patil | 079587b | 2011-08-26 09:25:25 -0700 | [diff] [blame] | 227 | /* |
| 228 | * Since DDP (Large Rx offload) was setup for this request, |
| 229 | * payload is expected to be copied directly to user buffers. |
| 230 | */ |
| 231 | buf = fc_frame_payload_get(fp, 1); |
| 232 | if (buf) |
| 233 | pr_err("%s: xid 0x%x, f_ctl 0x%x, cmd->sg %p, " |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 234 | "cmd->sg_cnt 0x%x. DDP was setup" |
| 235 | " hence not expected to receive frame with " |
Kiran Patil | 079587b | 2011-08-26 09:25:25 -0700 | [diff] [blame] | 236 | "payload, Frame will be dropped if" |
| 237 | "'Sequence Initiative' bit in f_ctl is" |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 238 | "not set\n", __func__, ep->xid, f_ctl, |
Roland Dreier | e182d68 | 2012-03-30 11:29:11 -0700 | [diff] [blame] | 239 | se_cmd->t_data_sg, se_cmd->t_data_nents); |
Kiran Patil | 079587b | 2011-08-26 09:25:25 -0700 | [diff] [blame] | 240 | /* |
| 241 | * Invalidate HW DDP context if it was setup for respective |
| 242 | * command. Invalidation of HW DDP context is requited in both |
| 243 | * situation (success and error). |
| 244 | */ |
| 245 | ft_invl_hw_context(cmd); |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 246 | |
Kiran Patil | 079587b | 2011-08-26 09:25:25 -0700 | [diff] [blame] | 247 | /* |
| 248 | * If "Sequence Initiative (TSI)" bit set in f_ctl, means last |
| 249 | * write data frame is received successfully where payload is |
| 250 | * posted directly to user buffer and only the last frame's |
| 251 | * header is posted in receive queue. |
| 252 | * |
| 253 | * If "Sequence Initiative (TSI)" bit is not set, means error |
| 254 | * condition w.r.t. DDP, hence drop the packet and let explict |
| 255 | * ABORTS from other end of exchange timer trigger the recovery. |
| 256 | */ |
| 257 | if (f_ctl & FC_FC_SEQ_INIT) |
| 258 | goto last_frame; |
| 259 | else |
| 260 | goto drop; |
| 261 | } |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 262 | |
| 263 | rel_off = ntohl(fh->fh_parm_offset); |
| 264 | frame_len = fr_len(fp); |
| 265 | if (frame_len <= sizeof(*fh)) |
| 266 | goto drop; |
| 267 | frame_len -= sizeof(*fh); |
| 268 | from = fc_frame_payload_get(fp, 0); |
| 269 | if (rel_off >= se_cmd->data_length) |
| 270 | goto drop; |
| 271 | if (frame_len + rel_off > se_cmd->data_length) |
| 272 | frame_len = se_cmd->data_length - rel_off; |
| 273 | |
| 274 | /* |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 275 | * Setup to use first mem list entry, unless no data. |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 276 | */ |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 277 | BUG_ON(frame_len && !se_cmd->t_data_sg); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 278 | if (frame_len) { |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 279 | sg = se_cmd->t_data_sg; |
| 280 | mem_len = sg->length; |
| 281 | mem_off = sg->offset; |
| 282 | page = sg_page(sg); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 283 | } |
| 284 | |
| 285 | while (frame_len) { |
| 286 | if (!mem_len) { |
Andy Grover | ec98f78 | 2011-07-20 19:28:46 +0000 | [diff] [blame] | 287 | sg = sg_next(sg); |
| 288 | mem_len = sg->length; |
| 289 | mem_off = sg->offset; |
| 290 | page = sg_page(sg); |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 291 | } |
| 292 | if (rel_off >= mem_len) { |
| 293 | rel_off -= mem_len; |
| 294 | mem_len = 0; |
| 295 | continue; |
| 296 | } |
| 297 | mem_off += rel_off; |
| 298 | mem_len -= rel_off; |
| 299 | rel_off = 0; |
| 300 | |
| 301 | tlen = min(mem_len, frame_len); |
| 302 | |
Cong Wang | ca747d6 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 303 | to = kmap_atomic(page + (mem_off >> PAGE_SHIFT)); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 304 | page_addr = to; |
Geliang Tang | b75d806 | 2015-11-25 21:49:27 +0800 | [diff] [blame] | 305 | to += offset_in_page(mem_off); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 306 | tlen = min(tlen, (size_t)(PAGE_SIZE - |
Geliang Tang | b75d806 | 2015-11-25 21:49:27 +0800 | [diff] [blame] | 307 | offset_in_page(mem_off))); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 308 | memcpy(to, from, tlen); |
Cong Wang | ca747d6 | 2011-11-25 23:14:25 +0800 | [diff] [blame] | 309 | kunmap_atomic(page_addr); |
Andy Grover | 05d1c7c | 2011-07-20 19:13:28 +0000 | [diff] [blame] | 310 | |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 311 | from += tlen; |
| 312 | frame_len -= tlen; |
| 313 | mem_off += tlen; |
| 314 | mem_len -= tlen; |
| 315 | cmd->write_data_len += tlen; |
| 316 | } |
| 317 | last_frame: |
Christoph Hellwig | b8b2253 | 2012-07-08 15:58:45 -0400 | [diff] [blame] | 318 | if (cmd->write_data_len == se_cmd->data_length) { |
| 319 | INIT_WORK(&cmd->work, ft_execute_work); |
| 320 | queue_work(cmd->sess->tport->tpg->workqueue, &cmd->work); |
| 321 | } |
Kiran Patil | 3699d92 | 2011-04-18 16:24:14 -0700 | [diff] [blame] | 322 | drop: |
| 323 | fc_frame_free(fp); |
| 324 | } |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 325 | |
| 326 | /* |
| 327 | * Handle and cleanup any HW specific resources if |
| 328 | * received ABORTS, errors, timeouts. |
| 329 | */ |
| 330 | void ft_invl_hw_context(struct ft_cmd *cmd) |
| 331 | { |
Wei Yongjun | 7875f17 | 2012-09-07 14:55:32 +0800 | [diff] [blame] | 332 | struct fc_seq *seq; |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 333 | struct fc_exch *ep = NULL; |
| 334 | struct fc_lport *lport = NULL; |
| 335 | |
| 336 | BUG_ON(!cmd); |
Wei Yongjun | 7875f17 | 2012-09-07 14:55:32 +0800 | [diff] [blame] | 337 | seq = cmd->seq; |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 338 | |
| 339 | /* Cleanup the DDP context in HW if DDP was setup */ |
| 340 | if (cmd->was_ddp_setup && seq) { |
| 341 | ep = fc_seq_exch(seq); |
| 342 | if (ep) { |
| 343 | lport = ep->lp; |
Dan Carpenter | d556546 | 2015-02-25 16:21:03 +0300 | [diff] [blame] | 344 | if (lport && (ep->xid <= lport->lro_xid)) { |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 345 | /* |
| 346 | * "ddp_done" trigger invalidation of HW |
| 347 | * specific DDP context |
| 348 | */ |
| 349 | cmd->write_data_len = lport->tt.ddp_done(lport, |
| 350 | ep->xid); |
| 351 | |
| 352 | /* |
| 353 | * Resetting same variable to indicate HW's |
| 354 | * DDP context has been invalidated to avoid |
| 355 | * re_invalidation of same context (context is |
| 356 | * identified using ep->xid) |
| 357 | */ |
| 358 | cmd->was_ddp_setup = 0; |
Dan Carpenter | d556546 | 2015-02-25 16:21:03 +0300 | [diff] [blame] | 359 | } |
Kiran Patil | dcd998c | 2011-08-03 09:20:01 +0000 | [diff] [blame] | 360 | } |
| 361 | } |
| 362 | } |