be_mgmt.c 13 KB

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