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,
903 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
904 subnet_param->value, subnet_param->len);
906 memcpy(req->ip_params.ip_record.ip_addr.addr,
907 if_info->ip_addr.addr, ip_param->len);
909 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
910 if_info->ip_addr.subnet_mask, ip_param->len);
913 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
915 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
916 "BG_%d : Failed to Modify existing IP Address\n");
920 static int mgmt_modify_gateway(struct beiscsi_hba *phba, uint8_t *gt_addr,
921 uint32_t gtway_action, uint32_t param_len)
923 struct be_cmd_set_def_gateway_req *req;
924 struct be_dma_mem nonemb_cmd;
928 rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
929 OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY,
935 req->action = gtway_action;
936 req->ip_addr.ip_type = BE2_IPV4;
938 memcpy(req->ip_addr.addr, gt_addr, param_len);
940 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
943 int mgmt_set_ip(struct beiscsi_hba *phba,
944 struct iscsi_iface_param_info *ip_param,
945 struct iscsi_iface_param_info *subnet_param,
948 struct be_cmd_get_def_gateway_resp gtway_addr_set;
949 struct be_cmd_get_if_info_resp *if_info;
950 struct be_cmd_set_dhcp_req *dhcpreq;
951 struct be_cmd_rel_dhcp_req *reldhcp;
952 struct be_dma_mem nonemb_cmd;
957 if (mgmt_get_all_if_id(phba))
960 ip_type = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
961 BE2_IPV6 : BE2_IPV4 ;
963 rc = mgmt_get_if_info(phba, ip_type, &if_info);
969 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
970 if (if_info->dhcp_state) {
971 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
972 "BG_%d : DHCP Already Enabled\n");
975 /* The ip_param->len is 1 in DHCP case. Setting
976 proper IP len as this it is used while
977 freeing the Static IP.
979 ip_param->len = (ip_param->param == ISCSI_NET_PARAM_IPV6_ADDR) ?
980 IP_V6_LEN : IP_V4_LEN;
983 if (if_info->dhcp_state) {
985 memset(if_info, 0, sizeof(*if_info));
986 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
987 OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR,
993 reldhcp = nonemb_cmd.va;
994 reldhcp->interface_hndl = phba->interface_handle;
995 reldhcp->ip_type = ip_type;
997 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
999 beiscsi_log(phba, KERN_WARNING,
1001 "BG_%d : Failed to Delete existing dhcp\n");
1007 /* Delete the Static IP Set */
1008 if (if_info->ip_addr.addr[0]) {
1009 rc = mgmt_static_ip_modify(phba, if_info, ip_param, NULL,
1015 /* Delete the Gateway settings if mode change is to DHCP */
1016 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
1017 memset(>way_addr_set, 0, sizeof(gtway_addr_set));
1018 rc = mgmt_get_gateway(phba, BE2_IPV4, >way_addr_set);
1020 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1021 "BG_%d : Failed to Get Gateway Addr\n");
1025 if (gtway_addr_set.ip_addr.addr[0]) {
1026 gtway_addr = (uint8_t *)>way_addr_set.ip_addr.addr;
1027 rc = mgmt_modify_gateway(phba, gtway_addr,
1028 IP_ACTION_DEL, IP_V4_LEN);
1031 beiscsi_log(phba, KERN_WARNING,
1033 "BG_%d : Failed to clear Gateway Addr Set\n");
1039 /* Set Adapter to DHCP/Static Mode */
1040 if (boot_proto == ISCSI_BOOTPROTO_DHCP) {
1041 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1042 OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
1047 dhcpreq = nonemb_cmd.va;
1048 dhcpreq->flags = BLOCKING;
1049 dhcpreq->retry_count = 1;
1050 dhcpreq->interface_hndl = phba->interface_handle;
1051 dhcpreq->ip_type = BE2_DHCP_V4;
1053 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
1055 return mgmt_static_ip_modify(phba, if_info, ip_param,
1056 subnet_param, IP_ACTION_ADD);
1062 int mgmt_set_gateway(struct beiscsi_hba *phba,
1063 struct iscsi_iface_param_info *gateway_param)
1065 struct be_cmd_get_def_gateway_resp gtway_addr_set;
1066 uint8_t *gtway_addr;
1069 memset(>way_addr_set, 0, sizeof(gtway_addr_set));
1070 rt_val = mgmt_get_gateway(phba, BE2_IPV4, >way_addr_set);
1072 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1073 "BG_%d : Failed to Get Gateway Addr\n");
1077 if (gtway_addr_set.ip_addr.addr[0]) {
1078 gtway_addr = (uint8_t *)>way_addr_set.ip_addr.addr;
1079 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_DEL,
1080 gateway_param->len);
1082 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1083 "BG_%d : Failed to clear Gateway Addr Set\n");
1088 gtway_addr = (uint8_t *)&gateway_param->value;
1089 rt_val = mgmt_modify_gateway(phba, gtway_addr, IP_ACTION_ADD,
1090 gateway_param->len);
1093 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1094 "BG_%d : Failed to Set Gateway Addr\n");
1099 int mgmt_get_gateway(struct beiscsi_hba *phba, int ip_type,
1100 struct be_cmd_get_def_gateway_resp *gateway)
1102 struct be_cmd_get_def_gateway_req *req;
1103 struct be_dma_mem nonemb_cmd;
1106 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1107 OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY,
1112 req = nonemb_cmd.va;
1113 req->ip_type = ip_type;
1115 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, gateway,
1119 int mgmt_get_if_info(struct beiscsi_hba *phba, int ip_type,
1120 struct be_cmd_get_if_info_resp **if_info)
1122 struct be_cmd_get_if_info_req *req;
1123 struct be_dma_mem nonemb_cmd;
1124 uint32_t ioctl_size = sizeof(struct be_cmd_get_if_info_resp);
1127 if (mgmt_get_all_if_id(phba))
1131 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1132 OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO,
1137 req = nonemb_cmd.va;
1138 req->interface_hndl = phba->interface_handle;
1139 req->ip_type = ip_type;
1141 /* Allocate memory for if_info */
1142 *if_info = kzalloc(ioctl_size, GFP_KERNEL);
1144 beiscsi_log(phba, KERN_ERR,
1145 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1146 "BG_%d : Memory Allocation Failure\n");
1148 /* Free the DMA memory for the IOCTL issuing */
1149 pci_free_consistent(phba->ctrl.pdev,
1156 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, *if_info,
1159 /* Check if the error is because of Insufficent_Buffer */
1160 if (rc == -EAGAIN) {
1162 /* Get the new memory size */
1163 ioctl_size = ((struct be_cmd_resp_hdr *)
1164 nonemb_cmd.va)->actual_resp_len;
1165 ioctl_size += sizeof(struct be_cmd_req_hdr);
1167 /* Free the previous allocated DMA memory */
1168 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1172 /* Free the virtual memory */
1180 int mgmt_get_nic_conf(struct beiscsi_hba *phba,
1181 struct be_cmd_get_nic_conf_resp *nic)
1183 struct be_dma_mem nonemb_cmd;
1186 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1187 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
1192 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic));
1197 unsigned int be_cmd_get_initname(struct beiscsi_hba *phba)
1199 unsigned int tag = 0;
1200 struct be_mcc_wrb *wrb;
1201 struct be_cmd_hba_name *req;
1202 struct be_ctrl_info *ctrl = &phba->ctrl;
1204 spin_lock(&ctrl->mbox_lock);
1205 tag = alloc_mcc_tag(phba);
1207 spin_unlock(&ctrl->mbox_lock);
1211 wrb = wrb_from_mccq(phba);
1212 req = embedded_payload(wrb);
1214 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1215 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1216 OPCODE_ISCSI_INI_CFG_GET_HBA_NAME,
1219 be_mcc_notify(phba);
1220 spin_unlock(&ctrl->mbox_lock);
1224 unsigned int be_cmd_get_port_speed(struct beiscsi_hba *phba)
1226 unsigned int tag = 0;
1227 struct be_mcc_wrb *wrb;
1228 struct be_cmd_ntwk_link_status_req *req;
1229 struct be_ctrl_info *ctrl = &phba->ctrl;
1231 spin_lock(&ctrl->mbox_lock);
1232 tag = alloc_mcc_tag(phba);
1234 spin_unlock(&ctrl->mbox_lock);
1238 wrb = wrb_from_mccq(phba);
1239 req = embedded_payload(wrb);
1241 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1242 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
1243 OPCODE_COMMON_NTWK_LINK_STATUS_QUERY,
1246 be_mcc_notify(phba);
1247 spin_unlock(&ctrl->mbox_lock);
1252 * be_mgmt_get_boot_shandle()- Get the session handle
1253 * @phba: device priv structure instance
1254 * @s_handle: session handle returned for boot session.
1256 * Get the boot target session handle. In case of
1257 * crashdump mode driver has to issue and MBX Cmd
1258 * for FW to login to boot target
1262 * Failure: Non-Zero value
1265 int be_mgmt_get_boot_shandle(struct beiscsi_hba *phba,
1266 unsigned int *s_handle)
1268 struct be_cmd_get_boot_target_resp *boot_resp;
1269 struct be_mcc_wrb *wrb;
1271 uint8_t boot_retry = 3;
1275 /* Get the Boot Target Session Handle and Count*/
1276 tag = mgmt_get_boot_target(phba);
1278 beiscsi_log(phba, KERN_ERR,
1279 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
1280 "BG_%d : Getting Boot Target Info Failed\n");
1284 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1286 beiscsi_log(phba, KERN_ERR,
1287 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1288 "BG_%d : MBX CMD get_boot_target Failed\n");
1292 boot_resp = embedded_payload(wrb);
1294 /* Check if the there are any Boot targets configured */
1295 if (!boot_resp->boot_session_count) {
1296 beiscsi_log(phba, KERN_INFO,
1297 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1298 "BG_%d ;No boot targets configured\n");
1302 /* FW returns the session handle of the boot session */
1303 if (boot_resp->boot_session_handle != INVALID_SESS_HANDLE) {
1304 *s_handle = boot_resp->boot_session_handle;
1308 /* Issue MBX Cmd to FW to login to the boot target */
1309 tag = mgmt_reopen_session(phba, BE_REOPEN_BOOT_SESSIONS,
1310 INVALID_SESS_HANDLE);
1312 beiscsi_log(phba, KERN_ERR,
1313 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1314 "BG_%d : mgmt_reopen_session Failed\n");
1318 rc = beiscsi_mccq_compl(phba, tag, NULL, NULL);
1320 beiscsi_log(phba, KERN_ERR,
1321 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1322 "BG_%d : mgmt_reopen_session Failed");
1325 } while (--boot_retry);
1327 /* Couldn't log into the boot target */
1328 beiscsi_log(phba, KERN_ERR,
1329 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1330 "BG_%d : Login to Boot Target Failed\n");
1335 * mgmt_set_vlan()- Issue and wait for CMD completion
1336 * @phba: device private structure instance
1337 * @vlan_tag: VLAN tag
1339 * Issue the MBX Cmd and wait for the completion of the
1344 * Failure: Non-Xero Value
1346 int mgmt_set_vlan(struct beiscsi_hba *phba,
1351 struct be_mcc_wrb *wrb = NULL;
1353 tag = be_cmd_set_vlan(phba, vlan_tag);
1355 beiscsi_log(phba, KERN_ERR,
1356 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1357 "BG_%d : VLAN Setting Failed\n");
1361 rc = beiscsi_mccq_compl(phba, tag, &wrb, NULL);
1363 beiscsi_log(phba, KERN_ERR,
1364 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1365 "BS_%d : VLAN MBX Cmd Failed\n");
1372 * beiscsi_drvr_ver_disp()- Display the driver Name and Version
1373 * @dev: ptr to device not used.
1374 * @attr: device attribute, not used.
1375 * @buf: contains formatted text driver name and version
1378 * size of the formatted string
1381 beiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr,
1384 return snprintf(buf, PAGE_SIZE, BE_NAME "\n");
1388 * beiscsi_fw_ver_disp()- Display Firmware Version
1389 * @dev: ptr to device not used.
1390 * @attr: device attribute, not used.
1391 * @buf: contains formatted text Firmware version
1394 * size of the formatted string
1397 beiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr,
1400 struct Scsi_Host *shost = class_to_shost(dev);
1401 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1403 return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str);
1407 * beiscsi_active_session_disp()- Display Sessions Active
1408 * @dev: ptr to device not used.
1409 * @attr: device attribute, not used.
1410 * @buf: contains formatted text Session Count
1413 * size of the formatted string
1416 beiscsi_active_session_disp(struct device *dev, struct device_attribute *attr,
1419 struct Scsi_Host *shost = class_to_shost(dev);
1420 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1421 uint16_t avlbl_cids = 0, ulp_num, len = 0, total_cids = 0;
1423 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
1424 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
1425 avlbl_cids = BEISCSI_ULP_AVLBL_CID(phba, ulp_num);
1426 total_cids = BEISCSI_GET_CID_COUNT(phba, ulp_num);
1427 len += snprintf(buf+len, PAGE_SIZE - len,
1428 "ULP%d : %d\n", ulp_num,
1429 (total_cids - avlbl_cids));
1431 len += snprintf(buf+len, PAGE_SIZE - len,
1432 "ULP%d : %d\n", ulp_num, 0);
1439 * beiscsi_free_session_disp()- Display Avaliable Session
1440 * @dev: ptr to device not used.
1441 * @attr: device attribute, not used.
1442 * @buf: contains formatted text Session Count
1445 * size of the formatted string
1448 beiscsi_free_session_disp(struct device *dev, struct device_attribute *attr,
1451 struct Scsi_Host *shost = class_to_shost(dev);
1452 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1453 uint16_t ulp_num, len = 0;
1455 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
1456 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported))
1457 len += snprintf(buf+len, PAGE_SIZE - len,
1458 "ULP%d : %d\n", ulp_num,
1459 BEISCSI_ULP_AVLBL_CID(phba, ulp_num));
1461 len += snprintf(buf+len, PAGE_SIZE - len,
1462 "ULP%d : %d\n", ulp_num, 0);
1469 * beiscsi_adap_family_disp()- Display adapter family.
1470 * @dev: ptr to device to get priv structure
1471 * @attr: device attribute, not used.
1472 * @buf: contains formatted text driver name and version
1475 * size of the formatted string
1478 beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr,
1481 uint16_t dev_id = 0;
1482 struct Scsi_Host *shost = class_to_shost(dev);
1483 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1485 dev_id = phba->pcidev->device;
1490 return snprintf(buf, PAGE_SIZE, "BE2 Adapter Family\n");
1494 return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n");
1497 return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n");
1500 return snprintf(buf, PAGE_SIZE,
1501 "Unknown Adapter Family: 0x%x\n", dev_id);
1507 * beiscsi_phys_port()- Display Physical Port Identifier
1508 * @dev: ptr to device not used.
1509 * @attr: device attribute, not used.
1510 * @buf: contains formatted text port identifier
1513 * size of the formatted string
1516 beiscsi_phys_port_disp(struct device *dev, struct device_attribute *attr,
1519 struct Scsi_Host *shost = class_to_shost(dev);
1520 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1522 return snprintf(buf, PAGE_SIZE, "Port Identifier : %d\n",
1523 phba->fw_config.phys_port);
1526 void beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params,
1527 struct wrb_handle *pwrb_handle,
1528 struct be_mem_descriptor *mem_descr)
1530 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1532 memset(pwrb, 0, sizeof(*pwrb));
1533 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1534 max_send_data_segment_length, pwrb,
1535 params->dw[offsetof(struct amap_beiscsi_offload_params,
1536 max_send_data_segment_length) / 32]);
1537 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
1538 BE_TGT_CTX_UPDT_CMD);
1539 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1542 params->dw[offsetof(struct amap_beiscsi_offload_params,
1543 first_burst_length) / 32]);
1544 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
1545 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1546 erl) / 32] & OFFLD_PARAMS_ERL));
1547 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
1548 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1549 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1550 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
1551 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1552 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1553 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
1554 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1555 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1556 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
1557 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1558 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1559 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
1561 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1562 exp_statsn) / 32] + 1));
1563 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
1564 pwrb, pwrb_handle->wrb_index);
1566 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1567 max_burst_length, pwrb, params->dw[offsetof
1568 (struct amap_beiscsi_offload_params,
1569 max_burst_length) / 32]);
1571 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
1572 pwrb, pwrb_handle->nxt_wrb_index);
1573 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1574 session_state, pwrb, 0);
1575 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
1577 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
1579 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
1582 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
1583 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1584 pad_buffer_addr_hi, pwrb,
1585 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
1586 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1587 pad_buffer_addr_lo, pwrb,
1588 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
1591 void beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params,
1592 struct wrb_handle *pwrb_handle)
1594 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1596 memset(pwrb, 0, sizeof(*pwrb));
1598 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1599 max_burst_length, pwrb, params->dw[offsetof
1600 (struct amap_beiscsi_offload_params,
1601 max_burst_length) / 32]);
1602 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1604 BE_TGT_CTX_UPDT_CMD);
1605 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1607 pwrb, pwrb_handle->nxt_wrb_index);
1608 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, wrb_idx,
1609 pwrb, pwrb_handle->wrb_index);
1610 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1611 max_send_data_segment_length, pwrb,
1612 params->dw[offsetof(struct amap_beiscsi_offload_params,
1613 max_send_data_segment_length) / 32]);
1614 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1615 first_burst_length, pwrb,
1616 params->dw[offsetof(struct amap_beiscsi_offload_params,
1617 first_burst_length) / 32]);
1618 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1619 max_recv_dataseg_len, pwrb,
1620 params->dw[offsetof(struct amap_beiscsi_offload_params,
1621 max_recv_data_segment_length) / 32]);
1622 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1623 max_cxns, pwrb, BEISCSI_MAX_CXNS);
1624 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, erl, pwrb,
1625 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1626 erl) / 32] & OFFLD_PARAMS_ERL));
1627 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, dde, pwrb,
1628 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1629 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1630 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, hde, pwrb,
1631 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1632 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1633 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1635 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1636 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1637 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, imd, pwrb,
1638 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1639 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1640 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1643 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1644 data_seq_inorder) / 32] &
1645 OFFLD_PARAMS_DATA_SEQ_INORDER) >> 6);
1646 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1649 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1650 pdu_seq_inorder) / 32] &
1651 OFFLD_PARAMS_PDU_SEQ_INORDER) >> 7);
1652 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, max_r2t,
1654 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1656 OFFLD_PARAMS_MAX_R2T) >> 8);
1657 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, stat_sn,
1659 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1660 exp_statsn) / 32] + 1));