blob: df1b327fe17badb57a4ee8c7a95f9fcf7d149be8 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
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
21#include "be_mgmt.h"
22#include "be_iscsi.h"
23
24unsigned char mgmt_get_fw_config(struct be_ctrl_info *ctrl,
25 struct beiscsi_hba *phba)
26{
27 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
28 struct be_fw_cfg *req = embedded_payload(wrb);
29 int status = 0;
30
31 spin_lock(&ctrl->mbox_lock);
32 memset(wrb, 0, sizeof(*wrb));
33
34 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
35
36 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
37 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053038 status = be_mbox_notify(ctrl);
39 if (!status) {
40 struct be_fw_cfg *pfw_cfg;
41 pfw_cfg = req;
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;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +053051 if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
52 status = 1;
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,
57 BE2_MAX_SESSIONS);
58 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053059 } else {
60 shost_printk(KERN_WARNING, phba->shost,
61 "Failed in mgmt_get_fw_config \n");
62 }
63
64 spin_unlock(&ctrl->mbox_lock);
65 return status;
66}
67
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +053068unsigned char mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
69 struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053070{
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);
75 int status = 0;
76
77 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
78 sizeof(struct be_mgmt_controller_attributes),
79 &nonemb_cmd.dma);
80 if (nonemb_cmd.va == NULL) {
81 SE_DEBUG(DBG_LVL_1,
82 "Failed to allocate memory for mgmt_check_supported_fw"
83 "\n");
84 return -1;
85 }
86 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
87 req = nonemb_cmd.va;
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);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053096 status = be_mbox_notify(ctrl);
97 if (!status) {
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);
103 SE_DEBUG(DBG_LVL_8,
104 "Developer Build, not performing version check...\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530105 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);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530109 } else
110 SE_DEBUG(DBG_LVL_1, " Failed in mgmt_check_supported_fw\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530111 spin_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530112 if (nonemb_cmd.va)
113 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
114 nonemb_cmd.va, nonemb_cmd.dma);
115
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530116 return status;
117}
118
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530119
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530120unsigned char mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
121{
122 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530123 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530124 struct iscsi_cleanup_req *req = embedded_payload(wrb);
125 int status = 0;
126
127 spin_lock(&ctrl->mbox_lock);
128 memset(wrb, 0, sizeof(*wrb));
129
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));
133
134 req->chute = chute;
135 req->hdr_ring_id = 0;
136 req->data_ring_id = 0;
137
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530138 status = be_mcc_notify_wait(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530139 if (status)
140 shost_printk(KERN_WARNING, phba->shost,
141 " mgmt_epfw_cleanup , FAILED\n");
142 spin_unlock(&ctrl->mbox_lock);
143 return status;
144}
145
146unsigned char mgmt_invalidate_icds(struct beiscsi_hba *phba,
147 unsigned int icd, unsigned int cid)
148{
149 struct be_dma_mem nonemb_cmd;
150 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530151 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530152 struct be_sge *sge = nonembedded_sgl(wrb);
153 struct invalidate_commands_params_in *req;
154 int status = 0;
155
156 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
157 sizeof(struct invalidate_commands_params_in),
158 &nonemb_cmd.dma);
159 if (nonemb_cmd.va == NULL) {
160 SE_DEBUG(DBG_LVL_1,
161 "Failed to allocate memory for"
162 "mgmt_invalidate_icds \n");
163 return -1;
164 }
165 nonemb_cmd.size = sizeof(struct invalidate_commands_params_in);
166 req = nonemb_cmd.va;
167 spin_lock(&ctrl->mbox_lock);
168 memset(wrb, 0, sizeof(*wrb));
169
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,
173 sizeof(*req));
174 req->ref_handle = 0;
175 req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
176 req->icd_count = 0;
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);
182
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530183 status = be_mcc_notify_wait(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530184 if (status)
185 SE_DEBUG(DBG_LVL_1, "ICDS Invalidation Failed\n");
186 spin_unlock(&ctrl->mbox_lock);
187 if (nonemb_cmd.va)
188 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
189 nonemb_cmd.va, nonemb_cmd.dma);
190 return status;
191}
192
193unsigned char mgmt_invalidate_connection(struct beiscsi_hba *phba,
194 struct beiscsi_endpoint *beiscsi_ep,
195 unsigned short cid,
196 unsigned short issue_reset,
197 unsigned short savecfg_flag)
198{
199 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530200 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530201 struct iscsi_invalidate_connection_params_in *req =
202 embedded_payload(wrb);
203 int status = 0;
204
205 spin_lock(&ctrl->mbox_lock);
206 memset(wrb, 0, sizeof(*wrb));
207
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,
211 sizeof(*req));
212 req->session_handle = beiscsi_ep->fw_handle;
213 req->cid = cid;
214 if (issue_reset)
215 req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
216 else
217 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
218 req->save_cfg = savecfg_flag;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530219 status = be_mcc_notify_wait(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530220 if (status)
221 SE_DEBUG(DBG_LVL_1, "Invalidation Failed\n");
222
223 spin_unlock(&ctrl->mbox_lock);
224 return status;
225}
226
227unsigned char mgmt_upload_connection(struct beiscsi_hba *phba,
228 unsigned short cid, unsigned int upload_flag)
229{
230 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530231 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530232 struct tcp_upload_params_in *req = embedded_payload(wrb);
233 int status = 0;
234
235 spin_lock(&ctrl->mbox_lock);
236 memset(wrb, 0, sizeof(*wrb));
237
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;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530243 status = be_mcc_notify_wait(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530244 if (status)
245 SE_DEBUG(DBG_LVL_1, "mgmt_upload_connection Failed\n");
246 spin_unlock(&ctrl->mbox_lock);
247 return status;
248}
249
250int mgmt_open_connection(struct beiscsi_hba *phba,
251 struct sockaddr *dst_addr,
252 struct beiscsi_endpoint *beiscsi_ep)
253{
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;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530259 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530260 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;
265 int status = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530266 unsigned int i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530267 unsigned short cid = beiscsi_ep->ep_cid;
268
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);
273
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));
278
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,
282 sizeof(*req));
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;
303 } else{
304 shost_printk(KERN_ERR, phba->shost, "unknown addr family %d\n",
305 dst_addr->sa_family);
306 spin_unlock(&ctrl->mbox_lock);
307 return -EINVAL;
308
309 }
310 req->cid = cid;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530311 i = phba->nxt_cqid++;
312 if (phba->nxt_cqid == phba->num_cpus)
313 phba->nxt_cqid = 0;
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);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530316 req->defq_id = def_hdr_id;
317 req->hdr_ring_id = def_hdr_id;
318 req->data_ring_id = def_data_id;
319 req->do_offload = 1;
320 req->dataout_template_pa.lo = ptemplate_address->lo;
321 req->dataout_template_pa.hi = ptemplate_address->hi;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530322 status = be_mcc_notify_wait(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530323 if (!status) {
324 struct iscsi_endpoint *ep;
325 struct tcp_connect_and_offload_out *ptcpcnct_out =
326 embedded_payload(wrb);
327
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530328 ep = phba->ep_array[ptcpcnct_out->cid -
329 phba->fw_config.iscsi_cid_start];
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530330 beiscsi_ep = ep->dd_data;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530331 beiscsi_ep->fw_handle = ptcpcnct_out->connection_handle;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530332 beiscsi_ep->cid_vld = 1;
333 SE_DEBUG(DBG_LVL_8, "mgmt_open_connection Success\n");
334 } else
335 SE_DEBUG(DBG_LVL_1, "mgmt_open_connection Failed\n");
336 spin_unlock(&ctrl->mbox_lock);
337 return status;
338}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530339
340int be_cmd_get_mac_addr(struct beiscsi_hba *phba, u8 *mac_addr)
341{
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);
345 int status;
346
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,
353 sizeof(*req));
354
355 status = be_mcc_notify_wait(phba);
356 if (!status) {
357 struct be_cmd_resp_get_mac_addr *resp = embedded_payload(wrb);
358
359 memcpy(mac_addr, resp->mac_address, ETH_ALEN);
360 }
361
362 spin_unlock(&ctrl->mbox_lock);
363 return status;
364}
365