be_iscsi.c 35 KB

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