be_iscsi.c 38 KB

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