be_iscsi.c 35 KB

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