be_iscsi.c 39 KB

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