be_mgmt.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. struct beiscsi_hba *phba)
  55. {
  56. struct be_dma_mem nonemb_cmd;
  57. struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
  58. struct be_mgmt_controller_attributes *req;
  59. struct be_sge *sge = nonembedded_sgl(wrb);
  60. int status = 0;
  61. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  62. sizeof(struct be_mgmt_controller_attributes),
  63. &nonemb_cmd.dma);
  64. if (nonemb_cmd.va == NULL) {
  65. SE_DEBUG(DBG_LVL_1,
  66. "Failed to allocate memory for mgmt_check_supported_fw"
  67. "\n");
  68. return -1;
  69. }
  70. nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
  71. req = nonemb_cmd.va;
  72. spin_lock(&ctrl->mbox_lock);
  73. memset(wrb, 0, sizeof(*wrb));
  74. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  75. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
  76. OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
  77. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  78. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  79. sge->len = cpu_to_le32(nonemb_cmd.size);
  80. status = be_mbox_notify(ctrl);
  81. if (!status) {
  82. struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
  83. SE_DEBUG(DBG_LVL_8, "Firmware version of CMD: %s\n",
  84. resp->params.hba_attribs.flashrom_version_string);
  85. SE_DEBUG(DBG_LVL_8, "Firmware version is : %s\n",
  86. resp->params.hba_attribs.firmware_version_string);
  87. SE_DEBUG(DBG_LVL_8,
  88. "Developer Build, not performing version check...\n");
  89. phba->fw_config.iscsi_features =
  90. resp->params.hba_attribs.iscsi_features;
  91. SE_DEBUG(DBG_LVL_8, " phba->fw_config.iscsi_features = %d\n",
  92. phba->fw_config.iscsi_features);
  93. } else
  94. SE_DEBUG(DBG_LVL_1, " Failed in mgmt_check_supported_fw\n");
  95. spin_unlock(&ctrl->mbox_lock);
  96. if (nonemb_cmd.va)
  97. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  98. nonemb_cmd.va, nonemb_cmd.dma);
  99. return status;
  100. }
  101. unsigned char mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
  102. {
  103. struct be_ctrl_info *ctrl = &phba->ctrl;
  104. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  105. struct iscsi_cleanup_req *req = embedded_payload(wrb);
  106. int status = 0;
  107. spin_lock(&ctrl->mbox_lock);
  108. memset(wrb, 0, sizeof(*wrb));
  109. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  110. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  111. OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
  112. req->chute = chute;
  113. req->hdr_ring_id = 0;
  114. req->data_ring_id = 0;
  115. status = be_mcc_notify_wait(phba);
  116. if (status)
  117. shost_printk(KERN_WARNING, phba->shost,
  118. " mgmt_epfw_cleanup , FAILED\n");
  119. spin_unlock(&ctrl->mbox_lock);
  120. return status;
  121. }
  122. unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
  123. unsigned int icd, unsigned int cid)
  124. {
  125. struct be_dma_mem nonemb_cmd;
  126. struct be_ctrl_info *ctrl = &phba->ctrl;
  127. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  128. struct be_sge *sge = nonembedded_sgl(wrb);
  129. struct invalidate_commands_params_in *req;
  130. int status = 0;
  131. nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
  132. sizeof(struct invalidate_commands_params_in),
  133. &nonemb_cmd.dma);
  134. if (nonemb_cmd.va == NULL) {
  135. SE_DEBUG(DBG_LVL_1,
  136. "Failed to allocate memory for"
  137. "mgmt_invalidate_icds \n");
  138. return -1;
  139. }
  140. nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
  141. req = nonemb_cmd.va;
  142. spin_lock(&ctrl->mbox_lock);
  143. memset(wrb, 0, sizeof(*wrb));
  144. be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
  145. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  146. OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
  147. sizeof(*req));
  148. req->ref_handle = 0;
  149. req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
  150. req->icd_count = 0;
  151. req->table[req->icd_count].icd = icd;
  152. req->table[req->icd_count].cid = cid;
  153. sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
  154. sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
  155. sge->len = cpu_to_le32(nonemb_cmd.size);
  156. status = be_mcc_notify_wait(phba);
  157. if (status)
  158. SE_DEBUG(DBG_LVL_1, "ICDS Invalidation Failed\n");
  159. spin_unlock(&ctrl->mbox_lock);
  160. if (nonemb_cmd.va)
  161. pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
  162. nonemb_cmd.va, nonemb_cmd.dma);
  163. return status;
  164. }
  165. unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
  166. struct beiscsi_endpoint *beiscsi_ep,
  167. unsigned short cid,
  168. unsigned short issue_reset,
  169. unsigned short savecfg_flag)
  170. {
  171. struct be_ctrl_info *ctrl = &phba->ctrl;
  172. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  173. struct iscsi_invalidate_connection_params_in *req =
  174. 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_INI,
  180. OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
  181. sizeof(*req));
  182. req->session_handle = beiscsi_ep->fw_handle;
  183. req->cid = cid;
  184. if (issue_reset)
  185. req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
  186. else
  187. req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
  188. req->save_cfg = savecfg_flag;
  189. status = be_mcc_notify_wait(phba);
  190. if (status)
  191. SE_DEBUG(DBG_LVL_1, "Invalidation Failed\n");
  192. spin_unlock(&ctrl->mbox_lock);
  193. return status;
  194. }
  195. unsigned char mgmt_upload_connection(struct beiscsi_hba *phba,
  196. unsigned short cid, unsigned int upload_flag)
  197. {
  198. struct be_ctrl_info *ctrl = &phba->ctrl;
  199. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  200. struct tcp_upload_params_in *req = embedded_payload(wrb);
  201. int status = 0;
  202. spin_lock(&ctrl->mbox_lock);
  203. memset(wrb, 0, sizeof(*wrb));
  204. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  205. be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
  206. OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
  207. req->id = (unsigned short)cid;
  208. req->upload_type = (unsigned char)upload_flag;
  209. status = be_mcc_notify_wait(phba);
  210. if (status)
  211. SE_DEBUG(DBG_LVL_1, "mgmt_upload_connection Failed\n");
  212. spin_unlock(&ctrl->mbox_lock);
  213. return status;
  214. }
  215. int mgmt_open_connection(struct beiscsi_hba *phba,
  216. struct sockaddr *dst_addr,
  217. struct beiscsi_endpoint *beiscsi_ep)
  218. {
  219. struct hwi_controller *phwi_ctrlr;
  220. struct hwi_context_memory *phwi_context;
  221. struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
  222. struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
  223. struct be_ctrl_info *ctrl = &phba->ctrl;
  224. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  225. struct tcp_connect_and_offload_in *req = embedded_payload(wrb);
  226. unsigned short def_hdr_id;
  227. unsigned short def_data_id;
  228. struct phys_addr template_address = { 0, 0 };
  229. struct phys_addr *ptemplate_address;
  230. int status = 0;
  231. unsigned int i;
  232. unsigned short cid = beiscsi_ep->ep_cid;
  233. phwi_ctrlr = phba->phwi_ctrlr;
  234. phwi_context = phwi_ctrlr->phwi_ctxt;
  235. def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba);
  236. def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba);
  237. ptemplate_address = &template_address;
  238. ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
  239. spin_lock(&ctrl->mbox_lock);
  240. memset(wrb, 0, sizeof(*wrb));
  241. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  242. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  243. OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
  244. sizeof(*req));
  245. if (dst_addr->sa_family == PF_INET) {
  246. __be32 s_addr = daddr_in->sin_addr.s_addr;
  247. req->ip_address.ip_type = BE2_IPV4;
  248. req->ip_address.ip_address[0] = s_addr & 0x000000ff;
  249. req->ip_address.ip_address[1] = (s_addr & 0x0000ff00) >> 8;
  250. req->ip_address.ip_address[2] = (s_addr & 0x00ff0000) >> 16;
  251. req->ip_address.ip_address[3] = (s_addr & 0xff000000) >> 24;
  252. req->tcp_port = ntohs(daddr_in->sin_port);
  253. beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
  254. beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
  255. beiscsi_ep->ip_type = BE2_IPV4;
  256. } else if (dst_addr->sa_family == PF_INET6) {
  257. req->ip_address.ip_type = BE2_IPV6;
  258. memcpy(&req->ip_address.ip_address,
  259. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  260. req->tcp_port = ntohs(daddr_in6->sin6_port);
  261. beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
  262. memcpy(&beiscsi_ep->dst6_addr,
  263. &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
  264. beiscsi_ep->ip_type = BE2_IPV6;
  265. } else{
  266. shost_printk(KERN_ERR, phba->shost, "unknown addr family %d\n",
  267. dst_addr->sa_family);
  268. spin_unlock(&ctrl->mbox_lock);
  269. return -EINVAL;
  270. }
  271. req->cid = cid;
  272. i = phba->nxt_cqid++;
  273. if (phba->nxt_cqid == phba->num_cpus)
  274. phba->nxt_cqid = 0;
  275. req->cq_id = phwi_context->be_cq[i].id;
  276. SE_DEBUG(DBG_LVL_8, "i=%d cq_id=%d \n", i, req->cq_id);
  277. req->defq_id = def_hdr_id;
  278. req->hdr_ring_id = def_hdr_id;
  279. req->data_ring_id = def_data_id;
  280. req->do_offload = 1;
  281. req->dataout_template_pa.lo = ptemplate_address->lo;
  282. req->dataout_template_pa.hi = ptemplate_address->hi;
  283. status = be_mcc_notify_wait(phba);
  284. if (!status) {
  285. struct iscsi_endpoint *ep;
  286. struct tcp_connect_and_offload_out *ptcpcnct_out =
  287. embedded_payload(wrb);
  288. ep = phba->ep_array[ptcpcnct_out->cid];
  289. beiscsi_ep = ep->dd_data;
  290. beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
  291. beiscsi_ep->cid_vld = 1;
  292. SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
  293. } else
  294. SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed\n");
  295. spin_unlock(&ctrl->mbox_lock);
  296. return status;
  297. }
  298. int be_cmd_get_mac_addr(struct beiscsi_hba *phba, u8 *mac_addr)
  299. {
  300. struct be_ctrl_info *ctrl = &phba->ctrl;
  301. struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
  302. struct be_cmd_req_get_mac_addr *req = embedded_payload(wrb);
  303. int status;
  304. SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n");
  305. spin_lock(&ctrl->mbox_lock);
  306. memset(wrb, 0, sizeof(*wrb));
  307. be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
  308. be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
  309. OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
  310. sizeof(*req));
  311. status = be_mcc_notify_wait(phba);
  312. if (!status) {
  313. struct be_cmd_resp_get_mac_addr *resp = embedded_payload(wrb);
  314. memcpy(mac_addr, resp->mac_address, ETH_ALEN);
  315. }
  316. spin_unlock(&ctrl->mbox_lock);
  317. return status;
  318. }