2 * Copyright (C) 2005 - 2015 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@avagotech.com)
12 * Contact Information:
13 * linux-drivers@avagotech.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_detect()- 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 pci_read_config_dword(phba->pcidev,
112 PCICFG_UE_STATUS_LOW, &ue_lo);
113 pci_read_config_dword(phba->pcidev,
114 PCICFG_UE_STATUS_MASK_LOW,
116 pci_read_config_dword(phba->pcidev,
117 PCICFG_UE_STATUS_HIGH,
119 pci_read_config_dword(phba->pcidev,
120 PCICFG_UE_STATUS_MASK_HI,
123 ue_lo = (ue_lo & ~ue_mask_lo);
124 ue_hi = (ue_hi & ~ue_mask_hi);
127 if (ue_lo || ue_hi) {
128 set_bit(BEISCSI_HBA_IN_UE, &phba->state);
129 beiscsi_log(phba, KERN_ERR,
130 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
131 "BG_%d : HBA error detected\n");
135 for (i = 0; ue_lo; ue_lo >>= 1, i++) {
137 beiscsi_log(phba, KERN_ERR,
139 "BG_%d : UE_LOW %s bit set\n",
140 desc_ue_status_low[i]);
145 for (i = 0; ue_hi; ue_hi >>= 1, i++) {
147 beiscsi_log(phba, KERN_ERR,
149 "BG_%d : UE_HIGH %s bit set\n",
150 desc_ue_status_hi[i]);
155 int beiscsi_modify_eq_delay(struct beiscsi_hba *phba,
156 struct be_set_eqd *set_eqd,
159 struct be_ctrl_info *ctrl = &phba->ctrl;
160 struct be_mcc_wrb *wrb;
161 struct be_cmd_req_modify_eq_delay *req;
165 mutex_lock(&ctrl->mbox_lock);
166 wrb = alloc_mcc_wrb(phba, &tag);
168 mutex_unlock(&ctrl->mbox_lock);
172 req = embedded_payload(wrb);
173 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
174 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
175 OPCODE_COMMON_MODIFY_EQ_DELAY, sizeof(*req));
177 req->num_eq = cpu_to_le32(num);
178 for (i = 0; i < num; i++) {
179 req->delay[i].eq_id = cpu_to_le32(set_eqd[i].eq_id);
180 req->delay[i].phase = 0;
181 req->delay[i].delay_multiplier =
182 cpu_to_le32(set_eqd[i].delay_multiplier);
185 /* ignore the completion of this mbox command */
186 set_bit(MCC_TAG_STATE_IGNORE, &ctrl->ptag_state[tag].tag_state);
187 be_mcc_notify(phba, tag);
188 mutex_unlock(&ctrl->mbox_lock);
193 * mgmt_get_port_name()- Get port name for the function
194 * @ctrl: ptr to Ctrl Info
195 * @phba: ptr to the dev priv structure
197 * Get the alphanumeric character for port
200 int mgmt_get_port_name(struct be_ctrl_info *ctrl,
201 struct beiscsi_hba *phba)
204 struct be_mcc_wrb *wrb;
205 struct be_cmd_get_port_name *ioctl;
207 mutex_lock(&ctrl->mbox_lock);
208 wrb = wrb_from_mbox(&ctrl->mbox_mem);
209 memset(wrb, 0, sizeof(*wrb));
210 ioctl = embedded_payload(wrb);
212 be_wrb_hdr_prepare(wrb, sizeof(*ioctl), true, 0);
213 be_cmd_hdr_prepare(&ioctl->h.req_hdr, CMD_SUBSYSTEM_COMMON,
214 OPCODE_COMMON_GET_PORT_NAME,
215 EMBED_MBX_MAX_PAYLOAD_SIZE);
216 ret = be_mbox_notify(ctrl);
219 phba->port_name = ioctl->p.resp.port_names >>
220 (phba->fw_config.phys_port * 8) & 0xff;
222 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
223 "BG_%d : GET_PORT_NAME ret 0x%x status 0x%x\n",
224 ret, ioctl->h.resp_hdr.status);
227 if (phba->port_name == 0)
228 phba->port_name = '?';
230 mutex_unlock(&ctrl->mbox_lock);
235 * mgmt_get_fw_config()- Get the FW config for the function
236 * @ctrl: ptr to Ctrl Info
237 * @phba: ptr to the dev priv structure
239 * Get the FW config and resources available for the function.
240 * The resources are created based on the count received here.
244 * Failure: Non-Zero Value
246 int mgmt_get_fw_config(struct be_ctrl_info *ctrl,
247 struct beiscsi_hba *phba)
249 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
250 struct be_fw_cfg *pfw_cfg = embedded_payload(wrb);
251 uint32_t cid_count, icd_count;
252 int status = -EINVAL;
255 mutex_lock(&ctrl->mbox_lock);
256 memset(wrb, 0, sizeof(*wrb));
257 be_wrb_hdr_prepare(wrb, sizeof(*pfw_cfg), true, 0);
259 be_cmd_hdr_prepare(&pfw_cfg->hdr, CMD_SUBSYSTEM_COMMON,
260 OPCODE_COMMON_QUERY_FIRMWARE_CONFIG,
261 EMBED_MBX_MAX_PAYLOAD_SIZE);
263 if (be_mbox_notify(ctrl)) {
264 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
265 "BG_%d : Failed in mgmt_get_fw_config\n");
269 /* FW response formats depend on port id */
270 phba->fw_config.phys_port = pfw_cfg->phys_port;
271 if (phba->fw_config.phys_port >= BEISCSI_PHYS_PORT_MAX) {
272 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
273 "BG_%d : invalid physical port id %d\n",
274 phba->fw_config.phys_port);
278 /* populate and check FW config against min and max values */
279 if (!is_chip_be2_be3r(phba)) {
280 phba->fw_config.eqid_count = pfw_cfg->eqid_count;
281 phba->fw_config.cqid_count = pfw_cfg->cqid_count;
282 if (phba->fw_config.eqid_count == 0 ||
283 phba->fw_config.eqid_count > 2048) {
284 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
285 "BG_%d : invalid EQ count %d\n",
286 phba->fw_config.eqid_count);
289 if (phba->fw_config.cqid_count == 0 ||
290 phba->fw_config.cqid_count > 4096) {
291 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
292 "BG_%d : invalid CQ count %d\n",
293 phba->fw_config.cqid_count);
296 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
297 "BG_%d : EQ_Count : %d CQ_Count : %d\n",
298 phba->fw_config.eqid_count,
299 phba->fw_config.cqid_count);
303 * Check on which all ULP iSCSI Protocol is loaded.
304 * Set the Bit for those ULP. This set flag is used
305 * at all places in the code to check on which ULP
306 * iSCSi Protocol is loaded
308 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
309 if (pfw_cfg->ulp[ulp_num].ulp_mode &
310 BEISCSI_ULP_ISCSI_INI_MODE) {
311 set_bit(ulp_num, &phba->fw_config.ulp_supported);
313 /* Get the CID, ICD and Chain count for each ULP */
314 phba->fw_config.iscsi_cid_start[ulp_num] =
315 pfw_cfg->ulp[ulp_num].sq_base;
316 phba->fw_config.iscsi_cid_count[ulp_num] =
317 pfw_cfg->ulp[ulp_num].sq_count;
319 phba->fw_config.iscsi_icd_start[ulp_num] =
320 pfw_cfg->ulp[ulp_num].icd_base;
321 phba->fw_config.iscsi_icd_count[ulp_num] =
322 pfw_cfg->ulp[ulp_num].icd_count;
324 phba->fw_config.iscsi_chain_start[ulp_num] =
325 pfw_cfg->chain_icd[ulp_num].chain_base;
326 phba->fw_config.iscsi_chain_count[ulp_num] =
327 pfw_cfg->chain_icd[ulp_num].chain_count;
329 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
330 "BG_%d : Function loaded on ULP : %d\n"
331 "\tiscsi_cid_count : %d\n"
332 "\tiscsi_cid_start : %d\n"
333 "\t iscsi_icd_count : %d\n"
334 "\t iscsi_icd_start : %d\n",
337 iscsi_cid_count[ulp_num],
339 iscsi_cid_start[ulp_num],
341 iscsi_icd_count[ulp_num],
343 iscsi_icd_start[ulp_num]);
347 if (phba->fw_config.ulp_supported == 0) {
348 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
349 "BG_%d : iSCSI initiator mode not set: ULP0 %x ULP1 %x\n",
350 pfw_cfg->ulp[BEISCSI_ULP0].ulp_mode,
351 pfw_cfg->ulp[BEISCSI_ULP1].ulp_mode);
356 * ICD is shared among ULPs. Use icd_count of any one loaded ULP
358 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++)
359 if (test_bit(ulp_num, &phba->fw_config.ulp_supported))
361 icd_count = phba->fw_config.iscsi_icd_count[ulp_num];
362 if (icd_count == 0 || icd_count > 65536) {
363 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
364 "BG_%d: invalid ICD count %d\n", icd_count);
368 cid_count = BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP0) +
369 BEISCSI_GET_CID_COUNT(phba, BEISCSI_ULP1);
370 if (cid_count == 0 || cid_count > 4096) {
371 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
372 "BG_%d: invalid CID count %d\n", cid_count);
377 * Check FW is dual ULP aware i.e. can handle either
380 phba->fw_config.dual_ulp_aware = (pfw_cfg->function_mode &
381 BEISCSI_FUNC_DUA_MODE);
383 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
384 "BG_%d : DUA Mode : 0x%x\n",
385 phba->fw_config.dual_ulp_aware);
387 /* all set, continue using this FW config */
390 mutex_unlock(&ctrl->mbox_lock);
394 int mgmt_check_supported_fw(struct be_ctrl_info *ctrl,
395 struct beiscsi_hba *phba)
397 struct be_dma_mem nonemb_cmd;
398 struct be_mcc_wrb *wrb = wrb_from_mbox(&ctrl->mbox_mem);
399 struct be_mgmt_controller_attributes *req;
400 struct be_sge *sge = nonembedded_sgl(wrb);
403 nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
404 sizeof(struct be_mgmt_controller_attributes),
406 if (nonemb_cmd.va == NULL) {
407 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
408 "BG_%d : Failed to allocate memory for "
409 "mgmt_check_supported_fw\n");
412 nonemb_cmd.size = sizeof(struct be_mgmt_controller_attributes);
414 memset(req, 0, sizeof(*req));
415 mutex_lock(&ctrl->mbox_lock);
416 memset(wrb, 0, sizeof(*wrb));
417 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
418 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_COMMON,
419 OPCODE_COMMON_GET_CNTL_ATTRIBUTES, sizeof(*req));
420 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd.dma));
421 sge->pa_lo = cpu_to_le32(nonemb_cmd.dma & 0xFFFFFFFF);
422 sge->len = cpu_to_le32(nonemb_cmd.size);
423 status = be_mbox_notify(ctrl);
425 struct be_mgmt_controller_attributes_resp *resp = nonemb_cmd.va;
426 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
427 "BG_%d : Firmware Version of CMD : %s\n"
428 "Firmware Version is : %s\n"
429 "Developer Build, not performing version check...\n",
430 resp->params.hba_attribs
431 .flashrom_version_string,
432 resp->params.hba_attribs.
433 firmware_version_string);
435 phba->fw_config.iscsi_features =
436 resp->params.hba_attribs.iscsi_features;
437 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_INIT,
438 "BM_%d : phba->fw_config.iscsi_features = %d\n",
439 phba->fw_config.iscsi_features);
440 memcpy(phba->fw_ver_str, resp->params.hba_attribs.
441 firmware_version_string, BEISCSI_VER_STRLEN);
443 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
444 "BG_%d : Failed in mgmt_check_supported_fw\n");
445 mutex_unlock(&ctrl->mbox_lock);
447 pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
448 nonemb_cmd.va, nonemb_cmd.dma);
453 unsigned int mgmt_vendor_specific_fw_cmd(struct be_ctrl_info *ctrl,
454 struct beiscsi_hba *phba,
456 struct be_dma_mem *nonemb_cmd)
458 struct be_cmd_resp_hdr *resp;
459 struct be_mcc_wrb *wrb;
460 struct be_sge *mcc_sge;
461 unsigned int tag = 0;
462 struct iscsi_bsg_request *bsg_req = job->request;
463 struct be_bsg_vendor_cmd *req = nonemb_cmd->va;
464 unsigned short region, sector_size, sector, offset;
466 nonemb_cmd->size = job->request_payload.payload_len;
467 memset(nonemb_cmd->va, 0, nonemb_cmd->size);
468 resp = nonemb_cmd->va;
469 region = bsg_req->rqst_data.h_vendor.vendor_cmd[1];
470 sector_size = bsg_req->rqst_data.h_vendor.vendor_cmd[2];
471 sector = bsg_req->rqst_data.h_vendor.vendor_cmd[3];
472 offset = bsg_req->rqst_data.h_vendor.vendor_cmd[4];
473 req->region = region;
474 req->sector = sector;
475 req->offset = offset;
477 if (mutex_lock_interruptible(&ctrl->mbox_lock))
479 switch (bsg_req->rqst_data.h_vendor.vendor_cmd[0]) {
480 case BEISCSI_WRITE_FLASH:
481 offset = sector * sector_size + offset;
482 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
483 OPCODE_COMMON_WRITE_FLASH, sizeof(*req));
484 sg_copy_to_buffer(job->request_payload.sg_list,
485 job->request_payload.sg_cnt,
486 nonemb_cmd->va + offset, job->request_len);
488 case BEISCSI_READ_FLASH:
489 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
490 OPCODE_COMMON_READ_FLASH, sizeof(*req));
493 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
494 "BG_%d : Unsupported cmd = 0x%x\n\n",
495 bsg_req->rqst_data.h_vendor.vendor_cmd[0]);
497 mutex_unlock(&ctrl->mbox_lock);
501 wrb = alloc_mcc_wrb(phba, &tag);
503 mutex_unlock(&ctrl->mbox_lock);
507 mcc_sge = nonembedded_sgl(wrb);
508 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false,
509 job->request_payload.sg_cnt);
510 mcc_sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
511 mcc_sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
512 mcc_sge->len = cpu_to_le32(nonemb_cmd->size);
514 be_mcc_notify(phba, tag);
516 mutex_unlock(&ctrl->mbox_lock);
521 * mgmt_epfw_cleanup()- Inform FW to cleanup data structures.
522 * @phba: pointer to dev priv structure
523 * @ulp_num: ULP number.
527 * Failure: Non-Zero Value
529 int mgmt_epfw_cleanup(struct beiscsi_hba *phba, unsigned short ulp_num)
531 struct be_ctrl_info *ctrl = &phba->ctrl;
532 struct be_mcc_wrb *wrb;
533 struct iscsi_cleanup_req *req;
537 mutex_lock(&ctrl->mbox_lock);
538 wrb = alloc_mcc_wrb(phba, &tag);
540 mutex_unlock(&ctrl->mbox_lock);
544 req = embedded_payload(wrb);
545 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
546 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
547 OPCODE_COMMON_ISCSI_CLEANUP, sizeof(*req));
549 req->chute = (1 << ulp_num);
550 req->hdr_ring_id = cpu_to_le16(HWI_GET_DEF_HDRQ_ID(phba, ulp_num));
551 req->data_ring_id = cpu_to_le16(HWI_GET_DEF_BUFQ_ID(phba, ulp_num));
553 be_mcc_notify(phba, tag);
554 status = be_mcc_compl_poll(phba, tag);
556 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_INIT,
557 "BG_%d : mgmt_epfw_cleanup , FAILED\n");
558 mutex_unlock(&ctrl->mbox_lock);
562 unsigned int mgmt_invalidate_icds(struct beiscsi_hba *phba,
563 struct invalidate_command_table *inv_tbl,
564 unsigned int num_invalidate, unsigned int cid,
565 struct be_dma_mem *nonemb_cmd)
568 struct be_ctrl_info *ctrl = &phba->ctrl;
569 struct be_mcc_wrb *wrb;
571 struct invalidate_commands_params_in *req;
574 mutex_lock(&ctrl->mbox_lock);
575 wrb = alloc_mcc_wrb(phba, &tag);
577 mutex_unlock(&ctrl->mbox_lock);
581 req = nonemb_cmd->va;
582 memset(req, 0, sizeof(*req));
583 sge = nonembedded_sgl(wrb);
585 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
586 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
587 OPCODE_COMMON_ISCSI_ERROR_RECOVERY_INVALIDATE_COMMANDS,
590 req->cleanup_type = CMD_ISCSI_COMMAND_INVALIDATE;
591 for (i = 0; i < num_invalidate; i++) {
592 req->table[i].icd = inv_tbl->icd;
593 req->table[i].cid = inv_tbl->cid;
597 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
598 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
599 sge->len = cpu_to_le32(nonemb_cmd->size);
601 be_mcc_notify(phba, tag);
602 mutex_unlock(&ctrl->mbox_lock);
606 unsigned int mgmt_invalidate_connection(struct beiscsi_hba *phba,
607 struct beiscsi_endpoint *beiscsi_ep,
609 unsigned short issue_reset,
610 unsigned short savecfg_flag)
612 struct be_ctrl_info *ctrl = &phba->ctrl;
613 struct be_mcc_wrb *wrb;
614 struct iscsi_invalidate_connection_params_in *req;
615 unsigned int tag = 0;
617 mutex_lock(&ctrl->mbox_lock);
618 wrb = alloc_mcc_wrb(phba, &tag);
620 mutex_unlock(&ctrl->mbox_lock);
624 req = embedded_payload(wrb);
625 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
626 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
627 OPCODE_ISCSI_INI_DRIVER_INVALIDATE_CONNECTION,
629 req->session_handle = beiscsi_ep->fw_handle;
632 req->cleanup_type = CMD_ISCSI_CONNECTION_ISSUE_TCP_RST;
634 req->cleanup_type = CMD_ISCSI_CONNECTION_INVALIDATE;
635 req->save_cfg = savecfg_flag;
636 be_mcc_notify(phba, tag);
637 mutex_unlock(&ctrl->mbox_lock);
641 unsigned int mgmt_upload_connection(struct beiscsi_hba *phba,
642 unsigned short cid, unsigned int upload_flag)
644 struct be_ctrl_info *ctrl = &phba->ctrl;
645 struct be_mcc_wrb *wrb;
646 struct tcp_upload_params_in *req;
649 mutex_lock(&ctrl->mbox_lock);
650 wrb = alloc_mcc_wrb(phba, &tag);
652 mutex_unlock(&ctrl->mbox_lock);
656 req = embedded_payload(wrb);
657 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
658 be_cmd_hdr_prepare(&req->hdr, CMD_COMMON_TCP_UPLOAD,
659 OPCODE_COMMON_TCP_UPLOAD, sizeof(*req));
660 req->id = (unsigned short)cid;
661 req->upload_type = (unsigned char)upload_flag;
662 be_mcc_notify(phba, tag);
663 mutex_unlock(&ctrl->mbox_lock);
668 * mgmt_open_connection()- Establish a TCP CXN
669 * @dst_addr: Destination Address
670 * @beiscsi_ep: ptr to device endpoint struct
671 * @nonemb_cmd: ptr to memory allocated for command
674 * Success: Tag number of the MBX Command issued
675 * Failure: Error code
677 int mgmt_open_connection(struct beiscsi_hba *phba,
678 struct sockaddr *dst_addr,
679 struct beiscsi_endpoint *beiscsi_ep,
680 struct be_dma_mem *nonemb_cmd)
682 struct hwi_controller *phwi_ctrlr;
683 struct hwi_context_memory *phwi_context;
684 struct sockaddr_in *daddr_in = (struct sockaddr_in *)dst_addr;
685 struct sockaddr_in6 *daddr_in6 = (struct sockaddr_in6 *)dst_addr;
686 struct be_ctrl_info *ctrl = &phba->ctrl;
687 struct be_mcc_wrb *wrb;
688 struct tcp_connect_and_offload_in_v1 *req;
689 unsigned short def_hdr_id;
690 unsigned short def_data_id;
691 struct phys_addr template_address = { 0, 0 };
692 struct phys_addr *ptemplate_address;
693 unsigned int tag = 0;
694 unsigned int i, ulp_num;
695 unsigned short cid = beiscsi_ep->ep_cid;
698 if (dst_addr->sa_family != PF_INET && dst_addr->sa_family != PF_INET6) {
699 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
700 "BG_%d : unknown addr family %d\n",
701 dst_addr->sa_family);
705 phwi_ctrlr = phba->phwi_ctrlr;
706 phwi_context = phwi_ctrlr->phwi_ctxt;
708 ulp_num = phwi_ctrlr->wrb_context[BE_GET_CRI_FROM_CID(cid)].ulp_num;
710 def_hdr_id = (unsigned short)HWI_GET_DEF_HDRQ_ID(phba, ulp_num);
711 def_data_id = (unsigned short)HWI_GET_DEF_BUFQ_ID(phba, ulp_num);
713 ptemplate_address = &template_address;
714 ISCSI_GET_PDU_TEMPLATE_ADDRESS(phba, ptemplate_address);
715 if (mutex_lock_interruptible(&ctrl->mbox_lock))
717 wrb = alloc_mcc_wrb(phba, &tag);
719 mutex_unlock(&ctrl->mbox_lock);
723 sge = nonembedded_sgl(wrb);
724 req = nonemb_cmd->va;
725 memset(req, 0, sizeof(*req));
727 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
728 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
729 OPCODE_COMMON_ISCSI_TCP_CONNECT_AND_OFFLOAD,
731 if (dst_addr->sa_family == PF_INET) {
732 __be32 s_addr = daddr_in->sin_addr.s_addr;
733 req->ip_address.ip_type = BEISCSI_IP_TYPE_V4;
734 req->ip_address.addr[0] = s_addr & 0x000000ff;
735 req->ip_address.addr[1] = (s_addr & 0x0000ff00) >> 8;
736 req->ip_address.addr[2] = (s_addr & 0x00ff0000) >> 16;
737 req->ip_address.addr[3] = (s_addr & 0xff000000) >> 24;
738 req->tcp_port = ntohs(daddr_in->sin_port);
739 beiscsi_ep->dst_addr = daddr_in->sin_addr.s_addr;
740 beiscsi_ep->dst_tcpport = ntohs(daddr_in->sin_port);
741 beiscsi_ep->ip_type = BEISCSI_IP_TYPE_V4;
743 /* else its PF_INET6 family */
744 req->ip_address.ip_type = BEISCSI_IP_TYPE_V6;
745 memcpy(&req->ip_address.addr,
746 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
747 req->tcp_port = ntohs(daddr_in6->sin6_port);
748 beiscsi_ep->dst_tcpport = ntohs(daddr_in6->sin6_port);
749 memcpy(&beiscsi_ep->dst6_addr,
750 &daddr_in6->sin6_addr.in6_u.u6_addr8, 16);
751 beiscsi_ep->ip_type = BEISCSI_IP_TYPE_V6;
754 i = phba->nxt_cqid++;
755 if (phba->nxt_cqid == phba->num_cpus)
757 req->cq_id = phwi_context->be_cq[i].id;
758 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
759 "BG_%d : i=%d cq_id=%d\n", i, req->cq_id);
760 req->defq_id = def_hdr_id;
761 req->hdr_ring_id = def_hdr_id;
762 req->data_ring_id = def_data_id;
764 req->dataout_template_pa.lo = ptemplate_address->lo;
765 req->dataout_template_pa.hi = ptemplate_address->hi;
766 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
767 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
768 sge->len = cpu_to_le32(nonemb_cmd->size);
770 if (!is_chip_be2_be3r(phba)) {
771 req->hdr.version = MBX_CMD_VER1;
772 req->tcp_window_size = 0;
773 req->tcp_window_scale_count = 2;
776 be_mcc_notify(phba, tag);
777 mutex_unlock(&ctrl->mbox_lock);
782 * mgmt_exec_nonemb_cmd()- Execute Non Embedded MBX Cmd
783 * @phba: Driver priv structure
784 * @nonemb_cmd: Address of the MBX command issued
785 * @resp_buf: Buffer to copy the MBX cmd response
786 * @resp_buf_len: respone lenght to be copied
789 static int mgmt_exec_nonemb_cmd(struct beiscsi_hba *phba,
790 struct be_dma_mem *nonemb_cmd, void *resp_buf,
793 struct be_ctrl_info *ctrl = &phba->ctrl;
794 struct be_mcc_wrb *wrb;
799 mutex_lock(&ctrl->mbox_lock);
800 wrb = alloc_mcc_wrb(phba, &tag);
802 mutex_unlock(&ctrl->mbox_lock);
807 sge = nonembedded_sgl(wrb);
808 be_wrb_hdr_prepare(wrb, nonemb_cmd->size, false, 1);
809 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
810 sge->pa_lo = cpu_to_le32(lower_32_bits(nonemb_cmd->dma));
811 sge->len = cpu_to_le32(nonemb_cmd->size);
813 be_mcc_notify(phba, tag);
814 mutex_unlock(&ctrl->mbox_lock);
816 rc = beiscsi_mccq_compl_wait(phba, tag, NULL, nonemb_cmd);
819 memcpy(resp_buf, nonemb_cmd->va, resp_buf_len);
822 /* Check if the MBX Cmd needs to be re-issued */
826 beiscsi_log(phba, KERN_WARNING,
827 BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX,
828 "BG_%d : mgmt_exec_nonemb_cmd Failed status\n");
836 pci_free_consistent(ctrl->pdev, nonemb_cmd->size,
837 nonemb_cmd->va, nonemb_cmd->dma);
841 static int mgmt_alloc_cmd_data(struct beiscsi_hba *phba, struct be_dma_mem *cmd,
842 int iscsi_cmd, int size)
844 cmd->va = pci_zalloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
846 beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
847 "BG_%d : Failed to allocate memory for if info\n");
851 be_cmd_hdr_prepare(cmd->va, CMD_SUBSYSTEM_ISCSI, iscsi_cmd, size);
852 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
853 "BG_%d : subsystem iSCSI cmd %d size %d\n",
858 unsigned int beiscsi_if_get_handle(struct beiscsi_hba *phba)
860 struct be_ctrl_info *ctrl = &phba->ctrl;
861 struct be_mcc_wrb *wrb;
862 struct be_cmd_get_all_if_id_req *req;
863 struct be_cmd_get_all_if_id_req *pbe_allid;
867 if (mutex_lock_interruptible(&ctrl->mbox_lock))
869 wrb = alloc_mcc_wrb(phba, &tag);
871 mutex_unlock(&ctrl->mbox_lock);
875 req = embedded_payload(wrb);
876 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
877 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI,
878 OPCODE_COMMON_ISCSI_NTWK_GET_ALL_IF_ID,
880 be_mcc_notify(phba, tag);
881 mutex_unlock(&ctrl->mbox_lock);
883 status = beiscsi_mccq_compl_wait(phba, tag, &wrb, NULL);
885 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
886 "BG_%d : %s failed: %d\n", __func__, status);
890 pbe_allid = embedded_payload(wrb);
891 /* we now support only one interface per function */
892 phba->interface_handle = pbe_allid->if_hndl_list[0];
897 static inline bool beiscsi_if_zero_ip(u8 *ip, u32 ip_type)
901 len = (ip_type < BEISCSI_IP_TYPE_V6) ? IP_V4_LEN : IP_V6_LEN;
902 while (len && !ip[len - 1])
907 static int beiscsi_if_mod_gw(struct beiscsi_hba *phba,
908 u32 action, u32 ip_type, u8 *gw)
910 struct be_cmd_set_def_gateway_req *req;
911 struct be_dma_mem nonemb_cmd;
914 rt_val = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
915 OPCODE_COMMON_ISCSI_NTWK_MODIFY_DEFAULT_GATEWAY,
921 req->action = action;
922 req->ip_addr.ip_type = ip_type;
923 memcpy(req->ip_addr.addr, gw,
924 (ip_type < BEISCSI_IP_TYPE_V6) ? IP_V4_LEN : IP_V6_LEN);
925 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
928 int beiscsi_if_set_gw(struct beiscsi_hba *phba, u32 ip_type, u8 *gw)
930 struct be_cmd_get_def_gateway_resp gw_resp;
933 memset(&gw_resp, 0, sizeof(gw_resp));
934 rt_val = beiscsi_if_get_gw(phba, ip_type, &gw_resp);
936 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
937 "BG_%d : Failed to Get Gateway Addr\n");
941 if (!beiscsi_if_zero_ip(gw_resp.ip_addr.addr, ip_type)) {
942 rt_val = beiscsi_if_mod_gw(phba, IP_ACTION_DEL, ip_type,
943 gw_resp.ip_addr.addr);
945 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
946 "BG_%d : Failed to clear Gateway Addr Set\n");
951 rt_val = beiscsi_if_mod_gw(phba, IP_ACTION_ADD, ip_type, gw);
953 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
954 "BG_%d : Failed to Set Gateway Addr\n");
959 int beiscsi_if_get_gw(struct beiscsi_hba *phba, u32 ip_type,
960 struct be_cmd_get_def_gateway_resp *resp)
962 struct be_cmd_get_def_gateway_req *req;
963 struct be_dma_mem nonemb_cmd;
966 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
967 OPCODE_COMMON_ISCSI_NTWK_GET_DEFAULT_GATEWAY,
973 req->ip_type = ip_type;
975 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, resp,
980 beiscsi_if_clr_ip(struct beiscsi_hba *phba,
981 struct be_cmd_get_if_info_resp *if_info)
983 struct be_cmd_set_ip_addr_req *req;
984 struct be_dma_mem nonemb_cmd;
987 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
988 OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR,
994 req->ip_params.record_entry_count = 1;
995 req->ip_params.ip_record.action = IP_ACTION_DEL;
996 req->ip_params.ip_record.interface_hndl =
997 phba->interface_handle;
998 req->ip_params.ip_record.ip_addr.size_of_structure =
999 sizeof(struct be_ip_addr_subnet_format);
1000 req->ip_params.ip_record.ip_addr.ip_type = if_info->ip_addr.ip_type;
1001 memcpy(req->ip_params.ip_record.ip_addr.addr,
1002 if_info->ip_addr.addr,
1003 sizeof(if_info->ip_addr.addr));
1004 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
1005 if_info->ip_addr.subnet_mask,
1006 sizeof(if_info->ip_addr.subnet_mask));
1007 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
1008 if (rc < 0 || req->ip_params.ip_record.status) {
1009 beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
1010 "BG_%d : failed to clear IP: rc %d status %d\n",
1011 rc, req->ip_params.ip_record.status);
1017 beiscsi_if_set_ip(struct beiscsi_hba *phba, u8 *ip,
1018 u8 *subnet, u32 ip_type)
1020 struct be_cmd_set_ip_addr_req *req;
1021 struct be_dma_mem nonemb_cmd;
1025 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1026 OPCODE_COMMON_ISCSI_NTWK_MODIFY_IP_ADDR,
1031 req = nonemb_cmd.va;
1032 req->ip_params.record_entry_count = 1;
1033 req->ip_params.ip_record.action = IP_ACTION_ADD;
1034 req->ip_params.ip_record.interface_hndl =
1035 phba->interface_handle;
1036 req->ip_params.ip_record.ip_addr.size_of_structure =
1037 sizeof(struct be_ip_addr_subnet_format);
1038 req->ip_params.ip_record.ip_addr.ip_type = ip_type;
1039 ip_len = (ip_type < BEISCSI_IP_TYPE_V6) ? IP_V4_LEN : IP_V6_LEN;
1040 memcpy(req->ip_params.ip_record.ip_addr.addr, ip, ip_len);
1042 memcpy(req->ip_params.ip_record.ip_addr.subnet_mask,
1045 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
1047 * In some cases, host needs to look into individual record status
1048 * even though FW reported success for that IOCTL.
1050 if (rc < 0 || req->ip_params.ip_record.status) {
1051 __beiscsi_log(phba, KERN_ERR,
1052 "BG_%d : failed to set IP: rc %d status %d\n",
1053 rc, req->ip_params.ip_record.status);
1054 if (req->ip_params.ip_record.status)
1060 int beiscsi_if_en_static(struct beiscsi_hba *phba, u32 ip_type,
1063 struct be_cmd_get_if_info_resp *if_info;
1064 struct be_cmd_rel_dhcp_req *reldhcp;
1065 struct be_dma_mem nonemb_cmd;
1068 rc = beiscsi_if_get_info(phba, ip_type, &if_info);
1072 if (if_info->dhcp_state) {
1073 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1074 OPCODE_COMMON_ISCSI_NTWK_REL_STATELESS_IP_ADDR,
1079 reldhcp = nonemb_cmd.va;
1080 reldhcp->interface_hndl = phba->interface_handle;
1081 reldhcp->ip_type = ip_type;
1082 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
1084 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1085 "BG_%d : failed to release existing DHCP: %d\n",
1091 /* first delete any IP set */
1092 if (!beiscsi_if_zero_ip(if_info->ip_addr.addr, ip_type)) {
1093 rc = beiscsi_if_clr_ip(phba, if_info);
1098 /* if ip == NULL then this is called just to release DHCP IP */
1100 rc = beiscsi_if_set_ip(phba, ip, subnet, ip_type);
1106 int beiscsi_if_en_dhcp(struct beiscsi_hba *phba, u32 ip_type)
1108 struct be_cmd_get_def_gateway_resp gw_resp;
1109 struct be_cmd_get_if_info_resp *if_info;
1110 struct be_cmd_set_dhcp_req *dhcpreq;
1111 struct be_dma_mem nonemb_cmd;
1115 rc = beiscsi_if_get_info(phba, ip_type, &if_info);
1119 if (if_info->dhcp_state) {
1120 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1121 "BG_%d : DHCP Already Enabled\n");
1125 /* first delete any IP set */
1126 if (!beiscsi_if_zero_ip(if_info->ip_addr.addr, ip_type)) {
1127 rc = beiscsi_if_clr_ip(phba, if_info);
1132 /* delete gateway settings if mode change is to DHCP */
1133 memset(&gw_resp, 0, sizeof(gw_resp));
1134 /* use ip_type provided in if_info */
1135 rc = beiscsi_if_get_gw(phba, if_info->ip_addr.ip_type, &gw_resp);
1137 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1138 "BG_%d : Failed to Get Gateway Addr\n");
1141 gw = (u8 *)&gw_resp.ip_addr.addr;
1142 if (!beiscsi_if_zero_ip(gw, if_info->ip_addr.ip_type)) {
1143 rc = beiscsi_if_mod_gw(phba, IP_ACTION_DEL,
1144 if_info->ip_addr.ip_type, gw);
1146 beiscsi_log(phba, KERN_WARNING, BEISCSI_LOG_CONFIG,
1147 "BG_%d : Failed to clear Gateway Addr Set\n");
1152 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1153 OPCODE_COMMON_ISCSI_NTWK_CONFIG_STATELESS_IP_ADDR,
1158 dhcpreq = nonemb_cmd.va;
1159 dhcpreq->flags = 1; /* 1 - blocking; 0 - non-blocking */
1160 dhcpreq->retry_count = 1;
1161 dhcpreq->interface_hndl = phba->interface_handle;
1162 dhcpreq->ip_type = ip_type;
1163 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, NULL, 0);
1171 * beiscsi_if_set_vlan()- Issue and wait for CMD completion
1172 * @phba: device private structure instance
1173 * @vlan_tag: VLAN tag
1175 * Issue the MBX Cmd and wait for the completion of the
1180 * Failure: Non-Xero Value
1182 int beiscsi_if_set_vlan(struct beiscsi_hba *phba, uint16_t vlan_tag)
1187 tag = be_cmd_set_vlan(phba, vlan_tag);
1189 beiscsi_log(phba, KERN_ERR,
1190 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1191 "BG_%d : VLAN Setting Failed\n");
1195 rc = beiscsi_mccq_compl_wait(phba, tag, NULL, NULL);
1197 beiscsi_log(phba, KERN_ERR,
1198 (BEISCSI_LOG_CONFIG | BEISCSI_LOG_MBOX),
1199 "BS_%d : VLAN MBX Cmd Failed\n");
1206 int beiscsi_if_get_info(struct beiscsi_hba *phba, int ip_type,
1207 struct be_cmd_get_if_info_resp **if_info)
1209 struct be_cmd_get_if_info_req *req;
1210 struct be_dma_mem nonemb_cmd;
1211 uint32_t ioctl_size = sizeof(struct be_cmd_get_if_info_resp);
1214 rc = beiscsi_if_get_handle(phba);
1219 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1220 OPCODE_COMMON_ISCSI_NTWK_GET_IF_INFO,
1225 req = nonemb_cmd.va;
1226 req->interface_hndl = phba->interface_handle;
1227 req->ip_type = ip_type;
1229 /* Allocate memory for if_info */
1230 *if_info = kzalloc(ioctl_size, GFP_KERNEL);
1232 beiscsi_log(phba, KERN_ERR,
1233 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1234 "BG_%d : Memory Allocation Failure\n");
1236 /* Free the DMA memory for the IOCTL issuing */
1237 pci_free_consistent(phba->ctrl.pdev,
1244 rc = mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, *if_info,
1247 /* Check if the error is because of Insufficent_Buffer */
1248 if (rc == -EAGAIN) {
1250 /* Get the new memory size */
1251 ioctl_size = ((struct be_cmd_resp_hdr *)
1252 nonemb_cmd.va)->actual_resp_len;
1253 ioctl_size += sizeof(struct be_cmd_req_hdr);
1255 /* Free the previous allocated DMA memory */
1256 pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1260 /* Free the virtual memory */
1268 int mgmt_get_nic_conf(struct beiscsi_hba *phba,
1269 struct be_cmd_get_nic_conf_resp *nic)
1271 struct be_dma_mem nonemb_cmd;
1274 rc = mgmt_alloc_cmd_data(phba, &nonemb_cmd,
1275 OPCODE_COMMON_ISCSI_NTWK_GET_NIC_CONFIG,
1280 return mgmt_exec_nonemb_cmd(phba, &nonemb_cmd, nic, sizeof(*nic));
1285 unsigned int be_cmd_get_initname(struct beiscsi_hba *phba)
1288 struct be_mcc_wrb *wrb;
1289 struct be_cmd_hba_name *req;
1290 struct be_ctrl_info *ctrl = &phba->ctrl;
1292 if (mutex_lock_interruptible(&ctrl->mbox_lock))
1294 wrb = alloc_mcc_wrb(phba, &tag);
1296 mutex_unlock(&ctrl->mbox_lock);
1300 req = embedded_payload(wrb);
1301 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1302 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1303 OPCODE_ISCSI_INI_CFG_GET_HBA_NAME,
1306 be_mcc_notify(phba, tag);
1307 mutex_unlock(&ctrl->mbox_lock);
1311 static void beiscsi_boot_process_compl(struct beiscsi_hba *phba,
1314 struct be_cmd_get_boot_target_resp *boot_resp;
1315 struct be_cmd_resp_logout_fw_sess *logo_resp;
1316 struct be_cmd_get_session_resp *sess_resp;
1317 struct be_mcc_wrb *wrb;
1318 struct boot_struct *bs;
1319 int boot_work, status;
1321 if (!test_bit(BEISCSI_HBA_BOOT_WORK, &phba->state)) {
1322 __beiscsi_log(phba, KERN_ERR,
1323 "BG_%d : %s no boot work %lx\n",
1324 __func__, phba->state);
1328 if (phba->boot_struct.tag != tag) {
1329 __beiscsi_log(phba, KERN_ERR,
1330 "BG_%d : %s tag mismatch %d:%d\n",
1331 __func__, tag, phba->boot_struct.tag);
1334 bs = &phba->boot_struct;
1337 switch (bs->action) {
1338 case BEISCSI_BOOT_REOPEN_SESS:
1339 status = __beiscsi_mcc_compl_status(phba, tag, NULL, NULL);
1341 bs->action = BEISCSI_BOOT_GET_SHANDLE;
1345 case BEISCSI_BOOT_GET_SHANDLE:
1346 status = __beiscsi_mcc_compl_status(phba, tag, &wrb, NULL);
1348 boot_resp = embedded_payload(wrb);
1349 bs->s_handle = boot_resp->boot_session_handle;
1351 if (bs->s_handle == BE_BOOT_INVALID_SHANDLE) {
1352 bs->action = BEISCSI_BOOT_REOPEN_SESS;
1355 bs->action = BEISCSI_BOOT_GET_SINFO;
1358 case BEISCSI_BOOT_GET_SINFO:
1359 status = __beiscsi_mcc_compl_status(phba, tag, NULL,
1362 sess_resp = bs->nonemb_cmd.va;
1363 memcpy(&bs->boot_sess, &sess_resp->session_info,
1364 sizeof(struct mgmt_session_info));
1365 bs->action = BEISCSI_BOOT_LOGOUT_SESS;
1367 __beiscsi_log(phba, KERN_ERR,
1368 "BG_%d : get boot session info error : 0x%x\n",
1372 pci_free_consistent(phba->ctrl.pdev, bs->nonemb_cmd.size,
1373 bs->nonemb_cmd.va, bs->nonemb_cmd.dma);
1374 bs->nonemb_cmd.va = NULL;
1376 case BEISCSI_BOOT_LOGOUT_SESS:
1377 status = __beiscsi_mcc_compl_status(phba, tag, &wrb, NULL);
1379 logo_resp = embedded_payload(wrb);
1380 if (logo_resp->session_status != BE_SESS_STATUS_CLOSE) {
1381 __beiscsi_log(phba, KERN_ERR,
1382 "BG_%d : FW boot session logout error : 0x%x\n",
1383 logo_resp->session_status);
1386 /* continue to create boot_kset even if logout failed? */
1387 bs->action = BEISCSI_BOOT_CREATE_KSET;
1393 /* clear the tag so no other completion matches this tag */
1397 __beiscsi_log(phba, KERN_ERR,
1398 "BG_%d : failed to setup boot target: status %d action %d\n",
1399 status, bs->action);
1402 /* wait for next event to start boot_work */
1403 clear_bit(BEISCSI_HBA_BOOT_WORK, &phba->state);
1406 schedule_work(&phba->boot_work);
1410 * beiscsi_boot_logout_sess()- Logout from boot FW session
1411 * @phba: Device priv structure instance
1414 * the TAG used for MBOX Command
1417 unsigned int beiscsi_boot_logout_sess(struct beiscsi_hba *phba)
1419 struct be_ctrl_info *ctrl = &phba->ctrl;
1420 struct be_mcc_wrb *wrb;
1421 struct be_cmd_req_logout_fw_sess *req;
1424 mutex_lock(&ctrl->mbox_lock);
1425 wrb = alloc_mcc_wrb(phba, &tag);
1427 mutex_unlock(&ctrl->mbox_lock);
1431 req = embedded_payload(wrb);
1432 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1433 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1434 OPCODE_ISCSI_INI_SESSION_LOGOUT_TARGET,
1435 sizeof(struct be_cmd_req_logout_fw_sess));
1436 /* Use the session handle copied into boot_sess */
1437 req->session_handle = phba->boot_struct.boot_sess.session_handle;
1439 phba->boot_struct.tag = tag;
1440 set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state);
1441 ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl;
1443 be_mcc_notify(phba, tag);
1444 mutex_unlock(&ctrl->mbox_lock);
1449 * beiscsi_boot_reopen_sess()- Reopen boot session
1450 * @phba: Device priv structure instance
1453 * the TAG used for MBOX Command
1456 unsigned int beiscsi_boot_reopen_sess(struct beiscsi_hba *phba)
1458 struct be_ctrl_info *ctrl = &phba->ctrl;
1459 struct be_mcc_wrb *wrb;
1460 struct be_cmd_reopen_session_req *req;
1463 mutex_lock(&ctrl->mbox_lock);
1464 wrb = alloc_mcc_wrb(phba, &tag);
1466 mutex_unlock(&ctrl->mbox_lock);
1470 req = embedded_payload(wrb);
1471 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1472 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1473 OPCODE_ISCSI_INI_DRIVER_REOPEN_ALL_SESSIONS,
1474 sizeof(struct be_cmd_reopen_session_resp));
1475 req->reopen_type = BE_REOPEN_BOOT_SESSIONS;
1476 req->session_handle = BE_BOOT_INVALID_SHANDLE;
1478 phba->boot_struct.tag = tag;
1479 set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state);
1480 ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl;
1482 be_mcc_notify(phba, tag);
1483 mutex_unlock(&ctrl->mbox_lock);
1489 * beiscsi_boot_get_sinfo()- Get boot session info
1490 * @phba: device priv structure instance
1492 * Fetches the boot_struct.s_handle info from FW.
1494 * the TAG used for MBOX Command
1497 unsigned int beiscsi_boot_get_sinfo(struct beiscsi_hba *phba)
1499 struct be_ctrl_info *ctrl = &phba->ctrl;
1500 struct be_cmd_get_session_resp *resp;
1501 struct be_cmd_get_session_req *req;
1502 struct be_dma_mem *nonemb_cmd;
1503 struct be_mcc_wrb *wrb;
1507 mutex_lock(&ctrl->mbox_lock);
1508 wrb = alloc_mcc_wrb(phba, &tag);
1510 mutex_unlock(&ctrl->mbox_lock);
1514 nonemb_cmd = &phba->boot_struct.nonemb_cmd;
1515 nonemb_cmd->size = sizeof(*resp);
1516 nonemb_cmd->va = pci_alloc_consistent(phba->ctrl.pdev,
1517 sizeof(nonemb_cmd->size),
1519 if (!nonemb_cmd->va)
1522 req = nonemb_cmd->va;
1523 memset(req, 0, sizeof(*req));
1524 sge = nonembedded_sgl(wrb);
1525 be_wrb_hdr_prepare(wrb, sizeof(*req), false, 1);
1526 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1527 OPCODE_ISCSI_INI_SESSION_GET_A_SESSION,
1529 req->session_handle = phba->boot_struct.s_handle;
1530 sge->pa_hi = cpu_to_le32(upper_32_bits(nonemb_cmd->dma));
1531 sge->pa_lo = cpu_to_le32(nonemb_cmd->dma & 0xFFFFFFFF);
1532 sge->len = cpu_to_le32(nonemb_cmd->size);
1534 phba->boot_struct.tag = tag;
1535 set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state);
1536 ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl;
1538 be_mcc_notify(phba, tag);
1539 mutex_unlock(&ctrl->mbox_lock);
1543 unsigned int __beiscsi_boot_get_shandle(struct beiscsi_hba *phba, int async)
1545 struct be_ctrl_info *ctrl = &phba->ctrl;
1546 struct be_mcc_wrb *wrb;
1547 struct be_cmd_get_boot_target_req *req;
1550 mutex_lock(&ctrl->mbox_lock);
1551 wrb = alloc_mcc_wrb(phba, &tag);
1553 mutex_unlock(&ctrl->mbox_lock);
1557 req = embedded_payload(wrb);
1558 be_wrb_hdr_prepare(wrb, sizeof(*req), true, 0);
1559 be_cmd_hdr_prepare(&req->hdr, CMD_SUBSYSTEM_ISCSI_INI,
1560 OPCODE_ISCSI_INI_BOOT_GET_BOOT_TARGET,
1561 sizeof(struct be_cmd_get_boot_target_resp));
1564 phba->boot_struct.tag = tag;
1565 set_bit(MCC_TAG_STATE_ASYNC, &ctrl->ptag_state[tag].tag_state);
1566 ctrl->ptag_state[tag].cbfn = beiscsi_boot_process_compl;
1569 be_mcc_notify(phba, tag);
1570 mutex_unlock(&ctrl->mbox_lock);
1575 * beiscsi_boot_get_shandle()- Get boot session handle
1576 * @phba: device priv structure instance
1577 * @s_handle: session handle returned for boot session.
1584 int beiscsi_boot_get_shandle(struct beiscsi_hba *phba, unsigned int *s_handle)
1586 struct be_cmd_get_boot_target_resp *boot_resp;
1587 struct be_mcc_wrb *wrb;
1591 *s_handle = BE_BOOT_INVALID_SHANDLE;
1592 /* get configured boot session count and handle */
1593 tag = __beiscsi_boot_get_shandle(phba, 0);
1595 beiscsi_log(phba, KERN_ERR,
1596 BEISCSI_LOG_CONFIG | BEISCSI_LOG_INIT,
1597 "BG_%d : Getting Boot Target Info Failed\n");
1601 rc = beiscsi_mccq_compl_wait(phba, tag, &wrb, NULL);
1603 beiscsi_log(phba, KERN_ERR,
1604 BEISCSI_LOG_INIT | BEISCSI_LOG_CONFIG,
1605 "BG_%d : MBX CMD get_boot_target Failed\n");
1609 boot_resp = embedded_payload(wrb);
1610 /* check if there are any boot targets configured */
1611 if (!boot_resp->boot_session_count) {
1612 __beiscsi_log(phba, KERN_INFO,
1613 "BG_%d : No boot targets configured\n");
1617 /* only if FW has logged in to the boot target, s_handle is valid */
1618 *s_handle = boot_resp->boot_session_handle;
1623 * beiscsi_drvr_ver_disp()- Display the driver Name and Version
1624 * @dev: ptr to device not used.
1625 * @attr: device attribute, not used.
1626 * @buf: contains formatted text driver name and version
1629 * size of the formatted string
1632 beiscsi_drvr_ver_disp(struct device *dev, struct device_attribute *attr,
1635 return snprintf(buf, PAGE_SIZE, BE_NAME "\n");
1639 * beiscsi_fw_ver_disp()- Display Firmware Version
1640 * @dev: ptr to device not used.
1641 * @attr: device attribute, not used.
1642 * @buf: contains formatted text Firmware version
1645 * size of the formatted string
1648 beiscsi_fw_ver_disp(struct device *dev, struct device_attribute *attr,
1651 struct Scsi_Host *shost = class_to_shost(dev);
1652 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1654 return snprintf(buf, PAGE_SIZE, "%s\n", phba->fw_ver_str);
1658 * beiscsi_active_session_disp()- Display Sessions Active
1659 * @dev: ptr to device not used.
1660 * @attr: device attribute, not used.
1661 * @buf: contains formatted text Session Count
1664 * size of the formatted string
1667 beiscsi_active_session_disp(struct device *dev, struct device_attribute *attr,
1670 struct Scsi_Host *shost = class_to_shost(dev);
1671 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1672 uint16_t avlbl_cids = 0, ulp_num, len = 0, total_cids = 0;
1674 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
1675 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported)) {
1676 avlbl_cids = BEISCSI_ULP_AVLBL_CID(phba, ulp_num);
1677 total_cids = BEISCSI_GET_CID_COUNT(phba, ulp_num);
1678 len += snprintf(buf+len, PAGE_SIZE - len,
1679 "ULP%d : %d\n", ulp_num,
1680 (total_cids - avlbl_cids));
1682 len += snprintf(buf+len, PAGE_SIZE - len,
1683 "ULP%d : %d\n", ulp_num, 0);
1690 * beiscsi_free_session_disp()- Display Avaliable Session
1691 * @dev: ptr to device not used.
1692 * @attr: device attribute, not used.
1693 * @buf: contains formatted text Session Count
1696 * size of the formatted string
1699 beiscsi_free_session_disp(struct device *dev, struct device_attribute *attr,
1702 struct Scsi_Host *shost = class_to_shost(dev);
1703 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1704 uint16_t ulp_num, len = 0;
1706 for (ulp_num = 0; ulp_num < BEISCSI_ULP_COUNT; ulp_num++) {
1707 if (test_bit(ulp_num, (void *)&phba->fw_config.ulp_supported))
1708 len += snprintf(buf+len, PAGE_SIZE - len,
1709 "ULP%d : %d\n", ulp_num,
1710 BEISCSI_ULP_AVLBL_CID(phba, ulp_num));
1712 len += snprintf(buf+len, PAGE_SIZE - len,
1713 "ULP%d : %d\n", ulp_num, 0);
1720 * beiscsi_adap_family_disp()- Display adapter family.
1721 * @dev: ptr to device to get priv structure
1722 * @attr: device attribute, not used.
1723 * @buf: contains formatted text driver name and version
1726 * size of the formatted string
1729 beiscsi_adap_family_disp(struct device *dev, struct device_attribute *attr,
1732 uint16_t dev_id = 0;
1733 struct Scsi_Host *shost = class_to_shost(dev);
1734 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1736 dev_id = phba->pcidev->device;
1741 return snprintf(buf, PAGE_SIZE, "BE2 Adapter Family\n");
1745 return snprintf(buf, PAGE_SIZE, "BE3-R Adapter Family\n");
1748 return snprintf(buf, PAGE_SIZE, "Skyhawk-R Adapter Family\n");
1751 return snprintf(buf, PAGE_SIZE,
1752 "Unknown Adapter Family: 0x%x\n", dev_id);
1758 * beiscsi_phys_port()- Display Physical Port Identifier
1759 * @dev: ptr to device not used.
1760 * @attr: device attribute, not used.
1761 * @buf: contains formatted text port identifier
1764 * size of the formatted string
1767 beiscsi_phys_port_disp(struct device *dev, struct device_attribute *attr,
1770 struct Scsi_Host *shost = class_to_shost(dev);
1771 struct beiscsi_hba *phba = iscsi_host_priv(shost);
1773 return snprintf(buf, PAGE_SIZE, "Port Identifier : %d\n",
1774 phba->fw_config.phys_port);
1777 void beiscsi_offload_cxn_v0(struct beiscsi_offload_params *params,
1778 struct wrb_handle *pwrb_handle,
1779 struct be_mem_descriptor *mem_descr,
1780 struct hwi_wrb_context *pwrb_context)
1782 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1784 memset(pwrb, 0, sizeof(*pwrb));
1785 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1786 max_send_data_segment_length, pwrb,
1787 params->dw[offsetof(struct amap_beiscsi_offload_params,
1788 max_send_data_segment_length) / 32]);
1789 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, type, pwrb,
1790 BE_TGT_CTX_UPDT_CMD);
1791 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1794 params->dw[offsetof(struct amap_beiscsi_offload_params,
1795 first_burst_length) / 32]);
1796 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, erl, pwrb,
1797 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1798 erl) / 32] & OFFLD_PARAMS_ERL));
1799 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, dde, pwrb,
1800 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1801 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1802 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, hde, pwrb,
1803 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1804 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1805 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ir2t, pwrb,
1806 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1807 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1808 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, imd, pwrb,
1809 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1810 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1811 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, stat_sn,
1813 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1814 exp_statsn) / 32] + 1));
1815 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, wrb_idx,
1816 pwrb, pwrb_handle->wrb_index);
1818 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1819 max_burst_length, pwrb, params->dw[offsetof
1820 (struct amap_beiscsi_offload_params,
1821 max_burst_length) / 32]);
1823 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, ptr2nextwrb,
1824 pwrb, pwrb_handle->wrb_index);
1825 if (pwrb_context->plast_wrb)
1826 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1828 pwrb_context->plast_wrb,
1829 pwrb_handle->wrb_index);
1830 pwrb_context->plast_wrb = pwrb;
1832 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1833 session_state, pwrb, 0);
1834 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, compltonack,
1836 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, notpredblq,
1838 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb, mode, pwrb,
1841 mem_descr += ISCSI_MEM_GLOBAL_HEADER;
1842 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1843 pad_buffer_addr_hi, pwrb,
1844 mem_descr->mem_array[0].bus_address.u.a32.address_hi);
1845 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb,
1846 pad_buffer_addr_lo, pwrb,
1847 mem_descr->mem_array[0].bus_address.u.a32.address_lo);
1850 void beiscsi_offload_cxn_v2(struct beiscsi_offload_params *params,
1851 struct wrb_handle *pwrb_handle,
1852 struct hwi_wrb_context *pwrb_context)
1854 struct iscsi_wrb *pwrb = pwrb_handle->pwrb;
1856 memset(pwrb, 0, sizeof(*pwrb));
1858 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1859 max_burst_length, pwrb, params->dw[offsetof
1860 (struct amap_beiscsi_offload_params,
1861 max_burst_length) / 32]);
1862 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1864 BE_TGT_CTX_UPDT_CMD);
1865 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1867 pwrb, pwrb_handle->wrb_index);
1868 if (pwrb_context->plast_wrb)
1869 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1871 pwrb_context->plast_wrb,
1872 pwrb_handle->wrb_index);
1873 pwrb_context->plast_wrb = pwrb;
1875 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, wrb_idx,
1876 pwrb, pwrb_handle->wrb_index);
1877 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1878 max_send_data_segment_length, pwrb,
1879 params->dw[offsetof(struct amap_beiscsi_offload_params,
1880 max_send_data_segment_length) / 32]);
1881 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1882 first_burst_length, pwrb,
1883 params->dw[offsetof(struct amap_beiscsi_offload_params,
1884 first_burst_length) / 32]);
1885 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1886 max_recv_dataseg_len, pwrb,
1887 params->dw[offsetof(struct amap_beiscsi_offload_params,
1888 max_recv_data_segment_length) / 32]);
1889 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1890 max_cxns, pwrb, BEISCSI_MAX_CXNS);
1891 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, erl, pwrb,
1892 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1893 erl) / 32] & OFFLD_PARAMS_ERL));
1894 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, dde, pwrb,
1895 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1896 dde) / 32] & OFFLD_PARAMS_DDE) >> 2);
1897 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, hde, pwrb,
1898 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1899 hde) / 32] & OFFLD_PARAMS_HDE) >> 3);
1900 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1902 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1903 ir2t) / 32] & OFFLD_PARAMS_IR2T) >> 4);
1904 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, imd, pwrb,
1905 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1906 imd) / 32] & OFFLD_PARAMS_IMD) >> 5);
1907 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1910 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1911 data_seq_inorder) / 32] &
1912 OFFLD_PARAMS_DATA_SEQ_INORDER) >> 6);
1913 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2,
1916 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1917 pdu_seq_inorder) / 32] &
1918 OFFLD_PARAMS_PDU_SEQ_INORDER) >> 7);
1919 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, max_r2t,
1921 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1923 OFFLD_PARAMS_MAX_R2T) >> 8);
1924 AMAP_SET_BITS(struct amap_iscsi_target_context_update_wrb_v2, stat_sn,
1926 (params->dw[offsetof(struct amap_beiscsi_offload_params,
1927 exp_statsn) / 32] + 1));