}
 
 struct tmf_arg {
+       struct list_head tmf_elem;
        struct qla_qpair *qpair;
        struct fc_port *fcport;
        struct scsi_qla_host *vha;
 typedef struct fc_port {
        struct list_head list;
        struct scsi_qla_host *vha;
-       struct list_head tmf_pending;
 
        unsigned int conf_compl_supported:1;
        unsigned int deleted:2;
        unsigned int do_prli_nvme:1;
 
        uint8_t nvme_flag;
-       uint8_t active_tmf;
-#define MAX_ACTIVE_TMF 8
-
        uint8_t node_name[WWN_SIZE];
        uint8_t port_name[WWN_SIZE];
        port_id_t d_id;
                uint32_t        flt_region_aux_img_status_sec;
        };
        uint8_t         active_image;
+       uint8_t active_tmf;
+#define MAX_ACTIVE_TMF 8
 
        /* Needed for BEACON */
        uint16_t        beacon_blink_led;
 
        struct qla_msix_entry *msix_entries;
 
+       struct list_head tmf_pending;
+       struct list_head tmf_active;
        struct list_head        vp_list;        /* list of VP */
        unsigned long   vp_idx_map[(MAX_MULTI_ID_FABRIC / 8) /
                        sizeof(unsigned long)];
 
        return rval;
 }
 
-static void qla_put_tmf(fc_port_t *fcport)
+static void qla_put_tmf(struct tmf_arg *arg)
 {
-       struct scsi_qla_host *vha = fcport->vha;
+       struct scsi_qla_host *vha = arg->vha;
        struct qla_hw_data *ha = vha->hw;
        unsigned long flags;
 
        spin_lock_irqsave(&ha->tgt.sess_lock, flags);
-       fcport->active_tmf--;
+       ha->active_tmf--;
+       list_del(&arg->tmf_elem);
        spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
 }
 
 static
-int qla_get_tmf(fc_port_t *fcport)
+int qla_get_tmf(struct tmf_arg *arg)
 {
-       struct scsi_qla_host *vha = fcport->vha;
+       struct scsi_qla_host *vha = arg->vha;
        struct qla_hw_data *ha = vha->hw;
        unsigned long flags;
+       fc_port_t *fcport = arg->fcport;
        int rc = 0;
-       LIST_HEAD(tmf_elem);
+       struct tmf_arg *t;
 
        spin_lock_irqsave(&ha->tgt.sess_lock, flags);
-       list_add_tail(&tmf_elem, &fcport->tmf_pending);
+       list_for_each_entry(t, &ha->tmf_active, tmf_elem) {
+               if (t->fcport == arg->fcport && t->lun == arg->lun) {
+                       /* reject duplicate TMF */
+                       ql_log(ql_log_warn, vha, 0x802c,
+                              "found duplicate TMF.  Nexus=%ld:%06x:%llu.\n",
+                              vha->host_no, fcport->d_id.b24, arg->lun);
+                       spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
+                       return -EINVAL;
+               }
+       }
 
-       while (fcport->active_tmf >= MAX_ACTIVE_TMF) {
+       list_add_tail(&arg->tmf_elem, &ha->tmf_pending);
+       while (ha->active_tmf >= MAX_ACTIVE_TMF) {
                spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
 
                msleep(1);
                        rc = EIO;
                        break;
                }
-               if (fcport->active_tmf < MAX_ACTIVE_TMF &&
-                   list_is_first(&tmf_elem, &fcport->tmf_pending))
+               if (ha->active_tmf < MAX_ACTIVE_TMF &&
+                   list_is_first(&arg->tmf_elem, &ha->tmf_pending))
                        break;
        }
 
-       list_del(&tmf_elem);
+       list_del(&arg->tmf_elem);
 
-       if (!rc)
-               fcport->active_tmf++;
+       if (!rc) {
+               ha->active_tmf++;
+               list_add_tail(&arg->tmf_elem, &ha->tmf_active);
+       }
 
        spin_unlock_irqrestore(&ha->tgt.sess_lock, flags);
 
        a.vha = fcport->vha;
        a.fcport = fcport;
        a.lun = lun;
+       a.flags = flags;
+       INIT_LIST_HEAD(&a.tmf_elem);
+
        if (flags & (TCF_LUN_RESET|TCF_ABORT_TASK_SET|TCF_CLEAR_TASK_SET|TCF_CLEAR_ACA)) {
                a.modifier = MK_SYNC_ID_LUN;
-
-               if (qla_get_tmf(fcport))
-                       return QLA_FUNCTION_FAILED;
        } else {
                a.modifier = MK_SYNC_ID;
        }
 
+       if (qla_get_tmf(&a))
+               return QLA_FUNCTION_FAILED;
+
        if (vha->hw->mqenable) {
                for (i = 0; i < vha->hw->num_qpairs; i++) {
                        qpair = vha->hw->queue_pair_map[i];
                goto bailout;
 
        a.qpair = vha->hw->base_qpair;
-       a.flags = flags;
        rval = __qla2x00_async_tm_cmd(&a);
 
 bailout:
-       if (a.modifier == MK_SYNC_ID_LUN)
-               qla_put_tmf(fcport);
-
+       qla_put_tmf(&a);
        return rval;
 }
 
        INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
        INIT_LIST_HEAD(&fcport->gnl_entry);
        INIT_LIST_HEAD(&fcport->list);
-       INIT_LIST_HEAD(&fcport->tmf_pending);
 
        INIT_LIST_HEAD(&fcport->sess_cmd_list);
        spin_lock_init(&fcport->sess_cmd_lock);