be_iscsi.c 39 KB

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