be_mgmt.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  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 <linux/bsg-lib.h>
  20. #include <scsi/scsi_transport_iscsi.h>
  21. #include <scsi/scsi_bsg_iscsi.h>
  22. #include "be_mgmt.h"
  23. #include "be_iscsi.h"
  24. /**
  25. * mgmt_reopen_session()- Reopen a session based on reopen_type
  26. * @phba: Device priv structure instance
  27. * @reopen_type: Type of reopen_session FW should do.
  28. * @sess_handle: Session Handle of the session to be re-opened
  29. *
  30. * return
  31. * the TAG used for MBOX Command
  32. *
  33. **/
  34. unsigned int mgmt_reopen_session(struct beiscsi_hba *phba,
  35. unsigned int reopen_type,
  36. unsigned int sess_handle)
  37. {
  38. struct be_ctrl_info *ctrl = &phba->ctrl;
  39. struct be_mcc_wrb *wrb;
  40. struct be_cmd_reopen_session_req *req;
  41. unsigned int tag = 0;
  42. beiscsi_log(phba, KERN_INFO,
  43. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  44. "BG_%d : In bescsi_get_boot_target\n");
  45. spin_lock(&ctrl->mbox_lock);
  46. tag = alloc_mcc_tag(phba);
  47. if (!tag) {
  48. spin_unlock(&ctrl->mbox_lock);
  49. return tag;
  50. }
  51. wrb = wrb_from_mccq(phba);
  52. req = embedded_payload(wrb);
  53. wrb->tag0 |= tag;
  54. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  55. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  56. OPCODE_ISCSI_INI_DRIVER_REOPEN_ALL_SESSIONS,
  57. sizeof(struct be_cmd_reopen_session_resp));
  58. /* set the reopen_type,sess_handle */
  59. req->reopen_type = reopen_type;
  60. req->session_handle = sess_handle;
  61. be_mcc_notify(phba);
  62. spin_unlock(&ctrl->mbox_lock);
  63. return tag;
  64. }
  65. unsigned int mgmt_get_boot_target(struct beiscsi_hba *phba)
  66. {
  67. struct be_ctrl_info *ctrl = &phba->ctrl;
  68. struct be_mcc_wrb *wrb;
  69. struct be_cmd_get_boot_target_req *req;
  70. unsigned int tag = 0;
  71. beiscsi_log(phba, KERN_INFO,
  72. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  73. "BG_%d : In bescsi_get_boot_target\n");
  74. spin_lock(&ctrl->mbox_lock);
  75. tag = alloc_mcc_tag(phba);
  76. if (!tag) {
  77. spin_unlock(&ctrl->mbox_lock);
  78. return tag;
  79. }
  80. wrb = wrb_from_mccq(phba);
  81. req = embedded_payload(wrb);
  82. wrb->tag0 |= tag;
  83. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  84. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  85. OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET,
  86. sizeof(struct be_cmd_get_boot_target_resp));
  87. be_mcc_notify(phba);
  88. spin_unlock(&ctrl->mbox_lock);
  89. return tag;
  90. }
  91. unsigned int mgmt_get_session_info(struct beiscsi_hba *phba,
  92. u32 boot_session_handle,
  93. struct be_dma_mem *nonemb_cmd)
  94. {
  95. struct be_ctrl_info *ctrl = &phba->ctrl;
  96. struct be_mcc_wrb *wrb;
  97. unsigned int tag = 0;
  98. struct be_cmd_get_session_req *req;
  99. struct be_cmd_get_session_resp *resp;
  100. struct be_sge *sge;
  101. beiscsi_log(phba, KERN_INFO,
  102. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  103. "BG_%d : In beiscsi_get_session_info\n");
  104. spin_lock(&ctrl->mbox_lock);
  105. tag = alloc_mcc_tag(phba);
  106. if (!tag) {
  107. spin_unlock(&ctrl->mbox_lock);
  108. return tag;
  109. }
  110. nonemb_cmd->size = sizeof(*resp);
  111. req = nonemb_cmd->va;
  112. memset(req, 0, sizeof(*req));
  113. wrb = wrb_from_mccq(phba);
  114. sge = nonembedded_sgl(wrb);
  115. wrb->tag0 |= tag;
  116. wrb->tag0 |= tag;
  117. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  118. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  119. OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
  120. sizeof(*resp));
  121. req->session_handle = boot_session_handle;
  122. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  123. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  124. sge->len = cpu_to_le32(nonemb_cmd->size);
  125. be_mcc_notify(phba);
  126. spin_unlock(&ctrl->mbox_lock);
  127. return tag;
  128. }
  129. int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
  130. struct beiscsi_hba *phba)
  131. {
  132. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  133. struct be_fw_cfg *req = embedded_payload(wrb);
  134. int status = 0;
  135. spin_lock(&ctrl->mbox_lock);
  136. memset(wrb, 0, sizeof(*wrb));
  137. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  138. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  139. OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
  140. status = be_mbox_notify(ctrl);
  141. if (!status) {
  142. struct be_fw_cfg *pfw_cfg;
  143. pfw_cfg = req;
  144. phba->fw_config.phys_port = pfw_cfg->phys_port;
  145. phba->fw_config.iscsi_icd_start =
  146. pfw_cfg->ulp[0].icd_base;
  147. phba->fw_config.iscsi_icd_count =
  148. pfw_cfg->ulp[0].icd_count;
  149. phba->fw_config.iscsi_cid_start =
  150. pfw_cfg->ulp[0].sq_base;
  151. phba->fw_config.iscsi_cid_count =
  152. pfw_cfg->ulp[0].sq_count;
  153. if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
  154. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  155. "BG_%d : FW reported MAX CXNS as %d\t"
  156. "Max Supported = %d.\n",
  157. phba->fw_config.iscsi_cid_count,
  158. BE2_MAX_SESSIONS);
  159. phba->fw_config.iscsi_cid_count = BE2_MAX_SESSIONS / 2;
  160. }
  161. } else {
  162. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  163. "BG_%d : Failed in mgmt_get_fw_config\n");
  164. }
  165. spin_unlock(&ctrl->mbox_lock);
  166. return status;
  167. }
  168. int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
  169. struct beiscsi_hba *phba)
  170. {
  171. struct be_dma_mem nonemb_cmd;
  172. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  173. struct be_mgmt_controller_attributes *req;
  174. struct be_sge *sge = nonembedded_sgl(wrb);
  175. int status = 0;
  176. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  177. sizeof(struct be_mgmt_controller_attributes),
  178. &nonemb_cmd.dma);
  179. if (nonemb_cmd.va == NULL) {
  180. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  181. "BG_%d : Failed to allocate memory for "
  182. "mgmt_check_supported_fw\n");
  183. return -ENOMEM;
  184. }
  185. nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
  186. req = nonemb_cmd.va;
  187. memset(req, 0, sizeof(*req));
  188. spin_lock(&ctrl->mbox_lock);
  189. memset(wrb, 0, sizeof(*wrb));
  190. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  191. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  192. OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
  193. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  194. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  195. sge->len = cpu_to_le32(nonemb_cmd.size);
  196. status = be_mbox_notify(ctrl);
  197. if (!status) {
  198. struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
  199. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  200. "BG_%d : Firmware Version of CMD : %s\n"
  201. "Firmware Version is : %s\n"
  202. "Developer Build, not performing version check...\n",
  203. resp->params.hba_attribs
  204. .flashrom_version_string,
  205. resp->params.hba_attribs.
  206. firmware_version_string);
  207. phba->fw_config.iscsi_features =
  208. resp->params.hba_attribs.iscsi_features;
  209. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
  210. "BM_%d : phba->fw_config.iscsi_features = %d\n",
  211. phba->fw_config.iscsi_features);
  212. } else
  213. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
  214. "BG_%d : Failed in mgmt_check_supported_fw\n");
  215. spin_unlock(&ctrl->mbox_lock);
  216. if (nonemb_cmd.va)
  217. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  218. nonemb_cmd.va, nonemb_cmd.dma);
  219. return status;
  220. }
  221. unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl,
  222. struct beiscsi_hba *phba,
  223. struct bsg_job *job,
  224. struct be_dma_mem *nonemb_cmd)
  225. {
  226. struct be_cmd_resp_hdr *resp;
  227. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  228. struct be_sge *mcc_sge = nonembedded_sgl(wrb);
  229. unsigned int tag = 0;
  230. struct iscsi_bsg_request *bsg_req = job->request;
  231. struct be_bsg_vendor_cmd *req = nonemb_cmd->va;
  232. unsigned short region, sector_size, sector, offset;
  233. nonemb_cmd->size = job->request_payload.payload_len;
  234. memset(nonemb_cmd->va, 0, nonemb_cmd->size);
  235. resp = nonemb_cmd->va;
  236. region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
  237. sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
  238. sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
  239. offset = bsg_req->rqst_data.h_vendor.vendor_cmd[4];
  240. req->region = region;
  241. req->sector = sector;
  242. req->offset = offset;
  243. spin_lock(&ctrl->mbox_lock);
  244. memset(wrb, 0, sizeof(*wrb));
  245. switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) {
  246. case BEISCSI_WRITE_FLASH:
  247. offset = sector * sector_size + offset;
  248. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  249. OPCODE_COMMON_WRITE_FLASH, sizeof(*req));
  250. sg_copy_to_buffer(job->request_payload.sg_list,
  251. job->request_payload.sg_cnt,
  252. nonemb_cmd->va + offset, job->request_len);
  253. break;
  254. case BEISCSI_READ_FLASH:
  255. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  256. OPCODE_COMMON_READ_FLASH, sizeof(*req));
  257. break;
  258. default:
  259. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  260. "BG_%d : Unsupported cmd = 0x%x\n\n",
  261. bsg_req->rqst_data.h_vendor.vendor_cmd[0]);
  262. spin_unlock(&ctrl->mbox_lock);
  263. return -ENOSYS;
  264. }
  265. tag = alloc_mcc_tag(phba);
  266. if (!tag) {
  267. spin_unlock(&ctrl->mbox_lock);
  268. return tag;
  269. }
  270. be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false,
  271. job->request_payload.sg_cnt);
  272. mcc_sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  273. mcc_sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  274. mcc_sge->len = cpu_to_le32(nonemb_cmd->size);
  275. wrb->tag0 |= tag;
  276. be_mcc_notify(phba);
  277. spin_unlock(&ctrl->mbox_lock);
  278. return tag;
  279. }
  280. int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
  281. {
  282. struct be_ctrl_info *ctrl = &phba->ctrl;
  283. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  284. struct iscsi_cleanup_req *req = embedded_payload(wrb);
  285. int status = 0;
  286. spin_lock(&ctrl->mbox_lock);
  287. memset(wrb, 0, sizeof(*wrb));
  288. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  289. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  290. OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
  291. req->chute = chute;
  292. req->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba));
  293. req->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba));
  294. status = be_mcc_notify_wait(phba);
  295. if (status)
  296. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
  297. "BG_%d : mgmt_epfw_cleanup , FAILED\n");
  298. spin_unlock(&ctrl->mbox_lock);
  299. return status;
  300. }
  301. unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
  302. struct invalidate_command_table *inv_tbl,
  303. unsigned int num_invalidate, unsigned int cid,
  304. struct be_dma_mem *nonemb_cmd)
  305. {
  306. struct be_ctrl_info *ctrl = &phba->ctrl;
  307. struct be_mcc_wrb *wrb;
  308. struct be_sge *sge;
  309. struct invalidate_commands_params_in *req;
  310. unsigned int i, tag = 0;
  311. spin_lock(&ctrl->mbox_lock);
  312. tag = alloc_mcc_tag(phba);
  313. if (!tag) {
  314. spin_unlock(&ctrl->mbox_lock);
  315. return tag;
  316. }
  317. req = nonemb_cmd->va;
  318. memset(req, 0, sizeof(*req));
  319. wrb = wrb_from_mccq(phba);
  320. sge = nonembedded_sgl(wrb);
  321. wrb->tag0 |= tag;
  322. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  323. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  324. OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
  325. sizeof(*req));
  326. req->ref_handle = 0;
  327. req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
  328. for (i = 0; i < num_invalidate; i++) {
  329. req->table[i].icd = inv_tbl->icd;
  330. req->table[i].cid = inv_tbl->cid;
  331. req->icd_count++;
  332. inv_tbl++;
  333. }
  334. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  335. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  336. sge->len = cpu_to_le32(nonemb_cmd->size);
  337. be_mcc_notify(phba);
  338. spin_unlock(&ctrl->mbox_lock);
  339. return tag;
  340. }
  341. unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
  342. struct beiscsi_endpoint *beiscsi_ep,
  343. unsigned short cid,
  344. unsigned short issue_reset,
  345. unsigned short savecfg_flag)
  346. {
  347. struct be_ctrl_info *ctrl = &phba->ctrl;
  348. struct be_mcc_wrb *wrb;
  349. struct iscsi_invalidate_connection_params_in *req;
  350. unsigned int tag = 0;
  351. spin_lock(&ctrl->mbox_lock);
  352. tag = alloc_mcc_tag(phba);
  353. if (!tag) {
  354. spin_unlock(&ctrl->mbox_lock);
  355. return tag;
  356. }
  357. wrb = wrb_from_mccq(phba);
  358. wrb->tag0 |= tag;
  359. req = embedded_payload(wrb);
  360. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  361. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  362. OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
  363. sizeof(*req));
  364. req->session_handle = beiscsi_ep->fw_handle;
  365. req->cid = cid;
  366. if (issue_reset)
  367. req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
  368. else
  369. req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
  370. req->save_cfg = savecfg_flag;
  371. be_mcc_notify(phba);
  372. spin_unlock(&ctrl->mbox_lock);
  373. return tag;
  374. }
  375. unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
  376. unsigned short cid, unsigned int upload_flag)
  377. {
  378. struct be_ctrl_info *ctrl = &phba->ctrl;
  379. struct be_mcc_wrb *wrb;
  380. struct tcp_upload_params_in *req;
  381. unsigned int tag = 0;
  382. spin_lock(&ctrl->mbox_lock);
  383. tag = alloc_mcc_tag(phba);
  384. if (!tag) {
  385. spin_unlock(&ctrl->mbox_lock);
  386. return tag;
  387. }
  388. wrb = wrb_from_mccq(phba);
  389. req = embedded_payload(wrb);
  390. wrb->tag0 |= tag;
  391. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  392. be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
  393. OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
  394. req->id = (unsigned short)cid;
  395. req->upload_type = (unsigned char)upload_flag;
  396. be_mcc_notify(phba);
  397. spin_unlock(&ctrl->mbox_lock);
  398. return tag;
  399. }
  400. int mgmt_open_connection(struct beiscsi_hba *phba,
  401. struct sockaddr *dst_addr,
  402. struct beiscsi_endpoint *beiscsi_ep,
  403. struct be_dma_mem *nonemb_cmd)
  404. {
  405. struct hwi_controller *phwi_ctrlr;
  406. struct hwi_context_memory *phwi_context;
  407. struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
  408. struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
  409. struct be_ctrl_info *ctrl = &phba->ctrl;
  410. struct be_mcc_wrb *wrb;
  411. struct tcp_connect_and_offload_in *req;
  412. unsigned short def_hdr_id;
  413. unsigned short def_data_id;
  414. struct phys_addr template_address = { 0, 0 };
  415. struct phys_addr *ptemplate_address;
  416. unsigned int tag = 0;
  417. unsigned int i;
  418. unsigned short cid = beiscsi_ep->ep_cid;
  419. struct be_sge *sge;
  420. phwi_ctrlr = phba->phwi_ctrlr;
  421. phwi_context = phwi_ctrlr->phwi_ctxt;
  422. def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba);
  423. def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba);
  424. ptemplate_address = &template_address;
  425. ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
  426. spin_lock(&ctrl->mbox_lock);
  427. tag = alloc_mcc_tag(phba);
  428. if (!tag) {
  429. spin_unlock(&ctrl->mbox_lock);
  430. return tag;
  431. }
  432. wrb = wrb_from_mccq(phba);
  433. memset(wrb, 0, sizeof(*wrb));
  434. sge = nonembedded_sgl(wrb);
  435. req = nonemb_cmd->va;
  436. memset(req, 0, sizeof(*req));
  437. wrb->tag0 |= tag;
  438. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  439. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  440. OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
  441. sizeof(*req));
  442. if (dst_addr->sa_family == PF_INET) {
  443. __be32 s_addr = daddr_in->sin_addr.s_addr;
  444. req->ip_address.ip_type = BE2_IPV4;
  445. req->ip_address.addr[0] = s_addr & 0x000000ff;
  446. req->ip_address.addr[1] = (s_addr & 0x0000ff00) >> 8;
  447. req->ip_address.addr[2] = (s_addr & 0x00ff0000) >> 16;
  448. req->ip_address.addr[3] = (s_addr & 0xff000000) >> 24;
  449. req->tcp_port = ntohs(daddr_in->sin_port);
  450. beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
  451. beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
  452. beiscsi_ep->ip_type = BE2_IPV4;
  453. } else if (dst_addr->sa_family == PF_INET6) {
  454. req->ip_address.ip_type = BE2_IPV6;
  455. memcpy(&req->ip_address.addr,
  456. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  457. req->tcp_port = ntohs(daddr_in6->sin6_port);
  458. beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
  459. memcpy(&beiscsi_ep->dst6_addr,
  460. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  461. beiscsi_ep->ip_type = BE2_IPV6;
  462. } else{
  463. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  464. "BG_%d : unknown addr family %d\n",
  465. dst_addr->sa_family);
  466. spin_unlock(&ctrl->mbox_lock);
  467. free_mcc_tag(&phba->ctrl, tag);
  468. return -EINVAL;
  469. }
  470. req->cid = cid;
  471. i = phba->nxt_cqid++;
  472. if (phba->nxt_cqid == phba->num_cpus)
  473. phba->nxt_cqid = 0;
  474. req->cq_id = phwi_context->be_cq[i].id;
  475. beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
  476. "BG_%d : i=%d cq_id=%d\n", i, req->cq_id);
  477. req->defq_id = def_hdr_id;
  478. req->hdr_ring_id = def_hdr_id;
  479. req->data_ring_id = def_data_id;
  480. req->do_offload = 1;
  481. req->dataout_template_pa.lo = ptemplate_address->lo;
  482. req->dataout_template_pa.hi = ptemplate_address->hi;
  483. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  484. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  485. sge->len = cpu_to_le32(nonemb_cmd->size);
  486. be_mcc_notify(phba);
  487. spin_unlock(&ctrl->mbox_lock);
  488. return tag;
  489. }
  490. unsigned int mgmt_get_all_if_id(struct beiscsi_hba *phba)
  491. {
  492. struct be_ctrl_info *ctrl = &phba->ctrl;
  493. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  494. struct be_cmd_get_all_if_id_req *req = embedded_payload(wrb);
  495. struct be_cmd_get_all_if_id_req *pbe_allid = req;
  496. int status = 0;
  497. memset(wrb, 0, sizeof(*wrb));
  498. spin_lock(&ctrl->mbox_lock);
  499. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  500. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  501. OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID,
  502. sizeof(*req));
  503. status = be_mbox_notify(ctrl);
  504. if (!status)
  505. phba->interface_handle = pbe_allid->if_hndl_list[0];
  506. else {
  507. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  508. "BG_%d : Failed in mgmt_get_all_if_id\n");
  509. }
  510. spin_unlock(&ctrl->mbox_lock);
  511. return status;
  512. }
  513. static int mgmt_exec_nonemb_cmd(struct beiscsi_hba *phba,
  514. struct be_dma_mem *nonemb_cmd, void *resp_buf,
  515. int resp_buf_len)
  516. {
  517. struct be_ctrl_info *ctrl = &phba->ctrl;
  518. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  519. unsigned short status, extd_status;
  520. struct be_sge *sge;
  521. unsigned int tag;
  522. int rc = 0;
  523. spin_lock(&ctrl->mbox_lock);
  524. tag = alloc_mcc_tag(phba);
  525. if (!tag) {
  526. spin_unlock(&ctrl->mbox_lock);
  527. rc = -ENOMEM;
  528. goto free_cmd;
  529. }
  530. memset(wrb, 0, sizeof(*wrb));
  531. wrb->tag0 |= tag;
  532. sge = nonembedded_sgl(wrb);
  533. be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
  534. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  535. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  536. sge->len = cpu_to_le32(nonemb_cmd->size);
  537. be_mcc_notify(phba);
  538. spin_unlock(&ctrl->mbox_lock);
  539. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  540. phba->ctrl.mcc_numtag[tag]);
  541. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  542. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  543. if (status || extd_status) {
  544. beiscsi_log(phba, KERN_ERR,
  545. BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
  546. "BG_%d : mgmt_exec_nonemb_cmd Failed status = %d"
  547. "extd_status = %d\n", status, extd_status);
  548. rc = -EIO;
  549. goto free_tag;
  550. }
  551. if (resp_buf)
  552. memcpy(resp_buf, nonemb_cmd->va, resp_buf_len);
  553. free_tag:
  554. free_mcc_tag(&phba->ctrl, tag);
  555. free_cmd:
  556. pci_free_consistent(ctrl->pdev, nonemb_cmd->size,
  557. nonemb_cmd->va, nonemb_cmd->dma);
  558. return rc;
  559. }
  560. static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd,
  561. int iscsi_cmd, int size)
  562. {
  563. cmd->va = pci_alloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
  564. if (!cmd->va) {
  565. beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
  566. "BG_%d : Failed to allocate memory for if info\n");
  567. return -ENOMEM;
  568. }
  569. memset(cmd->va, 0, size);
  570. cmd->size = size;
  571. be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size);
  572. return 0;
  573. }
  574. static int
  575. mgmt_static_ip_modify(struct beiscsi_hba *phba,
  576. struct be_cmd_get_if_info_resp *if_info,
  577. struct iscsi_iface_param_info *ip_param,
  578. struct iscsi_iface_param_info *subnet_param,
  579. uint32_t ip_action)
  580. {
  581. struct be_cmd_set_ip_addr_req *req;
  582. struct be_dma_mem nonemb_cmd;
  583. uint32_t ip_type;
  584. int rc;
  585. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  586. OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR,
  587. sizeof(*req));
  588. if (rc)
  589. return rc;
  590. ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
  591. BE2_IPV6 : BE2_IPV4 ;
  592. req = nonemb_cmd.va;
  593. req->ip_params.record_entry_count = 1;
  594. req->ip_params.ip_record.action = ip_action;
  595. req->ip_params.ip_record.interface_hndl =
  596. phba->interface_handle;
  597. req->ip_params.ip_record.ip_addr.size_of_structure =
  598. sizeof(struct be_ip_addr_subnet_format);
  599. req->ip_params.ip_record.ip_addr.ip_type = ip_type;
  600. if (ip_action == IP_ACTION_ADD) {
  601. memcpy(req->ip_params.ip_record.ip_addr.addr, ip_param->value,
  602. ip_param->len);
  603. if (subnet_param)
  604. memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
  605. subnet_param->value, subnet_param->len);
  606. } else {
  607. memcpy(req->ip_params.ip_record.ip_addr.addr,
  608. if_info->ip_addr.addr, ip_param->len);
  609. memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
  610. if_info->ip_addr.subnet_mask, ip_param->len);
  611. }
  612. rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  613. if (rc < 0)
  614. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  615. "BG_%d : Failed to Modify existing IP Address\n");
  616. return rc;
  617. }
  618. static int mgmt_modify_gateway(struct beiscsi_hba *phba, uint8_t *gt_addr,
  619. uint32_t gtway_action, uint32_t param_len)
  620. {
  621. struct be_cmd_set_def_gateway_req *req;
  622. struct be_dma_mem nonemb_cmd;
  623. int rt_val;
  624. rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  625. OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY,
  626. sizeof(*req));
  627. if (rt_val)
  628. return rt_val;
  629. req = nonemb_cmd.va;
  630. req->action = gtway_action;
  631. req->ip_addr.ip_type = BE2_IPV4;
  632. memcpy(req->ip_addr.addr, gt_addr, param_len);
  633. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  634. }
  635. int mgmt_set_ip(struct beiscsi_hba *phba,
  636. struct iscsi_iface_param_info *ip_param,
  637. struct iscsi_iface_param_info *subnet_param,
  638. uint32_t boot_proto)
  639. {
  640. struct be_cmd_get_def_gateway_resp gtway_addr_set;
  641. struct be_cmd_get_if_info_resp if_info;
  642. struct be_cmd_set_dhcp_req *dhcpreq;
  643. struct be_cmd_rel_dhcp_req *reldhcp;
  644. struct be_dma_mem nonemb_cmd;
  645. uint8_t *gtway_addr;
  646. uint32_t ip_type;
  647. int rc;
  648. if (mgmt_get_all_if_id(phba))
  649. return -EIO;
  650. memset(&if_info, 0, sizeof(if_info));
  651. ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
  652. BE2_IPV6 : BE2_IPV4 ;
  653. rc = mgmt_get_if_info(phba, ip_type, &if_info);
  654. if (rc)
  655. return rc;
  656. if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
  657. if (if_info.dhcp_state) {
  658. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  659. "BG_%d : DHCP Already Enabled\n");
  660. return 0;
  661. }
  662. /* The ip_param->len is 1 in DHCP case. Setting
  663. proper IP len as this it is used while
  664. freeing the Static IP.
  665. */
  666. ip_param->len = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
  667. IP_V6_LEN : IP_V4_LEN;
  668. } else {
  669. if (if_info.dhcp_state) {
  670. memset(&if_info, 0, sizeof(if_info));
  671. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  672. OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR,
  673. sizeof(*reldhcp));
  674. if (rc)
  675. return rc;
  676. reldhcp = nonemb_cmd.va;
  677. reldhcp->interface_hndl = phba->interface_handle;
  678. reldhcp->ip_type = ip_type;
  679. rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  680. if (rc < 0) {
  681. beiscsi_log(phba, KERN_WARNING,
  682. BEISCSI_LOG_CONFIG,
  683. "BG_%d : Failed to Delete existing dhcp\n");
  684. return rc;
  685. }
  686. }
  687. }
  688. /* Delete the Static IP Set */
  689. if (if_info.ip_addr.addr[0]) {
  690. rc = mgmt_static_ip_modify(phba, &if_info, ip_param, NULL,
  691. IP_ACTION_DEL);
  692. if (rc)
  693. return rc;
  694. }
  695. /* Delete the Gateway settings if mode change is to DHCP */
  696. if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
  697. memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
  698. rc = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
  699. if (rc) {
  700. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  701. "BG_%d : Failed to Get Gateway Addr\n");
  702. return rc;
  703. }
  704. if (gtway_addr_set.ip_addr.addr[0]) {
  705. gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
  706. rc = mgmt_modify_gateway(phba, gtway_addr,
  707. IP_ACTION_DEL, IP_V4_LEN);
  708. if (rc) {
  709. beiscsi_log(phba, KERN_WARNING,
  710. BEISCSI_LOG_CONFIG,
  711. "BG_%d : Failed to clear Gateway Addr Set\n");
  712. return rc;
  713. }
  714. }
  715. }
  716. /* Set Adapter to DHCP/Static Mode */
  717. if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
  718. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  719. OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
  720. sizeof(*dhcpreq));
  721. if (rc)
  722. return rc;
  723. dhcpreq = nonemb_cmd.va;
  724. dhcpreq->flags = BLOCKING;
  725. dhcpreq->retry_count = 1;
  726. dhcpreq->interface_hndl = phba->interface_handle;
  727. dhcpreq->ip_type = BE2_DHCP_V4;
  728. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
  729. } else {
  730. return mgmt_static_ip_modify(phba, &if_info, ip_param,
  731. subnet_param, IP_ACTION_ADD);
  732. }
  733. return rc;
  734. }
  735. int mgmt_set_gateway(struct beiscsi_hba *phba,
  736. struct iscsi_iface_param_info *gateway_param)
  737. {
  738. struct be_cmd_get_def_gateway_resp gtway_addr_set;
  739. uint8_t *gtway_addr;
  740. int rt_val;
  741. memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
  742. rt_val = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
  743. if (rt_val) {
  744. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  745. "BG_%d : Failed to Get Gateway Addr\n");
  746. return rt_val;
  747. }
  748. if (gtway_addr_set.ip_addr.addr[0]) {
  749. gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
  750. rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_DEL,
  751. gateway_param->len);
  752. if (rt_val) {
  753. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  754. "BG_%d : Failed to clear Gateway Addr Set\n");
  755. return rt_val;
  756. }
  757. }
  758. gtway_addr = (uint8_t *)&gateway_param->value;
  759. rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_ADD,
  760. gateway_param->len);
  761. if (rt_val)
  762. beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
  763. "BG_%d : Failed to Set Gateway Addr\n");
  764. return rt_val;
  765. }
  766. int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type,
  767. struct be_cmd_get_def_gateway_resp *gateway)
  768. {
  769. struct be_cmd_get_def_gateway_req *req;
  770. struct be_dma_mem nonemb_cmd;
  771. int rc;
  772. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  773. OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY,
  774. sizeof(*gateway));
  775. if (rc)
  776. return rc;
  777. req = nonemb_cmd.va;
  778. req->ip_type = ip_type;
  779. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, gateway,
  780. sizeof(*gateway));
  781. }
  782. int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type,
  783. struct be_cmd_get_if_info_resp *if_info)
  784. {
  785. struct be_cmd_get_if_info_req *req;
  786. struct be_dma_mem nonemb_cmd;
  787. int rc;
  788. if (mgmt_get_all_if_id(phba))
  789. return -EIO;
  790. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  791. OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO,
  792. sizeof(*if_info));
  793. if (rc)
  794. return rc;
  795. req = nonemb_cmd.va;
  796. req->interface_hndl = phba->interface_handle;
  797. req->ip_type = ip_type;
  798. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, if_info,
  799. sizeof(*if_info));
  800. }
  801. int mgmt_get_nic_conf(struct beiscsi_hba *phba,
  802. struct be_cmd_get_nic_conf_resp *nic)
  803. {
  804. struct be_dma_mem nonemb_cmd;
  805. int rc;
  806. rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
  807. OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
  808. sizeof(*nic));
  809. if (rc)
  810. return rc;
  811. return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic));
  812. }
  813. unsigned int be_cmd_get_initname(struct beiscsi_hba *phba)
  814. {
  815. unsigned int tag = 0;
  816. struct be_mcc_wrb *wrb;
  817. struct be_cmd_hba_name *req;
  818. struct be_ctrl_info *ctrl = &phba->ctrl;
  819. spin_lock(&ctrl->mbox_lock);
  820. tag = alloc_mcc_tag(phba);
  821. if (!tag) {
  822. spin_unlock(&ctrl->mbox_lock);
  823. return tag;
  824. }
  825. wrb = wrb_from_mccq(phba);
  826. req = embedded_payload(wrb);
  827. wrb->tag0 |= tag;
  828. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  829. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  830. OPCODE_ISCSI_INI_CFG_GET_HBA_NAME,
  831. sizeof(*req));
  832. be_mcc_notify(phba);
  833. spin_unlock(&ctrl->mbox_lock);
  834. return tag;
  835. }
  836. unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba)
  837. {
  838. unsigned int tag = 0;
  839. struct be_mcc_wrb *wrb;
  840. struct be_cmd_ntwk_link_status_req *req;
  841. struct be_ctrl_info *ctrl = &phba->ctrl;
  842. spin_lock(&ctrl->mbox_lock);
  843. tag = alloc_mcc_tag(phba);
  844. if (!tag) {
  845. spin_unlock(&ctrl->mbox_lock);
  846. return tag;
  847. }
  848. wrb = wrb_from_mccq(phba);
  849. req = embedded_payload(wrb);
  850. wrb->tag0 |= tag;
  851. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  852. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  853. OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
  854. sizeof(*req));
  855. be_mcc_notify(phba);
  856. spin_unlock(&ctrl->mbox_lock);
  857. return tag;
  858. }
  859. /**
  860. * be_mgmt_get_boot_shandle()- Get the session handle
  861. * @phba: device priv structure instance
  862. * @s_handle: session handle returned for boot session.
  863. *
  864. * Get the boot target session handle. In case of
  865. * crashdump mode driver has to issue and MBX Cmd
  866. * for FW to login to boot target
  867. *
  868. * return
  869. * Success: 0
  870. * Failure: Non-Zero value
  871. *
  872. **/
  873. int be_mgmt_get_boot_shandle(struct beiscsi_hba *phba,
  874. unsigned int *s_handle)
  875. {
  876. struct be_cmd_get_boot_target_resp *boot_resp;
  877. struct be_mcc_wrb *wrb;
  878. unsigned int tag, wrb_num;
  879. uint8_t boot_retry = 3;
  880. unsigned short status, extd_status;
  881. struct be_queue_info *mccq = &phba->ctrl.mcc_obj.q;
  882. do {
  883. /* Get the Boot Target Session Handle and Count*/
  884. tag = mgmt_get_boot_target(phba);
  885. if (!tag) {
  886. beiscsi_log(phba, KERN_ERR,
  887. BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
  888. "BG_%d : Getting Boot Target Info Failed\n");
  889. return -EAGAIN;
  890. } else
  891. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  892. phba->ctrl.mcc_numtag[tag]);
  893. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  894. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  895. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  896. if (status || extd_status) {
  897. beiscsi_log(phba, KERN_ERR,
  898. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  899. "BG_%d : mgmt_get_boot_target Failed"
  900. " status = %d extd_status = %d\n",
  901. status, extd_status);
  902. free_mcc_tag(&phba->ctrl, tag);
  903. return -EBUSY;
  904. }
  905. wrb = queue_get_wrb(mccq, wrb_num);
  906. free_mcc_tag(&phba->ctrl, tag);
  907. boot_resp = embedded_payload(wrb);
  908. /* Check if the there are any Boot targets configured */
  909. if (!boot_resp->boot_session_count) {
  910. beiscsi_log(phba, KERN_INFO,
  911. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  912. "BG_%d ;No boot targets configured\n");
  913. return -ENXIO;
  914. }
  915. /* FW returns the session handle of the boot session */
  916. if (boot_resp->boot_session_handle != INVALID_SESS_HANDLE) {
  917. *s_handle = boot_resp->boot_session_handle;
  918. return 0;
  919. }
  920. /* Issue MBX Cmd to FW to login to the boot target */
  921. tag = mgmt_reopen_session(phba, BE_REOPEN_BOOT_SESSIONS,
  922. INVALID_SESS_HANDLE);
  923. if (!tag) {
  924. beiscsi_log(phba, KERN_ERR,
  925. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  926. "BG_%d : mgmt_reopen_session Failed\n");
  927. return -EAGAIN;
  928. } else
  929. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  930. phba->ctrl.mcc_numtag[tag]);
  931. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  932. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  933. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  934. if (status || extd_status) {
  935. beiscsi_log(phba, KERN_ERR,
  936. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  937. "BG_%d : mgmt_reopen_session Failed"
  938. " status = %d extd_status = %d\n",
  939. status, extd_status);
  940. free_mcc_tag(&phba->ctrl, tag);
  941. return -EBUSY;
  942. }
  943. free_mcc_tag(&phba->ctrl, tag);
  944. } while (--boot_retry);
  945. /* Couldn't log into the boot target */
  946. beiscsi_log(phba, KERN_ERR,
  947. BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
  948. "BG_%d : Login to Boot Target Failed\n");
  949. return -ENXIO;
  950. }
  951. /**
  952. * mgmt_set_vlan()- Issue and wait for CMD completion
  953. * @phba: device private structure instance
  954. * @vlan_tag: VLAN tag
  955. *
  956. * Issue the MBX Cmd and wait for the completion of the
  957. * command.
  958. *
  959. * returns
  960. * Success: 0
  961. * Failure: Non-Xero Value
  962. **/
  963. int mgmt_set_vlan(struct beiscsi_hba *phba,
  964. uint16_t vlan_tag)
  965. {
  966. unsigned int tag, wrb_num;
  967. unsigned short status, extd_status;
  968. tag = be_cmd_set_vlan(phba, vlan_tag);
  969. if (!tag) {
  970. beiscsi_log(phba, KERN_ERR,
  971. (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
  972. "BG_%d : VLAN Setting Failed\n");
  973. return -EBUSY;
  974. } else
  975. wait_event_interruptible(phba->ctrl.mcc_wait[tag],
  976. phba->ctrl.mcc_numtag[tag]);
  977. wrb_num = (phba->ctrl.mcc_numtag[tag] & 0x00FF0000) >> 16;
  978. extd_status = (phba->ctrl.mcc_numtag[tag] & 0x0000FF00) >> 8;
  979. status = phba->ctrl.mcc_numtag[tag] & 0x000000FF;
  980. if (status || extd_status) {
  981. beiscsi_log(phba, KERN_ERR,
  982. (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
  983. "BS_%d : status : %d extd_status : %d\n",
  984. status, extd_status);
  985. free_mcc_tag(&phba->ctrl, tag);
  986. return -EAGAIN;
  987. }
  988. free_mcc_tag(&phba->ctrl, tag);
  989. return 0;
  990. }