mfd: wm8350-i2c: Make sure the i2c regmap functions are compiled
[linux/fpc-iii.git] / drivers / scsi / be2iscsi / be_mgmt.c
blobef0a78b0d730a7ecd0c9f0071d510bf7dadb16a0
1 /**
2 * Copyright (C) 2005 - 2013 Emulex
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 (jayamohan.kallickal@emulex.com)
12 * Contact Information:
13 * linux-drivers@emulex.com
15 * Emulex
16 * 3333 Susan Street
17 * Costa Mesa, CA 92626
20 #include <linux/bsg-lib.h>
21 #include <scsi/scsi_transport_iscsi.h>
22 #include <scsi/scsi_bsg_iscsi.h>
23 #include "be_mgmt.h"
24 #include "be_iscsi.h"
25 #include "be_main.h"
27 /* UE Status Low CSR */
28 static 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"
63 /* UE Status High CSR */
64 static 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"
100 * beiscsi_ue_detec()- Detect Unrecoverable Error on adapter
101 * @phba: Driver priv structure
103 * Read registers linked to UE and check for the UE status
105 void beiscsi_ue_detect(struct beiscsi_hba *phba)
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;
111 if (phba->ue_detected)
112 return;
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);
126 ue_lo = (ue_lo & ~ue_mask_lo);
127 ue_hi = (ue_hi & ~ue_mask_hi);
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");
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]);
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]);
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
164 * return
165 * the TAG used for MBOX Command
168 unsigned int mgmt_reopen_session(struct beiscsi_hba *phba,
169 unsigned int reopen_type,
170 unsigned int sess_handle)
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;
177 beiscsi_log(phba, KERN_INFO,
178 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
179 "BG_%d : In bescsi_get_boot_target\n");
181 spin_lock(&ctrl->mbox_lock);
182 tag = alloc_mcc_tag(phba);
183 if (!tag) {
184 spin_unlock(&ctrl->mbox_lock);
185 return tag;
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));
196 /* set the reopen_type,sess_handle */
197 req->reopen_type = reopen_type;
198 req->session_handle = sess_handle;
200 be_mcc_notify(phba);
201 spin_unlock(&ctrl->mbox_lock);
202 return tag;
205 unsigned int mgmt_get_boot_target(struct beiscsi_hba *phba)
207 struct be_ctrl_info *ctrl = &phba->ctrl;
208 struct be_mcc_wrb *wrb;
209 struct be_cmd_get_boot_target_req *req;
210 unsigned int tag = 0;
212 beiscsi_log(phba, KERN_INFO,
213 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
214 "BG_%d : In bescsi_get_boot_target\n");
216 spin_lock(&ctrl->mbox_lock);
217 tag = alloc_mcc_tag(phba);
218 if (!tag) {
219 spin_unlock(&ctrl->mbox_lock);
220 return tag;
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,
229 sizeof(struct be_cmd_get_boot_target_resp));
231 be_mcc_notify(phba);
232 spin_unlock(&ctrl->mbox_lock);
233 return tag;
236 unsigned int mgmt_get_session_info(struct beiscsi_hba *phba,
237 u32 boot_session_handle,
238 struct be_dma_mem *nonemb_cmd)
240 struct be_ctrl_info *ctrl = &phba->ctrl;
241 struct be_mcc_wrb *wrb;
242 unsigned int tag = 0;
243 struct be_cmd_get_session_req *req;
244 struct be_cmd_get_session_resp *resp;
245 struct be_sge *sge;
247 beiscsi_log(phba, KERN_INFO,
248 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
249 "BG_%d : In beiscsi_get_session_info\n");
251 spin_lock(&ctrl->mbox_lock);
252 tag = alloc_mcc_tag(phba);
253 if (!tag) {
254 spin_unlock(&ctrl->mbox_lock);
255 return tag;
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;
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);
276 be_mcc_notify(phba);
277 spin_unlock(&ctrl->mbox_lock);
278 return tag;
281 int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
282 struct beiscsi_hba *phba)
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;
288 spin_lock(&ctrl->mbox_lock);
289 memset(wrb, 0, sizeof(*wrb));
291 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
293 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
294 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG, sizeof(*req));
295 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;
308 if (phba->fw_config.iscsi_cid_count > (BE2_MAX_SESSIONS / 2)) {
309 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);
314 phba->fw_config.iscsi_cid_count = BE2_MAX_SESSIONS / 2;
316 } else {
317 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
318 "BG_%d : Failed in mgmt_get_fw_config\n");
321 spin_unlock(&ctrl->mbox_lock);
322 return status;
325 int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
326 struct beiscsi_hba *phba)
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;
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) {
338 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
339 "BG_%d : Failed to allocate memory for "
340 "mgmt_check_supported_fw\n");
341 return -ENOMEM;
343 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
344 req = nonemb_cmd.va;
345 memset(req, 0, sizeof(*req));
346 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);
354 status = be_mbox_notify(ctrl);
355 if (!status) {
356 struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
357 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);
366 phba->fw_config.iscsi_features =
367 resp->params.hba_attribs.iscsi_features;
368 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
369 "BM_%d : phba->fw_config.iscsi_features = %d\n",
370 phba->fw_config.iscsi_features);
371 memcpy(phba->fw_ver_str, resp->params.hba_attribs.
372 firmware_version_string, BEISCSI_VER_STRLEN);
373 } else
374 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
375 "BG_%d : Failed in mgmt_check_supported_fw\n");
376 spin_unlock(&ctrl->mbox_lock);
377 if (nonemb_cmd.va)
378 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
379 nonemb_cmd.va, nonemb_cmd.dma);
381 return status;
384 unsigned 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)
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;
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));
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:
424 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]);
428 spin_unlock(&ctrl->mbox_lock);
429 return -ENOSYS;
432 tag = alloc_mcc_tag(phba);
433 if (!tag) {
434 spin_unlock(&ctrl->mbox_lock);
435 return tag;
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;
445 be_mcc_notify(phba);
447 spin_unlock(&ctrl->mbox_lock);
448 return tag;
451 int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short chute)
453 struct be_ctrl_info *ctrl = &phba->ctrl;
454 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
455 struct iscsi_cleanup_req *req = embedded_payload(wrb);
456 int status = 0;
458 spin_lock(&ctrl->mbox_lock);
459 memset(wrb, 0, sizeof(*wrb));
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));
465 req->chute = chute;
466 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));
469 status = be_mcc_notify_wait(phba);
470 if (status)
471 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
472 "BG_%d : mgmt_epfw_cleanup , FAILED\n");
473 spin_unlock(&ctrl->mbox_lock);
474 return status;
477 unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
478 struct invalidate_command_table *inv_tbl,
479 unsigned int num_invalidate, unsigned int cid,
480 struct be_dma_mem *nonemb_cmd)
483 struct be_ctrl_info *ctrl = &phba->ctrl;
484 struct be_mcc_wrb *wrb;
485 struct be_sge *sge;
486 struct invalidate_commands_params_in *req;
487 unsigned int i, tag = 0;
489 spin_lock(&ctrl->mbox_lock);
490 tag = alloc_mcc_tag(phba);
491 if (!tag) {
492 spin_unlock(&ctrl->mbox_lock);
493 return tag;
496 req = nonemb_cmd->va;
497 memset(req, 0, sizeof(*req));
498 wrb = wrb_from_mccq(phba);
499 sge = nonembedded_sgl(wrb);
500 wrb->tag0 |= tag;
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;
508 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++;
514 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);
518 be_mcc_notify(phba);
519 spin_unlock(&ctrl->mbox_lock);
520 return tag;
523 unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
524 struct beiscsi_endpoint *beiscsi_ep,
525 unsigned short cid,
526 unsigned short issue_reset,
527 unsigned short savecfg_flag)
529 struct be_ctrl_info *ctrl = &phba->ctrl;
530 struct be_mcc_wrb *wrb;
531 struct iscsi_invalidate_connection_params_in *req;
532 unsigned int tag = 0;
534 spin_lock(&ctrl->mbox_lock);
535 tag = alloc_mcc_tag(phba);
536 if (!tag) {
537 spin_unlock(&ctrl->mbox_lock);
538 return tag;
540 wrb = wrb_from_mccq(phba);
541 wrb->tag0 |= tag;
542 req = embedded_payload(wrb);
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;
555 be_mcc_notify(phba);
556 spin_unlock(&ctrl->mbox_lock);
557 return tag;
560 unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
561 unsigned short cid, unsigned int upload_flag)
563 struct be_ctrl_info *ctrl = &phba->ctrl;
564 struct be_mcc_wrb *wrb;
565 struct tcp_upload_params_in *req;
566 unsigned int tag = 0;
568 spin_lock(&ctrl->mbox_lock);
569 tag = alloc_mcc_tag(phba);
570 if (!tag) {
571 spin_unlock(&ctrl->mbox_lock);
572 return tag;
574 wrb = wrb_from_mccq(phba);
575 req = embedded_payload(wrb);
576 wrb->tag0 |= tag;
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;
583 be_mcc_notify(phba);
584 spin_unlock(&ctrl->mbox_lock);
585 return tag;
588 int mgmt_open_connection(struct beiscsi_hba *phba,
589 struct sockaddr *dst_addr,
590 struct beiscsi_endpoint *beiscsi_ep,
591 struct be_dma_mem *nonemb_cmd)
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;
598 struct be_mcc_wrb *wrb;
599 struct tcp_connect_and_offload_in *req;
600 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;
604 unsigned int tag = 0;
605 unsigned int i;
606 unsigned short cid = beiscsi_ep->ep_cid;
607 struct be_sge *sge;
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);
614 ptemplate_address = &template_address;
615 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
616 spin_lock(&ctrl->mbox_lock);
617 tag = alloc_mcc_tag(phba);
618 if (!tag) {
619 spin_unlock(&ctrl->mbox_lock);
620 return tag;
622 wrb = wrb_from_mccq(phba);
623 memset(wrb, 0, sizeof(*wrb));
624 sge = nonembedded_sgl(wrb);
626 req = nonemb_cmd->va;
627 memset(req, 0, sizeof(*req));
628 wrb->tag0 |= tag;
630 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
631 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;
637 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;
641 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;
647 memcpy(&req->ip_address.addr,
648 &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{
655 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
656 "BG_%d : unknown addr family %d\n",
657 dst_addr->sa_family);
658 spin_unlock(&ctrl->mbox_lock);
659 free_mcc_tag(&phba->ctrl, tag);
660 return -EINVAL;
663 req->cid = cid;
664 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;
668 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
669 "BG_%d : i=%d cq_id=%d\n", i, req->cq_id);
670 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;
676 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);
679 be_mcc_notify(phba);
680 spin_unlock(&ctrl->mbox_lock);
681 return tag;
684 unsigned int mgmt_get_all_if_id(struct beiscsi_hba *phba)
686 struct be_ctrl_info *ctrl = &phba->ctrl;
687 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;
692 memset(wrb, 0, sizeof(*wrb));
694 spin_lock(&ctrl->mbox_lock);
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 {
704 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
705 "BG_%d : Failed in mgmt_get_all_if_id\n");
707 spin_unlock(&ctrl->mbox_lock);
709 return status;
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
720 static int mgmt_exec_nonemb_cmd(struct beiscsi_hba *phba,
721 struct be_dma_mem *nonemb_cmd, void *resp_buf,
722 int resp_buf_len)
724 struct be_ctrl_info *ctrl = &phba->ctrl;
725 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
726 struct be_sge *sge;
727 unsigned int tag;
728 int rc = 0;
730 spin_lock(&ctrl->mbox_lock);
731 tag = alloc_mcc_tag(phba);
732 if (!tag) {
733 spin_unlock(&ctrl->mbox_lock);
734 rc = -ENOMEM;
735 goto free_cmd;
737 memset(wrb, 0, sizeof(*wrb));
738 wrb->tag0 |= tag;
739 sge = nonembedded_sgl(wrb);
741 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
742 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
743 sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd->dma));
744 sge->len = cpu_to_le32(nonemb_cmd->size);
746 be_mcc_notify(phba);
747 spin_unlock(&ctrl->mbox_lock);
749 rc = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd->va);
750 if (rc) {
751 beiscsi_log(phba, KERN_ERR,
752 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
753 "BG_%d : mgmt_exec_nonemb_cmd Failed status\n");
755 rc = -EIO;
756 goto free_cmd;
759 if (resp_buf)
760 memcpy(resp_buf, nonemb_cmd->va, resp_buf_len);
762 free_cmd:
763 pci_free_consistent(ctrl->pdev, nonemb_cmd->size,
764 nonemb_cmd->va, nonemb_cmd->dma);
765 return rc;
768 static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd,
769 int iscsi_cmd, int size)
771 cmd->va = pci_alloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
772 if (!cmd->va) {
773 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
774 "BG_%d : Failed to allocate memory for if info\n");
775 return -ENOMEM;
777 memset(cmd->va, 0, size);
778 cmd->size = size;
779 be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size);
780 return 0;
783 static int
784 mgmt_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)
790 struct be_cmd_set_ip_addr_req *req;
791 struct be_dma_mem nonemb_cmd;
792 uint32_t ip_type;
793 int rc;
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;
801 ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
802 BE2_IPV6 : BE2_IPV4 ;
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;
813 if (ip_action == IP_ACTION_ADD) {
814 memcpy(req->ip_params.ip_record.ip_addr.addr, ip_param->value,
815 sizeof(req->ip_params.ip_record.ip_addr.addr));
817 if (subnet_param)
818 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
819 subnet_param->value,
820 sizeof(req->ip_params.ip_record.ip_addr.subnet_mask));
821 } else {
822 memcpy(req->ip_params.ip_record.ip_addr.addr,
823 if_info->ip_addr.addr,
824 sizeof(req->ip_params.ip_record.ip_addr.addr));
826 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
827 if_info->ip_addr.subnet_mask,
828 sizeof(req->ip_params.ip_record.ip_addr.subnet_mask));
831 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
832 if (rc < 0)
833 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
834 "BG_%d : Failed to Modify existing IP Address\n");
835 return rc;
838 static int mgmt_modify_gateway(struct beiscsi_hba *phba, uint8_t *gt_addr,
839 uint32_t gtway_action, uint32_t param_len)
841 struct be_cmd_set_def_gateway_req *req;
842 struct be_dma_mem nonemb_cmd;
843 int rt_val;
846 rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
847 OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY,
848 sizeof(*req));
849 if (rt_val)
850 return rt_val;
852 req = nonemb_cmd.va;
853 req->action = gtway_action;
854 req->ip_addr.ip_type = BE2_IPV4;
856 memcpy(req->ip_addr.addr, gt_addr, sizeof(req->ip_addr.addr));
858 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
861 int mgmt_set_ip(struct beiscsi_hba *phba,
862 struct iscsi_iface_param_info *ip_param,
863 struct iscsi_iface_param_info *subnet_param,
864 uint32_t boot_proto)
866 struct be_cmd_get_def_gateway_resp gtway_addr_set;
867 struct be_cmd_get_if_info_resp if_info;
868 struct be_cmd_set_dhcp_req *dhcpreq;
869 struct be_cmd_rel_dhcp_req *reldhcp;
870 struct be_dma_mem nonemb_cmd;
871 uint8_t *gtway_addr;
872 uint32_t ip_type;
873 int rc;
875 if (mgmt_get_all_if_id(phba))
876 return -EIO;
878 memset(&if_info, 0, sizeof(if_info));
879 ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
880 BE2_IPV6 : BE2_IPV4 ;
882 rc = mgmt_get_if_info(phba, ip_type, &if_info);
883 if (rc)
884 return rc;
886 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
887 if (if_info.dhcp_state) {
888 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
889 "BG_%d : DHCP Already Enabled\n");
890 return 0;
892 /* The ip_param->len is 1 in DHCP case. Setting
893 proper IP len as this it is used while
894 freeing the Static IP.
896 ip_param->len = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
897 IP_V6_LEN : IP_V4_LEN;
899 } else {
900 if (if_info.dhcp_state) {
902 memset(&if_info, 0, sizeof(if_info));
903 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
904 OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR,
905 sizeof(*reldhcp));
907 if (rc)
908 return rc;
910 reldhcp = nonemb_cmd.va;
911 reldhcp->interface_hndl = phba->interface_handle;
912 reldhcp->ip_type = ip_type;
914 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
915 if (rc < 0) {
916 beiscsi_log(phba, KERN_WARNING,
917 BEISCSI_LOG_CONFIG,
918 "BG_%d : Failed to Delete existing dhcp\n");
919 return rc;
924 /* Delete the Static IP Set */
925 if (if_info.ip_addr.addr[0]) {
926 rc = mgmt_static_ip_modify(phba, &if_info, ip_param, NULL,
927 IP_ACTION_DEL);
928 if (rc)
929 return rc;
932 /* Delete the Gateway settings if mode change is to DHCP */
933 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
934 memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
935 rc = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
936 if (rc) {
937 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
938 "BG_%d : Failed to Get Gateway Addr\n");
939 return rc;
942 if (gtway_addr_set.ip_addr.addr[0]) {
943 gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
944 rc = mgmt_modify_gateway(phba, gtway_addr,
945 IP_ACTION_DEL, IP_V4_LEN);
947 if (rc) {
948 beiscsi_log(phba, KERN_WARNING,
949 BEISCSI_LOG_CONFIG,
950 "BG_%d : Failed to clear Gateway Addr Set\n");
951 return rc;
956 /* Set Adapter to DHCP/Static Mode */
957 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
958 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
959 OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
960 sizeof(*dhcpreq));
961 if (rc)
962 return rc;
964 dhcpreq = nonemb_cmd.va;
965 dhcpreq->flags = BLOCKING;
966 dhcpreq->retry_count = 1;
967 dhcpreq->interface_hndl = phba->interface_handle;
968 dhcpreq->ip_type = BE2_DHCP_V4;
970 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
971 } else {
972 return mgmt_static_ip_modify(phba, &if_info, ip_param,
973 subnet_param, IP_ACTION_ADD);
976 return rc;
979 int mgmt_set_gateway(struct beiscsi_hba *phba,
980 struct iscsi_iface_param_info *gateway_param)
982 struct be_cmd_get_def_gateway_resp gtway_addr_set;
983 uint8_t *gtway_addr;
984 int rt_val;
986 memset(&gtway_addr_set, 0, sizeof(gtway_addr_set));
987 rt_val = mgmt_get_gateway(phba, BE2_IPV4, &gtway_addr_set);
988 if (rt_val) {
989 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
990 "BG_%d : Failed to Get Gateway Addr\n");
991 return rt_val;
994 if (gtway_addr_set.ip_addr.addr[0]) {
995 gtway_addr = (uint8_t *)&gtway_addr_set.ip_addr.addr;
996 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_DEL,
997 gateway_param->len);
998 if (rt_val) {
999 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1000 "BG_%d : Failed to clear Gateway Addr Set\n");
1001 return rt_val;
1005 gtway_addr = (uint8_t *)&gateway_param->value;
1006 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_ADD,
1007 gateway_param->len);
1009 if (rt_val)
1010 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1011 "BG_%d : Failed to Set Gateway Addr\n");
1013 return rt_val;
1016 int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type,
1017 struct be_cmd_get_def_gateway_resp *gateway)
1019 struct be_cmd_get_def_gateway_req *req;
1020 struct be_dma_mem nonemb_cmd;
1021 int rc;
1023 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1024 OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY,
1025 sizeof(*gateway));
1026 if (rc)
1027 return rc;
1029 req = nonemb_cmd.va;
1030 req->ip_type = ip_type;
1032 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, gateway,
1033 sizeof(*gateway));
1036 int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type,
1037 struct be_cmd_get_if_info_resp *if_info)
1039 struct be_cmd_get_if_info_req *req;
1040 struct be_dma_mem nonemb_cmd;
1041 int rc;
1043 if (mgmt_get_all_if_id(phba))
1044 return -EIO;
1046 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1047 OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO,
1048 sizeof(*if_info));
1049 if (rc)
1050 return rc;
1052 req = nonemb_cmd.va;
1053 req->interface_hndl = phba->interface_handle;
1054 req->ip_type = ip_type;
1056 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, if_info,
1057 sizeof(*if_info));
1060 int mgmt_get_nic_conf(struct beiscsi_hba *phba,
1061 struct be_cmd_get_nic_conf_resp *nic)
1063 struct be_dma_mem nonemb_cmd;
1064 int rc;
1066 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1067 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
1068 sizeof(*nic));
1069 if (rc)
1070 return rc;
1072 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic));
1077 unsigned int be_cmd_get_initname(struct beiscsi_hba *phba)
1079 unsigned int tag = 0;
1080 struct be_mcc_wrb *wrb;
1081 struct be_cmd_hba_name *req;
1082 struct be_ctrl_info *ctrl = &phba->ctrl;
1084 spin_lock(&ctrl->mbox_lock);
1085 tag = alloc_mcc_tag(phba);
1086 if (!tag) {
1087 spin_unlock(&ctrl->mbox_lock);
1088 return tag;
1091 wrb = wrb_from_mccq(phba);
1092 req = embedded_payload(wrb);
1093 wrb->tag0 |= tag;
1094 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1095 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1096 OPCODE_ISCSI_INI_CFG_GET_HBA_NAME,
1097 sizeof(*req));
1099 be_mcc_notify(phba);
1100 spin_unlock(&ctrl->mbox_lock);
1101 return tag;
1104 unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba)
1106 unsigned int tag = 0;
1107 struct be_mcc_wrb *wrb;
1108 struct be_cmd_ntwk_link_status_req *req;
1109 struct be_ctrl_info *ctrl = &phba->ctrl;
1111 spin_lock(&ctrl->mbox_lock);
1112 tag = alloc_mcc_tag(phba);
1113 if (!tag) {
1114 spin_unlock(&ctrl->mbox_lock);
1115 return tag;
1118 wrb = wrb_from_mccq(phba);
1119 req = embedded_payload(wrb);
1120 wrb->tag0 |= tag;
1121 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1122 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1123 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1124 sizeof(*req));
1126 be_mcc_notify(phba);
1127 spin_unlock(&ctrl->mbox_lock);
1128 return tag;
1132 * be_mgmt_get_boot_shandle()- Get the session handle
1133 * @phba: device priv structure instance
1134 * @s_handle: session handle returned for boot session.
1136 * Get the boot target session handle. In case of
1137 * crashdump mode driver has to issue and MBX Cmd
1138 * for FW to login to boot target
1140 * return
1141 * Success: 0
1142 * Failure: Non-Zero value
1145 int be_mgmt_get_boot_shandle(struct beiscsi_hba *phba,
1146 unsigned int *s_handle)
1148 struct be_cmd_get_boot_target_resp *boot_resp;
1149 struct be_mcc_wrb *wrb;
1150 unsigned int tag;
1151 uint8_t boot_retry = 3;
1152 int rc;
1154 do {
1155 /* Get the Boot Target Session Handle and Count*/
1156 tag = mgmt_get_boot_target(phba);
1157 if (!tag) {
1158 beiscsi_log(phba, KERN_ERR,
1159 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
1160 "BG_%d : Getting Boot Target Info Failed\n");
1161 return -EAGAIN;
1164 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1165 if (rc) {
1166 beiscsi_log(phba, KERN_ERR,
1167 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1168 "BG_%d : MBX CMD get_boot_target Failed\n");
1169 return -EBUSY;
1172 boot_resp = embedded_payload(wrb);
1174 /* Check if the there are any Boot targets configured */
1175 if (!boot_resp->boot_session_count) {
1176 beiscsi_log(phba, KERN_INFO,
1177 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1178 "BG_%d ;No boot targets configured\n");
1179 return -ENXIO;
1182 /* FW returns the session handle of the boot session */
1183 if (boot_resp->boot_session_handle != INVALID_SESS_HANDLE) {
1184 *s_handle = boot_resp->boot_session_handle;
1185 return 0;
1188 /* Issue MBX Cmd to FW to login to the boot target */
1189 tag = mgmt_reopen_session(phba, BE_REOPEN_BOOT_SESSIONS,
1190 INVALID_SESS_HANDLE);
1191 if (!tag) {
1192 beiscsi_log(phba, KERN_ERR,
1193 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1194 "BG_%d : mgmt_reopen_session Failed\n");
1195 return -EAGAIN;
1198 rc = beiscsi_mccq_compl(phba, tag, NULL, NULL);
1199 if (rc) {
1200 beiscsi_log(phba, KERN_ERR,
1201 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1202 "BG_%d : mgmt_reopen_session Failed");
1203 return rc;
1205 } while (--boot_retry);
1207 /* Couldn't log into the boot target */
1208 beiscsi_log(phba, KERN_ERR,
1209 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1210 "BG_%d : Login to Boot Target Failed\n");
1211 return -ENXIO;
1215 * mgmt_set_vlan()- Issue and wait for CMD completion
1216 * @phba: device private structure instance
1217 * @vlan_tag: VLAN tag
1219 * Issue the MBX Cmd and wait for the completion of the
1220 * command.
1222 * returns
1223 * Success: 0
1224 * Failure: Non-Xero Value
1226 int mgmt_set_vlan(struct beiscsi_hba *phba,
1227 uint16_t vlan_tag)
1229 int rc;
1230 unsigned int tag;
1231 struct be_mcc_wrb *wrb = NULL;
1233 tag = be_cmd_set_vlan(phba, vlan_tag);
1234 if (!tag) {
1235 beiscsi_log(phba, KERN_ERR,
1236 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1237 "BG_%d : VLAN Setting Failed\n");
1238 return -EBUSY;
1241 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1242 if (rc) {
1243 beiscsi_log(phba, KERN_ERR,
1244 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1245 "BS_%d : VLAN MBX Cmd Failed\n");
1246 return rc;
1248 return rc;
1252 * beiscsi_drvr_ver_disp()- Display the driver Name and Version
1253 * @dev: ptr to device not used.
1254 * @attr: device attribute, not used.
1255 * @buf: contains formatted text driver name and version
1257 * return
1258 * size of the formatted string
1260 ssize_t
1261 beiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr,
1262 char *buf)
1264 return snprintf(buf, PAGE_SIZE, BE_NAME "\n");
1268 * beiscsi_fw_ver_disp()- Display Firmware Version
1269 * @dev: ptr to device not used.
1270 * @attr: device attribute, not used.
1271 * @buf: contains formatted text Firmware version
1273 * return
1274 * size of the formatted string
1276 ssize_t
1277 beiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr,
1278 char *buf)
1280 struct Scsi_Host *shost = class_to_shost(dev);
1281 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1283 return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str);
1287 * beiscsi_active_cid_disp()- Display Sessions Active
1288 * @dev: ptr to device not used.
1289 * @attr: device attribute, not used.
1290 * @buf: contains formatted text Session Count
1292 * return
1293 * size of the formatted string
1295 ssize_t
1296 beiscsi_active_cid_disp(struct device *dev, struct device_attribute *attr,
1297 char *buf)
1299 struct Scsi_Host *shost = class_to_shost(dev);
1300 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1302 return snprintf(buf, PAGE_SIZE, "%d\n",
1303 (phba->params.cxns_per_ctrl - phba->avlbl_cids));
1307 * beiscsi_adap_family_disp()- Display adapter family.
1308 * @dev: ptr to device to get priv structure
1309 * @attr: device attribute, not used.
1310 * @buf: contains formatted text driver name and version
1312 * return
1313 * size of the formatted string
1315 ssize_t
1316 beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr,
1317 char *buf)
1319 uint16_t dev_id = 0;
1320 struct Scsi_Host *shost = class_to_shost(dev);
1321 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1323 dev_id = phba->pcidev->device;
1324 switch (dev_id) {
1325 case BE_DEVICE_ID1:
1326 case OC_DEVICE_ID1:
1327 case OC_DEVICE_ID2:
1328 return snprintf(buf, PAGE_SIZE, "BE2 Adapter Family\n");
1329 break;
1330 case BE_DEVICE_ID2:
1331 case OC_DEVICE_ID3:
1332 return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n");
1333 break;
1334 case OC_SKH_ID1:
1335 return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n");
1336 break;
1337 default:
1338 return snprintf(buf, PAGE_SIZE,
1339 "Unknown Adapter Family: 0x%x\n", dev_id);
1340 break;
1345 void beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params,
1346 struct wrb_handle *pwrb_handle,
1347 struct be_mem_descriptor *mem_descr)
1349 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1351 memset(pwrb, 0, sizeof(*pwrb));
1352 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1353 max_send_data_segment_length, pwrb,
1354 params->dw[offsetof(struct amap_beiscsi_offload_params,
1355 max_send_data_segment_length) / 32]);
1356 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
1357 BE_TGT_CTX_UPDT_CMD);
1358 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1359 first_burst_length,
1360 pwrb,
1361 params->dw[offsetof(struct amap_beiscsi_offload_params,
1362 first_burst_length) / 32]);
1363 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
1364 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1365 erl) / 32] & OFFLD_PARAMS_ERL));
1366 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
1367 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1368 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1369 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
1370 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1371 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1372 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
1373 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1374 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1375 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
1376 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1377 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1378 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
1379 pwrb,
1380 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1381 exp_statsn) / 32] + 1));
1382 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
1383 pwrb, pwrb_handle->wrb_index);
1385 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1386 max_burst_length, pwrb, params->dw[offsetof
1387 (struct amap_beiscsi_offload_params,
1388 max_burst_length) / 32]);
1390 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
1391 pwrb, pwrb_handle->nxt_wrb_index);
1392 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1393 session_state, pwrb, 0);
1394 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
1395 pwrb, 1);
1396 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
1397 pwrb, 0);
1398 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
1401 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
1402 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1403 pad_buffer_addr_hi, pwrb,
1404 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
1405 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1406 pad_buffer_addr_lo, pwrb,
1407 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
1410 void beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params,
1411 struct wrb_handle *pwrb_handle)
1413 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1415 memset(pwrb, 0, sizeof(*pwrb));
1417 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1418 max_burst_length, pwrb, params->dw[offsetof
1419 (struct amap_beiscsi_offload_params,
1420 max_burst_length) / 32]);
1421 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1422 max_burst_length, pwrb, params->dw[offsetof
1423 (struct amap_beiscsi_offload_params,
1424 max_burst_length) / 32]);
1425 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1426 type, pwrb,
1427 BE_TGT_CTX_UPDT_CMD);
1428 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1429 ptr2nextwrb,
1430 pwrb, pwrb_handle->nxt_wrb_index);
1431 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, wrb_idx,
1432 pwrb, pwrb_handle->wrb_index);
1433 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1434 max_send_data_segment_length, pwrb,
1435 params->dw[offsetof(struct amap_beiscsi_offload_params,
1436 max_send_data_segment_length) / 32]);
1437 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1438 first_burst_length, pwrb,
1439 params->dw[offsetof(struct amap_beiscsi_offload_params,
1440 first_burst_length) / 32]);
1441 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1442 max_recv_dataseg_len, pwrb, BEISCSI_MAX_RECV_DATASEG_LEN);
1443 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1444 max_cxns, pwrb, BEISCSI_MAX_CXNS);
1445 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, erl, pwrb,
1446 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1447 erl) / 32] & OFFLD_PARAMS_ERL));
1448 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, dde, pwrb,
1449 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1450 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1451 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, hde, pwrb,
1452 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1453 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1454 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1455 ir2t, pwrb,
1456 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1457 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1458 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, imd, pwrb,
1459 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1460 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1461 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1462 data_seq_inorder,
1463 pwrb,
1464 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1465 data_seq_inorder) / 32] &
1466 OFFLD_PARAMS_DATA_SEQ_INORDER) >> 6);
1467 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1468 pdu_seq_inorder,
1469 pwrb,
1470 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1471 pdu_seq_inorder) / 32] &
1472 OFFLD_PARAMS_PDU_SEQ_INORDER) >> 7);
1473 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, max_r2t,
1474 pwrb,
1475 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1476 max_r2t) / 32] &
1477 OFFLD_PARAMS_MAX_R2T) >> 8);
1478 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, stat_sn,
1479 pwrb,
1480 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1481 exp_statsn) / 32] + 1));