df7ed7248ae65596ad179c8da037707bd17f1f95
[mirror/scst/.git] / qla2x00t / qla2x_tgt.h
1 /*
2  *  qla2x_tgt.h
3  *
4  *  Copyright (C) 2004 - 2009 Vladislav Bolkhovitin <vst@vlnb.net>
5  *  Copyright (C) 2004 - 2005 Leonid Stoljar
6  *  Copyright (C) 2006 Nathaniel Clark <nate@misrule.us>
7  *  Copyright (C) 2007 - 2009  ID7 Ltd.
8  *
9  *  Additional file for the target driver support.
10  *
11  *  This program is free software; you can redistribute it and/or
12  *  modify it under the terms of the GNU General Public License
13  *  as published by the Free Software Foundation; either version 2
14  *  of the License, or (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  *  GNU General Public License for more details.
20  */
21 /*
22  * This should be included only from within qla2xxx module.
23  */
24
25
26 #ifndef __QLA2X_TGT_H
27 #define __QLA2X_TGT_H
28
29 extern request_t *qla2x00_req_pkt(scsi_qla_host_t *ha);
30
31 #ifdef CONFIG_SCSI_QLA2XXX_TARGET
32
33 #include "qla2x_tgt_def.h"
34
35 extern struct qla_tgt_data qla_target;
36
37 /* Called under HW lock */
38 static inline void qla_set_tgt_mode(scsi_qla_host_t *ha)
39 {
40 #ifdef CONFIG_SCSI_QLA2XXX_TARGET_DISABLE_INI_MODE
41         ha->host->active_mode = MODE_TARGET;
42 #else
43         ha->host->active_mode |= MODE_TARGET;
44 #endif
45 }
46
47 /* Called under HW lock */
48 static inline void qla_clear_tgt_mode(scsi_qla_host_t *ha)
49 {
50 #ifdef CONFIG_SCSI_QLA2XXX_TARGET_DISABLE_INI_MODE
51         ha->host->active_mode = MODE_INITIATOR;
52 #else
53         ha->host->active_mode &= ~MODE_TARGET;
54 #endif
55 }
56
57 static inline bool qla_tgt_mode_enabled(scsi_qla_host_t *ha)
58 {
59         return ha->host->active_mode & MODE_TARGET;
60 }
61
62 /********************************************************************\
63  * ISP Queue types left out of new QLogic driver (from old version)
64 \********************************************************************/
65
66 /*
67  * qla2x00_do_en_dis_lun
68  *      Issue enable or disable LUN entry IOCB.
69  *
70  * Input:
71  *      ha = adapter block pointer.
72  *
73  * Caller MUST have hardware lock held. This function might release it,
74  * then reaquire.
75  */
76 static inline void
77 __qla2x00_send_enable_lun(scsi_qla_host_t *ha, int enable)
78 {
79         elun_entry_t *pkt;
80
81         BUG_ON(IS_FWI2_CAPABLE(ha));
82
83         pkt = (elun_entry_t *)qla2x00_req_pkt(ha);
84         if (pkt != NULL) {
85                 pkt->entry_type = ENABLE_LUN_TYPE;
86                 if (enable) {
87                         pkt->command_count = QLA2X00_COMMAND_COUNT_INIT;
88                         pkt->immed_notify_count = QLA2X00_IMMED_NOTIFY_COUNT_INIT;
89                         pkt->timeout = 0xffff;
90                 } else {
91                         pkt->command_count = 0;
92                         pkt->immed_notify_count = 0;
93                         pkt->timeout = 0;
94                 }
95                 DEBUG2(printk(KERN_DEBUG
96                               "scsi%lu:ENABLE_LUN IOCB imm %u cmd %u timeout %u\n",
97                               ha->host_no, pkt->immed_notify_count,
98                               pkt->command_count, pkt->timeout));
99
100                 /* Issue command to ISP */
101                 qla2x00_isp_cmd(ha);
102
103         } else
104                 qla_clear_tgt_mode(ha);
105 #if defined(QL_DEBUG_LEVEL_2) || defined(QL_DEBUG_LEVEL_3)
106         if (!pkt)
107                 printk("%s: **** FAILED ****\n", __func__);
108 #endif
109
110         return;
111 }
112
113 /*
114  * qla2x00_send_enable_lun
115  *      Issue enable LUN entry IOCB.
116  *
117  * Input:
118  *      ha = adapter block pointer.
119  *      enable = enable/disable flag.
120  */
121 static inline void
122 qla2x00_send_enable_lun(scsi_qla_host_t *ha, bool enable)
123 {
124         if (!IS_FWI2_CAPABLE(ha)) {
125                 unsigned long flags;
126                 spin_lock_irqsave(&ha->hardware_lock, flags);
127                 __qla2x00_send_enable_lun(ha, enable);
128                 spin_unlock_irqrestore(&ha->hardware_lock, flags);
129         }
130 }
131
132 extern void qla2xxx_add_targets(void);
133
134 #endif /* CONFIG_SCSI_QLA2XXX_TARGET */
135
136 #endif /* __QLA2X_TGT_H */