be_iscsi.c 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289
  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_netlink.h>
  26. #include <net/netlink.h>
  27. #include <scsi/scsi.h>
  28. #include "be_iscsi.h"
  29. extern struct iscsi_transport beiscsi_iscsi_transport;
  30. /**
  31. * beiscsi_session_create - creates a new iscsi session
  32. * @cmds_max: max commands supported
  33. * @qdepth: max queue depth supported
  34. * @initial_cmdsn: initial iscsi CMDSN
  35. */
  36. struct iscsi_cls_session *beiscsi_session_create(struct iscsi_endpoint *ep,
  37. u16 cmds_max,
  38. u16 qdepth,
  39. u32 initial_cmdsn)
  40. {
  41. struct Scsi_Host *shost;
  42. struct beiscsi_endpoint *beiscsi_ep;
  43. struct iscsi_cls_session *cls_session;
  44. struct beiscsi_hba *phba;
  45. struct iscsi_session *sess;
  46. struct beiscsi_session *beiscsi_sess;
  47. struct beiscsi_io_task *io_task;
  48. if (!ep) {
  49. printk(KERN_ERR
  50. "beiscsi_session_create: invalid ep\n");
  51. return NULL;
  52. }
  53. beiscsi_ep = ep->dd_data;
  54. phba = beiscsi_ep->phba;
  55. shost = phba->shost;
  56. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  57. "BS_%d : In beiscsi_session_create\n");
  58. if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
  59. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  60. "BS_%d : Cannot handle %d cmds."
  61. "Max cmds per session supported is %d. Using %d."
  62. "\n", cmds_max,
  63. beiscsi_ep->phba->params.wrbs_per_cxn,
  64. beiscsi_ep->phba->params.wrbs_per_cxn);
  65. cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
  66. }
  67. cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
  68. shost, cmds_max,
  69. sizeof(*beiscsi_sess),
  70. sizeof(*io_task),
  71. initial_cmdsn, ISCSI_MAX_TARGET);
  72. if (!cls_session)
  73. return NULL;
  74. sess = cls_session->dd_data;
  75. beiscsi_sess = sess->dd_data;
  76. beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool",
  77. phba->pcidev,
  78. sizeof(struct be_cmd_bhs),
  79. 64, 0);
  80. if (!beiscsi_sess->bhs_pool)
  81. goto destroy_sess;
  82. return cls_session;
  83. destroy_sess:
  84. iscsi_session_teardown(cls_session);
  85. return NULL;
  86. }
  87. /**
  88. * beiscsi_session_destroy - destroys iscsi session
  89. * @cls_session: pointer to iscsi cls session
  90. *
  91. * Destroys iSCSI session instance and releases
  92. * resources allocated for it.
  93. */
  94. void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
  95. {
  96. struct iscsi_session *sess = cls_session->dd_data;
  97. struct beiscsi_session *beiscsi_sess = sess->dd_data;
  98. printk(KERN_INFO "In beiscsi_session_destroy\n");
  99. pci_pool_destroy(beiscsi_sess->bhs_pool);
  100. iscsi_session_teardown(cls_session);
  101. }
  102. /**
  103. * beiscsi_conn_create - create an instance of iscsi connection
  104. * @cls_session: ptr to iscsi_cls_session
  105. * @cid: iscsi cid
  106. */
  107. struct iscsi_cls_conn *
  108. beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid)
  109. {
  110. struct beiscsi_hba *phba;
  111. struct Scsi_Host *shost;
  112. struct iscsi_cls_conn *cls_conn;
  113. struct beiscsi_conn *beiscsi_conn;
  114. struct iscsi_conn *conn;
  115. struct iscsi_session *sess;
  116. struct beiscsi_session *beiscsi_sess;
  117. shost = iscsi_session_to_shost(cls_session);
  118. phba = iscsi_host_priv(shost);
  119. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  120. "BS_%d : In beiscsi_conn_create ,cid"
  121. "from iscsi layer=%d\n", cid);
  122. cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid);
  123. if (!cls_conn)
  124. return NULL;
  125. conn = cls_conn->dd_data;
  126. beiscsi_conn = conn->dd_data;
  127. beiscsi_conn->ep = NULL;
  128. beiscsi_conn->phba = phba;
  129. beiscsi_conn->conn = conn;
  130. sess = cls_session->dd_data;
  131. beiscsi_sess = sess->dd_data;
  132. beiscsi_conn->beiscsi_sess = beiscsi_sess;
  133. return cls_conn;
  134. }
  135. /**
  136. * beiscsi_bindconn_cid - Bind the beiscsi_conn with phba connection table
  137. * @beiscsi_conn: The pointer to beiscsi_conn structure
  138. * @phba: The phba instance
  139. * @cid: The cid to free
  140. */
  141. static int beiscsi_bindconn_cid(struct beiscsi_hba *phba,
  142. struct beiscsi_conn *beiscsi_conn,
  143. unsigned int cid)
  144. {
  145. if (phba->conn_table[cid]) {
  146. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  147. "BS_%d : Connection table already occupied. Detected clash\n");
  148. return -EINVAL;
  149. } else {
  150. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  151. "BS_%d : phba->conn_table[%d]=%p(beiscsi_conn)\n",
  152. cid, beiscsi_conn);
  153. phba->conn_table[cid] = beiscsi_conn;
  154. }
  155. return 0;
  156. }
  157. /**
  158. * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
  159. * @cls_session: pointer to iscsi cls session
  160. * @cls_conn: pointer to iscsi cls conn
  161. * @transport_fd: EP handle(64 bit)
  162. *
  163. * This function binds the TCP Conn with iSCSI Connection and Session.
  164. */
  165. int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
  166. struct iscsi_cls_conn *cls_conn,
  167. u64 transport_fd, int is_leading)
  168. {
  169. struct iscsi_conn *conn = cls_conn->dd_data;
  170. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  171. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  172. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  173. struct beiscsi_endpoint *beiscsi_ep;
  174. struct iscsi_endpoint *ep;
  175. ep = iscsi_lookup_endpoint(transport_fd);
  176. if (!ep)
  177. return -EINVAL;
  178. beiscsi_ep = ep->dd_data;
  179. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  180. return -EINVAL;
  181. if (beiscsi_ep->phba != phba) {
  182. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  183. "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n",
  184. beiscsi_ep->phba, phba);
  185. return -EEXIST;
  186. }
  187. beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
  188. beiscsi_conn->ep = beiscsi_ep;
  189. beiscsi_ep->conn = beiscsi_conn;
  190. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  191. "BS_%d : beiscsi_conn=%p conn=%p ep_cid=%d\n",
  192. beiscsi_conn, conn, beiscsi_ep->ep_cid);
  193. return beiscsi_bindconn_cid(phba, beiscsi_conn, beiscsi_ep->ep_cid);
  194. }
  195. static int beiscsi_create_ipv4_iface(struct beiscsi_hba *phba)
  196. {
  197. if (phba->ipv4_iface)
  198. return 0;
  199. phba->ipv4_iface = iscsi_create_iface(phba->shost,
  200. &beiscsi_iscsi_transport,
  201. ISCSI_IFACE_TYPE_IPV4,
  202. 0, 0);
  203. if (!phba->ipv4_iface) {
  204. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  205. "BS_%d : Could not "
  206. "create default IPv4 address.\n");
  207. return -ENODEV;
  208. }
  209. return 0;
  210. }
  211. static int beiscsi_create_ipv6_iface(struct beiscsi_hba *phba)
  212. {
  213. if (phba->ipv6_iface)
  214. return 0;
  215. phba->ipv6_iface = iscsi_create_iface(phba->shost,
  216. &beiscsi_iscsi_transport,
  217. ISCSI_IFACE_TYPE_IPV6,
  218. 0, 0);
  219. if (!phba->ipv6_iface) {
  220. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  221. "BS_%d : Could not "
  222. "create default IPv6 address.\n");
  223. return -ENODEV;
  224. }
  225. return 0;
  226. }
  227. void beiscsi_create_def_ifaces(struct beiscsi_hba *phba)
  228. {
  229. struct be_cmd_get_if_info_resp if_info;
  230. if (!mgmt_get_if_info(phba, BE2_IPV4, &if_info))
  231. beiscsi_create_ipv4_iface(phba);
  232. if (!mgmt_get_if_info(phba, BE2_IPV6, &if_info))
  233. beiscsi_create_ipv6_iface(phba);
  234. }
  235. void beiscsi_destroy_def_ifaces(struct beiscsi_hba *phba)
  236. {
  237. if (phba->ipv6_iface)
  238. iscsi_destroy_iface(phba->ipv6_iface);
  239. if (phba->ipv4_iface)
  240. iscsi_destroy_iface(phba->ipv4_iface);
  241. }
  242. static int
  243. beiscsi_set_static_ip(struct Scsi_Host *shost,
  244. struct iscsi_iface_param_info *iface_param,
  245. void *data, uint32_t dt_len)
  246. {
  247. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  248. struct iscsi_iface_param_info *iface_ip = NULL;
  249. struct iscsi_iface_param_info *iface_subnet = NULL;
  250. struct nlattr *nla;
  251. int ret;
  252. switch (iface_param->param) {
  253. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  254. nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
  255. if (nla)
  256. iface_ip = nla_data(nla);
  257. nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
  258. if (nla)
  259. iface_subnet = nla_data(nla);
  260. break;
  261. case ISCSI_NET_PARAM_IPV4_ADDR:
  262. iface_ip = iface_param;
  263. nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
  264. if (nla)
  265. iface_subnet = nla_data(nla);
  266. break;
  267. case ISCSI_NET_PARAM_IPV4_SUBNET:
  268. iface_subnet = iface_param;
  269. nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
  270. if (nla)
  271. iface_ip = nla_data(nla);
  272. break;
  273. default:
  274. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  275. "BS_%d : Unsupported param %d\n",
  276. iface_param->param);
  277. }
  278. if (!iface_ip || !iface_subnet) {
  279. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  280. "BS_%d : IP and Subnet Mask required\n");
  281. return -EINVAL;
  282. }
  283. ret = mgmt_set_ip(phba, iface_ip, iface_subnet,
  284. ISCSI_BOOTPROTO_STATIC);
  285. return ret;
  286. }
  287. static int
  288. beiscsi_set_ipv4(struct Scsi_Host *shost,
  289. struct iscsi_iface_param_info *iface_param,
  290. void *data, uint32_t dt_len)
  291. {
  292. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  293. int ret = 0;
  294. /* Check the param */
  295. switch (iface_param->param) {
  296. case ISCSI_NET_PARAM_IPV4_GW:
  297. ret = mgmt_set_gateway(phba, iface_param);
  298. break;
  299. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  300. if (iface_param->value[0] == ISCSI_BOOTPROTO_DHCP)
  301. ret = mgmt_set_ip(phba, iface_param,
  302. NULL, ISCSI_BOOTPROTO_DHCP);
  303. else if (iface_param->value[0] == ISCSI_BOOTPROTO_STATIC)
  304. ret = beiscsi_set_static_ip(shost, iface_param,
  305. data, dt_len);
  306. else
  307. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  308. "BS_%d : Invalid BOOTPROTO: %d\n",
  309. iface_param->value[0]);
  310. break;
  311. case ISCSI_NET_PARAM_IFACE_ENABLE:
  312. if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
  313. ret = beiscsi_create_ipv4_iface(phba);
  314. else
  315. iscsi_destroy_iface(phba->ipv4_iface);
  316. break;
  317. case ISCSI_NET_PARAM_IPV4_SUBNET:
  318. case ISCSI_NET_PARAM_IPV4_ADDR:
  319. ret = beiscsi_set_static_ip(shost, iface_param,
  320. data, dt_len);
  321. break;
  322. default:
  323. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  324. "BS_%d : Param %d not supported\n",
  325. iface_param->param);
  326. }
  327. return ret;
  328. }
  329. static int
  330. beiscsi_set_ipv6(struct Scsi_Host *shost,
  331. struct iscsi_iface_param_info *iface_param,
  332. void *data, uint32_t dt_len)
  333. {
  334. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  335. int ret = 0;
  336. switch (iface_param->param) {
  337. case ISCSI_NET_PARAM_IFACE_ENABLE:
  338. if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
  339. ret = beiscsi_create_ipv6_iface(phba);
  340. else {
  341. iscsi_destroy_iface(phba->ipv6_iface);
  342. ret = 0;
  343. }
  344. break;
  345. case ISCSI_NET_PARAM_IPV6_ADDR:
  346. ret = mgmt_set_ip(phba, iface_param, NULL,
  347. ISCSI_BOOTPROTO_STATIC);
  348. break;
  349. default:
  350. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  351. "BS_%d : Param %d not supported\n",
  352. iface_param->param);
  353. }
  354. return ret;
  355. }
  356. int be2iscsi_iface_set_param(struct Scsi_Host *shost,
  357. void *data, uint32_t dt_len)
  358. {
  359. struct iscsi_iface_param_info *iface_param = NULL;
  360. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  361. struct nlattr *attrib;
  362. uint32_t rm_len = dt_len;
  363. int ret = 0 ;
  364. nla_for_each_attr(attrib, data, dt_len, rm_len) {
  365. iface_param = nla_data(attrib);
  366. if (iface_param->param_type != ISCSI_NET_PARAM)
  367. continue;
  368. /*
  369. * BE2ISCSI only supports 1 interface
  370. */
  371. if (iface_param->iface_num) {
  372. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  373. "BS_%d : Invalid iface_num %d."
  374. "Only iface_num 0 is supported.\n",
  375. iface_param->iface_num);
  376. return -EINVAL;
  377. }
  378. switch (iface_param->iface_type) {
  379. case ISCSI_IFACE_TYPE_IPV4:
  380. ret = beiscsi_set_ipv4(shost, iface_param,
  381. data, dt_len);
  382. break;
  383. case ISCSI_IFACE_TYPE_IPV6:
  384. ret = beiscsi_set_ipv6(shost, iface_param,
  385. data, dt_len);
  386. break;
  387. default:
  388. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  389. "BS_%d : Invalid iface type :%d passed\n",
  390. iface_param->iface_type);
  391. break;
  392. }
  393. if (ret)
  394. return ret;
  395. }
  396. return ret;
  397. }
  398. static int be2iscsi_get_if_param(struct beiscsi_hba *phba,
  399. struct iscsi_iface *iface, int param,
  400. char *buf)
  401. {
  402. struct be_cmd_get_if_info_resp if_info;
  403. int len, ip_type = BE2_IPV4;
  404. memset(&if_info, 0, sizeof(if_info));
  405. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  406. ip_type = BE2_IPV6;
  407. len = mgmt_get_if_info(phba, ip_type, &if_info);
  408. if (len)
  409. return len;
  410. switch (param) {
  411. case ISCSI_NET_PARAM_IPV4_ADDR:
  412. len = sprintf(buf, "%pI4\n", &if_info.ip_addr.addr);
  413. break;
  414. case ISCSI_NET_PARAM_IPV6_ADDR:
  415. len = sprintf(buf, "%pI6\n", &if_info.ip_addr.addr);
  416. break;
  417. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  418. if (!if_info.dhcp_state)
  419. len = sprintf(buf, "static");
  420. else
  421. len = sprintf(buf, "dhcp");
  422. break;
  423. case ISCSI_NET_PARAM_IPV4_SUBNET:
  424. len = sprintf(buf, "%pI4\n", &if_info.ip_addr.subnet_mask);
  425. break;
  426. default:
  427. WARN_ON(1);
  428. }
  429. return len;
  430. }
  431. int be2iscsi_iface_get_param(struct iscsi_iface *iface,
  432. enum iscsi_param_type param_type,
  433. int param, char *buf)
  434. {
  435. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  436. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  437. struct be_cmd_get_def_gateway_resp gateway;
  438. int len = -ENOSYS;
  439. switch (param) {
  440. case ISCSI_NET_PARAM_IPV4_ADDR:
  441. case ISCSI_NET_PARAM_IPV4_SUBNET:
  442. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  443. case ISCSI_NET_PARAM_IPV6_ADDR:
  444. len = be2iscsi_get_if_param(phba, iface, param, buf);
  445. break;
  446. case ISCSI_NET_PARAM_IFACE_ENABLE:
  447. len = sprintf(buf, "enabled");
  448. break;
  449. case ISCSI_NET_PARAM_IPV4_GW:
  450. memset(&gateway, 0, sizeof(gateway));
  451. len = mgmt_get_gateway(phba, BE2_IPV4, &gateway);
  452. if (!len)
  453. len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
  454. break;
  455. default:
  456. len = -ENOSYS;
  457. }
  458. return len;
  459. }
  460. /**
  461. * beiscsi_ep_get_param - get the iscsi parameter
  462. * @ep: pointer to iscsi ep
  463. * @param: parameter type identifier
  464. * @buf: buffer pointer
  465. *
  466. * returns iscsi parameter
  467. */
  468. int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
  469. enum iscsi_param param, char *buf)
  470. {
  471. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  472. int len = 0;
  473. beiscsi_log(beiscsi_ep->phba, KERN_INFO,
  474. BEISCSI_LOG_CONFIG,
  475. "BS_%d : In beiscsi_ep_get_param,"
  476. " param= %d\n", param);
  477. switch (param) {
  478. case ISCSI_PARAM_CONN_PORT:
  479. len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
  480. break;
  481. case ISCSI_PARAM_CONN_ADDRESS:
  482. if (beiscsi_ep->ip_type == BE2_IPV4)
  483. len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
  484. else
  485. len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
  486. break;
  487. default:
  488. return -ENOSYS;
  489. }
  490. return len;
  491. }
  492. int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
  493. enum iscsi_param param, char *buf, int buflen)
  494. {
  495. struct iscsi_conn *conn = cls_conn->dd_data;
  496. struct iscsi_session *session = conn->session;
  497. struct beiscsi_hba *phba = NULL;
  498. int ret;
  499. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  500. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  501. "BS_%d : In beiscsi_conn_set_param,"
  502. " param= %d\n", param);
  503. ret = iscsi_set_param(cls_conn, param, buf, buflen);
  504. if (ret)
  505. return ret;
  506. /*
  507. * If userspace tried to set the value to higher than we can
  508. * support override here.
  509. */
  510. switch (param) {
  511. case ISCSI_PARAM_FIRST_BURST:
  512. if (session->first_burst > 8192)
  513. session->first_burst = 8192;
  514. break;
  515. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  516. if (conn->max_recv_dlength > 65536)
  517. conn->max_recv_dlength = 65536;
  518. break;
  519. case ISCSI_PARAM_MAX_BURST:
  520. if (session->max_burst > 262144)
  521. session->max_burst = 262144;
  522. break;
  523. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  524. if ((conn->max_xmit_dlength > 65536) ||
  525. (conn->max_xmit_dlength == 0))
  526. conn->max_xmit_dlength = 65536;
  527. default:
  528. return 0;
  529. }
  530. return 0;
  531. }
  532. /**
  533. * beiscsi_get_initname - Read Initiator Name from flash
  534. * @buf: buffer bointer
  535. * @phba: The device priv structure instance
  536. *
  537. * returns number of bytes
  538. */
  539. static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
  540. {
  541. int rc;
  542. unsigned int tag, wrb_num;
  543. unsigned short status, extd_status;
  544. struct be_mcc_wrb *wrb;
  545. struct be_cmd_hba_name *resp;
  546. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  547. tag = be_cmd_get_initname(phba);
  548. if (!tag) {
  549. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  550. "BS_%d : Getting Initiator Name Failed\n");
  551. return -EBUSY;
  552. } else
  553. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  554. phba->ctrl.mcc_numtag[tag]);
  555. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  556. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  557. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  558. if (status || extd_status) {
  559. beiscsi_log(phba, KERN_ERR,
  560. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  561. "BS_%d : MailBox Command Failed with "
  562. "status = %d extd_status = %d\n",
  563. status, extd_status);
  564. free_mcc_tag(&phba->ctrl, tag);
  565. return -EAGAIN;
  566. }
  567. wrb = queue_get_wrb(mccq, wrb_num);
  568. free_mcc_tag(&phba->ctrl, tag);
  569. resp = embedded_payload(wrb);
  570. rc = sprintf(buf, "%s\n", resp->initiator_name);
  571. return rc;
  572. }
  573. /**
  574. * beiscsi_get_port_state - Get the Port State
  575. * @shost : pointer to scsi_host structure
  576. *
  577. * returns number of bytes
  578. */
  579. static void beiscsi_get_port_state(struct Scsi_Host *shost)
  580. {
  581. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  582. struct iscsi_cls_host *ihost = shost->shost_data;
  583. ihost->port_state = (phba->state == BE_ADAPTER_UP) ?
  584. ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN;
  585. }
  586. /**
  587. * beiscsi_get_port_speed - Get the Port Speed from Adapter
  588. * @shost : pointer to scsi_host structure
  589. *
  590. * returns Success/Failure
  591. */
  592. static int beiscsi_get_port_speed(struct Scsi_Host *shost)
  593. {
  594. unsigned int tag, wrb_num;
  595. unsigned short status, extd_status;
  596. struct be_mcc_wrb *wrb;
  597. struct be_cmd_ntwk_link_status_resp *resp;
  598. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  599. struct iscsi_cls_host *ihost = shost->shost_data;
  600. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  601. tag = be_cmd_get_port_speed(phba);
  602. if (!tag) {
  603. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  604. "BS_%d : Getting Port Speed Failed\n");
  605. return -EBUSY;
  606. } else
  607. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  608. phba->ctrl.mcc_numtag[tag]);
  609. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  610. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  611. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  612. if (status || extd_status) {
  613. beiscsi_log(phba, KERN_ERR,
  614. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  615. "BS_%d : MailBox Command Failed with "
  616. "status = %d extd_status = %d\n",
  617. status, extd_status);
  618. free_mcc_tag(&phba->ctrl, tag);
  619. return -EAGAIN;
  620. }
  621. wrb = queue_get_wrb(mccq, wrb_num);
  622. free_mcc_tag(&phba->ctrl, tag);
  623. resp = embedded_payload(wrb);
  624. switch (resp->mac_speed) {
  625. case BE2ISCSI_LINK_SPEED_10MBPS:
  626. ihost->port_speed = ISCSI_PORT_SPEED_10MBPS;
  627. break;
  628. case BE2ISCSI_LINK_SPEED_100MBPS:
  629. ihost->port_speed = BE2ISCSI_LINK_SPEED_100MBPS;
  630. break;
  631. case BE2ISCSI_LINK_SPEED_1GBPS:
  632. ihost->port_speed = ISCSI_PORT_SPEED_1GBPS;
  633. break;
  634. case BE2ISCSI_LINK_SPEED_10GBPS:
  635. ihost->port_speed = ISCSI_PORT_SPEED_10GBPS;
  636. break;
  637. default:
  638. ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN;
  639. }
  640. return 0;
  641. }
  642. /**
  643. * beiscsi_get_host_param - get the iscsi parameter
  644. * @shost: pointer to scsi_host structure
  645. * @param: parameter type identifier
  646. * @buf: buffer pointer
  647. *
  648. * returns host parameter
  649. */
  650. int beiscsi_get_host_param(struct Scsi_Host *shost,
  651. enum iscsi_host_param param, char *buf)
  652. {
  653. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  654. int status = 0;
  655. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  656. "BS_%d : In beiscsi_get_host_param,"
  657. " param= %d\n", param);
  658. switch (param) {
  659. case ISCSI_HOST_PARAM_HWADDRESS:
  660. status = beiscsi_get_macaddr(buf, phba);
  661. if (status < 0) {
  662. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  663. "BS_%d : beiscsi_get_macaddr Failed\n");
  664. return status;
  665. }
  666. break;
  667. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  668. status = beiscsi_get_initname(buf, phba);
  669. if (status < 0) {
  670. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  671. "BS_%d : Retreiving Initiator Name Failed\n");
  672. return status;
  673. }
  674. break;
  675. case ISCSI_HOST_PARAM_PORT_STATE:
  676. beiscsi_get_port_state(shost);
  677. status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  678. break;
  679. case ISCSI_HOST_PARAM_PORT_SPEED:
  680. status = beiscsi_get_port_speed(shost);
  681. if (status) {
  682. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  683. "BS_%d : Retreiving Port Speed Failed\n");
  684. return status;
  685. }
  686. status = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  687. break;
  688. default:
  689. return iscsi_host_get_param(shost, param, buf);
  690. }
  691. return status;
  692. }
  693. int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
  694. {
  695. struct be_cmd_get_nic_conf_resp resp;
  696. int rc;
  697. if (strlen(phba->mac_address))
  698. return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
  699. memset(&resp, 0, sizeof(resp));
  700. rc = mgmt_get_nic_conf(phba, &resp);
  701. if (rc)
  702. return rc;
  703. memcpy(phba->mac_address, resp.mac_address, ETH_ALEN);
  704. return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
  705. }
  706. /**
  707. * beiscsi_conn_get_stats - get the iscsi stats
  708. * @cls_conn: pointer to iscsi cls conn
  709. * @stats: pointer to iscsi_stats structure
  710. *
  711. * returns iscsi stats
  712. */
  713. void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  714. struct iscsi_stats *stats)
  715. {
  716. struct iscsi_conn *conn = cls_conn->dd_data;
  717. struct beiscsi_hba *phba = NULL;
  718. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  719. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  720. "BS_%d : In beiscsi_conn_get_stats\n");
  721. stats->txdata_octets = conn->txdata_octets;
  722. stats->rxdata_octets = conn->rxdata_octets;
  723. stats->dataout_pdus = conn->dataout_pdus_cnt;
  724. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  725. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  726. stats->datain_pdus = conn->datain_pdus_cnt;
  727. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  728. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  729. stats->r2t_pdus = conn->r2t_pdus_cnt;
  730. stats->digest_err = 0;
  731. stats->timeout_err = 0;
  732. stats->custom_length = 0;
  733. strcpy(stats->custom[0].desc, "eh_abort_cnt");
  734. stats->custom[0].value = conn->eh_abort_cnt;
  735. }
  736. /**
  737. * beiscsi_set_params_for_offld - get the parameters for offload
  738. * @beiscsi_conn: pointer to beiscsi_conn
  739. * @params: pointer to offload_params structure
  740. */
  741. static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
  742. struct beiscsi_offload_params *params)
  743. {
  744. struct iscsi_conn *conn = beiscsi_conn->conn;
  745. struct iscsi_session *session = conn->session;
  746. AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
  747. params, session->max_burst);
  748. AMAP_SET_BITS(struct amap_beiscsi_offload_params,
  749. max_send_data_segment_length, params,
  750. conn->max_xmit_dlength);
  751. AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
  752. params, session->first_burst);
  753. AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
  754. session->erl);
  755. AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
  756. conn->datadgst_en);
  757. AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
  758. conn->hdrdgst_en);
  759. AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
  760. session->initial_r2t_en);
  761. AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
  762. session->imm_data_en);
  763. AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
  764. (conn->exp_statsn - 1));
  765. }
  766. /**
  767. * beiscsi_conn_start - offload of session to chip
  768. * @cls_conn: pointer to beiscsi_conn
  769. */
  770. int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
  771. {
  772. struct iscsi_conn *conn = cls_conn->dd_data;
  773. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  774. struct beiscsi_endpoint *beiscsi_ep;
  775. struct beiscsi_offload_params params;
  776. beiscsi_log(beiscsi_conn->phba, KERN_INFO,
  777. BEISCSI_LOG_CONFIG,
  778. "BS_%d : In beiscsi_conn_start\n");
  779. memset(&params, 0, sizeof(struct beiscsi_offload_params));
  780. beiscsi_ep = beiscsi_conn->ep;
  781. if (!beiscsi_ep)
  782. beiscsi_log(beiscsi_conn->phba, KERN_ERR,
  783. BEISCSI_LOG_CONFIG,
  784. "BS_%d : In beiscsi_conn_start , no beiscsi_ep\n");
  785. beiscsi_conn->login_in_progress = 0;
  786. beiscsi_set_params_for_offld(beiscsi_conn, &params);
  787. beiscsi_offload_connection(beiscsi_conn, &params);
  788. iscsi_conn_start(cls_conn);
  789. return 0;
  790. }
  791. /**
  792. * beiscsi_get_cid - Allocate a cid
  793. * @phba: The phba instance
  794. */
  795. static int beiscsi_get_cid(struct beiscsi_hba *phba)
  796. {
  797. unsigned short cid = 0xFFFF;
  798. if (!phba->avlbl_cids)
  799. return cid;
  800. cid = phba->cid_array[phba->cid_alloc++];
  801. if (phba->cid_alloc == phba->params.cxns_per_ctrl)
  802. phba->cid_alloc = 0;
  803. phba->avlbl_cids--;
  804. return cid;
  805. }
  806. /**
  807. * beiscsi_put_cid - Free the cid
  808. * @phba: The phba for which the cid is being freed
  809. * @cid: The cid to free
  810. */
  811. static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
  812. {
  813. phba->avlbl_cids++;
  814. phba->cid_array[phba->cid_free++] = cid;
  815. if (phba->cid_free == phba->params.cxns_per_ctrl)
  816. phba->cid_free = 0;
  817. }
  818. /**
  819. * beiscsi_free_ep - free endpoint
  820. * @ep: pointer to iscsi endpoint structure
  821. */
  822. static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
  823. {
  824. struct beiscsi_hba *phba = beiscsi_ep->phba;
  825. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  826. beiscsi_ep->phba = NULL;
  827. }
  828. /**
  829. * beiscsi_open_conn - Ask FW to open a TCP connection
  830. * @ep: endpoint to be used
  831. * @src_addr: The source IP address
  832. * @dst_addr: The Destination IP address
  833. *
  834. * Asks the FW to open a TCP connection
  835. */
  836. static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  837. struct sockaddr *src_addr,
  838. struct sockaddr *dst_addr, int non_blocking)
  839. {
  840. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  841. struct beiscsi_hba *phba = beiscsi_ep->phba;
  842. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  843. struct be_mcc_wrb *wrb;
  844. struct tcp_connect_and_offload_out *ptcpcnct_out;
  845. unsigned short status, extd_status;
  846. struct be_dma_mem nonemb_cmd;
  847. unsigned int tag, wrb_num;
  848. int ret = -ENOMEM;
  849. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  850. "BS_%d : In beiscsi_open_conn\n");
  851. beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
  852. if (beiscsi_ep->ep_cid == 0xFFFF) {
  853. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  854. "BS_%d : No free cid available\n");
  855. return ret;
  856. }
  857. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  858. "BS_%d : In beiscsi_open_conn, ep_cid=%d\n",
  859. beiscsi_ep->ep_cid);
  860. phba->ep_array[beiscsi_ep->ep_cid -
  861. phba->fw_config.iscsi_cid_start] = ep;
  862. if (beiscsi_ep->ep_cid > (phba->fw_config.iscsi_cid_start +
  863. phba->params.cxns_per_ctrl * 2)) {
  864. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  865. "BS_%d : Failed in allocate iscsi cid\n");
  866. goto free_ep;
  867. }
  868. beiscsi_ep->cid_vld = 0;
  869. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  870. sizeof(struct tcp_connect_and_offload_in),
  871. &nonemb_cmd.dma);
  872. if (nonemb_cmd.va == NULL) {
  873. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  874. "BS_%d : Failed to allocate memory for"
  875. " mgmt_open_connection\n");
  876. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  877. return -ENOMEM;
  878. }
  879. nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
  880. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  881. tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
  882. if (!tag) {
  883. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  884. "BS_%d : mgmt_open_connection Failed for cid=%d\n",
  885. beiscsi_ep->ep_cid);
  886. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  887. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  888. nonemb_cmd.va, nonemb_cmd.dma);
  889. return -EAGAIN;
  890. } else {
  891. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  892. phba->ctrl.mcc_numtag[tag]);
  893. }
  894. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  895. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  896. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  897. if (status || extd_status) {
  898. beiscsi_log(phba, KERN_ERR,
  899. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  900. "BS_%d : mgmt_open_connection Failed"
  901. " status = %d extd_status = %d\n",
  902. status, extd_status);
  903. free_mcc_tag(&phba->ctrl, tag);
  904. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  905. nonemb_cmd.va, nonemb_cmd.dma);
  906. goto free_ep;
  907. } else {
  908. wrb = queue_get_wrb(mccq, wrb_num);
  909. free_mcc_tag(&phba->ctrl, tag);
  910. ptcpcnct_out = embedded_payload(wrb);
  911. beiscsi_ep = ep->dd_data;
  912. beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
  913. beiscsi_ep->cid_vld = 1;
  914. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  915. "BS_%d : mgmt_open_connection Success\n");
  916. }
  917. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  918. nonemb_cmd.va, nonemb_cmd.dma);
  919. return 0;
  920. free_ep:
  921. beiscsi_free_ep(beiscsi_ep);
  922. return -EBUSY;
  923. }
  924. /**
  925. * beiscsi_ep_connect - Ask chip to create TCP Conn
  926. * @scsi_host: Pointer to scsi_host structure
  927. * @dst_addr: The IP address of Target
  928. * @non_blocking: blocking or non-blocking call
  929. *
  930. * This routines first asks chip to create a connection and then allocates an EP
  931. */
  932. struct iscsi_endpoint *
  933. beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  934. int non_blocking)
  935. {
  936. struct beiscsi_hba *phba;
  937. struct beiscsi_endpoint *beiscsi_ep;
  938. struct iscsi_endpoint *ep;
  939. int ret;
  940. if (shost)
  941. phba = iscsi_host_priv(shost);
  942. else {
  943. ret = -ENXIO;
  944. printk(KERN_ERR
  945. "beiscsi_ep_connect shost is NULL\n");
  946. return ERR_PTR(ret);
  947. }
  948. if (phba->state != BE_ADAPTER_UP) {
  949. ret = -EBUSY;
  950. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  951. "BS_%d : The Adapter state is Not UP\n");
  952. return ERR_PTR(ret);
  953. }
  954. ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
  955. if (!ep) {
  956. ret = -ENOMEM;
  957. return ERR_PTR(ret);
  958. }
  959. beiscsi_ep = ep->dd_data;
  960. beiscsi_ep->phba = phba;
  961. beiscsi_ep->openiscsi_ep = ep;
  962. ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
  963. if (ret) {
  964. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  965. "BS_%d : Failed in beiscsi_open_conn\n");
  966. goto free_ep;
  967. }
  968. return ep;
  969. free_ep:
  970. iscsi_destroy_endpoint(ep);
  971. return ERR_PTR(ret);
  972. }
  973. /**
  974. * beiscsi_ep_poll - Poll to see if connection is established
  975. * @ep: endpoint to be used
  976. * @timeout_ms: timeout specified in millisecs
  977. *
  978. * Poll to see if TCP connection established
  979. */
  980. int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  981. {
  982. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  983. beiscsi_log(beiscsi_ep->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  984. "BS_%d : In beiscsi_ep_poll\n");
  985. if (beiscsi_ep->cid_vld == 1)
  986. return 1;
  987. else
  988. return 0;
  989. }
  990. /**
  991. * beiscsi_close_conn - Upload the connection
  992. * @ep: The iscsi endpoint
  993. * @flag: The type of connection closure
  994. */
  995. static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
  996. {
  997. int ret = 0;
  998. unsigned int tag;
  999. struct beiscsi_hba *phba = beiscsi_ep->phba;
  1000. tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
  1001. if (!tag) {
  1002. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1003. "BS_%d : upload failed for cid 0x%x\n",
  1004. beiscsi_ep->ep_cid);
  1005. ret = -EAGAIN;
  1006. } else {
  1007. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  1008. phba->ctrl.mcc_numtag[tag]);
  1009. free_mcc_tag(&phba->ctrl, tag);
  1010. }
  1011. return ret;
  1012. }
  1013. /**
  1014. * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
  1015. * @phba: The phba instance
  1016. * @cid: The cid to free
  1017. */
  1018. static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
  1019. unsigned int cid)
  1020. {
  1021. if (phba->conn_table[cid])
  1022. phba->conn_table[cid] = NULL;
  1023. else {
  1024. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1025. "BS_%d : Connection table Not occupied.\n");
  1026. return -EINVAL;
  1027. }
  1028. return 0;
  1029. }
  1030. /**
  1031. * beiscsi_ep_disconnect - Tears down the TCP connection
  1032. * @ep: endpoint to be used
  1033. *
  1034. * Tears down the TCP connection
  1035. */
  1036. void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
  1037. {
  1038. struct beiscsi_conn *beiscsi_conn;
  1039. struct beiscsi_endpoint *beiscsi_ep;
  1040. struct beiscsi_hba *phba;
  1041. unsigned int tag;
  1042. unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
  1043. beiscsi_ep = ep->dd_data;
  1044. phba = beiscsi_ep->phba;
  1045. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1046. "BS_%d : In beiscsi_ep_disconnect for ep_cid = %d\n",
  1047. beiscsi_ep->ep_cid);
  1048. if (!beiscsi_ep->conn) {
  1049. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1050. "BS_%d : In beiscsi_ep_disconnect, no "
  1051. "beiscsi_ep\n");
  1052. return;
  1053. }
  1054. beiscsi_conn = beiscsi_ep->conn;
  1055. iscsi_suspend_queue(beiscsi_conn->conn);
  1056. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1057. "BS_%d : In beiscsi_ep_disconnect ep_cid = %d\n",
  1058. beiscsi_ep->ep_cid);
  1059. tag = mgmt_invalidate_connection(phba, beiscsi_ep,
  1060. beiscsi_ep->ep_cid, 1,
  1061. savecfg_flag);
  1062. if (!tag) {
  1063. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1064. "BS_%d : mgmt_invalidate_connection"
  1065. " Failed for cid=%d\n",
  1066. beiscsi_ep->ep_cid);
  1067. } else {
  1068. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  1069. phba->ctrl.mcc_numtag[tag]);
  1070. free_mcc_tag(&phba->ctrl, tag);
  1071. }
  1072. beiscsi_close_conn(beiscsi_ep, CONNECTION_UPLOAD_GRACEFUL);
  1073. beiscsi_free_ep(beiscsi_ep);
  1074. beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
  1075. iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
  1076. }
  1077. umode_t be2iscsi_attr_is_visible(int param_type, int param)
  1078. {
  1079. switch (param_type) {
  1080. case ISCSI_NET_PARAM:
  1081. switch (param) {
  1082. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1083. case ISCSI_NET_PARAM_IPV4_ADDR:
  1084. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1085. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1086. case ISCSI_NET_PARAM_IPV4_GW:
  1087. case ISCSI_NET_PARAM_IPV6_ADDR:
  1088. return S_IRUGO;
  1089. default:
  1090. return 0;
  1091. }
  1092. case ISCSI_HOST_PARAM:
  1093. switch (param) {
  1094. case ISCSI_HOST_PARAM_HWADDRESS:
  1095. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  1096. case ISCSI_HOST_PARAM_PORT_STATE:
  1097. case ISCSI_HOST_PARAM_PORT_SPEED:
  1098. return S_IRUGO;
  1099. default:
  1100. return 0;
  1101. }
  1102. case ISCSI_PARAM:
  1103. switch (param) {
  1104. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  1105. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  1106. case ISCSI_PARAM_HDRDGST_EN:
  1107. case ISCSI_PARAM_DATADGST_EN:
  1108. case ISCSI_PARAM_CONN_ADDRESS:
  1109. case ISCSI_PARAM_CONN_PORT:
  1110. case ISCSI_PARAM_EXP_STATSN:
  1111. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  1112. case ISCSI_PARAM_PERSISTENT_PORT:
  1113. case ISCSI_PARAM_PING_TMO:
  1114. case ISCSI_PARAM_RECV_TMO:
  1115. case ISCSI_PARAM_INITIAL_R2T_EN:
  1116. case ISCSI_PARAM_MAX_R2T:
  1117. case ISCSI_PARAM_IMM_DATA_EN:
  1118. case ISCSI_PARAM_FIRST_BURST:
  1119. case ISCSI_PARAM_MAX_BURST:
  1120. case ISCSI_PARAM_PDU_INORDER_EN:
  1121. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  1122. case ISCSI_PARAM_ERL:
  1123. case ISCSI_PARAM_TARGET_NAME:
  1124. case ISCSI_PARAM_TPGT:
  1125. case ISCSI_PARAM_USERNAME:
  1126. case ISCSI_PARAM_PASSWORD:
  1127. case ISCSI_PARAM_USERNAME_IN:
  1128. case ISCSI_PARAM_PASSWORD_IN:
  1129. case ISCSI_PARAM_FAST_ABORT:
  1130. case ISCSI_PARAM_ABORT_TMO:
  1131. case ISCSI_PARAM_LU_RESET_TMO:
  1132. case ISCSI_PARAM_IFACE_NAME:
  1133. case ISCSI_PARAM_INITIATOR_NAME:
  1134. return S_IRUGO;
  1135. default:
  1136. return 0;
  1137. }
  1138. }
  1139. return 0;
  1140. }