be_mgmt.c 11 KB

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