blob: 2b3c58bd65292118d65eab13ccc7008e24a11adb [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
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
31extern 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 */
39struct 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;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053047 struct beiscsi_hba *phba;
Jayamohan Kallickalb8b9e1b82009-09-22 08:21:22 +053048 struct iscsi_session *sess;
49 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053050 struct beiscsi_io_task *io_task;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053051
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
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053070 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);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053075 if (!cls_session)
76 return NULL;
77 sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053078 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;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053085
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053086 return cls_session;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +053087destroy_sess:
88 iscsi_session_teardown(cls_session);
89 return NULL;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053090}
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 */
99void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
100{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530101 struct iscsi_session *sess = cls_session->dd_data;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530102 struct beiscsi_session *beiscsi_sess = sess->dd_data;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530103
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530104 pci_pool_destroy(beiscsi_sess->bhs_pool);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530105 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 */
113struct iscsi_cls_conn *
114beiscsi_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;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530121 struct iscsi_session *sess;
122 struct beiscsi_session *beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530123
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;
Jayamohan Kallickal2afc95b2009-09-22 08:22:26 +0530138 sess = cls_session->dd_data;
139 beiscsi_sess = sess->dd_data;
140 beiscsi_conn->beiscsi_sess = beiscsi_sess;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530141 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 */
150static 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 */
174int 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 */
219int 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
250int 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 */
292int 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:
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530300 be_cmd_get_mac_addr(phba, phba->mac_address);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530301 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 */
316void 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 */
343static 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 */
374int 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;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530380
381 memset(&params, 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
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530386 beiscsi_conn->login_in_progress = 0;
387 beiscsi_set_params_for_offld(beiscsi_conn, &params);
388 beiscsi_offload_connection(beiscsi_conn, &params);
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 */
397static 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 */
419static 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);
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530434 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)) {
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530438 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 */
451static 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 */
463static void beiscsi_free_ep(struct iscsi_endpoint *ep)
464{
465 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
466 struct beiscsi_hba *phba = beiscsi_ep->phba;
467
468 beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
469 beiscsi_ep->phba = NULL;
470 iscsi_destroy_endpoint(ep);
471}
472
473/**
474 * beiscsi_ep_connect - Ask chip to create TCP Conn
475 * @scsi_host: Pointer to scsi_host structure
476 * @dst_addr: The IP address of Target
477 * @non_blocking: blocking or non-blocking call
478 *
479 * This routines first asks chip to create a connection and then allocates an EP
480 */
481struct iscsi_endpoint *
482beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
483 int non_blocking)
484{
485 struct beiscsi_hba *phba;
486 struct beiscsi_endpoint *beiscsi_ep;
487 struct iscsi_endpoint *ep;
488 int ret;
489
490 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_connect \n");
491 if (shost)
492 phba = iscsi_host_priv(shost);
493 else {
494 ret = -ENXIO;
495 SE_DEBUG(DBG_LVL_1, "shost is NULL \n");
496 return ERR_PTR(ret);
497 }
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530498
499 if (phba->state) {
500 ret = -EBUSY;
501 SE_DEBUG(DBG_LVL_1, "The Adapet state is Not UP \n");
502 return ERR_PTR(ret);
503 }
504
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530505 ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
506 if (!ep) {
507 ret = -ENOMEM;
508 return ERR_PTR(ret);
509 }
510
511 beiscsi_ep = ep->dd_data;
512 beiscsi_ep->phba = phba;
513
514 if (beiscsi_open_conn(ep, NULL, dst_addr, non_blocking)) {
515 SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n");
516 ret = -ENOMEM;
517 goto free_ep;
518 }
519
520 return ep;
521
522free_ep:
523 beiscsi_free_ep(ep);
524 return ERR_PTR(ret);
525}
526
527/**
528 * beiscsi_ep_poll - Poll to see if connection is established
529 * @ep: endpoint to be used
530 * @timeout_ms: timeout specified in millisecs
531 *
532 * Poll to see if TCP connection established
533 */
534int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
535{
536 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
537
538 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_poll\n");
539 if (beiscsi_ep->cid_vld == 1)
540 return 1;
541 else
542 return 0;
543}
544
545/**
546 * beiscsi_close_conn - Upload the connection
547 * @ep: The iscsi endpoint
548 * @flag: The type of connection closure
549 */
550static int beiscsi_close_conn(struct iscsi_endpoint *ep, int flag)
551{
552 int ret = 0;
553 struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
554 struct beiscsi_hba *phba = beiscsi_ep->phba;
555
556 if (MGMT_STATUS_SUCCESS !=
557 mgmt_upload_connection(phba, beiscsi_ep->ep_cid,
558 CONNECTION_UPLOAD_GRACEFUL)) {
559 SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x",
560 beiscsi_ep->ep_cid);
561 ret = -1;
562 }
563
564 return ret;
565}
566
567/**
568 * beiscsi_ep_disconnect - Tears down the TCP connection
569 * @ep: endpoint to be used
570 *
571 * Tears down the TCP connection
572 */
573void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
574{
575 struct beiscsi_conn *beiscsi_conn;
576 struct beiscsi_endpoint *beiscsi_ep;
577 struct beiscsi_hba *phba;
578 int flag = 0;
579
580 beiscsi_ep = ep->dd_data;
581 phba = beiscsi_ep->phba;
582 SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect\n");
583
584 if (beiscsi_ep->conn) {
585 beiscsi_conn = beiscsi_ep->conn;
586 iscsi_suspend_queue(beiscsi_conn->conn);
587 beiscsi_close_conn(ep, flag);
588 }
589
590 beiscsi_free_ep(ep);
591}
592
593/**
594 * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
595 * @phba: The phba instance
596 * @cid: The cid to free
597 */
598static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
599 unsigned int cid)
600{
601 if (phba->conn_table[cid])
602 phba->conn_table[cid] = NULL;
603 else {
604 SE_DEBUG(DBG_LVL_8, "Connection table Not occupied. \n");
605 return -EINVAL;
606 }
607 return 0;
608}
609
610/**
611 * beiscsi_conn_stop - Invalidate and stop the connection
612 * @cls_conn: pointer to get iscsi_conn
613 * @flag: The type of connection closure
614 */
615void beiscsi_conn_stop(struct iscsi_cls_conn *cls_conn, int flag)
616{
617 struct iscsi_conn *conn = cls_conn->dd_data;
618 struct beiscsi_conn *beiscsi_conn = conn->dd_data;
619 struct beiscsi_endpoint *beiscsi_ep;
620 struct iscsi_session *session = conn->session;
621 struct Scsi_Host *shost = iscsi_session_to_shost(session->cls_session);
622 struct beiscsi_hba *phba = iscsi_host_priv(shost);
623 unsigned int status;
624 unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
625
626 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop\n");
627 beiscsi_ep = beiscsi_conn->ep;
628 if (!beiscsi_ep) {
629 SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_stop , no beiscsi_ep\n");
630 return;
631 }
632 status = mgmt_invalidate_connection(phba, beiscsi_ep,
633 beiscsi_ep->ep_cid, 1,
634 savecfg_flag);
635 if (status != MGMT_STATUS_SUCCESS) {
636 SE_DEBUG(DBG_LVL_1,
637 "mgmt_invalidate_connection Failed for cid=%d \n",
638 beiscsi_ep->ep_cid);
639 }
640 beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
641 iscsi_conn_stop(cls_conn, flag);
642}