be_iscsi.c 38 KB

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