be_iscsi.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436
  1. /**
  2. * Copyright (C) 2005 - 2013 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@emulex.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@emulex.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. kfree(if_info);
  475. return len;
  476. }
  477. switch (param) {
  478. case ISCSI_NET_PARAM_IPV4_ADDR:
  479. len = sprintf(buf, "%pI4\n", if_info->ip_addr.addr);
  480. break;
  481. case ISCSI_NET_PARAM_IPV6_ADDR:
  482. len = sprintf(buf, "%pI6\n", if_info->ip_addr.addr);
  483. break;
  484. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  485. if (!if_info->dhcp_state)
  486. len = sprintf(buf, "static\n");
  487. else
  488. len = sprintf(buf, "dhcp\n");
  489. break;
  490. case ISCSI_NET_PARAM_IPV4_SUBNET:
  491. len = sprintf(buf, "%pI4\n", if_info->ip_addr.subnet_mask);
  492. break;
  493. case ISCSI_NET_PARAM_VLAN_ENABLED:
  494. len = sprintf(buf, "%s\n",
  495. (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
  496. ? "Disabled\n" : "Enabled\n");
  497. break;
  498. case ISCSI_NET_PARAM_VLAN_ID:
  499. if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
  500. return -EINVAL;
  501. else
  502. len = sprintf(buf, "%d\n",
  503. (if_info->vlan_priority &
  504. ISCSI_MAX_VLAN_ID));
  505. break;
  506. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  507. if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
  508. return -EINVAL;
  509. else
  510. len = sprintf(buf, "%d\n",
  511. ((if_info->vlan_priority >> 13) &
  512. ISCSI_MAX_VLAN_PRIORITY));
  513. break;
  514. default:
  515. WARN_ON(1);
  516. }
  517. kfree(if_info);
  518. return len;
  519. }
  520. int be2iscsi_iface_get_param(struct iscsi_iface *iface,
  521. enum iscsi_param_type param_type,
  522. int param, char *buf)
  523. {
  524. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  525. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  526. struct be_cmd_get_def_gateway_resp gateway;
  527. int len = -ENOSYS;
  528. if (phba->state & BE_ADAPTER_PCI_ERR) {
  529. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  530. "BS_%d : In PCI_ERROR Recovery\n");
  531. return -EBUSY;
  532. }
  533. switch (param) {
  534. case ISCSI_NET_PARAM_IPV4_ADDR:
  535. case ISCSI_NET_PARAM_IPV4_SUBNET:
  536. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  537. case ISCSI_NET_PARAM_IPV6_ADDR:
  538. case ISCSI_NET_PARAM_VLAN_ENABLED:
  539. case ISCSI_NET_PARAM_VLAN_ID:
  540. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  541. len = be2iscsi_get_if_param(phba, iface, param, buf);
  542. break;
  543. case ISCSI_NET_PARAM_IFACE_ENABLE:
  544. len = sprintf(buf, "enabled\n");
  545. break;
  546. case ISCSI_NET_PARAM_IPV4_GW:
  547. memset(&gateway, 0, sizeof(gateway));
  548. len = mgmt_get_gateway(phba, BE2_IPV4, &gateway);
  549. if (!len)
  550. len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
  551. break;
  552. default:
  553. len = -ENOSYS;
  554. }
  555. return len;
  556. }
  557. /**
  558. * beiscsi_ep_get_param - get the iscsi parameter
  559. * @ep: pointer to iscsi ep
  560. * @param: parameter type identifier
  561. * @buf: buffer pointer
  562. *
  563. * returns iscsi parameter
  564. */
  565. int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
  566. enum iscsi_param param, char *buf)
  567. {
  568. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  569. int len = 0;
  570. beiscsi_log(beiscsi_ep->phba, KERN_INFO,
  571. BEISCSI_LOG_CONFIG,
  572. "BS_%d : In beiscsi_ep_get_param,"
  573. " param= %d\n", param);
  574. switch (param) {
  575. case ISCSI_PARAM_CONN_PORT:
  576. len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
  577. break;
  578. case ISCSI_PARAM_CONN_ADDRESS:
  579. if (beiscsi_ep->ip_type == BE2_IPV4)
  580. len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
  581. else
  582. len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
  583. break;
  584. default:
  585. return -ENOSYS;
  586. }
  587. return len;
  588. }
  589. int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
  590. enum iscsi_param param, char *buf, int buflen)
  591. {
  592. struct iscsi_conn *conn = cls_conn->dd_data;
  593. struct iscsi_session *session = conn->session;
  594. struct beiscsi_hba *phba = NULL;
  595. int ret;
  596. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  597. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  598. "BS_%d : In beiscsi_conn_set_param,"
  599. " param= %d\n", param);
  600. ret = iscsi_set_param(cls_conn, param, buf, buflen);
  601. if (ret)
  602. return ret;
  603. /*
  604. * If userspace tried to set the value to higher than we can
  605. * support override here.
  606. */
  607. switch (param) {
  608. case ISCSI_PARAM_FIRST_BURST:
  609. if (session->first_burst > 8192)
  610. session->first_burst = 8192;
  611. break;
  612. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  613. if (conn->max_recv_dlength > 65536)
  614. conn->max_recv_dlength = 65536;
  615. break;
  616. case ISCSI_PARAM_MAX_BURST:
  617. if (session->max_burst > 262144)
  618. session->max_burst = 262144;
  619. break;
  620. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  621. if (conn->max_xmit_dlength > 65536)
  622. conn->max_xmit_dlength = 65536;
  623. default:
  624. return 0;
  625. }
  626. return 0;
  627. }
  628. /**
  629. * beiscsi_get_initname - Read Initiator Name from flash
  630. * @buf: buffer bointer
  631. * @phba: The device priv structure instance
  632. *
  633. * returns number of bytes
  634. */
  635. static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
  636. {
  637. int rc;
  638. unsigned int tag;
  639. struct be_mcc_wrb *wrb;
  640. struct be_cmd_hba_name *resp;
  641. tag = be_cmd_get_initname(phba);
  642. if (!tag) {
  643. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  644. "BS_%d : Getting Initiator Name Failed\n");
  645. return -EBUSY;
  646. }
  647. rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
  648. if (rc) {
  649. beiscsi_log(phba, KERN_ERR,
  650. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  651. "BS_%d : Initiator Name MBX Failed\n");
  652. return rc;
  653. }
  654. resp = embedded_payload(wrb);
  655. rc = sprintf(buf, "%s\n", resp->initiator_name);
  656. return rc;
  657. }
  658. /**
  659. * beiscsi_get_port_state - Get the Port State
  660. * @shost : pointer to scsi_host structure
  661. *
  662. */
  663. static void beiscsi_get_port_state(struct Scsi_Host *shost)
  664. {
  665. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  666. struct iscsi_cls_host *ihost = shost->shost_data;
  667. ihost->port_state = (phba->state == BE_ADAPTER_LINK_UP) ?
  668. ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN;
  669. }
  670. /**
  671. * beiscsi_get_port_speed - Get the Port Speed from Adapter
  672. * @shost : pointer to scsi_host structure
  673. *
  674. * returns Success/Failure
  675. */
  676. static int beiscsi_get_port_speed(struct Scsi_Host *shost)
  677. {
  678. int rc;
  679. unsigned int tag;
  680. struct be_mcc_wrb *wrb;
  681. struct be_cmd_ntwk_link_status_resp *resp;
  682. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  683. struct iscsi_cls_host *ihost = shost->shost_data;
  684. tag = be_cmd_get_port_speed(phba);
  685. if (!tag) {
  686. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  687. "BS_%d : Getting Port Speed Failed\n");
  688. return -EBUSY;
  689. }
  690. rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
  691. if (rc) {
  692. beiscsi_log(phba, KERN_ERR,
  693. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  694. "BS_%d : Port Speed MBX Failed\n");
  695. return rc;
  696. }
  697. resp = embedded_payload(wrb);
  698. switch (resp->mac_speed) {
  699. case BE2ISCSI_LINK_SPEED_10MBPS:
  700. ihost->port_speed = ISCSI_PORT_SPEED_10MBPS;
  701. break;
  702. case BE2ISCSI_LINK_SPEED_100MBPS:
  703. ihost->port_speed = BE2ISCSI_LINK_SPEED_100MBPS;
  704. break;
  705. case BE2ISCSI_LINK_SPEED_1GBPS:
  706. ihost->port_speed = ISCSI_PORT_SPEED_1GBPS;
  707. break;
  708. case BE2ISCSI_LINK_SPEED_10GBPS:
  709. ihost->port_speed = ISCSI_PORT_SPEED_10GBPS;
  710. break;
  711. default:
  712. ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN;
  713. }
  714. return 0;
  715. }
  716. /**
  717. * beiscsi_get_host_param - get the iscsi parameter
  718. * @shost: pointer to scsi_host structure
  719. * @param: parameter type identifier
  720. * @buf: buffer pointer
  721. *
  722. * returns host parameter
  723. */
  724. int beiscsi_get_host_param(struct Scsi_Host *shost,
  725. enum iscsi_host_param param, char *buf)
  726. {
  727. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  728. int status = 0;
  729. if (phba->state & BE_ADAPTER_PCI_ERR) {
  730. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  731. "BS_%d : In PCI_ERROR Recovery\n");
  732. return -EBUSY;
  733. } else {
  734. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  735. "BS_%d : In beiscsi_get_host_param,"
  736. " param = %d\n", param);
  737. }
  738. switch (param) {
  739. case ISCSI_HOST_PARAM_HWADDRESS:
  740. status = beiscsi_get_macaddr(buf, phba);
  741. if (status < 0) {
  742. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  743. "BS_%d : beiscsi_get_macaddr Failed\n");
  744. return status;
  745. }
  746. break;
  747. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  748. status = beiscsi_get_initname(buf, phba);
  749. if (status < 0) {
  750. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  751. "BS_%d : Retreiving Initiator Name Failed\n");
  752. return status;
  753. }
  754. break;
  755. case ISCSI_HOST_PARAM_PORT_STATE:
  756. beiscsi_get_port_state(shost);
  757. status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  758. break;
  759. case ISCSI_HOST_PARAM_PORT_SPEED:
  760. status = beiscsi_get_port_speed(shost);
  761. if (status) {
  762. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  763. "BS_%d : Retreiving Port Speed Failed\n");
  764. return status;
  765. }
  766. status = sprintf(buf, "%s\n", iscsi_get_port_speed_name(shost));
  767. break;
  768. default:
  769. return iscsi_host_get_param(shost, param, buf);
  770. }
  771. return status;
  772. }
  773. int beiscsi_get_macaddr(char *buf, struct beiscsi_hba *phba)
  774. {
  775. struct be_cmd_get_nic_conf_resp resp;
  776. int rc;
  777. if (phba->mac_addr_set)
  778. return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
  779. memset(&resp, 0, sizeof(resp));
  780. rc = mgmt_get_nic_conf(phba, &resp);
  781. if (rc)
  782. return rc;
  783. phba->mac_addr_set = true;
  784. memcpy(phba->mac_address, resp.mac_address, ETH_ALEN);
  785. return sysfs_format_mac(buf, phba->mac_address, ETH_ALEN);
  786. }
  787. /**
  788. * beiscsi_conn_get_stats - get the iscsi stats
  789. * @cls_conn: pointer to iscsi cls conn
  790. * @stats: pointer to iscsi_stats structure
  791. *
  792. * returns iscsi stats
  793. */
  794. void beiscsi_conn_get_stats(struct iscsi_cls_conn *cls_conn,
  795. struct iscsi_stats *stats)
  796. {
  797. struct iscsi_conn *conn = cls_conn->dd_data;
  798. struct beiscsi_hba *phba = NULL;
  799. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  800. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  801. "BS_%d : In beiscsi_conn_get_stats\n");
  802. stats->txdata_octets = conn->txdata_octets;
  803. stats->rxdata_octets = conn->rxdata_octets;
  804. stats->dataout_pdus = conn->dataout_pdus_cnt;
  805. stats->scsirsp_pdus = conn->scsirsp_pdus_cnt;
  806. stats->scsicmd_pdus = conn->scsicmd_pdus_cnt;
  807. stats->datain_pdus = conn->datain_pdus_cnt;
  808. stats->tmfrsp_pdus = conn->tmfrsp_pdus_cnt;
  809. stats->tmfcmd_pdus = conn->tmfcmd_pdus_cnt;
  810. stats->r2t_pdus = conn->r2t_pdus_cnt;
  811. stats->digest_err = 0;
  812. stats->timeout_err = 0;
  813. stats->custom_length = 0;
  814. strcpy(stats->custom[0].desc, "eh_abort_cnt");
  815. stats->custom[0].value = conn->eh_abort_cnt;
  816. }
  817. /**
  818. * beiscsi_set_params_for_offld - get the parameters for offload
  819. * @beiscsi_conn: pointer to beiscsi_conn
  820. * @params: pointer to offload_params structure
  821. */
  822. static void beiscsi_set_params_for_offld(struct beiscsi_conn *beiscsi_conn,
  823. struct beiscsi_offload_params *params)
  824. {
  825. struct iscsi_conn *conn = beiscsi_conn->conn;
  826. struct iscsi_session *session = conn->session;
  827. AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_burst_length,
  828. params, session->max_burst);
  829. AMAP_SET_BITS(struct amap_beiscsi_offload_params,
  830. max_send_data_segment_length, params,
  831. conn->max_xmit_dlength);
  832. AMAP_SET_BITS(struct amap_beiscsi_offload_params, first_burst_length,
  833. params, session->first_burst);
  834. AMAP_SET_BITS(struct amap_beiscsi_offload_params, erl, params,
  835. session->erl);
  836. AMAP_SET_BITS(struct amap_beiscsi_offload_params, dde, params,
  837. conn->datadgst_en);
  838. AMAP_SET_BITS(struct amap_beiscsi_offload_params, hde, params,
  839. conn->hdrdgst_en);
  840. AMAP_SET_BITS(struct amap_beiscsi_offload_params, ir2t, params,
  841. session->initial_r2t_en);
  842. AMAP_SET_BITS(struct amap_beiscsi_offload_params, imd, params,
  843. session->imm_data_en);
  844. AMAP_SET_BITS(struct amap_beiscsi_offload_params,
  845. data_seq_inorder, params,
  846. session->dataseq_inorder_en);
  847. AMAP_SET_BITS(struct amap_beiscsi_offload_params,
  848. pdu_seq_inorder, params,
  849. session->pdu_inorder_en);
  850. AMAP_SET_BITS(struct amap_beiscsi_offload_params, max_r2t, params,
  851. session->max_r2t);
  852. AMAP_SET_BITS(struct amap_beiscsi_offload_params, exp_statsn, params,
  853. (conn->exp_statsn - 1));
  854. AMAP_SET_BITS(struct amap_beiscsi_offload_params,
  855. max_recv_data_segment_length, params,
  856. conn->max_recv_dlength);
  857. }
  858. /**
  859. * beiscsi_conn_start - offload of session to chip
  860. * @cls_conn: pointer to beiscsi_conn
  861. */
  862. int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
  863. {
  864. struct iscsi_conn *conn = cls_conn->dd_data;
  865. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  866. struct beiscsi_endpoint *beiscsi_ep;
  867. struct beiscsi_offload_params params;
  868. struct beiscsi_hba *phba;
  869. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  870. if (phba->state & BE_ADAPTER_PCI_ERR) {
  871. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  872. "BS_%d : In PCI_ERROR Recovery\n");
  873. return -EBUSY;
  874. } else {
  875. beiscsi_log(beiscsi_conn->phba, KERN_INFO,
  876. BEISCSI_LOG_CONFIG,
  877. "BS_%d : In beiscsi_conn_start\n");
  878. }
  879. memset(&params, 0, sizeof(struct beiscsi_offload_params));
  880. beiscsi_ep = beiscsi_conn->ep;
  881. if (!beiscsi_ep)
  882. beiscsi_log(beiscsi_conn->phba, KERN_ERR,
  883. BEISCSI_LOG_CONFIG,
  884. "BS_%d : In beiscsi_conn_start , no beiscsi_ep\n");
  885. beiscsi_conn->login_in_progress = 0;
  886. beiscsi_set_params_for_offld(beiscsi_conn, &params);
  887. beiscsi_offload_connection(beiscsi_conn, &params);
  888. iscsi_conn_start(cls_conn);
  889. return 0;
  890. }
  891. /**
  892. * beiscsi_get_cid - Allocate a cid
  893. * @phba: The phba instance
  894. */
  895. static int beiscsi_get_cid(struct beiscsi_hba *phba)
  896. {
  897. unsigned short cid = 0xFFFF, cid_from_ulp;
  898. struct ulp_cid_info *cid_info = NULL;
  899. uint16_t cid_avlbl_ulp0, cid_avlbl_ulp1;
  900. /* Find the ULP which has more CID available */
  901. cid_avlbl_ulp0 = (phba->cid_array_info[BEISCSI_ULP0]) ?
  902. BEISCSI_ULP0_AVLBL_CID(phba) : 0;
  903. cid_avlbl_ulp1 = (phba->cid_array_info[BEISCSI_ULP1]) ?
  904. BEISCSI_ULP1_AVLBL_CID(phba) : 0;
  905. cid_from_ulp = (cid_avlbl_ulp0 > cid_avlbl_ulp1) ?
  906. BEISCSI_ULP0 : BEISCSI_ULP1;
  907. if (test_bit(cid_from_ulp, (void *)&phba->fw_config.ulp_supported)) {
  908. cid_info = phba->cid_array_info[cid_from_ulp];
  909. if (!cid_info->avlbl_cids)
  910. return cid;
  911. cid = cid_info->cid_array[cid_info->cid_alloc++];
  912. if (cid_info->cid_alloc == BEISCSI_GET_CID_COUNT(
  913. phba, cid_from_ulp))
  914. cid_info->cid_alloc = 0;
  915. cid_info->avlbl_cids--;
  916. }
  917. return cid;
  918. }
  919. /**
  920. * beiscsi_put_cid - Free the cid
  921. * @phba: The phba for which the cid is being freed
  922. * @cid: The cid to free
  923. */
  924. static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
  925. {
  926. uint16_t cid_post_ulp;
  927. struct hwi_controller *phwi_ctrlr;
  928. struct hwi_wrb_context *pwrb_context;
  929. struct ulp_cid_info *cid_info = NULL;
  930. uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
  931. phwi_ctrlr = phba->phwi_ctrlr;
  932. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  933. cid_post_ulp = pwrb_context->ulp_num;
  934. cid_info = phba->cid_array_info[cid_post_ulp];
  935. cid_info->avlbl_cids++;
  936. cid_info->cid_array[cid_info->cid_free++] = cid;
  937. if (cid_info->cid_free == BEISCSI_GET_CID_COUNT(phba, cid_post_ulp))
  938. cid_info->cid_free = 0;
  939. }
  940. /**
  941. * beiscsi_free_ep - free endpoint
  942. * @ep: pointer to iscsi endpoint structure
  943. */
  944. static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
  945. {
  946. struct beiscsi_hba *phba = beiscsi_ep->phba;
  947. struct beiscsi_conn *beiscsi_conn;
  948. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  949. beiscsi_ep->phba = NULL;
  950. phba->ep_array[BE_GET_CRI_FROM_CID
  951. (beiscsi_ep->ep_cid)] = NULL;
  952. /**
  953. * Check if any connection resource allocated by driver
  954. * is to be freed.This case occurs when target redirection
  955. * or connection retry is done.
  956. **/
  957. if (!beiscsi_ep->conn)
  958. return;
  959. beiscsi_conn = beiscsi_ep->conn;
  960. if (beiscsi_conn->login_in_progress) {
  961. beiscsi_free_mgmt_task_handles(beiscsi_conn,
  962. beiscsi_conn->task);
  963. beiscsi_conn->login_in_progress = 0;
  964. }
  965. }
  966. /**
  967. * beiscsi_open_conn - Ask FW to open a TCP connection
  968. * @ep: endpoint to be used
  969. * @src_addr: The source IP address
  970. * @dst_addr: The Destination IP address
  971. *
  972. * Asks the FW to open a TCP connection
  973. */
  974. static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  975. struct sockaddr *src_addr,
  976. struct sockaddr *dst_addr, int non_blocking)
  977. {
  978. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  979. struct beiscsi_hba *phba = beiscsi_ep->phba;
  980. struct tcp_connect_and_offload_out *ptcpcnct_out;
  981. struct be_dma_mem nonemb_cmd;
  982. unsigned int tag;
  983. int ret = -ENOMEM;
  984. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  985. "BS_%d : In beiscsi_open_conn\n");
  986. beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
  987. if (beiscsi_ep->ep_cid == 0xFFFF) {
  988. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  989. "BS_%d : No free cid available\n");
  990. return ret;
  991. }
  992. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  993. "BS_%d : In beiscsi_open_conn, ep_cid=%d\n",
  994. beiscsi_ep->ep_cid);
  995. phba->ep_array[BE_GET_CRI_FROM_CID
  996. (beiscsi_ep->ep_cid)] = ep;
  997. beiscsi_ep->cid_vld = 0;
  998. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  999. sizeof(struct tcp_connect_and_offload_in),
  1000. &nonemb_cmd.dma);
  1001. if (nonemb_cmd.va == NULL) {
  1002. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1003. "BS_%d : Failed to allocate memory for"
  1004. " mgmt_open_connection\n");
  1005. beiscsi_free_ep(beiscsi_ep);
  1006. return -ENOMEM;
  1007. }
  1008. nonemb_cmd.size = sizeof(struct tcp_connect_and_offload_in);
  1009. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  1010. tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
  1011. if (tag <= 0) {
  1012. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1013. "BS_%d : mgmt_open_connection Failed for cid=%d\n",
  1014. beiscsi_ep->ep_cid);
  1015. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  1016. nonemb_cmd.va, nonemb_cmd.dma);
  1017. beiscsi_free_ep(beiscsi_ep);
  1018. return -EAGAIN;
  1019. }
  1020. ret = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd.va);
  1021. if (ret) {
  1022. beiscsi_log(phba, KERN_ERR,
  1023. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  1024. "BS_%d : mgmt_open_connection Failed");
  1025. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  1026. nonemb_cmd.va, nonemb_cmd.dma);
  1027. beiscsi_free_ep(beiscsi_ep);
  1028. return -EBUSY;
  1029. }
  1030. ptcpcnct_out = (struct tcp_connect_and_offload_out *)nonemb_cmd.va;
  1031. beiscsi_ep = ep->dd_data;
  1032. beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
  1033. beiscsi_ep->cid_vld = 1;
  1034. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1035. "BS_%d : mgmt_open_connection Success\n");
  1036. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  1037. nonemb_cmd.va, nonemb_cmd.dma);
  1038. return 0;
  1039. }
  1040. /**
  1041. * beiscsi_ep_connect - Ask chip to create TCP Conn
  1042. * @scsi_host: Pointer to scsi_host structure
  1043. * @dst_addr: The IP address of Target
  1044. * @non_blocking: blocking or non-blocking call
  1045. *
  1046. * This routines first asks chip to create a connection and then allocates an EP
  1047. */
  1048. struct iscsi_endpoint *
  1049. beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  1050. int non_blocking)
  1051. {
  1052. struct beiscsi_hba *phba;
  1053. struct beiscsi_endpoint *beiscsi_ep;
  1054. struct iscsi_endpoint *ep;
  1055. int ret;
  1056. if (shost)
  1057. phba = iscsi_host_priv(shost);
  1058. else {
  1059. ret = -ENXIO;
  1060. printk(KERN_ERR
  1061. "beiscsi_ep_connect shost is NULL\n");
  1062. return ERR_PTR(ret);
  1063. }
  1064. if (beiscsi_error(phba)) {
  1065. ret = -EIO;
  1066. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  1067. "BS_%d : The FW state Not Stable!!!\n");
  1068. return ERR_PTR(ret);
  1069. }
  1070. if (phba->state & BE_ADAPTER_PCI_ERR) {
  1071. ret = -EBUSY;
  1072. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1073. "BS_%d : In PCI_ERROR Recovery\n");
  1074. return ERR_PTR(ret);
  1075. } else if (phba->state & BE_ADAPTER_LINK_DOWN) {
  1076. ret = -EBUSY;
  1077. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  1078. "BS_%d : The Adapter Port state is Down!!!\n");
  1079. return ERR_PTR(ret);
  1080. }
  1081. ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
  1082. if (!ep) {
  1083. ret = -ENOMEM;
  1084. return ERR_PTR(ret);
  1085. }
  1086. beiscsi_ep = ep->dd_data;
  1087. beiscsi_ep->phba = phba;
  1088. beiscsi_ep->openiscsi_ep = ep;
  1089. ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
  1090. if (ret) {
  1091. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1092. "BS_%d : Failed in beiscsi_open_conn\n");
  1093. goto free_ep;
  1094. }
  1095. return ep;
  1096. free_ep:
  1097. iscsi_destroy_endpoint(ep);
  1098. return ERR_PTR(ret);
  1099. }
  1100. /**
  1101. * beiscsi_ep_poll - Poll to see if connection is established
  1102. * @ep: endpoint to be used
  1103. * @timeout_ms: timeout specified in millisecs
  1104. *
  1105. * Poll to see if TCP connection established
  1106. */
  1107. int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  1108. {
  1109. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  1110. beiscsi_log(beiscsi_ep->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1111. "BS_%d : In beiscsi_ep_poll\n");
  1112. if (beiscsi_ep->cid_vld == 1)
  1113. return 1;
  1114. else
  1115. return 0;
  1116. }
  1117. /**
  1118. * beiscsi_close_conn - Upload the connection
  1119. * @ep: The iscsi endpoint
  1120. * @flag: The type of connection closure
  1121. */
  1122. static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
  1123. {
  1124. int ret = 0;
  1125. unsigned int tag;
  1126. struct beiscsi_hba *phba = beiscsi_ep->phba;
  1127. tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
  1128. if (!tag) {
  1129. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1130. "BS_%d : upload failed for cid 0x%x\n",
  1131. beiscsi_ep->ep_cid);
  1132. ret = -EAGAIN;
  1133. }
  1134. ret = beiscsi_mccq_compl(phba, tag, NULL, NULL);
  1135. return ret;
  1136. }
  1137. /**
  1138. * beiscsi_unbind_conn_to_cid - Unbind the beiscsi_conn from phba conn table
  1139. * @phba: The phba instance
  1140. * @cid: The cid to free
  1141. */
  1142. static int beiscsi_unbind_conn_to_cid(struct beiscsi_hba *phba,
  1143. unsigned int cid)
  1144. {
  1145. uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
  1146. if (phba->conn_table[cri_index])
  1147. phba->conn_table[cri_index] = NULL;
  1148. else {
  1149. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1150. "BS_%d : Connection table Not occupied.\n");
  1151. return -EINVAL;
  1152. }
  1153. return 0;
  1154. }
  1155. /**
  1156. * beiscsi_ep_disconnect - Tears down the TCP connection
  1157. * @ep: endpoint to be used
  1158. *
  1159. * Tears down the TCP connection
  1160. */
  1161. void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
  1162. {
  1163. struct beiscsi_conn *beiscsi_conn;
  1164. struct beiscsi_endpoint *beiscsi_ep;
  1165. struct beiscsi_hba *phba;
  1166. unsigned int tag;
  1167. uint8_t mgmt_invalidate_flag, tcp_upload_flag;
  1168. unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
  1169. beiscsi_ep = ep->dd_data;
  1170. phba = beiscsi_ep->phba;
  1171. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1172. "BS_%d : In beiscsi_ep_disconnect for ep_cid = %d\n",
  1173. beiscsi_ep->ep_cid);
  1174. if (beiscsi_ep->conn) {
  1175. beiscsi_conn = beiscsi_ep->conn;
  1176. iscsi_suspend_queue(beiscsi_conn->conn);
  1177. mgmt_invalidate_flag = ~BEISCSI_NO_RST_ISSUE;
  1178. tcp_upload_flag = CONNECTION_UPLOAD_GRACEFUL;
  1179. } else {
  1180. mgmt_invalidate_flag = BEISCSI_NO_RST_ISSUE;
  1181. tcp_upload_flag = CONNECTION_UPLOAD_ABORT;
  1182. }
  1183. if (phba->state & BE_ADAPTER_PCI_ERR) {
  1184. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1185. "BS_%d : PCI_ERROR Recovery\n");
  1186. goto free_ep;
  1187. }
  1188. tag = mgmt_invalidate_connection(phba, beiscsi_ep,
  1189. beiscsi_ep->ep_cid,
  1190. mgmt_invalidate_flag,
  1191. savecfg_flag);
  1192. if (!tag) {
  1193. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1194. "BS_%d : mgmt_invalidate_connection Failed for cid=%d\n",
  1195. beiscsi_ep->ep_cid);
  1196. }
  1197. beiscsi_mccq_compl(phba, tag, NULL, NULL);
  1198. beiscsi_close_conn(beiscsi_ep, tcp_upload_flag);
  1199. free_ep:
  1200. beiscsi_free_ep(beiscsi_ep);
  1201. beiscsi_unbind_conn_to_cid(phba, beiscsi_ep->ep_cid);
  1202. iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
  1203. }
  1204. umode_t be2iscsi_attr_is_visible(int param_type, int param)
  1205. {
  1206. switch (param_type) {
  1207. case ISCSI_NET_PARAM:
  1208. switch (param) {
  1209. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1210. case ISCSI_NET_PARAM_IPV4_ADDR:
  1211. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1212. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1213. case ISCSI_NET_PARAM_IPV4_GW:
  1214. case ISCSI_NET_PARAM_IPV6_ADDR:
  1215. case ISCSI_NET_PARAM_VLAN_ID:
  1216. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  1217. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1218. return S_IRUGO;
  1219. default:
  1220. return 0;
  1221. }
  1222. case ISCSI_HOST_PARAM:
  1223. switch (param) {
  1224. case ISCSI_HOST_PARAM_HWADDRESS:
  1225. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  1226. case ISCSI_HOST_PARAM_PORT_STATE:
  1227. case ISCSI_HOST_PARAM_PORT_SPEED:
  1228. return S_IRUGO;
  1229. default:
  1230. return 0;
  1231. }
  1232. case ISCSI_PARAM:
  1233. switch (param) {
  1234. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  1235. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  1236. case ISCSI_PARAM_HDRDGST_EN:
  1237. case ISCSI_PARAM_DATADGST_EN:
  1238. case ISCSI_PARAM_CONN_ADDRESS:
  1239. case ISCSI_PARAM_CONN_PORT:
  1240. case ISCSI_PARAM_EXP_STATSN:
  1241. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  1242. case ISCSI_PARAM_PERSISTENT_PORT:
  1243. case ISCSI_PARAM_PING_TMO:
  1244. case ISCSI_PARAM_RECV_TMO:
  1245. case ISCSI_PARAM_INITIAL_R2T_EN:
  1246. case ISCSI_PARAM_MAX_R2T:
  1247. case ISCSI_PARAM_IMM_DATA_EN:
  1248. case ISCSI_PARAM_FIRST_BURST:
  1249. case ISCSI_PARAM_MAX_BURST:
  1250. case ISCSI_PARAM_PDU_INORDER_EN:
  1251. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  1252. case ISCSI_PARAM_ERL:
  1253. case ISCSI_PARAM_TARGET_NAME:
  1254. case ISCSI_PARAM_TPGT:
  1255. case ISCSI_PARAM_USERNAME:
  1256. case ISCSI_PARAM_PASSWORD:
  1257. case ISCSI_PARAM_USERNAME_IN:
  1258. case ISCSI_PARAM_PASSWORD_IN:
  1259. case ISCSI_PARAM_FAST_ABORT:
  1260. case ISCSI_PARAM_ABORT_TMO:
  1261. case ISCSI_PARAM_LU_RESET_TMO:
  1262. case ISCSI_PARAM_IFACE_NAME:
  1263. case ISCSI_PARAM_INITIATOR_NAME:
  1264. return S_IRUGO;
  1265. default:
  1266. return 0;
  1267. }
  1268. }
  1269. return 0;
  1270. }