be_iscsi.c 35 KB

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