2 * Copyright (C) 2005 - 2013 Emulex
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
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>
27 /* UE Status Low CSR */
28 static const char * const desc_ue_status_low[] = {
63 /* UE Status High CSR */
64 static const char * const desc_ue_status_hi[] = {
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;
111 if (phba->ue_detected)
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,
119 pci_read_config_dword(phba->pcidev,
120 PCICFG_UE_STATUS_HIGH,
122 pci_read_config_dword(phba->pcidev,
123 PCICFG_UE_STATUS_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");
138 for (i = 0; ue_lo; ue_lo >>= 1, i++) {
140 beiscsi_log(phba, KERN_ERR,
142 "BG_%d : UE_LOW %s bit set\n",
143 desc_ue_status_low[i]);
148 for (i = 0; ue_hi; ue_hi >>= 1, i++) {
150 beiscsi_log(phba, KERN_ERR,
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
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);
184 spin_unlock(&ctrl->mbox_lock);
188 wrb = wrb_from_mccq(phba);
189 req = embedded_payload(wrb);
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;
201 spin_unlock(&ctrl->mbox_lock);
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);
219 spin_unlock(&ctrl->mbox_lock);
223 wrb = wrb_from_mccq(phba);
224 req = embedded_payload(wrb);
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));
232 spin_unlock(&ctrl->mbox_lock);
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;
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);
254 spin_unlock(&ctrl->mbox_lock);
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);
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,
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);
277 spin_unlock(&ctrl->mbox_lock);
282 * mgmt_get_fw_config()- Get the FW config for the function
283 * @ctrl: ptr to Ctrl Info
284 * @phba: ptr to the dev priv structure
286 * Get the FW config and resources available for the function.
287 * The resources are created based on the count received here.
291 * Failure: Non-Zero Value
293 int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
294 struct beiscsi_hba *phba)
296 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
297 struct be_fw_cfg *req = embedded_payload(wrb);
300 spin_lock(&ctrl->mbox_lock);
301 memset(wrb, 0, sizeof(*wrb));
303 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
305 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
306 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
307 EMBED_MBX_MAX_PAYLOAD_SIZE);
308 status = be_mbox_notify(ctrl);
311 struct be_fw_cfg *pfw_cfg;
314 if (!is_chip_be2_be3r(phba)) {
315 phba->fw_config.eqid_count = pfw_cfg->eqid_count;
316 phba->fw_config.cqid_count = pfw_cfg->cqid_count;
318 beiscsi_log(phba, KERN_INFO,
320 "BG_%d : EQ_Count : %d CQ_Count : %d\n",
321 phba->fw_config.eqid_count,
322 phba->fw_config.cqid_count);
325 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
326 if (pfw_cfg->ulp[ulp_num].ulp_mode &
327 BEISCSI_ULP_ISCSI_INI_MODE)
329 &phba->fw_config.ulp_supported);
331 phba->fw_config.phys_port = pfw_cfg->phys_port;
332 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
333 if (test_bit(ulp_num, &phba->fw_config.ulp_supported)) {
335 phba->fw_config.iscsi_cid_start[ulp_num] =
336 pfw_cfg->ulp[ulp_num].sq_base;
337 phba->fw_config.iscsi_cid_count[ulp_num] =
338 pfw_cfg->ulp[ulp_num].sq_count;
340 phba->fw_config.iscsi_icd_start[ulp_num] =
341 pfw_cfg->ulp[ulp_num].icd_base;
342 phba->fw_config.iscsi_icd_count[ulp_num] =
343 pfw_cfg->ulp[ulp_num].icd_count;
345 phba->fw_config.iscsi_chain_start[ulp_num] =
346 pfw_cfg->chain_icd[ulp_num].chain_base;
347 phba->fw_config.iscsi_chain_count[ulp_num] =
348 pfw_cfg->chain_icd[ulp_num].chain_count;
350 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
351 "BG_%d : Function loaded on ULP : %d\n"
352 "\tiscsi_cid_count : %d\n"
353 "\tiscsi_cid_start : %d\n"
354 "\t iscsi_icd_count : %d\n"
355 "\t iscsi_icd_start : %d\n",
358 iscsi_cid_count[ulp_num],
360 iscsi_cid_start[ulp_num],
362 iscsi_icd_count[ulp_num],
364 iscsi_icd_start[ulp_num]);
368 phba->fw_config.dual_ulp_aware = (pfw_cfg->function_mode &
369 BEISCSI_FUNC_DUA_MODE);
371 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
372 "BG_%d : DUA Mode : 0x%x\n",
373 phba->fw_config.dual_ulp_aware);
376 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
377 "BG_%d : Failed in mgmt_get_fw_config\n");
381 spin_unlock(&ctrl->mbox_lock);
385 int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
386 struct beiscsi_hba *phba)
388 struct be_dma_mem nonemb_cmd;
389 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
390 struct be_mgmt_controller_attributes *req;
391 struct be_sge *sge = nonembedded_sgl(wrb);
394 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
395 sizeof(struct be_mgmt_controller_attributes),
397 if (nonemb_cmd.va == NULL) {
398 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
399 "BG_%d : Failed to allocate memory for "
400 "mgmt_check_supported_fw\n");
403 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
405 memset(req, 0, sizeof(*req));
406 spin_lock(&ctrl->mbox_lock);
407 memset(wrb, 0, sizeof(*wrb));
408 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
409 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
410 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
411 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
412 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
413 sge->len = cpu_to_le32(nonemb_cmd.size);
414 status = be_mbox_notify(ctrl);
416 struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
417 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
418 "BG_%d : Firmware Version of CMD : %s\n"
419 "Firmware Version is : %s\n"
420 "Developer Build, not performing version check...\n",
421 resp->params.hba_attribs
422 .flashrom_version_string,
423 resp->params.hba_attribs.
424 firmware_version_string);
426 phba->fw_config.iscsi_features =
427 resp->params.hba_attribs.iscsi_features;
428 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
429 "BM_%d : phba->fw_config.iscsi_features = %d\n",
430 phba->fw_config.iscsi_features);
431 memcpy(phba->fw_ver_str, resp->params.hba_attribs.
432 firmware_version_string, BEISCSI_VER_STRLEN);
434 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
435 "BG_%d : Failed in mgmt_check_supported_fw\n");
436 spin_unlock(&ctrl->mbox_lock);
438 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
439 nonemb_cmd.va, nonemb_cmd.dma);
444 unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl,
445 struct beiscsi_hba *phba,
447 struct be_dma_mem *nonemb_cmd)
449 struct be_cmd_resp_hdr *resp;
450 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
451 struct be_sge *mcc_sge = nonembedded_sgl(wrb);
452 unsigned int tag = 0;
453 struct iscsi_bsg_request *bsg_req = job->request;
454 struct be_bsg_vendor_cmd *req = nonemb_cmd->va;
455 unsigned short region, sector_size, sector, offset;
457 nonemb_cmd->size = job->request_payload.payload_len;
458 memset(nonemb_cmd->va, 0, nonemb_cmd->size);
459 resp = nonemb_cmd->va;
460 region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
461 sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
462 sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
463 offset = bsg_req->rqst_data.h_vendor.vendor_cmd[4];
464 req->region = region;
465 req->sector = sector;
466 req->offset = offset;
467 spin_lock(&ctrl->mbox_lock);
468 memset(wrb, 0, sizeof(*wrb));
470 switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) {
471 case BEISCSI_WRITE_FLASH:
472 offset = sector * sector_size + offset;
473 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
474 OPCODE_COMMON_WRITE_FLASH, sizeof(*req));
475 sg_copy_to_buffer(job->request_payload.sg_list,
476 job->request_payload.sg_cnt,
477 nonemb_cmd->va + offset, job->request_len);
479 case BEISCSI_READ_FLASH:
480 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
481 OPCODE_COMMON_READ_FLASH, sizeof(*req));
484 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
485 "BG_%d : Unsupported cmd = 0x%x\n\n",
486 bsg_req->rqst_data.h_vendor.vendor_cmd[0]);
488 spin_unlock(&ctrl->mbox_lock);
492 tag = alloc_mcc_tag(phba);
494 spin_unlock(&ctrl->mbox_lock);
498 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false,
499 job->request_payload.sg_cnt);
500 mcc_sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
501 mcc_sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
502 mcc_sge->len = cpu_to_le32(nonemb_cmd->size);
507 spin_unlock(&ctrl->mbox_lock);
512 * mgmt_epfw_cleanup()- Inform FW to cleanup data structures.
513 * @phba: pointer to dev priv structure
514 * @ulp_num: ULP number.
518 * Failure: Non-Zero Value
520 int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short ulp_num)
522 struct be_ctrl_info *ctrl = &phba->ctrl;
523 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
524 struct iscsi_cleanup_req *req = embedded_payload(wrb);
527 spin_lock(&ctrl->mbox_lock);
528 memset(wrb, 0, sizeof(*wrb));
530 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
531 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
532 OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
534 req->chute = (1 << ulp_num);
535 req->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba, ulp_num));
536 req->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba, ulp_num));
538 status = be_mcc_notify_wait(phba);
540 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
541 "BG_%d : mgmt_epfw_cleanup , FAILED\n");
542 spin_unlock(&ctrl->mbox_lock);
546 unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
547 struct invalidate_command_table *inv_tbl,
548 unsigned int num_invalidate, unsigned int cid,
549 struct be_dma_mem *nonemb_cmd)
552 struct be_ctrl_info *ctrl = &phba->ctrl;
553 struct be_mcc_wrb *wrb;
555 struct invalidate_commands_params_in *req;
556 unsigned int i, tag = 0;
558 spin_lock(&ctrl->mbox_lock);
559 tag = alloc_mcc_tag(phba);
561 spin_unlock(&ctrl->mbox_lock);
565 req = nonemb_cmd->va;
566 memset(req, 0, sizeof(*req));
567 wrb = wrb_from_mccq(phba);
568 sge = nonembedded_sgl(wrb);
571 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
572 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
573 OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
576 req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
577 for (i = 0; i < num_invalidate; i++) {
578 req->table[i].icd = inv_tbl->icd;
579 req->table[i].cid = inv_tbl->cid;
583 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
584 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
585 sge->len = cpu_to_le32(nonemb_cmd->size);
588 spin_unlock(&ctrl->mbox_lock);
592 unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
593 struct beiscsi_endpoint *beiscsi_ep,
595 unsigned short issue_reset,
596 unsigned short savecfg_flag)
598 struct be_ctrl_info *ctrl = &phba->ctrl;
599 struct be_mcc_wrb *wrb;
600 struct iscsi_invalidate_connection_params_in *req;
601 unsigned int tag = 0;
603 spin_lock(&ctrl->mbox_lock);
604 tag = alloc_mcc_tag(phba);
606 spin_unlock(&ctrl->mbox_lock);
609 wrb = wrb_from_mccq(phba);
611 req = embedded_payload(wrb);
613 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
614 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
615 OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
617 req->session_handle = beiscsi_ep->fw_handle;
620 req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
622 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
623 req->save_cfg = savecfg_flag;
625 spin_unlock(&ctrl->mbox_lock);
629 unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
630 unsigned short cid, unsigned int upload_flag)
632 struct be_ctrl_info *ctrl = &phba->ctrl;
633 struct be_mcc_wrb *wrb;
634 struct tcp_upload_params_in *req;
635 unsigned int tag = 0;
637 spin_lock(&ctrl->mbox_lock);
638 tag = alloc_mcc_tag(phba);
640 spin_unlock(&ctrl->mbox_lock);
643 wrb = wrb_from_mccq(phba);
644 req = embedded_payload(wrb);
647 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
648 be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
649 OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
650 req->id = (unsigned short)cid;
651 req->upload_type = (unsigned char)upload_flag;
653 spin_unlock(&ctrl->mbox_lock);
658 * mgmt_open_connection()- Establish a TCP CXN
659 * @dst_addr: Destination Address
660 * @beiscsi_ep: ptr to device endpoint struct
661 * @nonemb_cmd: ptr to memory allocated for command
664 * Success: Tag number of the MBX Command issued
665 * Failure: Error code
667 int mgmt_open_connection(struct beiscsi_hba *phba,
668 struct sockaddr *dst_addr,
669 struct beiscsi_endpoint *beiscsi_ep,
670 struct be_dma_mem *nonemb_cmd)
672 struct hwi_controller *phwi_ctrlr;
673 struct hwi_context_memory *phwi_context;
674 struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
675 struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
676 struct be_ctrl_info *ctrl = &phba->ctrl;
677 struct be_mcc_wrb *wrb;
678 struct tcp_connect_and_offload_in *req;
679 unsigned short def_hdr_id;
680 unsigned short def_data_id;
681 struct phys_addr template_address = { 0, 0 };
682 struct phys_addr *ptemplate_address;
683 unsigned int tag = 0;
684 unsigned int i, ulp_num;
685 unsigned short cid = beiscsi_ep->ep_cid;
688 phwi_ctrlr = phba->phwi_ctrlr;
689 phwi_context = phwi_ctrlr->phwi_ctxt;
691 ulp_num = phwi_ctrlr->wrb_context[BE_GET_CRI_FROM_CID(cid)].ulp_num;
693 def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba, ulp_num);
694 def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba, ulp_num);
696 ptemplate_address = &template_address;
697 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
698 spin_lock(&ctrl->mbox_lock);
699 tag = alloc_mcc_tag(phba);
701 spin_unlock(&ctrl->mbox_lock);
704 wrb = wrb_from_mccq(phba);
705 memset(wrb, 0, sizeof(*wrb));
706 sge = nonembedded_sgl(wrb);
708 req = nonemb_cmd->va;
709 memset(req, 0, sizeof(*req));
712 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
713 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
714 OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
716 if (dst_addr->sa_family == PF_INET) {
717 __be32 s_addr = daddr_in->sin_addr.s_addr;
718 req->ip_address.ip_type = BE2_IPV4;
719 req->ip_address.addr[0] = s_addr & 0x000000ff;
720 req->ip_address.addr[1] = (s_addr & 0x0000ff00) >> 8;
721 req->ip_address.addr[2] = (s_addr & 0x00ff0000) >> 16;
722 req->ip_address.addr[3] = (s_addr & 0xff000000) >> 24;
723 req->tcp_port = ntohs(daddr_in->sin_port);
724 beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
725 beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
726 beiscsi_ep->ip_type = BE2_IPV4;
727 } else if (dst_addr->sa_family == PF_INET6) {
728 req->ip_address.ip_type = BE2_IPV6;
729 memcpy(&req->ip_address.addr,
730 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
731 req->tcp_port = ntohs(daddr_in6->sin6_port);
732 beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
733 memcpy(&beiscsi_ep->dst6_addr,
734 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
735 beiscsi_ep->ip_type = BE2_IPV6;
737 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
738 "BG_%d : unknown addr family %d\n",
739 dst_addr->sa_family);
740 spin_unlock(&ctrl->mbox_lock);
741 free_mcc_tag(&phba->ctrl, tag);
746 i = phba->nxt_cqid++;
747 if (phba->nxt_cqid == phba->num_cpus)
749 req->cq_id = phwi_context->be_cq[i].id;
750 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
751 "BG_%d : i=%d cq_id=%d\n", i, req->cq_id);
752 req->defq_id = def_hdr_id;
753 req->hdr_ring_id = def_hdr_id;
754 req->data_ring_id = def_data_id;
756 req->dataout_template_pa.lo = ptemplate_address->lo;
757 req->dataout_template_pa.hi = ptemplate_address->hi;
758 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
759 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
760 sge->len = cpu_to_le32(nonemb_cmd->size);
762 spin_unlock(&ctrl->mbox_lock);
766 unsigned int mgmt_get_all_if_id(struct beiscsi_hba *phba)
768 struct be_ctrl_info *ctrl = &phba->ctrl;
769 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
770 struct be_cmd_get_all_if_id_req *req = embedded_payload(wrb);
771 struct be_cmd_get_all_if_id_req *pbe_allid = req;
774 memset(wrb, 0, sizeof(*wrb));
776 spin_lock(&ctrl->mbox_lock);
778 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
779 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
780 OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID,
782 status = be_mbox_notify(ctrl);
784 phba->interface_handle = pbe_allid->if_hndl_list[0];
786 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
787 "BG_%d : Failed in mgmt_get_all_if_id\n");
789 spin_unlock(&ctrl->mbox_lock);
795 * mgmt_exec_nonemb_cmd()- Execute Non Embedded MBX Cmd
796 * @phba: Driver priv structure
797 * @nonemb_cmd: Address of the MBX command issued
798 * @resp_buf: Buffer to copy the MBX cmd response
799 * @resp_buf_len: respone lenght to be copied
802 static int mgmt_exec_nonemb_cmd(struct beiscsi_hba *phba,
803 struct be_dma_mem *nonemb_cmd, void *resp_buf,
806 struct be_ctrl_info *ctrl = &phba->ctrl;
807 struct be_mcc_wrb *wrb = wrb_from_mccq(phba);
812 spin_lock(&ctrl->mbox_lock);
813 tag = alloc_mcc_tag(phba);
815 spin_unlock(&ctrl->mbox_lock);
819 memset(wrb, 0, sizeof(*wrb));
821 sge = nonembedded_sgl(wrb);
823 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
824 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
825 sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd->dma));
826 sge->len = cpu_to_le32(nonemb_cmd->size);
829 spin_unlock(&ctrl->mbox_lock);
831 rc = beiscsi_mccq_compl(phba, tag, NULL, nonemb_cmd->va);
833 /* Check if the IOCTL needs to be re-issued */
837 beiscsi_log(phba, KERN_ERR,
838 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
839 "BG_%d : mgmt_exec_nonemb_cmd Failed status\n");
845 memcpy(resp_buf, nonemb_cmd->va, resp_buf_len);
848 pci_free_consistent(ctrl->pdev, nonemb_cmd->size,
849 nonemb_cmd->va, nonemb_cmd->dma);
853 static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd,
854 int iscsi_cmd, int size)
856 cmd->va = pci_alloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
858 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
859 "BG_%d : Failed to allocate memory for if info\n");
862 memset(cmd->va, 0, size);
864 be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size);
869 mgmt_static_ip_modify(struct beiscsi_hba *phba,
870 struct be_cmd_get_if_info_resp *if_info,
871 struct iscsi_iface_param_info *ip_param,
872 struct iscsi_iface_param_info *subnet_param,
875 struct be_cmd_set_ip_addr_req *req;
876 struct be_dma_mem nonemb_cmd;
880 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
881 OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR,
886 ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
887 BE2_IPV6 : BE2_IPV4 ;
890 req->ip_params.record_entry_count = 1;
891 req->ip_params.ip_record.action = ip_action;
892 req->ip_params.ip_record.interface_hndl =
893 phba->interface_handle;
894 req->ip_params.ip_record.ip_addr.size_of_structure =
895 sizeof(struct be_ip_addr_subnet_format);
896 req->ip_params.ip_record.ip_addr.ip_type = ip_type;
898 if (ip_action == IP_ACTION_ADD) {
899 memcpy(req->ip_params.ip_record.ip_addr.addr, ip_param->value,
900 sizeof(req->ip_params.ip_record.ip_addr.addr));
903 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
905 sizeof(req->ip_params.ip_record.ip_addr.subnet_mask));
907 memcpy(req->ip_params.ip_record.ip_addr.addr,
908 if_info->ip_addr.addr,
909 sizeof(req->ip_params.ip_record.ip_addr.addr));
911 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
912 if_info->ip_addr.subnet_mask,
913 sizeof(req->ip_params.ip_record.ip_addr.subnet_mask));
916 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
918 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
919 "BG_%d : Failed to Modify existing IP Address\n");
923 static int mgmt_modify_gateway(struct beiscsi_hba *phba, uint8_t *gt_addr,
924 uint32_t gtway_action, uint32_t param_len)
926 struct be_cmd_set_def_gateway_req *req;
927 struct be_dma_mem nonemb_cmd;
931 rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
932 OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY,
938 req->action = gtway_action;
939 req->ip_addr.ip_type = BE2_IPV4;
941 memcpy(req->ip_addr.addr, gt_addr, sizeof(req->ip_addr.addr));
943 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
946 int mgmt_set_ip(struct beiscsi_hba *phba,
947 struct iscsi_iface_param_info *ip_param,
948 struct iscsi_iface_param_info *subnet_param,
951 struct be_cmd_get_def_gateway_resp gtway_addr_set;
952 struct be_cmd_get_if_info_resp *if_info;
953 struct be_cmd_set_dhcp_req *dhcpreq;
954 struct be_cmd_rel_dhcp_req *reldhcp;
955 struct be_dma_mem nonemb_cmd;
960 if (mgmt_get_all_if_id(phba))
963 ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
964 BE2_IPV6 : BE2_IPV4 ;
966 rc = mgmt_get_if_info(phba, ip_type, &if_info);
972 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
973 if (if_info->dhcp_state) {
974 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
975 "BG_%d : DHCP Already Enabled\n");
978 /* The ip_param->len is 1 in DHCP case. Setting
979 proper IP len as this it is used while
980 freeing the Static IP.
982 ip_param->len = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
983 IP_V6_LEN : IP_V4_LEN;
986 if (if_info->dhcp_state) {
988 memset(if_info, 0, sizeof(*if_info));
989 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
990 OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR,
996 reldhcp = nonemb_cmd.va;
997 reldhcp->interface_hndl = phba->interface_handle;
998 reldhcp->ip_type = ip_type;
1000 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
1002 beiscsi_log(phba, KERN_WARNING,
1004 "BG_%d : Failed to Delete existing dhcp\n");
1010 /* Delete the Static IP Set */
1011 if (if_info->ip_addr.addr[0]) {
1012 rc = mgmt_static_ip_modify(phba, if_info, ip_param, NULL,
1018 /* Delete the Gateway settings if mode change is to DHCP */
1019 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
1020 memset(>way_addr_set, 0, sizeof(gtway_addr_set));
1021 rc = mgmt_get_gateway(phba, BE2_IPV4, >way_addr_set);
1023 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1024 "BG_%d : Failed to Get Gateway Addr\n");
1028 if (gtway_addr_set.ip_addr.addr[0]) {
1029 gtway_addr = (uint8_t *)>way_addr_set.ip_addr.addr;
1030 rc = mgmt_modify_gateway(phba, gtway_addr,
1031 IP_ACTION_DEL, IP_V4_LEN);
1034 beiscsi_log(phba, KERN_WARNING,
1036 "BG_%d : Failed to clear Gateway Addr Set\n");
1042 /* Set Adapter to DHCP/Static Mode */
1043 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
1044 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1045 OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
1050 dhcpreq = nonemb_cmd.va;
1051 dhcpreq->flags = BLOCKING;
1052 dhcpreq->retry_count = 1;
1053 dhcpreq->interface_hndl = phba->interface_handle;
1054 dhcpreq->ip_type = BE2_DHCP_V4;
1056 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
1058 return mgmt_static_ip_modify(phba, if_info, ip_param,
1059 subnet_param, IP_ACTION_ADD);
1065 int mgmt_set_gateway(struct beiscsi_hba *phba,
1066 struct iscsi_iface_param_info *gateway_param)
1068 struct be_cmd_get_def_gateway_resp gtway_addr_set;
1069 uint8_t *gtway_addr;
1072 memset(>way_addr_set, 0, sizeof(gtway_addr_set));
1073 rt_val = mgmt_get_gateway(phba, BE2_IPV4, >way_addr_set);
1075 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1076 "BG_%d : Failed to Get Gateway Addr\n");
1080 if (gtway_addr_set.ip_addr.addr[0]) {
1081 gtway_addr = (uint8_t *)>way_addr_set.ip_addr.addr;
1082 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_DEL,
1083 gateway_param->len);
1085 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1086 "BG_%d : Failed to clear Gateway Addr Set\n");
1091 gtway_addr = (uint8_t *)&gateway_param->value;
1092 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_ADD,
1093 gateway_param->len);
1096 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1097 "BG_%d : Failed to Set Gateway Addr\n");
1102 int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type,
1103 struct be_cmd_get_def_gateway_resp *gateway)
1105 struct be_cmd_get_def_gateway_req *req;
1106 struct be_dma_mem nonemb_cmd;
1109 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1110 OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY,
1115 req = nonemb_cmd.va;
1116 req->ip_type = ip_type;
1118 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, gateway,
1122 int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type,
1123 struct be_cmd_get_if_info_resp **if_info)
1125 struct be_cmd_get_if_info_req *req;
1126 struct be_dma_mem nonemb_cmd;
1127 uint32_t ioctl_size = sizeof(struct be_cmd_get_if_info_resp);
1130 if (mgmt_get_all_if_id(phba))
1134 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1135 OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO,
1140 req = nonemb_cmd.va;
1141 req->interface_hndl = phba->interface_handle;
1142 req->ip_type = ip_type;
1144 /* Allocate memory for if_info */
1145 *if_info = kzalloc(ioctl_size, GFP_KERNEL);
1147 beiscsi_log(phba, KERN_ERR,
1148 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1149 "BG_%d : Memory Allocation Failure\n");
1151 /* Free the DMA memory for the IOCTL issuing */
1152 pci_free_consistent(phba->ctrl.pdev,
1159 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, *if_info,
1162 /* Check if the error is because of Insufficent_Buffer */
1163 if (rc == -EAGAIN) {
1165 /* Get the new memory size */
1166 ioctl_size = ((struct be_cmd_resp_hdr *)
1167 nonemb_cmd.va)->actual_resp_len;
1168 ioctl_size += sizeof(struct be_cmd_req_hdr);
1170 /* Free the previous allocated DMA memory */
1171 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1175 /* Free the virtual memory */
1183 int mgmt_get_nic_conf(struct beiscsi_hba *phba,
1184 struct be_cmd_get_nic_conf_resp *nic)
1186 struct be_dma_mem nonemb_cmd;
1189 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1190 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
1195 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic));
1200 unsigned int be_cmd_get_initname(struct beiscsi_hba *phba)
1202 unsigned int tag = 0;
1203 struct be_mcc_wrb *wrb;
1204 struct be_cmd_hba_name *req;
1205 struct be_ctrl_info *ctrl = &phba->ctrl;
1207 spin_lock(&ctrl->mbox_lock);
1208 tag = alloc_mcc_tag(phba);
1210 spin_unlock(&ctrl->mbox_lock);
1214 wrb = wrb_from_mccq(phba);
1215 req = embedded_payload(wrb);
1217 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1218 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1219 OPCODE_ISCSI_INI_CFG_GET_HBA_NAME,
1222 be_mcc_notify(phba);
1223 spin_unlock(&ctrl->mbox_lock);
1227 unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba)
1229 unsigned int tag = 0;
1230 struct be_mcc_wrb *wrb;
1231 struct be_cmd_ntwk_link_status_req *req;
1232 struct be_ctrl_info *ctrl = &phba->ctrl;
1234 spin_lock(&ctrl->mbox_lock);
1235 tag = alloc_mcc_tag(phba);
1237 spin_unlock(&ctrl->mbox_lock);
1241 wrb = wrb_from_mccq(phba);
1242 req = embedded_payload(wrb);
1244 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1245 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1246 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1249 be_mcc_notify(phba);
1250 spin_unlock(&ctrl->mbox_lock);
1255 * be_mgmt_get_boot_shandle()- Get the session handle
1256 * @phba: device priv structure instance
1257 * @s_handle: session handle returned for boot session.
1259 * Get the boot target session handle. In case of
1260 * crashdump mode driver has to issue and MBX Cmd
1261 * for FW to login to boot target
1265 * Failure: Non-Zero value
1268 int be_mgmt_get_boot_shandle(struct beiscsi_hba *phba,
1269 unsigned int *s_handle)
1271 struct be_cmd_get_boot_target_resp *boot_resp;
1272 struct be_mcc_wrb *wrb;
1274 uint8_t boot_retry = 3;
1278 /* Get the Boot Target Session Handle and Count*/
1279 tag = mgmt_get_boot_target(phba);
1281 beiscsi_log(phba, KERN_ERR,
1282 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
1283 "BG_%d : Getting Boot Target Info Failed\n");
1287 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1289 beiscsi_log(phba, KERN_ERR,
1290 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1291 "BG_%d : MBX CMD get_boot_target Failed\n");
1295 boot_resp = embedded_payload(wrb);
1297 /* Check if the there are any Boot targets configured */
1298 if (!boot_resp->boot_session_count) {
1299 beiscsi_log(phba, KERN_INFO,
1300 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1301 "BG_%d ;No boot targets configured\n");
1305 /* FW returns the session handle of the boot session */
1306 if (boot_resp->boot_session_handle != INVALID_SESS_HANDLE) {
1307 *s_handle = boot_resp->boot_session_handle;
1311 /* Issue MBX Cmd to FW to login to the boot target */
1312 tag = mgmt_reopen_session(phba, BE_REOPEN_BOOT_SESSIONS,
1313 INVALID_SESS_HANDLE);
1315 beiscsi_log(phba, KERN_ERR,
1316 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1317 "BG_%d : mgmt_reopen_session Failed\n");
1321 rc = beiscsi_mccq_compl(phba, tag, NULL, NULL);
1323 beiscsi_log(phba, KERN_ERR,
1324 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1325 "BG_%d : mgmt_reopen_session Failed");
1328 } while (--boot_retry);
1330 /* Couldn't log into the boot target */
1331 beiscsi_log(phba, KERN_ERR,
1332 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1333 "BG_%d : Login to Boot Target Failed\n");
1338 * mgmt_set_vlan()- Issue and wait for CMD completion
1339 * @phba: device private structure instance
1340 * @vlan_tag: VLAN tag
1342 * Issue the MBX Cmd and wait for the completion of the
1347 * Failure: Non-Xero Value
1349 int mgmt_set_vlan(struct beiscsi_hba *phba,
1354 struct be_mcc_wrb *wrb = NULL;
1356 tag = be_cmd_set_vlan(phba, vlan_tag);
1358 beiscsi_log(phba, KERN_ERR,
1359 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1360 "BG_%d : VLAN Setting Failed\n");
1364 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1366 beiscsi_log(phba, KERN_ERR,
1367 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1368 "BS_%d : VLAN MBX Cmd Failed\n");
1375 * beiscsi_drvr_ver_disp()- Display the driver Name and Version
1376 * @dev: ptr to device not used.
1377 * @attr: device attribute, not used.
1378 * @buf: contains formatted text driver name and version
1381 * size of the formatted string
1384 beiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr,
1387 return snprintf(buf, PAGE_SIZE, BE_NAME "\n");
1391 * beiscsi_fw_ver_disp()- Display Firmware Version
1392 * @dev: ptr to device not used.
1393 * @attr: device attribute, not used.
1394 * @buf: contains formatted text Firmware version
1397 * size of the formatted string
1400 beiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr,
1403 struct Scsi_Host *shost = class_to_shost(dev);
1404 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1406 return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str);
1410 * beiscsi_active_session_disp()- Display Sessions Active
1411 * @dev: ptr to device not used.
1412 * @attr: device attribute, not used.
1413 * @buf: contains formatted text Session Count
1416 * size of the formatted string
1419 beiscsi_active_session_disp(struct device *dev, struct device_attribute *attr,
1422 struct Scsi_Host *shost = class_to_shost(dev);
1423 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1424 uint16_t avlbl_cids = 0, ulp_num, len = 0, total_cids = 0;
1426 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
1427 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
1428 avlbl_cids = BEISCSI_ULP_AVLBL_CID(phba, ulp_num);
1429 total_cids = BEISCSI_GET_CID_COUNT(phba, ulp_num);
1430 len += snprintf(buf+len, PAGE_SIZE - len,
1431 "ULP%d : %d\n", ulp_num,
1432 (total_cids - avlbl_cids));
1434 len += snprintf(buf+len, PAGE_SIZE - len,
1435 "ULP%d : %d\n", ulp_num, 0);
1442 * beiscsi_free_session_disp()- Display Avaliable Session
1443 * @dev: ptr to device not used.
1444 * @attr: device attribute, not used.
1445 * @buf: contains formatted text Session Count
1448 * size of the formatted string
1451 beiscsi_free_session_disp(struct device *dev, struct device_attribute *attr,
1454 struct Scsi_Host *shost = class_to_shost(dev);
1455 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1456 uint16_t ulp_num, len = 0;
1458 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
1459 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported))
1460 len += snprintf(buf+len, PAGE_SIZE - len,
1461 "ULP%d : %d\n", ulp_num,
1462 BEISCSI_ULP_AVLBL_CID(phba, ulp_num));
1464 len += snprintf(buf+len, PAGE_SIZE - len,
1465 "ULP%d : %d\n", ulp_num, 0);
1472 * beiscsi_adap_family_disp()- Display adapter family.
1473 * @dev: ptr to device to get priv structure
1474 * @attr: device attribute, not used.
1475 * @buf: contains formatted text driver name and version
1478 * size of the formatted string
1481 beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr,
1484 uint16_t dev_id = 0;
1485 struct Scsi_Host *shost = class_to_shost(dev);
1486 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1488 dev_id = phba->pcidev->device;
1493 return snprintf(buf, PAGE_SIZE, "BE2 Adapter Family\n");
1497 return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n");
1500 return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n");
1503 return snprintf(buf, PAGE_SIZE,
1504 "Unknown Adapter Family: 0x%x\n", dev_id);
1510 * beiscsi_phys_port()- Display Physical Port Identifier
1511 * @dev: ptr to device not used.
1512 * @attr: device attribute, not used.
1513 * @buf: contains formatted text port identifier
1516 * size of the formatted string
1519 beiscsi_phys_port_disp(struct device *dev, struct device_attribute *attr,
1522 struct Scsi_Host *shost = class_to_shost(dev);
1523 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1525 return snprintf(buf, PAGE_SIZE, "Port Identifier : %d\n",
1526 phba->fw_config.phys_port);
1529 void beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params,
1530 struct wrb_handle *pwrb_handle,
1531 struct be_mem_descriptor *mem_descr)
1533 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1535 memset(pwrb, 0, sizeof(*pwrb));
1536 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1537 max_send_data_segment_length, pwrb,
1538 params->dw[offsetof(struct amap_beiscsi_offload_params,
1539 max_send_data_segment_length) / 32]);
1540 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
1541 BE_TGT_CTX_UPDT_CMD);
1542 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1545 params->dw[offsetof(struct amap_beiscsi_offload_params,
1546 first_burst_length) / 32]);
1547 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
1548 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1549 erl) / 32] & OFFLD_PARAMS_ERL));
1550 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
1551 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1552 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1553 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
1554 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1555 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1556 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
1557 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1558 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1559 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
1560 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1561 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1562 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
1564 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1565 exp_statsn) / 32] + 1));
1566 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
1567 pwrb, pwrb_handle->wrb_index);
1569 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1570 max_burst_length, pwrb, params->dw[offsetof
1571 (struct amap_beiscsi_offload_params,
1572 max_burst_length) / 32]);
1574 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
1575 pwrb, pwrb_handle->nxt_wrb_index);
1576 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1577 session_state, pwrb, 0);
1578 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
1580 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
1582 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
1585 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
1586 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1587 pad_buffer_addr_hi, pwrb,
1588 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
1589 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1590 pad_buffer_addr_lo, pwrb,
1591 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
1594 void beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params,
1595 struct wrb_handle *pwrb_handle)
1597 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1599 memset(pwrb, 0, sizeof(*pwrb));
1601 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1602 max_burst_length, pwrb, params->dw[offsetof
1603 (struct amap_beiscsi_offload_params,
1604 max_burst_length) / 32]);
1605 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1607 BE_TGT_CTX_UPDT_CMD);
1608 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1610 pwrb, pwrb_handle->nxt_wrb_index);
1611 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, wrb_idx,
1612 pwrb, pwrb_handle->wrb_index);
1613 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1614 max_send_data_segment_length, pwrb,
1615 params->dw[offsetof(struct amap_beiscsi_offload_params,
1616 max_send_data_segment_length) / 32]);
1617 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1618 first_burst_length, pwrb,
1619 params->dw[offsetof(struct amap_beiscsi_offload_params,
1620 first_burst_length) / 32]);
1621 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1622 max_recv_dataseg_len, pwrb,
1623 params->dw[offsetof(struct amap_beiscsi_offload_params,
1624 max_recv_data_segment_length) / 32]);
1625 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1626 max_cxns, pwrb, BEISCSI_MAX_CXNS);
1627 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, erl, pwrb,
1628 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1629 erl) / 32] & OFFLD_PARAMS_ERL));
1630 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, dde, pwrb,
1631 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1632 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1633 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, hde, pwrb,
1634 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1635 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1636 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1638 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1639 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1640 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, imd, pwrb,
1641 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1642 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1643 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1646 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1647 data_seq_inorder) / 32] &
1648 OFFLD_PARAMS_DATA_SEQ_INORDER) >> 6);
1649 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1652 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1653 pdu_seq_inorder) / 32] &
1654 OFFLD_PARAMS_PDU_SEQ_INORDER) >> 7);
1655 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, max_r2t,
1657 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1659 OFFLD_PARAMS_MAX_R2T) >> 8);
1660 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, stat_sn,
1662 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1663 exp_statsn) / 32] + 1));