be_iscsi.c 38 KB

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