2 * Copyright (C) 2005 - 2010 ServerEngines
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.
10 * Written by: Jayamohan Kallickal (jayamohank@serverengines.com)
12 * Contact Information:
13 * linux-drivers@serverengines.com
16 * 209 N. Fair Oaks Ave
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>
31 extern struct iscsi_transport beiscsi_iscsi_transport
;
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
39 struct iscsi_cls_session
*beiscsi_session_create(struct iscsi_endpoint
*ep
,
44 struct Scsi_Host
*shost
;
45 struct beiscsi_endpoint
*beiscsi_ep
;
46 struct iscsi_cls_session
*cls_session
;
47 struct beiscsi_hba
*phba
;
48 struct iscsi_session
*sess
;
49 struct beiscsi_session
*beiscsi_sess
;
50 struct beiscsi_io_task
*io_task
;
52 SE_DEBUG(DBG_LVL_8
, "In beiscsi_session_create\n");
55 SE_DEBUG(DBG_LVL_1
, "beiscsi_session_create: invalid ep\n");
58 beiscsi_ep
= ep
->dd_data
;
59 phba
= beiscsi_ep
->phba
;
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. "
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
;
70 cls_session
= iscsi_session_setup(&beiscsi_iscsi_transport
,
72 sizeof(*beiscsi_sess
),
74 initial_cmdsn
, ISCSI_MAX_TARGET
);
77 sess
= cls_session
->dd_data
;
78 beiscsi_sess
= sess
->dd_data
;
79 beiscsi_sess
->bhs_pool
= pci_pool_create("beiscsi_bhs_pool",
81 sizeof(struct be_cmd_bhs
),
83 if (!beiscsi_sess
->bhs_pool
)
88 iscsi_session_teardown(cls_session
);
93 * beiscsi_session_destroy - destroys iscsi session
94 * @cls_session: pointer to iscsi cls session
96 * Destroys iSCSI session instance and releases
97 * resources allocated for it.
99 void beiscsi_session_destroy(struct iscsi_cls_session
*cls_session
)
101 struct iscsi_session
*sess
= cls_session
->dd_data
;
102 struct beiscsi_session
*beiscsi_sess
= sess
->dd_data
;
104 SE_DEBUG(DBG_LVL_8
, "In beiscsi_session_destroy\n");
105 pci_pool_destroy(beiscsi_sess
->bhs_pool
);
106 iscsi_session_teardown(cls_session
);
110 * beiscsi_conn_create - create an instance of iscsi connection
111 * @cls_session: ptr to iscsi_cls_session
114 struct iscsi_cls_conn
*
115 beiscsi_conn_create(struct iscsi_cls_session
*cls_session
, u32 cid
)
117 struct beiscsi_hba
*phba
;
118 struct Scsi_Host
*shost
;
119 struct iscsi_cls_conn
*cls_conn
;
120 struct beiscsi_conn
*beiscsi_conn
;
121 struct iscsi_conn
*conn
;
122 struct iscsi_session
*sess
;
123 struct beiscsi_session
*beiscsi_sess
;
125 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_create ,cid"
126 "from iscsi layer=%d\n", cid
);
127 shost
= iscsi_session_to_shost(cls_session
);
128 phba
= iscsi_host_priv(shost
);
130 cls_conn
= iscsi_conn_setup(cls_session
, sizeof(*beiscsi_conn
), cid
);
134 conn
= cls_conn
->dd_data
;
135 beiscsi_conn
= conn
->dd_data
;
136 beiscsi_conn
->ep
= NULL
;
137 beiscsi_conn
->phba
= phba
;
138 beiscsi_conn
->conn
= conn
;
139 sess
= cls_session
->dd_data
;
140 beiscsi_sess
= sess
->dd_data
;
141 beiscsi_conn
->beiscsi_sess
= beiscsi_sess
;
146 * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table
147 * @beiscsi_conn: The pointer to beiscsi_conn structure
148 * @phba: The phba instance
149 * @cid: The cid to free
151 static int beiscsi_bindconn_cid(struct beiscsi_hba
*phba
,
152 struct beiscsi_conn
*beiscsi_conn
,
155 if (phba
->conn_table
[cid
]) {
157 "Connection table already occupied. Detected clash\n");
160 SE_DEBUG(DBG_LVL_8
, "phba->conn_table[%d]=%p(beiscsi_conn)\n",
162 phba
->conn_table
[cid
] = beiscsi_conn
;
168 * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
169 * @cls_session: pointer to iscsi cls session
170 * @cls_conn: pointer to iscsi cls conn
171 * @transport_fd: EP handle(64 bit)
173 * This function binds the TCP Conn with iSCSI Connection and Session.
175 int beiscsi_conn_bind(struct iscsi_cls_session
*cls_session
,
176 struct iscsi_cls_conn
*cls_conn
,
177 u64 transport_fd
, int is_leading
)
179 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
180 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
181 struct Scsi_Host
*shost
=
182 (struct Scsi_Host
*)iscsi_session_to_shost(cls_session
);
183 struct beiscsi_hba
*phba
= (struct beiscsi_hba
*)iscsi_host_priv(shost
);
184 struct beiscsi_endpoint
*beiscsi_ep
;
185 struct iscsi_endpoint
*ep
;
187 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_bind\n");
188 ep
= iscsi_lookup_endpoint(transport_fd
);
192 beiscsi_ep
= ep
->dd_data
;
194 if (iscsi_conn_bind(cls_session
, cls_conn
, is_leading
))
197 if (beiscsi_ep
->phba
!= phba
) {
199 "beiscsi_ep->hba=%p not equal to phba=%p\n",
200 beiscsi_ep
->phba
, phba
);
204 beiscsi_conn
->beiscsi_conn_cid
= beiscsi_ep
->ep_cid
;
205 beiscsi_conn
->ep
= beiscsi_ep
;
206 beiscsi_ep
->conn
= beiscsi_conn
;
207 SE_DEBUG(DBG_LVL_8
, "beiscsi_conn=%p conn=%p ep_cid=%d\n",
208 beiscsi_conn
, conn
, beiscsi_ep
->ep_cid
);
209 return beiscsi_bindconn_cid(phba
, beiscsi_conn
, beiscsi_ep
->ep_cid
);
213 * beiscsi_conn_get_param - get the iscsi parameter
214 * @cls_conn: pointer to iscsi cls conn
215 * @param: parameter type identifier
216 * @buf: buffer pointer
218 * returns iscsi parameter
220 int beiscsi_conn_get_param(struct iscsi_cls_conn
*cls_conn
,
221 enum iscsi_param param
, char *buf
)
223 struct beiscsi_endpoint
*beiscsi_ep
;
224 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
225 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
228 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_get_param, param= %d\n", param
);
229 beiscsi_ep
= beiscsi_conn
->ep
;
232 "In beiscsi_conn_get_param , no beiscsi_ep\n");
237 case ISCSI_PARAM_CONN_PORT
:
238 len
= sprintf(buf
, "%hu\n", beiscsi_ep
->dst_tcpport
);
240 case ISCSI_PARAM_CONN_ADDRESS
:
241 if (beiscsi_ep
->ip_type
== BE2_IPV4
)
242 len
= sprintf(buf
, "%pI4\n", &beiscsi_ep
->dst_addr
);
244 len
= sprintf(buf
, "%pI6\n", &beiscsi_ep
->dst6_addr
);
247 return iscsi_conn_get_param(cls_conn
, param
, buf
);
252 int beiscsi_set_param(struct iscsi_cls_conn
*cls_conn
,
253 enum iscsi_param param
, char *buf
, int buflen
)
255 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
256 struct iscsi_session
*session
= conn
->session
;
259 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_set_param, param= %d\n", param
);
260 ret
= iscsi_set_param(cls_conn
, param
, buf
, buflen
);
264 * If userspace tried to set the value to higher than we can
265 * support override here.
268 case ISCSI_PARAM_FIRST_BURST
:
269 if (session
->first_burst
> 8192)
270 session
->first_burst
= 8192;
272 case ISCSI_PARAM_MAX_RECV_DLENGTH
:
273 if (conn
->max_recv_dlength
> 65536)
274 conn
->max_recv_dlength
= 65536;
276 case ISCSI_PARAM_MAX_BURST
:
277 if (session
->max_burst
> 262144)
278 session
->max_burst
= 262144;
280 case ISCSI_PARAM_MAX_XMIT_DLENGTH
:
281 if ((conn
->max_xmit_dlength
> 65536) ||
282 (conn
->max_xmit_dlength
== 0))
283 conn
->max_xmit_dlength
= 65536;
292 * beiscsi_get_host_param - get the iscsi parameter
293 * @shost: pointer to scsi_host structure
294 * @param: parameter type identifier
295 * @buf: buffer pointer
297 * returns host parameter
299 int beiscsi_get_host_param(struct Scsi_Host
*shost
,
300 enum iscsi_host_param param
, char *buf
)
302 struct beiscsi_hba
*phba
= (struct beiscsi_hba
*)iscsi_host_priv(shost
);
306 SE_DEBUG(DBG_LVL_8
, "In beiscsi_get_host_param, param= %d\n", param
);
308 case ISCSI_HOST_PARAM_HWADDRESS
:
309 status
= beiscsi_get_macaddr(buf
, phba
);
311 SE_DEBUG(DBG_LVL_1
, "beiscsi_get_macaddr Failed\n");
316 return iscsi_host_get_param(shost
, param
, buf
);
321 int beiscsi_get_macaddr(char *buf
, struct beiscsi_hba
*phba
)
323 struct be_cmd_resp_get_mac_addr
*resp
;
324 struct be_mcc_wrb
*wrb
;
325 unsigned int tag
, wrb_num
;
326 unsigned short status
, extd_status
;
327 struct be_queue_info
*mccq
= &phba
->ctrl
.mcc_obj
.q
;
330 if (phba
->read_mac_address
)
331 return sysfs_format_mac(buf
, phba
->mac_address
,
334 tag
= be_cmd_get_mac_addr(phba
);
336 SE_DEBUG(DBG_LVL_1
, "be_cmd_get_mac_addr Failed\n");
339 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
340 phba
->ctrl
.mcc_numtag
[tag
]);
342 wrb_num
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x00FF0000) >> 16;
343 extd_status
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x0000FF00) >> 8;
344 status
= phba
->ctrl
.mcc_numtag
[tag
] & 0x000000FF;
345 if (status
|| extd_status
) {
346 SE_DEBUG(DBG_LVL_1
, "Failed to get be_cmd_get_mac_addr"
347 " status = %d extd_status = %d\n",
348 status
, extd_status
);
349 free_mcc_tag(&phba
->ctrl
, tag
);
352 wrb
= queue_get_wrb(mccq
, wrb_num
);
353 free_mcc_tag(&phba
->ctrl
, tag
);
354 resp
= embedded_payload(wrb
);
355 memcpy(phba
->mac_address
, resp
->mac_address
, ETH_ALEN
);
356 rc
= sysfs_format_mac(buf
, phba
->mac_address
,
358 phba
->read_mac_address
= 1;
364 * beiscsi_conn_get_stats - get the iscsi stats
365 * @cls_conn: pointer to iscsi cls conn
366 * @stats: pointer to iscsi_stats structure
368 * returns iscsi stats
370 void beiscsi_conn_get_stats(struct iscsi_cls_conn
*cls_conn
,
371 struct iscsi_stats
*stats
)
373 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
375 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_get_stats\n");
376 stats
->txdata_octets
= conn
->txdata_octets
;
377 stats
->rxdata_octets
= conn
->rxdata_octets
;
378 stats
->dataout_pdus
= conn
->dataout_pdus_cnt
;
379 stats
->scsirsp_pdus
= conn
->scsirsp_pdus_cnt
;
380 stats
->scsicmd_pdus
= conn
->scsicmd_pdus_cnt
;
381 stats
->datain_pdus
= conn
->datain_pdus_cnt
;
382 stats
->tmfrsp_pdus
= conn
->tmfrsp_pdus_cnt
;
383 stats
->tmfcmd_pdus
= conn
->tmfcmd_pdus_cnt
;
384 stats
->r2t_pdus
= conn
->r2t_pdus_cnt
;
385 stats
->digest_err
= 0;
386 stats
->timeout_err
= 0;
387 stats
->custom_length
= 0;
388 strcpy(stats
->custom
[0].desc
, "eh_abort_cnt");
389 stats
->custom
[0].value
= conn
->eh_abort_cnt
;
393 * beiscsi_set_params_for_offld - get the parameters for offload
394 * @beiscsi_conn: pointer to beiscsi_conn
395 * @params: pointer to offload_params structure
397 static void beiscsi_set_params_for_offld(struct beiscsi_conn
*beiscsi_conn
,
398 struct beiscsi_offload_params
*params
)
400 struct iscsi_conn
*conn
= beiscsi_conn
->conn
;
401 struct iscsi_session
*session
= conn
->session
;
403 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, max_burst_length
,
404 params
, session
->max_burst
);
405 AMAP_SET_BITS(struct amap_beiscsi_offload_params
,
406 max_send_data_segment_length
, params
,
407 conn
->max_xmit_dlength
);
408 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, first_burst_length
,
409 params
, session
->first_burst
);
410 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, erl
, params
,
412 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, dde
, params
,
414 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, hde
, params
,
416 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, ir2t
, params
,
417 session
->initial_r2t_en
);
418 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, imd
, params
,
419 session
->imm_data_en
);
420 AMAP_SET_BITS(struct amap_beiscsi_offload_params
, exp_statsn
, params
,
421 (conn
->exp_statsn
- 1));
425 * beiscsi_conn_start - offload of session to chip
426 * @cls_conn: pointer to beiscsi_conn
428 int beiscsi_conn_start(struct iscsi_cls_conn
*cls_conn
)
430 struct iscsi_conn
*conn
= cls_conn
->dd_data
;
431 struct beiscsi_conn
*beiscsi_conn
= conn
->dd_data
;
432 struct beiscsi_endpoint
*beiscsi_ep
;
433 struct beiscsi_offload_params params
;
435 SE_DEBUG(DBG_LVL_8
, "In beiscsi_conn_start\n");
436 memset(¶ms
, 0, sizeof(struct beiscsi_offload_params
));
437 beiscsi_ep
= beiscsi_conn
->ep
;
439 SE_DEBUG(DBG_LVL_1
, "In beiscsi_conn_start , no beiscsi_ep\n");
441 beiscsi_conn
->login_in_progress
= 0;
442 beiscsi_set_params_for_offld(beiscsi_conn
, ¶ms
);
443 beiscsi_offload_connection(beiscsi_conn
, ¶ms
);
444 iscsi_conn_start(cls_conn
);
449 * beiscsi_get_cid - Allocate a cid
450 * @phba: The phba instance
452 static int beiscsi_get_cid(struct beiscsi_hba
*phba
)
454 unsigned short cid
= 0xFFFF;
456 if (!phba
->avlbl_cids
)
459 cid
= phba
->cid_array
[phba
->cid_alloc
++];
460 if (phba
->cid_alloc
== phba
->params
.cxns_per_ctrl
)
467 * beiscsi_put_cid - Free the cid
468 * @phba: The phba for which the cid is being freed
469 * @cid: The cid to free
471 static void beiscsi_put_cid(struct beiscsi_hba
*phba
, unsigned short cid
)
474 phba
->cid_array
[phba
->cid_free
++] = cid
;
475 if (phba
->cid_free
== phba
->params
.cxns_per_ctrl
)
480 * beiscsi_free_ep - free endpoint
481 * @ep: pointer to iscsi endpoint structure
483 static void beiscsi_free_ep(struct beiscsi_endpoint
*beiscsi_ep
)
485 struct beiscsi_hba
*phba
= beiscsi_ep
->phba
;
487 beiscsi_put_cid(phba
, beiscsi_ep
->ep_cid
);
488 beiscsi_ep
->phba
= NULL
;
492 * beiscsi_open_conn - Ask FW to open a TCP connection
493 * @ep: endpoint to be used
494 * @src_addr: The source IP address
495 * @dst_addr: The Destination IP address
497 * Asks the FW to open a TCP connection
499 static int beiscsi_open_conn(struct iscsi_endpoint
*ep
,
500 struct sockaddr
*src_addr
,
501 struct sockaddr
*dst_addr
, int non_blocking
)
503 struct beiscsi_endpoint
*beiscsi_ep
= ep
->dd_data
;
504 struct beiscsi_hba
*phba
= beiscsi_ep
->phba
;
505 struct be_queue_info
*mccq
= &phba
->ctrl
.mcc_obj
.q
;
506 struct be_mcc_wrb
*wrb
;
507 struct tcp_connect_and_offload_out
*ptcpcnct_out
;
508 unsigned short status
, extd_status
;
509 struct be_dma_mem nonemb_cmd
;
510 unsigned int tag
, wrb_num
;
513 SE_DEBUG(DBG_LVL_8
, "In beiscsi_open_conn\n");
514 beiscsi_ep
->ep_cid
= beiscsi_get_cid(phba
);
515 if (beiscsi_ep
->ep_cid
== 0xFFFF) {
516 SE_DEBUG(DBG_LVL_1
, "No free cid available\n");
519 SE_DEBUG(DBG_LVL_8
, "In beiscsi_open_conn, ep_cid=%d\n",
521 phba
->ep_array
[beiscsi_ep
->ep_cid
-
522 phba
->fw_config
.iscsi_cid_start
] = ep
;
523 if (beiscsi_ep
->ep_cid
> (phba
->fw_config
.iscsi_cid_start
+
524 phba
->params
.cxns_per_ctrl
* 2)) {
525 SE_DEBUG(DBG_LVL_1
, "Failed in allocate iscsi cid\n");
529 beiscsi_ep
->cid_vld
= 0;
530 nonemb_cmd
.va
= pci_alloc_consistent(phba
->ctrl
.pdev
,
531 sizeof(struct tcp_connect_and_offload_in
),
533 if (nonemb_cmd
.va
== NULL
) {
535 "Failed to allocate memory for mgmt_open_connection"
537 beiscsi_put_cid(phba
, beiscsi_ep
->ep_cid
);
540 nonemb_cmd
.size
= sizeof(struct tcp_connect_and_offload_in
);
541 memset(nonemb_cmd
.va
, 0, nonemb_cmd
.size
);
542 tag
= mgmt_open_connection(phba
, dst_addr
, beiscsi_ep
, &nonemb_cmd
);
545 "mgmt_open_connection Failed for cid=%d\n",
547 beiscsi_put_cid(phba
, beiscsi_ep
->ep_cid
);
548 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
549 nonemb_cmd
.va
, nonemb_cmd
.dma
);
552 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
553 phba
->ctrl
.mcc_numtag
[tag
]);
555 wrb_num
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x00FF0000) >> 16;
556 extd_status
= (phba
->ctrl
.mcc_numtag
[tag
] & 0x0000FF00) >> 8;
557 status
= phba
->ctrl
.mcc_numtag
[tag
] & 0x000000FF;
558 if (status
|| extd_status
) {
559 SE_DEBUG(DBG_LVL_1
, "mgmt_open_connection Failed"
560 " status = %d extd_status = %d\n",
561 status
, extd_status
);
562 free_mcc_tag(&phba
->ctrl
, tag
);
563 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
564 nonemb_cmd
.va
, nonemb_cmd
.dma
);
567 wrb
= queue_get_wrb(mccq
, wrb_num
);
568 free_mcc_tag(&phba
->ctrl
, tag
);
570 ptcpcnct_out
= embedded_payload(wrb
);
571 beiscsi_ep
= ep
->dd_data
;
572 beiscsi_ep
->fw_handle
= ptcpcnct_out
->connection_handle
;
573 beiscsi_ep
->cid_vld
= 1;
574 SE_DEBUG(DBG_LVL_8
, "mgmt_open_connection Success\n");
576 pci_free_consistent(phba
->ctrl
.pdev
, nonemb_cmd
.size
,
577 nonemb_cmd
.va
, nonemb_cmd
.dma
);
581 beiscsi_free_ep(beiscsi_ep
);
586 * beiscsi_ep_connect - Ask chip to create TCP Conn
587 * @scsi_host: Pointer to scsi_host structure
588 * @dst_addr: The IP address of Target
589 * @non_blocking: blocking or non-blocking call
591 * This routines first asks chip to create a connection and then allocates an EP
593 struct iscsi_endpoint
*
594 beiscsi_ep_connect(struct Scsi_Host
*shost
, struct sockaddr
*dst_addr
,
597 struct beiscsi_hba
*phba
;
598 struct beiscsi_endpoint
*beiscsi_ep
;
599 struct iscsi_endpoint
*ep
;
602 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_connect\n");
604 phba
= iscsi_host_priv(shost
);
607 SE_DEBUG(DBG_LVL_1
, "shost is NULL\n");
611 if (phba
->state
!= BE_ADAPTER_UP
) {
613 SE_DEBUG(DBG_LVL_1
, "The Adapter state is Not UP\n");
617 ep
= iscsi_create_endpoint(sizeof(struct beiscsi_endpoint
));
623 beiscsi_ep
= ep
->dd_data
;
624 beiscsi_ep
->phba
= phba
;
625 beiscsi_ep
->openiscsi_ep
= ep
;
626 ret
= beiscsi_open_conn(ep
, NULL
, dst_addr
, non_blocking
);
628 SE_DEBUG(DBG_LVL_1
, "Failed in beiscsi_open_conn\n");
635 iscsi_destroy_endpoint(ep
);
640 * beiscsi_ep_poll - Poll to see if connection is established
641 * @ep: endpoint to be used
642 * @timeout_ms: timeout specified in millisecs
644 * Poll to see if TCP connection established
646 int beiscsi_ep_poll(struct iscsi_endpoint
*ep
, int timeout_ms
)
648 struct beiscsi_endpoint
*beiscsi_ep
= ep
->dd_data
;
650 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_poll\n");
651 if (beiscsi_ep
->cid_vld
== 1)
658 * beiscsi_close_conn - Upload the connection
659 * @ep: The iscsi endpoint
660 * @flag: The type of connection closure
662 static int beiscsi_close_conn(struct beiscsi_endpoint
*beiscsi_ep
, int flag
)
666 struct beiscsi_hba
*phba
= beiscsi_ep
->phba
;
668 tag
= mgmt_upload_connection(phba
, beiscsi_ep
->ep_cid
, flag
);
670 SE_DEBUG(DBG_LVL_8
, "upload failed for cid 0x%x\n",
674 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
675 phba
->ctrl
.mcc_numtag
[tag
]);
676 free_mcc_tag(&phba
->ctrl
, tag
);
682 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
683 * @phba: The phba instance
684 * @cid: The cid to free
686 static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba
*phba
,
689 if (phba
->conn_table
[cid
])
690 phba
->conn_table
[cid
] = NULL
;
692 SE_DEBUG(DBG_LVL_8
, "Connection table Not occupied.\n");
699 * beiscsi_ep_disconnect - Tears down the TCP connection
700 * @ep: endpoint to be used
702 * Tears down the TCP connection
704 void beiscsi_ep_disconnect(struct iscsi_endpoint
*ep
)
706 struct beiscsi_conn
*beiscsi_conn
;
707 struct beiscsi_endpoint
*beiscsi_ep
;
708 struct beiscsi_hba
*phba
;
710 unsigned short savecfg_flag
= CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH
;
712 beiscsi_ep
= ep
->dd_data
;
713 phba
= beiscsi_ep
->phba
;
714 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_disconnect for ep_cid = %d\n",
717 if (!beiscsi_ep
->conn
) {
718 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_disconnect, no "
722 beiscsi_conn
= beiscsi_ep
->conn
;
723 iscsi_suspend_queue(beiscsi_conn
->conn
);
725 SE_DEBUG(DBG_LVL_8
, "In beiscsi_ep_disconnect ep_cid = %d\n",
728 tag
= mgmt_invalidate_connection(phba
, beiscsi_ep
,
729 beiscsi_ep
->ep_cid
, 1,
733 "mgmt_invalidate_connection Failed for cid=%d\n",
736 wait_event_interruptible(phba
->ctrl
.mcc_wait
[tag
],
737 phba
->ctrl
.mcc_numtag
[tag
]);
738 free_mcc_tag(&phba
->ctrl
, tag
);
741 beiscsi_close_conn(beiscsi_ep
, CONNECTION_UPLOAD_GRACEFUL
);
742 beiscsi_free_ep(beiscsi_ep
);
743 beiscsi_unbind_conn_to_cid(phba
, beiscsi_ep
->ep_cid
);
744 iscsi_destroy_endpoint(beiscsi_ep
->openiscsi_ep
);