be_mgmt.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. /**
  2. * Copyright (C) 2005 - 2009 ServerEngines
  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 (jayamohank@serverengines.com)
  11. *
  12. * Contact Information:
  13. * linux-drivers@serverengines.com
  14. *
  15. * ServerEngines
  16. * 209 N. Fair Oaks Ave
  17. * Sunnyvale, CA 94085
  18. *
  19. */
  20. #include "be_mgmt.h"
  21. #include "be_iscsi.h"
  22. unsigned char mgmt_get_fw_config(struct be_ctrl_info *ctrl,
  23. struct beiscsi_hba *phba)
  24. {
  25. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  26. struct be_fw_cfg *req = embedded_payload(wrb);
  27. int status = 0;
  28. spin_lock(&ctrl->mbox_lock);
  29. memset(wrb, 0, sizeof(*wrb));
  30. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  31. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  32. OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
  33. status = be_mbox_notify(ctrl);
  34. if (!status) {
  35. struct be_fw_cfg *pfw_cfg;
  36. pfw_cfg = req;
  37. phba->fw_config.phys_port = pfw_cfg->phys_port;
  38. phba->fw_config.iscsi_icd_start =
  39. pfw_cfg->ulp[0].icd_base;
  40. phba->fw_config.iscsi_icd_count =
  41. pfw_cfg->ulp[0].icd_count;
  42. phba->fw_config.iscsi_cid_start =
  43. pfw_cfg->ulp[0].sq_base;
  44. phba->fw_config.iscsi_cid_count =
  45. pfw_cfg->ulp[0].sq_count;
  46. } else {
  47. shost_printk(KERN_WARNING, phba->shost,
  48. "Failed in mgmt_get_fw_config \n");
  49. }
  50. spin_unlock(&ctrl->mbox_lock);
  51. return status;
  52. }
  53. unsigned char mgmt_check_supported_fw(struct be_ctrl_info *ctrl)
  54. {
  55. struct be_dma_mem nonemb_cmd;
  56. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  57. struct be_mgmt_controller_attributes *req;
  58. struct be_sge *sge = nonembedded_sgl(wrb);
  59. int status = 0;
  60. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  61. sizeof(struct be_mgmt_controller_attributes),
  62. &nonemb_cmd.dma);
  63. if (nonemb_cmd.va == NULL) {
  64. SE_DEBUG(DBG_LVL_1,
  65. "Failed to allocate memory for mgmt_check_supported_fw"
  66. "\n");
  67. return -1;
  68. }
  69. nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
  70. req = nonemb_cmd.va;
  71. spin_lock(&ctrl->mbox_lock);
  72. memset(wrb, 0, sizeof(*wrb));
  73. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  74. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  75. OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
  76. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  77. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  78. sge->len = cpu_to_le32(nonemb_cmd.size);
  79. status = be_mbox_notify(ctrl);
  80. if (!status) {
  81. struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
  82. SE_DEBUG(DBG_LVL_8, "Firmware version of CMD: %s\n",
  83. resp->params.hba_attribs.flashrom_version_string);
  84. SE_DEBUG(DBG_LVL_8, "Firmware version is : %s\n",
  85. resp->params.hba_attribs.firmware_version_string);
  86. SE_DEBUG(DBG_LVL_8,
  87. "Developer Build, not performing version check...\n");
  88. } else
  89. SE_DEBUG(DBG_LVL_1, " Failed in mgmt_check_supported_fw\n");
  90. if (nonemb_cmd.va)
  91. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  92. nonemb_cmd.va, nonemb_cmd.dma);
  93. spin_unlock(&ctrl->mbox_lock);
  94. return status;
  95. }
  96. unsigned char mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
  97. {
  98. struct be_ctrl_info *ctrl = &phba->ctrl;
  99. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  100. struct iscsi_cleanup_req *req = embedded_payload(wrb);
  101. int status = 0;
  102. spin_lock(&ctrl->mbox_lock);
  103. memset(wrb, 0, sizeof(*wrb));
  104. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  105. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  106. OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
  107. req->chute = chute;
  108. req->hdr_ring_id = 0;
  109. req->data_ring_id = 0;
  110. status = be_mbox_notify(ctrl);
  111. if (status)
  112. shost_printk(KERN_WARNING, phba->shost,
  113. " mgmt_epfw_cleanup , FAILED\n");
  114. spin_unlock(&ctrl->mbox_lock);
  115. return status;
  116. }
  117. unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
  118. unsigned int icd, unsigned int cid)
  119. {
  120. struct be_dma_mem nonemb_cmd;
  121. struct be_ctrl_info *ctrl = &phba->ctrl;
  122. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  123. struct be_sge *sge = nonembedded_sgl(wrb);
  124. struct invalidate_commands_params_in *req;
  125. int status = 0;
  126. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  127. sizeof(struct invalidate_commands_params_in),
  128. &nonemb_cmd.dma);
  129. if (nonemb_cmd.va == NULL) {
  130. SE_DEBUG(DBG_LVL_1,
  131. "Failed to allocate memory for"
  132. "mgmt_invalidate_icds \n");
  133. return -1;
  134. }
  135. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  136. req = nonemb_cmd.va;
  137. spin_lock(&ctrl->mbox_lock);
  138. memset(wrb, 0, sizeof(*wrb));
  139. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  140. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  141. OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
  142. sizeof(*req));
  143. req->ref_handle = 0;
  144. req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
  145. req->icd_count = 0;
  146. req->table[req->icd_count].icd = icd;
  147. req->table[req->icd_count].cid = cid;
  148. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  149. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  150. sge->len = cpu_to_le32(nonemb_cmd.size);
  151. status = be_mbox_notify(ctrl);
  152. if (status)
  153. SE_DEBUG(DBG_LVL_1, "ICDS Invalidation Failed\n");
  154. spin_unlock(&ctrl->mbox_lock);
  155. if (nonemb_cmd.va)
  156. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  157. nonemb_cmd.va, nonemb_cmd.dma);
  158. return status;
  159. }
  160. unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
  161. struct beiscsi_endpoint *beiscsi_ep,
  162. unsigned short cid,
  163. unsigned short issue_reset,
  164. unsigned short savecfg_flag)
  165. {
  166. struct be_ctrl_info *ctrl = &phba->ctrl;
  167. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  168. struct iscsi_invalidate_connection_params_in *req =
  169. embedded_payload(wrb);
  170. int status = 0;
  171. spin_lock(&ctrl->mbox_lock);
  172. memset(wrb, 0, sizeof(*wrb));
  173. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  174. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
  175. OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
  176. sizeof(*req));
  177. req->session_handle = beiscsi_ep->fw_handle;
  178. req->cid = cid;
  179. if (issue_reset)
  180. req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
  181. else
  182. req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
  183. req->save_cfg = savecfg_flag;
  184. status = be_mbox_notify(ctrl);
  185. if (status)
  186. SE_DEBUG(DBG_LVL_1, "Invalidation Failed\n");
  187. spin_unlock(&ctrl->mbox_lock);
  188. return status;
  189. }
  190. unsigned char mgmt_upload_connection(struct beiscsi_hba *phba,
  191. unsigned short cid, unsigned int upload_flag)
  192. {
  193. struct be_ctrl_info *ctrl = &phba->ctrl;
  194. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  195. struct tcp_upload_params_in *req = embedded_payload(wrb);
  196. int status = 0;
  197. spin_lock(&ctrl->mbox_lock);
  198. memset(wrb, 0, sizeof(*wrb));
  199. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  200. be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
  201. OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
  202. req->id = (unsigned short)cid;
  203. req->upload_type = (unsigned char)upload_flag;
  204. status = be_mbox_notify(ctrl);
  205. if (status)
  206. SE_DEBUG(DBG_LVL_1, "mgmt_upload_connection Failed\n");
  207. spin_unlock(&ctrl->mbox_lock);
  208. return status;
  209. }
  210. int mgmt_open_connection(struct beiscsi_hba *phba,
  211. struct sockaddr *dst_addr,
  212. struct beiscsi_endpoint *beiscsi_ep)
  213. {
  214. struct hwi_controller *phwi_ctrlr;
  215. struct hwi_context_memory *phwi_context;
  216. struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
  217. struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
  218. struct be_ctrl_info *ctrl = &phba->ctrl;
  219. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  220. struct tcp_connect_and_offload_in *req = embedded_payload(wrb);
  221. unsigned short def_hdr_id;
  222. unsigned short def_data_id;
  223. struct phys_addr template_address = { 0, 0 };
  224. struct phys_addr *ptemplate_address;
  225. int status = 0;
  226. unsigned short cid = beiscsi_ep->ep_cid;
  227. phwi_ctrlr = phba->phwi_ctrlr;
  228. phwi_context = phwi_ctrlr->phwi_ctxt;
  229. def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba);
  230. def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba);
  231. ptemplate_address = &template_address;
  232. ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
  233. spin_lock(&ctrl->mbox_lock);
  234. memset(wrb, 0, sizeof(*wrb));
  235. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  236. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  237. OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
  238. sizeof(*req));
  239. if (dst_addr->sa_family == PF_INET) {
  240. __be32 s_addr = daddr_in->sin_addr.s_addr;
  241. req->ip_address.ip_type = BE2_IPV4;
  242. req->ip_address.ip_address[0] = s_addr & 0x000000ff;
  243. req->ip_address.ip_address[1] = (s_addr & 0x0000ff00) >> 8;
  244. req->ip_address.ip_address[2] = (s_addr & 0x00ff0000) >> 16;
  245. req->ip_address.ip_address[3] = (s_addr & 0xff000000) >> 24;
  246. req->tcp_port = ntohs(daddr_in->sin_port);
  247. beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
  248. beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
  249. beiscsi_ep->ip_type = BE2_IPV4;
  250. } else if (dst_addr->sa_family == PF_INET6) {
  251. req->ip_address.ip_type = BE2_IPV6;
  252. memcpy(&req->ip_address.ip_address,
  253. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  254. req->tcp_port = ntohs(daddr_in6->sin6_port);
  255. beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
  256. memcpy(&beiscsi_ep->dst6_addr,
  257. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  258. beiscsi_ep->ip_type = BE2_IPV6;
  259. } else{
  260. shost_printk(KERN_ERR, phba->shost, "unknown addr family %d\n",
  261. dst_addr->sa_family);
  262. spin_unlock(&ctrl->mbox_lock);
  263. return -EINVAL;
  264. }
  265. req->cid = cid;
  266. req->cq_id = phwi_context->be_cq.id;
  267. req->defq_id = def_hdr_id;
  268. req->hdr_ring_id = def_hdr_id;
  269. req->data_ring_id = def_data_id;
  270. req->do_offload = 1;
  271. req->dataout_template_pa.lo = ptemplate_address->lo;
  272. req->dataout_template_pa.hi = ptemplate_address->hi;
  273. status = be_mbox_notify(ctrl);
  274. if (!status) {
  275. struct iscsi_endpoint *ep;
  276. struct tcp_connect_and_offload_out *ptcpcnct_out =
  277. embedded_payload(wrb);
  278. ep = phba->ep_array[ptcpcnct_out->cid];
  279. beiscsi_ep = ep->dd_data;
  280. beiscsi_ep->fw_handle = 0;
  281. beiscsi_ep->cid_vld = 1;
  282. SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
  283. } else
  284. SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed\n");
  285. spin_unlock(&ctrl->mbox_lock);
  286. return status;
  287. }