be_iscsi.c 35 KB

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