be_mgmt.c 11 KB

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