27 #include <linux/slab.h>
29 #include <linux/list.h>
30 #include <linux/export.h>
31 #include <scsi/scsi.h>
51 tmr = kzalloc(
sizeof(
struct se_tmr_req), gfp_flags);
53 pr_err(
"Unable to allocate struct se_tmr_req\n");
86 static void core_tmr_handle_tas_abort(
100 (tmr_nacl == cmd->
se_sess->se_node_acl)) || tas)
106 static int target_check_cdb_and_preempt(
struct list_head *
list,
134 if (dev != se_cmd->
se_dev)
136 ref_tag = se_cmd->
se_tfo->get_task_tag(se_cmd);
140 printk(
"ABORT_TASK: Found referenced %s task_tag: %u\n",
141 se_cmd->
se_tfo->get_fabric_name(), ref_tag);
145 printk(
"ABORT_TASK: ref_tag: %u already complete, skipping\n", ref_tag);
172 printk(
"ABORT_TASK: Sending TMR_FUNCTION_COMPLETE for"
173 " ref_tag: %d\n", ref_tag);
180 printk(
"ABORT_TASK: Sending TMR_TASK_DOES_NOT_EXIST for ref_tag: %d\n",
185 static void core_tmr_drain_tmr_list(
188 struct list_head *preempt_and_abort_list)
208 pr_err(
"Unable to locate struct se_cmd for TMR\n");
216 if (target_check_cdb_and_preempt(preempt_and_abort_list, cmd))
230 list_move_tail(&tmr_p->
tmr_list, &drain_tmr_list);
238 pr_debug(
"LUN_RESET: %s releasing TMR %p Function: 0x%02x,"
239 " Response: 0x%02x, t_state: %d\n",
240 (preempt_and_abort_list) ?
"Preempt" :
"", tmr_p,
247 static void core_tmr_drain_state_list(
252 struct list_head *preempt_and_abort_list)
287 if (target_check_cdb_and_preempt(preempt_and_abort_list, cmd))
293 if (prout_cmd == cmd)
296 list_move_tail(&cmd->
state_list, &drain_task_list);
301 while (!list_empty(&drain_task_list)) {
306 " ITT/CmdSN: 0x%08x/0x%08x, i_state: %d, t_state: %d"
308 (preempt_and_abort_list) ?
"Preempt" :
"", cmd,
309 cmd->
se_tfo->get_task_tag(cmd), 0,
312 pr_debug(
"LUN_RESET: ITT[0x%08x] - pr_res_key: 0x%016Lx"
313 " -- CMD_T_ACTIVE: %d"
314 " CMD_T_STOP: %d CMD_T_SENT: %d\n",
336 pr_debug(
"LUN_RESET: got CMD_T_ACTIVE for"
337 " cdb: %p, t_fe_count: %d dev: %p\n", cmd,
342 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
345 pr_debug(
"LUN_RESET: Got !CMD_T_ACTIVE for cdb: %p,"
346 " t_fe_count: %d dev: %p\n", cmd, fe_count, dev);
350 core_tmr_handle_tas_abort(tmr_nacl, cmd, tas, fe_count);
357 struct list_head *preempt_and_abort_list,
374 tas = dev->
se_sub_dev->se_dev_attrib.emulate_tas;
380 tmr_nacl = tmr->
task_cmd->se_sess->se_node_acl;
381 tmr_tpg = tmr->
task_cmd->se_sess->se_tpg;
382 if (tmr_nacl && tmr_tpg) {
383 pr_debug(
"LUN_RESET: TMR caller fabric: %s"
384 " initiator port %s\n",
389 pr_debug(
"LUN_RESET: %s starting for [%s], tas: %d\n",
390 (preempt_and_abort_list) ?
"Preempt" :
"TMR",
393 core_tmr_drain_tmr_list(dev, tmr, preempt_and_abort_list);
394 core_tmr_drain_state_list(dev, prout_cmd, tmr_nacl, tas,
395 preempt_and_abort_list);
401 if (!preempt_and_abort_list &&
407 pr_debug(
"LUN_RESET: SCSI-2 Released reservation\n");
414 pr_debug(
"LUN_RESET: %s for [%s] Complete\n",
415 (preempt_and_abort_list) ?
"Preempt" :
"TMR",