be_iscsi.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788
  1. /**
  2. * Copyright (C) 2005 - 2011 Emulex
  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 (jayamohan.kallickal@emulex.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@emulex.com
  14. *
  15. * Emulex
  16. * 3333 Susan Street
  17. * Costa Mesa, CA 92626
  18. */
  19. #include <scsi/libiscsi.h>
  20. #include <scsi/scsi_transport_iscsi.h>
  21. #include <scsi/scsi_transport.h>
  22. #include <scsi/scsi_cmnd.h>
  23. #include <scsi/scsi_device.h>
  24. #include <scsi/scsi_host.h>
  25. #include <scsi/scsi.h>
  26. #include "be_iscsi.h"
  27. extern struct iscsi_transport beiscsi_iscsi_transport;
  28. /**
  29. * beiscsi_session_create - creates a new iscsi session
  30. * @cmds_max: max commands supported
  31. * @qdepth: max queue depth supported
  32. * @initial_cmdsn: initial iscsi CMDSN
  33. */
  34. struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep,
  35. u16 cmds_max,
  36. u16 qdepth,
  37. u32 initial_cmdsn)
  38. {
  39. struct Scsi_Host *shost;
  40. struct beiscsi_endpoint *beiscsi_ep;
  41. struct iscsi_cls_session *cls_session;
  42. struct beiscsi_hba *phba;
  43. struct iscsi_session *sess;
  44. struct beiscsi_session *beiscsi_sess;
  45. struct beiscsi_io_task *io_task;
  46. SE_DEBUG(DBG_LVL_8, "In beiscsi_session_create\n");
  47. if (!ep) {
  48. SE_DEBUG(DBG_LVL_1, "beiscsi_session_create: invalid ep\n");
  49. return NULL;
  50. }
  51. beiscsi_ep = ep->dd_data;
  52. phba = beiscsi_ep->phba;
  53. shost = phba->shost;
  54. if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
  55. shost_printk(KERN_ERR, shost, "Cannot handle %d cmds."
  56. "Max cmds per session supported is %d. Using %d. "
  57. "\n", cmds_max,
  58. beiscsi_ep->phba->params.wrbs_per_cxn,
  59. beiscsi_ep->phba->params.wrbs_per_cxn);
  60. cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
  61. }
  62. cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
  63. shost, cmds_max,
  64. sizeof(*beiscsi_sess),
  65. sizeof(*io_task),
  66. initial_cmdsn, ISCSI_MAX_TARGET);
  67. if (!cls_session)
  68. return NULL;
  69. sess = cls_session->dd_data;
  70. beiscsi_sess = sess->dd_data;
  71. beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool",
  72. phba->pcidev,
  73. sizeof(struct be_cmd_bhs),
  74. 64, 0);
  75. if (!beiscsi_sess->bhs_pool)
  76. goto destroy_sess;
  77. return cls_session;
  78. destroy_sess:
  79. iscsi_session_teardown(cls_session);
  80. return NULL;
  81. }
  82. /**
  83. * beiscsi_session_destroy - destroys iscsi session
  84. * @cls_session: pointer to iscsi cls session
  85. *
  86. * Destroys iSCSI session instance and releases
  87. * resources allocated for it.
  88. */
  89. void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
  90. {
  91. struct iscsi_session *sess = cls_session->dd_data;
  92. struct beiscsi_session *beiscsi_sess = sess->dd_data;
  93. SE_DEBUG(DBG_LVL_8, "In beiscsi_session_destroy\n");
  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 = iscsi_session_to_shost(cls_session);
  165. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  166. struct beiscsi_endpoint *beiscsi_ep;
  167. struct iscsi_endpoint *ep;
  168. SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_bind\n");
  169. ep = iscsi_lookup_endpoint(transport_fd);
  170. if (!ep)
  171. return -EINVAL;
  172. beiscsi_ep = ep->dd_data;
  173. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  174. return -EINVAL;
  175. if (beiscsi_ep->phba != phba) {
  176. SE_DEBUG(DBG_LVL_8,
  177. "beiscsi_ep->hba=%p not equal to phba=%p\n",
  178. beiscsi_ep->phba, phba);
  179. return -EEXIST;
  180. }
  181. beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
  182. beiscsi_conn->ep = beiscsi_ep;
  183. beiscsi_ep->conn = beiscsi_conn;
  184. SE_DEBUG(DBG_LVL_8, "beiscsi_conn=%p conn=%p ep_cid=%d\n",
  185. beiscsi_conn, conn, beiscsi_ep->ep_cid);
  186. return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
  187. }
  188. /**
  189. * beiscsi_ep_get_param - get the iscsi parameter
  190. * @ep: pointer to iscsi ep
  191. * @param: parameter type identifier
  192. * @buf: buffer pointer
  193. *
  194. * returns iscsi parameter
  195. */
  196. int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
  197. enum iscsi_param param, char *buf)
  198. {
  199. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  200. int len = 0;
  201. SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_param, param= %d\n", param);
  202. switch (param) {
  203. case ISCSI_PARAM_CONN_PORT:
  204. len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
  205. break;
  206. case ISCSI_PARAM_CONN_ADDRESS:
  207. if (beiscsi_ep->ip_type == BE2_IPV4)
  208. len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
  209. else
  210. len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
  211. break;
  212. default:
  213. return -ENOSYS;
  214. }
  215. return len;
  216. }
  217. int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
  218. enum iscsi_param param, char *buf, int buflen)
  219. {
  220. struct iscsi_conn *conn = cls_conn->dd_data;
  221. struct iscsi_session *session = conn->session;
  222. int ret;
  223. SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_set_param, param= %d\n", param);
  224. ret = iscsi_set_param(cls_conn, param, buf, buflen);
  225. if (ret)
  226. return ret;
  227. /*
  228. * If userspace tried to set the value to higher than we can
  229. * support override here.
  230. */
  231. switch (param) {
  232. case ISCSI_PARAM_FIRST_BURST:
  233. if (session->first_burst > 8192)
  234. session->first_burst = 8192;
  235. break;
  236. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  237. if (conn->max_recv_dlength > 65536)
  238. conn->max_recv_dlength = 65536;
  239. break;
  240. case ISCSI_PARAM_MAX_BURST:
  241. if (session->max_burst > 262144)
  242. session->max_burst = 262144;
  243. break;
  244. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  245. if ((conn->max_xmit_dlength > 65536) ||
  246. (conn->max_xmit_dlength == 0))
  247. conn->max_xmit_dlength = 65536;
  248. default:
  249. return 0;
  250. }
  251. return 0;
  252. }
  253. /**
  254. * beiscsi_get_host_param - get the iscsi parameter
  255. * @shost: pointer to scsi_host structure
  256. * @param: parameter type identifier
  257. * @buf: buffer pointer
  258. *
  259. * returns host parameter
  260. */
  261. int beiscsi_get_host_param(struct Scsi_Host *shost,
  262. enum iscsi_host_param param, char *buf)
  263. {
  264. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  265. int status = 0;
  266. SE_DEBUG(DBG_LVL_8, "In beiscsi_get_host_param, param= %d\n", param);
  267. switch (param) {
  268. case ISCSI_HOST_PARAM_HWADDRESS:
  269. status = beiscsi_get_macaddr(buf, phba);
  270. if (status < 0) {
  271. SE_DEBUG(DBG_LVL_1, "beiscsi_get_macaddr Failed\n");
  272. return status;
  273. }
  274. break;
  275. default:
  276. return iscsi_host_get_param(shost, param, buf);
  277. }
  278. return status;
  279. }
  280. int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
  281. {
  282. struct be_cmd_resp_get_mac_addr *resp;
  283. struct be_mcc_wrb *wrb;
  284. unsigned int tag, wrb_num;
  285. unsigned short status, extd_status;
  286. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  287. int rc;
  288. if (phba->read_mac_address)
  289. return sysfs_format_mac(buf, phba->mac_address,
  290. ETH_ALEN);
  291. tag = be_cmd_get_mac_addr(phba);
  292. if (!tag) {
  293. SE_DEBUG(DBG_LVL_1, "be_cmd_get_mac_addr Failed\n");
  294. return -EBUSY;
  295. } else
  296. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  297. phba->ctrl.mcc_numtag[tag]);
  298. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  299. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  300. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  301. if (status || extd_status) {
  302. SE_DEBUG(DBG_LVL_1, "Failed to get be_cmd_get_mac_addr"
  303. " status = %d extd_status = %d\n",
  304. status, extd_status);
  305. free_mcc_tag(&phba->ctrl, tag);
  306. return -EAGAIN;
  307. }
  308. wrb = queue_get_wrb(mccq, wrb_num);
  309. free_mcc_tag(&phba->ctrl, tag);
  310. resp = embedded_payload(wrb);
  311. memcpy(phba->mac_address, resp->mac_address, ETH_ALEN);
  312. rc = sysfs_format_mac(buf, phba->mac_address,
  313. ETH_ALEN);
  314. phba->read_mac_address = 1;
  315. return rc;
  316. }
  317. /**
  318. * beiscsi_conn_get_stats - get the iscsi stats
  319. * @cls_conn: pointer to iscsi cls conn
  320. * @stats: pointer to iscsi_stats structure
  321. *
  322. * returns iscsi stats
  323. */
  324. void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  325. struct iscsi_stats *stats)
  326. {
  327. struct iscsi_conn *conn = cls_conn->dd_data;
  328. SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_get_stats\n");
  329. stats->txdata_octets = conn->txdata_octets;
  330. stats->rxdata_octets = conn->rxdata_octets;
  331. stats->dataout_pdus = conn->dataout_pdus_cnt;
  332. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  333. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  334. stats->datain_pdus = conn->datain_pdus_cnt;
  335. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  336. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  337. stats->r2t_pdus = conn->r2t_pdus_cnt;
  338. stats->digest_err = 0;
  339. stats->timeout_err = 0;
  340. stats->custom_length = 0;
  341. strcpy(stats->custom[0].desc, "eh_abort_cnt");
  342. stats->custom[0].value = conn->eh_abort_cnt;
  343. }
  344. /**
  345. * beiscsi_set_params_for_offld - get the parameters for offload
  346. * @beiscsi_conn: pointer to beiscsi_conn
  347. * @params: pointer to offload_params structure
  348. */
  349. static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
  350. struct beiscsi_offload_params *params)
  351. {
  352. struct iscsi_conn *conn = beiscsi_conn->conn;
  353. struct iscsi_session *session = conn->session;
  354. AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
  355. params, session->max_burst);
  356. AMAP_SET_BITS(struct amap_beiscsi_offload_params,
  357. max_send_data_segment_length, params,
  358. conn->max_xmit_dlength);
  359. AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
  360. params, session->first_burst);
  361. AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
  362. session->erl);
  363. AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
  364. conn->datadgst_en);
  365. AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
  366. conn->hdrdgst_en);
  367. AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
  368. session->initial_r2t_en);
  369. AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
  370. session->imm_data_en);
  371. AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
  372. (conn->exp_statsn - 1));
  373. }
  374. /**
  375. * beiscsi_conn_start - offload of session to chip
  376. * @cls_conn: pointer to beiscsi_conn
  377. */
  378. int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
  379. {
  380. struct iscsi_conn *conn = cls_conn->dd_data;
  381. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  382. struct beiscsi_endpoint *beiscsi_ep;
  383. struct beiscsi_offload_params params;
  384. SE_DEBUG(DBG_LVL_8, "In beiscsi_conn_start\n");
  385. memset(&params, 0, sizeof(struct beiscsi_offload_params));
  386. beiscsi_ep = beiscsi_conn->ep;
  387. if (!beiscsi_ep)
  388. SE_DEBUG(DBG_LVL_1, "In beiscsi_conn_start , no beiscsi_ep\n");
  389. beiscsi_conn->login_in_progress = 0;
  390. beiscsi_set_params_for_offld(beiscsi_conn, &params);
  391. beiscsi_offload_connection(beiscsi_conn, &params);
  392. iscsi_conn_start(cls_conn);
  393. return 0;
  394. }
  395. /**
  396. * beiscsi_get_cid - Allocate a cid
  397. * @phba: The phba instance
  398. */
  399. static int beiscsi_get_cid(struct beiscsi_hba *phba)
  400. {
  401. unsigned short cid = 0xFFFF;
  402. if (!phba->avlbl_cids)
  403. return cid;
  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. * beiscsi_put_cid - Free the cid
  412. * @phba: The phba for which the cid is being freed
  413. * @cid: The cid to free
  414. */
  415. static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
  416. {
  417. phba->avlbl_cids++;
  418. phba->cid_array[phba->cid_free++] = cid;
  419. if (phba->cid_free == phba->params.cxns_per_ctrl)
  420. phba->cid_free = 0;
  421. }
  422. /**
  423. * beiscsi_free_ep - free endpoint
  424. * @ep: pointer to iscsi endpoint structure
  425. */
  426. static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
  427. {
  428. struct beiscsi_hba *phba = beiscsi_ep->phba;
  429. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  430. beiscsi_ep->phba = NULL;
  431. }
  432. /**
  433. * beiscsi_open_conn - Ask FW to open a TCP connection
  434. * @ep: endpoint to be used
  435. * @src_addr: The source IP address
  436. * @dst_addr: The Destination IP address
  437. *
  438. * Asks the FW to open a TCP connection
  439. */
  440. static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  441. struct sockaddr *src_addr,
  442. struct sockaddr *dst_addr, int non_blocking)
  443. {
  444. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  445. struct beiscsi_hba *phba = beiscsi_ep->phba;
  446. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  447. struct be_mcc_wrb *wrb;
  448. struct tcp_connect_and_offload_out *ptcpcnct_out;
  449. unsigned short status, extd_status;
  450. struct be_dma_mem nonemb_cmd;
  451. unsigned int tag, wrb_num;
  452. int ret = -ENOMEM;
  453. SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn\n");
  454. beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
  455. if (beiscsi_ep->ep_cid == 0xFFFF) {
  456. SE_DEBUG(DBG_LVL_1, "No free cid available\n");
  457. return ret;
  458. }
  459. SE_DEBUG(DBG_LVL_8, "In beiscsi_open_conn, ep_cid=%d\n",
  460. beiscsi_ep->ep_cid);
  461. phba->ep_array[beiscsi_ep->ep_cid -
  462. phba->fw_config.iscsi_cid_start] = ep;
  463. if (beiscsi_ep->ep_cid > (phba->fw_config.iscsi_cid_start +
  464. phba->params.cxns_per_ctrl * 2)) {
  465. SE_DEBUG(DBG_LVL_1, "Failed in allocate iscsi cid\n");
  466. goto free_ep;
  467. }
  468. beiscsi_ep->cid_vld = 0;
  469. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  470. sizeof(struct tcp_connect_and_offload_in),
  471. &nonemb_cmd.dma);
  472. if (nonemb_cmd.va == NULL) {
  473. SE_DEBUG(DBG_LVL_1,
  474. "Failed to allocate memory for mgmt_open_connection"
  475. "\n");
  476. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  477. return -ENOMEM;
  478. }
  479. nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
  480. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  481. tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
  482. if (!tag) {
  483. SE_DEBUG(DBG_LVL_1,
  484. "mgmt_open_connection Failed for cid=%d\n",
  485. beiscsi_ep->ep_cid);
  486. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  487. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  488. nonemb_cmd.va, nonemb_cmd.dma);
  489. return -EAGAIN;
  490. } else {
  491. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  492. phba->ctrl.mcc_numtag[tag]);
  493. }
  494. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  495. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  496. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  497. if (status || extd_status) {
  498. SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed"
  499. " status = %d extd_status = %d\n",
  500. status, extd_status);
  501. free_mcc_tag(&phba->ctrl, tag);
  502. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  503. nonemb_cmd.va, nonemb_cmd.dma);
  504. goto free_ep;
  505. } else {
  506. wrb = queue_get_wrb(mccq, wrb_num);
  507. free_mcc_tag(&phba->ctrl, tag);
  508. ptcpcnct_out = embedded_payload(wrb);
  509. beiscsi_ep = ep->dd_data;
  510. beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
  511. beiscsi_ep->cid_vld = 1;
  512. SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
  513. }
  514. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  515. nonemb_cmd.va, nonemb_cmd.dma);
  516. return 0;
  517. free_ep:
  518. beiscsi_free_ep(beiscsi_ep);
  519. return -EBUSY;
  520. }
  521. /**
  522. * beiscsi_ep_connect - Ask chip to create TCP Conn
  523. * @scsi_host: Pointer to scsi_host structure
  524. * @dst_addr: The IP address of Target
  525. * @non_blocking: blocking or non-blocking call
  526. *
  527. * This routines first asks chip to create a connection and then allocates an EP
  528. */
  529. struct iscsi_endpoint *
  530. beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  531. int non_blocking)
  532. {
  533. struct beiscsi_hba *phba;
  534. struct beiscsi_endpoint *beiscsi_ep;
  535. struct iscsi_endpoint *ep;
  536. int ret;
  537. SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_connect\n");
  538. if (shost)
  539. phba = iscsi_host_priv(shost);
  540. else {
  541. ret = -ENXIO;
  542. SE_DEBUG(DBG_LVL_1, "shost is NULL\n");
  543. return ERR_PTR(ret);
  544. }
  545. if (phba->state != BE_ADAPTER_UP) {
  546. ret = -EBUSY;
  547. SE_DEBUG(DBG_LVL_1, "The Adapter state is Not UP\n");
  548. return ERR_PTR(ret);
  549. }
  550. ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
  551. if (!ep) {
  552. ret = -ENOMEM;
  553. return ERR_PTR(ret);
  554. }
  555. beiscsi_ep = ep->dd_data;
  556. beiscsi_ep->phba = phba;
  557. beiscsi_ep->openiscsi_ep = ep;
  558. ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
  559. if (ret) {
  560. SE_DEBUG(DBG_LVL_1, "Failed in beiscsi_open_conn\n");
  561. goto free_ep;
  562. }
  563. return ep;
  564. free_ep:
  565. iscsi_destroy_endpoint(ep);
  566. return ERR_PTR(ret);
  567. }
  568. /**
  569. * beiscsi_ep_poll - Poll to see if connection is established
  570. * @ep: endpoint to be used
  571. * @timeout_ms: timeout specified in millisecs
  572. *
  573. * Poll to see if TCP connection established
  574. */
  575. int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  576. {
  577. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  578. SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_poll\n");
  579. if (beiscsi_ep->cid_vld == 1)
  580. return 1;
  581. else
  582. return 0;
  583. }
  584. /**
  585. * beiscsi_close_conn - Upload the connection
  586. * @ep: The iscsi endpoint
  587. * @flag: The type of connection closure
  588. */
  589. static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
  590. {
  591. int ret = 0;
  592. unsigned int tag;
  593. struct beiscsi_hba *phba = beiscsi_ep->phba;
  594. tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
  595. if (!tag) {
  596. SE_DEBUG(DBG_LVL_8, "upload failed for cid 0x%x\n",
  597. beiscsi_ep->ep_cid);
  598. ret = -EAGAIN;
  599. } else {
  600. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  601. phba->ctrl.mcc_numtag[tag]);
  602. free_mcc_tag(&phba->ctrl, tag);
  603. }
  604. return ret;
  605. }
  606. /**
  607. * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
  608. * @phba: The phba instance
  609. * @cid: The cid to free
  610. */
  611. static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
  612. unsigned int cid)
  613. {
  614. if (phba->conn_table[cid])
  615. phba->conn_table[cid] = NULL;
  616. else {
  617. SE_DEBUG(DBG_LVL_8, "Connection table Not occupied.\n");
  618. return -EINVAL;
  619. }
  620. return 0;
  621. }
  622. /**
  623. * beiscsi_ep_disconnect - Tears down the TCP connection
  624. * @ep: endpoint to be used
  625. *
  626. * Tears down the TCP connection
  627. */
  628. void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
  629. {
  630. struct beiscsi_conn *beiscsi_conn;
  631. struct beiscsi_endpoint *beiscsi_ep;
  632. struct beiscsi_hba *phba;
  633. unsigned int tag;
  634. unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
  635. beiscsi_ep = ep->dd_data;
  636. phba = beiscsi_ep->phba;
  637. SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect for ep_cid = %d\n",
  638. beiscsi_ep->ep_cid);
  639. if (!beiscsi_ep->conn) {
  640. SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect, no "
  641. "beiscsi_ep\n");
  642. return;
  643. }
  644. beiscsi_conn = beiscsi_ep->conn;
  645. iscsi_suspend_queue(beiscsi_conn->conn);
  646. SE_DEBUG(DBG_LVL_8, "In beiscsi_ep_disconnect ep_cid = %d\n",
  647. beiscsi_ep->ep_cid);
  648. tag = mgmt_invalidate_connection(phba, beiscsi_ep,
  649. beiscsi_ep->ep_cid, 1,
  650. savecfg_flag);
  651. if (!tag) {
  652. SE_DEBUG(DBG_LVL_1,
  653. "mgmt_invalidate_connection Failed for cid=%d\n",
  654. beiscsi_ep->ep_cid);
  655. } else {
  656. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  657. phba->ctrl.mcc_numtag[tag]);
  658. free_mcc_tag(&phba->ctrl, tag);
  659. }
  660. beiscsi_close_conn(beiscsi_ep, CONNECTION_UPLOAD_GRACEFUL);
  661. beiscsi_free_ep(beiscsi_ep);
  662. beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
  663. iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
  664. }
  665. umode_t be2iscsi_attr_is_visible(int param_type, int param)
  666. {
  667. switch (param_type) {
  668. case ISCSI_HOST_PARAM:
  669. switch (param) {
  670. case ISCSI_HOST_PARAM_HWADDRESS:
  671. case ISCSI_HOST_PARAM_IPADDRESS:
  672. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  673. return S_IRUGO;
  674. default:
  675. return 0;
  676. }
  677. case ISCSI_PARAM:
  678. switch (param) {
  679. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  680. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  681. case ISCSI_PARAM_HDRDGST_EN:
  682. case ISCSI_PARAM_DATADGST_EN:
  683. case ISCSI_PARAM_CONN_ADDRESS:
  684. case ISCSI_PARAM_CONN_PORT:
  685. case ISCSI_PARAM_EXP_STATSN:
  686. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  687. case ISCSI_PARAM_PERSISTENT_PORT:
  688. case ISCSI_PARAM_PING_TMO:
  689. case ISCSI_PARAM_RECV_TMO:
  690. case ISCSI_PARAM_INITIAL_R2T_EN:
  691. case ISCSI_PARAM_MAX_R2T:
  692. case ISCSI_PARAM_IMM_DATA_EN:
  693. case ISCSI_PARAM_FIRST_BURST:
  694. case ISCSI_PARAM_MAX_BURST:
  695. case ISCSI_PARAM_PDU_INORDER_EN:
  696. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  697. case ISCSI_PARAM_ERL:
  698. case ISCSI_PARAM_TARGET_NAME:
  699. case ISCSI_PARAM_TPGT:
  700. case ISCSI_PARAM_USERNAME:
  701. case ISCSI_PARAM_PASSWORD:
  702. case ISCSI_PARAM_USERNAME_IN:
  703. case ISCSI_PARAM_PASSWORD_IN:
  704. case ISCSI_PARAM_FAST_ABORT:
  705. case ISCSI_PARAM_ABORT_TMO:
  706. case ISCSI_PARAM_LU_RESET_TMO:
  707. case ISCSI_PARAM_IFACE_NAME:
  708. case ISCSI_PARAM_INITIATOR_NAME:
  709. return S_IRUGO;
  710. default:
  711. return 0;
  712. }
  713. }
  714. return 0;
  715. }