be_iscsi.c 37 KB

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