be_iscsi.c 35 KB

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