2 * Copyright (C) 2005 - 2010 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 int 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 "FW reported MAX CXNS as %d\t"
54 "Max Supported = %d.\n",
55 phba
->fw_config
.iscsi_cid_count
,
57 phba
->fw_config
.iscsi_cid_count
= BE2_MAX_SESSIONS
/ 2;
60 shost_printk(KERN_WARNING
, phba
->shost
,
61 "Failed in mgmt_get_fw_config\n");
64 spin_unlock(&ctrl
->mbox_lock
);
68 int 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 memset(req
, 0, sizeof(*req
));
89 spin_lock(&ctrl
->mbox_lock
);
90 memset(wrb
, 0, sizeof(*wrb
));
91 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1);
92 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_COMMON
,
93 OPCODE_COMMON_GET_CNTL_ATTRIBUTES
, sizeof(*req
));
94 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
.dma
));
95 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
.dma
& 0xFFFFFFFF);
96 sge
->len
= cpu_to_le32(nonemb_cmd
.size
);
97 status
= be_mbox_notify(ctrl
);
99 struct be_mgmt_controller_attributes_resp
*resp
= nonemb_cmd
.va
;
100 SE_DEBUG(DBG_LVL_8
, "Firmware version of CMD: %s\n",
101 resp
->params
.hba_attribs
.flashrom_version_string
);
102 SE_DEBUG(DBG_LVL_8
, "Firmware version is : %s\n",
103 resp
->params
.hba_attribs
.firmware_version_string
);
105 "Developer Build, not performing version check...\n");
106 phba
->fw_config
.iscsi_features
=
107 resp
->params
.hba_attribs
.iscsi_features
;
108 SE_DEBUG(DBG_LVL_8
, " phba->fw_config.iscsi_features = %d\n",
109 phba
->fw_config
.iscsi_features
);
111 SE_DEBUG(DBG_LVL_1
, " Failed in mgmt_check_supported_fw\n");
112 spin_unlock(&ctrl
->mbox_lock
);
114 pci_free_consistent(ctrl
->pdev
, nonemb_cmd
.size
,
115 nonemb_cmd
.va
, nonemb_cmd
.dma
);
120 int 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 int mgmt_invalidate_icds(struct beiscsi_hba
*phba
,
147 struct invalidate_command_table
*inv_tbl
,
148 unsigned int num_invalidate
, unsigned int cid
,
149 struct be_dma_mem
*nonemb_cmd
)
152 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
153 struct be_mcc_wrb
*wrb
;
155 struct invalidate_commands_params_in
*req
;
156 unsigned int i
, tag
= 0;
158 spin_lock(&ctrl
->mbox_lock
);
159 tag
= alloc_mcc_tag(phba
);
161 spin_unlock(&ctrl
->mbox_lock
);
165 req
= nonemb_cmd
->va
;
166 memset(req
, 0, sizeof(*req
));
167 wrb
= wrb_from_mccq(phba
);
168 sge
= nonembedded_sgl(wrb
);
171 be_wrb_hdr_prepare(wrb
, sizeof(*req
), false, 1);
172 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ISCSI
,
173 OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS
,
176 req
->cleanup_type
= CMD_ISCSI_COMMAND_INVALIDATE
;
177 for (i
= 0; i
< num_invalidate
; i
++) {
178 req
->table
[i
].icd
= inv_tbl
->icd
;
179 req
->table
[i
].cid
= inv_tbl
->cid
;
183 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
184 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
185 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
188 spin_unlock(&ctrl
->mbox_lock
);
192 unsigned int mgmt_invalidate_connection(struct beiscsi_hba
*phba
,
193 struct beiscsi_endpoint
*beiscsi_ep
,
195 unsigned short issue_reset
,
196 unsigned short savecfg_flag
)
198 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
199 struct be_mcc_wrb
*wrb
;
200 struct iscsi_invalidate_connection_params_in
*req
;
201 unsigned int tag
= 0;
203 spin_lock(&ctrl
->mbox_lock
);
204 tag
= alloc_mcc_tag(phba
);
206 spin_unlock(&ctrl
->mbox_lock
);
209 wrb
= wrb_from_mccq(phba
);
211 req
= embedded_payload(wrb
);
213 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0);
214 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ISCSI_INI
,
215 OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION
,
217 req
->session_handle
= beiscsi_ep
->fw_handle
;
220 req
->cleanup_type
= CMD_ISCSI_CONNECTION_ISSUE_TCP_RST
;
222 req
->cleanup_type
= CMD_ISCSI_CONNECTION_INVALIDATE
;
223 req
->save_cfg
= savecfg_flag
;
225 spin_unlock(&ctrl
->mbox_lock
);
229 unsigned int mgmt_upload_connection(struct beiscsi_hba
*phba
,
230 unsigned short cid
, unsigned int upload_flag
)
232 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
233 struct be_mcc_wrb
*wrb
;
234 struct tcp_upload_params_in
*req
;
235 unsigned int tag
= 0;
237 spin_lock(&ctrl
->mbox_lock
);
238 tag
= alloc_mcc_tag(phba
);
240 spin_unlock(&ctrl
->mbox_lock
);
243 wrb
= wrb_from_mccq(phba
);
244 req
= embedded_payload(wrb
);
247 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0);
248 be_cmd_hdr_prepare(&req
->hdr
, CMD_COMMON_TCP_UPLOAD
,
249 OPCODE_COMMON_TCP_UPLOAD
, sizeof(*req
));
250 req
->id
= (unsigned short)cid
;
251 req
->upload_type
= (unsigned char)upload_flag
;
253 spin_unlock(&ctrl
->mbox_lock
);
257 int mgmt_open_connection(struct beiscsi_hba
*phba
,
258 struct sockaddr
*dst_addr
,
259 struct beiscsi_endpoint
*beiscsi_ep
,
260 struct be_dma_mem
*nonemb_cmd
)
263 struct hwi_controller
*phwi_ctrlr
;
264 struct hwi_context_memory
*phwi_context
;
265 struct sockaddr_in
*daddr_in
= (struct sockaddr_in
*)dst_addr
;
266 struct sockaddr_in6
*daddr_in6
= (struct sockaddr_in6
*)dst_addr
;
267 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
268 struct be_mcc_wrb
*wrb
;
269 struct tcp_connect_and_offload_in
*req
;
270 unsigned short def_hdr_id
;
271 unsigned short def_data_id
;
272 struct phys_addr template_address
= { 0, 0 };
273 struct phys_addr
*ptemplate_address
;
274 unsigned int tag
= 0;
276 unsigned short cid
= beiscsi_ep
->ep_cid
;
279 phwi_ctrlr
= phba
->phwi_ctrlr
;
280 phwi_context
= phwi_ctrlr
->phwi_ctxt
;
281 def_hdr_id
= (unsigned short)HWI_GET_DEF_HDRQ_ID(phba
);
282 def_data_id
= (unsigned short)HWI_GET_DEF_BUFQ_ID(phba
);
284 ptemplate_address
= &template_address
;
285 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba
, ptemplate_address
);
286 spin_lock(&ctrl
->mbox_lock
);
287 tag
= alloc_mcc_tag(phba
);
289 spin_unlock(&ctrl
->mbox_lock
);
292 wrb
= wrb_from_mccq(phba
);
293 memset(wrb
, 0, sizeof(*wrb
));
294 sge
= nonembedded_sgl(wrb
);
296 req
= nonemb_cmd
->va
;
297 memset(req
, 0, sizeof(*req
));
300 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 1);
301 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ISCSI
,
302 OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD
,
304 if (dst_addr
->sa_family
== PF_INET
) {
305 __be32 s_addr
= daddr_in
->sin_addr
.s_addr
;
306 req
->ip_address
.ip_type
= BE2_IPV4
;
307 req
->ip_address
.ip_address
[0] = s_addr
& 0x000000ff;
308 req
->ip_address
.ip_address
[1] = (s_addr
& 0x0000ff00) >> 8;
309 req
->ip_address
.ip_address
[2] = (s_addr
& 0x00ff0000) >> 16;
310 req
->ip_address
.ip_address
[3] = (s_addr
& 0xff000000) >> 24;
311 req
->tcp_port
= ntohs(daddr_in
->sin_port
);
312 beiscsi_ep
->dst_addr
= daddr_in
->sin_addr
.s_addr
;
313 beiscsi_ep
->dst_tcpport
= ntohs(daddr_in
->sin_port
);
314 beiscsi_ep
->ip_type
= BE2_IPV4
;
315 } else if (dst_addr
->sa_family
== PF_INET6
) {
316 req
->ip_address
.ip_type
= BE2_IPV6
;
317 memcpy(&req
->ip_address
.ip_address
,
318 &daddr_in6
->sin6_addr
.in6_u
.u6_addr8
, 16);
319 req
->tcp_port
= ntohs(daddr_in6
->sin6_port
);
320 beiscsi_ep
->dst_tcpport
= ntohs(daddr_in6
->sin6_port
);
321 memcpy(&beiscsi_ep
->dst6_addr
,
322 &daddr_in6
->sin6_addr
.in6_u
.u6_addr8
, 16);
323 beiscsi_ep
->ip_type
= BE2_IPV6
;
325 shost_printk(KERN_ERR
, phba
->shost
, "unknown addr family %d\n",
326 dst_addr
->sa_family
);
327 spin_unlock(&ctrl
->mbox_lock
);
328 free_mcc_tag(&phba
->ctrl
, tag
);
333 i
= phba
->nxt_cqid
++;
334 if (phba
->nxt_cqid
== phba
->num_cpus
)
336 req
->cq_id
= phwi_context
->be_cq
[i
].id
;
337 SE_DEBUG(DBG_LVL_8
, "i=%d cq_id=%d\n", i
, req
->cq_id
);
338 req
->defq_id
= def_hdr_id
;
339 req
->hdr_ring_id
= def_hdr_id
;
340 req
->data_ring_id
= def_data_id
;
342 req
->dataout_template_pa
.lo
= ptemplate_address
->lo
;
343 req
->dataout_template_pa
.hi
= ptemplate_address
->hi
;
344 sge
->pa_hi
= cpu_to_le32(upper_32_bits(nonemb_cmd
->dma
));
345 sge
->pa_lo
= cpu_to_le32(nonemb_cmd
->dma
& 0xFFFFFFFF);
346 sge
->len
= cpu_to_le32(nonemb_cmd
->size
);
348 spin_unlock(&ctrl
->mbox_lock
);
352 unsigned int be_cmd_get_mac_addr(struct beiscsi_hba
*phba
)
354 struct be_ctrl_info
*ctrl
= &phba
->ctrl
;
355 struct be_mcc_wrb
*wrb
;
356 struct be_cmd_req_get_mac_addr
*req
;
357 unsigned int tag
= 0;
359 SE_DEBUG(DBG_LVL_8
, "In be_cmd_get_mac_addr\n");
360 spin_lock(&ctrl
->mbox_lock
);
361 tag
= alloc_mcc_tag(phba
);
363 spin_unlock(&ctrl
->mbox_lock
);
367 wrb
= wrb_from_mccq(phba
);
368 req
= embedded_payload(wrb
);
370 be_wrb_hdr_prepare(wrb
, sizeof(*req
), true, 0);
371 be_cmd_hdr_prepare(&req
->hdr
, CMD_SUBSYSTEM_ISCSI
,
372 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG
,
376 spin_unlock(&ctrl
->mbox_lock
);