be_iscsi.c 39 KB

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