Commit | Line | Data |
---|---|---|
6733b39a JK |
1 | /** |
2 | * Copyright (C) 2005 - 2009 ServerEngines | |
3 | * All rights reserved. | |
4 | * | |
5 | * This program is free software; you can redistribute it and/or | |
6 | * modify it under the terms of the GNU General Public License version 2 | |
7 | * as published by the Free Software Foundation. The full GNU General | |
8 | * Public License is included in this distribution in the file called COPYING. | |
9 | * | |
10 | * Written by: Jayamohan Kallickal (jayamohank@serverengines.com) | |
11 | * | |
12 | * Contact Information: | |
13 | * linux-drivers@serverengines.com | |
14 | * | |
15 | * ServerEngines | |
16 | * 209 N. Fair Oaks Ave | |
17 | * Sunnyvale, CA 94085 | |
18 | * | |
19 | */ | |
20 | ||
21 | #include <scsi/libiscsi.h> | |
22 | #include <scsi/scsi_transport_iscsi.h> | |
23 | #include <scsi/scsi_transport.h> | |
24 | #include <scsi/scsi_cmnd.h> | |
25 | #include <scsi/scsi_device.h> | |
26 | #include <scsi/scsi_host.h> | |
27 | #include <scsi/scsi.h> | |
28 | ||
29 | #include "be_iscsi.h" | |
30 | ||
31 | extern struct iscsi_transport beiscsi_iscsi_transport; | |
32 | ||
33 | /** | |
34 | * beiscsi_session_create - creates a new iscsi session | |
35 | * @cmds_max: max commands supported | |
36 | * @qdepth: max queue depth supported | |
37 | * @initial_cmdsn: initial iscsi CMDSN | |
38 | */ | |
39 | struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep, | |
40 | u16 cmds_max, | |
41 | u16 qdepth, | |
42 | u32 initial_cmdsn) | |
43 | { | |
44 | struct Scsi_Host *shost; | |
45 | struct beiscsi_endpoint *beiscsi_ep; | |
46 | struct iscsi_cls_session *cls_session; | |
6733b39a | 47 | struct beiscsi_hba *phba; |
b8b9e1b8 JK |
48 | struct iscsi_session *sess; |
49 | struct beiscsi_session *beiscsi_sess; | |
6733b39a | 50 | struct beiscsi_io_task *io_task; |
6733b39a JK |
51 | |
52 | SE_DEBUG(DBG_LVL_8, "In beiscsi_session_create\n"); | |
53 | ||
54 | if (!ep) { | |
55 | SE_DEBUG(DBG_LVL_1, "beiscsi_session_create: invalid ep \n"); | |
56 | return NULL; | |
57 | } | |
58 | beiscsi_ep = ep->dd_data; | |
59 | phba = beiscsi_ep->phba; | |
60 | shost = phba->shost; | |
61 | if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) { | |
62 | shost_printk(KERN_ERR, shost, "Cannot handle %d cmds." | |
63 | "Max cmds per session supported is %d. Using %d. " | |
64 | "\n", cmds_max, | |
65 | beiscsi_ep->phba->params.wrbs_per_cxn, | |
66 | beiscsi_ep->phba->params.wrbs_per_cxn); | |
67 | cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn; | |
68 | } | |
69 | ||
bfead3b2 JK |
70 | cls_session = iscsi_session_setup(&beiscsi_iscsi_transport, |
71 | shost, cmds_max, | |
72 | sizeof(*beiscsi_sess), | |
73 | sizeof(*io_task), | |
74 | initial_cmdsn, ISCSI_MAX_TARGET); | |
6733b39a JK |
75 | if (!cls_session) |
76 | return NULL; | |
77 | sess = cls_session->dd_data; | |
2afc95bf JK |
78 | beiscsi_sess = sess->dd_data; |
79 | beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool", | |
80 | phba->pcidev, | |
81 | sizeof(struct be_cmd_bhs), | |
82 | 64, 0); | |
83 | if (!beiscsi_sess->bhs_pool) | |
84 | goto destroy_sess; | |
6733b39a | 85 | |
6733b39a | 86 | return cls_session; |
2afc95bf JK |
87 | destroy_sess: |
88 | iscsi_session_teardown(cls_session); | |
89 | return NULL; | |
6733b39a JK |
90 | } |
91 | ||
92 | /** | |
93 | * beiscsi_session_destroy - destroys iscsi session | |
94 | * @cls_session: pointer to iscsi cls session | |
95 | * | |
96 | * Destroys iSCSI session instance and releases | |
97 | * resources allocated for it. | |
98 | */ | |
99 | void beiscsi_session_destroy(struct iscsi_cls_session *cls_session) | |
100 | { | |
6733b39a | 101 | struct iscsi_session *sess = cls_session->dd_data; |
2afc95bf | 102 | struct beiscsi_session *beiscsi_sess = sess->dd_data; |
6733b39a | 103 | |
2afc95bf | 104 | pci_pool_destroy(beiscsi_sess->bhs_pool); |
6733b39a JK |
105 | iscsi_session_teardown(cls_session); |
106 | } | |
107 | ||
108 | /** | |
109 | * beiscsi_conn_create - create an instance of iscsi connection | |
110 | * @cls_session: ptr to iscsi_cls_session | |
111 | * @cid: iscsi cid | |
112 | */ | |
113 | struct iscsi_cls_conn * | |
114 | beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid) | |
115 | { | |
116 | struct beiscsi_hba *phba; | |
117 | struct Scsi_Host *shost; | |
118 | struct iscsi_cls_conn *cls_conn; | |
119 | struct beiscsi_conn *beiscsi_conn; | |
120 | struct iscsi_conn *conn; | |
2afc95bf JK |
121 | struct iscsi_session *sess; |
122 | struct beiscsi_session *beiscsi_sess; | |
6733b39a JK |
123 | |
124 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_create ,cid" | |
125 | "from iscsi layer=%d\n", cid); | |
126 | shost = iscsi_session_to_shost(cls_session); | |
127 | phba = iscsi_host_priv(shost); | |
128 | ||
129 | cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid); | |
130 | if (!cls_conn) | |
131 | return NULL; | |
132 | ||
133 | conn = cls_conn->dd_data; | |
134 | beiscsi_conn = conn->dd_data; | |
135 | beiscsi_conn->ep = NULL; | |
136 | beiscsi_conn->phba = phba; | |
137 | beiscsi_conn->conn = conn; | |
2afc95bf JK |
138 | sess = cls_session->dd_data; |
139 | beiscsi_sess = sess->dd_data; | |
140 | beiscsi_conn->beiscsi_sess = beiscsi_sess; | |
6733b39a JK |
141 | return cls_conn; |
142 | } | |
143 | ||
144 | /** | |
145 | * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table | |
146 | * @beiscsi_conn: The pointer to beiscsi_conn structure | |
147 | * @phba: The phba instance | |
148 | * @cid: The cid to free | |
149 | */ | |
150 | static int beiscsi_bindconn_cid(struct beiscsi_hba *phba, | |
151 | struct beiscsi_conn *beiscsi_conn, | |
152 | unsigned int cid) | |
153 | { | |
154 | if (phba->conn_table[cid]) { | |
155 | SE_DEBUG(DBG_LVL_1, | |
156 | "Connection table already occupied. Detected clash\n"); | |
157 | return -EINVAL; | |
158 | } else { | |
159 | SE_DEBUG(DBG_LVL_8, "phba->conn_table[%d]=%p(beiscsi_conn) \n", | |
160 | cid, beiscsi_conn); | |
161 | phba->conn_table[cid] = beiscsi_conn; | |
162 | } | |
163 | return 0; | |
164 | } | |
165 | ||
166 | /** | |
167 | * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection | |
168 | * @cls_session: pointer to iscsi cls session | |
169 | * @cls_conn: pointer to iscsi cls conn | |
170 | * @transport_fd: EP handle(64 bit) | |
171 | * | |
172 | * This function binds the TCP Conn with iSCSI Connection and Session. | |
173 | */ | |
174 | int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, | |
175 | struct iscsi_cls_conn *cls_conn, | |
176 | u64 transport_fd, int is_leading) | |
177 | { | |
178 | struct iscsi_conn *conn = cls_conn->dd_data; | |
179 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
180 | struct Scsi_Host *shost = | |
181 | (struct Scsi_Host *)iscsi_session_to_shost(cls_session); | |
182 | struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost); | |
183 | struct beiscsi_endpoint *beiscsi_ep; | |
184 | struct iscsi_endpoint *ep; | |
185 | ||
186 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_bind\n"); | |
187 | ep = iscsi_lookup_endpoint(transport_fd); | |
188 | if (!ep) | |
189 | return -EINVAL; | |
190 | ||
191 | beiscsi_ep = ep->dd_data; | |
192 | ||
193 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) | |
194 | return -EINVAL; | |
195 | ||
196 | if (beiscsi_ep->phba != phba) { | |
197 | SE_DEBUG(DBG_LVL_8, | |
198 | "beiscsi_ep->hba=%p not equal to phba=%p \n", | |
199 | beiscsi_ep->phba, phba); | |
200 | return -EEXIST; | |
201 | } | |
202 | ||
203 | beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid; | |
204 | beiscsi_conn->ep = beiscsi_ep; | |
205 | beiscsi_ep->conn = beiscsi_conn; | |
206 | SE_DEBUG(DBG_LVL_8, "beiscsi_conn=%p conn=%p ep_cid=%d \n", | |
207 | beiscsi_conn, conn, beiscsi_ep->ep_cid); | |
208 | return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid); | |
209 | } | |
210 | ||
211 | /** | |
212 | * beiscsi_conn_get_param - get the iscsi parameter | |
213 | * @cls_conn: pointer to iscsi cls conn | |
214 | * @param: parameter type identifier | |
215 | * @buf: buffer pointer | |
216 | * | |
217 | * returns iscsi parameter | |
218 | */ | |
219 | int beiscsi_conn_get_param(struct iscsi_cls_conn *cls_conn, | |
220 | enum iscsi_param param, char *buf) | |
221 | { | |
222 | struct beiscsi_endpoint *beiscsi_ep; | |
223 | struct iscsi_conn *conn = cls_conn->dd_data; | |
224 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
225 | int len = 0; | |
226 | ||
227 | beiscsi_ep = beiscsi_conn->ep; | |
228 | if (!beiscsi_ep) { | |
229 | SE_DEBUG(DBG_LVL_1, | |
230 | "In beiscsi_conn_get_param , no beiscsi_ep\n"); | |
231 | return -1; | |
232 | } | |
233 | ||
234 | switch (param) { | |
235 | case ISCSI_PARAM_CONN_PORT: | |
236 | len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport); | |
237 | break; | |
238 | case ISCSI_PARAM_CONN_ADDRESS: | |
239 | if (beiscsi_ep->ip_type == BE2_IPV4) | |
240 | len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr); | |
241 | else | |
242 | len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr); | |
243 | break; | |
244 | default: | |
245 | return iscsi_conn_get_param(cls_conn, param, buf); | |
246 | } | |
247 | return len; | |
248 | } | |
249 | ||
250 | int beiscsi_set_param(struct iscsi_cls_conn *cls_conn, | |
251 | enum iscsi_param param, char *buf, int buflen) | |
252 | { | |
253 | struct iscsi_conn *conn = cls_conn->dd_data; | |
254 | struct iscsi_session *session = conn->session; | |
255 | int ret; | |
256 | ||
257 | ret = iscsi_set_param(cls_conn, param, buf, buflen); | |
258 | if (ret) | |
259 | return ret; | |
260 | /* | |
261 | * If userspace tried to set the value to higher than we can | |
262 | * support override here. | |
263 | */ | |
264 | switch (param) { | |
265 | case ISCSI_PARAM_FIRST_BURST: | |
266 | if (session->first_burst > 8192) | |
267 | session->first_burst = 8192; | |
268 | break; | |
269 | case ISCSI_PARAM_MAX_RECV_DLENGTH: | |
270 | if (conn->max_recv_dlength > 65536) | |
271 | conn->max_recv_dlength = 65536; | |
272 | break; | |
273 | case ISCSI_PARAM_MAX_BURST: | |
274 | if (session->first_burst > 262144) | |
275 | session->first_burst = 262144; | |
276 | break; | |
277 | default: | |
278 | return 0; | |
279 | } | |
280 | ||
281 | return 0; | |
282 | } | |
283 | ||
284 | /** | |
285 | * beiscsi_get_host_param - get the iscsi parameter | |
286 | * @shost: pointer to scsi_host structure | |
287 | * @param: parameter type identifier | |
288 | * @buf: buffer pointer | |
289 | * | |
290 | * returns host parameter | |
291 | */ | |
292 | int beiscsi_get_host_param(struct Scsi_Host *shost, | |
293 | enum iscsi_host_param param, char *buf) | |
294 | { | |
295 | struct beiscsi_hba *phba = (struct beiscsi_hba *)iscsi_host_priv(shost); | |
296 | int len = 0; | |
297 | ||
298 | switch (param) { | |
299 | case ISCSI_HOST_PARAM_HWADDRESS: | |
bfead3b2 | 300 | be_cmd_get_mac_addr(phba, phba->mac_address); |
6733b39a JK |
301 | len = sysfs_format_mac(buf, phba->mac_address, ETH_ALEN); |
302 | break; | |
303 | default: | |
304 | return iscsi_host_get_param(shost, param, buf); | |
305 | } | |
306 | return len; | |
307 | } | |
308 | ||
309 | /** | |
310 | * beiscsi_conn_get_stats - get the iscsi stats | |
311 | * @cls_conn: pointer to iscsi cls conn | |
312 | * @stats: pointer to iscsi_stats structure | |
313 | * | |
314 | * returns iscsi stats | |
315 | */ | |
316 | void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn, | |
317 | struct iscsi_stats *stats) | |
318 | { | |
319 | struct iscsi_conn *conn = cls_conn->dd_data; | |
320 | ||
321 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_stats\n"); | |
322 | stats->txdata_octets = conn->txdata_octets; | |
323 | stats->rxdata_octets = conn->rxdata_octets; | |
324 | stats->dataout_pdus = conn->dataout_pdus_cnt; | |
325 | stats->scsirsp_pdus = conn->scsirsp_pdus_cnt; | |
326 | stats->scsicmd_pdus = conn->scsicmd_pdus_cnt; | |
327 | stats->datain_pdus = conn->datain_pdus_cnt; | |
328 | stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt; | |
329 | stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt; | |
330 | stats->r2t_pdus = conn->r2t_pdus_cnt; | |
331 | stats->digest_err = 0; | |
332 | stats->timeout_err = 0; | |
333 | stats->custom_length = 0; | |
334 | strcpy(stats->custom[0].desc, "eh_abort_cnt"); | |
335 | stats->custom[0].value = conn->eh_abort_cnt; | |
336 | } | |
337 | ||
338 | /** | |
339 | * beiscsi_set_params_for_offld - get the parameters for offload | |
340 | * @beiscsi_conn: pointer to beiscsi_conn | |
341 | * @params: pointer to offload_params structure | |
342 | */ | |
343 | static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn, | |
344 | struct beiscsi_offload_params *params) | |
345 | { | |
346 | struct iscsi_conn *conn = beiscsi_conn->conn; | |
347 | struct iscsi_session *session = conn->session; | |
348 | ||
349 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length, | |
350 | params, session->max_burst); | |
351 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, | |
352 | max_send_data_segment_length, params, | |
353 | conn->max_xmit_dlength); | |
354 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length, | |
355 | params, session->first_burst); | |
356 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params, | |
357 | session->erl); | |
358 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params, | |
359 | conn->datadgst_en); | |
360 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params, | |
361 | conn->hdrdgst_en); | |
362 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params, | |
363 | session->initial_r2t_en); | |
364 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params, | |
365 | session->imm_data_en); | |
366 | AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params, | |
367 | (conn->exp_statsn - 1)); | |
368 | } | |
369 | ||
370 | /** | |
371 | * beiscsi_conn_start - offload of session to chip | |
372 | * @cls_conn: pointer to beiscsi_conn | |
373 | */ | |
374 | int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn) | |
375 | { | |
376 | struct iscsi_conn *conn = cls_conn->dd_data; | |
377 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
378 | struct beiscsi_endpoint *beiscsi_ep; | |
379 | struct beiscsi_offload_params params; | |
6733b39a JK |
380 | |
381 | memset(¶ms, 0, sizeof(struct beiscsi_offload_params)); | |
382 | beiscsi_ep = beiscsi_conn->ep; | |
383 | if (!beiscsi_ep) | |
384 | SE_DEBUG(DBG_LVL_1, "In beiscsi_conn_start , no beiscsi_ep\n"); | |
385 | ||
6733b39a JK |
386 | beiscsi_conn->login_in_progress = 0; |
387 | beiscsi_set_params_for_offld(beiscsi_conn, ¶ms); | |
388 | beiscsi_offload_connection(beiscsi_conn, ¶ms); | |
389 | iscsi_conn_start(cls_conn); | |
390 | return 0; | |
391 | } | |
392 | ||
393 | /** | |
394 | * beiscsi_get_cid - Allocate a cid | |
395 | * @phba: The phba instance | |
396 | */ | |
397 | static int beiscsi_get_cid(struct beiscsi_hba *phba) | |
398 | { | |
399 | unsigned short cid = 0xFFFF; | |
400 | ||
401 | if (!phba->avlbl_cids) | |
402 | return cid; | |
403 | ||
404 | cid = phba->cid_array[phba->cid_alloc++]; | |
405 | if (phba->cid_alloc == phba->params.cxns_per_ctrl) | |
406 | phba->cid_alloc = 0; | |
407 | phba->avlbl_cids--; | |
408 | return cid; | |
409 | } | |
410 | ||
411 | /** | |
412 | * beiscsi_open_conn - Ask FW to open a TCP connection | |
413 | * @ep: endpoint to be used | |
414 | * @src_addr: The source IP address | |
415 | * @dst_addr: The Destination IP address | |
416 | * | |
417 | * Asks the FW to open a TCP connection | |
418 | */ | |
419 | static int beiscsi_open_conn(struct iscsi_endpoint *ep, | |
420 | struct sockaddr *src_addr, | |
421 | struct sockaddr *dst_addr, int non_blocking) | |
422 | { | |
423 | struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; | |
424 | struct beiscsi_hba *phba = beiscsi_ep->phba; | |
425 | int ret = -1; | |
426 | ||
427 | beiscsi_ep->ep_cid = beiscsi_get_cid(phba); | |
428 | if (beiscsi_ep->ep_cid == 0xFFFF) { | |
429 | SE_DEBUG(DBG_LVL_1, "No free cid available\n"); | |
430 | return ret; | |
431 | } | |
432 | SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn, ep_cid=%d ", | |
433 | beiscsi_ep->ep_cid); | |
7da50879 JK |
434 | phba->ep_array[beiscsi_ep->ep_cid - |
435 | phba->fw_config.iscsi_cid_start] = ep; | |
436 | if (beiscsi_ep->ep_cid > (phba->fw_config.iscsi_cid_start + | |
437 | phba->params.cxns_per_ctrl * 2)) { | |
6733b39a JK |
438 | SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n"); |
439 | return ret; | |
440 | } | |
441 | ||
442 | beiscsi_ep->cid_vld = 0; | |
443 | return mgmt_open_connection(phba, dst_addr, beiscsi_ep); | |
444 | } | |
445 | ||
446 | /** | |
447 | * beiscsi_put_cid - Free the cid | |
448 | * @phba: The phba for which the cid is being freed | |
449 | * @cid: The cid to free | |
450 | */ | |
451 | static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid) | |
452 | { | |
453 | phba->avlbl_cids++; | |
454 | phba->cid_array[phba->cid_free++] = cid; | |
455 | if (phba->cid_free == phba->params.cxns_per_ctrl) | |
456 | phba->cid_free = 0; | |
457 | } | |
458 | ||
459 | /** | |
460 | * beiscsi_free_ep - free endpoint | |
461 | * @ep: pointer to iscsi endpoint structure | |
462 | */ | |
c2462288 | 463 | static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep) |
6733b39a | 464 | { |
6733b39a JK |
465 | struct beiscsi_hba *phba = beiscsi_ep->phba; |
466 | ||
467 | beiscsi_put_cid(phba, beiscsi_ep->ep_cid); | |
468 | beiscsi_ep->phba = NULL; | |
6733b39a JK |
469 | } |
470 | ||
471 | /** | |
472 | * beiscsi_ep_connect - Ask chip to create TCP Conn | |
473 | * @scsi_host: Pointer to scsi_host structure | |
474 | * @dst_addr: The IP address of Target | |
475 | * @non_blocking: blocking or non-blocking call | |
476 | * | |
477 | * This routines first asks chip to create a connection and then allocates an EP | |
478 | */ | |
479 | struct iscsi_endpoint * | |
480 | beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr, | |
481 | int non_blocking) | |
482 | { | |
483 | struct beiscsi_hba *phba; | |
484 | struct beiscsi_endpoint *beiscsi_ep; | |
485 | struct iscsi_endpoint *ep; | |
486 | int ret; | |
487 | ||
488 | SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_connect \n"); | |
489 | if (shost) | |
490 | phba = iscsi_host_priv(shost); | |
491 | else { | |
492 | ret = -ENXIO; | |
493 | SE_DEBUG(DBG_LVL_1, "shost is NULL \n"); | |
494 | return ERR_PTR(ret); | |
495 | } | |
bfead3b2 JK |
496 | |
497 | if (phba->state) { | |
498 | ret = -EBUSY; | |
c2462288 | 499 | SE_DEBUG(DBG_LVL_1, "The Adapter state is Not UP \n"); |
bfead3b2 JK |
500 | return ERR_PTR(ret); |
501 | } | |
502 | ||
6733b39a JK |
503 | ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint)); |
504 | if (!ep) { | |
505 | ret = -ENOMEM; | |
506 | return ERR_PTR(ret); | |
507 | } | |
508 | ||
509 | beiscsi_ep = ep->dd_data; | |
510 | beiscsi_ep->phba = phba; | |
c2462288 | 511 | beiscsi_ep->openiscsi_ep = ep; |
6733b39a JK |
512 | |
513 | if (beiscsi_open_conn(ep, NULL, dst_addr, non_blocking)) { | |
c2462288 | 514 | SE_DEBUG(DBG_LVL_1, "Failed in beiscsi_open_conn \n"); |
6733b39a JK |
515 | ret = -ENOMEM; |
516 | goto free_ep; | |
517 | } | |
518 | ||
519 | return ep; | |
520 | ||
521 | free_ep: | |
c2462288 | 522 | beiscsi_free_ep(beiscsi_ep); |
6733b39a JK |
523 | return ERR_PTR(ret); |
524 | } | |
525 | ||
526 | /** | |
527 | * beiscsi_ep_poll - Poll to see if connection is established | |
528 | * @ep: endpoint to be used | |
529 | * @timeout_ms: timeout specified in millisecs | |
530 | * | |
531 | * Poll to see if TCP connection established | |
532 | */ | |
533 | int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms) | |
534 | { | |
535 | struct beiscsi_endpoint *beiscsi_ep = ep->dd_data; | |
536 | ||
537 | SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_poll\n"); | |
538 | if (beiscsi_ep->cid_vld == 1) | |
539 | return 1; | |
540 | else | |
541 | return 0; | |
542 | } | |
543 | ||
544 | /** | |
545 | * beiscsi_close_conn - Upload the connection | |
546 | * @ep: The iscsi endpoint | |
547 | * @flag: The type of connection closure | |
548 | */ | |
c2462288 | 549 | static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag) |
6733b39a JK |
550 | { |
551 | int ret = 0; | |
6733b39a JK |
552 | struct beiscsi_hba *phba = beiscsi_ep->phba; |
553 | ||
554 | if (MGMT_STATUS_SUCCESS != | |
555 | mgmt_upload_connection(phba, beiscsi_ep->ep_cid, | |
c2462288 | 556 | flag)) { |
6733b39a JK |
557 | SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x", |
558 | beiscsi_ep->ep_cid); | |
559 | ret = -1; | |
560 | } | |
561 | ||
562 | return ret; | |
563 | } | |
564 | ||
565 | /** | |
566 | * beiscsi_ep_disconnect - Tears down the TCP connection | |
567 | * @ep: endpoint to be used | |
568 | * | |
569 | * Tears down the TCP connection | |
570 | */ | |
571 | void beiscsi_ep_disconnect(struct iscsi_endpoint *ep) | |
572 | { | |
573 | struct beiscsi_conn *beiscsi_conn; | |
574 | struct beiscsi_endpoint *beiscsi_ep; | |
575 | struct beiscsi_hba *phba; | |
6733b39a JK |
576 | |
577 | beiscsi_ep = ep->dd_data; | |
578 | phba = beiscsi_ep->phba; | |
6733b39a JK |
579 | |
580 | if (beiscsi_ep->conn) { | |
581 | beiscsi_conn = beiscsi_ep->conn; | |
582 | iscsi_suspend_queue(beiscsi_conn->conn); | |
6733b39a JK |
583 | } |
584 | ||
6733b39a JK |
585 | } |
586 | ||
587 | /** | |
588 | * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table | |
589 | * @phba: The phba instance | |
590 | * @cid: The cid to free | |
591 | */ | |
592 | static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba, | |
593 | unsigned int cid) | |
594 | { | |
595 | if (phba->conn_table[cid]) | |
596 | phba->conn_table[cid] = NULL; | |
597 | else { | |
598 | SE_DEBUG(DBG_LVL_8, "Connection table Not occupied. \n"); | |
599 | return -EINVAL; | |
600 | } | |
601 | return 0; | |
602 | } | |
603 | ||
604 | /** | |
605 | * beiscsi_conn_stop - Invalidate and stop the connection | |
606 | * @cls_conn: pointer to get iscsi_conn | |
607 | * @flag: The type of connection closure | |
608 | */ | |
609 | void beiscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag) | |
610 | { | |
611 | struct iscsi_conn *conn = cls_conn->dd_data; | |
612 | struct beiscsi_conn *beiscsi_conn = conn->dd_data; | |
613 | struct beiscsi_endpoint *beiscsi_ep; | |
614 | struct iscsi_session *session = conn->session; | |
615 | struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session); | |
616 | struct beiscsi_hba *phba = iscsi_host_priv(shost); | |
617 | unsigned int status; | |
618 | unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH; | |
619 | ||
620 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop\n"); | |
621 | beiscsi_ep = beiscsi_conn->ep; | |
622 | if (!beiscsi_ep) { | |
623 | SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop , no beiscsi_ep\n"); | |
624 | return; | |
625 | } | |
626 | status = mgmt_invalidate_connection(phba, beiscsi_ep, | |
627 | beiscsi_ep->ep_cid, 1, | |
628 | savecfg_flag); | |
629 | if (status != MGMT_STATUS_SUCCESS) { | |
630 | SE_DEBUG(DBG_LVL_1, | |
631 | "mgmt_invalidate_connection Failed for cid=%d \n", | |
632 | beiscsi_ep->ep_cid); | |
633 | } | |
c2462288 JK |
634 | beiscsi_close_conn(beiscsi_ep, CONNECTION_UPLOAD_GRACEFUL); |
635 | beiscsi_free_ep(beiscsi_ep); | |
636 | iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep); | |
6733b39a JK |
637 | beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid); |
638 | iscsi_conn_stop(cls_conn, flag); | |
639 | } |