be_iscsi.c 18 KB

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