be_iscsi.c 32 KB

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