be_iscsi.c 36 KB

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