be_iscsi.c 17 KB

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