be_iscsi.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432
  1. /**
  2. * Copyright (C) 2005 - 2016 Broadcom
  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@broadcom.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@broadcom.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. pr_err("beiscsi_session_create: invalid ep\n");
  50. return NULL;
  51. }
  52. beiscsi_ep = ep->dd_data;
  53. phba = beiscsi_ep->phba;
  54. if (!beiscsi_hba_is_online(phba)) {
  55. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  56. "BS_%d : HBA in error 0x%lx\n", phba->state);
  57. return NULL;
  58. }
  59. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  60. "BS_%d : In beiscsi_session_create\n");
  61. if (cmds_max > beiscsi_ep->phba->params.wrbs_per_cxn) {
  62. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  63. "BS_%d : Cannot handle %d cmds."
  64. "Max cmds per session supported is %d. Using %d."
  65. "\n", cmds_max,
  66. beiscsi_ep->phba->params.wrbs_per_cxn,
  67. beiscsi_ep->phba->params.wrbs_per_cxn);
  68. cmds_max = beiscsi_ep->phba->params.wrbs_per_cxn;
  69. }
  70. shost = phba->shost;
  71. cls_session = iscsi_session_setup(&beiscsi_iscsi_transport,
  72. shost, cmds_max,
  73. sizeof(*beiscsi_sess),
  74. sizeof(*io_task),
  75. initial_cmdsn, ISCSI_MAX_TARGET);
  76. if (!cls_session)
  77. return NULL;
  78. sess = cls_session->dd_data;
  79. beiscsi_sess = sess->dd_data;
  80. beiscsi_sess->bhs_pool = pci_pool_create("beiscsi_bhs_pool",
  81. phba->pcidev,
  82. sizeof(struct be_cmd_bhs),
  83. 64, 0);
  84. if (!beiscsi_sess->bhs_pool)
  85. goto destroy_sess;
  86. return cls_session;
  87. destroy_sess:
  88. iscsi_session_teardown(cls_session);
  89. return NULL;
  90. }
  91. /**
  92. * beiscsi_session_destroy - destroys iscsi session
  93. * @cls_session: pointer to iscsi cls session
  94. *
  95. * Destroys iSCSI session instance and releases
  96. * resources allocated for it.
  97. */
  98. void beiscsi_session_destroy(struct iscsi_cls_session *cls_session)
  99. {
  100. struct iscsi_session *sess = cls_session->dd_data;
  101. struct beiscsi_session *beiscsi_sess = sess->dd_data;
  102. printk(KERN_INFO "In beiscsi_session_destroy\n");
  103. pci_pool_destroy(beiscsi_sess->bhs_pool);
  104. iscsi_session_teardown(cls_session);
  105. }
  106. /**
  107. * beiscsi_session_fail(): Closing session with appropriate error
  108. * @cls_session: ptr to session
  109. **/
  110. void beiscsi_session_fail(struct iscsi_cls_session *cls_session)
  111. {
  112. iscsi_session_failure(cls_session->dd_data, ISCSI_ERR_CONN_FAILED);
  113. }
  114. /**
  115. * beiscsi_conn_create - create an instance of iscsi connection
  116. * @cls_session: ptr to iscsi_cls_session
  117. * @cid: iscsi cid
  118. */
  119. struct iscsi_cls_conn *
  120. beiscsi_conn_create(struct iscsi_cls_session *cls_session, u32 cid)
  121. {
  122. struct beiscsi_hba *phba;
  123. struct Scsi_Host *shost;
  124. struct iscsi_cls_conn *cls_conn;
  125. struct beiscsi_conn *beiscsi_conn;
  126. struct iscsi_conn *conn;
  127. struct iscsi_session *sess;
  128. struct beiscsi_session *beiscsi_sess;
  129. shost = iscsi_session_to_shost(cls_session);
  130. phba = iscsi_host_priv(shost);
  131. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  132. "BS_%d : In beiscsi_conn_create ,cid"
  133. "from iscsi layer=%d\n", cid);
  134. cls_conn = iscsi_conn_setup(cls_session, sizeof(*beiscsi_conn), cid);
  135. if (!cls_conn)
  136. return NULL;
  137. conn = cls_conn->dd_data;
  138. beiscsi_conn = conn->dd_data;
  139. beiscsi_conn->ep = NULL;
  140. beiscsi_conn->phba = phba;
  141. beiscsi_conn->conn = conn;
  142. sess = cls_session->dd_data;
  143. beiscsi_sess = sess->dd_data;
  144. beiscsi_conn->beiscsi_sess = beiscsi_sess;
  145. return cls_conn;
  146. }
  147. /**
  148. * beiscsi_conn_bind - Binds iscsi session/connection with TCP connection
  149. * @cls_session: pointer to iscsi cls session
  150. * @cls_conn: pointer to iscsi cls conn
  151. * @transport_fd: EP handle(64 bit)
  152. *
  153. * This function binds the TCP Conn with iSCSI Connection and Session.
  154. */
  155. int beiscsi_conn_bind(struct iscsi_cls_session *cls_session,
  156. struct iscsi_cls_conn *cls_conn,
  157. u64 transport_fd, int is_leading)
  158. {
  159. struct iscsi_conn *conn = cls_conn->dd_data;
  160. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  161. struct Scsi_Host *shost = iscsi_session_to_shost(cls_session);
  162. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  163. struct hwi_controller *phwi_ctrlr = phba->phwi_ctrlr;
  164. struct hwi_wrb_context *pwrb_context;
  165. struct beiscsi_endpoint *beiscsi_ep;
  166. struct iscsi_endpoint *ep;
  167. uint16_t cri_index;
  168. ep = iscsi_lookup_endpoint(transport_fd);
  169. if (!ep)
  170. return -EINVAL;
  171. beiscsi_ep = ep->dd_data;
  172. if (iscsi_conn_bind(cls_session, cls_conn, is_leading))
  173. return -EINVAL;
  174. if (beiscsi_ep->phba != phba) {
  175. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  176. "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n",
  177. beiscsi_ep->phba, phba);
  178. return -EEXIST;
  179. }
  180. cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid);
  181. if (phba->conn_table[cri_index]) {
  182. if (beiscsi_conn != phba->conn_table[cri_index] ||
  183. beiscsi_ep != phba->conn_table[cri_index]->ep) {
  184. __beiscsi_log(phba, KERN_ERR,
  185. "BS_%d : conn_table not empty at %u: cid %u conn %p:%p\n",
  186. cri_index,
  187. beiscsi_ep->ep_cid,
  188. beiscsi_conn,
  189. phba->conn_table[cri_index]);
  190. return -EINVAL;
  191. }
  192. }
  193. beiscsi_conn->beiscsi_conn_cid = beiscsi_ep->ep_cid;
  194. beiscsi_conn->ep = beiscsi_ep;
  195. beiscsi_ep->conn = beiscsi_conn;
  196. /**
  197. * Each connection is associated with a WRBQ kept in wrb_context.
  198. * Store doorbell offset for transmit path.
  199. */
  200. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  201. beiscsi_conn->doorbell_offset = pwrb_context->doorbell_offset;
  202. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  203. "BS_%d : cid %d phba->conn_table[%u]=%p\n",
  204. beiscsi_ep->ep_cid, cri_index, beiscsi_conn);
  205. phba->conn_table[cri_index] = beiscsi_conn;
  206. return 0;
  207. }
  208. static int beiscsi_iface_create_ipv4(struct beiscsi_hba *phba)
  209. {
  210. if (phba->ipv4_iface)
  211. return 0;
  212. phba->ipv4_iface = iscsi_create_iface(phba->shost,
  213. &beiscsi_iscsi_transport,
  214. ISCSI_IFACE_TYPE_IPV4,
  215. 0, 0);
  216. if (!phba->ipv4_iface) {
  217. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  218. "BS_%d : Could not "
  219. "create default IPv4 address.\n");
  220. return -ENODEV;
  221. }
  222. return 0;
  223. }
  224. static int beiscsi_iface_create_ipv6(struct beiscsi_hba *phba)
  225. {
  226. if (phba->ipv6_iface)
  227. return 0;
  228. phba->ipv6_iface = iscsi_create_iface(phba->shost,
  229. &beiscsi_iscsi_transport,
  230. ISCSI_IFACE_TYPE_IPV6,
  231. 0, 0);
  232. if (!phba->ipv6_iface) {
  233. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  234. "BS_%d : Could not "
  235. "create default IPv6 address.\n");
  236. return -ENODEV;
  237. }
  238. return 0;
  239. }
  240. void beiscsi_iface_create_default(struct beiscsi_hba *phba)
  241. {
  242. struct be_cmd_get_if_info_resp *if_info;
  243. if (!beiscsi_if_get_info(phba, BEISCSI_IP_TYPE_V4, &if_info)) {
  244. beiscsi_iface_create_ipv4(phba);
  245. kfree(if_info);
  246. }
  247. if (!beiscsi_if_get_info(phba, BEISCSI_IP_TYPE_V6, &if_info)) {
  248. beiscsi_iface_create_ipv6(phba);
  249. kfree(if_info);
  250. }
  251. }
  252. void beiscsi_iface_destroy_default(struct beiscsi_hba *phba)
  253. {
  254. if (phba->ipv6_iface) {
  255. iscsi_destroy_iface(phba->ipv6_iface);
  256. phba->ipv6_iface = NULL;
  257. }
  258. if (phba->ipv4_iface) {
  259. iscsi_destroy_iface(phba->ipv4_iface);
  260. phba->ipv4_iface = NULL;
  261. }
  262. }
  263. /**
  264. * beiscsi_set_vlan_tag()- Set the VLAN TAG
  265. * @shost: Scsi Host for the driver instance
  266. * @iface_param: Interface paramters
  267. *
  268. * Set the VLAN TAG for the adapter or disable
  269. * the VLAN config
  270. *
  271. * returns
  272. * Success: 0
  273. * Failure: Non-Zero Value
  274. **/
  275. static int
  276. beiscsi_iface_config_vlan(struct Scsi_Host *shost,
  277. struct iscsi_iface_param_info *iface_param)
  278. {
  279. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  280. int ret = -EPERM;
  281. switch (iface_param->param) {
  282. case ISCSI_NET_PARAM_VLAN_ENABLED:
  283. ret = 0;
  284. if (iface_param->value[0] != ISCSI_VLAN_ENABLE)
  285. ret = beiscsi_if_set_vlan(phba, BEISCSI_VLAN_DISABLE);
  286. break;
  287. case ISCSI_NET_PARAM_VLAN_TAG:
  288. ret = beiscsi_if_set_vlan(phba,
  289. *((uint16_t *)iface_param->value));
  290. break;
  291. }
  292. return ret;
  293. }
  294. static int
  295. beiscsi_iface_config_ipv4(struct Scsi_Host *shost,
  296. struct iscsi_iface_param_info *info,
  297. void *data, uint32_t dt_len)
  298. {
  299. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  300. u8 *ip = NULL, *subnet = NULL, *gw;
  301. struct nlattr *nla;
  302. int ret = -EPERM;
  303. /* Check the param */
  304. switch (info->param) {
  305. case ISCSI_NET_PARAM_IFACE_ENABLE:
  306. if (info->value[0] == ISCSI_IFACE_ENABLE)
  307. ret = beiscsi_iface_create_ipv4(phba);
  308. else {
  309. iscsi_destroy_iface(phba->ipv4_iface);
  310. phba->ipv4_iface = NULL;
  311. }
  312. break;
  313. case ISCSI_NET_PARAM_IPV4_GW:
  314. gw = info->value;
  315. ret = beiscsi_if_set_gw(phba, BEISCSI_IP_TYPE_V4, gw);
  316. break;
  317. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  318. if (info->value[0] == ISCSI_BOOTPROTO_DHCP)
  319. ret = beiscsi_if_en_dhcp(phba, BEISCSI_IP_TYPE_V4);
  320. else if (info->value[0] == ISCSI_BOOTPROTO_STATIC)
  321. /* release DHCP IP address */
  322. ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V4,
  323. NULL, NULL);
  324. else
  325. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  326. "BS_%d : Invalid BOOTPROTO: %d\n",
  327. info->value[0]);
  328. break;
  329. case ISCSI_NET_PARAM_IPV4_ADDR:
  330. ip = info->value;
  331. nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_SUBNET);
  332. if (nla) {
  333. info = nla_data(nla);
  334. subnet = info->value;
  335. }
  336. ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V4,
  337. ip, subnet);
  338. break;
  339. case ISCSI_NET_PARAM_IPV4_SUBNET:
  340. /*
  341. * OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR ioctl needs IP
  342. * and subnet both. Find IP to be applied for this subnet.
  343. */
  344. subnet = info->value;
  345. nla = nla_find(data, dt_len, ISCSI_NET_PARAM_IPV4_ADDR);
  346. if (nla) {
  347. info = nla_data(nla);
  348. ip = info->value;
  349. }
  350. ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V4,
  351. ip, subnet);
  352. break;
  353. }
  354. return ret;
  355. }
  356. static int
  357. beiscsi_iface_config_ipv6(struct Scsi_Host *shost,
  358. struct iscsi_iface_param_info *iface_param,
  359. void *data, uint32_t dt_len)
  360. {
  361. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  362. int ret = -EPERM;
  363. switch (iface_param->param) {
  364. case ISCSI_NET_PARAM_IFACE_ENABLE:
  365. if (iface_param->value[0] == ISCSI_IFACE_ENABLE)
  366. ret = beiscsi_iface_create_ipv6(phba);
  367. else {
  368. iscsi_destroy_iface(phba->ipv6_iface);
  369. phba->ipv6_iface = NULL;
  370. }
  371. break;
  372. case ISCSI_NET_PARAM_IPV6_ADDR:
  373. ret = beiscsi_if_en_static(phba, BEISCSI_IP_TYPE_V6,
  374. iface_param->value, NULL);
  375. break;
  376. }
  377. return ret;
  378. }
  379. int beiscsi_iface_set_param(struct Scsi_Host *shost,
  380. void *data, uint32_t dt_len)
  381. {
  382. struct iscsi_iface_param_info *iface_param = NULL;
  383. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  384. struct nlattr *attrib;
  385. uint32_t rm_len = dt_len;
  386. int ret;
  387. if (!beiscsi_hba_is_online(phba)) {
  388. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  389. "BS_%d : HBA in error 0x%lx\n", phba->state);
  390. return -EBUSY;
  391. }
  392. /* update interface_handle */
  393. ret = beiscsi_if_get_handle(phba);
  394. if (ret) {
  395. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  396. "BS_%d : Getting Interface Handle Failed\n");
  397. return ret;
  398. }
  399. nla_for_each_attr(attrib, data, dt_len, rm_len) {
  400. iface_param = nla_data(attrib);
  401. if (iface_param->param_type != ISCSI_NET_PARAM)
  402. continue;
  403. /*
  404. * BE2ISCSI only supports 1 interface
  405. */
  406. if (iface_param->iface_num) {
  407. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  408. "BS_%d : Invalid iface_num %d."
  409. "Only iface_num 0 is supported.\n",
  410. iface_param->iface_num);
  411. return -EINVAL;
  412. }
  413. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  414. "BS_%d : %s.0 set param %d",
  415. (iface_param->iface_type == ISCSI_IFACE_TYPE_IPV4) ?
  416. "ipv4" : "ipv6", iface_param->param);
  417. ret = -EPERM;
  418. switch (iface_param->param) {
  419. case ISCSI_NET_PARAM_VLAN_ENABLED:
  420. case ISCSI_NET_PARAM_VLAN_TAG:
  421. ret = beiscsi_iface_config_vlan(shost, iface_param);
  422. break;
  423. default:
  424. switch (iface_param->iface_type) {
  425. case ISCSI_IFACE_TYPE_IPV4:
  426. ret = beiscsi_iface_config_ipv4(shost,
  427. iface_param,
  428. data, dt_len);
  429. break;
  430. case ISCSI_IFACE_TYPE_IPV6:
  431. ret = beiscsi_iface_config_ipv6(shost,
  432. iface_param,
  433. data, dt_len);
  434. break;
  435. }
  436. }
  437. if (ret == -EPERM) {
  438. __beiscsi_log(phba, KERN_ERR,
  439. "BS_%d : %s.0 set param %d not permitted",
  440. (iface_param->iface_type ==
  441. ISCSI_IFACE_TYPE_IPV4) ? "ipv4" : "ipv6",
  442. iface_param->param);
  443. ret = 0;
  444. }
  445. if (ret)
  446. break;
  447. }
  448. return ret;
  449. }
  450. static int __beiscsi_iface_get_param(struct beiscsi_hba *phba,
  451. struct iscsi_iface *iface,
  452. int param, char *buf)
  453. {
  454. struct be_cmd_get_if_info_resp *if_info;
  455. int len, ip_type = BEISCSI_IP_TYPE_V4;
  456. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  457. ip_type = BEISCSI_IP_TYPE_V6;
  458. len = beiscsi_if_get_info(phba, ip_type, &if_info);
  459. if (len)
  460. return len;
  461. switch (param) {
  462. case ISCSI_NET_PARAM_IPV4_ADDR:
  463. len = sprintf(buf, "%pI4\n", if_info->ip_addr.addr);
  464. break;
  465. case ISCSI_NET_PARAM_IPV6_ADDR:
  466. len = sprintf(buf, "%pI6\n", if_info->ip_addr.addr);
  467. break;
  468. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  469. if (!if_info->dhcp_state)
  470. len = sprintf(buf, "static\n");
  471. else
  472. len = sprintf(buf, "dhcp\n");
  473. break;
  474. case ISCSI_NET_PARAM_IPV4_SUBNET:
  475. len = sprintf(buf, "%pI4\n", if_info->ip_addr.subnet_mask);
  476. break;
  477. case ISCSI_NET_PARAM_VLAN_ENABLED:
  478. len = sprintf(buf, "%s\n",
  479. (if_info->vlan_priority == BEISCSI_VLAN_DISABLE) ?
  480. "disable" : "enable");
  481. break;
  482. case ISCSI_NET_PARAM_VLAN_ID:
  483. if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
  484. len = -EINVAL;
  485. else
  486. len = sprintf(buf, "%d\n",
  487. (if_info->vlan_priority &
  488. ISCSI_MAX_VLAN_ID));
  489. break;
  490. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  491. if (if_info->vlan_priority == BEISCSI_VLAN_DISABLE)
  492. len = -EINVAL;
  493. else
  494. len = sprintf(buf, "%d\n",
  495. ((if_info->vlan_priority >> 13) &
  496. ISCSI_MAX_VLAN_PRIORITY));
  497. break;
  498. default:
  499. WARN_ON(1);
  500. }
  501. kfree(if_info);
  502. return len;
  503. }
  504. int beiscsi_iface_get_param(struct iscsi_iface *iface,
  505. enum iscsi_param_type param_type,
  506. int param, char *buf)
  507. {
  508. struct Scsi_Host *shost = iscsi_iface_to_shost(iface);
  509. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  510. struct be_cmd_get_def_gateway_resp gateway;
  511. int len = -EPERM;
  512. if (param_type != ISCSI_NET_PARAM)
  513. return 0;
  514. if (!beiscsi_hba_is_online(phba)) {
  515. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  516. "BS_%d : HBA in error 0x%lx\n", phba->state);
  517. return -EBUSY;
  518. }
  519. switch (param) {
  520. case ISCSI_NET_PARAM_IPV4_ADDR:
  521. case ISCSI_NET_PARAM_IPV4_SUBNET:
  522. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  523. case ISCSI_NET_PARAM_IPV6_ADDR:
  524. case ISCSI_NET_PARAM_VLAN_ENABLED:
  525. case ISCSI_NET_PARAM_VLAN_ID:
  526. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  527. len = __beiscsi_iface_get_param(phba, iface, param, buf);
  528. break;
  529. case ISCSI_NET_PARAM_IFACE_ENABLE:
  530. if (iface->iface_type == ISCSI_IFACE_TYPE_IPV4)
  531. len = sprintf(buf, "%s\n",
  532. phba->ipv4_iface ? "enable" : "disable");
  533. else if (iface->iface_type == ISCSI_IFACE_TYPE_IPV6)
  534. len = sprintf(buf, "%s\n",
  535. phba->ipv6_iface ? "enable" : "disable");
  536. break;
  537. case ISCSI_NET_PARAM_IPV4_GW:
  538. memset(&gateway, 0, sizeof(gateway));
  539. len = beiscsi_if_get_gw(phba, BEISCSI_IP_TYPE_V4, &gateway);
  540. if (!len)
  541. len = sprintf(buf, "%pI4\n", &gateway.ip_addr.addr);
  542. break;
  543. }
  544. return len;
  545. }
  546. /**
  547. * beiscsi_ep_get_param - get the iscsi parameter
  548. * @ep: pointer to iscsi ep
  549. * @param: parameter type identifier
  550. * @buf: buffer pointer
  551. *
  552. * returns iscsi parameter
  553. */
  554. int beiscsi_ep_get_param(struct iscsi_endpoint *ep,
  555. enum iscsi_param param, char *buf)
  556. {
  557. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  558. int len;
  559. beiscsi_log(beiscsi_ep->phba, KERN_INFO,
  560. BEISCSI_LOG_CONFIG,
  561. "BS_%d : In beiscsi_ep_get_param,"
  562. " param= %d\n", param);
  563. switch (param) {
  564. case ISCSI_PARAM_CONN_PORT:
  565. len = sprintf(buf, "%hu\n", beiscsi_ep->dst_tcpport);
  566. break;
  567. case ISCSI_PARAM_CONN_ADDRESS:
  568. if (beiscsi_ep->ip_type == BEISCSI_IP_TYPE_V4)
  569. len = sprintf(buf, "%pI4\n", &beiscsi_ep->dst_addr);
  570. else
  571. len = sprintf(buf, "%pI6\n", &beiscsi_ep->dst6_addr);
  572. break;
  573. default:
  574. len = -EPERM;
  575. }
  576. return len;
  577. }
  578. int beiscsi_set_param(struct iscsi_cls_conn *cls_conn,
  579. enum iscsi_param param, char *buf, int buflen)
  580. {
  581. struct iscsi_conn *conn = cls_conn->dd_data;
  582. struct iscsi_session *session = conn->session;
  583. struct beiscsi_hba *phba = NULL;
  584. int ret;
  585. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  586. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  587. "BS_%d : In beiscsi_conn_set_param,"
  588. " param= %d\n", param);
  589. ret = iscsi_set_param(cls_conn, param, buf, buflen);
  590. if (ret)
  591. return ret;
  592. /*
  593. * If userspace tried to set the value to higher than we can
  594. * support override here.
  595. */
  596. switch (param) {
  597. case ISCSI_PARAM_FIRST_BURST:
  598. if (session->first_burst > 8192)
  599. session->first_burst = 8192;
  600. break;
  601. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  602. if (conn->max_recv_dlength > 65536)
  603. conn->max_recv_dlength = 65536;
  604. break;
  605. case ISCSI_PARAM_MAX_BURST:
  606. if (session->max_burst > 262144)
  607. session->max_burst = 262144;
  608. break;
  609. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  610. if (conn->max_xmit_dlength > 65536)
  611. conn->max_xmit_dlength = 65536;
  612. default:
  613. return 0;
  614. }
  615. return 0;
  616. }
  617. /**
  618. * beiscsi_get_initname - Read Initiator Name from flash
  619. * @buf: buffer bointer
  620. * @phba: The device priv structure instance
  621. *
  622. * returns number of bytes
  623. */
  624. static int beiscsi_get_initname(char *buf, struct beiscsi_hba *phba)
  625. {
  626. int rc;
  627. unsigned int tag;
  628. struct be_mcc_wrb *wrb;
  629. struct be_cmd_hba_name *resp;
  630. tag = be_cmd_get_initname(phba);
  631. if (!tag) {
  632. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  633. "BS_%d : Getting Initiator Name Failed\n");
  634. return -EBUSY;
  635. }
  636. rc = beiscsi_mccq_compl_wait(phba, tag, &wrb, NULL);
  637. if (rc) {
  638. beiscsi_log(phba, KERN_ERR,
  639. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  640. "BS_%d : Initiator Name MBX Failed\n");
  641. return rc;
  642. }
  643. resp = embedded_payload(wrb);
  644. rc = sprintf(buf, "%s\n", resp->initiator_name);
  645. return rc;
  646. }
  647. /**
  648. * beiscsi_get_port_state - Get the Port State
  649. * @shost : pointer to scsi_host structure
  650. *
  651. */
  652. static void beiscsi_get_port_state(struct Scsi_Host *shost)
  653. {
  654. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  655. struct iscsi_cls_host *ihost = shost->shost_data;
  656. ihost->port_state = test_bit(BEISCSI_HBA_LINK_UP, &phba->state) ?
  657. ISCSI_PORT_STATE_UP : ISCSI_PORT_STATE_DOWN;
  658. }
  659. /**
  660. * beiscsi_get_port_speed - Get the Port Speed from Adapter
  661. * @shost : pointer to scsi_host structure
  662. *
  663. */
  664. static void beiscsi_get_port_speed(struct Scsi_Host *shost)
  665. {
  666. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  667. struct iscsi_cls_host *ihost = shost->shost_data;
  668. switch (phba->port_speed) {
  669. case BE2ISCSI_LINK_SPEED_10MBPS:
  670. ihost->port_speed = ISCSI_PORT_SPEED_10MBPS;
  671. break;
  672. case BE2ISCSI_LINK_SPEED_100MBPS:
  673. ihost->port_speed = ISCSI_PORT_SPEED_100MBPS;
  674. break;
  675. case BE2ISCSI_LINK_SPEED_1GBPS:
  676. ihost->port_speed = ISCSI_PORT_SPEED_1GBPS;
  677. break;
  678. case BE2ISCSI_LINK_SPEED_10GBPS:
  679. ihost->port_speed = ISCSI_PORT_SPEED_10GBPS;
  680. break;
  681. case BE2ISCSI_LINK_SPEED_25GBPS:
  682. ihost->port_speed = ISCSI_PORT_SPEED_25GBPS;
  683. break;
  684. case BE2ISCSI_LINK_SPEED_40GBPS:
  685. ihost->port_speed = ISCSI_PORT_SPEED_40GBPS;
  686. break;
  687. default:
  688. ihost->port_speed = ISCSI_PORT_SPEED_UNKNOWN;
  689. }
  690. }
  691. /**
  692. * beiscsi_get_host_param - get the iscsi parameter
  693. * @shost: pointer to scsi_host structure
  694. * @param: parameter type identifier
  695. * @buf: buffer pointer
  696. *
  697. * returns host parameter
  698. */
  699. int beiscsi_get_host_param(struct Scsi_Host *shost,
  700. enum iscsi_host_param param, char *buf)
  701. {
  702. struct beiscsi_hba *phba = iscsi_host_priv(shost);
  703. int status = 0;
  704. if (!beiscsi_hba_is_online(phba)) {
  705. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  706. "BS_%d : HBA in error 0x%lx\n", phba->state);
  707. return -EBUSY;
  708. }
  709. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  710. "BS_%d : In beiscsi_get_host_param, param = %d\n", param);
  711. switch (param) {
  712. case ISCSI_HOST_PARAM_HWADDRESS:
  713. status = beiscsi_get_macaddr(buf, phba);
  714. if (status < 0) {
  715. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  716. "BS_%d : beiscsi_get_macaddr Failed\n");
  717. return status;
  718. }
  719. break;
  720. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  721. status = beiscsi_get_initname(buf, phba);
  722. if (status < 0) {
  723. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  724. "BS_%d : Retreiving Initiator Name Failed\n");
  725. return status;
  726. }
  727. break;
  728. case ISCSI_HOST_PARAM_PORT_STATE:
  729. beiscsi_get_port_state(shost);
  730. status = sprintf(buf, "%s\n", iscsi_get_port_state_name(shost));
  731. break;
  732. case ISCSI_HOST_PARAM_PORT_SPEED:
  733. beiscsi_get_port_speed(shost);
  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 = 1;
  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. AMAP_SET_BITS(struct amap_beiscsi_offload_params,
  823. max_recv_data_segment_length, params,
  824. conn->max_recv_dlength);
  825. }
  826. /**
  827. * beiscsi_conn_start - offload of session to chip
  828. * @cls_conn: pointer to beiscsi_conn
  829. */
  830. int beiscsi_conn_start(struct iscsi_cls_conn *cls_conn)
  831. {
  832. struct iscsi_conn *conn = cls_conn->dd_data;
  833. struct beiscsi_conn *beiscsi_conn = conn->dd_data;
  834. struct beiscsi_endpoint *beiscsi_ep;
  835. struct beiscsi_offload_params params;
  836. struct beiscsi_hba *phba;
  837. phba = ((struct beiscsi_conn *)conn->dd_data)->phba;
  838. if (!beiscsi_hba_is_online(phba)) {
  839. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  840. "BS_%d : HBA in error 0x%lx\n", phba->state);
  841. return -EBUSY;
  842. }
  843. beiscsi_log(beiscsi_conn->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  844. "BS_%d : In beiscsi_conn_start\n");
  845. memset(&params, 0, sizeof(struct beiscsi_offload_params));
  846. beiscsi_ep = beiscsi_conn->ep;
  847. if (!beiscsi_ep)
  848. beiscsi_log(beiscsi_conn->phba, KERN_ERR,
  849. BEISCSI_LOG_CONFIG,
  850. "BS_%d : In beiscsi_conn_start , no beiscsi_ep\n");
  851. beiscsi_conn->login_in_progress = 0;
  852. beiscsi_set_params_for_offld(beiscsi_conn, &params);
  853. beiscsi_offload_connection(beiscsi_conn, &params);
  854. iscsi_conn_start(cls_conn);
  855. return 0;
  856. }
  857. /**
  858. * beiscsi_get_cid - Allocate a cid
  859. * @phba: The phba instance
  860. */
  861. static int beiscsi_get_cid(struct beiscsi_hba *phba)
  862. {
  863. uint16_t cid_avlbl_ulp0, cid_avlbl_ulp1;
  864. unsigned short cid, cid_from_ulp;
  865. struct ulp_cid_info *cid_info;
  866. /* Find the ULP which has more CID available */
  867. cid_avlbl_ulp0 = (phba->cid_array_info[BEISCSI_ULP0]) ?
  868. BEISCSI_ULP0_AVLBL_CID(phba) : 0;
  869. cid_avlbl_ulp1 = (phba->cid_array_info[BEISCSI_ULP1]) ?
  870. BEISCSI_ULP1_AVLBL_CID(phba) : 0;
  871. cid_from_ulp = (cid_avlbl_ulp0 > cid_avlbl_ulp1) ?
  872. BEISCSI_ULP0 : BEISCSI_ULP1;
  873. /**
  874. * If iSCSI protocol is loaded only on ULP 0, and when cid_avlbl_ulp
  875. * is ZERO for both, ULP 1 is returned.
  876. * Check if ULP is loaded before getting new CID.
  877. */
  878. if (!test_bit(cid_from_ulp, (void *)&phba->fw_config.ulp_supported))
  879. return BE_INVALID_CID;
  880. cid_info = phba->cid_array_info[cid_from_ulp];
  881. cid = cid_info->cid_array[cid_info->cid_alloc];
  882. if (!cid_info->avlbl_cids || cid == BE_INVALID_CID) {
  883. __beiscsi_log(phba, KERN_ERR,
  884. "BS_%d : failed to get cid: available %u:%u\n",
  885. cid_info->avlbl_cids, cid_info->cid_free);
  886. return BE_INVALID_CID;
  887. }
  888. /* empty the slot */
  889. cid_info->cid_array[cid_info->cid_alloc++] = BE_INVALID_CID;
  890. if (cid_info->cid_alloc == BEISCSI_GET_CID_COUNT(phba, cid_from_ulp))
  891. cid_info->cid_alloc = 0;
  892. cid_info->avlbl_cids--;
  893. return cid;
  894. }
  895. /**
  896. * beiscsi_put_cid - Free the cid
  897. * @phba: The phba for which the cid is being freed
  898. * @cid: The cid to free
  899. */
  900. static void beiscsi_put_cid(struct beiscsi_hba *phba, unsigned short cid)
  901. {
  902. uint16_t cri_index = BE_GET_CRI_FROM_CID(cid);
  903. struct hwi_wrb_context *pwrb_context;
  904. struct hwi_controller *phwi_ctrlr;
  905. struct ulp_cid_info *cid_info;
  906. uint16_t cid_post_ulp;
  907. phwi_ctrlr = phba->phwi_ctrlr;
  908. pwrb_context = &phwi_ctrlr->wrb_context[cri_index];
  909. cid_post_ulp = pwrb_context->ulp_num;
  910. cid_info = phba->cid_array_info[cid_post_ulp];
  911. /* fill only in empty slot */
  912. if (cid_info->cid_array[cid_info->cid_free] != BE_INVALID_CID) {
  913. __beiscsi_log(phba, KERN_ERR,
  914. "BS_%d : failed to put cid %u: available %u:%u\n",
  915. cid, cid_info->avlbl_cids, cid_info->cid_free);
  916. return;
  917. }
  918. cid_info->cid_array[cid_info->cid_free++] = cid;
  919. if (cid_info->cid_free == BEISCSI_GET_CID_COUNT(phba, cid_post_ulp))
  920. cid_info->cid_free = 0;
  921. cid_info->avlbl_cids++;
  922. }
  923. /**
  924. * beiscsi_free_ep - free endpoint
  925. * @ep: pointer to iscsi endpoint structure
  926. */
  927. static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep)
  928. {
  929. struct beiscsi_hba *phba = beiscsi_ep->phba;
  930. struct beiscsi_conn *beiscsi_conn;
  931. beiscsi_put_cid(phba, beiscsi_ep->ep_cid);
  932. beiscsi_ep->phba = NULL;
  933. /* clear this to track freeing in beiscsi_ep_disconnect */
  934. phba->ep_array[BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid)] = NULL;
  935. /**
  936. * Check if any connection resource allocated by driver
  937. * is to be freed.This case occurs when target redirection
  938. * or connection retry is done.
  939. **/
  940. if (!beiscsi_ep->conn)
  941. return;
  942. beiscsi_conn = beiscsi_ep->conn;
  943. /**
  944. * Break ep->conn link here so that completions after
  945. * this are ignored.
  946. */
  947. beiscsi_ep->conn = NULL;
  948. if (beiscsi_conn->login_in_progress) {
  949. beiscsi_free_mgmt_task_handles(beiscsi_conn,
  950. beiscsi_conn->task);
  951. beiscsi_conn->login_in_progress = 0;
  952. }
  953. }
  954. /**
  955. * beiscsi_open_conn - Ask FW to open a TCP connection
  956. * @ep: endpoint to be used
  957. * @src_addr: The source IP address
  958. * @dst_addr: The Destination IP address
  959. *
  960. * Asks the FW to open a TCP connection
  961. */
  962. static int beiscsi_open_conn(struct iscsi_endpoint *ep,
  963. struct sockaddr *src_addr,
  964. struct sockaddr *dst_addr, int non_blocking)
  965. {
  966. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  967. struct beiscsi_hba *phba = beiscsi_ep->phba;
  968. struct tcp_connect_and_offload_out *ptcpcnct_out;
  969. struct be_dma_mem nonemb_cmd;
  970. unsigned int tag, req_memsize;
  971. int ret = -ENOMEM;
  972. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  973. "BS_%d : In beiscsi_open_conn\n");
  974. beiscsi_ep->ep_cid = beiscsi_get_cid(phba);
  975. if (beiscsi_ep->ep_cid == BE_INVALID_CID) {
  976. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  977. "BS_%d : No free cid available\n");
  978. return ret;
  979. }
  980. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  981. "BS_%d : In beiscsi_open_conn, ep_cid=%d\n",
  982. beiscsi_ep->ep_cid);
  983. phba->ep_array[BE_GET_CRI_FROM_CID
  984. (beiscsi_ep->ep_cid)] = ep;
  985. beiscsi_ep->cid_vld = 0;
  986. if (is_chip_be2_be3r(phba))
  987. req_memsize = sizeof(struct tcp_connect_and_offload_in);
  988. else
  989. req_memsize = sizeof(struct tcp_connect_and_offload_in_v1);
  990. nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
  991. req_memsize,
  992. &nonemb_cmd.dma);
  993. if (nonemb_cmd.va == NULL) {
  994. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  995. "BS_%d : Failed to allocate memory for"
  996. " mgmt_open_connection\n");
  997. beiscsi_free_ep(beiscsi_ep);
  998. return -ENOMEM;
  999. }
  1000. nonemb_cmd.size = req_memsize;
  1001. memset(nonemb_cmd.va, 0, nonemb_cmd.size);
  1002. tag = mgmt_open_connection(phba, dst_addr, beiscsi_ep, &nonemb_cmd);
  1003. if (tag <= 0) {
  1004. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1005. "BS_%d : mgmt_open_connection Failed for cid=%d\n",
  1006. beiscsi_ep->ep_cid);
  1007. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  1008. nonemb_cmd.va, nonemb_cmd.dma);
  1009. beiscsi_free_ep(beiscsi_ep);
  1010. return -EAGAIN;
  1011. }
  1012. ret = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
  1013. if (ret) {
  1014. beiscsi_log(phba, KERN_ERR,
  1015. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  1016. "BS_%d : mgmt_open_connection Failed");
  1017. if (ret != -EBUSY)
  1018. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  1019. nonemb_cmd.va, nonemb_cmd.dma);
  1020. beiscsi_free_ep(beiscsi_ep);
  1021. return ret;
  1022. }
  1023. ptcpcnct_out = (struct tcp_connect_and_offload_out *)nonemb_cmd.va;
  1024. beiscsi_ep = ep->dd_data;
  1025. beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
  1026. beiscsi_ep->cid_vld = 1;
  1027. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1028. "BS_%d : mgmt_open_connection Success\n");
  1029. pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
  1030. nonemb_cmd.va, nonemb_cmd.dma);
  1031. return 0;
  1032. }
  1033. /**
  1034. * beiscsi_ep_connect - Ask chip to create TCP Conn
  1035. * @scsi_host: Pointer to scsi_host structure
  1036. * @dst_addr: The IP address of Target
  1037. * @non_blocking: blocking or non-blocking call
  1038. *
  1039. * This routines first asks chip to create a connection and then allocates an EP
  1040. */
  1041. struct iscsi_endpoint *
  1042. beiscsi_ep_connect(struct Scsi_Host *shost, struct sockaddr *dst_addr,
  1043. int non_blocking)
  1044. {
  1045. struct beiscsi_hba *phba;
  1046. struct beiscsi_endpoint *beiscsi_ep;
  1047. struct iscsi_endpoint *ep;
  1048. int ret;
  1049. if (!shost) {
  1050. ret = -ENXIO;
  1051. pr_err("beiscsi_ep_connect shost is NULL\n");
  1052. return ERR_PTR(ret);
  1053. }
  1054. phba = iscsi_host_priv(shost);
  1055. if (!beiscsi_hba_is_online(phba)) {
  1056. ret = -EIO;
  1057. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1058. "BS_%d : HBA in error 0x%lx\n", phba->state);
  1059. return ERR_PTR(ret);
  1060. }
  1061. if (!test_bit(BEISCSI_HBA_LINK_UP, &phba->state)) {
  1062. ret = -EBUSY;
  1063. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  1064. "BS_%d : The Adapter Port state is Down!!!\n");
  1065. return ERR_PTR(ret);
  1066. }
  1067. ep = iscsi_create_endpoint(sizeof(struct beiscsi_endpoint));
  1068. if (!ep) {
  1069. ret = -ENOMEM;
  1070. return ERR_PTR(ret);
  1071. }
  1072. beiscsi_ep = ep->dd_data;
  1073. beiscsi_ep->phba = phba;
  1074. beiscsi_ep->openiscsi_ep = ep;
  1075. ret = beiscsi_open_conn(ep, NULL, dst_addr, non_blocking);
  1076. if (ret) {
  1077. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1078. "BS_%d : Failed in beiscsi_open_conn\n");
  1079. goto free_ep;
  1080. }
  1081. return ep;
  1082. free_ep:
  1083. iscsi_destroy_endpoint(ep);
  1084. return ERR_PTR(ret);
  1085. }
  1086. /**
  1087. * beiscsi_ep_poll - Poll to see if connection is established
  1088. * @ep: endpoint to be used
  1089. * @timeout_ms: timeout specified in millisecs
  1090. *
  1091. * Poll to see if TCP connection established
  1092. */
  1093. int beiscsi_ep_poll(struct iscsi_endpoint *ep, int timeout_ms)
  1094. {
  1095. struct beiscsi_endpoint *beiscsi_ep = ep->dd_data;
  1096. beiscsi_log(beiscsi_ep->phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1097. "BS_%d : In beiscsi_ep_poll\n");
  1098. if (beiscsi_ep->cid_vld == 1)
  1099. return 1;
  1100. else
  1101. return 0;
  1102. }
  1103. /**
  1104. * beiscsi_flush_cq()- Flush the CQ created.
  1105. * @phba: ptr device priv structure.
  1106. *
  1107. * Before the connection resource are freed flush
  1108. * all the CQ enteries
  1109. **/
  1110. static void beiscsi_flush_cq(struct beiscsi_hba *phba)
  1111. {
  1112. uint16_t i;
  1113. struct be_eq_obj *pbe_eq;
  1114. struct hwi_controller *phwi_ctrlr;
  1115. struct hwi_context_memory *phwi_context;
  1116. phwi_ctrlr = phba->phwi_ctrlr;
  1117. phwi_context = phwi_ctrlr->phwi_ctxt;
  1118. for (i = 0; i < phba->num_cpus; i++) {
  1119. pbe_eq = &phwi_context->be_eq[i];
  1120. irq_poll_disable(&pbe_eq->iopoll);
  1121. beiscsi_process_cq(pbe_eq, BE2_MAX_NUM_CQ_PROC);
  1122. irq_poll_enable(&pbe_eq->iopoll);
  1123. }
  1124. }
  1125. /**
  1126. * beiscsi_close_conn - Upload the connection
  1127. * @ep: The iscsi endpoint
  1128. * @flag: The type of connection closure
  1129. */
  1130. static int beiscsi_close_conn(struct beiscsi_endpoint *beiscsi_ep, int flag)
  1131. {
  1132. int ret = 0;
  1133. unsigned int tag;
  1134. struct beiscsi_hba *phba = beiscsi_ep->phba;
  1135. tag = mgmt_upload_connection(phba, beiscsi_ep->ep_cid, flag);
  1136. if (!tag) {
  1137. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1138. "BS_%d : upload failed for cid 0x%x\n",
  1139. beiscsi_ep->ep_cid);
  1140. ret = -EAGAIN;
  1141. }
  1142. ret = beiscsi_mccq_compl_wait(phba, tag, NULL, NULL);
  1143. /* Flush the CQ entries */
  1144. beiscsi_flush_cq(phba);
  1145. return ret;
  1146. }
  1147. /**
  1148. * beiscsi_ep_disconnect - Tears down the TCP connection
  1149. * @ep: endpoint to be used
  1150. *
  1151. * Tears down the TCP connection
  1152. */
  1153. void beiscsi_ep_disconnect(struct iscsi_endpoint *ep)
  1154. {
  1155. struct beiscsi_conn *beiscsi_conn;
  1156. struct beiscsi_endpoint *beiscsi_ep;
  1157. struct beiscsi_hba *phba;
  1158. unsigned int tag;
  1159. uint8_t mgmt_invalidate_flag, tcp_upload_flag;
  1160. unsigned short savecfg_flag = CMD_ISCSI_SESSION_SAVE_CFG_ON_FLASH;
  1161. uint16_t cri_index;
  1162. beiscsi_ep = ep->dd_data;
  1163. phba = beiscsi_ep->phba;
  1164. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1165. "BS_%d : In beiscsi_ep_disconnect for ep_cid = %u\n",
  1166. beiscsi_ep->ep_cid);
  1167. cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid);
  1168. if (!phba->ep_array[cri_index]) {
  1169. __beiscsi_log(phba, KERN_ERR,
  1170. "BS_%d : ep_array at %u cid %u empty\n",
  1171. cri_index,
  1172. beiscsi_ep->ep_cid);
  1173. return;
  1174. }
  1175. if (beiscsi_ep->conn) {
  1176. beiscsi_conn = beiscsi_ep->conn;
  1177. iscsi_suspend_queue(beiscsi_conn->conn);
  1178. mgmt_invalidate_flag = ~BEISCSI_NO_RST_ISSUE;
  1179. tcp_upload_flag = CONNECTION_UPLOAD_GRACEFUL;
  1180. } else {
  1181. mgmt_invalidate_flag = BEISCSI_NO_RST_ISSUE;
  1182. tcp_upload_flag = CONNECTION_UPLOAD_ABORT;
  1183. }
  1184. if (!beiscsi_hba_is_online(phba)) {
  1185. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  1186. "BS_%d : HBA in error 0x%lx\n", phba->state);
  1187. goto free_ep;
  1188. }
  1189. tag = mgmt_invalidate_connection(phba, beiscsi_ep,
  1190. beiscsi_ep->ep_cid,
  1191. mgmt_invalidate_flag,
  1192. savecfg_flag);
  1193. if (!tag) {
  1194. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  1195. "BS_%d : mgmt_invalidate_connection Failed for cid=%d\n",
  1196. beiscsi_ep->ep_cid);
  1197. }
  1198. beiscsi_mccq_compl_wait(phba, tag, NULL, NULL);
  1199. beiscsi_close_conn(beiscsi_ep, tcp_upload_flag);
  1200. free_ep:
  1201. msleep(BEISCSI_LOGOUT_SYNC_DELAY);
  1202. beiscsi_free_ep(beiscsi_ep);
  1203. if (!phba->conn_table[cri_index])
  1204. __beiscsi_log(phba, KERN_ERR,
  1205. "BS_%d : conn_table empty at %u: cid %u\n",
  1206. cri_index,
  1207. beiscsi_ep->ep_cid);
  1208. phba->conn_table[cri_index] = NULL;
  1209. iscsi_destroy_endpoint(beiscsi_ep->openiscsi_ep);
  1210. }
  1211. umode_t beiscsi_attr_is_visible(int param_type, int param)
  1212. {
  1213. switch (param_type) {
  1214. case ISCSI_NET_PARAM:
  1215. switch (param) {
  1216. case ISCSI_NET_PARAM_IFACE_ENABLE:
  1217. case ISCSI_NET_PARAM_IPV4_ADDR:
  1218. case ISCSI_NET_PARAM_IPV4_SUBNET:
  1219. case ISCSI_NET_PARAM_IPV4_BOOTPROTO:
  1220. case ISCSI_NET_PARAM_IPV4_GW:
  1221. case ISCSI_NET_PARAM_IPV6_ADDR:
  1222. case ISCSI_NET_PARAM_VLAN_ID:
  1223. case ISCSI_NET_PARAM_VLAN_PRIORITY:
  1224. case ISCSI_NET_PARAM_VLAN_ENABLED:
  1225. return S_IRUGO;
  1226. default:
  1227. return 0;
  1228. }
  1229. case ISCSI_HOST_PARAM:
  1230. switch (param) {
  1231. case ISCSI_HOST_PARAM_HWADDRESS:
  1232. case ISCSI_HOST_PARAM_INITIATOR_NAME:
  1233. case ISCSI_HOST_PARAM_PORT_STATE:
  1234. case ISCSI_HOST_PARAM_PORT_SPEED:
  1235. return S_IRUGO;
  1236. default:
  1237. return 0;
  1238. }
  1239. case ISCSI_PARAM:
  1240. switch (param) {
  1241. case ISCSI_PARAM_MAX_RECV_DLENGTH:
  1242. case ISCSI_PARAM_MAX_XMIT_DLENGTH:
  1243. case ISCSI_PARAM_HDRDGST_EN:
  1244. case ISCSI_PARAM_DATADGST_EN:
  1245. case ISCSI_PARAM_CONN_ADDRESS:
  1246. case ISCSI_PARAM_CONN_PORT:
  1247. case ISCSI_PARAM_EXP_STATSN:
  1248. case ISCSI_PARAM_PERSISTENT_ADDRESS:
  1249. case ISCSI_PARAM_PERSISTENT_PORT:
  1250. case ISCSI_PARAM_PING_TMO:
  1251. case ISCSI_PARAM_RECV_TMO:
  1252. case ISCSI_PARAM_INITIAL_R2T_EN:
  1253. case ISCSI_PARAM_MAX_R2T:
  1254. case ISCSI_PARAM_IMM_DATA_EN:
  1255. case ISCSI_PARAM_FIRST_BURST:
  1256. case ISCSI_PARAM_MAX_BURST:
  1257. case ISCSI_PARAM_PDU_INORDER_EN:
  1258. case ISCSI_PARAM_DATASEQ_INORDER_EN:
  1259. case ISCSI_PARAM_ERL:
  1260. case ISCSI_PARAM_TARGET_NAME:
  1261. case ISCSI_PARAM_TPGT:
  1262. case ISCSI_PARAM_USERNAME:
  1263. case ISCSI_PARAM_PASSWORD:
  1264. case ISCSI_PARAM_USERNAME_IN:
  1265. case ISCSI_PARAM_PASSWORD_IN:
  1266. case ISCSI_PARAM_FAST_ABORT:
  1267. case ISCSI_PARAM_ABORT_TMO:
  1268. case ISCSI_PARAM_LU_RESET_TMO:
  1269. case ISCSI_PARAM_IFACE_NAME:
  1270. case ISCSI_PARAM_INITIATOR_NAME:
  1271. return S_IRUGO;
  1272. default:
  1273. return 0;
  1274. }
  1275. }
  1276. return 0;
  1277. }