be_mgmt.c 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450
  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 "be_mgmt.h"
  20. #include "be_iscsi.h"
  21. #include <scsi/scsi_transport_iscsi.h>
  22. unsigned int beiscsi_get_boot_target(struct beiscsi_hba *phba)
  23. {
  24. struct be_ctrl_info *ctrl = &phba->ctrl;
  25. struct be_mcc_wrb *wrb;
  26. struct be_cmd_req_get_mac_addr *req;
  27. unsigned int tag = 0;
  28. SE_DEBUG(DBG_LVL_8, "In bescsi_get_boot_target\n");
  29. spin_lock(&ctrl->mbox_lock);
  30. tag = alloc_mcc_tag(phba);
  31. if (!tag) {
  32. spin_unlock(&ctrl->mbox_lock);
  33. return tag;
  34. }
  35. wrb = wrb_from_mccq(phba);
  36. req = embedded_payload(wrb);
  37. wrb->tag0 |= tag;
  38. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  39. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  40. OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET,
  41. sizeof(*req));
  42. be_mcc_notify(phba);
  43. spin_unlock(&ctrl->mbox_lock);
  44. return tag;
  45. }
  46. unsigned int beiscsi_get_session_info(struct beiscsi_hba *phba,
  47. u32 boot_session_handle,
  48. struct be_dma_mem *nonemb_cmd)
  49. {
  50. struct be_ctrl_info *ctrl = &phba->ctrl;
  51. struct be_mcc_wrb *wrb;
  52. unsigned int tag = 0;
  53. struct be_cmd_req_get_session *req;
  54. struct be_cmd_resp_get_session *resp;
  55. struct be_sge *sge;
  56. SE_DEBUG(DBG_LVL_8, "In beiscsi_get_session_info\n");
  57. spin_lock(&ctrl->mbox_lock);
  58. tag = alloc_mcc_tag(phba);
  59. if (!tag) {
  60. spin_unlock(&ctrl->mbox_lock);
  61. return tag;
  62. }
  63. nonemb_cmd->size = sizeof(*resp);
  64. req = nonemb_cmd->va;
  65. memset(req, 0, sizeof(*req));
  66. wrb = wrb_from_mccq(phba);
  67. sge = nonembedded_sgl(wrb);
  68. wrb->tag0 |= tag;
  69. wrb->tag0 |= tag;
  70. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  71. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  72. OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
  73. sizeof(*resp));
  74. req->session_handle = boot_session_handle;
  75. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  76. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  77. sge->len = cpu_to_le32(nonemb_cmd->size);
  78. be_mcc_notify(phba);
  79. spin_unlock(&ctrl->mbox_lock);
  80. return tag;
  81. }
  82. int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
  83. struct beiscsi_hba *phba)
  84. {
  85. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  86. struct be_fw_cfg *req = embedded_payload(wrb);
  87. int status = 0;
  88. spin_lock(&ctrl->mbox_lock);
  89. memset(wrb, 0, sizeof(*wrb));
  90. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  91. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  92. OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
  93. status = be_mbox_notify(ctrl);
  94. if (!status) {
  95. struct be_fw_cfg *pfw_cfg;
  96. pfw_cfg = req;
  97. phba->fw_config.phys_port = pfw_cfg->phys_port;
  98. phba->fw_config.iscsi_icd_start =
  99. pfw_cfg->ulp[0].icd_base;
  100. phba->fw_config.iscsi_icd_count =
  101. pfw_cfg->ulp[0].icd_count;
  102. phba->fw_config.iscsi_cid_start =
  103. pfw_cfg->ulp[0].sq_base;
  104. phba->fw_config.iscsi_cid_count =
  105. pfw_cfg->ulp[0].sq_count;
  106. if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
  107. SE_DEBUG(DBG_LVL_8,
  108. "FW reported MAX CXNS as %d\t"
  109. "Max Supported = %d.\n",
  110. phba->fw_config.iscsi_cid_count,
  111. BE2_MAX_SESSIONS);
  112. phba->fw_config.iscsi_cid_count = BE2_MAX_SESSIONS / 2;
  113. }
  114. } else {
  115. shost_printk(KERN_WARNING, phba->shost,
  116. "Failed in mgmt_get_fw_config\n");
  117. }
  118. spin_unlock(&ctrl->mbox_lock);
  119. return status;
  120. }
  121. int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
  122. struct beiscsi_hba *phba)
  123. {
  124. struct be_dma_mem nonemb_cmd;
  125. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  126. struct be_mgmt_controller_attributes *req;
  127. struct be_sge *sge = nonembedded_sgl(wrb);
  128. int status = 0;
  129. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  130. sizeof(struct be_mgmt_controller_attributes),
  131. &nonemb_cmd.dma);
  132. if (nonemb_cmd.va == NULL) {
  133. SE_DEBUG(DBG_LVL_1,
  134. "Failed to allocate memory for mgmt_check_supported_fw"
  135. "\n");
  136. return -ENOMEM;
  137. }
  138. nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
  139. req = nonemb_cmd.va;
  140. memset(req, 0, sizeof(*req));
  141. spin_lock(&ctrl->mbox_lock);
  142. memset(wrb, 0, sizeof(*wrb));
  143. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  144. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  145. OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
  146. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  147. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  148. sge->len = cpu_to_le32(nonemb_cmd.size);
  149. status = be_mbox_notify(ctrl);
  150. if (!status) {
  151. struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
  152. SE_DEBUG(DBG_LVL_8, "Firmware version of CMD: %s\n",
  153. resp->params.hba_attribs.flashrom_version_string);
  154. SE_DEBUG(DBG_LVL_8, "Firmware version is : %s\n",
  155. resp->params.hba_attribs.firmware_version_string);
  156. SE_DEBUG(DBG_LVL_8,
  157. "Developer Build, not performing version check...\n");
  158. phba->fw_config.iscsi_features =
  159. resp->params.hba_attribs.iscsi_features;
  160. SE_DEBUG(DBG_LVL_8, " phba->fw_config.iscsi_features = %d\n",
  161. phba->fw_config.iscsi_features);
  162. } else
  163. SE_DEBUG(DBG_LVL_1, " Failed in mgmt_check_supported_fw\n");
  164. spin_unlock(&ctrl->mbox_lock);
  165. if (nonemb_cmd.va)
  166. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  167. nonemb_cmd.va, nonemb_cmd.dma);
  168. return status;
  169. }
  170. int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
  171. {
  172. struct be_ctrl_info *ctrl = &phba->ctrl;
  173. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  174. struct iscsi_cleanup_req *req = embedded_payload(wrb);
  175. int status = 0;
  176. spin_lock(&ctrl->mbox_lock);
  177. memset(wrb, 0, sizeof(*wrb));
  178. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  179. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  180. OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
  181. req->chute = chute;
  182. req->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba));
  183. req->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba));
  184. status = be_mcc_notify_wait(phba);
  185. if (status)
  186. shost_printk(KERN_WARNING, phba->shost,
  187. " mgmt_epfw_cleanup , FAILED\n");
  188. spin_unlock(&ctrl->mbox_lock);
  189. return status;
  190. }
  191. unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
  192. struct invalidate_command_table *inv_tbl,
  193. unsigned int num_invalidate, unsigned int cid,
  194. struct be_dma_mem *nonemb_cmd)
  195. {
  196. struct be_ctrl_info *ctrl = &phba->ctrl;
  197. struct be_mcc_wrb *wrb;
  198. struct be_sge *sge;
  199. struct invalidate_commands_params_in *req;
  200. unsigned int i, tag = 0;
  201. spin_lock(&ctrl->mbox_lock);
  202. tag = alloc_mcc_tag(phba);
  203. if (!tag) {
  204. spin_unlock(&ctrl->mbox_lock);
  205. return tag;
  206. }
  207. req = nonemb_cmd->va;
  208. memset(req, 0, sizeof(*req));
  209. wrb = wrb_from_mccq(phba);
  210. sge = nonembedded_sgl(wrb);
  211. wrb->tag0 |= tag;
  212. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  213. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  214. OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
  215. sizeof(*req));
  216. req->ref_handle = 0;
  217. req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
  218. for (i = 0; i < num_invalidate; i++) {
  219. req->table[i].icd = inv_tbl->icd;
  220. req->table[i].cid = inv_tbl->cid;
  221. req->icd_count++;
  222. inv_tbl++;
  223. }
  224. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  225. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  226. sge->len = cpu_to_le32(nonemb_cmd->size);
  227. be_mcc_notify(phba);
  228. spin_unlock(&ctrl->mbox_lock);
  229. return tag;
  230. }
  231. unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
  232. struct beiscsi_endpoint *beiscsi_ep,
  233. unsigned short cid,
  234. unsigned short issue_reset,
  235. unsigned short savecfg_flag)
  236. {
  237. struct be_ctrl_info *ctrl = &phba->ctrl;
  238. struct be_mcc_wrb *wrb;
  239. struct iscsi_invalidate_connection_params_in *req;
  240. unsigned int tag = 0;
  241. spin_lock(&ctrl->mbox_lock);
  242. tag = alloc_mcc_tag(phba);
  243. if (!tag) {
  244. spin_unlock(&ctrl->mbox_lock);
  245. return tag;
  246. }
  247. wrb = wrb_from_mccq(phba);
  248. wrb->tag0 |= tag;
  249. req = embedded_payload(wrb);
  250. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  251. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  252. OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
  253. sizeof(*req));
  254. req->session_handle = beiscsi_ep->fw_handle;
  255. req->cid = cid;
  256. if (issue_reset)
  257. req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
  258. else
  259. req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
  260. req->save_cfg = savecfg_flag;
  261. be_mcc_notify(phba);
  262. spin_unlock(&ctrl->mbox_lock);
  263. return tag;
  264. }
  265. unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
  266. unsigned short cid, unsigned int upload_flag)
  267. {
  268. struct be_ctrl_info *ctrl = &phba->ctrl;
  269. struct be_mcc_wrb *wrb;
  270. struct tcp_upload_params_in *req;
  271. unsigned int tag = 0;
  272. spin_lock(&ctrl->mbox_lock);
  273. tag = alloc_mcc_tag(phba);
  274. if (!tag) {
  275. spin_unlock(&ctrl->mbox_lock);
  276. return tag;
  277. }
  278. wrb = wrb_from_mccq(phba);
  279. req = embedded_payload(wrb);
  280. wrb->tag0 |= tag;
  281. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  282. be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
  283. OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
  284. req->id = (unsigned short)cid;
  285. req->upload_type = (unsigned char)upload_flag;
  286. be_mcc_notify(phba);
  287. spin_unlock(&ctrl->mbox_lock);
  288. return tag;
  289. }
  290. int mgmt_open_connection(struct beiscsi_hba *phba,
  291. struct sockaddr *dst_addr,
  292. struct beiscsi_endpoint *beiscsi_ep,
  293. struct be_dma_mem *nonemb_cmd)
  294. {
  295. struct hwi_controller *phwi_ctrlr;
  296. struct hwi_context_memory *phwi_context;
  297. struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
  298. struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
  299. struct be_ctrl_info *ctrl = &phba->ctrl;
  300. struct be_mcc_wrb *wrb;
  301. struct tcp_connect_and_offload_in *req;
  302. unsigned short def_hdr_id;
  303. unsigned short def_data_id;
  304. struct phys_addr template_address = { 0, 0 };
  305. struct phys_addr *ptemplate_address;
  306. unsigned int tag = 0;
  307. unsigned int i;
  308. unsigned short cid = beiscsi_ep->ep_cid;
  309. struct be_sge *sge;
  310. phwi_ctrlr = phba->phwi_ctrlr;
  311. phwi_context = phwi_ctrlr->phwi_ctxt;
  312. def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba);
  313. def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba);
  314. ptemplate_address = &template_address;
  315. ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
  316. spin_lock(&ctrl->mbox_lock);
  317. tag = alloc_mcc_tag(phba);
  318. if (!tag) {
  319. spin_unlock(&ctrl->mbox_lock);
  320. return tag;
  321. }
  322. wrb = wrb_from_mccq(phba);
  323. memset(wrb, 0, sizeof(*wrb));
  324. sge = nonembedded_sgl(wrb);
  325. req = nonemb_cmd->va;
  326. memset(req, 0, sizeof(*req));
  327. wrb->tag0 |= tag;
  328. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  329. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  330. OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
  331. sizeof(*req));
  332. if (dst_addr->sa_family == PF_INET) {
  333. __be32 s_addr = daddr_in->sin_addr.s_addr;
  334. req->ip_address.ip_type = BE2_IPV4;
  335. req->ip_address.ip_address[0] = s_addr & 0x000000ff;
  336. req->ip_address.ip_address[1] = (s_addr & 0x0000ff00) >> 8;
  337. req->ip_address.ip_address[2] = (s_addr & 0x00ff0000) >> 16;
  338. req->ip_address.ip_address[3] = (s_addr & 0xff000000) >> 24;
  339. req->tcp_port = ntohs(daddr_in->sin_port);
  340. beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
  341. beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
  342. beiscsi_ep->ip_type = BE2_IPV4;
  343. } else if (dst_addr->sa_family == PF_INET6) {
  344. req->ip_address.ip_type = BE2_IPV6;
  345. memcpy(&req->ip_address.ip_address,
  346. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  347. req->tcp_port = ntohs(daddr_in6->sin6_port);
  348. beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
  349. memcpy(&beiscsi_ep->dst6_addr,
  350. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  351. beiscsi_ep->ip_type = BE2_IPV6;
  352. } else{
  353. shost_printk(KERN_ERR, phba->shost, "unknown addr family %d\n",
  354. dst_addr->sa_family);
  355. spin_unlock(&ctrl->mbox_lock);
  356. free_mcc_tag(&phba->ctrl, tag);
  357. return -EINVAL;
  358. }
  359. req->cid = cid;
  360. i = phba->nxt_cqid++;
  361. if (phba->nxt_cqid == phba->num_cpus)
  362. phba->nxt_cqid = 0;
  363. req->cq_id = phwi_context->be_cq[i].id;
  364. SE_DEBUG(DBG_LVL_8, "i=%d cq_id=%d\n", i, req->cq_id);
  365. req->defq_id = def_hdr_id;
  366. req->hdr_ring_id = def_hdr_id;
  367. req->data_ring_id = def_data_id;
  368. req->do_offload = 1;
  369. req->dataout_template_pa.lo = ptemplate_address->lo;
  370. req->dataout_template_pa.hi = ptemplate_address->hi;
  371. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
  372. sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
  373. sge->len = cpu_to_le32(nonemb_cmd->size);
  374. be_mcc_notify(phba);
  375. spin_unlock(&ctrl->mbox_lock);
  376. return tag;
  377. }
  378. unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba)
  379. {
  380. struct be_ctrl_info *ctrl = &phba->ctrl;
  381. struct be_mcc_wrb *wrb;
  382. struct be_cmd_req_get_mac_addr *req;
  383. unsigned int tag = 0;
  384. SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n");
  385. spin_lock(&ctrl->mbox_lock);
  386. tag = alloc_mcc_tag(phba);
  387. if (!tag) {
  388. spin_unlock(&ctrl->mbox_lock);
  389. return tag;
  390. }
  391. wrb = wrb_from_mccq(phba);
  392. req = embedded_payload(wrb);
  393. wrb->tag0 |= tag;
  394. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  395. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  396. OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
  397. sizeof(*req));
  398. be_mcc_notify(phba);
  399. spin_unlock(&ctrl->mbox_lock);
  400. return tag;
  401. }