2 * Copyright (C) 2005 - 2009 ServerEngines
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.
10 * Written by: Jayamohan Kallickal (jayamohank@serverengines.com)
12 * Contact Information:
13 * linux-drivers@serverengines.com
16 * 209 N. Fair Oaks Ave
24 unsigned char mgmt_get_fw_config(struct be_ctrl_info *ctrl,
25 struct beiscsi_hba *phba)
27 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
28 struct be_fw_cfg *req = embedded_payload(wrb);
31 spin_lock(&ctrl->mbox_lock);
32 memset(wrb, 0, sizeof(*wrb));
34 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
36 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
37 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
38 status = be_mbox_notify(ctrl);
40 struct be_fw_cfg *pfw_cfg;
42 phba->fw_config.phys_port = pfw_cfg->phys_port;
43 phba->fw_config.iscsi_icd_start =
44 pfw_cfg->ulp[0].icd_base;
45 phba->fw_config.iscsi_icd_count =
46 pfw_cfg->ulp[0].icd_count;
47 phba->fw_config.iscsi_cid_start =
48 pfw_cfg->ulp[0].sq_base;
49 phba->fw_config.iscsi_cid_count =
50 pfw_cfg->ulp[0].sq_count;
51 if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
53 shost_printk(KERN_WARNING, phba->shost,
54 "FW reported MAX CXNS as %d \t"
55 "Max Supported = %d. Failing to load \n",
56 phba->fw_config.iscsi_cid_count,
60 shost_printk(KERN_WARNING, phba->shost,
61 "Failed in mgmt_get_fw_config \n");
64 spin_unlock(&ctrl->mbox_lock);
68 unsigned char mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
69 struct beiscsi_hba *phba)
71 struct be_dma_mem nonemb_cmd;
72 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
73 struct be_mgmt_controller_attributes *req;
74 struct be_sge *sge = nonembedded_sgl(wrb);
77 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
78 sizeof(struct be_mgmt_controller_attributes),
80 if (nonemb_cmd.va == NULL) {
82 "Failed to allocate memory for mgmt_check_supported_fw"
86 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
88 spin_lock(&ctrl->mbox_lock);
89 memset(wrb, 0, sizeof(*wrb));
90 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
91 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
92 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
93 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
94 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
95 sge->len = cpu_to_le32(nonemb_cmd.size);
96 status = be_mbox_notify(ctrl);
98 struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
99 SE_DEBUG(DBG_LVL_8, "Firmware version of CMD: %s\n",
100 resp->params.hba_attribs.flashrom_version_string);
101 SE_DEBUG(DBG_LVL_8, "Firmware version is : %s\n",
102 resp->params.hba_attribs.firmware_version_string);
104 "Developer Build, not performing version check...\n");
105 phba->fw_config.iscsi_features =
106 resp->params.hba_attribs.iscsi_features;
107 SE_DEBUG(DBG_LVL_8, " phba->fw_config.iscsi_features = %d\n",
108 phba->fw_config.iscsi_features);
110 SE_DEBUG(DBG_LVL_1, " Failed in mgmt_check_supported_fw\n");
111 spin_unlock(&ctrl->mbox_lock);
113 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
114 nonemb_cmd.va, nonemb_cmd.dma);
120 unsigned char mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
122 struct be_ctrl_info *ctrl = &phba->ctrl;
123 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
124 struct iscsi_cleanup_req *req = embedded_payload(wrb);
127 spin_lock(&ctrl->mbox_lock);
128 memset(wrb, 0, sizeof(*wrb));
130 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
131 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
132 OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
135 req->hdr_ring_id = 0;
136 req->data_ring_id = 0;
138 status = be_mcc_notify_wait(phba);
140 shost_printk(KERN_WARNING, phba->shost,
141 " mgmt_epfw_cleanup , FAILED\n");
142 spin_unlock(&ctrl->mbox_lock);
146 unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
147 unsigned int icd, unsigned int cid)
149 struct be_dma_mem nonemb_cmd;
150 struct be_ctrl_info *ctrl = &phba->ctrl;
151 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
152 struct be_sge *sge = nonembedded_sgl(wrb);
153 struct invalidate_commands_params_in *req;
156 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
157 sizeof(struct invalidate_commands_params_in),
159 if (nonemb_cmd.va == NULL) {
161 "Failed to allocate memory for"
162 "mgmt_invalidate_icds \n");
165 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
167 spin_lock(&ctrl->mbox_lock);
168 memset(wrb, 0, sizeof(*wrb));
170 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
171 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
172 OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
175 req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
177 req->table[req->icd_count].icd = icd;
178 req->table[req->icd_count].cid = cid;
179 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
180 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
181 sge->len = cpu_to_le32(nonemb_cmd.size);
183 status = be_mcc_notify_wait(phba);
185 SE_DEBUG(DBG_LVL_1, "ICDS Invalidation Failed\n");
186 spin_unlock(&ctrl->mbox_lock);
188 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
189 nonemb_cmd.va, nonemb_cmd.dma);
193 unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
194 struct beiscsi_endpoint *beiscsi_ep,
196 unsigned short issue_reset,
197 unsigned short savecfg_flag)
199 struct be_ctrl_info *ctrl = &phba->ctrl;
200 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
201 struct iscsi_invalidate_connection_params_in *req =
202 embedded_payload(wrb);
205 spin_lock(&ctrl->mbox_lock);
206 memset(wrb, 0, sizeof(*wrb));
208 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
209 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
210 OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
212 req->session_handle = beiscsi_ep->fw_handle;
215 req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
217 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
218 req->save_cfg = savecfg_flag;
219 status = be_mcc_notify_wait(phba);
221 SE_DEBUG(DBG_LVL_1, "Invalidation Failed\n");
223 spin_unlock(&ctrl->mbox_lock);
227 unsigned char mgmt_upload_connection(struct beiscsi_hba *phba,
228 unsigned short cid, unsigned int upload_flag)
230 struct be_ctrl_info *ctrl = &phba->ctrl;
231 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
232 struct tcp_upload_params_in *req = embedded_payload(wrb);
235 spin_lock(&ctrl->mbox_lock);
236 memset(wrb, 0, sizeof(*wrb));
238 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
239 be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
240 OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
241 req->id = (unsigned short)cid;
242 req->upload_type = (unsigned char)upload_flag;
243 status = be_mcc_notify_wait(phba);
245 SE_DEBUG(DBG_LVL_1, "mgmt_upload_connection Failed\n");
246 spin_unlock(&ctrl->mbox_lock);
250 int mgmt_open_connection(struct beiscsi_hba *phba,
251 struct sockaddr *dst_addr,
252 struct beiscsi_endpoint *beiscsi_ep)
254 struct hwi_controller *phwi_ctrlr;
255 struct hwi_context_memory *phwi_context;
256 struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
257 struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
258 struct be_ctrl_info *ctrl = &phba->ctrl;
259 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
260 struct tcp_connect_and_offload_in *req = embedded_payload(wrb);
261 unsigned short def_hdr_id;
262 unsigned short def_data_id;
263 struct phys_addr template_address = { 0, 0 };
264 struct phys_addr *ptemplate_address;
267 unsigned short cid = beiscsi_ep->ep_cid;
269 phwi_ctrlr = phba->phwi_ctrlr;
270 phwi_context = phwi_ctrlr->phwi_ctxt;
271 def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba);
272 def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba);
274 ptemplate_address = &template_address;
275 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
276 spin_lock(&ctrl->mbox_lock);
277 memset(wrb, 0, sizeof(*wrb));
279 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
280 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
281 OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
283 if (dst_addr->sa_family == PF_INET) {
284 __be32 s_addr = daddr_in->sin_addr.s_addr;
285 req->ip_address.ip_type = BE2_IPV4;
286 req->ip_address.ip_address[0] = s_addr & 0x000000ff;
287 req->ip_address.ip_address[1] = (s_addr & 0x0000ff00) >> 8;
288 req->ip_address.ip_address[2] = (s_addr & 0x00ff0000) >> 16;
289 req->ip_address.ip_address[3] = (s_addr & 0xff000000) >> 24;
290 req->tcp_port = ntohs(daddr_in->sin_port);
291 beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
292 beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
293 beiscsi_ep->ip_type = BE2_IPV4;
294 } else if (dst_addr->sa_family == PF_INET6) {
295 req->ip_address.ip_type = BE2_IPV6;
296 memcpy(&req->ip_address.ip_address,
297 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
298 req->tcp_port = ntohs(daddr_in6->sin6_port);
299 beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
300 memcpy(&beiscsi_ep->dst6_addr,
301 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
302 beiscsi_ep->ip_type = BE2_IPV6;
304 shost_printk(KERN_ERR, phba->shost, "unknown addr family %d\n",
305 dst_addr->sa_family);
306 spin_unlock(&ctrl->mbox_lock);
311 i = phba->nxt_cqid++;
312 if (phba->nxt_cqid == phba->num_cpus)
314 req->cq_id = phwi_context->be_cq[i].id;
315 SE_DEBUG(DBG_LVL_8, "i=%d cq_id=%d \n", i, req->cq_id);
316 req->defq_id = def_hdr_id;
317 req->hdr_ring_id = def_hdr_id;
318 req->data_ring_id = def_data_id;
320 req->dataout_template_pa.lo = ptemplate_address->lo;
321 req->dataout_template_pa.hi = ptemplate_address->hi;
322 status = be_mcc_notify_wait(phba);
324 struct iscsi_endpoint *ep;
325 struct tcp_connect_and_offload_out *ptcpcnct_out =
326 embedded_payload(wrb);
328 ep = phba->ep_array[ptcpcnct_out->cid -
329 phba->fw_config.iscsi_cid_start];
330 beiscsi_ep = ep->dd_data;
331 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
332 beiscsi_ep->cid_vld = 1;
333 SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
335 SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed\n");
336 spin_unlock(&ctrl->mbox_lock);
340 int be_cmd_get_mac_addr(struct beiscsi_hba *phba, u8 *mac_addr)
342 struct be_ctrl_info *ctrl = &phba->ctrl;
343 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
344 struct be_cmd_req_get_mac_addr *req = embedded_payload(wrb);
347 SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n");
348 spin_lock(&ctrl->mbox_lock);
349 memset(wrb, 0, sizeof(*wrb));
350 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
351 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
352 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
355 status = be_mcc_notify_wait(phba);
357 struct be_cmd_resp_get_mac_addr *resp = embedded_payload(wrb);
359 memcpy(mac_addr, resp->mac_address, ETH_ALEN);
362 spin_unlock(&ctrl->mbox_lock);