blob: 02bad04112ffe28df070bbf7af25f42eecc472c4 [file] [log] [blame]
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05301/**
John Soni Jose5faf17b2012-10-20 04:45:27 +05302 * Copyright (C) 2005 - 2012 Emulex
Jayamohan Kallickal6733b392009-09-05 07:36:35 +05303 * 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 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070010 * Written by: Jayamohan Kallickal (jayamohan.kallickal@emulex.com)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053011 *
12 * Contact Information:
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070013 * linux-drivers@emulex.com
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053014 *
Jayamohan Kallickal255fa9a2011-03-25 14:23:57 -070015 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053018 */
19
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -050020#include <linux/bsg-lib.h>
21#include <scsi/scsi_transport_iscsi.h>
22#include <scsi/scsi_bsg_iscsi.h>
Jayamohan Kallickal6733b392009-09-05 07:36:35 +053023#include "be_mgmt.h"
24#include "be_iscsi.h"
John Soni Jose7a158002012-10-20 04:45:51 +053025#include "be_main.h"
26
27/* UE Status Low CSR */
28static const char * const desc_ue_status_low[] = {
29 "CEV",
30 "CTX",
31 "DBUF",
32 "ERX",
33 "Host",
34 "MPU",
35 "NDMA",
36 "PTC ",
37 "RDMA ",
38 "RXF ",
39 "RXIPS ",
40 "RXULP0 ",
41 "RXULP1 ",
42 "RXULP2 ",
43 "TIM ",
44 "TPOST ",
45 "TPRE ",
46 "TXIPS ",
47 "TXULP0 ",
48 "TXULP1 ",
49 "UC ",
50 "WDMA ",
51 "TXULP2 ",
52 "HOST1 ",
53 "P0_OB_LINK ",
54 "P1_OB_LINK ",
55 "HOST_GPIO ",
56 "MBOX ",
57 "AXGMAC0",
58 "AXGMAC1",
59 "JTAG",
60 "MPU_INTPEND"
61};
62
63/* UE Status High CSR */
64static const char * const desc_ue_status_hi[] = {
65 "LPCMEMHOST",
66 "MGMT_MAC",
67 "PCS0ONLINE",
68 "MPU_IRAM",
69 "PCS1ONLINE",
70 "PCTL0",
71 "PCTL1",
72 "PMEM",
73 "RR",
74 "TXPB",
75 "RXPP",
76 "XAUI",
77 "TXP",
78 "ARM",
79 "IPC",
80 "HOST2",
81 "HOST3",
82 "HOST4",
83 "HOST5",
84 "HOST6",
85 "HOST7",
86 "HOST8",
87 "HOST9",
88 "NETC",
89 "Unknown",
90 "Unknown",
91 "Unknown",
92 "Unknown",
93 "Unknown",
94 "Unknown",
95 "Unknown",
96 "Unknown"
97};
98
99/*
100 * beiscsi_ue_detec()- Detect Unrecoverable Error on adapter
101 * @phba: Driver priv structure
102 *
103 * Read registers linked to UE and check for the UE status
104 **/
105void beiscsi_ue_detect(struct beiscsi_hba *phba)
106{
107 uint32_t ue_hi = 0, ue_lo = 0;
108 uint32_t ue_mask_hi = 0, ue_mask_lo = 0;
109 uint8_t i = 0;
110
111 if (phba->ue_detected)
112 return;
113
114 pci_read_config_dword(phba->pcidev,
115 PCICFG_UE_STATUS_LOW, &ue_lo);
116 pci_read_config_dword(phba->pcidev,
117 PCICFG_UE_STATUS_MASK_LOW,
118 &ue_mask_lo);
119 pci_read_config_dword(phba->pcidev,
120 PCICFG_UE_STATUS_HIGH,
121 &ue_hi);
122 pci_read_config_dword(phba->pcidev,
123 PCICFG_UE_STATUS_MASK_HI,
124 &ue_mask_hi);
125
126 ue_lo = (ue_lo & ~ue_mask_lo);
127 ue_hi = (ue_hi & ~ue_mask_hi);
128
129
130 if (ue_lo || ue_hi) {
131 phba->ue_detected = true;
132 beiscsi_log(phba, KERN_ERR,
133 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
134 "BG_%d : Error detected on the adapter\n");
135 }
136
137 if (ue_lo) {
138 for (i = 0; ue_lo; ue_lo >>= 1, i++) {
139 if (ue_lo & 1)
140 beiscsi_log(phba, KERN_ERR,
141 BEISCSI_LOG_CONFIG,
142 "BG_%d : UE_LOW %s bit set\n",
143 desc_ue_status_low[i]);
144 }
145 }
146
147 if (ue_hi) {
148 for (i = 0; ue_hi; ue_hi >>= 1, i++) {
149 if (ue_hi & 1)
150 beiscsi_log(phba, KERN_ERR,
151 BEISCSI_LOG_CONFIG,
152 "BG_%d : UE_HIGH %s bit set\n",
153 desc_ue_status_hi[i]);
154 }
155 }
156}
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530157
John Soni Jose9aef4202012-08-20 23:00:08 +0530158/**
159 * mgmt_reopen_session()- Reopen a session based on reopen_type
160 * @phba: Device priv structure instance
161 * @reopen_type: Type of reopen_session FW should do.
162 * @sess_handle: Session Handle of the session to be re-opened
163 *
164 * return
165 * the TAG used for MBOX Command
166 *
167 **/
168unsigned int mgmt_reopen_session(struct beiscsi_hba *phba,
169 unsigned int reopen_type,
170 unsigned int sess_handle)
171{
172 struct be_ctrl_info *ctrl = &phba->ctrl;
173 struct be_mcc_wrb *wrb;
174 struct be_cmd_reopen_session_req *req;
175 unsigned int tag = 0;
176
John Soni Jose99bc5d52012-08-20 23:00:18 +0530177 beiscsi_log(phba, KERN_INFO,
178 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
179 "BG_%d : In bescsi_get_boot_target\n");
180
John Soni Jose9aef4202012-08-20 23:00:08 +0530181 spin_lock(&ctrl->mbox_lock);
182 tag = alloc_mcc_tag(phba);
183 if (!tag) {
184 spin_unlock(&ctrl->mbox_lock);
185 return tag;
186 }
187
188 wrb = wrb_from_mccq(phba);
189 req = embedded_payload(wrb);
190 wrb->tag0 |= tag;
191 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
192 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
193 OPCODE_ISCSI_INI_DRIVER_REOPEN_ALL_SESSIONS,
194 sizeof(struct be_cmd_reopen_session_resp));
195
196 /* set the reopen_type,sess_handle */
197 req->reopen_type = reopen_type;
198 req->session_handle = sess_handle;
199
200 be_mcc_notify(phba);
201 spin_unlock(&ctrl->mbox_lock);
202 return tag;
203}
204
Mike Christie0e438952012-04-03 23:41:51 -0500205unsigned int mgmt_get_boot_target(struct beiscsi_hba *phba)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530206{
207 struct be_ctrl_info *ctrl = &phba->ctrl;
208 struct be_mcc_wrb *wrb;
Mike Christie0e438952012-04-03 23:41:51 -0500209 struct be_cmd_get_boot_target_req *req;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530210 unsigned int tag = 0;
211
John Soni Jose99bc5d52012-08-20 23:00:18 +0530212 beiscsi_log(phba, KERN_INFO,
213 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
214 "BG_%d : In bescsi_get_boot_target\n");
215
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530216 spin_lock(&ctrl->mbox_lock);
217 tag = alloc_mcc_tag(phba);
218 if (!tag) {
219 spin_unlock(&ctrl->mbox_lock);
220 return tag;
221 }
222
223 wrb = wrb_from_mccq(phba);
224 req = embedded_payload(wrb);
225 wrb->tag0 |= tag;
226 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
227 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
228 OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET,
Mike Christie0e438952012-04-03 23:41:51 -0500229 sizeof(struct be_cmd_get_boot_target_resp));
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530230
231 be_mcc_notify(phba);
232 spin_unlock(&ctrl->mbox_lock);
233 return tag;
234}
235
Mike Christie0e438952012-04-03 23:41:51 -0500236unsigned int mgmt_get_session_info(struct beiscsi_hba *phba,
237 u32 boot_session_handle,
238 struct be_dma_mem *nonemb_cmd)
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530239{
240 struct be_ctrl_info *ctrl = &phba->ctrl;
241 struct be_mcc_wrb *wrb;
242 unsigned int tag = 0;
Mike Christie0e438952012-04-03 23:41:51 -0500243 struct be_cmd_get_session_req *req;
244 struct be_cmd_get_session_resp *resp;
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530245 struct be_sge *sge;
246
John Soni Jose99bc5d52012-08-20 23:00:18 +0530247 beiscsi_log(phba, KERN_INFO,
248 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
249 "BG_%d : In beiscsi_get_session_info\n");
250
Jayamohan Kallickalc7acc5b2010-07-22 04:29:18 +0530251 spin_lock(&ctrl->mbox_lock);
252 tag = alloc_mcc_tag(phba);
253 if (!tag) {
254 spin_unlock(&ctrl->mbox_lock);
255 return tag;
256 }
257
258 nonemb_cmd->size = sizeof(*resp);
259 req = nonemb_cmd->va;
260 memset(req, 0, sizeof(*req));
261 wrb = wrb_from_mccq(phba);
262 sge = nonembedded_sgl(wrb);
263 wrb->tag0 |= tag;
264
265
266 wrb->tag0 |= tag;
267 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
268 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
269 OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
270 sizeof(*resp));
271 req->session_handle = boot_session_handle;
272 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
273 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
274 sge->len = cpu_to_le32(nonemb_cmd->size);
275
276 be_mcc_notify(phba);
277 spin_unlock(&ctrl->mbox_lock);
278 return tag;
279}
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530280
Jayamohan Kallickal03a12312010-07-22 04:17:16 +0530281int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530282 struct beiscsi_hba *phba)
283{
284 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
285 struct be_fw_cfg *req = embedded_payload(wrb);
286 int status = 0;
287
288 spin_lock(&ctrl->mbox_lock);
289 memset(wrb, 0, sizeof(*wrb));
290
291 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
292
293 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
294 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530295 status = be_mbox_notify(ctrl);
296 if (!status) {
297 struct be_fw_cfg *pfw_cfg;
298 pfw_cfg = req;
299 phba->fw_config.phys_port = pfw_cfg->phys_port;
300 phba->fw_config.iscsi_icd_start =
301 pfw_cfg->ulp[0].icd_base;
302 phba->fw_config.iscsi_icd_count =
303 pfw_cfg->ulp[0].icd_count;
304 phba->fw_config.iscsi_cid_start =
305 pfw_cfg->ulp[0].sq_base;
306 phba->fw_config.iscsi_cid_count =
307 pfw_cfg->ulp[0].sq_count;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530308 if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530309 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
310 "BG_%d : FW reported MAX CXNS as %d\t"
311 "Max Supported = %d.\n",
312 phba->fw_config.iscsi_cid_count,
313 BE2_MAX_SESSIONS);
Jayamohan Kallickala3babda2010-01-07 01:51:44 +0530314 phba->fw_config.iscsi_cid_count = BE2_MAX_SESSIONS / 2;
Jayamohan Kallickal7da50872010-01-05 05:04:12 +0530315 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530316 } else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530317 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
318 "BG_%d : Failed in mgmt_get_fw_config\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530319 }
320
321 spin_unlock(&ctrl->mbox_lock);
322 return status;
323}
324
Jayamohan Kallickal03a12312010-07-22 04:17:16 +0530325int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530326 struct beiscsi_hba *phba)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530327{
328 struct be_dma_mem nonemb_cmd;
329 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
330 struct be_mgmt_controller_attributes *req;
331 struct be_sge *sge = nonembedded_sgl(wrb);
332 int status = 0;
333
334 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
335 sizeof(struct be_mgmt_controller_attributes),
336 &nonemb_cmd.dma);
337 if (nonemb_cmd.va == NULL) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530338 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
339 "BG_%d : Failed to allocate memory for "
340 "mgmt_check_supported_fw\n");
Jayamohan Kallickald3ad2bb2010-07-22 04:16:38 +0530341 return -ENOMEM;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530342 }
343 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
344 req = nonemb_cmd.va;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530345 memset(req, 0, sizeof(*req));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530346 spin_lock(&ctrl->mbox_lock);
347 memset(wrb, 0, sizeof(*wrb));
348 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
349 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
350 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
351 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
352 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
353 sge->len = cpu_to_le32(nonemb_cmd.size);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530354 status = be_mbox_notify(ctrl);
355 if (!status) {
356 struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530357 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
358 "BG_%d : Firmware Version of CMD : %s\n"
359 "Firmware Version is : %s\n"
360 "Developer Build, not performing version check...\n",
361 resp->params.hba_attribs
362 .flashrom_version_string,
363 resp->params.hba_attribs.
364 firmware_version_string);
365
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530366 phba->fw_config.iscsi_features =
367 resp->params.hba_attribs.iscsi_features;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530368 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
369 "BM_%d : phba->fw_config.iscsi_features = %d\n",
370 phba->fw_config.iscsi_features);
Jayamohan Kallickal22661e22013-04-05 20:38:28 -0700371 memcpy(phba->fw_ver_str, resp->params.hba_attribs.
372 firmware_version_string, BEISCSI_VER_STRLEN);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530373 } else
John Soni Jose99bc5d52012-08-20 23:00:18 +0530374 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
375 "BG_%d : Failed in mgmt_check_supported_fw\n");
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530376 spin_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530377 if (nonemb_cmd.va)
378 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
379 nonemb_cmd.va, nonemb_cmd.dma);
380
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530381 return status;
382}
383
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -0500384unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl,
385 struct beiscsi_hba *phba,
386 struct bsg_job *job,
387 struct be_dma_mem *nonemb_cmd)
388{
389 struct be_cmd_resp_hdr *resp;
390 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
391 struct be_sge *mcc_sge = nonembedded_sgl(wrb);
392 unsigned int tag = 0;
393 struct iscsi_bsg_request *bsg_req = job->request;
394 struct be_bsg_vendor_cmd *req = nonemb_cmd->va;
395 unsigned short region, sector_size, sector, offset;
396
397 nonemb_cmd->size = job->request_payload.payload_len;
398 memset(nonemb_cmd->va, 0, nonemb_cmd->size);
399 resp = nonemb_cmd->va;
400 region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
401 sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
402 sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
403 offset = bsg_req->rqst_data.h_vendor.vendor_cmd[4];
404 req->region = region;
405 req->sector = sector;
406 req->offset = offset;
407 spin_lock(&ctrl->mbox_lock);
408 memset(wrb, 0, sizeof(*wrb));
409
410 switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) {
411 case BEISCSI_WRITE_FLASH:
412 offset = sector * sector_size + offset;
413 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
414 OPCODE_COMMON_WRITE_FLASH, sizeof(*req));
415 sg_copy_to_buffer(job->request_payload.sg_list,
416 job->request_payload.sg_cnt,
417 nonemb_cmd->va + offset, job->request_len);
418 break;
419 case BEISCSI_READ_FLASH:
420 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
421 OPCODE_COMMON_READ_FLASH, sizeof(*req));
422 break;
423 default:
John Soni Jose99bc5d52012-08-20 23:00:18 +0530424 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
425 "BG_%d : Unsupported cmd = 0x%x\n\n",
426 bsg_req->rqst_data.h_vendor.vendor_cmd[0]);
427
Jayamohan Kallickalffce3e22012-04-03 23:41:50 -0500428 spin_unlock(&ctrl->mbox_lock);
429 return -ENOSYS;
430 }
431
432 tag = alloc_mcc_tag(phba);
433 if (!tag) {
434 spin_unlock(&ctrl->mbox_lock);
435 return tag;
436 }
437
438 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false,
439 job->request_payload.sg_cnt);
440 mcc_sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
441 mcc_sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
442 mcc_sge->len = cpu_to_le32(nonemb_cmd->size);
443 wrb->tag0 |= tag;
444
445 be_mcc_notify(phba);
446
447 spin_unlock(&ctrl->mbox_lock);
448 return tag;
449}
450
Jayamohan Kallickal03a12312010-07-22 04:17:16 +0530451int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530452{
453 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530454 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530455 struct iscsi_cleanup_req *req = embedded_payload(wrb);
456 int status = 0;
457
458 spin_lock(&ctrl->mbox_lock);
459 memset(wrb, 0, sizeof(*wrb));
460
461 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
462 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
463 OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
464
465 req->chute = chute;
Jayamohan Kallickal069adc72011-04-29 14:30:07 -0500466 req->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba));
467 req->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba));
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530468
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530469 status = be_mcc_notify_wait(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530470 if (status)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530471 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
472 "BG_%d : mgmt_epfw_cleanup , FAILED\n");
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530473 spin_unlock(&ctrl->mbox_lock);
474 return status;
475}
476
Jayamohan Kallickal03a12312010-07-22 04:17:16 +0530477unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530478 struct invalidate_command_table *inv_tbl,
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530479 unsigned int num_invalidate, unsigned int cid,
480 struct be_dma_mem *nonemb_cmd)
481
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530482{
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530483 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530484 struct be_mcc_wrb *wrb;
485 struct be_sge *sge;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530486 struct invalidate_commands_params_in *req;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530487 unsigned int i, tag = 0;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530488
489 spin_lock(&ctrl->mbox_lock);
490 tag = alloc_mcc_tag(phba);
491 if (!tag) {
492 spin_unlock(&ctrl->mbox_lock);
493 return tag;
494 }
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530495
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530496 req = nonemb_cmd->va;
Jayamohan Kallickalf98c96b2010-02-11 05:11:15 +0530497 memset(req, 0, sizeof(*req));
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530498 wrb = wrb_from_mccq(phba);
499 sge = nonembedded_sgl(wrb);
500 wrb->tag0 |= tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530501
502 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
503 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
504 OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
505 sizeof(*req));
506 req->ref_handle = 0;
507 req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
Jayamohan Kallickal41831222010-02-20 08:02:39 +0530508 for (i = 0; i < num_invalidate; i++) {
509 req->table[i].icd = inv_tbl->icd;
510 req->table[i].cid = inv_tbl->cid;
511 req->icd_count++;
512 inv_tbl++;
513 }
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530514 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
515 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
516 sge->len = cpu_to_le32(nonemb_cmd->size);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530517
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530518 be_mcc_notify(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530519 spin_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530520 return tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530521}
522
Jayamohan Kallickal03a12312010-07-22 04:17:16 +0530523unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530524 struct beiscsi_endpoint *beiscsi_ep,
525 unsigned short cid,
526 unsigned short issue_reset,
527 unsigned short savecfg_flag)
528{
529 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530530 struct be_mcc_wrb *wrb;
531 struct iscsi_invalidate_connection_params_in *req;
532 unsigned int tag = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530533
534 spin_lock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530535 tag = alloc_mcc_tag(phba);
536 if (!tag) {
537 spin_unlock(&ctrl->mbox_lock);
538 return tag;
539 }
540 wrb = wrb_from_mccq(phba);
541 wrb->tag0 |= tag;
542 req = embedded_payload(wrb);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530543
544 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
545 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
546 OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
547 sizeof(*req));
548 req->session_handle = beiscsi_ep->fw_handle;
549 req->cid = cid;
550 if (issue_reset)
551 req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
552 else
553 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
554 req->save_cfg = savecfg_flag;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530555 be_mcc_notify(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530556 spin_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530557 return tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530558}
559
Jayamohan Kallickal03a12312010-07-22 04:17:16 +0530560unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530561 unsigned short cid, unsigned int upload_flag)
562{
563 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530564 struct be_mcc_wrb *wrb;
565 struct tcp_upload_params_in *req;
566 unsigned int tag = 0;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530567
568 spin_lock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530569 tag = alloc_mcc_tag(phba);
570 if (!tag) {
571 spin_unlock(&ctrl->mbox_lock);
572 return tag;
573 }
574 wrb = wrb_from_mccq(phba);
575 req = embedded_payload(wrb);
576 wrb->tag0 |= tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530577
578 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
579 be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
580 OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
581 req->id = (unsigned short)cid;
582 req->upload_type = (unsigned char)upload_flag;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530583 be_mcc_notify(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530584 spin_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530585 return tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530586}
587
588int mgmt_open_connection(struct beiscsi_hba *phba,
589 struct sockaddr *dst_addr,
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530590 struct beiscsi_endpoint *beiscsi_ep,
591 struct be_dma_mem *nonemb_cmd)
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530592{
593 struct hwi_controller *phwi_ctrlr;
594 struct hwi_context_memory *phwi_context;
595 struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
596 struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
597 struct be_ctrl_info *ctrl = &phba->ctrl;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530598 struct be_mcc_wrb *wrb;
599 struct tcp_connect_and_offload_in *req;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530600 unsigned short def_hdr_id;
601 unsigned short def_data_id;
602 struct phys_addr template_address = { 0, 0 };
603 struct phys_addr *ptemplate_address;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530604 unsigned int tag = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530605 unsigned int i;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530606 unsigned short cid = beiscsi_ep->ep_cid;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530607 struct be_sge *sge;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530608
609 phwi_ctrlr = phba->phwi_ctrlr;
610 phwi_context = phwi_ctrlr->phwi_ctxt;
611 def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba);
612 def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba);
613
614 ptemplate_address = &template_address;
615 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
616 spin_lock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530617 tag = alloc_mcc_tag(phba);
618 if (!tag) {
619 spin_unlock(&ctrl->mbox_lock);
620 return tag;
621 }
622 wrb = wrb_from_mccq(phba);
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530623 memset(wrb, 0, sizeof(*wrb));
624 sge = nonembedded_sgl(wrb);
625
626 req = nonemb_cmd->va;
627 memset(req, 0, sizeof(*req));
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530628 wrb->tag0 |= tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530629
Jayamohan Kallickalb15d05b2010-08-12 23:36:06 +0530630 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530631 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
632 OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
633 sizeof(*req));
634 if (dst_addr->sa_family == PF_INET) {
635 __be32 s_addr = daddr_in->sin_addr.s_addr;
636 req->ip_address.ip_type = BE2_IPV4;
Mike Christie0e438952012-04-03 23:41:51 -0500637 req->ip_address.addr[0] = s_addr & 0x000000ff;
638 req->ip_address.addr[1] = (s_addr & 0x0000ff00) >> 8;
639 req->ip_address.addr[2] = (s_addr & 0x00ff0000) >> 16;
640 req->ip_address.addr[3] = (s_addr & 0xff000000) >> 24;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530641 req->tcp_port = ntohs(daddr_in->sin_port);
642 beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
643 beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
644 beiscsi_ep->ip_type = BE2_IPV4;
645 } else if (dst_addr->sa_family == PF_INET6) {
646 req->ip_address.ip_type = BE2_IPV6;
Mike Christie0e438952012-04-03 23:41:51 -0500647 memcpy(&req->ip_address.addr,
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530648 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
649 req->tcp_port = ntohs(daddr_in6->sin6_port);
650 beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
651 memcpy(&beiscsi_ep->dst6_addr,
652 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
653 beiscsi_ep->ip_type = BE2_IPV6;
654 } else{
John Soni Jose99bc5d52012-08-20 23:00:18 +0530655 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
656 "BG_%d : unknown addr family %d\n",
657 dst_addr->sa_family);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530658 spin_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal5db3f332010-07-22 04:24:22 +0530659 free_mcc_tag(&phba->ctrl, tag);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530660 return -EINVAL;
661
662 }
663 req->cid = cid;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530664 i = phba->nxt_cqid++;
665 if (phba->nxt_cqid == phba->num_cpus)
666 phba->nxt_cqid = 0;
667 req->cq_id = phwi_context->be_cq[i].id;
John Soni Jose99bc5d52012-08-20 23:00:18 +0530668 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
669 "BG_%d : i=%d cq_id=%d\n", i, req->cq_id);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530670 req->defq_id = def_hdr_id;
671 req->hdr_ring_id = def_hdr_id;
672 req->data_ring_id = def_data_id;
673 req->do_offload = 1;
674 req->dataout_template_pa.lo = ptemplate_address->lo;
675 req->dataout_template_pa.hi = ptemplate_address->hi;
Jayamohan Kallickal3cbb7a72010-07-22 04:27:47 +0530676 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
677 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
678 sge->len = cpu_to_le32(nonemb_cmd->size);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530679 be_mcc_notify(phba);
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530680 spin_unlock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530681 return tag;
Jayamohan Kallickal6733b392009-09-05 07:36:35 +0530682}
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530683
Mike Christie0e438952012-04-03 23:41:51 -0500684unsigned int mgmt_get_all_if_id(struct beiscsi_hba *phba)
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530685{
686 struct be_ctrl_info *ctrl = &phba->ctrl;
Mike Christie0e438952012-04-03 23:41:51 -0500687 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
688 struct be_cmd_get_all_if_id_req *req = embedded_payload(wrb);
689 struct be_cmd_get_all_if_id_req *pbe_allid = req;
690 int status = 0;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530691
Mike Christie0e438952012-04-03 23:41:51 -0500692 memset(wrb, 0, sizeof(*wrb));
693
694 spin_lock(&ctrl->mbox_lock);
695
696 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
697 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
698 OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID,
699 sizeof(*req));
700 status = be_mbox_notify(ctrl);
701 if (!status)
702 phba->interface_handle = pbe_allid->if_hndl_list[0];
703 else {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530704 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
705 "BG_%d : Failed in mgmt_get_all_if_id\n");
Mike Christie0e438952012-04-03 23:41:51 -0500706 }
707 spin_unlock(&ctrl->mbox_lock);
708
709 return status;
710}
711
John Soni Josee175def2012-10-20 04:45:40 +0530712/*
713 * mgmt_exec_nonemb_cmd()- Execute Non Embedded MBX Cmd
714 * @phba: Driver priv structure
715 * @nonemb_cmd: Address of the MBX command issued
716 * @resp_buf: Buffer to copy the MBX cmd response
717 * @resp_buf_len: respone lenght to be copied
718 *
719 **/
Mike Christie0e438952012-04-03 23:41:51 -0500720static int mgmt_exec_nonemb_cmd(struct beiscsi_hba *phba,
721 struct be_dma_mem *nonemb_cmd, void *resp_buf,
722 int resp_buf_len)
723{
724 struct be_ctrl_info *ctrl = &phba->ctrl;
725 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
Mike Christie0e438952012-04-03 23:41:51 -0500726 struct be_sge *sge;
727 unsigned int tag;
728 int rc = 0;
729
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530730 spin_lock(&ctrl->mbox_lock);
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530731 tag = alloc_mcc_tag(phba);
732 if (!tag) {
733 spin_unlock(&ctrl->mbox_lock);
Mike Christie0e438952012-04-03 23:41:51 -0500734 rc = -ENOMEM;
735 goto free_cmd;
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530736 }
Mike Christie0e438952012-04-03 23:41:51 -0500737 memset(wrb, 0, sizeof(*wrb));
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530738 wrb->tag0 |= tag;
Mike Christie0e438952012-04-03 23:41:51 -0500739 sge = nonembedded_sgl(wrb);
740
741 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
742 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
John Soni Josee175def2012-10-20 04:45:40 +0530743 sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd->dma));
Mike Christie0e438952012-04-03 23:41:51 -0500744 sge->len = cpu_to_le32(nonemb_cmd->size);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530745
Jayamohan Kallickal756d29c2010-01-05 05:10:46 +0530746 be_mcc_notify(phba);
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530747 spin_unlock(&ctrl->mbox_lock);
Mike Christie0e438952012-04-03 23:41:51 -0500748
John Soni Josee175def2012-10-20 04:45:40 +0530749 rc = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd->va);
750 if (rc) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530751 beiscsi_log(phba, KERN_ERR,
752 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
John Soni Josee175def2012-10-20 04:45:40 +0530753 "BG_%d : mgmt_exec_nonemb_cmd Failed status\n");
754
Mike Christie0e438952012-04-03 23:41:51 -0500755 rc = -EIO;
John Soni Josee175def2012-10-20 04:45:40 +0530756 goto free_cmd;
Mike Christie0e438952012-04-03 23:41:51 -0500757 }
758
759 if (resp_buf)
760 memcpy(resp_buf, nonemb_cmd->va, resp_buf_len);
761
Mike Christie0e438952012-04-03 23:41:51 -0500762free_cmd:
763 pci_free_consistent(ctrl->pdev, nonemb_cmd->size,
764 nonemb_cmd->va, nonemb_cmd->dma);
765 return rc;
Jayamohan Kallickalbfead3b2009-10-23 11:52:33 +0530766}
767
Mike Christie0e438952012-04-03 23:41:51 -0500768static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd,
769 int iscsi_cmd, int size)
770{
Mike Christieb83d5432012-05-23 20:40:54 -0500771 cmd->va = pci_alloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
Mike Christie0e438952012-04-03 23:41:51 -0500772 if (!cmd->va) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530773 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
774 "BG_%d : Failed to allocate memory for if info\n");
Mike Christie0e438952012-04-03 23:41:51 -0500775 return -ENOMEM;
776 }
Mike Christieb83d5432012-05-23 20:40:54 -0500777 memset(cmd->va, 0, size);
Mike Christie0e438952012-04-03 23:41:51 -0500778 cmd->size = size;
779 be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size);
780 return 0;
781}
782
783static int
784mgmt_static_ip_modify(struct beiscsi_hba *phba,
785 struct be_cmd_get_if_info_resp *if_info,
786 struct iscsi_iface_param_info *ip_param,
787 struct iscsi_iface_param_info *subnet_param,
788 uint32_t ip_action)
789{
790 struct be_cmd_set_ip_addr_req *req;
791 struct be_dma_mem nonemb_cmd;
792 uint32_t ip_type;
793 int rc;
794
795 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
796 OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR,
797 sizeof(*req));
798 if (rc)
799 return rc;
800
801 ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
802 BE2_IPV6 : BE2_IPV4 ;
803
804 req = nonemb_cmd.va;
805 req->ip_params.record_entry_count = 1;
806 req->ip_params.ip_record.action = ip_action;
807 req->ip_params.ip_record.interface_hndl =
808 phba->interface_handle;
809 req->ip_params.ip_record.ip_addr.size_of_structure =
810 sizeof(struct be_ip_addr_subnet_format);
811 req->ip_params.ip_record.ip_addr.ip_type = ip_type;
812
813 if (ip_action == IP_ACTION_ADD) {
814 memcpy(req->ip_params.ip_record.ip_addr.addr, ip_param->value,
815 ip_param->len);
816
817 if (subnet_param)
818 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
819 subnet_param->value, subnet_param->len);
820 } else {
821 memcpy(req->ip_params.ip_record.ip_addr.addr,
822 if_info->ip_addr.addr, ip_param->len);
823
824 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
825 if_info->ip_addr.subnet_mask, ip_param->len);
826 }
827
828 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
829 if (rc < 0)
John Soni Jose99bc5d52012-08-20 23:00:18 +0530830 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
831 "BG_%d : Failed to Modify existing IP Address\n");
Mike Christie0e438952012-04-03 23:41:51 -0500832 return rc;
833}
834
835static int mgmt_modify_gateway(struct beiscsi_hba *phba, uint8_t *gt_addr,
836 uint32_t gtway_action, uint32_t param_len)
837{
838 struct be_cmd_set_def_gateway_req *req;
839 struct be_dma_mem nonemb_cmd;
840 int rt_val;
841
842
843 rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
844 OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY,
845 sizeof(*req));
846 if (rt_val)
847 return rt_val;
848
849 req = nonemb_cmd.va;
850 req->action = gtway_action;
851 req->ip_addr.ip_type = BE2_IPV4;
852
853 memcpy(req->ip_addr.addr, gt_addr, param_len);
854
855 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
856}
857
858int mgmt_set_ip(struct beiscsi_hba *phba,
859 struct iscsi_iface_param_info *ip_param,
860 struct iscsi_iface_param_info *subnet_param,
861 uint32_t boot_proto)
862{
863 struct be_cmd_get_def_gateway_resp gtway_addr_set;
864 struct be_cmd_get_if_info_resp if_info;
865 struct be_cmd_set_dhcp_req *dhcpreq;
866 struct be_cmd_rel_dhcp_req *reldhcp;
867 struct be_dma_mem nonemb_cmd;
868 uint8_t *gtway_addr;
869 uint32_t ip_type;
870 int rc;
871
872 if (mgmt_get_all_if_id(phba))
873 return -EIO;
874
875 memset(&if_info, 0, sizeof(if_info));
876 ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
877 BE2_IPV6 : BE2_IPV4 ;
878
879 rc = mgmt_get_if_info(phba, ip_type, &if_info);
880 if (rc)
881 return rc;
882
883 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
884 if (if_info.dhcp_state) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530885 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
886 "BG_%d : DHCP Already Enabled\n");
Mike Christie0e438952012-04-03 23:41:51 -0500887 return 0;
888 }
889 /* The ip_param->len is 1 in DHCP case. Setting
890 proper IP len as this it is used while
891 freeing the Static IP.
892 */
893 ip_param->len = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
894 IP_V6_LEN : IP_V4_LEN;
895
896 } else {
897 if (if_info.dhcp_state) {
898
899 memset(&if_info, 0, sizeof(if_info));
900 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
901 OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR,
902 sizeof(*reldhcp));
903
904 if (rc)
905 return rc;
906
907 reldhcp = nonemb_cmd.va;
908 reldhcp->interface_hndl = phba->interface_handle;
909 reldhcp->ip_type = ip_type;
910
911 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
912 if (rc < 0) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530913 beiscsi_log(phba, KERN_WARNING,
914 BEISCSI_LOG_CONFIG,
915 "BG_%d : Failed to Delete existing dhcp\n");
Mike Christie0e438952012-04-03 23:41:51 -0500916 return rc;
917 }
918 }
919 }
920
921 /* Delete the Static IP Set */
922 if (if_info.ip_addr.addr[0]) {
923 rc = mgmt_static_ip_modify(phba, &if_info, ip_param, NULL,
924 IP_ACTION_DEL);
925 if (rc)
926 return rc;
927 }
928
929 /* Delete the Gateway settings if mode change is to DHCP */
930 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
931 memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
932 rc = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
933 if (rc) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530934 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
935 "BG_%d : Failed to Get Gateway Addr\n");
Mike Christie0e438952012-04-03 23:41:51 -0500936 return rc;
937 }
938
939 if (gtway_addr_set.ip_addr.addr[0]) {
940 gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
941 rc = mgmt_modify_gateway(phba, gtway_addr,
942 IP_ACTION_DEL, IP_V4_LEN);
943
944 if (rc) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530945 beiscsi_log(phba, KERN_WARNING,
946 BEISCSI_LOG_CONFIG,
947 "BG_%d : Failed to clear Gateway Addr Set\n");
Mike Christie0e438952012-04-03 23:41:51 -0500948 return rc;
949 }
950 }
951 }
952
953 /* Set Adapter to DHCP/Static Mode */
954 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
955 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
956 OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
957 sizeof(*dhcpreq));
958 if (rc)
959 return rc;
960
961 dhcpreq = nonemb_cmd.va;
962 dhcpreq->flags = BLOCKING;
963 dhcpreq->retry_count = 1;
964 dhcpreq->interface_hndl = phba->interface_handle;
965 dhcpreq->ip_type = BE2_DHCP_V4;
966
967 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
968 } else {
969 return mgmt_static_ip_modify(phba, &if_info, ip_param,
970 subnet_param, IP_ACTION_ADD);
971 }
972
973 return rc;
974}
975
976int mgmt_set_gateway(struct beiscsi_hba *phba,
977 struct iscsi_iface_param_info *gateway_param)
978{
979 struct be_cmd_get_def_gateway_resp gtway_addr_set;
980 uint8_t *gtway_addr;
981 int rt_val;
982
983 memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
984 rt_val = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
985 if (rt_val) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530986 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
987 "BG_%d : Failed to Get Gateway Addr\n");
Mike Christie0e438952012-04-03 23:41:51 -0500988 return rt_val;
989 }
990
991 if (gtway_addr_set.ip_addr.addr[0]) {
992 gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
993 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_DEL,
994 gateway_param->len);
995 if (rt_val) {
John Soni Jose99bc5d52012-08-20 23:00:18 +0530996 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
997 "BG_%d : Failed to clear Gateway Addr Set\n");
Mike Christie0e438952012-04-03 23:41:51 -0500998 return rt_val;
999 }
1000 }
1001
1002 gtway_addr = (uint8_t *)&gateway_param->value;
1003 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_ADD,
1004 gateway_param->len);
1005
1006 if (rt_val)
John Soni Jose99bc5d52012-08-20 23:00:18 +05301007 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1008 "BG_%d : Failed to Set Gateway Addr\n");
Mike Christie0e438952012-04-03 23:41:51 -05001009
1010 return rt_val;
1011}
1012
1013int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type,
1014 struct be_cmd_get_def_gateway_resp *gateway)
1015{
1016 struct be_cmd_get_def_gateway_req *req;
1017 struct be_dma_mem nonemb_cmd;
1018 int rc;
1019
1020 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1021 OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY,
1022 sizeof(*gateway));
1023 if (rc)
1024 return rc;
1025
1026 req = nonemb_cmd.va;
1027 req->ip_type = ip_type;
1028
1029 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, gateway,
1030 sizeof(*gateway));
1031}
1032
1033int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type,
1034 struct be_cmd_get_if_info_resp *if_info)
1035{
1036 struct be_cmd_get_if_info_req *req;
1037 struct be_dma_mem nonemb_cmd;
1038 int rc;
1039
1040 if (mgmt_get_all_if_id(phba))
1041 return -EIO;
1042
1043 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1044 OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO,
1045 sizeof(*if_info));
1046 if (rc)
1047 return rc;
1048
1049 req = nonemb_cmd.va;
1050 req->interface_hndl = phba->interface_handle;
1051 req->ip_type = ip_type;
1052
1053 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, if_info,
1054 sizeof(*if_info));
1055}
1056
1057int mgmt_get_nic_conf(struct beiscsi_hba *phba,
1058 struct be_cmd_get_nic_conf_resp *nic)
1059{
1060 struct be_dma_mem nonemb_cmd;
1061 int rc;
1062
1063 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1064 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
1065 sizeof(*nic));
1066 if (rc)
1067 return rc;
1068
1069 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic));
1070}
1071
1072
1073
John Soni Jose21771992012-04-03 23:41:49 -05001074unsigned int be_cmd_get_initname(struct beiscsi_hba *phba)
1075{
1076 unsigned int tag = 0;
1077 struct be_mcc_wrb *wrb;
1078 struct be_cmd_hba_name *req;
1079 struct be_ctrl_info *ctrl = &phba->ctrl;
1080
1081 spin_lock(&ctrl->mbox_lock);
1082 tag = alloc_mcc_tag(phba);
1083 if (!tag) {
1084 spin_unlock(&ctrl->mbox_lock);
1085 return tag;
1086 }
1087
1088 wrb = wrb_from_mccq(phba);
1089 req = embedded_payload(wrb);
1090 wrb->tag0 |= tag;
1091 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1092 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1093 OPCODE_ISCSI_INI_CFG_GET_HBA_NAME,
1094 sizeof(*req));
1095
1096 be_mcc_notify(phba);
1097 spin_unlock(&ctrl->mbox_lock);
1098 return tag;
1099}
John Soni Josec62eef02012-04-03 23:41:52 -05001100
1101unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba)
1102{
1103 unsigned int tag = 0;
1104 struct be_mcc_wrb *wrb;
1105 struct be_cmd_ntwk_link_status_req *req;
1106 struct be_ctrl_info *ctrl = &phba->ctrl;
1107
1108 spin_lock(&ctrl->mbox_lock);
1109 tag = alloc_mcc_tag(phba);
1110 if (!tag) {
1111 spin_unlock(&ctrl->mbox_lock);
1112 return tag;
1113 }
1114
1115 wrb = wrb_from_mccq(phba);
1116 req = embedded_payload(wrb);
1117 wrb->tag0 |= tag;
1118 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1119 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1120 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1121 sizeof(*req));
1122
1123 be_mcc_notify(phba);
1124 spin_unlock(&ctrl->mbox_lock);
1125 return tag;
1126}
John Soni Jose9aef4202012-08-20 23:00:08 +05301127
1128/**
1129 * be_mgmt_get_boot_shandle()- Get the session handle
1130 * @phba: device priv structure instance
1131 * @s_handle: session handle returned for boot session.
1132 *
1133 * Get the boot target session handle. In case of
1134 * crashdump mode driver has to issue and MBX Cmd
1135 * for FW to login to boot target
1136 *
1137 * return
1138 * Success: 0
1139 * Failure: Non-Zero value
1140 *
1141 **/
1142int be_mgmt_get_boot_shandle(struct beiscsi_hba *phba,
1143 unsigned int *s_handle)
1144{
1145 struct be_cmd_get_boot_target_resp *boot_resp;
1146 struct be_mcc_wrb *wrb;
John Soni Josee175def2012-10-20 04:45:40 +05301147 unsigned int tag;
John Soni Jose9aef4202012-08-20 23:00:08 +05301148 uint8_t boot_retry = 3;
John Soni Josee175def2012-10-20 04:45:40 +05301149 int rc;
John Soni Jose9aef4202012-08-20 23:00:08 +05301150
1151 do {
1152 /* Get the Boot Target Session Handle and Count*/
1153 tag = mgmt_get_boot_target(phba);
1154 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301155 beiscsi_log(phba, KERN_ERR,
1156 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
1157 "BG_%d : Getting Boot Target Info Failed\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05301158 return -EAGAIN;
John Soni Josee175def2012-10-20 04:45:40 +05301159 }
John Soni Jose9aef4202012-08-20 23:00:08 +05301160
John Soni Josee175def2012-10-20 04:45:40 +05301161 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1162 if (rc) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301163 beiscsi_log(phba, KERN_ERR,
1164 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
John Soni Josee175def2012-10-20 04:45:40 +05301165 "BG_%d : MBX CMD get_boot_target Failed\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05301166 return -EBUSY;
1167 }
John Soni Josee175def2012-10-20 04:45:40 +05301168
John Soni Jose9aef4202012-08-20 23:00:08 +05301169 boot_resp = embedded_payload(wrb);
1170
1171 /* Check if the there are any Boot targets configured */
1172 if (!boot_resp->boot_session_count) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301173 beiscsi_log(phba, KERN_INFO,
1174 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1175 "BG_%d ;No boot targets configured\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05301176 return -ENXIO;
1177 }
1178
1179 /* FW returns the session handle of the boot session */
1180 if (boot_resp->boot_session_handle != INVALID_SESS_HANDLE) {
1181 *s_handle = boot_resp->boot_session_handle;
1182 return 0;
1183 }
1184
1185 /* Issue MBX Cmd to FW to login to the boot target */
1186 tag = mgmt_reopen_session(phba, BE_REOPEN_BOOT_SESSIONS,
1187 INVALID_SESS_HANDLE);
1188 if (!tag) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301189 beiscsi_log(phba, KERN_ERR,
1190 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1191 "BG_%d : mgmt_reopen_session Failed\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05301192 return -EAGAIN;
John Soni Josee175def2012-10-20 04:45:40 +05301193 }
John Soni Jose9aef4202012-08-20 23:00:08 +05301194
John Soni Josee175def2012-10-20 04:45:40 +05301195 rc = beiscsi_mccq_compl(phba, tag, NULL, NULL);
1196 if (rc) {
John Soni Jose99bc5d52012-08-20 23:00:18 +05301197 beiscsi_log(phba, KERN_ERR,
1198 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
John Soni Josee175def2012-10-20 04:45:40 +05301199 "BG_%d : mgmt_reopen_session Failed");
1200 return rc;
John Soni Jose9aef4202012-08-20 23:00:08 +05301201 }
John Soni Jose9aef4202012-08-20 23:00:08 +05301202 } while (--boot_retry);
1203
1204 /* Couldn't log into the boot target */
John Soni Jose99bc5d52012-08-20 23:00:18 +05301205 beiscsi_log(phba, KERN_ERR,
1206 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1207 "BG_%d : Login to Boot Target Failed\n");
John Soni Jose9aef4202012-08-20 23:00:08 +05301208 return -ENXIO;
1209}
John Soni Jose6f722382012-08-20 23:00:43 +05301210
1211/**
1212 * mgmt_set_vlan()- Issue and wait for CMD completion
1213 * @phba: device private structure instance
1214 * @vlan_tag: VLAN tag
1215 *
1216 * Issue the MBX Cmd and wait for the completion of the
1217 * command.
1218 *
1219 * returns
1220 * Success: 0
1221 * Failure: Non-Xero Value
1222 **/
1223int mgmt_set_vlan(struct beiscsi_hba *phba,
1224 uint16_t vlan_tag)
1225{
John Soni Josee175def2012-10-20 04:45:40 +05301226 int rc;
1227 unsigned int tag;
1228 struct be_mcc_wrb *wrb = NULL;
John Soni Jose6f722382012-08-20 23:00:43 +05301229
1230 tag = be_cmd_set_vlan(phba, vlan_tag);
1231 if (!tag) {
1232 beiscsi_log(phba, KERN_ERR,
1233 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1234 "BG_%d : VLAN Setting Failed\n");
1235 return -EBUSY;
John Soni Jose6f722382012-08-20 23:00:43 +05301236 }
1237
John Soni Josee175def2012-10-20 04:45:40 +05301238 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1239 if (rc) {
1240 beiscsi_log(phba, KERN_ERR,
1241 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1242 "BS_%d : VLAN MBX Cmd Failed\n");
1243 return rc;
1244 }
1245 return rc;
John Soni Jose6f722382012-08-20 23:00:43 +05301246}
John Soni Jose5cac7592012-10-20 04:42:25 +05301247
1248/**
1249 * beiscsi_drvr_ver_disp()- Display the driver Name and Version
1250 * @dev: ptr to device not used.
1251 * @attr: device attribute, not used.
1252 * @buf: contains formatted text driver name and version
1253 *
1254 * return
1255 * size of the formatted string
1256 **/
1257ssize_t
1258beiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr,
1259 char *buf)
1260{
1261 return snprintf(buf, PAGE_SIZE, BE_NAME "\n");
1262}
John Soni Joseacb96932012-10-20 04:44:35 +05301263
John Soni Jose26000db2012-10-20 04:45:06 +05301264/**
Jayamohan Kallickal22661e22013-04-05 20:38:28 -07001265 * beiscsi_fw_ver_disp()- Display Firmware Version
1266 * @dev: ptr to device not used.
1267 * @attr: device attribute, not used.
1268 * @buf: contains formatted text Firmware version
1269 *
1270 * return
1271 * size of the formatted string
1272 **/
1273ssize_t
1274beiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr,
1275 char *buf)
1276{
1277 struct Scsi_Host *shost = class_to_shost(dev);
1278 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1279
1280 return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str);
1281}
1282
1283/**
John Soni Jose26000db2012-10-20 04:45:06 +05301284 * beiscsi_adap_family_disp()- Display adapter family.
1285 * @dev: ptr to device to get priv structure
1286 * @attr: device attribute, not used.
1287 * @buf: contains formatted text driver name and version
1288 *
1289 * return
1290 * size of the formatted string
1291 **/
1292ssize_t
1293beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr,
1294 char *buf)
1295{
1296 uint16_t dev_id = 0;
1297 struct Scsi_Host *shost = class_to_shost(dev);
1298 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1299
1300 dev_id = phba->pcidev->device;
1301 switch (dev_id) {
1302 case BE_DEVICE_ID1:
1303 case OC_DEVICE_ID1:
1304 case OC_DEVICE_ID2:
1305 return snprintf(buf, PAGE_SIZE, "BE2 Adapter Family\n");
1306 break;
1307 case BE_DEVICE_ID2:
1308 case OC_DEVICE_ID3:
1309 return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n");
1310 break;
1311 case OC_SKH_ID1:
1312 return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n");
1313 break;
1314 default:
1315 return snprintf(buf, PAGE_SIZE,
Masanari Iidab23f7a02013-04-18 00:12:55 +09001316 "Unknown Adapter Family: 0x%x\n", dev_id);
John Soni Jose26000db2012-10-20 04:45:06 +05301317 break;
1318 }
1319}
1320
1321
John Soni Joseacb96932012-10-20 04:44:35 +05301322void beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params,
1323 struct wrb_handle *pwrb_handle,
1324 struct be_mem_descriptor *mem_descr)
1325{
1326 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1327
1328 memset(pwrb, 0, sizeof(*pwrb));
1329 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1330 max_send_data_segment_length, pwrb,
1331 params->dw[offsetof(struct amap_beiscsi_offload_params,
1332 max_send_data_segment_length) / 32]);
1333 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
1334 BE_TGT_CTX_UPDT_CMD);
1335 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1336 first_burst_length,
1337 pwrb,
1338 params->dw[offsetof(struct amap_beiscsi_offload_params,
1339 first_burst_length) / 32]);
1340 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
1341 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1342 erl) / 32] & OFFLD_PARAMS_ERL));
1343 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
1344 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1345 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1346 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
1347 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1348 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1349 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
1350 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1351 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1352 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
1353 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1354 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1355 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
1356 pwrb,
1357 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1358 exp_statsn) / 32] + 1));
1359 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
1360 pwrb, pwrb_handle->wrb_index);
1361
1362 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1363 max_burst_length, pwrb, params->dw[offsetof
1364 (struct amap_beiscsi_offload_params,
1365 max_burst_length) / 32]);
1366
1367 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
1368 pwrb, pwrb_handle->nxt_wrb_index);
1369 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1370 session_state, pwrb, 0);
1371 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
1372 pwrb, 1);
1373 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
1374 pwrb, 0);
1375 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
1376 0);
1377
1378 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
1379 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1380 pad_buffer_addr_hi, pwrb,
1381 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
1382 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1383 pad_buffer_addr_lo, pwrb,
1384 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
1385}
1386
1387void beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params,
1388 struct wrb_handle *pwrb_handle)
1389{
1390 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1391
1392 memset(pwrb, 0, sizeof(*pwrb));
1393
1394 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1395 max_burst_length, pwrb, params->dw[offsetof
1396 (struct amap_beiscsi_offload_params,
1397 max_burst_length) / 32]);
1398 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1399 max_burst_length, pwrb, params->dw[offsetof
1400 (struct amap_beiscsi_offload_params,
1401 max_burst_length) / 32]);
1402 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1403 type, pwrb,
1404 BE_TGT_CTX_UPDT_CMD);
1405 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1406 ptr2nextwrb,
1407 pwrb, pwrb_handle->nxt_wrb_index);
1408 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, wrb_idx,
1409 pwrb, pwrb_handle->wrb_index);
1410 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1411 max_send_data_segment_length, pwrb,
1412 params->dw[offsetof(struct amap_beiscsi_offload_params,
1413 max_send_data_segment_length) / 32]);
1414 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1415 first_burst_length, pwrb,
1416 params->dw[offsetof(struct amap_beiscsi_offload_params,
1417 first_burst_length) / 32]);
1418 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1419 max_recv_dataseg_len, pwrb, BEISCSI_MAX_RECV_DATASEG_LEN);
1420 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1421 max_cxns, pwrb, BEISCSI_MAX_CXNS);
1422 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, erl, pwrb,
1423 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1424 erl) / 32] & OFFLD_PARAMS_ERL));
1425 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, dde, pwrb,
1426 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1427 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1428 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, hde, pwrb,
1429 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1430 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1431 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1432 ir2t, pwrb,
1433 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1434 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1435 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, imd, pwrb,
1436 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1437 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1438 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1439 data_seq_inorder,
1440 pwrb,
1441 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1442 data_seq_inorder) / 32] &
1443 OFFLD_PARAMS_DATA_SEQ_INORDER) >> 6);
1444 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1445 pdu_seq_inorder,
1446 pwrb,
1447 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1448 pdu_seq_inorder) / 32] &
1449 OFFLD_PARAMS_PDU_SEQ_INORDER) >> 7);
1450 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, max_r2t,
1451 pwrb,
1452 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1453 max_r2t) / 32] &
1454 OFFLD_PARAMS_MAX_R2T) >> 8);
1455 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, stat_sn,
1456 pwrb,
1457 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1458 exp_statsn) / 32] + 1));
1459}