Emulex Logo
OneCoreā„¢ Storage SDK Release 11.2
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ocs_session.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2011-2015, Emulex
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  * this list of conditions and the following disclaimer.
10  *
11  * 2. Redistributions in binary form must reproduce the above copyright notice,
12  * this list of conditions and the following disclaimer in the documentation
13  * and/or other materials provided with the distribution.
14  *
15  * 3. Neither the name of the copyright holder nor the names of its contributors
16  * may be used to endorse or promote products derived from this software
17  * without specific prior written permission.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  *
31  */
32 
33 /**
34  * @file
35  * Defines the iSCSI session managment functions.
36  * This code should be OS independant.
37  */
38 
39 #ifndef _OCS_SESSION_H
40 #define _OCS_SESSION_H
41 
42 #include "ocs_os.h"
43 
44 /* Initialization and Configuration */
47 
48 int32_t ocs_session_cxn_new(ocs_cxn_t *cxn,
49  char *tgt_name,
50  char *ini_name,
51  uint64_t isid,
52  uint16_t tsih,
53  uint16_t cid,
54  uint32_t cmd_sn);
55 
56 int32_t ocs_session_cxn_del(ocs_cxn_t *cxn);
57 
58 ocs_cxn_t *ocs_session_cxn_find(ocs_session_t *session,
59  uint16_t cid);
60 
61 void ocs_session_close(ocs_session_t *session, uint8_t reset);
62 
63 void ocs_session_max_cmd_sn_upd(ocs_session_t *session);
64 
65 int32_t ocs_session_tgt_unsol_pdu_recv(ocs_cxn_t *cxn,
67  uint32_t hdr_len,
68  ocs_hal_rq_buffer_t *data,
69  uint32_t data_len,
70  uint8_t code);
71 
72 int32_t ocs_session_abort_itt(ocs_session_t *session,
73  uint32_t itt);
74 
75 void ocs_session_abort_cmdsn(ocs_session_t *session,
76  uint32_t cmdsn);
77 
79  uint32_t cmdsn);
80 
81 void ocs_ddump_sessions(ocs_textbuf_t *textbuf, ocs_iscsi_t *iscsi);
82 
83 /* Helper functions for routines building commands on connections */
84 
85 static inline uint32_t
87 {
88  ocs_session_t *session = cxn->session;
89  uint32_t rc = FALSE;
90 
91  if (session != NULL &&
92  !GT_NOTWRAPPED(session->exp_cmd_sn + session->cmd_window,
93  session->cmd_sn)) {
94  rc = TRUE;
95  }
96 
97  return rc;
98 }
99 
100 static inline uint64_t
101 ocs_session_isid_get(ocs_cxn_t *cxn)
102 {
103  ocs_session_t *session = cxn->session;
104 
105  return (session == NULL ? 0 : session->isid);
106 }
107 
108 static inline uint32_t
109 ocs_session_cmd_sn_get(ocs_cxn_t *cxn, uint32_t inc)
110 {
111  ocs_session_t *session = cxn->session;
112  uint32_t rc = 0;
113 
114  if (session != NULL) {
115  rc = session->cmd_sn;
116  session->cmd_sn += inc;
117  }
118  return rc;
119 }
120 
121 static inline uint32_t
123 {
124  ocs_session_t *session = cxn->session;
125 
126  return (session == NULL ? 0 : session->exp_cmd_sn);
127 }
128 
129 static inline uint32_t
131 {
132  ocs_session_t *session = cxn->session;
133 
134  return (session == NULL ? 0 : session->max_cmd_sn);
135 }
136 
137 static inline uint32_t
139 {
140  ocs_session_t *session = cxn->session;
141 
142  return (session == NULL ? 0 : session->cmd_window);
143 }
144 
145 static inline uint16_t
146 ocs_session_tsih_get(ocs_cxn_t *cxn)
147 {
148  ocs_session_t *session = cxn->session;
149 
150  return (session == NULL ? 0 : session->tsih);
151 }
152 
153 static inline void
154 ocs_session_cmd_sn_set(ocs_cxn_t *cxn, uint32_t cmd_sn)
155 {
156  ocs_session_t *session = cxn->session;
157 
158  if (session != NULL) {
159  session->cmd_sn = cmd_sn;
160  }
161 }
162 
163 static inline void
164 ocs_session_exp_cmd_sn_set(ocs_cxn_t *cxn, uint32_t exp_cmd_sn)
165 {
166  ocs_session_t *session = cxn->session;
167 
168  if (session != NULL) {
169  session->exp_cmd_sn = exp_cmd_sn;
170  }
171 }
172 
173 static inline void
174 ocs_session_max_cmd_sn_set(ocs_cxn_t *cxn, uint32_t max_cmd_sn)
175 {
176  ocs_session_t *session = cxn->session;
177 
178  if (session != NULL) {
179  session->max_cmd_sn = max_cmd_sn;
180  }
181 }
182 
183 static inline void
184 ocs_session_cmd_window_set(ocs_cxn_t *cxn, uint32_t cmd_window)
185 {
186  ocs_session_t *session = cxn->session;
187 
188  if (session != NULL) {
189  session->cmd_window = cmd_window;
190  }
191 }
192 
193 static inline void
195 {
196  ocs_session_t *session = cxn->session;
197 
198  if (session != NULL) {
199  if (GT_NOTWRAPPED(session->max_cmd_sn, session->exp_cmd_sn)) {
200  session->cmd_window = session->max_cmd_sn - session->exp_cmd_sn;
201  } else {
202  session->cmd_window = (0xFFFFFFFF - session->exp_cmd_sn) + session->max_cmd_sn;
203  }
204  }
205 }
206 
207 static inline void
208 ocs_session_tsih_set(ocs_cxn_t *cxn, uint16_t tsih)
209 {
210  ocs_session_t *session = cxn->session;
211 
212  if (session != NULL) {
213  session->tsih = tsih;
214  }
215 }
216 
217 #endif /* !_OCS_SESSION_H */
218 
219 /* vim: set noexpandtab textwidth=120: */
static void ocs_session_max_cmd_sn_set(ocs_cxn_t *cxn, uint32_t max_cmd_sn)
Definition: ocs_session.h:174
static uint32_t ocs_session_max_cmd_sn_get(ocs_cxn_t *cxn)
Definition: ocs_session.h:130
void ocs_session_max_cmd_sn_upd(ocs_session_t *session)
Updates the max_cmd_sn based on the number IOs available.
Definition: ocs_session.c:449
#define GT_NOTWRAPPED(a, b)
Definition: ocs_iscsi.h:79
static void ocs_session_calc_cmd_window(ocs_cxn_t *cxn)
Definition: ocs_session.h:194
int32_t ocs_session_initialize(ocs_iscsi_t *iscsi)
Initialize the session management by allocating objects for sessions.
Definition: ocs_session.c:67
static void ocs_session_cmd_sn_set(ocs_cxn_t *cxn, uint32_t cmd_sn)
Definition: ocs_session.h:154
int32_t ocs_session_cxn_del(ocs_cxn_t *cxn)
Removes a connection from its session.
Definition: ocs_session.c:343
void ocs_ddump_sessions(ocs_textbuf_t *textbuf, ocs_iscsi_t *iscsi)
Generate node ddump data.
Definition: ocs_session.c:1095
int32_t ocs_session_tgt_unsol_pdu_recv(ocs_cxn_t *cxn, ocs_hal_rq_buffer_t *hdr, uint32_t hdr_len, ocs_hal_rq_buffer_t *data, uint32_t data_len, uint8_t code)
Function to handle unsolicited PDUs on a target.
Definition: ocs_session.c:699
iSCSI object
Definition: ocs_iscsi.h:293
Defines a wrapper for the RQ payload buffers so that we can place it back on the proper queue...
Definition: ocs_hal.h:694
static void ocs_session_exp_cmd_sn_set(ocs_cxn_t *cxn, uint32_t exp_cmd_sn)
Definition: ocs_session.h:164
void ocs_session_close(ocs_session_t *session, uint8_t reset)
Closes all connections on a session.
Definition: ocs_session.c:405
static uint32_t ocs_session_exp_cmd_sn_get(ocs_cxn_t *cxn)
Definition: ocs_session.h:122
void ocs_session_all_abort_cmdsn(ocs_iscsi_t *iscsi, uint32_t cmdsn)
Abort a specific IO based on the cmdSN of the abort request.
Definition: ocs_session.c:994
static uint64_t ocs_session_isid_get(ocs_cxn_t *cxn)
Definition: ocs_session.h:101
static uint32_t ocs_session_cmd_sn_get(ocs_cxn_t *cxn, uint32_t inc)
Definition: ocs_session.h:109
static uint16_t ocs_session_tsih_get(ocs_cxn_t *cxn)
Definition: ocs_session.h:146
static void ocs_session_tsih_set(ocs_cxn_t *cxn, uint16_t tsih)
Definition: ocs_session.h:208
static uint32_t ocs_session_cmd_window_get(ocs_cxn_t *cxn)
Definition: ocs_session.h:138
int32_t ocs_session_cxn_new(ocs_cxn_t *cxn, char *tgt_name, char *ini_name, uint64_t isid, uint16_t tsih, uint16_t cid, uint32_t cmd_sn)
Find an existing session or create a new one based on the login parameters.
Definition: ocs_session.c:187
void ocs_session_teardown(ocs_iscsi_t *iscsi)
Releases the session objects used within the login module.
Definition: ocs_session.c:123
int32_t ocs_session_abort_itt(ocs_session_t *session, uint32_t itt)
Abort a specific IO based on the ITT.
Definition: ocs_session.c:932
ocs_cxn_t * ocs_session_cxn_find(ocs_session_t *session, uint16_t cid)
Locate a connection within a session based on the cid.
Definition: ocs_session.c:379
static void ocs_session_cmd_window_set(ocs_cxn_t *cxn, uint32_t cmd_window)
Definition: ocs_session.h:184
static uint32_t ocs_session_is_window_open(ocs_cxn_t *cxn)
Definition: ocs_session.h:86
void ocs_session_abort_cmdsn(ocs_session_t *session, uint32_t cmdsn)
Abort a specific IO based on the cmdSN of the abort request.
Definition: ocs_session.c:965