RT-AC56 3.0.0.4.374.37 core
[tomato.git] / release / src-rt-6.x.4708 / linux / linux-2.6.36 / drivers / scsi / be2iscsi / be_mgmt.c
blobfcdb465156d742f71b30a157e06059be9fa5bf30
1 /**
2 * Copyright (C) 2005 - 2010 ServerEngines
3 * All rights reserved.
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
15 * ServerEngines
16 * 209 N. Fair Oaks Ave
17 * Sunnyvale, CA 94085
21 #include "be_mgmt.h"
22 #include "be_iscsi.h"
23 #include <scsi/scsi_transport_iscsi.h>
25 unsigned int beiscsi_get_boot_target(struct beiscsi_hba *phba)
27 struct be_ctrl_info *ctrl = &phba->ctrl;
28 struct be_mcc_wrb *wrb;
29 struct be_cmd_req_get_mac_addr *req;
30 unsigned int tag = 0;
32 SE_DEBUG(DBG_LVL_8, "In bescsi_get_boot_target\n");
33 spin_lock(&ctrl->mbox_lock);
34 tag = alloc_mcc_tag(phba);
35 if (!tag) {
36 spin_unlock(&ctrl->mbox_lock);
37 return tag;
40 wrb = wrb_from_mccq(phba);
41 req = embedded_payload(wrb);
42 wrb->tag0 |= tag;
43 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
44 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
45 OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET,
46 sizeof(*req));
48 be_mcc_notify(phba);
49 spin_unlock(&ctrl->mbox_lock);
50 return tag;
53 unsigned int beiscsi_get_session_info(struct beiscsi_hba *phba,
54 u32 boot_session_handle,
55 struct be_dma_mem *nonemb_cmd)
57 struct be_ctrl_info *ctrl = &phba->ctrl;
58 struct be_mcc_wrb *wrb;
59 unsigned int tag = 0;
60 struct be_cmd_req_get_session *req;
61 struct be_cmd_resp_get_session *resp;
62 struct be_sge *sge;
64 SE_DEBUG(DBG_LVL_8, "In beiscsi_get_session_info\n");
65 spin_lock(&ctrl->mbox_lock);
66 tag = alloc_mcc_tag(phba);
67 if (!tag) {
68 spin_unlock(&ctrl->mbox_lock);
69 return tag;
72 nonemb_cmd->size = sizeof(*resp);
73 req = nonemb_cmd->va;
74 memset(req, 0, sizeof(*req));
75 wrb = wrb_from_mccq(phba);
76 sge = nonembedded_sgl(wrb);
77 wrb->tag0 |= tag;
80 wrb->tag0 |= tag;
81 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
82 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
83 OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
84 sizeof(*resp));
85 req->session_handle = boot_session_handle;
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);
90 be_mcc_notify(phba);
91 spin_unlock(&ctrl->mbox_lock);
92 return tag;
95 int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
96 struct beiscsi_hba *phba)
98 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
99 struct be_fw_cfg *req = embedded_payload(wrb);
100 int status = 0;
102 spin_lock(&ctrl->mbox_lock);
103 memset(wrb, 0, sizeof(*wrb));
105 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
107 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
108 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
109 status = be_mbox_notify(ctrl);
110 if (!status) {
111 struct be_fw_cfg *pfw_cfg;
112 pfw_cfg = req;
113 phba->fw_config.phys_port = pfw_cfg->phys_port;
114 phba->fw_config.iscsi_icd_start =
115 pfw_cfg->ulp[0].icd_base;
116 phba->fw_config.iscsi_icd_count =
117 pfw_cfg->ulp[0].icd_count;
118 phba->fw_config.iscsi_cid_start =
119 pfw_cfg->ulp[0].sq_base;
120 phba->fw_config.iscsi_cid_count =
121 pfw_cfg->ulp[0].sq_count;
122 if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
123 SE_DEBUG(DBG_LVL_8,
124 "FW reported MAX CXNS as %d\t"
125 "Max Supported = %d.\n",
126 phba->fw_config.iscsi_cid_count,
127 BE2_MAX_SESSIONS);
128 phba->fw_config.iscsi_cid_count = BE2_MAX_SESSIONS / 2;
130 } else {
131 shost_printk(KERN_WARNING, phba->shost,
132 "Failed in mgmt_get_fw_config\n");
135 spin_unlock(&ctrl->mbox_lock);
136 return status;
139 int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
140 struct beiscsi_hba *phba)
142 struct be_dma_mem nonemb_cmd;
143 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
144 struct be_mgmt_controller_attributes *req;
145 struct be_sge *sge = nonembedded_sgl(wrb);
146 int status = 0;
148 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
149 sizeof(struct be_mgmt_controller_attributes),
150 &nonemb_cmd.dma);
151 if (nonemb_cmd.va == NULL) {
152 SE_DEBUG(DBG_LVL_1,
153 "Failed to allocate memory for mgmt_check_supported_fw"
154 "\n");
155 return -ENOMEM;
157 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
158 req = nonemb_cmd.va;
159 memset(req, 0, sizeof(*req));
160 spin_lock(&ctrl->mbox_lock);
161 memset(wrb, 0, sizeof(*wrb));
162 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
163 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
164 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
165 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
166 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
167 sge->len = cpu_to_le32(nonemb_cmd.size);
168 status = be_mbox_notify(ctrl);
169 if (!status) {
170 struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
171 SE_DEBUG(DBG_LVL_8, "Firmware version of CMD: %s\n",
172 resp->params.hba_attribs.flashrom_version_string);
173 SE_DEBUG(DBG_LVL_8, "Firmware version is : %s\n",
174 resp->params.hba_attribs.firmware_version_string);
175 SE_DEBUG(DBG_LVL_8,
176 "Developer Build, not performing version check...\n");
177 phba->fw_config.iscsi_features =
178 resp->params.hba_attribs.iscsi_features;
179 SE_DEBUG(DBG_LVL_8, " phba->fw_config.iscsi_features = %d\n",
180 phba->fw_config.iscsi_features);
181 } else
182 SE_DEBUG(DBG_LVL_1, " Failed in mgmt_check_supported_fw\n");
183 spin_unlock(&ctrl->mbox_lock);
184 if (nonemb_cmd.va)
185 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
186 nonemb_cmd.va, nonemb_cmd.dma);
188 return status;
191 int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
193 struct be_ctrl_info *ctrl = &phba->ctrl;
194 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
195 struct iscsi_cleanup_req *req = embedded_payload(wrb);
196 int status = 0;
198 spin_lock(&ctrl->mbox_lock);
199 memset(wrb, 0, sizeof(*wrb));
201 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
202 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
203 OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
205 req->chute = chute;
206 req->hdr_ring_id = 0;
207 req->data_ring_id = 0;
209 status = be_mcc_notify_wait(phba);
210 if (status)
211 shost_printk(KERN_WARNING, phba->shost,
212 " mgmt_epfw_cleanup , FAILED\n");
213 spin_unlock(&ctrl->mbox_lock);
214 return status;
217 unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
218 struct invalidate_command_table *inv_tbl,
219 unsigned int num_invalidate, unsigned int cid,
220 struct be_dma_mem *nonemb_cmd)
223 struct be_ctrl_info *ctrl = &phba->ctrl;
224 struct be_mcc_wrb *wrb;
225 struct be_sge *sge;
226 struct invalidate_commands_params_in *req;
227 unsigned int i, tag = 0;
229 spin_lock(&ctrl->mbox_lock);
230 tag = alloc_mcc_tag(phba);
231 if (!tag) {
232 spin_unlock(&ctrl->mbox_lock);
233 return tag;
236 req = nonemb_cmd->va;
237 memset(req, 0, sizeof(*req));
238 wrb = wrb_from_mccq(phba);
239 sge = nonembedded_sgl(wrb);
240 wrb->tag0 |= tag;
242 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
243 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
244 OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
245 sizeof(*req));
246 req->ref_handle = 0;
247 req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
248 for (i = 0; i < num_invalidate; i++) {
249 req->table[i].icd = inv_tbl->icd;
250 req->table[i].cid = inv_tbl->cid;
251 req->icd_count++;
252 inv_tbl++;
254 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
255 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
256 sge->len = cpu_to_le32(nonemb_cmd->size);
258 be_mcc_notify(phba);
259 spin_unlock(&ctrl->mbox_lock);
260 return tag;
263 unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
264 struct beiscsi_endpoint *beiscsi_ep,
265 unsigned short cid,
266 unsigned short issue_reset,
267 unsigned short savecfg_flag)
269 struct be_ctrl_info *ctrl = &phba->ctrl;
270 struct be_mcc_wrb *wrb;
271 struct iscsi_invalidate_connection_params_in *req;
272 unsigned int tag = 0;
274 spin_lock(&ctrl->mbox_lock);
275 tag = alloc_mcc_tag(phba);
276 if (!tag) {
277 spin_unlock(&ctrl->mbox_lock);
278 return tag;
280 wrb = wrb_from_mccq(phba);
281 wrb->tag0 |= tag;
282 req = embedded_payload(wrb);
284 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
285 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
286 OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
287 sizeof(*req));
288 req->session_handle = beiscsi_ep->fw_handle;
289 req->cid = cid;
290 if (issue_reset)
291 req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
292 else
293 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
294 req->save_cfg = savecfg_flag;
295 be_mcc_notify(phba);
296 spin_unlock(&ctrl->mbox_lock);
297 return tag;
300 unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
301 unsigned short cid, unsigned int upload_flag)
303 struct be_ctrl_info *ctrl = &phba->ctrl;
304 struct be_mcc_wrb *wrb;
305 struct tcp_upload_params_in *req;
306 unsigned int tag = 0;
308 spin_lock(&ctrl->mbox_lock);
309 tag = alloc_mcc_tag(phba);
310 if (!tag) {
311 spin_unlock(&ctrl->mbox_lock);
312 return tag;
314 wrb = wrb_from_mccq(phba);
315 req = embedded_payload(wrb);
316 wrb->tag0 |= tag;
318 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
319 be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
320 OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
321 req->id = (unsigned short)cid;
322 req->upload_type = (unsigned char)upload_flag;
323 be_mcc_notify(phba);
324 spin_unlock(&ctrl->mbox_lock);
325 return tag;
328 int mgmt_open_connection(struct beiscsi_hba *phba,
329 struct sockaddr *dst_addr,
330 struct beiscsi_endpoint *beiscsi_ep,
331 struct be_dma_mem *nonemb_cmd)
334 struct hwi_controller *phwi_ctrlr;
335 struct hwi_context_memory *phwi_context;
336 struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
337 struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
338 struct be_ctrl_info *ctrl = &phba->ctrl;
339 struct be_mcc_wrb *wrb;
340 struct tcp_connect_and_offload_in *req;
341 unsigned short def_hdr_id;
342 unsigned short def_data_id;
343 struct phys_addr template_address = { 0, 0 };
344 struct phys_addr *ptemplate_address;
345 unsigned int tag = 0;
346 unsigned int i;
347 unsigned short cid = beiscsi_ep->ep_cid;
348 struct be_sge *sge;
350 phwi_ctrlr = phba->phwi_ctrlr;
351 phwi_context = phwi_ctrlr->phwi_ctxt;
352 def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba);
353 def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba);
355 ptemplate_address = &template_address;
356 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
357 spin_lock(&ctrl->mbox_lock);
358 tag = alloc_mcc_tag(phba);
359 if (!tag) {
360 spin_unlock(&ctrl->mbox_lock);
361 return tag;
363 wrb = wrb_from_mccq(phba);
364 memset(wrb, 0, sizeof(*wrb));
365 sge = nonembedded_sgl(wrb);
367 req = nonemb_cmd->va;
368 memset(req, 0, sizeof(*req));
369 wrb->tag0 |= tag;
371 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
372 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
373 OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
374 sizeof(*req));
375 if (dst_addr->sa_family == PF_INET) {
376 __be32 s_addr = daddr_in->sin_addr.s_addr;
377 req->ip_address.ip_type = BE2_IPV4;
378 req->ip_address.ip_address[0] = s_addr & 0x000000ff;
379 req->ip_address.ip_address[1] = (s_addr & 0x0000ff00) >> 8;
380 req->ip_address.ip_address[2] = (s_addr & 0x00ff0000) >> 16;
381 req->ip_address.ip_address[3] = (s_addr & 0xff000000) >> 24;
382 req->tcp_port = ntohs(daddr_in->sin_port);
383 beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
384 beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
385 beiscsi_ep->ip_type = BE2_IPV4;
386 } else if (dst_addr->sa_family == PF_INET6) {
387 req->ip_address.ip_type = BE2_IPV6;
388 memcpy(&req->ip_address.ip_address,
389 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
390 req->tcp_port = ntohs(daddr_in6->sin6_port);
391 beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
392 memcpy(&beiscsi_ep->dst6_addr,
393 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
394 beiscsi_ep->ip_type = BE2_IPV6;
395 } else{
396 shost_printk(KERN_ERR, phba->shost, "unknown addr family %d\n",
397 dst_addr->sa_family);
398 spin_unlock(&ctrl->mbox_lock);
399 free_mcc_tag(&phba->ctrl, tag);
400 return -EINVAL;
403 req->cid = cid;
404 i = phba->nxt_cqid++;
405 if (phba->nxt_cqid == phba->num_cpus)
406 phba->nxt_cqid = 0;
407 req->cq_id = phwi_context->be_cq[i].id;
408 SE_DEBUG(DBG_LVL_8, "i=%d cq_id=%d\n", i, req->cq_id);
409 req->defq_id = def_hdr_id;
410 req->hdr_ring_id = def_hdr_id;
411 req->data_ring_id = def_data_id;
412 req->do_offload = 1;
413 req->dataout_template_pa.lo = ptemplate_address->lo;
414 req->dataout_template_pa.hi = ptemplate_address->hi;
415 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
416 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
417 sge->len = cpu_to_le32(nonemb_cmd->size);
418 be_mcc_notify(phba);
419 spin_unlock(&ctrl->mbox_lock);
420 return tag;
423 unsigned int be_cmd_get_mac_addr(struct beiscsi_hba *phba)
425 struct be_ctrl_info *ctrl = &phba->ctrl;
426 struct be_mcc_wrb *wrb;
427 struct be_cmd_req_get_mac_addr *req;
428 unsigned int tag = 0;
430 SE_DEBUG(DBG_LVL_8, "In be_cmd_get_mac_addr\n");
431 spin_lock(&ctrl->mbox_lock);
432 tag = alloc_mcc_tag(phba);
433 if (!tag) {
434 spin_unlock(&ctrl->mbox_lock);
435 return tag;
438 wrb = wrb_from_mccq(phba);
439 req = embedded_payload(wrb);
440 wrb->tag0 |= tag;
441 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
442 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
443 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
444 sizeof(*req));
446 be_mcc_notify(phba);
447 spin_unlock(&ctrl->mbox_lock);
448 return tag;