Pull SCSI updates from James Bottomley: "This series consists of the usual driver updates (ufs, ibmvfc, megaraid_sas, lpfc, elx, mpi3mr, qedi, iscsi, storvsc, mpt3sas) with elx and mpi3mr being new drivers. The major core change is a rework to drop the status byte handling macros and the old bit shifted definitions and the rest of the updates are minor fixes" * tag 'scsi-misc' of git://git.kernel.org/pub/scm/linux/kernel/git/jejb/scsi: (287 commits) scsi: aha1740: Avoid over-read of sense buffer scsi: arcmsr: Avoid over-read of sense buffer scsi: ips: Avoid over-read of sense buffer scsi: ufs: ufs-mediatek: Add missing of_node_put() in ufs_mtk_probe() scsi: elx: libefc: Fix IRQ restore in efc_domain_dispatch_frame() scsi: elx: libefc: Fix less than zero comparison of a unsigned int scsi: elx: efct: Fix pointer error checking in debugfs init scsi: elx: efct: Fix is_originator return code type scsi: elx: efct: Fix link error for _bad_cmpxchg scsi: elx: efct: Eliminate unnecessary boolean check in efct_hw_command_cancel() scsi: elx: efct: Do not use id uninitialized in efct_lio_setup_session() scsi: elx: efct: Fix error handling in efct_hw_init() scsi: elx: efct: Remove redundant initialization of variable lun scsi: elx: efct: Fix spelling mistake "Unexected" -> "Unexpected" scsi: lpfc: Fix build error in lpfc_scsi.c scsi: target: iscsi: Remove redundant continue statement scsi: qla4xxx: Remove redundant continue statement scsi: ppa: Switch to use module_parport_driver() scsi: imm: Switch to use module_parport_driver() scsi: mpt3sas: Fix error return value in _scsih_expander_add() ...
Unified · Split
| @@ -995,6 +995,132 @@ Description: This entry shows the target state of an UFS UIC link · 994 unmodified lines | |||
| 995 | 995 | ||
| 996 | The file is read only. | 996 | The file is read only. |
| 997 | 997 | ||
| 998 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/monitor_enable | ||
| 999 | Date: January 2021 | ||
| 1000 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1001 | Description: This file shows the status of performance monitor enablement | ||
| 1002 | and it can be used to start/stop the monitor. When the monitor | ||
| 1003 | is stopped, the performance data collected is also cleared. | ||
| 1004 | |||
| 1005 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/monitor_chunk_size | ||
| 1006 | Date: January 2021 | ||
| 1007 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1008 | Description: This file tells the monitor to focus on requests transferring | ||
| 1009 | data of specific chunk size (in Bytes). 0 means any chunk size. | ||
| 1010 | It can only be changed when monitor is disabled. | ||
| 1011 | |||
| 1012 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/read_total_sectors | ||
| 1013 | Date: January 2021 | ||
| 1014 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1015 | Description: This file shows how many sectors (in 512 Bytes) have been | ||
| 1016 | sent from device to host after monitor gets started. | ||
| 1017 | |||
| 1018 | The file is read only. | ||
| 1019 | |||
| 1020 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/read_total_busy | ||
| 1021 | Date: January 2021 | ||
| 1022 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1023 | Description: This file shows how long (in micro seconds) has been spent | ||
| 1024 | sending data from device to host after monitor gets started. | ||
| 1025 | |||
| 1026 | The file is read only. | ||
| 1027 | |||
| 1028 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/read_nr_requests | ||
| 1029 | Date: January 2021 | ||
| 1030 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1031 | Description: This file shows how many read requests have been sent after | ||
| 1032 | monitor gets started. | ||
| 1033 | |||
| 1034 | The file is read only. | ||
| 1035 | |||
| 1036 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_max | ||
| 1037 | Date: January 2021 | ||
| 1038 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1039 | Description: This file shows the maximum latency (in micro seconds) of | ||
| 1040 | read requests after monitor gets started. | ||
| 1041 | |||
| 1042 | The file is read only. | ||
| 1043 | |||
| 1044 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_min | ||
| 1045 | Date: January 2021 | ||
| 1046 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1047 | Description: This file shows the minimum latency (in micro seconds) of | ||
| 1048 | read requests after monitor gets started. | ||
| 1049 | |||
| 1050 | The file is read only. | ||
| 1051 | |||
| 1052 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_avg | ||
| 1053 | Date: January 2021 | ||
| 1054 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1055 | Description: This file shows the average latency (in micro seconds) of | ||
| 1056 | read requests after monitor gets started. | ||
| 1057 | |||
| 1058 | The file is read only. | ||
| 1059 | |||
| 1060 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/read_req_latency_sum | ||
| 1061 | Date: January 2021 | ||
| 1062 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1063 | Description: This file shows the total latency (in micro seconds) of | ||
| 1064 | read requests sent after monitor gets started. | ||
| 1065 | |||
| 1066 | The file is read only. | ||
| 1067 | |||
| 1068 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/write_total_sectors | ||
| 1069 | Date: January 2021 | ||
| 1070 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1071 | Description: This file shows how many sectors (in 512 Bytes) have been sent | ||
| 1072 | from host to device after monitor gets started. | ||
| 1073 | |||
| 1074 | The file is read only. | ||
| 1075 | |||
| 1076 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/write_total_busy | ||
| 1077 | Date: January 2021 | ||
| 1078 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1079 | Description: This file shows how long (in micro seconds) has been spent | ||
| 1080 | sending data from host to device after monitor gets started. | ||
| 1081 | |||
| 1082 | The file is read only. | ||
| 1083 | |||
| 1084 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/write_nr_requests | ||
| 1085 | Date: January 2021 | ||
| 1086 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1087 | Description: This file shows how many write requests have been sent after | ||
| 1088 | monitor gets started. | ||
| 1089 | |||
| 1090 | The file is read only. | ||
| 1091 | |||
| 1092 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_max | ||
| 1093 | Date: January 2021 | ||
| 1094 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1095 | Description: This file shows the maximum latency (in micro seconds) of write | ||
| 1096 | requests after monitor gets started. | ||
| 1097 | |||
| 1098 | The file is read only. | ||
| 1099 | |||
| 1100 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_min | ||
| 1101 | Date: January 2021 | ||
| 1102 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1103 | Description: This file shows the minimum latency (in micro seconds) of write | ||
| 1104 | requests after monitor gets started. | ||
| 1105 | |||
| 1106 | The file is read only. | ||
| 1107 | |||
| 1108 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_avg | ||
| 1109 | Date: January 2021 | ||
| 1110 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1111 | Description: This file shows the average latency (in micro seconds) of write | ||
| 1112 | requests after monitor gets started. | ||
| 1113 | |||
| 1114 | The file is read only. | ||
| 1115 | |||
| 1116 | What: /sys/bus/platform/drivers/ufshcd/*/monitor/write_req_latency_sum | ||
| 1117 | Date: January 2021 | ||
| 1118 | Contact: Can Guo <cang@codeaurora.org> | ||
| 1119 | Description: This file shows the total latency (in micro seconds) of write | ||
| 1120 | requests after monitor gets started. | ||
| 1121 | |||
| 1122 | The file is read only. | ||
| 1123 | |||
| 998 | What: /sys/bus/platform/drivers/ufshcd/*/device_descriptor/wb_presv_us_en | 1124 | What: /sys/bus/platform/drivers/ufshcd/*/device_descriptor/wb_presv_us_en |
| 999 | Date: June 2020 | 1125 | Date: June 2020 |
| 1000 | Contact: Asutosh Das <asutoshd@codeaurora.org> | 1126 | Contact: Asutosh Das <asutoshd@codeaurora.org> |
| @@ -1172,10 +1172,9 @@ Members of interest: · 1171 unmodified lines | |||
| 1172 | of 0 implies a successfully completed command (and all | 1172 | of 0 implies a successfully completed command (and all |
| 1173 | data (if any) has been transferred to or from the SCSI | 1173 | data (if any) has been transferred to or from the SCSI |
| 1174 | target device). 'result' is a 32 bit unsigned integer that | 1174 | target device). 'result' is a 32 bit unsigned integer that |
| 1175 | can be viewed as 4 related bytes. The SCSI status value is | 1175 | can be viewed as 2 related bytes. The SCSI status value is |
| 1176 | in the LSB. See include/scsi/scsi.h status_byte(), | 1176 | in the LSB. See include/scsi/scsi.h status_byte() and |
| 1177 | msg_byte(), host_byte() and driver_byte() macros and | 1177 | host_byte() macros and related constants. |
| 1178 | related constants. | ||
| 1179 | sense_buffer | 1178 | sense_buffer |
| 1180 | - an array (maximum size: SCSI_SENSE_BUFFERSIZE bytes) that | 1179 | - an array (maximum size: SCSI_SENSE_BUFFERSIZE bytes) that |
| 1181 | should be written when the SCSI status (LSB of 'result') | 1180 | should be written when the SCSI status (LSB of 'result') |
| @@ -6800,6 +6800,15 @@ S: Supported · 6799 unmodified lines | |||
| 6800 | W: http://www.broadcom.com | 6800 | W: http://www.broadcom.com |
| 6801 | F: drivers/scsi/lpfc/ | 6801 | F: drivers/scsi/lpfc/ |
| 6802 | 6802 | ||
| 6803 | EMULEX/BROADCOM EFCT FC/FCOE SCSI TARGET DRIVER | ||
| 6804 | M: James Smart <james.smart@broadcom.com> | ||
| 6805 | M: Ram Vegesna <ram.vegesna@broadcom.com> | ||
| 6806 | L: linux-scsi@vger.kernel.org | ||
| 6807 | L: target-devel@vger.kernel.org | ||
| 6808 | S: Supported | ||
| 6809 | W: http://www.broadcom.com | ||
| 6810 | F: drivers/scsi/elx/ | ||
| 6811 | |||
| 6803 | ENE CB710 FLASH CARD READER DRIVER | 6812 | ENE CB710 FLASH CARD READER DRIVER |
| 6804 | M: Michał Mirosław <mirq-linux@rere.qmqm.pl> | 6813 | M: Michał Mirosław <mirq-linux@rere.qmqm.pl> |
| 6805 | S: Maintained | 6814 | S: Maintained |
| @@ -151,6 +151,15 @@ config BLK_CGROUP_IOLATENCY · 150 unmodified lines | |||
| 151 | 151 | ||
| 152 | Note, this is an experimental interface and could be changed someday. | 152 | Note, this is an experimental interface and could be changed someday. |
| 153 | 153 | ||
| 154 | config BLK_CGROUP_FC_APPID | ||
| 155 | bool "Enable support to track FC I/O Traffic across cgroup applications" | ||
| 156 | depends on BLK_CGROUP=y | ||
| 157 | help | ||
| 158 | Enabling this option enables the support to track FC I/O traffic across | ||
| 159 | cgroup applications. It enables the Fabric and the storage targets to | ||
| 160 | identify, monitor, and handle FC traffic based on VM tags by inserting | ||
| 161 | application specific identification into the FC frame. | ||
| 162 | |||
| 154 | config BLK_CGROUP_IOCOST | 163 | config BLK_CGROUP_IOCOST |
| 155 | bool "Enable support for cost model based cgroup IO controller" | 164 | bool "Enable support for cost model based cgroup IO controller" |
| 156 | depends on BLK_CGROUP=y | 165 | depends on BLK_CGROUP=y |
| @@ -84,7 +84,7 @@ static int bsg_transport_complete_rq(struct request *rq, struct sg_io_v4 *hdr) · 83 unmodified lines | |||
| 84 | */ | 84 | */ |
| 85 | hdr->device_status = job->result & 0xff; | 85 | hdr->device_status = job->result & 0xff; |
| 86 | hdr->transport_status = host_byte(job->result); | 86 | hdr->transport_status = host_byte(job->result); |
| 87 | hdr->driver_status = driver_byte(job->result); | 87 | hdr->driver_status = 0; |
| 88 | hdr->info = 0; | 88 | hdr->info = 0; |
| 89 | if (hdr->device_status || hdr->transport_status || hdr->driver_status) | 89 | if (hdr->device_status || hdr->transport_status || hdr->driver_status) |
| 90 | hdr->info |= SG_INFO_CHECK; | 90 | hdr->info |= SG_INFO_CHECK; |
| @@ -96,7 +96,9 @@ static int bsg_scsi_complete_rq(struct request *rq, struct sg_io_v4 *hdr) · 95 unmodified lines | |||
| 96 | */ | 96 | */ |
| 97 | hdr->device_status = sreq->result & 0xff; | 97 | hdr->device_status = sreq->result & 0xff; |
| 98 | hdr->transport_status = host_byte(sreq->result); | 98 | hdr->transport_status = host_byte(sreq->result); |
| 99 | hdr->driver_status = driver_byte(sreq->result); | 99 | hdr->driver_status = 0; |
| 100 | if (scsi_status_is_check_condition(sreq->result)) | ||
| 101 | hdr->driver_status = DRIVER_SENSE; | ||
| 100 | hdr->info = 0; | 102 | hdr->info = 0; |
| 101 | if (hdr->device_status || hdr->transport_status || hdr->driver_status) | 103 | if (hdr->device_status || hdr->transport_status || hdr->driver_status) |
| 102 | hdr->info |= SG_INFO_CHECK; | 104 | hdr->info |= SG_INFO_CHECK; |
| @@ -254,9 +254,11 @@ static int blk_complete_sghdr_rq(struct request *rq, struct sg_io_hdr *hdr, · 253 unmodified lines | |||
| 254 | */ | 254 | */ |
| 255 | hdr->status = req->result & 0xff; | 255 | hdr->status = req->result & 0xff; |
| 256 | hdr->masked_status = status_byte(req->result); | 256 | hdr->masked_status = status_byte(req->result); |
| 257 | hdr->msg_status = msg_byte(req->result); | 257 | hdr->msg_status = COMMAND_COMPLETE; |
| 258 | hdr->host_status = host_byte(req->result); | 258 | hdr->host_status = host_byte(req->result); |
| 259 | hdr->driver_status = driver_byte(req->result); | 259 | hdr->driver_status = 0; |
| 260 | if (scsi_status_is_check_condition(hdr->status)) | ||
| 261 | hdr->driver_status = DRIVER_SENSE; | ||
| 260 | hdr->info = 0; | 262 | hdr->info = 0; |
| 261 | if (hdr->masked_status || hdr->host_status || hdr->driver_status) | 263 | if (hdr->masked_status || hdr->host_status || hdr->driver_status) |
| 262 | hdr->info |= SG_INFO_CHECK; | 264 | hdr->info |= SG_INFO_CHECK; |
| @@ -484,9 +486,10 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode, · 221 unmodified lines | |||
| 484 | break; | 486 | break; |
| 485 | } | 487 | } |
| 486 | 488 | ||
| 487 | if (bytes && blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO)) { | 489 | if (bytes) { |
| 488 | err = DRIVER_ERROR << 24; | 490 | err = blk_rq_map_kern(q, rq, buffer, bytes, GFP_NOIO); |
| 489 | goto error; | 491 | if (err) |
| 492 | goto error; | ||
| 490 | } | 493 | } |
| 491 | 494 | ||
| 492 | blk_execute_rq(disk, rq, 0); | 495 | blk_execute_rq(disk, rq, 0); |
| @@ -196,9 +196,7 @@ void ata_scsi_set_sense(struct ata_device *dev, struct scsi_cmnd *cmd, · 195 unmodified lines | |||
| 196 | if (!cmd) | 196 | if (!cmd) |
| 197 | return; | 197 | return; |
| 198 | 198 | ||
| 199 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | 199 | scsi_build_sense(cmd, d_sense, sk, asc, ascq); |
| 200 | |||
| 201 | scsi_build_sense_buffer(d_sense, cmd->sense_buffer, sk, asc, ascq); | ||
| 202 | } | 200 | } |
| 203 | 201 | ||
| 204 | void ata_scsi_set_sense_information(struct ata_device *dev, | 202 | void ata_scsi_set_sense_information(struct ata_device *dev, |
| @@ -409,13 +407,16 @@ int ata_cmd_ioctl(struct scsi_device *scsidev, void __user *arg) · 204 unmodified lines | |||
| 409 | cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize, | 407 | cmd_result = scsi_execute(scsidev, scsi_cmd, data_dir, argbuf, argsize, |
| 410 | sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); | 408 | sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); |
| 411 | 409 | ||
| 412 | if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ | 410 | if (cmd_result < 0) { |
| 411 | rc = cmd_result; | ||
| 412 | goto error; | ||
| 413 | } | ||
| 414 | if (scsi_sense_valid(&sshdr)) {/* sense data available */ | ||
| 413 | u8 *desc = sensebuf + 8; | 415 | u8 *desc = sensebuf + 8; |
| 414 | cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ | ||
| 415 | 416 | ||
| 416 | /* If we set cc then ATA pass-through will cause a | 417 | /* If we set cc then ATA pass-through will cause a |
| 417 | * check condition even if no error. Filter that. */ | 418 | * check condition even if no error. Filter that. */ |
| 418 | if (cmd_result & SAM_STAT_CHECK_CONDITION) { | 419 | if (scsi_status_is_check_condition(cmd_result)) { |
| 419 | if (sshdr.sense_key == RECOVERED_ERROR && | 420 | if (sshdr.sense_key == RECOVERED_ERROR && |
| 420 | sshdr.asc == 0 && sshdr.ascq == 0x1d) | 421 | sshdr.asc == 0 && sshdr.ascq == 0x1d) |
| 421 | cmd_result &= ~SAM_STAT_CHECK_CONDITION; | 422 | cmd_result &= ~SAM_STAT_CHECK_CONDITION; |
| @@ -490,9 +491,12 @@ int ata_task_ioctl(struct scsi_device *scsidev, void __user *arg) · 68 unmodified lines | |||
| 490 | cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0, | 491 | cmd_result = scsi_execute(scsidev, scsi_cmd, DMA_NONE, NULL, 0, |
| 491 | sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); | 492 | sensebuf, &sshdr, (10*HZ), 5, 0, 0, NULL); |
| 492 | 493 | ||
| 493 | if (driver_byte(cmd_result) == DRIVER_SENSE) {/* sense data available */ | 494 | if (cmd_result < 0) { |
| 495 | rc = cmd_result; | ||
| 496 | goto error; | ||
| 497 | } | ||
| 498 | if (scsi_sense_valid(&sshdr)) {/* sense data available */ | ||
| 494 | u8 *desc = sensebuf + 8; | 499 | u8 *desc = sensebuf + 8; |
| 495 | cmd_result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ | ||
| 496 | 500 | ||
| 497 | /* If we set cc then ATA pass-through will cause a | 501 | /* If we set cc then ATA pass-through will cause a |
| 498 | * check condition even if no error. Filter that. */ | 502 | * check condition even if no error. Filter that. */ |
| @@ -638,7 +642,7 @@ static struct ata_queued_cmd *ata_scsi_qc_new(struct ata_device *dev, · 139 unmodified lines | |||
| 638 | if (cmd->request->rq_flags & RQF_QUIET) | 642 | if (cmd->request->rq_flags & RQF_QUIET) |
| 639 | qc->flags |= ATA_QCFLAG_QUIET; | 643 | qc->flags |= ATA_QCFLAG_QUIET; |
| 640 | } else { | 644 | } else { |
| 641 | cmd->result = (DID_OK << 16) | (QUEUE_FULL << 1); | 645 | cmd->result = (DID_OK << 16) | SAM_STAT_TASK_SET_FULL; |
| 642 | cmd->scsi_done(cmd); | 646 | cmd->scsi_done(cmd); |
| 643 | } | 647 | } |
| 644 | 648 | ||
| @@ -858,8 +862,6 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) · 213 unmodified lines | |||
| 858 | 862 | ||
| 859 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); | 863 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); |
| 860 | 864 | ||
| 861 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | ||
| 862 | |||
| 863 | /* | 865 | /* |
| 864 | * Use ata_to_sense_error() to map status register bits | 866 | * Use ata_to_sense_error() to map status register bits |
| 865 | * onto sense key, asc & ascq. | 867 | * onto sense key, asc & ascq. |
| @@ -874,8 +876,7 @@ static void ata_gen_passthru_sense(struct ata_queued_cmd *qc) · 8 unmodified lines | |||
| 874 | * ATA PASS-THROUGH INFORMATION AVAILABLE | 876 | * ATA PASS-THROUGH INFORMATION AVAILABLE |
| 875 | * Always in descriptor format sense. | 877 | * Always in descriptor format sense. |
| 876 | */ | 878 | */ |
| 877 | scsi_build_sense_buffer(1, cmd->sense_buffer, | 879 | scsi_build_sense(cmd, 1, RECOVERED_ERROR, 0, 0x1D); |
| 878 | RECOVERED_ERROR, 0, 0x1D); | ||
| 879 | } | 880 | } |
| 880 | 881 | ||
| 881 | if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) { | 882 | if ((cmd->sense_buffer[0] & 0x7f) >= 0x72) { |
| @@ -957,8 +958,6 @@ static void ata_gen_ata_sense(struct ata_queued_cmd *qc) · 75 unmodified lines | |||
| 957 | 958 | ||
| 958 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); | 959 | memset(sb, 0, SCSI_SENSE_BUFFERSIZE); |
| 959 | 960 | ||
| 960 | cmd->result = (DRIVER_SENSE << 24) | SAM_STAT_CHECK_CONDITION; | ||
| 961 | |||
| 962 | if (ata_dev_disabled(dev)) { | 961 | if (ata_dev_disabled(dev)) { |
| 963 | /* Device disabled after error recovery */ | 962 | /* Device disabled after error recovery */ |
| 964 | /* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */ | 963 | /* LOGICAL UNIT NOT READY, HARD RESET REQUIRED */ |
| @@ -4196,7 +4195,6 @@ void ata_scsi_simulate(struct ata_device *dev, struct scsi_cmnd *cmd) · 3231 unmodified lines | |||
| 4196 | 4195 | ||
| 4197 | case REQUEST_SENSE: | 4196 | case REQUEST_SENSE: |
| 4198 | ata_scsi_set_sense(dev, cmd, 0, 0, 0); | 4197 | ata_scsi_set_sense(dev, cmd, 0, 0, 0); |
| 4199 | cmd->result = (DRIVER_SENSE << 24); | ||
| 4200 | break; | 4198 | break; |
| 4201 | 4199 | ||
| 4202 | /* if we reach this, then writeback caching is disabled, | 4200 | /* if we reach this, then writeback caching is disabled, |
| @@ -506,6 +506,7 @@ iscsi_iser_conn_bind(struct iscsi_cls_session *cls_session, · 505 unmodified lines | |||
| 506 | iser_conn->iscsi_conn = conn; | 506 | iser_conn->iscsi_conn = conn; |
| 507 | 507 | ||
| 508 | out: | 508 | out: |
| 509 | iscsi_put_endpoint(ep); | ||
| 509 | mutex_unlock(&iser_conn->state_mutex); | 510 | mutex_unlock(&iser_conn->state_mutex); |
| 510 | return error; | 511 | return error; |
| 511 | } | 512 | } |
| @@ -1002,6 +1003,7 @@ static struct iscsi_transport iscsi_iser_transport = { · 490 unmodified lines | |||
| 1002 | /* connection management */ | 1003 | /* connection management */ |
| 1003 | .create_conn = iscsi_iser_conn_create, | 1004 | .create_conn = iscsi_iser_conn_create, |
| 1004 | .bind_conn = iscsi_iser_conn_bind, | 1005 | .bind_conn = iscsi_iser_conn_bind, |
| 1006 | .unbind_conn = iscsi_conn_unbind, | ||
| 1005 | .destroy_conn = iscsi_conn_teardown, | 1007 | .destroy_conn = iscsi_conn_teardown, |
| 1006 | .attr_is_visible = iser_attr_is_visible, | 1008 | .attr_is_visible = iser_attr_is_visible, |
| 1007 | .set_param = iscsi_iser_set_param, | 1009 | .set_param = iscsi_iser_set_param, |
| @@ -2209,7 +2209,7 @@ static int srp_queuecommand(struct Scsi_Host *shost, struct scsi_cmnd *scmnd) · 2208 unmodified lines | |||
| 2209 | * to reduce queue depth temporarily. | 2209 | * to reduce queue depth temporarily. |
| 2210 | */ | 2210 | */ |
| 2211 | scmnd->result = len == -ENOMEM ? | 2211 | scmnd->result = len == -ENOMEM ? |
| 2212 | DID_OK << 16 | QUEUE_FULL << 1 : DID_ERROR << 16; | 2212 | DID_OK << 16 | SAM_STAT_TASK_SET_FULL : DID_ERROR << 16; |
| 2213 | goto err_iu; | 2213 | goto err_iu; |
| 2214 | } | 2214 | } |
| 2215 | 2215 | ||
| @@ -6993,8 +6993,6 @@ mpt_SoftResetHandler(MPT_ADAPTER *ioc, int sleepFlag) · 6992 unmodified lines | |||
| 6993 | ioc->ioc_reset_in_progress = 1; | 6993 | ioc->ioc_reset_in_progress = 1; |
| 6994 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); | 6994 | spin_unlock_irqrestore(&ioc->taskmgmt_lock, flags); |
| 6995 | 6995 | ||
| 6996 | rc = -1; | ||
| 6997 | |||
| 6998 | for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) { | 6996 | for (cb_idx = MPT_MAX_PROTOCOL_DRIVERS-1; cb_idx; cb_idx--) { |
| 6999 | if (MptResetHandlers[cb_idx]) | 6997 | if (MptResetHandlers[cb_idx]) |
| 7000 | mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET); | 6998 | mpt_signal_reset(cb_idx, ioc, MPT_IOC_SETUP_RESET); |
| @@ -86,7 +86,7 @@ MODULE_PARM_DESC(mpt_pt_clear, · 85 unmodified lines | |||
| 86 | " Clear persistency table: enable=1 " | 86 | " Clear persistency table: enable=1 " |
| 87 | "(default=MPTSCSIH_PT_CLEAR=0)"); | 87 | "(default=MPTSCSIH_PT_CLEAR=0)"); |
| 88 | 88 | ||
| 89 | /* scsi-mid layer global parmeter is max_report_luns, which is 511 */ | 89 | /* scsi-mid layer global parameter is max_report_luns, which is 511 */ |
| 90 | #define MPTSAS_MAX_LUN (16895) | 90 | #define MPTSAS_MAX_LUN (16895) |
| 91 | static int max_lun = MPTSAS_MAX_LUN; | 91 | static int max_lun = MPTSAS_MAX_LUN; |
| 92 | module_param(max_lun, int, 0); | 92 | module_param(max_lun, int, 0); |
| @@ -420,12 +420,14 @@ mptsas_find_portinfo_by_handle(MPT_ADAPTER *ioc, u16 handle) · 327 unmodified lines | |||
| 420 | } | 420 | } |
| 421 | 421 | ||
| 422 | /** | 422 | /** |
| 423 | * mptsas_find_portinfo_by_sas_address - | 423 | * mptsas_find_portinfo_by_sas_address - find and return portinfo for |
| 424 | * this sas_address | ||
| 424 | * @ioc: Pointer to MPT_ADAPTER structure | 425 | * @ioc: Pointer to MPT_ADAPTER structure |
| 425 | * @handle: | 426 | * @sas_address: expander sas address |
| 426 | * | 427 | * |
| 427 | * This function should be called with the sas_topology_mutex already held | 428 | * This function should be called with the sas_topology_mutex already held. |
| 428 | * | 429 | * |
| 430 | * Return: %NULL if not found. | ||
| 429 | **/ | 431 | **/ |
| 430 | static struct mptsas_portinfo * | 432 | static struct mptsas_portinfo * |
| 431 | mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) | 433 | mptsas_find_portinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) |
| @@ -567,12 +569,14 @@ starget) · 135 unmodified lines | |||
| 567 | } | 569 | } |
| 568 | 570 | ||
| 569 | /** | 571 | /** |
| 570 | * mptsas_add_device_component - | 572 | * mptsas_add_device_component - adds a new device component to our lists |
| 571 | * @ioc: Pointer to MPT_ADAPTER structure | 573 | * @ioc: Pointer to MPT_ADAPTER structure |
| 572 | * @channel: fw mapped id's | 574 | * @channel: channel number |
| 573 | * @id: | 575 | * @id: Logical Target ID for reset (if appropriate) |
| 574 | * @sas_address: | 576 | * @sas_address: expander sas address |
| 575 | * @device_info: | 577 | * @device_info: specific bits (flags) for devices |
| 578 | * @slot: enclosure slot ID | ||
| 579 | * @enclosure_logical_id: enclosure WWN | ||
| 576 | * | 580 | * |
| 577 | **/ | 581 | **/ |
| 578 | static void | 582 | static void |
| @@ -634,10 +638,10 @@ mptsas_add_device_component(MPT_ADAPTER *ioc, u8 channel, u8 id, · 55 unmodified lines | |||
| 634 | } | 638 | } |
| 635 | 639 | ||
| 636 | /** | 640 | /** |
| 637 | * mptsas_add_device_component_by_fw - | 641 | * mptsas_add_device_component_by_fw - adds a new device component by FW ID |
| 638 | * @ioc: Pointer to MPT_ADAPTER structure | 642 | * @ioc: Pointer to MPT_ADAPTER structure |
| 639 | * @channel: fw mapped id's | 643 | * @channel: channel number |
| 640 | * @id: | 644 | * @id: Logical Target ID |
| 641 | * | 645 | * |
| 642 | **/ | 646 | **/ |
| 643 | static void | 647 | static void |
| @@ -668,8 +672,7 @@ mptsas_add_device_component_by_fw(MPT_ADAPTER *ioc, u8 channel, u8 id) · 24 unmodified lines | |||
| 668 | /** | 672 | /** |
| 669 | * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list | 673 | * mptsas_add_device_component_starget_ir - Handle Integrated RAID, adding each individual device to list |
| 670 | * @ioc: Pointer to MPT_ADAPTER structure | 674 | * @ioc: Pointer to MPT_ADAPTER structure |
| 671 | * @channel: fw mapped id's | 675 | * @starget: SCSI target for this SCSI device |
| 672 | * @id: | ||
| 673 | * | 676 | * |
| 674 | **/ | 677 | **/ |
| 675 | static void | 678 | static void |
| @@ -771,9 +774,9 @@ mptsas_add_device_component_starget_ir(MPT_ADAPTER *ioc, · 95 unmodified lines | |||
| 771 | } | 774 | } |
| 772 | 775 | ||
| 773 | /** | 776 | /** |
| 774 | * mptsas_add_device_component_starget - | 777 | * mptsas_add_device_component_starget - adds a SCSI target device component |
| 775 | * @ioc: Pointer to MPT_ADAPTER structure | 778 | * @ioc: Pointer to MPT_ADAPTER structure |
| 776 | * @starget: | 779 | * @starget: SCSI target for this SCSI device |
| 777 | * | 780 | * |
| 778 | **/ | 781 | **/ |
| 779 | static void | 782 | static void |
| @@ -806,7 +809,7 @@ mptsas_add_device_component_starget(MPT_ADAPTER *ioc, · 26 unmodified lines | |||
| 806 | * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached | 809 | * mptsas_del_device_component_by_os - Once a device has been removed, we mark the entry in the list as being cached |
| 807 | * @ioc: Pointer to MPT_ADAPTER structure | 810 | * @ioc: Pointer to MPT_ADAPTER structure |
| 808 | * @channel: os mapped id's | 811 | * @channel: os mapped id's |
| 809 | * @id: | 812 | * @id: Logical Target ID |
| 810 | * | 813 | * |
| 811 | **/ | 814 | **/ |
| 812 | static void | 815 | static void |
| @@ -978,11 +981,12 @@ mptsas_setup_wide_ports(MPT_ADAPTER *ioc, struct mptsas_portinfo *port_info) · 165 unmodified lines | |||
| 978 | } | 981 | } |
| 979 | 982 | ||
| 980 | /** | 983 | /** |
| 981 | * csmisas_find_vtarget | 984 | * mptsas_find_vtarget - find a virtual target device (FC LUN device or |
| 985 | * SCSI target device) | ||
| 982 | * | 986 | * |
| 983 | * @ioc | 987 | * @ioc: Pointer to MPT_ADAPTER structure |
| 984 | * @volume_id | 988 | * @channel: channel number |
| 985 | * @volume_bus | 989 | * @id: Logical Target ID |
| 986 | * | 990 | * |
| 987 | **/ | 991 | **/ |
| 988 | static VirtTarget * | 992 | static VirtTarget * |
| @@ -1047,15 +1051,14 @@ mptsas_queue_rescan(MPT_ADAPTER *ioc) · 58 unmodified lines | |||
| 1047 | 1051 | ||
| 1048 | 1052 | ||
| 1049 | /** | 1053 | /** |
| 1050 | * mptsas_target_reset | 1054 | * mptsas_target_reset - Issues TARGET_RESET to end device using |
| 1051 | * | 1055 | * handshaking method |
| 1052 | * Issues TARGET_RESET to end device using handshaking method | ||
| 1053 | * | 1056 | * |
| 1054 | * @ioc | 1057 | * @ioc: Pointer to MPT_ADAPTER structure |
| 1055 | * @channel | 1058 | * @channel: channel number |
| 1056 | * @id | 1059 | * @id: Logical Target ID for reset |
| 1057 | * | 1060 | * |
| 1058 | * Returns (1) success | 1061 | * Return: (1) success |
| 1059 | * (0) failure | 1062 | * (0) failure |
| 1060 | * | 1063 | * |
| 1061 | **/ | 1064 | **/ |
| @@ -1119,15 +1122,15 @@ mptsas_block_io_starget(struct scsi_target *starget) · 57 unmodified lines | |||
| 1119 | } | 1122 | } |
| 1120 | 1123 | ||
| 1121 | /** | 1124 | /** |
| 1122 | * mptsas_target_reset_queue | 1125 | * mptsas_target_reset_queue - queue a target reset |
| 1123 | * | 1126 | * |
| 1124 | * Receive request for TARGET_RESET after receiving an firmware | 1127 | * @ioc: Pointer to MPT_ADAPTER structure |
| 1128 | * @sas_event_data: SAS Device Status Change Event data | ||
| 1129 | * | ||
| 1130 | * Receive request for TARGET_RESET after receiving a firmware | ||
| 1125 | * event NOT_RESPONDING_EVENT, then put command in link list | 1131 | * event NOT_RESPONDING_EVENT, then put command in link list |
| 1126 | * and queue if task_queue already in use. | 1132 | * and queue if task_queue already in use. |
| 1127 | * | 1133 | * |
| 1128 | * @ioc | ||
| 1129 | * @sas_event_data | ||
| 1130 | * | ||
| 1131 | **/ | 1134 | **/ |
| 1132 | static void | 1135 | static void |
| 1133 | mptsas_target_reset_queue(MPT_ADAPTER *ioc, | 1136 | mptsas_target_reset_queue(MPT_ADAPTER *ioc, |
| @@ -1207,9 +1210,11 @@ mptsas_schedule_target_reset(void *iocp) · 73 unmodified lines | |||
| 1207 | /** | 1210 | /** |
| 1208 | * mptsas_taskmgmt_complete - complete SAS task management function | 1211 | * mptsas_taskmgmt_complete - complete SAS task management function |
| 1209 | * @ioc: Pointer to MPT_ADAPTER structure | 1212 | * @ioc: Pointer to MPT_ADAPTER structure |
| 1213 | * @mf: MPT message frame | ||
| 1214 | * @mr: SCSI Task Management Reply structure ptr (may be %NULL) | ||
| 1210 | * | 1215 | * |
| 1211 | * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work | 1216 | * Completion for TARGET_RESET after NOT_RESPONDING_EVENT, enable work |
| 1212 | * queue to finish off removing device from upper layers. then send next | 1217 | * queue to finish off removing device from upper layers, then send next |
| 1213 | * TARGET_RESET in the queue. | 1218 | * TARGET_RESET in the queue. |
| 1214 | **/ | 1219 | **/ |
| 1215 | static int | 1220 | static int |
| @@ -1300,10 +1305,10 @@ mptsas_taskmgmt_complete(MPT_ADAPTER *ioc, MPT_FRAME_HDR *mf, MPT_FRAME_HDR *mr) · 84 unmodified lines | |||
| 1300 | } | 1305 | } |
| 1301 | 1306 | ||
| 1302 | /** | 1307 | /** |
| 1303 | * mptscsih_ioc_reset | 1308 | * mptsas_ioc_reset - issue an IOC reset for this reset phase |
| 1304 | * | 1309 | * |
| 1305 | * @ioc | 1310 | * @ioc: Pointer to MPT_ADAPTER structure |
| 1306 | * @reset_phase | 1311 | * @reset_phase: id of phase of reset |
| 1307 | * | 1312 | * |
| 1308 | **/ | 1313 | **/ |
| 1309 | static int | 1314 | static int |
| @@ -1350,7 +1355,7 @@ mptsas_ioc_reset(MPT_ADAPTER *ioc, int reset_phase) · 40 unmodified lines | |||
| 1350 | 1355 | ||
| 1351 | 1356 | ||
| 1352 | /** | 1357 | /** |
| 1353 | * enum device_state - | 1358 | * enum device_state - TUR device state |
| 1354 | * @DEVICE_RETRY: need to retry the TUR | 1359 | * @DEVICE_RETRY: need to retry the TUR |
| 1355 | * @DEVICE_ERROR: TUR return error, don't add device | 1360 | * @DEVICE_ERROR: TUR return error, don't add device |
| 1356 | * @DEVICE_READY: device can be added | 1361 | * @DEVICE_READY: device can be added |
| @@ -1941,7 +1946,7 @@ mptsas_qcmd(struct Scsi_Host *shost, struct scsi_cmnd *SCpnt) · 584 unmodified lines | |||
| 1941 | } | 1946 | } |
| 1942 | 1947 | ||
| 1943 | /** | 1948 | /** |
| 1944 | * mptsas_mptsas_eh_timed_out - resets the scsi_cmnd timeout | 1949 | * mptsas_eh_timed_out - resets the scsi_cmnd timeout |
| 1945 | * if the device under question is currently in the | 1950 | * if the device under question is currently in the |
| 1946 | * device removal delay. | 1951 | * device removal delay. |
| 1947 | * @sc: scsi command that the midlayer is about to time out | 1952 | * @sc: scsi command that the midlayer is about to time out |
| @@ -2839,14 +2844,15 @@ struct rep_manu_reply{ · 891 unmodified lines | |||
| 2839 | }; | 2844 | }; |
| 2840 | 2845 | ||
| 2841 | /** | 2846 | /** |
| 2842 | * mptsas_exp_repmanufacture_info - | 2847 | * mptsas_exp_repmanufacture_info - sets expander manufacturer info |
| 2843 | * @ioc: per adapter object | 2848 | * @ioc: per adapter object |
| 2844 | * @sas_address: expander sas address | 2849 | * @sas_address: expander sas address |
| 2845 | * @edev: the sas_expander_device object | 2850 | * @edev: the sas_expander_device object |
| 2846 | * | 2851 | * |
| 2847 | * Fills in the sas_expander_device object when SMP port is created. | 2852 | * For an edge expander or a fanout expander: |
| 2853 | * fills in the sas_expander_device object when SMP port is created. | ||
| 2848 | * | 2854 | * |
| 2849 | * Returns 0 for success, non-zero for failure. | 2855 | * Return: 0 for success, non-zero for failure. |
| 2850 | */ | 2856 | */ |
| 2851 | static int | 2857 | static int |
| 2852 | mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc, | 2858 | mptsas_exp_repmanufacture_info(MPT_ADAPTER *ioc, |
| @@ -3284,7 +3290,7 @@ static int mptsas_probe_one_phy(struct device *dev, · 431 unmodified lines | |||
| 3284 | rphy_to_expander_device(rphy)); | 3290 | rphy_to_expander_device(rphy)); |
| 3285 | } | 3291 | } |
| 3286 | 3292 | ||
| 3287 | /* If the device exists,verify it wasn't previously flagged | 3293 | /* If the device exists, verify it wasn't previously flagged |
| 3288 | as a missing device. If so, clear it */ | 3294 | as a missing device. If so, clear it */ |
| 3289 | vtarget = mptsas_find_vtarget(ioc, | 3295 | vtarget = mptsas_find_vtarget(ioc, |
| 3290 | phy_info->attached.channel, | 3296 | phy_info->attached.channel, |
| @@ -3611,8 +3617,7 @@ static void mptsas_expander_delete(MPT_ADAPTER *ioc, · 320 unmodified lines | |||
| 3611 | 3617 | ||
| 3612 | /** | 3618 | /** |
| 3613 | * mptsas_send_expander_event - expanders events | 3619 | * mptsas_send_expander_event - expanders events |
| 3614 | * @ioc: Pointer to MPT_ADAPTER structure | 3620 | * @fw_event: event data |
| 3615 | * @expander_data: event data | ||
| 3616 | * | 3621 | * |
| 3617 | * | 3622 | * |
| 3618 | * This function handles adding, removing, and refreshing | 3623 | * This function handles adding, removing, and refreshing |
| @@ -3657,9 +3662,9 @@ mptsas_send_expander_event(struct fw_event_work *fw_event) · 38 unmodified lines | |||
| 3657 | 3662 | ||
| 3658 | 3663 | ||
| 3659 | /** | 3664 | /** |
| 3660 | * mptsas_expander_add - | 3665 | * mptsas_expander_add - adds a newly discovered expander |
| 3661 | * @ioc: Pointer to MPT_ADAPTER structure | 3666 | * @ioc: Pointer to MPT_ADAPTER structure |
| 3662 | * @handle: | 3667 | * @handle: device handle |
| 3663 | * | 3668 | * |
| 3664 | */ | 3669 | */ |
| 3665 | static struct mptsas_portinfo * | 3670 | static struct mptsas_portinfo * |
| @@ -4000,9 +4005,9 @@ mptsas_probe_devices(MPT_ADAPTER *ioc) · 334 unmodified lines | |||
| 4000 | } | 4005 | } |
| 4001 | 4006 | ||
| 4002 | /** | 4007 | /** |
| 4003 | * mptsas_scan_sas_topology - | 4008 | * mptsas_scan_sas_topology - scans new SAS topology |
| 4009 | * (part of probe or rescan) | ||
| 4004 | * @ioc: Pointer to MPT_ADAPTER structure | 4010 | * @ioc: Pointer to MPT_ADAPTER structure |
| 4005 | * @sas_address: | ||
| 4006 | * | 4011 | * |
| 4007 | **/ | 4012 | **/ |
| 4008 | static void | 4013 | static void |
| @@ -4150,11 +4155,12 @@ mptsas_find_phyinfo_by_sas_address(MPT_ADAPTER *ioc, u64 sas_address) · 141 unmodified lines | |||
| 4150 | } | 4155 | } |
| 4151 | 4156 | ||
| 4152 | /** | 4157 | /** |
| 4153 | * mptsas_find_phyinfo_by_phys_disk_num - | 4158 | * mptsas_find_phyinfo_by_phys_disk_num - find phyinfo for the |
| 4159 | * specified @phys_disk_num | ||
| 4154 | * @ioc: Pointer to MPT_ADAPTER structure | 4160 | * @ioc: Pointer to MPT_ADAPTER structure |
| 4155 | * @phys_disk_num: | 4161 | * @phys_disk_num: (hot plug) physical disk number (for RAID support) |
| 4156 | * @channel: | 4162 | * @channel: channel number |
| 4157 | * @id: | 4163 | * @id: Logical Target ID |
| 4158 | * | 4164 | * |
| 4159 | **/ | 4165 | **/ |
| 4160 | static struct mptsas_phyinfo * | 4166 | static struct mptsas_phyinfo * |
| @@ -4773,8 +4779,9 @@ mptsas_send_raid_event(struct fw_event_work *fw_event) · 612 unmodified lines | |||
| 4773 | * @lun: Logical unit for reset (if appropriate) | 4779 | * @lun: Logical unit for reset (if appropriate) |
| 4774 | * @task_context: Context for the task to be aborted | 4780 | * @task_context: Context for the task to be aborted |
| 4775 | * @timeout: timeout for task management control | 4781 | * @timeout: timeout for task management control |
| 4782 | * @issue_reset: set to 1 on return if reset is needed, else 0 | ||
| 4776 | * | 4783 | * |
| 4777 | * return 0 on success and -1 on failure: | 4784 | * Return: 0 on success or -1 on failure. |
| 4778 | * | 4785 | * |
| 4779 | */ | 4786 | */ |
| 4780 | static int | 4787 | static int |
| @@ -4847,9 +4854,9 @@ mptsas_issue_tm(MPT_ADAPTER *ioc, u8 type, u8 channel, u8 id, u64 lun, · 66 unmodified lines | |||
| 4847 | 4854 | ||
| 4848 | /** | 4855 | /** |
| 4849 | * mptsas_broadcast_primitive_work - Handle broadcast primitives | 4856 | * mptsas_broadcast_primitive_work - Handle broadcast primitives |
| 4850 | * @work: work queue payload containing info describing the event | 4857 | * @fw_event: work queue payload containing info describing the event |
| 4851 | * | 4858 | * |
| 4852 | * this will be handled in workqueue context. | 4859 | * This will be handled in workqueue context. |
| 4853 | */ | 4860 | */ |
| 4854 | static void | 4861 | static void |
| 4855 | mptsas_broadcast_primitive_work(struct fw_event_work *fw_event) | 4862 | mptsas_broadcast_primitive_work(struct fw_event_work *fw_event) |
| @@ -9,7 +9,7 @@ · 8 unmodified lines | |||
| 9 | #include <uapi/scsi/fc/fc_els.h> | 9 | #include <uapi/scsi/fc/fc_els.h> |
| 10 | #include <linux/delay.h> | 10 | #include <linux/delay.h> |
| 11 | #include <linux/overflow.h> | 11 | #include <linux/overflow.h> |
| 12 | 12 | #include <linux/blk-cgroup.h> | |
| 13 | #include "nvme.h" | 13 | #include "nvme.h" |
| 14 | #include "fabrics.h" | 14 | #include "fabrics.h" |
| 15 | #include <linux/nvme-fc-driver.h> | 15 | #include <linux/nvme-fc-driver.h> |
| @@ -3808,10 +3808,80 @@ process_local_list: · 3792 unmodified lines | |||
| 3808 | 3808 | ||
| 3809 | return count; | 3809 | return count; |
| 3810 | } | 3810 | } |
| 3811 | |||
| 3812 | /* Parse the cgroup id from a buf and return the length of cgrpid */ | ||
| 3813 | static int fc_parse_cgrpid(const char *buf, u64 *id) | ||
| 3814 | { | ||
| 3815 | char cgrp_id[16+1]; | ||
| 3816 | int cgrpid_len, j; | ||
| 3817 | |||
| 3818 | memset(cgrp_id, 0x0, sizeof(cgrp_id)); | ||
| 3819 | for (cgrpid_len = 0, j = 0; cgrpid_len < 17; cgrpid_len++) { | ||
| 3820 | if (buf[cgrpid_len] != ':') | ||
| 3821 | cgrp_id[cgrpid_len] = buf[cgrpid_len]; | ||
| 3822 | else { | ||
| 3823 | j = 1; | ||
| 3824 | break; | ||
| 3825 | } | ||
| 3826 | } | ||
| 3827 | if (!j) | ||
| 3828 | return -EINVAL; | ||
| 3829 | if (kstrtou64(cgrp_id, 16, id) < 0) | ||
| 3830 | return -EINVAL; | ||
| 3831 | return cgrpid_len; | ||
| 3832 | } | ||
| 3833 | |||
| 3834 | /* | ||
| 3835 | * fc_update_appid: Parse and update the appid in the blkcg associated with | ||
| 3836 | * cgroupid. | ||
| 3837 | * @buf: buf contains both cgrpid and appid info | ||
| 3838 | * @count: size of the buffer | ||
| 3839 | */ | ||
| 3840 | static int fc_update_appid(const char *buf, size_t count) | ||
| 3841 | { | ||
| 3842 | u64 cgrp_id; | ||
| 3843 | int appid_len = 0; | ||
| 3844 | int cgrpid_len = 0; | ||
| 3845 | char app_id[FC_APPID_LEN]; | ||
| 3846 | int ret = 0; | ||
| 3847 | |||
| 3848 | if (buf[count-1] == '\n') | ||
| 3849 | count--; | ||
| 3850 | |||
| 3851 | if ((count > (16+1+FC_APPID_LEN)) || (!strchr(buf, ':'))) | ||
| 3852 | return -EINVAL; | ||
| 3853 | |||
| 3854 | cgrpid_len = fc_parse_cgrpid(buf, &cgrp_id); | ||
| 3855 | if (cgrpid_len < 0) | ||
| 3856 | return -EINVAL; | ||
| 3857 | appid_len = count - cgrpid_len - 1; | ||
| 3858 | if (appid_len > FC_APPID_LEN) | ||
| 3859 | return -EINVAL; | ||
| 3860 | |||
| 3861 | memset(app_id, 0x0, sizeof(app_id)); | ||
| 3862 | memcpy(app_id, &buf[cgrpid_len+1], appid_len); | ||
| 3863 | ret = blkcg_set_fc_appid(app_id, cgrp_id, sizeof(app_id)); | ||
| 3864 | if (ret < 0) | ||
| 3865 | return ret; | ||
| 3866 | return count; | ||
| 3867 | } | ||
| 3868 | |||
| 3869 | static ssize_t fc_appid_store(struct device *dev, | ||
| 3870 | struct device_attribute *attr, const char *buf, size_t count) | ||
| 3871 | { | ||
| 3872 | int ret = 0; | ||
| 3873 | |||
| 3874 | ret = fc_update_appid(buf, count); | ||
| 3875 | if (ret < 0) | ||
| 3876 | return -EINVAL; | ||
| 3877 | return count; | ||
| 3878 | } | ||
| 3811 | static DEVICE_ATTR(nvme_discovery, 0200, NULL, nvme_fc_nvme_discovery_store); | 3879 | static DEVICE_ATTR(nvme_discovery, 0200, NULL, nvme_fc_nvme_discovery_store); |
| 3880 | static DEVICE_ATTR(appid_store, 0200, NULL, fc_appid_store); | ||
| 3812 | 3881 | ||
| 3813 | static struct attribute *nvme_fc_attrs[] = { | 3882 | static struct attribute *nvme_fc_attrs[] = { |
| 3814 | &dev_attr_nvme_discovery.attr, | 3883 | &dev_attr_nvme_discovery.attr, |
| 3884 | &dev_attr_appid_store.attr, | ||
| 3815 | NULL | 3885 | NULL |
| 3816 | }; | 3886 | }; |
| 3817 | 3887 | ||
| @@ -856,10 +856,7 @@ void zfcp_scsi_set_prot(struct zfcp_adapter *adapter) · 855 unmodified lines | |||
| 856 | */ | 856 | */ |
| 857 | void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq) | 857 | void zfcp_scsi_dif_sense_error(struct scsi_cmnd *scmd, int ascq) |
| 858 | { | 858 | { |
| 859 | scsi_build_sense_buffer(1, scmd->sense_buffer, | 859 | scsi_build_sense(scmd, 1, ILLEGAL_REQUEST, 0x10, ascq); |
| 860 | ILLEGAL_REQUEST, 0x10, ascq); | ||
| 861 | set_driver_byte(scmd, DRIVER_SENSE); | ||
| 862 | scmd->result |= SAM_STAT_CHECK_CONDITION; | ||
| 863 | set_host_byte(scmd, DID_SOFT_ERROR); | 860 | set_host_byte(scmd, DID_SOFT_ERROR); |
| 864 | } | 861 | } |
| 865 | 862 | ||
| @@ -303,10 +303,10 @@ static int twa_aen_drain_queue(TW_Device_Extension *tw_dev, int no_check_reset) · 302 unmodified lines | |||
| 303 | 303 | ||
| 304 | /* Initialize sglist */ | 304 | /* Initialize sglist */ |
| 305 | memset(&sglist, 0, sizeof(TW_SG_Entry)); | 305 | memset(&sglist, 0, sizeof(TW_SG_Entry)); |
| 306 | sglist[0].length = TW_SECTOR_SIZE; | 306 | sglist[0].length = cpu_to_le32(TW_SECTOR_SIZE); |
| 307 | sglist[0].address = tw_dev->generic_buffer_phys[request_id]; | 307 | sglist[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); |
| 308 | 308 | ||
| 309 | if (sglist[0].address & TW_ALIGNMENT_9000_SGL) { | 309 | if (tw_dev->generic_buffer_phys[request_id] & TW_ALIGNMENT_9000_SGL) { |
| 310 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Found unaligned address during AEN drain"); | 310 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x1, "Found unaligned address during AEN drain"); |
| 311 | goto out; | 311 | goto out; |
| 312 | } | 312 | } |
| @@ -440,8 +440,8 @@ static int twa_aen_read_queue(TW_Device_Extension *tw_dev, int request_id) · 127 unmodified lines | |||
| 440 | 440 | ||
| 441 | /* Initialize sglist */ | 441 | /* Initialize sglist */ |
| 442 | memset(&sglist, 0, sizeof(TW_SG_Entry)); | 442 | memset(&sglist, 0, sizeof(TW_SG_Entry)); |
| 443 | sglist[0].length = TW_SECTOR_SIZE; | 443 | sglist[0].length = cpu_to_le32(TW_SECTOR_SIZE); |
| 444 | sglist[0].address = tw_dev->generic_buffer_phys[request_id]; | 444 | sglist[0].address = TW_CPU_TO_SGL(tw_dev->generic_buffer_phys[request_id]); |
| 445 | 445 | ||
| 446 | /* Mark internal command */ | 446 | /* Mark internal command */ |
| 447 | tw_dev->srb[request_id] = NULL; | 447 | tw_dev->srb[request_id] = NULL; |
| @@ -501,9 +501,8 @@ static void twa_aen_sync_time(TW_Device_Extension *tw_dev, int request_id) · 53 unmodified lines | |||
| 501 | Sunday 12:00AM */ | 501 | Sunday 12:00AM */ |
| 502 | local_time = (ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60)); | 502 | local_time = (ktime_get_real_seconds() - (sys_tz.tz_minuteswest * 60)); |
| 503 | div_u64_rem(local_time - (3 * 86400), 604800, &schedulertime); | 503 | div_u64_rem(local_time - (3 * 86400), 604800, &schedulertime); |
| 504 | schedulertime = cpu_to_le32(schedulertime % 604800); | ||
| 505 | 504 | ||
| 506 | memcpy(param->data, &schedulertime, sizeof(u32)); | 505 | memcpy(param->data, &(__le32){cpu_to_le32(schedulertime)}, sizeof(__le32)); |
| 507 | 506 | ||
| 508 | /* Mark internal command */ | 507 | /* Mark internal command */ |
| 509 | tw_dev->srb[request_id] = NULL; | 508 | tw_dev->srb[request_id] = NULL; |
| @@ -676,7 +675,9 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long · 166 unmodified lines | |||
| 676 | data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511; | 675 | data_buffer_length_adjusted = (driver_command.buffer_length + 511) & ~511; |
| 677 | 676 | ||
| 678 | /* Now allocate ioctl buf memory */ | 677 | /* Now allocate ioctl buf memory */ |
| 679 | cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, &dma_handle, GFP_KERNEL); | 678 | cpu_addr = dma_alloc_coherent(&tw_dev->tw_pci_dev->dev, |
| 679 | sizeof(TW_Ioctl_Buf_Apache) + data_buffer_length_adjusted, | ||
| 680 | &dma_handle, GFP_KERNEL); | ||
| 680 | if (!cpu_addr) { | 681 | if (!cpu_addr) { |
| 681 | retval = TW_IOCTL_ERROR_OS_ENOMEM; | 682 | retval = TW_IOCTL_ERROR_OS_ENOMEM; |
| 682 | goto out2; | 683 | goto out2; |
| @@ -685,7 +686,7 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long · 2 unmodified lines | |||
| 685 | tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr; | 686 | tw_ioctl = (TW_Ioctl_Buf_Apache *)cpu_addr; |
| 686 | 687 | ||
| 687 | /* Now copy down the entire ioctl */ | 688 | /* Now copy down the entire ioctl */ |
| 688 | if (copy_from_user(tw_ioctl, argp, driver_command.buffer_length + sizeof(TW_Ioctl_Buf_Apache) - 1)) | 689 | if (copy_from_user(tw_ioctl, argp, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length)) |
| 689 | goto out3; | 690 | goto out3; |
| 690 | 691 | ||
| 691 | /* See which ioctl we are doing */ | 692 | /* See which ioctl we are doing */ |
| @@ -867,11 +868,13 @@ static long twa_chrdev_ioctl(struct file *file, unsigned int cmd, unsigned long · 175 unmodified lines | |||
| 867 | } | 868 | } |
| 868 | 869 | ||
| 869 | /* Now copy the entire response to userspace */ | 870 | /* Now copy the entire response to userspace */ |
| 870 | if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length - 1) == 0) | 871 | if (copy_to_user(argp, tw_ioctl, sizeof(TW_Ioctl_Buf_Apache) + driver_command.buffer_length) == 0) |
| 871 | retval = 0; | 872 | retval = 0; |
| 872 | out3: | 873 | out3: |
| 873 | /* Now free ioctl buf memory */ | 874 | /* Now free ioctl buf memory */ |
| 874 | dma_free_coherent(&tw_dev->tw_pci_dev->dev, data_buffer_length_adjusted+sizeof(TW_Ioctl_Buf_Apache) - 1, cpu_addr, dma_handle); | 875 | dma_free_coherent(&tw_dev->tw_pci_dev->dev, |
| 876 | sizeof(TW_Ioctl_Buf_Apache) + data_buffer_length_adjusted, | ||
| 877 | cpu_addr, dma_handle); | ||
| 875 | out2: | 878 | out2: |
| 876 | mutex_unlock(&tw_dev->ioctl_lock); | 879 | mutex_unlock(&tw_dev->ioctl_lock); |
| 877 | out: | 880 | out: |
| @@ -1000,19 +1003,13 @@ static int twa_fill_sense(TW_Device_Extension *tw_dev, int request_id, int copy_ · 122 unmodified lines | |||
| 1000 | if (print_host) | 1003 | if (print_host) |
| 1001 | printk(KERN_WARNING "3w-9xxx: scsi%d: ERROR: (0x%02X:0x%04X): %s:%s.\n", | 1004 | printk(KERN_WARNING "3w-9xxx: scsi%d: ERROR: (0x%02X:0x%04X): %s:%s.\n", |
| 1002 | tw_dev->host->host_no, | 1005 | tw_dev->host->host_no, |
| 1003 | TW_MESSAGE_SOURCE_CONTROLLER_ERROR, | 1006 | TW_MESSAGE_SOURCE_CONTROLLER_ERROR, error, |
| 1004 | full_command_packet->header.status_block.error, | 1007 | error_str[0] ? error_str : twa_string_lookup(twa_error_table, error), |
| 1005 | error_str[0] == '\0' ? | ||
| 1006 | twa_string_lookup(twa_error_table, | ||
| 1007 | full_command_packet->header.status_block.error) : error_str, | ||
| 1008 | full_command_packet->header.err_specific_desc); | 1008 | full_command_packet->header.err_specific_desc); |
| 1009 | else | 1009 | else |
| 1010 | printk(KERN_WARNING "3w-9xxx: ERROR: (0x%02X:0x%04X): %s:%s.\n", | 1010 | printk(KERN_WARNING "3w-9xxx: ERROR: (0x%02X:0x%04X): %s:%s.\n", |
| 1011 | TW_MESSAGE_SOURCE_CONTROLLER_ERROR, | 1011 | TW_MESSAGE_SOURCE_CONTROLLER_ERROR, error, |
| 1012 | full_command_packet->header.status_block.error, | 1012 | error_str[0] ? error_str : twa_string_lookup(twa_error_table, error), |
| 1013 | error_str[0] == '\0' ? | ||
| 1014 | twa_string_lookup(twa_error_table, | ||
| 1015 | full_command_packet->header.status_block.error) : error_str, | ||
| 1016 | full_command_packet->header.err_specific_desc); | 1013 | full_command_packet->header.err_specific_desc); |
| 1017 | } | 1014 | } |
| 1018 | 1015 | ||
| @@ -1129,12 +1126,11 @@ static int twa_initconnection(TW_Device_Extension *tw_dev, int message_credits, · 110 unmodified lines | |||
| 1129 | tw_initconnect->opcode__reserved = TW_OPRES_IN(0, TW_OP_INIT_CONNECTION); | 1126 | tw_initconnect->opcode__reserved = TW_OPRES_IN(0, TW_OP_INIT_CONNECTION); |
| 1130 | tw_initconnect->request_id = request_id; | 1127 | tw_initconnect->request_id = request_id; |
| 1131 | tw_initconnect->message_credits = cpu_to_le16(message_credits); | 1128 | tw_initconnect->message_credits = cpu_to_le16(message_credits); |
| 1132 | tw_initconnect->features = set_features; | ||
| 1133 | 1129 | ||
| 1134 | /* Turn on 64-bit sgl support if we need to */ | 1130 | /* Turn on 64-bit sgl support if we need to */ |
| 1135 | tw_initconnect->features |= sizeof(dma_addr_t) > 4 ? 1 : 0; | 1131 | set_features |= sizeof(dma_addr_t) > 4 ? 1 : 0; |
| 1136 | 1132 | ||
| 1137 | tw_initconnect->features = cpu_to_le32(tw_initconnect->features); | 1133 | tw_initconnect->features = cpu_to_le32(set_features); |
| 1138 | 1134 | ||
| 1139 | if (set_features & TW_EXTENDED_INIT_CONNECT) { | 1135 | if (set_features & TW_EXTENDED_INIT_CONNECT) { |
| 1140 | tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE_EXTENDED; | 1136 | tw_initconnect->size = TW_INIT_COMMAND_PACKET_SIZE_EXTENDED; |
| @@ -1342,13 +1338,15 @@ static irqreturn_t twa_interrupt(int irq, void *dev_instance) · 201 unmodified lines | |||
| 1342 | /* If error, command failed */ | 1338 | /* If error, command failed */ |
| 1343 | if (error == 1) { | 1339 | if (error == 1) { |
| 1344 | /* Ask for a host reset */ | 1340 | /* Ask for a host reset */ |
| 1345 | cmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | 1341 | cmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; |
| 1346 | } | 1342 | } |
| 1347 | 1343 | ||
| 1348 | /* Report residual bytes for single sgl */ | 1344 | /* Report residual bytes for single sgl */ |
| 1349 | if ((scsi_sg_count(cmd) <= 1) && (full_command_packet->command.newcommand.status == 0)) { | 1345 | if ((scsi_sg_count(cmd) <= 1) && (full_command_packet->command.newcommand.status == 0)) { |
| 1350 | if (full_command_packet->command.newcommand.sg_list[0].length < scsi_bufflen(tw_dev->srb[request_id])) | 1346 | u32 length = le32_to_cpu(full_command_packet->command.newcommand.sg_list[0].length); |
| 1351 | scsi_set_resid(cmd, scsi_bufflen(cmd) - full_command_packet->command.newcommand.sg_list[0].length); | 1347 | |
| 1348 | if (length < scsi_bufflen(cmd)) | ||
| 1349 | scsi_set_resid(cmd, scsi_bufflen(cmd) - length); | ||
| 1352 | } | 1350 | } |
| 1353 | 1351 | ||
| 1354 | /* Now complete the io */ | 1352 | /* Now complete the io */ |
| @@ -1390,13 +1388,13 @@ static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm · 35 unmodified lines | |||
| 1390 | if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) { | 1388 | if (TW_OP_OUT(full_command_packet->command.newcommand.opcode__reserved) == TW_OP_EXECUTE_SCSI) { |
| 1391 | newcommand = &full_command_packet->command.newcommand; | 1389 | newcommand = &full_command_packet->command.newcommand; |
| 1392 | newcommand->request_id__lunl = | 1390 | newcommand->request_id__lunl = |
| 1393 | cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id)); | 1391 | TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->request_id__lunl), request_id); |
| 1394 | if (length) { | 1392 | if (length) { |
| 1395 | newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1); | 1393 | newcommand->sg_list[0].address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache)); |
| 1396 | newcommand->sg_list[0].length = cpu_to_le32(length); | 1394 | newcommand->sg_list[0].length = cpu_to_le32(length); |
| 1397 | } | 1395 | } |
| 1398 | newcommand->sgl_entries__lunh = | 1396 | newcommand->sgl_entries__lunh = |
| 1399 | cpu_to_le16(TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->sgl_entries__lunh), length ? 1 : 0)); | 1397 | TW_REQ_LUN_IN(TW_LUN_OUT(newcommand->sgl_entries__lunh), length ? 1 : 0); |
| 1400 | } else { | 1398 | } else { |
| 1401 | oldcommand = &full_command_packet->command.oldcommand; | 1399 | oldcommand = &full_command_packet->command.oldcommand; |
| 1402 | oldcommand->request_id = request_id; | 1400 | oldcommand->request_id = request_id; |
| @@ -1407,7 +1405,7 @@ static void twa_load_sgl(TW_Device_Extension *tw_dev, TW_Command_Full *full_comm · 4 unmodified lines | |||
| 1407 | sgl = (TW_SG_Entry *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry)/4) + pae); | 1405 | sgl = (TW_SG_Entry *)((u32 *)oldcommand+oldcommand->size - (sizeof(TW_SG_Entry)/4) + pae); |
| 1408 | else | 1406 | else |
| 1409 | sgl = (TW_SG_Entry *)((u32 *)oldcommand+TW_SGL_OUT(oldcommand->opcode__sgloffset)); | 1407 | sgl = (TW_SG_Entry *)((u32 *)oldcommand+TW_SGL_OUT(oldcommand->opcode__sgloffset)); |
| 1410 | sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache) - 1); | 1408 | sgl->address = TW_CPU_TO_SGL(dma_handle + sizeof(TW_Ioctl_Buf_Apache)); |
| 1411 | sgl->length = cpu_to_le32(length); | 1409 | sgl->length = cpu_to_le32(length); |
| 1412 | 1410 | ||
| 1413 | oldcommand->size += pae; | 1411 | oldcommand->size += pae; |
| @@ -1831,10 +1829,10 @@ static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, · 417 unmodified lines | |||
| 1831 | if (srb) { | 1829 | if (srb) { |
| 1832 | command_packet->unit = srb->device->id; | 1830 | command_packet->unit = srb->device->id; |
| 1833 | command_packet->request_id__lunl = | 1831 | command_packet->request_id__lunl = |
| 1834 | cpu_to_le16(TW_REQ_LUN_IN(srb->device->lun, request_id)); | 1832 | TW_REQ_LUN_IN(srb->device->lun, request_id); |
| 1835 | } else { | 1833 | } else { |
| 1836 | command_packet->request_id__lunl = | 1834 | command_packet->request_id__lunl = |
| 1837 | cpu_to_le16(TW_REQ_LUN_IN(0, request_id)); | 1835 | TW_REQ_LUN_IN(0, request_id); |
| 1838 | command_packet->unit = 0; | 1836 | command_packet->unit = 0; |
| 1839 | } | 1837 | } |
| 1840 | 1838 | ||
| @@ -1866,19 +1864,19 @@ static int twa_scsiop_execute_scsi(TW_Device_Extension *tw_dev, int request_id, · 25 unmodified lines | |||
| 1866 | } | 1864 | } |
| 1867 | } | 1865 | } |
| 1868 | } | 1866 | } |
| 1869 | command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id]))); | 1867 | command_packet->sgl_entries__lunh = TW_REQ_LUN_IN((srb->device->lun >> 4), scsi_sg_count(tw_dev->srb[request_id])); |
| 1870 | } | 1868 | } |
| 1871 | } else { | 1869 | } else { |
| 1872 | /* Internal cdb post */ | 1870 | /* Internal cdb post */ |
| 1873 | for (i = 0; i < use_sg; i++) { | 1871 | for (i = 0; i < use_sg; i++) { |
| 1874 | command_packet->sg_list[i].address = TW_CPU_TO_SGL(sglistarg[i].address); | 1872 | command_packet->sg_list[i].address = sglistarg[i].address; |
| 1875 | command_packet->sg_list[i].length = cpu_to_le32(sglistarg[i].length); | 1873 | command_packet->sg_list[i].length = sglistarg[i].length; |
| 1876 | if (command_packet->sg_list[i].address & TW_CPU_TO_SGL(TW_ALIGNMENT_9000_SGL)) { | 1874 | if (command_packet->sg_list[i].address & TW_CPU_TO_SGL(TW_ALIGNMENT_9000_SGL)) { |
| 1877 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2f, "Found unaligned sgl address during internal post"); | 1875 | TW_PRINTK(tw_dev->host, TW_DRIVER, 0x2f, "Found unaligned sgl address during internal post"); |
| 1878 | goto out; | 1876 | goto out; |
| 1879 | } | 1877 | } |
| 1880 | } | 1878 | } |
| 1881 | command_packet->sgl_entries__lunh = cpu_to_le16(TW_REQ_LUN_IN(0, use_sg)); | 1879 | command_packet->sgl_entries__lunh = TW_REQ_LUN_IN(0, use_sg); |
| 1882 | } | 1880 | } |
| 1883 | 1881 | ||
| 1884 | if (srb) { | 1882 | if (srb) { |
| @@ -2103,7 +2101,7 @@ static int twa_probe(struct pci_dev *pdev, const struct pci_device_id *dev_id) · 218 unmodified lines | |||
| 2103 | TW_PARAM_FWVER, TW_PARAM_FWVER_LENGTH), | 2101 | TW_PARAM_FWVER, TW_PARAM_FWVER_LENGTH), |
| 2104 | (char *)twa_get_param(tw_dev, 1, TW_VERSION_TABLE, | 2102 | (char *)twa_get_param(tw_dev, 1, TW_VERSION_TABLE, |
| 2105 | TW_PARAM_BIOSVER, TW_PARAM_BIOSVER_LENGTH), | 2103 | TW_PARAM_BIOSVER, TW_PARAM_BIOSVER_LENGTH), |
| 2106 | le32_to_cpu(*(int *)twa_get_param(tw_dev, 2, TW_INFORMATION_TABLE, | 2104 | le32_to_cpu(*(__le32 *)twa_get_param(tw_dev, 2, TW_INFORMATION_TABLE, |
| 2107 | TW_PARAM_PORTCOUNT, TW_PARAM_PORTCOUNT_LENGTH))); | 2105 | TW_PARAM_PORTCOUNT, TW_PARAM_PORTCOUNT_LENGTH))); |
| 2108 | 2106 | ||
| 2109 | /* Try to enable MSI */ | 2107 | /* Try to enable MSI */ |
| @@ -50,7 +50,7 @@ · 49 unmodified lines | |||
| 50 | /* AEN string type */ | 50 | /* AEN string type */ |
| 51 | typedef struct TAG_twa_message_type { | 51 | typedef struct TAG_twa_message_type { |
| 52 | unsigned int code; | 52 | unsigned int code; |
| 53 | char* text; | 53 | char *text; |
| 54 | } twa_message_type; | 54 | } twa_message_type; |
| 55 | 55 | ||
| 56 | /* AEN strings */ | 56 | /* AEN strings */ |
| @@ -435,8 +435,8 @@ static twa_message_type twa_error_table[] = { · 378 unmodified lines | |||
| 435 | 435 | ||
| 436 | /* request_id: 12, lun: 4 */ | 436 | /* request_id: 12, lun: 4 */ |
| 437 | #define TW_REQ_LUN_IN(lun, request_id) \ | 437 | #define TW_REQ_LUN_IN(lun, request_id) \ |
| 438 | (((lun << 12) & 0xf000) | (request_id & 0xfff)) | 438 | cpu_to_le16(((lun << 12) & 0xf000) | (request_id & 0xfff)) |
| 439 | #define TW_LUN_OUT(lun) ((lun >> 12) & 0xf) | 439 | #define TW_LUN_OUT(lun) ((le16_to_cpu(lun) >> 12) & 0xf) |
| 440 | 440 | ||
| 441 | /* Macros */ | 441 | /* Macros */ |
| 442 | #define TW_CONTROL_REG_ADDR(x) (x->base_addr) | 442 | #define TW_CONTROL_REG_ADDR(x) (x->base_addr) |
| @@ -483,70 +483,75 @@ printk(KERN_WARNING "3w-9xxx: ERROR: (0x%02X:0x%04X): %s.\n",a,b,c); \ · 40 unmodified lines | |||
| 483 | #define TW_APACHE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 72 : 109) | 483 | #define TW_APACHE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 72 : 109) |
| 484 | #define TW_ESCALADE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 41 : 62) | 484 | #define TW_ESCALADE_MAX_SGL_LENGTH (sizeof(dma_addr_t) > 4 ? 41 : 62) |
| 485 | #define TW_PADDING_LENGTH (sizeof(dma_addr_t) > 4 ? 8 : 0) | 485 | #define TW_PADDING_LENGTH (sizeof(dma_addr_t) > 4 ? 8 : 0) |
| 486 | #define TW_CPU_TO_SGL(x) (sizeof(dma_addr_t) > 4 ? cpu_to_le64(x) : cpu_to_le32(x)) | ||
| 487 | 486 | ||
| 488 | #pragma pack(1) | 487 | #if IS_ENABLED(CONFIG_ARCH_DMA_ADDR_T_64BIT) |
| 488 | typedef __le64 twa_addr_t; | ||
| 489 | #define TW_CPU_TO_SGL(x) cpu_to_le64(x) | ||
| 490 | #else | ||
| 491 | typedef __le32 twa_addr_t; | ||
| 492 | #define TW_CPU_TO_SGL(x) cpu_to_le32(x) | ||
| 493 | #endif | ||
| 489 | 494 | ||
| 490 | /* Scatter Gather List Entry */ | 495 | /* Scatter Gather List Entry */ |
| 491 | typedef struct TAG_TW_SG_Entry { | 496 | typedef struct TAG_TW_SG_Entry { |
| 492 | dma_addr_t address; | 497 | twa_addr_t address; |
| 493 | u32 length; | 498 | __le32 length; |
| 494 | } TW_SG_Entry; | 499 | } __packed TW_SG_Entry; |
| 495 | 500 | ||
| 496 | /* Command Packet */ | 501 | /* Command Packet */ |
| 497 | typedef struct TW_Command { | 502 | typedef struct TW_Command { |
| 498 | unsigned char opcode__sgloffset; | 503 | u8 opcode__sgloffset; |
| 499 | unsigned char size; | 504 | u8 size; |
| 500 | unsigned char request_id; | 505 | u8 request_id; |
| 501 | unsigned char unit__hostid; | 506 | u8 unit__hostid; |
| 502 | /* Second DWORD */ | 507 | /* Second DWORD */ |
| 503 | unsigned char status; | 508 | u8 status; |
| 504 | unsigned char flags; | 509 | u8 flags; |
| 505 | union { | 510 | union { |
| 506 | unsigned short block_count; | 511 | __le16 block_count; |
| 507 | unsigned short parameter_count; | 512 | __le16 parameter_count; |
| 508 | } byte6_offset; | 513 | } byte6_offset; |
| 509 | union { | 514 | union { |
| 510 | struct { | 515 | struct { |
| 511 | u32 lba; | 516 | __le32 lba; |
| 512 | TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH]; | 517 | TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH]; |
| 513 | dma_addr_t padding; | 518 | twa_addr_t padding; |
| 514 | } io; | 519 | } io; |
| 515 | struct { | 520 | struct { |
| 516 | TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH]; | 521 | TW_SG_Entry sgl[TW_ESCALADE_MAX_SGL_LENGTH]; |
| 517 | u32 padding; | 522 | __le32 padding; |
| 518 | dma_addr_t padding2; | 523 | twa_addr_t padding2; |
| 519 | } param; | 524 | } param; |
| 520 | } byte8_offset; | 525 | } byte8_offset; |
| 521 | } TW_Command; | 526 | } TW_Command; |
| 522 | 527 | ||
| 523 | /* Command Packet for 9000+ controllers */ | 528 | /* Command Packet for 9000+ controllers */ |
| 524 | typedef struct TAG_TW_Command_Apache { | 529 | typedef struct TAG_TW_Command_Apache { |
| 525 | unsigned char opcode__reserved; | 530 | u8 opcode__reserved; |
| 526 | unsigned char unit; | 531 | u8 unit; |
| 527 | unsigned short request_id__lunl; | 532 | __le16 request_id__lunl; |
| 528 | unsigned char status; | 533 | u8 status; |
| 529 | unsigned char sgl_offset; | 534 | u8 sgl_offset; |
| 530 | unsigned short sgl_entries__lunh; | 535 | __le16 sgl_entries__lunh; |
| 531 | unsigned char cdb[16]; | 536 | u8 cdb[16]; |
| 532 | TW_SG_Entry sg_list[TW_APACHE_MAX_SGL_LENGTH]; | 537 | TW_SG_Entry sg_list[TW_APACHE_MAX_SGL_LENGTH]; |
| 533 | unsigned char padding[TW_PADDING_LENGTH]; | 538 | u8 padding[TW_PADDING_LENGTH]; |
| 534 | } TW_Command_Apache; | 539 | } TW_Command_Apache; |
| 535 | 540 | ||
| 536 | /* New command packet header */ | 541 | /* New command packet header */ |
| 537 | typedef struct TAG_TW_Command_Apache_Header { | 542 | typedef struct TAG_TW_Command_Apache_Header { |
| 538 | unsigned char sense_data[TW_SENSE_DATA_LENGTH]; | 543 | unsigned char sense_data[TW_SENSE_DATA_LENGTH]; |
| 539 | struct { | 544 | struct { |
| 540 | char reserved[4]; | 545 | u8 reserved[4]; |
| 541 | unsigned short error; | 546 | __le16 error; |
| 542 | unsigned char padding; | 547 | u8 padding; |
| 543 | unsigned char severity__reserved; | 548 | u8 severity__reserved; |
| 544 | } status_block; | 549 | } status_block; |
| 545 | unsigned char err_specific_desc[98]; | 550 | unsigned char err_specific_desc[98]; |
| 546 | struct { | 551 | struct { |
| 547 | unsigned char size_header; | 552 | u8 size_header; |
| 548 | unsigned short reserved; | 553 | u8 reserved[2]; |
| 549 | unsigned char size_sense; | 554 | u8 size_sense; |
| 550 | } header_desc; | 555 | } header_desc; |
| 551 | } TW_Command_Apache_Header; | 556 | } TW_Command_Apache_Header; |
| 552 | 557 | ||
| @@ -561,19 +566,19 @@ typedef struct TAG_TW_Command_Full { · 8 unmodified lines | |||
| 561 | 566 | ||
| 562 | /* Initconnection structure */ | 567 | /* Initconnection structure */ |
| 563 | typedef struct TAG_TW_Initconnect { | 568 | typedef struct TAG_TW_Initconnect { |
| 564 | unsigned char opcode__reserved; | 569 | u8 opcode__reserved; |
| 565 | unsigned char size; | 570 | u8 size; |
| 566 | unsigned char request_id; | 571 | u8 request_id; |
| 567 | unsigned char res2; | 572 | u8 res2; |
| 568 | unsigned char status; | 573 | u8 status; |
| 569 | unsigned char flags; | 574 | u8 flags; |
| 570 | unsigned short message_credits; | 575 | __le16 message_credits; |
| 571 | u32 features; | 576 | __le32 features; |
| 572 | unsigned short fw_srl; | 577 | __le16 fw_srl; |
| 573 | unsigned short fw_arch_id; | 578 | __le16 fw_arch_id; |
| 574 | unsigned short fw_branch; | 579 | __le16 fw_branch; |
| 575 | unsigned short fw_build; | 580 | __le16 fw_build; |
| 576 | u32 result; | 581 | __le32 result; |
| 577 | } TW_Initconnect; | 582 | } TW_Initconnect; |
| 578 | 583 | ||
| 579 | /* Event info structure */ | 584 | /* Event info structure */ |
| @@ -602,7 +607,7 @@ typedef struct TAG_TW_Ioctl_Apache { · 22 unmodified lines | |||
| 602 | TW_Ioctl_Driver_Command driver_command; | 607 | TW_Ioctl_Driver_Command driver_command; |
| 603 | char padding[488]; | 608 | char padding[488]; |
| 604 | TW_Command_Full firmware_command; | 609 | TW_Command_Full firmware_command; |
| 605 | char data_buffer[1]; | 610 | char data_buffer[]; |
| 606 | } TW_Ioctl_Buf_Apache; | 611 | } TW_Ioctl_Buf_Apache; |
| 607 | 612 | ||
| 608 | /* Lock structure for ioctl get/release lock */ | 613 | /* Lock structure for ioctl get/release lock */ |
| @@ -614,11 +619,11 @@ typedef struct TAG_TW_Lock { · 5 unmodified lines | |||
| 614 | 619 | ||
| 615 | /* GetParam descriptor */ | 620 | /* GetParam descriptor */ |
| 616 | typedef struct { | 621 | typedef struct { |
| 617 | unsigned short table_id; | 622 | __le16 table_id; |
| 618 | unsigned short parameter_id; | 623 | __le16 parameter_id; |
| 619 | unsigned short parameter_size_bytes; | 624 | __le16 parameter_size_bytes; |
| 620 | unsigned short actual_parameter_size_bytes; | 625 | __le16 actual_parameter_size_bytes; |
| 621 | unsigned char data[1]; | 626 | u8 data[]; |
| 622 | } TW_Param_Apache, *PTW_Param_Apache; | 627 | } TW_Param_Apache, *PTW_Param_Apache; |
| 623 | 628 | ||
| 624 | /* Response queue */ | 629 | /* Response queue */ |
| @@ -645,8 +650,6 @@ typedef struct TAG_TW_Compatibility_Info · 20 unmodified lines | |||
| 645 | unsigned short fw_on_ctlr_build; | 650 | unsigned short fw_on_ctlr_build; |
| 646 | } TW_Compatibility_Info; | 651 | } TW_Compatibility_Info; |
| 647 | 652 | ||
| 648 | #pragma pack() | ||
| 649 | |||
| 650 | typedef struct TAG_TW_Device_Extension { | 653 | typedef struct TAG_TW_Device_Extension { |
| 651 | u32 __iomem *base_addr; | 654 | u32 __iomem *base_addr; |
| 652 | unsigned long *generic_buffer_virt[TW_Q_LENGTH]; | 655 | unsigned long *generic_buffer_virt[TW_Q_LENGTH]; |
| @@ -429,7 +429,7 @@ static int tw_decode_sense(TW_Device_Extension *tw_dev, int request_id, int fill · 428 unmodified lines | |||
| 429 | /* Additional sense code qualifier */ | 429 | /* Additional sense code qualifier */ |
| 430 | tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3]; | 430 | tw_dev->srb[request_id]->sense_buffer[13] = tw_sense_table[i][3]; |
| 431 | 431 | ||
| 432 | tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | 432 | tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; |
| 433 | return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */ | 433 | return TW_ISR_DONT_RESULT; /* Special case for isr to not over-write result */ |
| 434 | } | 434 | } |
| 435 | } | 435 | } |
| @@ -1977,7 +1977,7 @@ static int tw_scsi_queue_lck(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_c · 1541 unmodified lines | |||
| 1977 | printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command); | 1977 | printk(KERN_NOTICE "3w-xxxx: scsi%d: Unknown scsi opcode: 0x%x\n", tw_dev->host->host_no, *command); |
| 1978 | tw_dev->state[request_id] = TW_S_COMPLETED; | 1978 | tw_dev->state[request_id] = TW_S_COMPLETED; |
| 1979 | tw_state_request_finish(tw_dev, request_id); | 1979 | tw_state_request_finish(tw_dev, request_id); |
| 1980 | scsi_build_sense_buffer(1, SCpnt->sense_buffer, ILLEGAL_REQUEST, 0x20, 0); | 1980 | scsi_build_sense(SCpnt, 1, ILLEGAL_REQUEST, 0x20, 0); |
| 1981 | done(SCpnt); | 1981 | done(SCpnt); |
| 1982 | retval = 0; | 1982 | retval = 0; |
| 1983 | } | 1983 | } |
| @@ -2159,7 +2159,7 @@ static irqreturn_t tw_interrupt(int irq, void *dev_instance) · 175 unmodified lines | |||
| 2159 | /* If error, command failed */ | 2159 | /* If error, command failed */ |
| 2160 | if (error == 1) { | 2160 | if (error == 1) { |
| 2161 | /* Ask for a host reset */ | 2161 | /* Ask for a host reset */ |
| 2162 | tw_dev->srb[request_id]->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | 2162 | tw_dev->srb[request_id]->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; |
| 2163 | } | 2163 | } |
| 2164 | 2164 | ||
| 2165 | /* Now complete the io */ | 2165 | /* Now complete the io */ |
| @@ -978,10 +978,10 @@ process_script_interrupt(__u32 dsps, __u32 dsp, struct scsi_cmnd *SCp, · 977 unmodified lines | |||
| 978 | if (NCR_700_get_tag_neg_state(SCp->device) == NCR_700_DURING_TAG_NEGOTIATION) | 978 | if (NCR_700_get_tag_neg_state(SCp->device) == NCR_700_DURING_TAG_NEGOTIATION) |
| 979 | NCR_700_set_tag_neg_state(SCp->device, | 979 | NCR_700_set_tag_neg_state(SCp->device, |
| 980 | NCR_700_FINISHED_TAG_NEGOTIATION); | 980 | NCR_700_FINISHED_TAG_NEGOTIATION); |
| 981 | 981 | ||
| 982 | /* check for contingent allegiance conditions */ | 982 | /* check for contingent allegiance conditions */ |
| 983 | if (hostdata->status[0] >> 1 == CHECK_CONDITION || | 983 | if (hostdata->status[0] == SAM_STAT_CHECK_CONDITION || |
| 984 | hostdata->status[0] >> 1 == COMMAND_TERMINATED) { | 984 | hostdata->status[0] == SAM_STAT_COMMAND_TERMINATED) { |
| 985 | struct NCR_700_command_slot *slot = | 985 | struct NCR_700_command_slot *slot = |
| 986 | (struct NCR_700_command_slot *)SCp->host_scribble; | 986 | (struct NCR_700_command_slot *)SCp->host_scribble; |
| 987 | if(slot->flags == NCR_700_FLAG_AUTOSENSE) { | 987 | if(slot->flags == NCR_700_FLAG_AUTOSENSE) { |
| @@ -40,7 +40,7 @@ struct sccb_mgr_info { · 39 unmodified lines | |||
| 40 | u16 si_per_targ_ultra_nego; | 40 | u16 si_per_targ_ultra_nego; |
| 41 | u16 si_per_targ_no_disc; | 41 | u16 si_per_targ_no_disc; |
| 42 | u16 si_per_targ_wide_nego; | 42 | u16 si_per_targ_wide_nego; |
| 43 | u16 si_flags; | 43 | u16 si_mflags; |
| 44 | unsigned char si_card_family; | 44 | unsigned char si_card_family; |
| 45 | unsigned char si_bustype; | 45 | unsigned char si_bustype; |
| 46 | unsigned char si_card_model[3]; | 46 | unsigned char si_card_model[3]; |
| @@ -304,40 +304,12 @@ typedef struct SCCBscam_info { · 257 unmodified lines | |||
| 304 | 304 | ||
| 305 | } SCCBSCAM_INFO; | 305 | } SCCBSCAM_INFO; |
| 306 | 306 | ||
| 307 | #define SCSI_REQUEST_SENSE 0x03 | ||
| 308 | #define SCSI_READ 0x08 | ||
| 309 | #define SCSI_WRITE 0x0A | ||
| 310 | #define SCSI_START_STOP_UNIT 0x1B | ||
| 311 | #define SCSI_READ_EXTENDED 0x28 | ||
| 312 | #define SCSI_WRITE_EXTENDED 0x2A | ||
| 313 | #define SCSI_WRITE_AND_VERIFY 0x2E | ||
| 314 | |||
| 315 | #define SSGOOD 0x00 | ||
| 316 | #define SSCHECK 0x02 | ||
| 317 | #define SSQ_FULL 0x28 | ||
| 318 | |||
| 319 | #define SMCMD_COMP 0x00 | ||
| 320 | #define SMEXT 0x01 | ||
| 321 | #define SMSAVE_DATA_PTR 0x02 | ||
| 322 | #define SMREST_DATA_PTR 0x03 | ||
| 323 | #define SMDISC 0x04 | ||
| 324 | #define SMABORT 0x06 | ||
| 325 | #define SMREJECT 0x07 | ||
| 326 | #define SMNO_OP 0x08 | ||
| 327 | #define SMPARITY 0x09 | ||
| 328 | #define SMDEV_RESET 0x0C | ||
| 329 | #define SMABORT_TAG 0x0D | ||
| 330 | #define SMINIT_RECOVERY 0x0F | ||
| 331 | #define SMREL_RECOVERY 0x10 | ||
| 332 | 307 | ||
| 333 | #define SMIDENT 0x80 | 308 | #define SMIDENT 0x80 |
| 334 | #define DISC_PRIV 0x40 | 309 | #define DISC_PRIV 0x40 |
| 335 | 310 | ||
| 336 | #define SMSYNC 0x01 | ||
| 337 | #define SMWDTR 0x03 | ||
| 338 | #define SM8BIT 0x00 | 311 | #define SM8BIT 0x00 |
| 339 | #define SM16BIT 0x01 | 312 | #define SM16BIT 0x01 |
| 340 | #define SMIGNORWR 0x23 /* Ignore Wide Residue */ | ||
| 341 | 313 | ||
| 342 | #define SIX_BYTE_CMD 0x06 | 314 | #define SIX_BYTE_CMD 0x06 |
| 343 | #define TWELVE_BYTE_CMD 0x0C | 315 | #define TWELVE_BYTE_CMD 0x0C |
| @@ -1073,22 +1045,22 @@ static int FlashPoint_ProbeHostAdapter(struct sccb_mgr_info *pCardInfo) · 729 unmodified lines | |||
| 1073 | ScamFlg = | 1045 | ScamFlg = |
| 1074 | (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2); | 1046 | (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2); |
| 1075 | 1047 | ||
| 1076 | pCardInfo->si_flags = 0x0000; | 1048 | pCardInfo->si_mflags = 0x0000; |
| 1077 | 1049 | ||
| 1078 | if (i & 0x01) | 1050 | if (i & 0x01) |
| 1079 | pCardInfo->si_flags |= SCSI_PARITY_ENA; | 1051 | pCardInfo->si_mflags |= SCSI_PARITY_ENA; |
| 1080 | 1052 | ||
| 1081 | if (!(i & 0x02)) | 1053 | if (!(i & 0x02)) |
| 1082 | pCardInfo->si_flags |= SOFT_RESET; | 1054 | pCardInfo->si_mflags |= SOFT_RESET; |
| 1083 | 1055 | ||
| 1084 | if (i & 0x10) | 1056 | if (i & 0x10) |
| 1085 | pCardInfo->si_flags |= EXTENDED_TRANSLATION; | 1057 | pCardInfo->si_mflags |= EXTENDED_TRANSLATION; |
| 1086 | 1058 | ||
| 1087 | if (ScamFlg & SCAM_ENABLED) | 1059 | if (ScamFlg & SCAM_ENABLED) |
| 1088 | pCardInfo->si_flags |= FLAG_SCAM_ENABLED; | 1060 | pCardInfo->si_mflags |= FLAG_SCAM_ENABLED; |
| 1089 | 1061 | ||
| 1090 | if (ScamFlg & SCAM_LEVEL2) | 1062 | if (ScamFlg & SCAM_LEVEL2) |
| 1091 | pCardInfo->si_flags |= FLAG_SCAM_LEVEL2; | 1063 | pCardInfo->si_mflags |= FLAG_SCAM_LEVEL2; |
| 1092 | 1064 | ||
| 1093 | j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L); | 1065 | j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L); |
| 1094 | if (i & 0x04) { | 1066 | if (i & 0x04) { |
| @@ -1104,7 +1076,7 @@ static int FlashPoint_ProbeHostAdapter(struct sccb_mgr_info *pCardInfo) · 9 unmodified lines | |||
| 1104 | 1076 | ||
| 1105 | if (!(RD_HARPOON(ioport + hp_page_ctrl) & NARROW_SCSI_CARD)) | 1077 | if (!(RD_HARPOON(ioport + hp_page_ctrl) & NARROW_SCSI_CARD)) |
| 1106 | 1078 | ||
| 1107 | pCardInfo->si_flags |= SUPPORT_16TAR_32LUN; | 1079 | pCardInfo->si_mflags |= SUPPORT_16TAR_32LUN; |
| 1108 | 1080 | ||
| 1109 | pCardInfo->si_card_family = HARPOON_FAMILY; | 1081 | pCardInfo->si_card_family = HARPOON_FAMILY; |
| 1110 | pCardInfo->si_bustype = BUSTYPE_PCI; | 1082 | pCardInfo->si_bustype = BUSTYPE_PCI; |
| @@ -1140,15 +1112,15 @@ static int FlashPoint_ProbeHostAdapter(struct sccb_mgr_info *pCardInfo) · 29 unmodified lines | |||
| 1140 | 1112 | ||
| 1141 | if (pCardInfo->si_card_model[1] == '3') { | 1113 | if (pCardInfo->si_card_model[1] == '3') { |
| 1142 | if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)) | 1114 | if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)) |
| 1143 | pCardInfo->si_flags |= LOW_BYTE_TERM; | 1115 | pCardInfo->si_mflags |= LOW_BYTE_TERM; |
| 1144 | } else if (pCardInfo->si_card_model[2] == '0') { | 1116 | } else if (pCardInfo->si_card_model[2] == '0') { |
| 1145 | temp = RD_HARPOON(ioport + hp_xfer_pad); | 1117 | temp = RD_HARPOON(ioport + hp_xfer_pad); |
| 1146 | WR_HARPOON(ioport + hp_xfer_pad, (temp & ~BIT(4))); | 1118 | WR_HARPOON(ioport + hp_xfer_pad, (temp & ~BIT(4))); |
| 1147 | if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)) | 1119 | if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)) |
| 1148 | pCardInfo->si_flags |= LOW_BYTE_TERM; | 1120 | pCardInfo->si_mflags |= LOW_BYTE_TERM; |
| 1149 | WR_HARPOON(ioport + hp_xfer_pad, (temp | BIT(4))); | 1121 | WR_HARPOON(ioport + hp_xfer_pad, (temp | BIT(4))); |
| 1150 | if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)) | 1122 | if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)) |
| 1151 | pCardInfo->si_flags |= HIGH_BYTE_TERM; | 1123 | pCardInfo->si_mflags |= HIGH_BYTE_TERM; |
| 1152 | WR_HARPOON(ioport + hp_xfer_pad, temp); | 1124 | WR_HARPOON(ioport + hp_xfer_pad, temp); |
| 1153 | } else { | 1125 | } else { |
| 1154 | temp = RD_HARPOON(ioport + hp_ee_ctrl); | 1126 | temp = RD_HARPOON(ioport + hp_ee_ctrl); |
| @@ -1166,9 +1138,9 @@ static int FlashPoint_ProbeHostAdapter(struct sccb_mgr_info *pCardInfo) · 11 unmodified lines | |||
| 1166 | WR_HARPOON(ioport + hp_ee_ctrl, temp); | 1138 | WR_HARPOON(ioport + hp_ee_ctrl, temp); |
| 1167 | WR_HARPOON(ioport + hp_xfer_pad, temp2); | 1139 | WR_HARPOON(ioport + hp_xfer_pad, temp2); |
| 1168 | if (!(temp3 & BIT(7))) | 1140 | if (!(temp3 & BIT(7))) |
| 1169 | pCardInfo->si_flags |= LOW_BYTE_TERM; | 1141 | pCardInfo->si_mflags |= LOW_BYTE_TERM; |
| 1170 | if (!(temp3 & BIT(6))) | 1142 | if (!(temp3 & BIT(6))) |
| 1171 | pCardInfo->si_flags |= HIGH_BYTE_TERM; | 1143 | pCardInfo->si_mflags |= HIGH_BYTE_TERM; |
| 1172 | } | 1144 | } |
| 1173 | 1145 | ||
| 1174 | ARAM_ACCESS(ioport); | 1146 | ARAM_ACCESS(ioport); |
| @@ -1275,7 +1247,7 @@ static void *FlashPoint_HardwareResetHostAdapter(struct sccb_mgr_info · 100 unmodified lines | |||
| 1275 | WR_HARPOON(ioport + hp_arb_id, pCardInfo->si_id); | 1247 | WR_HARPOON(ioport + hp_arb_id, pCardInfo->si_id); |
| 1276 | CurrCard->ourId = pCardInfo->si_id; | 1248 | CurrCard->ourId = pCardInfo->si_id; |
| 1277 | 1249 | ||
| 1278 | i = (unsigned char)pCardInfo->si_flags; | 1250 | i = (unsigned char)pCardInfo->si_mflags; |
| 1279 | if (i & SCSI_PARITY_ENA) | 1251 | if (i & SCSI_PARITY_ENA) |
| 1280 | WR_HARPOON(ioport + hp_portctrl_1, (HOST_MODE8 | CHK_SCSI_P)); | 1252 | WR_HARPOON(ioport + hp_portctrl_1, (HOST_MODE8 | CHK_SCSI_P)); |
| 1281 | 1253 | ||
| @@ -1289,14 +1261,14 @@ static void *FlashPoint_HardwareResetHostAdapter(struct sccb_mgr_info · 7 unmodified lines | |||
| 1289 | j |= SCSI_TERM_ENA_H; | 1261 | j |= SCSI_TERM_ENA_H; |
| 1290 | WR_HARPOON(ioport + hp_ee_ctrl, j); | 1262 | WR_HARPOON(ioport + hp_ee_ctrl, j); |
| 1291 | 1263 | ||
| 1292 | if (!(pCardInfo->si_flags & SOFT_RESET)) { | 1264 | if (!(pCardInfo->si_mflags & SOFT_RESET)) { |
| 1293 | 1265 | ||
| 1294 | FPT_sresb(ioport, thisCard); | 1266 | FPT_sresb(ioport, thisCard); |
| 1295 | 1267 | ||
| 1296 | FPT_scini(thisCard, pCardInfo->si_id, 0); | 1268 | FPT_scini(thisCard, pCardInfo->si_id, 0); |
| 1297 | } | 1269 | } |
| 1298 | 1270 | ||
| 1299 | if (pCardInfo->si_flags & POST_ALL_UNDERRRUNS) | 1271 | if (pCardInfo->si_mflags & POST_ALL_UNDERRRUNS) |
| 1300 | CurrCard->globalFlags |= F_NO_FILTER; | 1272 | CurrCard->globalFlags |= F_NO_FILTER; |
| 1301 | 1273 | ||
| 1302 | if (pCurrNvRam) { | 1274 | if (pCurrNvRam) { |
| @@ -1660,7 +1632,7 @@ static int FlashPoint_AbortCCB(void *pCurrCard, struct sccb *p_Sccb) · 357 unmodified lines | |||
| 1660 | p_Sccb->Sccb_scsistat = | 1632 | p_Sccb->Sccb_scsistat = |
| 1661 | ABORT_ST; | 1633 | ABORT_ST; |
| 1662 | p_Sccb->Sccb_scsimsg = | 1634 | p_Sccb->Sccb_scsimsg = |
| 1663 | SMABORT_TAG; | 1635 | ABORT_TASK; |
| 1664 | 1636 | ||
| 1665 | if (((struct sccb_card *) | 1637 | if (((struct sccb_card *) |
| 1666 | pCurrCard)->currentSCCB == | 1638 | pCurrCard)->currentSCCB == |
| @@ -1812,7 +1784,7 @@ static int FlashPoint_HandleInterrupt(void *pcard) · 145 unmodified lines | |||
| 1812 | FPT_phaseChkFifo(ioport, thisCard); | 1784 | FPT_phaseChkFifo(ioport, thisCard); |
| 1813 | 1785 | ||
| 1814 | if (RD_HARPOON(ioport + hp_gp_reg_1) == | 1786 | if (RD_HARPOON(ioport + hp_gp_reg_1) == |
| 1815 | SMSAVE_DATA_PTR) { | 1787 | SAVE_POINTERS) { |
| 1816 | 1788 | ||
| 1817 | WR_HARPOON(ioport + hp_gp_reg_1, 0x00); | 1789 | WR_HARPOON(ioport + hp_gp_reg_1, 0x00); |
| 1818 | currSCCB->Sccb_XferState |= F_NO_DATA_YET; | 1790 | currSCCB->Sccb_XferState |= F_NO_DATA_YET; |
| @@ -1865,7 +1837,7 @@ static int FlashPoint_HandleInterrupt(void *pcard) · 46 unmodified lines | |||
| 1865 | FPT_phaseChkFifo(ioport, thisCard); | 1837 | FPT_phaseChkFifo(ioport, thisCard); |
| 1866 | 1838 | ||
| 1867 | if (RD_HARPOON(ioport + hp_gp_reg_1) == | 1839 | if (RD_HARPOON(ioport + hp_gp_reg_1) == |
| 1868 | SMSAVE_DATA_PTR) { | 1840 | SAVE_POINTERS) { |
| 1869 | WR_HARPOON(ioport + hp_gp_reg_1, 0x00); | 1841 | WR_HARPOON(ioport + hp_gp_reg_1, 0x00); |
| 1870 | currSCCB->Sccb_XferState |= | 1842 | currSCCB->Sccb_XferState |= |
| 1871 | F_NO_DATA_YET; | 1843 | F_NO_DATA_YET; |
| @@ -2258,7 +2230,7 @@ static unsigned char FPT_sfm(u32 port, struct sccb *pCurrSCCB) · 386 unmodified lines | |||
| 2258 | WR_HARPOON(port + hp_fiforead, 0); | 2230 | WR_HARPOON(port + hp_fiforead, 0); |
| 2259 | WR_HARPOON(port + hp_fifowrite, 0); | 2231 | WR_HARPOON(port + hp_fifowrite, 0); |
| 2260 | if (pCurrSCCB != NULL) { | 2232 | if (pCurrSCCB != NULL) { |
| 2261 | pCurrSCCB->Sccb_scsimsg = SMPARITY; | 2233 | pCurrSCCB->Sccb_scsimsg = MSG_PARITY_ERROR; |
| 2262 | } | 2234 | } |
| 2263 | message = 0x00; | 2235 | message = 0x00; |
| 2264 | do { | 2236 | do { |
| @@ -2411,7 +2383,7 @@ static void FPT_ssel(u32 port, unsigned char p_card) · 146 unmodified lines | |||
| 2411 | 2383 | ||
| 2412 | WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + NP); | 2384 | WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + NP); |
| 2413 | 2385 | ||
| 2414 | currSCCB->Sccb_scsimsg = SMDEV_RESET; | 2386 | currSCCB->Sccb_scsimsg = TARGET_RESET; |
| 2415 | 2387 | ||
| 2416 | WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT)); | 2388 | WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT)); |
| 2417 | auto_loaded = 1; | 2389 | auto_loaded = 1; |
| @@ -2758,9 +2730,9 @@ static void FPT_sres(u32 port, unsigned char p_card, · 340 unmodified lines | |||
| 2758 | if (message == 0) { | 2730 | if (message == 0) { |
| 2759 | msgRetryCount++; | 2731 | msgRetryCount++; |
| 2760 | if (msgRetryCount == 1) { | 2732 | if (msgRetryCount == 1) { |
| 2761 | FPT_SendMsg(port, SMPARITY); | 2733 | FPT_SendMsg(port, MSG_PARITY_ERROR); |
| 2762 | } else { | 2734 | } else { |
| 2763 | FPT_SendMsg(port, SMDEV_RESET); | 2735 | FPT_SendMsg(port, TARGET_RESET); |
| 2764 | 2736 | ||
| 2765 | FPT_sssyncv(port, our_target, NARROW_SCSI, | 2737 | FPT_sssyncv(port, our_target, NARROW_SCSI, |
| 2766 | currTar_Info); | 2738 | currTar_Info); |
| @@ -2860,8 +2832,8 @@ static void FPT_SendMsg(u32 port, unsigned char message) · 93 unmodified lines | |||
| 2860 | 2832 | ||
| 2861 | WR_HARPOON(port + hp_portctrl_0, 0x00); | 2833 | WR_HARPOON(port + hp_portctrl_0, 0x00); |
| 2862 | 2834 | ||
| 2863 | if ((message == SMABORT) || (message == SMDEV_RESET) || | 2835 | if ((message == ABORT_TASK_SET) || (message == TARGET_RESET) || |
| 2864 | (message == SMABORT_TAG)) { | 2836 | (message == ABORT_TASK)) { |
| 2865 | while (! | 2837 | while (! |
| 2866 | (RDW_HARPOON((port + hp_intstat)) & | 2838 | (RDW_HARPOON((port + hp_intstat)) & |
| 2867 | (BUS_FREE | PHASE))) { | 2839 | (BUS_FREE | PHASE))) { |
| @@ -2893,7 +2865,7 @@ static void FPT_sdecm(unsigned char message, u32 port, unsigned char p_card) · 25 unmodified lines | |||
| 2893 | 2865 | ||
| 2894 | currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID]; | 2866 | currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID]; |
| 2895 | 2867 | ||
| 2896 | if (message == SMREST_DATA_PTR) { | 2868 | if (message == RESTORE_POINTERS) { |
| 2897 | if (!(currSCCB->Sccb_XferState & F_NO_DATA_YET)) { | 2869 | if (!(currSCCB->Sccb_XferState & F_NO_DATA_YET)) { |
| 2898 | currSCCB->Sccb_ATC = currSCCB->Sccb_savedATC; | 2870 | currSCCB->Sccb_ATC = currSCCB->Sccb_savedATC; |
| 2899 | 2871 | ||
| @@ -2905,7 +2877,7 @@ static void FPT_sdecm(unsigned char message, u32 port, unsigned char p_card) · 5 unmodified lines | |||
| 2905 | (AUTO_IMMED + DISCONNECT_START)); | 2877 | (AUTO_IMMED + DISCONNECT_START)); |
| 2906 | } | 2878 | } |
| 2907 | 2879 | ||
| 2908 | else if (message == SMCMD_COMP) { | 2880 | else if (message == COMMAND_COMPLETE) { |
| 2909 | 2881 | ||
| 2910 | if (currSCCB->Sccb_scsistat == SELECT_Q_ST) { | 2882 | if (currSCCB->Sccb_scsistat == SELECT_Q_ST) { |
| 2911 | currTar_Info->TarStatus &= | 2883 | currTar_Info->TarStatus &= |
| @@ -2917,15 +2889,16 @@ static void FPT_sdecm(unsigned char message, u32 port, unsigned char p_card) · 5 unmodified lines | |||
| 2917 | 2889 | ||
| 2918 | } | 2890 | } |
| 2919 | 2891 | ||
| 2920 | else if ((message == SMNO_OP) || (message >= SMIDENT) | 2892 | else if ((message == NOP) || (message >= IDENTIFY_BASE) || |
| 2921 | || (message == SMINIT_RECOVERY) || (message == SMREL_RECOVERY)) { | 2893 | (message == INITIATE_RECOVERY) || |
| 2894 | (message == RELEASE_RECOVERY)) { | ||
| 2922 | 2895 | ||
| 2923 | ACCEPT_MSG(port); | 2896 | ACCEPT_MSG(port); |
| 2924 | WR_HARPOON(port + hp_autostart_1, | 2897 | WR_HARPOON(port + hp_autostart_1, |
| 2925 | (AUTO_IMMED + DISCONNECT_START)); | 2898 | (AUTO_IMMED + DISCONNECT_START)); |
| 2926 | } | 2899 | } |
| 2927 | 2900 | ||
| 2928 | else if (message == SMREJECT) { | 2901 | else if (message == MESSAGE_REJECT) { |
| 2929 | 2902 | ||
| 2930 | if ((currSCCB->Sccb_scsistat == SELECT_SN_ST) || | 2903 | if ((currSCCB->Sccb_scsistat == SELECT_SN_ST) || |
| 2931 | (currSCCB->Sccb_scsistat == SELECT_WN_ST) || | 2904 | (currSCCB->Sccb_scsistat == SELECT_WN_ST) || |
| @@ -3026,19 +2999,19 @@ static void FPT_sdecm(unsigned char message, u32 port, unsigned char p_card) · 94 unmodified lines | |||
| 3026 | } | 2999 | } |
| 3027 | } | 3000 | } |
| 3028 | 3001 | ||
| 3029 | else if (message == SMEXT) { | 3002 | else if (message == EXTENDED_MESSAGE) { |
| 3030 | 3003 | ||
| 3031 | ACCEPT_MSG(port); | 3004 | ACCEPT_MSG(port); |
| 3032 | FPT_shandem(port, p_card, currSCCB); | 3005 | FPT_shandem(port, p_card, currSCCB); |
| 3033 | } | 3006 | } |
| 3034 | 3007 | ||
| 3035 | else if (message == SMIGNORWR) { | 3008 | else if (message == IGNORE_WIDE_RESIDUE) { |
| 3036 | 3009 | ||
| 3037 | ACCEPT_MSG(port); /* ACK the RESIDUE MSG */ | 3010 | ACCEPT_MSG(port); /* ACK the RESIDUE MSG */ |
| 3038 | 3011 | ||
| 3039 | message = FPT_sfm(port, currSCCB); | 3012 | message = FPT_sfm(port, currSCCB); |
| 3040 | 3013 | ||
| 3041 | if (currSCCB->Sccb_scsimsg != SMPARITY) | 3014 | if (currSCCB->Sccb_scsimsg != MSG_PARITY_ERROR) |
| 3042 | ACCEPT_MSG(port); | 3015 | ACCEPT_MSG(port); |
| 3043 | WR_HARPOON(port + hp_autostart_1, | 3016 | WR_HARPOON(port + hp_autostart_1, |
| 3044 | (AUTO_IMMED + DISCONNECT_START)); | 3017 | (AUTO_IMMED + DISCONNECT_START)); |
| @@ -3047,7 +3020,7 @@ static void FPT_sdecm(unsigned char message, u32 port, unsigned char p_card) · 2 unmodified lines | |||
| 3047 | else { | 3020 | else { |
| 3048 | 3021 | ||
| 3049 | currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL; | 3022 | currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL; |
| 3050 | currSCCB->Sccb_scsimsg = SMREJECT; | 3023 | currSCCB->Sccb_scsimsg = MESSAGE_REJECT; |
| 3051 | 3024 | ||
| 3052 | ACCEPT_MSG_ATN(port); | 3025 | ACCEPT_MSG_ATN(port); |
| 3053 | WR_HARPOON(port + hp_autostart_1, | 3026 | WR_HARPOON(port + hp_autostart_1, |
| @@ -3073,7 +3046,7 @@ static void FPT_shandem(u32 port, unsigned char p_card, struct sccb *pCurrSCCB) · 19 unmodified lines | |||
| 3073 | message = FPT_sfm(port, pCurrSCCB); | 3046 | message = FPT_sfm(port, pCurrSCCB); |
| 3074 | if (message) { | 3047 | if (message) { |
| 3075 | 3048 | ||
| 3076 | if (message == SMSYNC) { | 3049 | if (message == EXTENDED_SDTR) { |
| 3077 | 3050 | ||
| 3078 | if (length == 0x03) { | 3051 | if (length == 0x03) { |
| 3079 | 3052 | ||
| @@ -3081,10 +3054,10 @@ static void FPT_shandem(u32 port, unsigned char p_card, struct sccb *pCurrSCCB) · 1 unmodified line | |||
| 3081 | FPT_stsyncn(port, p_card); | 3054 | FPT_stsyncn(port, p_card); |
| 3082 | } else { | 3055 | } else { |
| 3083 | 3056 | ||
| 3084 | pCurrSCCB->Sccb_scsimsg = SMREJECT; | 3057 | pCurrSCCB->Sccb_scsimsg = MESSAGE_REJECT; |
| 3085 | ACCEPT_MSG_ATN(port); | 3058 | ACCEPT_MSG_ATN(port); |
| 3086 | } | 3059 | } |
| 3087 | } else if (message == SMWDTR) { | 3060 | } else if (message == EXTENDED_WDTR) { |
| 3088 | 3061 | ||
| 3089 | if (length == 0x02) { | 3062 | if (length == 0x02) { |
| 3090 | 3063 | ||
| @@ -3092,7 +3065,7 @@ static void FPT_shandem(u32 port, unsigned char p_card, struct sccb *pCurrSCCB) · 1 unmodified line | |||
| 3092 | FPT_stwidn(port, p_card); | 3065 | FPT_stwidn(port, p_card); |
| 3093 | } else { | 3066 | } else { |
| 3094 | 3067 | ||
| 3095 | pCurrSCCB->Sccb_scsimsg = SMREJECT; | 3068 | pCurrSCCB->Sccb_scsimsg = MESSAGE_REJECT; |
| 3096 | ACCEPT_MSG_ATN(port); | 3069 | ACCEPT_MSG_ATN(port); |
| 3097 | 3070 | ||
| 3098 | WR_HARPOON(port + hp_autostart_1, | 3071 | WR_HARPOON(port + hp_autostart_1, |
| @@ -3101,20 +3074,20 @@ static void FPT_shandem(u32 port, unsigned char p_card, struct sccb *pCurrSCCB) · 2 unmodified lines | |||
| 3101 | } | 3074 | } |
| 3102 | } else { | 3075 | } else { |
| 3103 | 3076 | ||
| 3104 | pCurrSCCB->Sccb_scsimsg = SMREJECT; | 3077 | pCurrSCCB->Sccb_scsimsg = MESSAGE_REJECT; |
| 3105 | ACCEPT_MSG_ATN(port); | 3078 | ACCEPT_MSG_ATN(port); |
| 3106 | 3079 | ||
| 3107 | WR_HARPOON(port + hp_autostart_1, | 3080 | WR_HARPOON(port + hp_autostart_1, |
| 3108 | (AUTO_IMMED + DISCONNECT_START)); | 3081 | (AUTO_IMMED + DISCONNECT_START)); |
| 3109 | } | 3082 | } |
| 3110 | } else { | 3083 | } else { |
| 3111 | if (pCurrSCCB->Sccb_scsimsg != SMPARITY) | 3084 | if (pCurrSCCB->Sccb_scsimsg != MSG_PARITY_ERROR) |
| 3112 | ACCEPT_MSG(port); | 3085 | ACCEPT_MSG(port); |
| 3113 | WR_HARPOON(port + hp_autostart_1, | 3086 | WR_HARPOON(port + hp_autostart_1, |
| 3114 | (AUTO_IMMED + DISCONNECT_START)); | 3087 | (AUTO_IMMED + DISCONNECT_START)); |
| 3115 | } | 3088 | } |
| 3116 | } else { | 3089 | } else { |
| 3117 | if (pCurrSCCB->Sccb_scsimsg == SMPARITY) | 3090 | if (pCurrSCCB->Sccb_scsimsg == MSG_PARITY_ERROR) |
| 3118 | WR_HARPOON(port + hp_autostart_1, | 3091 | WR_HARPOON(port + hp_autostart_1, |
| 3119 | (AUTO_IMMED + DISCONNECT_START)); | 3092 | (AUTO_IMMED + DISCONNECT_START)); |
| 3120 | } | 3093 | } |
| @@ -3148,10 +3121,10 @@ static unsigned char FPT_sisyncn(u32 port, unsigned char p_card, · 27 unmodified lines | |||
| 3148 | WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ); | 3121 | WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ); |
| 3149 | 3122 | ||
| 3150 | WRW_HARPOON((port + SYNC_MSGS + 0), | 3123 | WRW_HARPOON((port + SYNC_MSGS + 0), |
| 3151 | (MPM_OP + AMSG_OUT + SMEXT)); | 3124 | (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE)); |
| 3152 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03)); | 3125 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03)); |
| 3153 | WRW_HARPOON((port + SYNC_MSGS + 4), | 3126 | WRW_HARPOON((port + SYNC_MSGS + 4), |
| 3154 | (MPM_OP + AMSG_OUT + SMSYNC)); | 3127 | (MPM_OP + AMSG_OUT + EXTENDED_SDTR)); |
| 3155 | 3128 | ||
| 3156 | if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB) | 3129 | if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB) |
| 3157 | 3130 | ||
| @@ -3221,7 +3194,7 @@ static void FPT_stsyncn(u32 port, unsigned char p_card) · 63 unmodified lines | |||
| 3221 | 3194 | ||
| 3222 | sync_msg = FPT_sfm(port, currSCCB); | 3195 | sync_msg = FPT_sfm(port, currSCCB); |
| 3223 | 3196 | ||
| 3224 | if ((sync_msg == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) { | 3197 | if ((sync_msg == 0x00) && (currSCCB->Sccb_scsimsg == MSG_PARITY_ERROR)) { |
| 3225 | WR_HARPOON(port + hp_autostart_1, | 3198 | WR_HARPOON(port + hp_autostart_1, |
| 3226 | (AUTO_IMMED + DISCONNECT_START)); | 3199 | (AUTO_IMMED + DISCONNECT_START)); |
| 3227 | return; | 3200 | return; |
| @@ -3231,7 +3204,7 @@ static void FPT_stsyncn(u32 port, unsigned char p_card) · 3 unmodified lines | |||
| 3231 | 3204 | ||
| 3232 | offset = FPT_sfm(port, currSCCB); | 3205 | offset = FPT_sfm(port, currSCCB); |
| 3233 | 3206 | ||
| 3234 | if ((offset == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) { | 3207 | if ((offset == 0x00) && (currSCCB->Sccb_scsimsg == MSG_PARITY_ERROR)) { |
| 3235 | WR_HARPOON(port + hp_autostart_1, | 3208 | WR_HARPOON(port + hp_autostart_1, |
| 3236 | (AUTO_IMMED + DISCONNECT_START)); | 3209 | (AUTO_IMMED + DISCONNECT_START)); |
| 3237 | return; | 3210 | return; |
| @@ -3343,9 +3316,11 @@ static void FPT_sisyncr(u32 port, unsigned char sync_pulse, · 105 unmodified lines | |||
| 3343 | unsigned char offset) | 3316 | unsigned char offset) |
| 3344 | { | 3317 | { |
| 3345 | ARAM_ACCESS(port); | 3318 | ARAM_ACCESS(port); |
| 3346 | WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT + SMEXT)); | 3319 | WRW_HARPOON((port + SYNC_MSGS + 0), |
| 3320 | (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE)); | ||
| 3347 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03)); | 3321 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03)); |
| 3348 | WRW_HARPOON((port + SYNC_MSGS + 4), (MPM_OP + AMSG_OUT + SMSYNC)); | 3322 | WRW_HARPOON((port + SYNC_MSGS + 4), |
| 3323 | (MPM_OP + AMSG_OUT + EXTENDED_SDTR)); | ||
| 3349 | WRW_HARPOON((port + SYNC_MSGS + 6), (MPM_OP + AMSG_OUT + sync_pulse)); | 3324 | WRW_HARPOON((port + SYNC_MSGS + 6), (MPM_OP + AMSG_OUT + sync_pulse)); |
| 3350 | WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP)); | 3325 | WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP)); |
| 3351 | WRW_HARPOON((port + SYNC_MSGS + 10), (MPM_OP + AMSG_OUT + offset)); | 3326 | WRW_HARPOON((port + SYNC_MSGS + 10), (MPM_OP + AMSG_OUT + offset)); |
| @@ -3388,10 +3363,10 @@ static unsigned char FPT_siwidn(u32 port, unsigned char p_card) · 36 unmodified lines | |||
| 3388 | WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ); | 3363 | WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ); |
| 3389 | 3364 | ||
| 3390 | WRW_HARPOON((port + SYNC_MSGS + 0), | 3365 | WRW_HARPOON((port + SYNC_MSGS + 0), |
| 3391 | (MPM_OP + AMSG_OUT + SMEXT)); | 3366 | (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE)); |
| 3392 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02)); | 3367 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02)); |
| 3393 | WRW_HARPOON((port + SYNC_MSGS + 4), | 3368 | WRW_HARPOON((port + SYNC_MSGS + 4), |
| 3394 | (MPM_OP + AMSG_OUT + SMWDTR)); | 3369 | (MPM_OP + AMSG_OUT + EXTENDED_WDTR)); |
| 3395 | WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP)); | 3370 | WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP)); |
| 3396 | WRW_HARPOON((port + SYNC_MSGS + 8), | 3371 | WRW_HARPOON((port + SYNC_MSGS + 8), |
| 3397 | (MPM_OP + AMSG_OUT + SM16BIT)); | 3372 | (MPM_OP + AMSG_OUT + SM16BIT)); |
| @@ -3436,7 +3411,7 @@ static void FPT_stwidn(u32 port, unsigned char p_card) · 38 unmodified lines | |||
| 3436 | 3411 | ||
| 3437 | width = FPT_sfm(port, currSCCB); | 3412 | width = FPT_sfm(port, currSCCB); |
| 3438 | 3413 | ||
| 3439 | if ((width == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) { | 3414 | if ((width == 0x00) && (currSCCB->Sccb_scsimsg == MSG_PARITY_ERROR)) { |
| 3440 | WR_HARPOON(port + hp_autostart_1, | 3415 | WR_HARPOON(port + hp_autostart_1, |
| 3441 | (AUTO_IMMED + DISCONNECT_START)); | 3416 | (AUTO_IMMED + DISCONNECT_START)); |
| 3442 | return; | 3417 | return; |
| @@ -3499,9 +3474,11 @@ static void FPT_stwidn(u32 port, unsigned char p_card) · 56 unmodified lines | |||
| 3499 | static void FPT_siwidr(u32 port, unsigned char width) | 3474 | static void FPT_siwidr(u32 port, unsigned char width) |
| 3500 | { | 3475 | { |
| 3501 | ARAM_ACCESS(port); | 3476 | ARAM_ACCESS(port); |
| 3502 | WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT + SMEXT)); | 3477 | WRW_HARPOON((port + SYNC_MSGS + 0), |
| 3478 | (MPM_OP + AMSG_OUT + EXTENDED_MESSAGE)); | ||
| 3503 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02)); | 3479 | WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02)); |
| 3504 | WRW_HARPOON((port + SYNC_MSGS + 4), (MPM_OP + AMSG_OUT + SMWDTR)); | 3480 | WRW_HARPOON((port + SYNC_MSGS + 4), |
| 3481 | (MPM_OP + AMSG_OUT + EXTENDED_WDTR)); | ||
| 3505 | WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP)); | 3482 | WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP)); |
| 3506 | WRW_HARPOON((port + SYNC_MSGS + 8), (MPM_OP + AMSG_OUT + width)); | 3483 | WRW_HARPOON((port + SYNC_MSGS + 8), (MPM_OP + AMSG_OUT + width)); |
| 3507 | WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP)); | 3484 | WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP)); |
| @@ -3682,7 +3659,7 @@ static void FPT_ssenss(struct sccb_card *pCurrCard) · 174 unmodified lines | |||
| 3682 | } | 3659 | } |
| 3683 | 3660 | ||
| 3684 | currSCCB->CdbLength = SIX_BYTE_CMD; | 3661 | currSCCB->CdbLength = SIX_BYTE_CMD; |
| 3685 | currSCCB->Cdb[0] = SCSI_REQUEST_SENSE; | 3662 | currSCCB->Cdb[0] = REQUEST_SENSE; |
| 3686 | currSCCB->Cdb[1] = currSCCB->Cdb[1] & (unsigned char)0xE0; /*Keep LUN. */ | 3663 | currSCCB->Cdb[1] = currSCCB->Cdb[1] & (unsigned char)0xE0; /*Keep LUN. */ |
| 3687 | currSCCB->Cdb[2] = 0x00; | 3664 | currSCCB->Cdb[2] = 0x00; |
| 3688 | currSCCB->Cdb[3] = 0x00; | 3665 | currSCCB->Cdb[3] = 0x00; |
| @@ -3939,13 +3916,9 @@ static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card) · 250 unmodified lines | |||
| 3939 | */ | 3916 | */ |
| 3940 | if ((currTar_Info->TarStatus & TAR_ALLOW_DISC) || | 3917 | if ((currTar_Info->TarStatus & TAR_ALLOW_DISC) || |
| 3941 | (currTar_Info->TarStatus & TAG_Q_TRYING)) { | 3918 | (currTar_Info->TarStatus & TAG_Q_TRYING)) { |
| 3942 | p_sccb->Sccb_idmsg = | 3919 | p_sccb->Sccb_idmsg = IDENTIFY(true, p_sccb->Lun); |
| 3943 | (unsigned char)(SMIDENT | DISC_PRIV) | p_sccb->Lun; | 3920 | } else { |
| 3944 | } | 3921 | p_sccb->Sccb_idmsg = IDENTIFY(false, p_sccb->Lun); |
| 3945 | |||
| 3946 | else { | ||
| 3947 | |||
| 3948 | p_sccb->Sccb_idmsg = (unsigned char)SMIDENT | p_sccb->Lun; | ||
| 3949 | } | 3922 | } |
| 3950 | 3923 | ||
| 3951 | p_sccb->HostStatus = 0x00; | 3924 | p_sccb->HostStatus = 0x00; |
| @@ -3962,7 +3935,7 @@ static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card) · 10 unmodified lines | |||
| 3962 | */ | 3935 | */ |
| 3963 | p_sccb->Sccb_scsistat = BUS_FREE_ST; | 3936 | p_sccb->Sccb_scsistat = BUS_FREE_ST; |
| 3964 | p_sccb->SccbStatus = SCCB_IN_PROCESS; | 3937 | p_sccb->SccbStatus = SCCB_IN_PROCESS; |
| 3965 | p_sccb->Sccb_scsimsg = SMNO_OP; | 3938 | p_sccb->Sccb_scsimsg = NOP; |
| 3966 | 3939 | ||
| 3967 | } | 3940 | } |
| 3968 | 3941 | ||
| @@ -4167,7 +4140,7 @@ static void FPT_phaseMsgOut(u32 port, unsigned char p_card) · 198 unmodified lines | |||
| 4167 | message = currSCCB->Sccb_scsimsg; | 4140 | message = currSCCB->Sccb_scsimsg; |
| 4168 | scsiID = currSCCB->TargID; | 4141 | scsiID = currSCCB->TargID; |
| 4169 | 4142 | ||
| 4170 | if (message == SMDEV_RESET) { | 4143 | if (message == TARGET_RESET) { |
| 4171 | 4144 | ||
| 4172 | currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID]; | 4145 | currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID]; |
| 4173 | currTar_Info->TarSyncCtrl = 0; | 4146 | currTar_Info->TarSyncCtrl = 0; |
| @@ -4203,7 +4176,7 @@ static void FPT_phaseMsgOut(u32 port, unsigned char p_card) · 29 unmodified lines | |||
| 4203 | 4176 | ||
| 4204 | else if (currSCCB->Sccb_scsistat < COMMAND_ST) { | 4177 | else if (currSCCB->Sccb_scsistat < COMMAND_ST) { |
| 4205 | 4178 | ||
| 4206 | if (message == SMNO_OP) { | 4179 | if (message == NOP) { |
| 4207 | currSCCB->Sccb_MGRFlags |= F_DEV_SELECTED; | 4180 | currSCCB->Sccb_MGRFlags |= F_DEV_SELECTED; |
| 4208 | 4181 | ||
| 4209 | FPT_ssel(port, p_card); | 4182 | FPT_ssel(port, p_card); |
| @@ -4211,13 +4184,13 @@ static void FPT_phaseMsgOut(u32 port, unsigned char p_card) · 1 unmodified line | |||
| 4211 | } | 4184 | } |
| 4212 | } else { | 4185 | } else { |
| 4213 | 4186 | ||
| 4214 | if (message == SMABORT) | 4187 | if (message == ABORT_TASK_SET) |
| 4215 | 4188 | ||
| 4216 | FPT_queueFlushSccb(p_card, SCCB_COMPLETE); | 4189 | FPT_queueFlushSccb(p_card, SCCB_COMPLETE); |
| 4217 | } | 4190 | } |
| 4218 | 4191 | ||
| 4219 | } else { | 4192 | } else { |
| 4220 | message = SMABORT; | 4193 | message = ABORT_TASK_SET; |
| 4221 | } | 4194 | } |
| 4222 | 4195 | ||
| 4223 | WRW_HARPOON((port + hp_intstat), (BUS_FREE | PHASE | XFER_CNT_0)); | 4196 | WRW_HARPOON((port + hp_intstat), (BUS_FREE | PHASE | XFER_CNT_0)); |
| @@ -4232,8 +4205,8 @@ static void FPT_phaseMsgOut(u32 port, unsigned char p_card) · 8 unmodified lines | |||
| 4232 | 4205 | ||
| 4233 | WR_HARPOON(port + hp_portctrl_0, 0x00); | 4206 | WR_HARPOON(port + hp_portctrl_0, 0x00); |
| 4234 | 4207 | ||
| 4235 | if ((message == SMABORT) || (message == SMDEV_RESET) || | 4208 | if ((message == ABORT_TASK_SET) || (message == TARGET_RESET) || |
| 4236 | (message == SMABORT_TAG)) { | 4209 | (message == ABORT_TASK)) { |
| 4237 | 4210 | ||
| 4238 | while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | PHASE))) { | 4211 | while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | PHASE))) { |
| 4239 | } | 4212 | } |
| @@ -4275,8 +4248,8 @@ static void FPT_phaseMsgOut(u32 port, unsigned char p_card) · 35 unmodified lines | |||
| 4275 | 4248 | ||
| 4276 | else { | 4249 | else { |
| 4277 | 4250 | ||
| 4278 | if (message == SMPARITY) { | 4251 | if (message == MSG_PARITY_ERROR) { |
| 4279 | currSCCB->Sccb_scsimsg = SMNO_OP; | 4252 | currSCCB->Sccb_scsimsg = NOP; |
| 4280 | WR_HARPOON(port + hp_autostart_1, | 4253 | WR_HARPOON(port + hp_autostart_1, |
| 4281 | (AUTO_IMMED + DISCONNECT_START)); | 4254 | (AUTO_IMMED + DISCONNECT_START)); |
| 4282 | } else { | 4255 | } else { |
| @@ -4306,7 +4279,7 @@ static void FPT_phaseMsgIn(u32 port, unsigned char p_card) · 23 unmodified lines | |||
| 4306 | } | 4279 | } |
| 4307 | 4280 | ||
| 4308 | message = RD_HARPOON(port + hp_scsidata_0); | 4281 | message = RD_HARPOON(port + hp_scsidata_0); |
| 4309 | if ((message == SMDISC) || (message == SMSAVE_DATA_PTR)) { | 4282 | if ((message == DISCONNECT) || (message == SAVE_POINTERS)) { |
| 4310 | 4283 | ||
| 4311 | WR_HARPOON(port + hp_autostart_1, | 4284 | WR_HARPOON(port + hp_autostart_1, |
| 4312 | (AUTO_IMMED + END_DATA_START)); | 4285 | (AUTO_IMMED + END_DATA_START)); |
| @@ -4321,7 +4294,7 @@ static void FPT_phaseMsgIn(u32 port, unsigned char p_card) · 8 unmodified lines | |||
| 4321 | FPT_sdecm(message, port, p_card); | 4294 | FPT_sdecm(message, port, p_card); |
| 4322 | 4295 | ||
| 4323 | } else { | 4296 | } else { |
| 4324 | if (currSCCB->Sccb_scsimsg != SMPARITY) | 4297 | if (currSCCB->Sccb_scsimsg != MSG_PARITY_ERROR) |
| 4325 | ACCEPT_MSG(port); | 4298 | ACCEPT_MSG(port); |
| 4326 | WR_HARPOON(port + hp_autostart_1, | 4299 | WR_HARPOON(port + hp_autostart_1, |
| 4327 | (AUTO_IMMED + DISCONNECT_START)); | 4300 | (AUTO_IMMED + DISCONNECT_START)); |
| @@ -4351,7 +4324,7 @@ static void FPT_phaseIllegal(u32 port, unsigned char p_card) · 23 unmodified lines | |||
| 4351 | 4324 | ||
| 4352 | currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL; | 4325 | currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL; |
| 4353 | currSCCB->Sccb_scsistat = ABORT_ST; | 4326 | currSCCB->Sccb_scsistat = ABORT_ST; |
| 4354 | currSCCB->Sccb_scsimsg = SMABORT; | 4327 | currSCCB->Sccb_scsimsg = ABORT_TASK_SET; |
| 4355 | } | 4328 | } |
| 4356 | 4329 | ||
| 4357 | ACCEPT_MSG_ATN(port); | 4330 | ACCEPT_MSG_ATN(port); |
| @@ -4650,9 +4623,9 @@ static void FPT_autoCmdCmplt(u32 p_port, unsigned char p_card) · 292 unmodified lines | |||
| 4650 | 4623 | ||
| 4651 | FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA = 0; | 4624 | FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA = 0; |
| 4652 | 4625 | ||
| 4653 | if (status_byte != SSGOOD) { | 4626 | if (status_byte != SAM_STAT_GOOD) { |
| 4654 | 4627 | ||
| 4655 | if (status_byte == SSQ_FULL) { | 4628 | if (status_byte == SAM_STAT_TASK_SET_FULL) { |
| 4656 | 4629 | ||
| 4657 | if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) && | 4630 | if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) && |
| 4658 | ((FPT_sccbMgrTbl[p_card][currSCCB->TargID]. | 4631 | ((FPT_sccbMgrTbl[p_card][currSCCB->TargID]. |
| @@ -4784,7 +4757,7 @@ static void FPT_autoCmdCmplt(u32 p_port, unsigned char p_card) · 125 unmodified lines | |||
| 4784 | 4757 | ||
| 4785 | } | 4758 | } |
| 4786 | 4759 | ||
| 4787 | if (status_byte == SSCHECK) { | 4760 | if (status_byte == SAM_STAT_CHECK_CONDITION) { |
| 4788 | if (FPT_BL_Card[p_card].globalFlags & F_DO_RENEGO) { | 4761 | if (FPT_BL_Card[p_card].globalFlags & F_DO_RENEGO) { |
| 4789 | if (FPT_sccbMgrTbl[p_card][currSCCB->TargID]. | 4762 | if (FPT_sccbMgrTbl[p_card][currSCCB->TargID]. |
| 4790 | TarEEValue & EE_SYNC_MASK) { | 4763 | TarEEValue & EE_SYNC_MASK) { |
| @@ -4806,7 +4779,7 @@ static void FPT_autoCmdCmplt(u32 p_port, unsigned char p_card) · 15 unmodified lines | |||
| 4806 | currSCCB->SccbStatus = SCCB_ERROR; | 4779 | currSCCB->SccbStatus = SCCB_ERROR; |
| 4807 | currSCCB->TargetStatus = status_byte; | 4780 | currSCCB->TargetStatus = status_byte; |
| 4808 | 4781 | ||
| 4809 | if (status_byte == SSCHECK) { | 4782 | if (status_byte == SAM_STAT_CHECK_CONDITION) { |
| 4810 | 4783 | ||
| 4811 | FPT_sccbMgrTbl[p_card][currSCCB->TargID]. | 4784 | FPT_sccbMgrTbl[p_card][currSCCB->TargID]. |
| 4812 | TarLUN_CA = 1; | 4785 | TarLUN_CA = 1; |
| @@ -6868,14 +6841,14 @@ static void FPT_queueCmdComplete(struct sccb_card *pCurrCard, · 2055 unmodified lines | |||
| 6868 | if ((p_sccb-> | 6841 | if ((p_sccb-> |
| 6869 | ControlByte & (SCCB_DATA_XFER_OUT | SCCB_DATA_XFER_IN)) | 6842 | ControlByte & (SCCB_DATA_XFER_OUT | SCCB_DATA_XFER_IN)) |
| 6870 | && (p_sccb->HostStatus == SCCB_COMPLETE) | 6843 | && (p_sccb->HostStatus == SCCB_COMPLETE) |
| 6871 | && (p_sccb->TargetStatus != SSCHECK)) | 6844 | && (p_sccb->TargetStatus != SAM_STAT_CHECK_CONDITION)) |
| 6872 | 6845 | ||
| 6873 | if ((SCSIcmd == SCSI_READ) || | 6846 | if ((SCSIcmd == READ_6) || |
| 6874 | (SCSIcmd == SCSI_WRITE) || | 6847 | (SCSIcmd == WRITE_6) || |
| 6875 | (SCSIcmd == SCSI_READ_EXTENDED) || | 6848 | (SCSIcmd == READ_10) || |
| 6876 | (SCSIcmd == SCSI_WRITE_EXTENDED) || | 6849 | (SCSIcmd == WRITE_10) || |
| 6877 | (SCSIcmd == SCSI_WRITE_AND_VERIFY) || | 6850 | (SCSIcmd == WRITE_VERIFY) || |
| 6878 | (SCSIcmd == SCSI_START_STOP_UNIT) || | 6851 | (SCSIcmd == START_STOP) || |
| 6879 | (pCurrCard->globalFlags & F_NO_FILTER) | 6852 | (pCurrCard->globalFlags & F_NO_FILTER) |
| 6880 | ) | 6853 | ) |
| 6881 | p_sccb->HostStatus = SCCB_DATA_UNDER_RUN; | 6854 | p_sccb->HostStatus = SCCB_DATA_UNDER_RUN; |
| @@ -235,6 +235,19 @@ config SCSI_FC_ATTRS · 234 unmodified lines | |||
| 235 | each attached FiberChannel device to sysfs, say Y. | 235 | each attached FiberChannel device to sysfs, say Y. |
| 236 | Otherwise, say N. | 236 | Otherwise, say N. |
| 237 | 237 | ||
| 238 | config FC_APPID | ||
| 239 | bool "Enable support to track FC I/O Traffic" | ||
| 240 | depends on BLOCK && BLK_CGROUP | ||
| 241 | depends on SCSI | ||
| 242 | select BLK_CGROUP_FC_APPID | ||
| 243 | default y | ||
| 244 | help | ||
| 245 | If you say Y here, it enables the support to track | ||
| 246 | FC I/O traffic over fabric. It enables the Fabric and the | ||
| 247 | storage targets to identify, monitor, and handle FC traffic | ||
| 248 | based on VM tags by inserting application specific | ||
| 249 | identification into the FC frame. | ||
| 250 | |||
| 238 | config SCSI_ISCSI_ATTRS | 251 | config SCSI_ISCSI_ATTRS |
| 239 | tristate "iSCSI Transport Attributes" | 252 | tristate "iSCSI Transport Attributes" |
| 240 | depends on SCSI && NET | 253 | depends on SCSI && NET |
| @@ -311,7 +324,7 @@ source "drivers/scsi/cxlflash/Kconfig" · 70 unmodified lines | |||
| 311 | config SGIWD93_SCSI | 324 | config SGIWD93_SCSI |
| 312 | tristate "SGI WD93C93 SCSI Driver" | 325 | tristate "SGI WD93C93 SCSI Driver" |
| 313 | depends on SGI_HAS_WD93 && SCSI | 326 | depends on SGI_HAS_WD93 && SCSI |
| 314 | help | 327 | help |
| 315 | If you have a Western Digital WD93 SCSI controller on | 328 | If you have a Western Digital WD93 SCSI controller on |
| 316 | an SGI MIPS system, say Y. Otherwise, say N. | 329 | an SGI MIPS system, say Y. Otherwise, say N. |
| 317 | 330 | ||
| @@ -482,6 +495,7 @@ config SCSI_ARCMSR · 164 unmodified lines | |||
| 482 | source "drivers/scsi/esas2r/Kconfig" | 495 | source "drivers/scsi/esas2r/Kconfig" |
| 483 | source "drivers/scsi/megaraid/Kconfig.megaraid" | 496 | source "drivers/scsi/megaraid/Kconfig.megaraid" |
| 484 | source "drivers/scsi/mpt3sas/Kconfig" | 497 | source "drivers/scsi/mpt3sas/Kconfig" |
| 498 | source "drivers/scsi/mpi3mr/Kconfig" | ||
| 485 | source "drivers/scsi/smartpqi/Kconfig" | 499 | source "drivers/scsi/smartpqi/Kconfig" |
| 486 | source "drivers/scsi/ufs/Kconfig" | 500 | source "drivers/scsi/ufs/Kconfig" |
| 487 | 501 | ||
| @@ -1157,6 +1171,8 @@ config SCSI_LPFC_DEBUG_FS · 669 unmodified lines | |||
| 1157 | This makes debugging information from the lpfc driver | 1171 | This makes debugging information from the lpfc driver |
| 1158 | available via the debugfs filesystem. | 1172 | available via the debugfs filesystem. |
| 1159 | 1173 | ||
| 1174 | source "drivers/scsi/elx/Kconfig" | ||
| 1175 | |||
| 1160 | config SCSI_SIM710 | 1176 | config SCSI_SIM710 |
| 1161 | tristate "Simple 53c710 SCSI support (Compaq, NCR machines)" | 1177 | tristate "Simple 53c710 SCSI support (Compaq, NCR machines)" |
| 1162 | depends on EISA && SCSI | 1178 | depends on EISA && SCSI |
| @@ -85,6 +85,7 @@ obj-$(CONFIG_SCSI_QLOGIC_1280) += qla1280.o · 84 unmodified lines | |||
| 85 | obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx/ | 85 | obj-$(CONFIG_SCSI_QLA_FC) += qla2xxx/ |
| 86 | obj-$(CONFIG_SCSI_QLA_ISCSI) += libiscsi.o qla4xxx/ | 86 | obj-$(CONFIG_SCSI_QLA_ISCSI) += libiscsi.o qla4xxx/ |
| 87 | obj-$(CONFIG_SCSI_LPFC) += lpfc/ | 87 | obj-$(CONFIG_SCSI_LPFC) += lpfc/ |
| 88 | obj-$(CONFIG_SCSI_EFCT) += elx/ | ||
| 88 | obj-$(CONFIG_SCSI_BFA_FC) += bfa/ | 89 | obj-$(CONFIG_SCSI_BFA_FC) += bfa/ |
| 89 | obj-$(CONFIG_SCSI_CHELSIO_FCOE) += csiostor/ | 90 | obj-$(CONFIG_SCSI_CHELSIO_FCOE) += csiostor/ |
| 90 | obj-$(CONFIG_SCSI_DMX3191D) += dmx3191d.o | 91 | obj-$(CONFIG_SCSI_DMX3191D) += dmx3191d.o |
| @@ -99,6 +100,7 @@ obj-$(CONFIG_MEGARAID_LEGACY) += megaraid.o · 8 unmodified lines | |||
| 99 | obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ | 100 | obj-$(CONFIG_MEGARAID_NEWGEN) += megaraid/ |
| 100 | obj-$(CONFIG_MEGARAID_SAS) += megaraid/ | 101 | obj-$(CONFIG_MEGARAID_SAS) += megaraid/ |
| 101 | obj-$(CONFIG_SCSI_MPT3SAS) += mpt3sas/ | 102 | obj-$(CONFIG_SCSI_MPT3SAS) += mpt3sas/ |
| 103 | obj-$(CONFIG_SCSI_MPI3MR) += mpi3mr/ | ||
| 102 | obj-$(CONFIG_SCSI_UFSHCD) += ufs/ | 104 | obj-$(CONFIG_SCSI_UFSHCD) += ufs/ |
| 103 | obj-$(CONFIG_SCSI_ACARD) += atp870u.o | 105 | obj-$(CONFIG_SCSI_ACARD) += atp870u.o |
| 104 | obj-$(CONFIG_SCSI_SUNESP) += esp_scsi.o sun_esp.o | 106 | obj-$(CONFIG_SCSI_SUNESP) += esp_scsi.o sun_esp.o |
| @@ -538,11 +538,11 @@ static void complete_cmd(struct Scsi_Host *instance, · 537 unmodified lines | |||
| 538 | 538 | ||
| 539 | if (hostdata->sensing == cmd) { | 539 | if (hostdata->sensing == cmd) { |
| 540 | /* Autosense processing ends here */ | 540 | /* Autosense processing ends here */ |
| 541 | if (status_byte(cmd->result) != GOOD) { | 541 | if (get_status_byte(cmd) != SAM_STAT_GOOD) { |
| 542 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); | 542 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); |
| 543 | } else { | 543 | } else { |
| 544 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); | 544 | scsi_eh_restore_cmnd(cmd, &hostdata->ses); |
| 545 | set_driver_byte(cmd, DRIVER_SENSE); | 545 | set_status_byte(cmd, SAM_STAT_CHECK_CONDITION); |
| 546 | } | 546 | } |
| 547 | hostdata->sensing = NULL; | 547 | hostdata->sensing = NULL; |
| 548 | } | 548 | } |
| @@ -1815,6 +1815,8 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) · 1266 unmodified lines | |||
| 1815 | 1815 | ||
| 1816 | switch (tmp) { | 1816 | switch (tmp) { |
| 1817 | case ABORT: | 1817 | case ABORT: |
| 1818 | set_host_byte(cmd, DID_ABORT); | ||
| 1819 | fallthrough; | ||
| 1818 | case COMMAND_COMPLETE: | 1820 | case COMMAND_COMPLETE: |
| 1819 | /* Accept message by clearing ACK */ | 1821 | /* Accept message by clearing ACK */ |
| 1820 | sink = 1; | 1822 | sink = 1; |
| @@ -1826,9 +1828,7 @@ static void NCR5380_information_transfer(struct Scsi_Host *instance) · 5 unmodified lines | |||
| 1826 | hostdata->connected = NULL; | 1828 | hostdata->connected = NULL; |
| 1827 | hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); | 1829 | hostdata->busy[scmd_id(cmd)] &= ~(1 << cmd->device->lun); |
| 1828 | 1830 | ||
| 1829 | cmd->result &= ~0xffff; | 1831 | set_status_byte(cmd, cmd->SCp.Status); |
| 1830 | cmd->result |= cmd->SCp.Status; | ||
| 1831 | cmd->result |= cmd->SCp.Message << 8; | ||
| 1832 | 1832 | ||
| 1833 | set_resid_from_SCp(cmd); | 1833 | set_resid_from_SCp(cmd); |
| 1834 | 1834 | ||
| @@ -1235,8 +1235,8 @@ static int aac_read_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u3 · 1234 unmodified lines | |||
| 1235 | if (ret < 0) | 1235 | if (ret < 0) |
| 1236 | return ret; | 1236 | return ret; |
| 1237 | command = ContainerRawIo2; | 1237 | command = ContainerRawIo2; |
| 1238 | fibsize = sizeof(struct aac_raw_io2) + | 1238 | fibsize = struct_size(readcmd2, sge, |
| 1239 | ((le32_to_cpu(readcmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212)); | 1239 | le32_to_cpu(readcmd2->sgeCnt)); |
| 1240 | } else { | 1240 | } else { |
| 1241 | struct aac_raw_io *readcmd; | 1241 | struct aac_raw_io *readcmd; |
| 1242 | readcmd = (struct aac_raw_io *) fib_data(fib); | 1242 | readcmd = (struct aac_raw_io *) fib_data(fib); |
| @@ -1366,8 +1366,8 @@ static int aac_write_raw_io(struct fib * fib, struct scsi_cmnd * cmd, u64 lba, u · 123 unmodified lines | |||
| 1366 | if (ret < 0) | 1366 | if (ret < 0) |
| 1367 | return ret; | 1367 | return ret; |
| 1368 | command = ContainerRawIo2; | 1368 | command = ContainerRawIo2; |
| 1369 | fibsize = sizeof(struct aac_raw_io2) + | 1369 | fibsize = struct_size(writecmd2, sge, |
| 1370 | ((le32_to_cpu(writecmd2->sgeCnt)-1) * sizeof(struct sge_ieee1212)); | 1370 | le32_to_cpu(writecmd2->sgeCnt)); |
| 1371 | } else { | 1371 | } else { |
| 1372 | struct aac_raw_io *writecmd; | 1372 | struct aac_raw_io *writecmd; |
| 1373 | writecmd = (struct aac_raw_io *) fib_data(fib); | 1373 | writecmd = (struct aac_raw_io *) fib_data(fib); |
| @@ -3998,7 +3998,7 @@ static int aac_convert_sgraw2(struct aac_raw_io2 *rio2, int pages, int nseg, int · 2624 unmodified lines | |||
| 3998 | if (aac_convert_sgl == 0) | 3998 | if (aac_convert_sgl == 0) |
| 3999 | return 0; | 3999 | return 0; |
| 4000 | 4000 | ||
| 4001 | sge = kmalloc_array(nseg_new, sizeof(struct sge_ieee1212), GFP_ATOMIC); | 4001 | sge = kmalloc_array(nseg_new, sizeof(*sge), GFP_ATOMIC); |
| 4002 | if (sge == NULL) | 4002 | if (sge == NULL) |
| 4003 | return -ENOMEM; | 4003 | return -ENOMEM; |
| 4004 | 4004 | ||
| @@ -1929,7 +1929,7 @@ struct aac_raw_io2 { · 1928 unmodified lines | |||
| 1929 | u8 bpComplete; /* reserved for F/W use */ | 1929 | u8 bpComplete; /* reserved for F/W use */ |
| 1930 | u8 sgeFirstIndex; /* reserved for F/W use */ | 1930 | u8 sgeFirstIndex; /* reserved for F/W use */ |
| 1931 | u8 unused[4]; | 1931 | u8 unused[4]; |
| 1932 | struct sge_ieee1212 sge[1]; | 1932 | struct sge_ieee1212 sge[]; |
| 1933 | }; | 1933 | }; |
| 1934 | 1934 | ||
| 1935 | #define CT_FLUSH_CACHE 129 | 1935 | #define CT_FLUSH_CACHE 129 |
| @@ -5964,7 +5964,6 @@ static void adv_isr_callback(ADV_DVC_VAR *adv_dvc_varp, ADV_SCSI_REQ_Q *scsiqp) · 5963 unmodified lines | |||
| 5964 | ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); | 5964 | ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); |
| 5965 | ASC_DBG_PRT_SENSE(2, scp->sense_buffer, | 5965 | ASC_DBG_PRT_SENSE(2, scp->sense_buffer, |
| 5966 | SCSI_SENSE_BUFFERSIZE); | 5966 | SCSI_SENSE_BUFFERSIZE); |
| 5967 | set_driver_byte(scp, DRIVER_SENSE); | ||
| 5968 | } | 5967 | } |
| 5969 | break; | 5968 | break; |
| 5970 | 5969 | ||
| @@ -6715,7 +6714,6 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep) · 744 unmodified lines | |||
| 6715 | ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); | 6714 | ASC_DBG(2, "SAM_STAT_CHECK_CONDITION\n"); |
| 6716 | ASC_DBG_PRT_SENSE(2, scp->sense_buffer, | 6715 | ASC_DBG_PRT_SENSE(2, scp->sense_buffer, |
| 6717 | SCSI_SENSE_BUFFERSIZE); | 6716 | SCSI_SENSE_BUFFERSIZE); |
| 6718 | set_driver_byte(scp, DRIVER_SENSE); | ||
| 6719 | } | 6717 | } |
| 6720 | break; | 6718 | break; |
| 6721 | 6719 | ||
| @@ -6730,14 +6728,12 @@ static void asc_isr_callback(ASC_DVC_VAR *asc_dvc_varp, ASC_QDONE_INFO *qdonep) · 8 unmodified lines | |||
| 6730 | case QD_ABORTED_BY_HOST: | 6728 | case QD_ABORTED_BY_HOST: |
| 6731 | ASC_DBG(1, "QD_ABORTED_BY_HOST\n"); | 6729 | ASC_DBG(1, "QD_ABORTED_BY_HOST\n"); |
| 6732 | set_status_byte(scp, qdonep->d3.scsi_stat); | 6730 | set_status_byte(scp, qdonep->d3.scsi_stat); |
| 6733 | set_msg_byte(scp, qdonep->d3.scsi_msg); | ||
| 6734 | set_host_byte(scp, DID_ABORT); | 6731 | set_host_byte(scp, DID_ABORT); |
| 6735 | break; | 6732 | break; |
| 6736 | 6733 | ||
| 6737 | default: | 6734 | default: |
| 6738 | ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat); | 6735 | ASC_DBG(1, "done_stat 0x%x\n", qdonep->d3.done_stat); |
| 6739 | set_status_byte(scp, qdonep->d3.scsi_stat); | 6736 | set_status_byte(scp, qdonep->d3.scsi_stat); |
| 6740 | set_msg_byte(scp, qdonep->d3.scsi_msg); | ||
| 6741 | set_host_byte(scp, DID_ERROR); | 6737 | set_host_byte(scp, DID_ERROR); |
| 6742 | break; | 6738 | break; |
| 6743 | } | 6739 | } |
| @@ -619,7 +619,8 @@ static struct { · 618 unmodified lines | |||
| 619 | static irqreturn_t intr(int irq, void *dev_id); | 619 | static irqreturn_t intr(int irq, void *dev_id); |
| 620 | static void reset_ports(struct Scsi_Host *shpnt); | 620 | static void reset_ports(struct Scsi_Host *shpnt); |
| 621 | static void aha152x_error(struct Scsi_Host *shpnt, char *msg); | 621 | static void aha152x_error(struct Scsi_Host *shpnt, char *msg); |
| 622 | static void done(struct Scsi_Host *shpnt, int error); | 622 | static void done(struct Scsi_Host *shpnt, unsigned char status_byte, |
| 623 | unsigned char host_byte); | ||
| 623 | 624 | ||
| 624 | /* diagnostics */ | 625 | /* diagnostics */ |
| 625 | static void show_command(struct scsi_cmnd * ptr); | 626 | static void show_command(struct scsi_cmnd * ptr); |
| @@ -1271,7 +1272,8 @@ static int aha152x_biosparam(struct scsi_device *sdev, struct block_device *bdev · 645 unmodified lines | |||
| 1271 | * Internal done function | 1272 | * Internal done function |
| 1272 | * | 1273 | * |
| 1273 | */ | 1274 | */ |
| 1274 | static void done(struct Scsi_Host *shpnt, int error) | 1275 | static void done(struct Scsi_Host *shpnt, unsigned char status_byte, |
| 1276 | unsigned char host_byte) | ||
| 1275 | { | 1277 | { |
| 1276 | if (CURRENT_SC) { | 1278 | if (CURRENT_SC) { |
| 1277 | if(DONE_SC) | 1279 | if(DONE_SC) |
| @@ -1281,7 +1283,8 @@ static void done(struct Scsi_Host *shpnt, int error) · 3 unmodified lines | |||
| 1281 | 1283 | ||
| 1282 | DONE_SC = CURRENT_SC; | 1284 | DONE_SC = CURRENT_SC; |
| 1283 | CURRENT_SC = NULL; | 1285 | CURRENT_SC = NULL; |
| 1284 | DONE_SC->result = error; | 1286 | set_status_byte(DONE_SC, status_byte); |
| 1287 | set_host_byte(DONE_SC, host_byte); | ||
| 1285 | } else | 1288 | } else |
| 1286 | printk(KERN_ERR "aha152x: done() called outside of command\n"); | 1289 | printk(KERN_ERR "aha152x: done() called outside of command\n"); |
| 1287 | } | 1290 | } |
| @@ -1376,13 +1379,13 @@ static void busfree_run(struct Scsi_Host *shpnt) · 88 unmodified lines | |||
| 1376 | 1379 | ||
| 1377 | if(CURRENT_SC->SCp.phase & completed) { | 1380 | if(CURRENT_SC->SCp.phase & completed) { |
| 1378 | /* target sent COMMAND COMPLETE */ | 1381 | /* target sent COMMAND COMPLETE */ |
| 1379 | done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_OK << 16)); | 1382 | done(shpnt, CURRENT_SC->SCp.Status, DID_OK); |
| 1380 | 1383 | ||
| 1381 | } else if(CURRENT_SC->SCp.phase & aborted) { | 1384 | } else if(CURRENT_SC->SCp.phase & aborted) { |
| 1382 | done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_ABORT << 16)); | 1385 | done(shpnt, CURRENT_SC->SCp.Status, DID_ABORT); |
| 1383 | 1386 | ||
| 1384 | } else if(CURRENT_SC->SCp.phase & resetted) { | 1387 | } else if(CURRENT_SC->SCp.phase & resetted) { |
| 1385 | done(shpnt, (CURRENT_SC->SCp.Status & 0xff) | ((CURRENT_SC->SCp.Message & 0xff) << 8) | (DID_RESET << 16)); | 1388 | done(shpnt, CURRENT_SC->SCp.Status, DID_RESET); |
| 1386 | 1389 | ||
| 1387 | } else if(CURRENT_SC->SCp.phase & disconnected) { | 1390 | } else if(CURRENT_SC->SCp.phase & disconnected) { |
| 1388 | /* target sent DISCONNECT */ | 1391 | /* target sent DISCONNECT */ |
| @@ -1394,7 +1397,7 @@ static void busfree_run(struct Scsi_Host *shpnt) · 5 unmodified lines | |||
| 1394 | CURRENT_SC = NULL; | 1397 | CURRENT_SC = NULL; |
| 1395 | 1398 | ||
| 1396 | } else { | 1399 | } else { |
| 1397 | done(shpnt, DID_ERROR << 16); | 1400 | done(shpnt, SAM_STAT_GOOD, DID_ERROR); |
| 1398 | } | 1401 | } |
| 1399 | #if defined(AHA152X_STAT) | 1402 | #if defined(AHA152X_STAT) |
| 1400 | } else { | 1403 | } else { |
| @@ -1515,7 +1518,7 @@ static void seldo_run(struct Scsi_Host *shpnt) · 114 unmodified lines | |||
| 1515 | if (TESTLO(SSTAT0, SELDO)) { | 1518 | if (TESTLO(SSTAT0, SELDO)) { |
| 1516 | scmd_printk(KERN_ERR, CURRENT_SC, | 1519 | scmd_printk(KERN_ERR, CURRENT_SC, |
| 1517 | "aha152x: passing bus free condition\n"); | 1520 | "aha152x: passing bus free condition\n"); |
| 1518 | done(shpnt, DID_NO_CONNECT << 16); | 1521 | done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT); |
| 1519 | return; | 1522 | return; |
| 1520 | } | 1523 | } |
| 1521 | 1524 | ||
| @@ -1552,12 +1555,12 @@ static void selto_run(struct Scsi_Host *shpnt) · 30 unmodified lines | |||
| 1552 | CURRENT_SC->SCp.phase &= ~selecting; | 1555 | CURRENT_SC->SCp.phase &= ~selecting; |
| 1553 | 1556 | ||
| 1554 | if (CURRENT_SC->SCp.phase & aborted) | 1557 | if (CURRENT_SC->SCp.phase & aborted) |
| 1555 | done(shpnt, DID_ABORT << 16); | 1558 | done(shpnt, SAM_STAT_GOOD, DID_ABORT); |
| 1556 | else if (TESTLO(SSTAT0, SELINGO)) | 1559 | else if (TESTLO(SSTAT0, SELINGO)) |
| 1557 | done(shpnt, DID_BUS_BUSY << 16); | 1560 | done(shpnt, SAM_STAT_GOOD, DID_BUS_BUSY); |
| 1558 | else | 1561 | else |
| 1559 | /* ARBITRATION won, but SELECTION failed */ | 1562 | /* ARBITRATION won, but SELECTION failed */ |
| 1560 | done(shpnt, DID_NO_CONNECT << 16); | 1563 | done(shpnt, SAM_STAT_GOOD, DID_NO_CONNECT); |
| 1561 | } | 1564 | } |
| 1562 | 1565 | ||
| 1563 | /* | 1566 | /* |
| @@ -1891,7 +1894,7 @@ static void cmd_init(struct Scsi_Host *shpnt) · 327 unmodified lines | |||
| 1891 | if (CURRENT_SC->SCp.sent_command) { | 1894 | if (CURRENT_SC->SCp.sent_command) { |
| 1892 | scmd_printk(KERN_ERR, CURRENT_SC, | 1895 | scmd_printk(KERN_ERR, CURRENT_SC, |
| 1893 | "command already sent\n"); | 1896 | "command already sent\n"); |
| 1894 | done(shpnt, DID_ERROR << 16); | 1897 | done(shpnt, SAM_STAT_GOOD, DID_ERROR); |
| 1895 | return; | 1898 | return; |
| 1896 | } | 1899 | } |
| 1897 | 1900 | ||
| @@ -2231,7 +2234,7 @@ static int update_state(struct Scsi_Host *shpnt) · 333 unmodified lines | |||
| 2231 | static void parerr_run(struct Scsi_Host *shpnt) | 2234 | static void parerr_run(struct Scsi_Host *shpnt) |
| 2232 | { | 2235 | { |
| 2233 | scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n"); | 2236 | scmd_printk(KERN_ERR, CURRENT_SC, "parity error\n"); |
| 2234 | done(shpnt, DID_PARITY << 16); | 2237 | done(shpnt, SAM_STAT_GOOD, DID_PARITY); |
| 2235 | } | 2238 | } |
| 2236 | 2239 | ||
| 2237 | /* | 2240 | /* |
| @@ -2254,7 +2257,7 @@ static void rsti_run(struct Scsi_Host *shpnt) · 16 unmodified lines | |||
| 2254 | kfree(ptr->host_scribble); | 2257 | kfree(ptr->host_scribble); |
| 2255 | ptr->host_scribble=NULL; | 2258 | ptr->host_scribble=NULL; |
| 2256 | 2259 | ||
| 2257 | ptr->result = DID_RESET << 16; | 2260 | set_host_byte(ptr, DID_RESET); |
| 2258 | ptr->scsi_done(ptr); | 2261 | ptr->scsi_done(ptr); |
| 2259 | } | 2262 | } |
| 2260 | 2263 | ||
| @@ -2262,7 +2265,7 @@ static void rsti_run(struct Scsi_Host *shpnt) · 1 unmodified line | |||
| 2262 | } | 2265 | } |
| 2263 | 2266 | ||
| 2264 | if(CURRENT_SC && !CURRENT_SC->device->soft_reset) | 2267 | if(CURRENT_SC && !CURRENT_SC->device->soft_reset) |
| 2265 | done(shpnt, DID_RESET << 16 ); | 2268 | done(shpnt, SAM_STAT_GOOD, DID_RESET); |
| 2266 | } | 2269 | } |
| 2267 | 2270 | ||
| 2268 | 2271 | ||
| @@ -267,8 +267,11 @@ static irqreturn_t aha1740_intr_handle(int irq, void *dev_id) · 266 unmodified lines | |||
| 267 | guarantee that we will still have it in the | 267 | guarantee that we will still have it in the |
| 268 | cdb when we come back */ | 268 | cdb when we come back */ |
| 269 | if ( (adapstat & G2INTST_MASK) == G2INTST_CCBERROR ) { | 269 | if ( (adapstat & G2INTST_MASK) == G2INTST_CCBERROR ) { |
| 270 | memcpy(SCtmp->sense_buffer, ecbptr->sense, | 270 | memcpy_and_pad(SCtmp->sense_buffer, |
| 271 | SCSI_SENSE_BUFFERSIZE); | 271 | SCSI_SENSE_BUFFERSIZE, |
| 272 | ecbptr->sense, | ||
| 273 | sizeof(ecbptr->sense), | ||
| 274 | 0); | ||
| 272 | errstatus = aha1740_makecode(ecbptr->sense,ecbptr->status); | 275 | errstatus = aha1740_makecode(ecbptr->sense,ecbptr->status); |
| 273 | } else | 276 | } else |
| 274 | errstatus = 0; | 277 | errstatus = 0; |
| @@ -1928,7 +1928,7 @@ ahd_linux_handle_scsi_status(struct ahd_softc *ahd, · 1927 unmodified lines | |||
| 1928 | memcpy(cmd->sense_buffer, | 1928 | memcpy(cmd->sense_buffer, |
| 1929 | ahd_get_sense_buf(ahd, scb) | 1929 | ahd_get_sense_buf(ahd, scb) |
| 1930 | + sense_offset, sense_size); | 1930 | + sense_offset, sense_size); |
| 1931 | cmd->result |= (DRIVER_SENSE << 24); | 1931 | set_status_byte(cmd, SAM_STAT_CHECK_CONDITION); |
| 1932 | 1932 | ||
| 1933 | #ifdef AHD_DEBUG | 1933 | #ifdef AHD_DEBUG |
| 1934 | if (ahd_debug & AHD_SHOW_SENSE) { | 1934 | if (ahd_debug & AHD_SHOW_SENSE) { |
| @@ -2018,6 +2018,7 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd) · 83 unmodified lines | |||
| 2018 | int new_status = DID_OK; | 2018 | int new_status = DID_OK; |
| 2019 | int do_fallback = 0; | 2019 | int do_fallback = 0; |
| 2020 | int scsi_status; | 2020 | int scsi_status; |
| 2021 | struct scsi_sense_data *sense; | ||
| 2021 | 2022 | ||
| 2022 | /* | 2023 | /* |
| 2023 | * Map CAM error codes into Linux Error codes. We | 2024 | * Map CAM error codes into Linux Error codes. We |
| @@ -2041,18 +2042,12 @@ ahd_linux_queue_cmd_complete(struct ahd_softc *ahd, struct scsi_cmnd *cmd) · 17 unmodified lines | |||
| 2041 | switch(scsi_status) { | 2042 | switch(scsi_status) { |
| 2042 | case SAM_STAT_COMMAND_TERMINATED: | 2043 | case SAM_STAT_COMMAND_TERMINATED: |
| 2043 | case SAM_STAT_CHECK_CONDITION: | 2044 | case SAM_STAT_CHECK_CONDITION: |
| 2044 | if ((cmd->result >> 24) != DRIVER_SENSE) { | 2045 | sense = (struct scsi_sense_data *) |
| 2046 | cmd->sense_buffer; | ||
| 2047 | if (sense->extra_len >= 5 && | ||
| 2048 | (sense->add_sense_code == 0x47 | ||
| 2049 | || sense->add_sense_code == 0x48)) | ||
| 2045 | do_fallback = 1; | 2050 | do_fallback = 1; |
| 2046 | } else { | ||
| 2047 | struct scsi_sense_data *sense; | ||
| 2048 | |||
| 2049 | sense = (struct scsi_sense_data *) | ||
| 2050 | cmd->sense_buffer; | ||
| 2051 | if (sense->extra_len >= 5 && | ||
| 2052 | (sense->add_sense_code == 0x47 | ||
| 2053 | || sense->add_sense_code == 0x48)) | ||
| 2054 | do_fallback = 1; | ||
| 2055 | } | ||
| 2056 | break; | 2051 | break; |
| 2057 | default: | 2052 | default: |
| 2058 | break; | 2053 | break; |
| @@ -1838,7 +1838,6 @@ ahc_linux_handle_scsi_status(struct ahc_softc *ahc, · 1837 unmodified lines | |||
| 1838 | if (sense_size < SCSI_SENSE_BUFFERSIZE) | 1838 | if (sense_size < SCSI_SENSE_BUFFERSIZE) |
| 1839 | memset(&cmd->sense_buffer[sense_size], 0, | 1839 | memset(&cmd->sense_buffer[sense_size], 0, |
| 1840 | SCSI_SENSE_BUFFERSIZE - sense_size); | 1840 | SCSI_SENSE_BUFFERSIZE - sense_size); |
| 1841 | cmd->result |= (DRIVER_SENSE << 24); | ||
| 1842 | #ifdef AHC_DEBUG | 1841 | #ifdef AHC_DEBUG |
| 1843 | if (ahc_debug & AHC_SHOW_SENSE) { | 1842 | if (ahc_debug & AHC_SHOW_SENSE) { |
| 1844 | int i; | 1843 | int i; |
| @@ -205,7 +205,7 @@ Again: · 204 unmodified lines | |||
| 205 | switch (opcode) { | 205 | switch (opcode) { |
| 206 | case TC_NO_ERROR: | 206 | case TC_NO_ERROR: |
| 207 | ts->resp = SAS_TASK_COMPLETE; | 207 | ts->resp = SAS_TASK_COMPLETE; |
| 208 | ts->stat = SAM_STAT_GOOD; | 208 | ts->stat = SAS_SAM_STAT_GOOD; |
| 209 | break; | 209 | break; |
| 210 | case TC_UNDERRUN: | 210 | case TC_UNDERRUN: |
| 211 | ts->resp = SAS_TASK_COMPLETE; | 211 | ts->resp = SAS_TASK_COMPLETE; |
| @@ -49,7 +49,7 @@ struct device_attribute; · 48 unmodified lines | |||
| 49 | #define ARCMSR_MAX_OUTSTANDING_CMD 1024 | 49 | #define ARCMSR_MAX_OUTSTANDING_CMD 1024 |
| 50 | #define ARCMSR_DEFAULT_OUTSTANDING_CMD 128 | 50 | #define ARCMSR_DEFAULT_OUTSTANDING_CMD 128 |
| 51 | #define ARCMSR_MIN_OUTSTANDING_CMD 32 | 51 | #define ARCMSR_MIN_OUTSTANDING_CMD 32 |
| 52 | #define ARCMSR_DRIVER_VERSION "v1.50.00.02-20200819" | 52 | #define ARCMSR_DRIVER_VERSION "v1.50.00.05-20210429" |
| 53 | #define ARCMSR_SCSI_INITIATOR_ID 255 | 53 | #define ARCMSR_SCSI_INITIATOR_ID 255 |
| 54 | #define ARCMSR_MAX_XFER_SECTORS 512 | 54 | #define ARCMSR_MAX_XFER_SECTORS 512 |
| 55 | #define ARCMSR_MAX_XFER_SECTORS_B 4096 | 55 | #define ARCMSR_MAX_XFER_SECTORS_B 4096 |
| @@ -1323,19 +1323,21 @@ static void arcmsr_ccb_complete(struct CommandControlBlock *ccb) · 1322 unmodified lines | |||
| 1323 | 1323 | ||
| 1324 | static void arcmsr_report_sense_info(struct CommandControlBlock *ccb) | 1324 | static void arcmsr_report_sense_info(struct CommandControlBlock *ccb) |
| 1325 | { | 1325 | { |
| 1326 | |||
| 1327 | struct scsi_cmnd *pcmd = ccb->pcmd; | 1326 | struct scsi_cmnd *pcmd = ccb->pcmd; |
| 1328 | struct SENSE_DATA *sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer; | 1327 | |
| 1329 | pcmd->result = (DID_OK << 16) | (CHECK_CONDITION << 1); | 1328 | pcmd->result = (DID_OK << 16) | SAM_STAT_CHECK_CONDITION; |
| 1330 | if (sensebuffer) { | 1329 | if (pcmd->sense_buffer) { |
| 1331 | int sense_data_length = | 1330 | struct SENSE_DATA *sensebuffer; |
| 1332 | sizeof(struct SENSE_DATA) < SCSI_SENSE_BUFFERSIZE | 1331 | |
| 1333 | ? sizeof(struct SENSE_DATA) : SCSI_SENSE_BUFFERSIZE; | 1332 | memcpy_and_pad(pcmd->sense_buffer, |
| 1334 | memset(sensebuffer, 0, SCSI_SENSE_BUFFERSIZE); | 1333 | SCSI_SENSE_BUFFERSIZE, |
| 1335 | memcpy(sensebuffer, ccb->arcmsr_cdb.SenseData, sense_data_length); | 1334 | ccb->arcmsr_cdb.SenseData, |
| 1335 | sizeof(ccb->arcmsr_cdb.SenseData), | ||
| 1336 | 0); | ||
| 1337 | |||
| 1338 | sensebuffer = (struct SENSE_DATA *)pcmd->sense_buffer; | ||
| 1336 | sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS; | 1339 | sensebuffer->ErrorCode = SCSI_SENSE_CURRENT_ERRORS; |
| 1337 | sensebuffer->Valid = 1; | 1340 | sensebuffer->Valid = 1; |
| 1338 | pcmd->result |= (DRIVER_SENSE << 24); | ||
| 1339 | } | 1341 | } |
| 1340 | } | 1342 | } |
| 1341 | 1343 | ||
| @@ -1923,8 +1925,12 @@ static void arcmsr_post_ccb(struct AdapterControlBlock *acb, struct CommandContr · 581 unmodified lines | |||
| 1923 | 1925 | ||
| 1924 | if (ccb->arc_cdb_size <= 0x300) | 1926 | if (ccb->arc_cdb_size <= 0x300) |
| 1925 | arc_cdb_size = (ccb->arc_cdb_size - 1) >> 6 | 1; | 1927 | arc_cdb_size = (ccb->arc_cdb_size - 1) >> 6 | 1; |
| 1926 | else | 1928 | else { |
| 1927 | arc_cdb_size = (((ccb->arc_cdb_size + 0xff) >> 8) + 2) << 1 | 1; | 1929 | arc_cdb_size = ((ccb->arc_cdb_size + 0xff) >> 8) + 2; |
| 1930 | if (arc_cdb_size > 0xF) | ||
| 1931 | arc_cdb_size = 0xF; | ||
| 1932 | arc_cdb_size = (arc_cdb_size << 1) | 1; | ||
| 1933 | } | ||
| 1928 | ccb_post_stamp = (ccb->smid | arc_cdb_size); | 1934 | ccb_post_stamp = (ccb->smid | arc_cdb_size); |
| 1929 | writel(0, &pmu->inbound_queueport_high); | 1935 | writel(0, &pmu->inbound_queueport_high); |
| 1930 | writel(ccb_post_stamp, &pmu->inbound_queueport_low); | 1936 | writel(ccb_post_stamp, &pmu->inbound_queueport_low); |
| @@ -2415,10 +2421,17 @@ static void arcmsr_hbaD_doorbell_isr(struct AdapterControlBlock *pACB) · 484 unmodified lines | |||
| 2415 | 2421 | ||
| 2416 | static void arcmsr_hbaE_doorbell_isr(struct AdapterControlBlock *pACB) | 2422 | static void arcmsr_hbaE_doorbell_isr(struct AdapterControlBlock *pACB) |
| 2417 | { | 2423 | { |
| 2418 | uint32_t outbound_doorbell, in_doorbell, tmp; | 2424 | uint32_t outbound_doorbell, in_doorbell, tmp, i; |
| 2419 | struct MessageUnit_E __iomem *reg = pACB->pmuE; | 2425 | struct MessageUnit_E __iomem *reg = pACB->pmuE; |
| 2420 | 2426 | ||
| 2421 | in_doorbell = readl(®->iobound_doorbell); | 2427 | if (pACB->adapter_type == ACB_ADAPTER_TYPE_F) { |
| 2428 | for (i = 0; i < 5; i++) { | ||
| 2429 | in_doorbell = readl(®->iobound_doorbell); | ||
| 2430 | if (in_doorbell != 0) | ||
| 2431 | break; | ||
| 2432 | } | ||
| 2433 | } else | ||
| 2434 | in_doorbell = readl(®->iobound_doorbell); | ||
| 2422 | outbound_doorbell = in_doorbell ^ pACB->in_doorbell; | 2435 | outbound_doorbell = in_doorbell ^ pACB->in_doorbell; |
| 2423 | do { | 2436 | do { |
| 2424 | writel(0, ®->host_int_status); /* clear interrupt */ | 2437 | writel(0, ®->host_int_status); /* clear interrupt */ |
| @@ -3243,7 +3256,7 @@ static int arcmsr_queue_command_lck(struct scsi_cmnd *cmd, · 818 unmodified lines | |||
| 3243 | if (!ccb) | 3256 | if (!ccb) |
| 3244 | return SCSI_MLQUEUE_HOST_BUSY; | 3257 | return SCSI_MLQUEUE_HOST_BUSY; |
| 3245 | if (arcmsr_build_ccb( acb, ccb, cmd ) == FAILED) { | 3258 | if (arcmsr_build_ccb( acb, ccb, cmd ) == FAILED) { |
| 3246 | cmd->result = (DID_ERROR << 16) | (RESERVATION_CONFLICT << 1); | 3259 | cmd->result = (DID_ERROR << 16) | SAM_STAT_RESERVATION_CONFLICT; |
| 3247 | cmd->scsi_done(cmd); | 3260 | cmd->scsi_done(cmd); |
| 3248 | return 0; | 3261 | return 0; |
| 3249 | } | 3262 | } |
| @@ -794,7 +794,10 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp, · 793 unmodified lines | |||
| 794 | 794 | ||
| 795 | acornscsi_dma_cleanup(host); | 795 | acornscsi_dma_cleanup(host); |
| 796 | 796 | ||
| 797 | SCpnt->result = result << 16 | host->scsi.SCp.Message << 8 | host->scsi.SCp.Status; | 797 | set_host_byte(SCpnt, result); |
| 798 | if (result == DID_OK) | ||
| 799 | scsi_msg_to_host_byte(SCpnt, host->scsi.SCp.Message); | ||
| 800 | set_status_byte(SCpnt, host->scsi.SCp.Status); | ||
| 798 | 801 | ||
| 799 | /* | 802 | /* |
| 800 | * In theory, this should not happen. In practice, it seems to. | 803 | * In theory, this should not happen. In practice, it seems to. |
| @@ -833,12 +836,12 @@ static void acornscsi_done(AS_Host *host, struct scsi_cmnd **SCpntp, · 32 unmodified lines | |||
| 833 | xfer_warn = 0; | 836 | xfer_warn = 0; |
| 834 | 837 | ||
| 835 | if (xfer_warn) { | 838 | if (xfer_warn) { |
| 836 | switch (status_byte(SCpnt->result)) { | 839 | switch (get_status_byte(SCpnt)) { |
| 837 | case CHECK_CONDITION: | 840 | case SAM_STAT_CHECK_CONDITION: |
| 838 | case COMMAND_TERMINATED: | 841 | case SAM_STAT_COMMAND_TERMINATED: |
| 839 | case BUSY: | 842 | case SAM_STAT_BUSY: |
| 840 | case QUEUE_FULL: | 843 | case SAM_STAT_TASK_SET_FULL: |
| 841 | case RESERVATION_CONFLICT: | 844 | case SAM_STAT_RESERVATION_CONFLICT: |
| 842 | break; | 845 | break; |
| 843 | 846 | ||
| 844 | default: | 847 | default: |
| @@ -2470,7 +2473,7 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt, · 1625 unmodified lines | |||
| 2470 | if (acornscsi_cmdtype(SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->device->id))) { | 2473 | if (acornscsi_cmdtype(SCpnt->cmnd[0]) == CMD_WRITE && (NO_WRITE & (1 << SCpnt->device->id))) { |
| 2471 | printk(KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n", | 2474 | printk(KERN_CRIT "scsi%d.%c: WRITE attempted with NO_WRITE flag set\n", |
| 2472 | host->host->host_no, '0' + SCpnt->device->id); | 2475 | host->host->host_no, '0' + SCpnt->device->id); |
| 2473 | SCpnt->result = DID_NO_CONNECT << 16; | 2476 | set_host_byte(SCpnt, DID_NO_CONNECT); |
| 2474 | done(SCpnt); | 2477 | done(SCpnt); |
| 2475 | return 0; | 2478 | return 0; |
| 2476 | } | 2479 | } |
| @@ -2492,7 +2495,7 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt, · 15 unmodified lines | |||
| 2492 | unsigned long flags; | 2495 | unsigned long flags; |
| 2493 | 2496 | ||
| 2494 | if (!queue_add_cmd_ordered(&host->queues.issue, SCpnt)) { | 2497 | if (!queue_add_cmd_ordered(&host->queues.issue, SCpnt)) { |
| 2495 | SCpnt->result = DID_ERROR << 16; | 2498 | set_host_byte(SCpnt, DID_ERROR); |
| 2496 | done(SCpnt); | 2499 | done(SCpnt); |
| 2497 | return 0; | 2500 | return 0; |
| 2498 | } | 2501 | } |
| @@ -2506,31 +2509,6 @@ static int acornscsi_queuecmd_lck(struct scsi_cmnd *SCpnt, · 7 unmodified lines | |||
| 2506 | 2509 | ||
| 2507 | DEF_SCSI_QCMD(acornscsi_queuecmd) | 2510 | DEF_SCSI_QCMD(acornscsi_queuecmd) |
| 2508 | 2511 | ||
| 2509 | /* | ||
| 2510 | * Prototype: void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, struct scsi_cmnd **SCpntp2, int result) | ||
| 2511 | * Purpose : pass a result to *SCpntp1, and check if *SCpntp1 = *SCpntp2 | ||
| 2512 | * Params : SCpntp1 - pointer to command to return | ||
| 2513 | * SCpntp2 - pointer to command to check | ||
| 2514 | * result - result to pass back to mid-level done function | ||
| 2515 | * Returns : *SCpntp2 = NULL if *SCpntp1 is the same command structure as *SCpntp2. | ||
| 2516 | */ | ||
| 2517 | static inline void acornscsi_reportstatus(struct scsi_cmnd **SCpntp1, | ||
| 2518 | struct scsi_cmnd **SCpntp2, | ||
| 2519 | int result) | ||
| 2520 | { | ||
| 2521 | struct scsi_cmnd *SCpnt = *SCpntp1; | ||
| 2522 | |||
| 2523 | if (SCpnt) { | ||
| 2524 | *SCpntp1 = NULL; | ||
| 2525 | |||
| 2526 | SCpnt->result = result; | ||
| 2527 | SCpnt->scsi_done(SCpnt); | ||
| 2528 | } | ||
| 2529 | |||
| 2530 | if (SCpnt == *SCpntp2) | ||
| 2531 | *SCpntp2 = NULL; | ||
| 2532 | } | ||
| 2533 | |||
| 2534 | enum res_abort { res_not_running, res_success, res_success_clear, res_snooze }; | 2512 | enum res_abort { res_not_running, res_success, res_success_clear, res_snooze }; |
| 2535 | 2513 | ||
| 2536 | /* | 2514 | /* |
| @@ -1479,7 +1479,7 @@ static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigne · 1478 unmodified lines | |||
| 1479 | 1479 | ||
| 1480 | if (msgqueue_msglength(&info->scsi.msgs) > 1) | 1480 | if (msgqueue_msglength(&info->scsi.msgs) > 1) |
| 1481 | fas216_cmd(info, CMD_SETATN); | 1481 | fas216_cmd(info, CMD_SETATN); |
| 1482 | /*FALLTHROUGH*/ | 1482 | fallthrough; |
| 1483 | 1483 | ||
| 1484 | /* | 1484 | /* |
| 1485 | * Any -> Message Out | 1485 | * Any -> Message Out |
| @@ -2042,8 +2042,10 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result) · 556 unmodified lines | |||
| 2042 | { | 2042 | { |
| 2043 | info->stats.fins += 1; | 2043 | info->stats.fins += 1; |
| 2044 | 2044 | ||
| 2045 | SCpnt->result = result << 16 | info->scsi.SCp.Message << 8 | | 2045 | set_host_byte(SCpnt, result); |
| 2046 | info->scsi.SCp.Status; | 2046 | if (result == DID_OK) |
| 2047 | scsi_msg_to_host_byte(SCpnt, info->scsi.SCp.Message); | ||
| 2048 | set_status_byte(SCpnt, info->scsi.SCp.Status); | ||
| 2047 | 2049 | ||
| 2048 | fas216_log_command(info, LOG_CONNECT, SCpnt, | 2050 | fas216_log_command(info, LOG_CONNECT, SCpnt, |
| 2049 | "command complete, result=0x%08x", SCpnt->result); | 2051 | "command complete, result=0x%08x", SCpnt->result); |
| @@ -2051,23 +2053,22 @@ fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result) · 1 unmodified line | |||
| 2051 | /* | 2053 | /* |
| 2052 | * If the driver detected an error, we're all done. | 2054 | * If the driver detected an error, we're all done. |
| 2053 | */ | 2055 | */ |
| 2054 | if (host_byte(SCpnt->result) != DID_OK || | 2056 | if (get_host_byte(SCpnt) != DID_OK) |
| 2055 | msg_byte(SCpnt->result) != COMMAND_COMPLETE) | ||
| 2056 | goto done; | 2057 | goto done; |
| 2057 | 2058 | ||
| 2058 | /* | 2059 | /* |
| 2059 | * If the command returned CHECK_CONDITION or COMMAND_TERMINATED | 2060 | * If the command returned CHECK_CONDITION or COMMAND_TERMINATED |
| 2060 | * status, request the sense information. | 2061 | * status, request the sense information. |
| 2061 | */ | 2062 | */ |
| 2062 | if (status_byte(SCpnt->result) == CHECK_CONDITION || | 2063 | if (get_status_byte(SCpnt) == SAM_STAT_CHECK_CONDITION || |
| 2063 | status_byte(SCpnt->result) == COMMAND_TERMINATED) | 2064 | get_status_byte(SCpnt) == SAM_STAT_COMMAND_TERMINATED) |
| 2064 | goto request_sense; | 2065 | goto request_sense; |
| 2065 | 2066 | ||
| 2066 | /* | 2067 | /* |
| 2067 | * If the command did not complete with GOOD status, | 2068 | * If the command did not complete with GOOD status, |
| 2068 | * we are all done here. | 2069 | * we are all done here. |
| 2069 | */ | 2070 | */ |
| 2070 | if (status_byte(SCpnt->result) != GOOD) | 2071 | if (get_status_byte(SCpnt) != SAM_STAT_GOOD) |
| 2071 | goto done; | 2072 | goto done; |
| 2072 | 2073 | ||
| 2073 | /* | 2074 | /* |
| @@ -182,6 +182,7 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, · 181 unmodified lines | |||
| 182 | struct beiscsi_endpoint *beiscsi_ep; | 182 | struct beiscsi_endpoint *beiscsi_ep; |
| 183 | struct iscsi_endpoint *ep; | 183 | struct iscsi_endpoint *ep; |
| 184 | uint16_t cri_index; | 184 | uint16_t cri_index; |
| 185 | int rc = 0; | ||
| 185 | 186 | ||
| 186 | ep = iscsi_lookup_endpoint(transport_fd); | 187 | ep = iscsi_lookup_endpoint(transport_fd); |
| 187 | if (!ep) | 188 | if (!ep) |
| @@ -189,15 +190,17 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, · 1 unmodified line | |||
| 189 | 190 | ||
| 190 | beiscsi_ep = ep->dd_data; | 191 | beiscsi_ep = ep->dd_data; |
| 191 | 192 | ||
| 192 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) | 193 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) { |
| 193 | return -EINVAL; | 194 | rc = -EINVAL; |
| 195 | goto put_ep; | ||
| 196 | } | ||
| 194 | 197 | ||
| 195 | if (beiscsi_ep->phba != phba) { | 198 | if (beiscsi_ep->phba != phba) { |
| 196 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, | 199 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
| 197 | "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n", | 200 | "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n", |
| 198 | beiscsi_ep->phba, phba); | 201 | beiscsi_ep->phba, phba); |
| 199 | 202 | rc = -EEXIST; | |
| 200 | return -EEXIST; | 203 | goto put_ep; |
| 201 | } | 204 | } |
| 202 | cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid); | 205 | cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid); |
| 203 | if (phba->conn_table[cri_index]) { | 206 | if (phba->conn_table[cri_index]) { |
| @@ -209,7 +212,8 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, · 5 unmodified lines | |||
| 209 | beiscsi_ep->ep_cid, | 212 | beiscsi_ep->ep_cid, |
| 210 | beiscsi_conn, | 213 | beiscsi_conn, |
| 211 | phba->conn_table[cri_index]); | 214 | phba->conn_table[cri_index]); |
| 212 | return -EINVAL; | 215 | rc = -EINVAL; |
| 216 | goto put_ep; | ||
| 213 | } | 217 | } |
| 214 | } | 218 | } |
| 215 | 219 | ||
| @@ -226,7 +230,10 @@ int beiscsi_conn_bind(struct iscsi_cls_session *cls_session, · 10 unmodified lines | |||
| 226 | "BS_%d : cid %d phba->conn_table[%u]=%p\n", | 230 | "BS_%d : cid %d phba->conn_table[%u]=%p\n", |
| 227 | beiscsi_ep->ep_cid, cri_index, beiscsi_conn); | 231 | beiscsi_ep->ep_cid, cri_index, beiscsi_conn); |
| 228 | phba->conn_table[cri_index] = beiscsi_conn; | 232 | phba->conn_table[cri_index] = beiscsi_conn; |
| 229 | return 0; | 233 | |
| 234 | put_ep: | ||
| 235 | iscsi_put_endpoint(ep); | ||
| 236 | return rc; | ||
| 230 | } | 237 | } |
| 231 | 238 | ||
| 232 | static int beiscsi_iface_create_ipv4(struct beiscsi_hba *phba) | 239 | static int beiscsi_iface_create_ipv4(struct beiscsi_hba *phba) |
| @@ -1293,7 +1300,6 @@ static int beiscsi_conn_close(struct beiscsi_endpoint *beiscsi_ep) · 1060 unmodified lines | |||
| 1293 | void beiscsi_ep_disconnect(struct iscsi_endpoint *ep) | 1300 | void beiscsi_ep_disconnect(struct iscsi_endpoint *ep) |
| 1294 | { | 1301 | { |
| 1295 | struct beiscsi_endpoint *beiscsi_ep; | 1302 | struct beiscsi_endpoint *beiscsi_ep; |
| 1296 | struct beiscsi_conn *beiscsi_conn; | ||
| 1297 | struct beiscsi_hba *phba; | 1303 | struct beiscsi_hba *phba; |
| 1298 | uint16_t cri_index; | 1304 | uint16_t cri_index; |
| 1299 | 1305 | ||
| @@ -1312,11 +1318,6 @@ void beiscsi_ep_disconnect(struct iscsi_endpoint *ep) · 12 unmodified lines | |||
| 1312 | return; | 1318 | return; |
| 1313 | } | 1319 | } |
| 1314 | 1320 | ||
| 1315 | if (beiscsi_ep->conn) { | ||
| 1316 | beiscsi_conn = beiscsi_ep->conn; | ||
| 1317 | iscsi_suspend_queue(beiscsi_conn->conn); | ||
| 1318 | } | ||
| 1319 | |||
| 1320 | if (!beiscsi_hba_is_online(phba)) { | 1321 | if (!beiscsi_hba_is_online(phba)) { |
| 1321 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, | 1322 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
| 1322 | "BS_%d : HBA in error 0x%lx\n", phba->state); | 1323 | "BS_%d : HBA in error 0x%lx\n", phba->state); |
| @@ -416,7 +416,7 @@ static struct beiscsi_hba *beiscsi_hba_alloc(struct pci_dev *pcidev) · 415 unmodified lines | |||
| 416 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); | 416 | "beiscsi_hba_alloc - iscsi_host_alloc failed\n"); |
| 417 | return NULL; | 417 | return NULL; |
| 418 | } | 418 | } |
| 419 | shost->max_id = BE2_MAX_SESSIONS; | 419 | shost->max_id = BE2_MAX_SESSIONS - 1; |
| 420 | shost->max_channel = 0; | 420 | shost->max_channel = 0; |
| 421 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; | 421 | shost->max_cmd_len = BEISCSI_MAX_CMD_LEN; |
| 422 | shost->max_lun = BEISCSI_NUM_MAX_LUN; | 422 | shost->max_lun = BEISCSI_NUM_MAX_LUN; |
| @@ -3858,8 +3858,6 @@ static void beiscsi_free_mem(struct beiscsi_hba *phba) · 3435 unmodified lines | |||
| 3858 | int i, j; | 3858 | int i, j; |
| 3859 | 3859 | ||
| 3860 | mem_descr = phba->init_mem; | 3860 | mem_descr = phba->init_mem; |
| 3861 | i = 0; | ||
| 3862 | j = 0; | ||
| 3863 | for (i = 0; i < SE_MEM_MAX; i++) { | 3861 | for (i = 0; i < SE_MEM_MAX; i++) { |
| 3864 | for (j = mem_descr->num_elements; j > 0; j--) { | 3862 | for (j = mem_descr->num_elements; j > 0; j--) { |
| 3865 | dma_free_coherent(&phba->pcidev->dev, | 3863 | dma_free_coherent(&phba->pcidev->dev, |
| @@ -5318,7 +5316,7 @@ static int beiscsi_enable_port(struct beiscsi_hba *phba) · 1452 unmodified lines | |||
| 5318 | /* Re-enable UER. If different TPE occurs then it is recoverable. */ | 5316 | /* Re-enable UER. If different TPE occurs then it is recoverable. */ |
| 5319 | beiscsi_set_uer_feature(phba); | 5317 | beiscsi_set_uer_feature(phba); |
| 5320 | 5318 | ||
| 5321 | phba->shost->max_id = phba->params.cxns_per_ctrl; | 5319 | phba->shost->max_id = phba->params.cxns_per_ctrl - 1; |
| 5322 | phba->shost->can_queue = phba->params.ios_per_ctrl; | 5320 | phba->shost->can_queue = phba->params.ios_per_ctrl; |
| 5323 | ret = beiscsi_init_port(phba); | 5321 | ret = beiscsi_init_port(phba); |
| 5324 | if (ret < 0) { | 5322 | if (ret < 0) { |
| @@ -5809,6 +5807,7 @@ struct iscsi_transport beiscsi_iscsi_transport = { · 484 unmodified lines | |||
| 5809 | .destroy_session = beiscsi_session_destroy, | 5807 | .destroy_session = beiscsi_session_destroy, |
| 5810 | .create_conn = beiscsi_conn_create, | 5808 | .create_conn = beiscsi_conn_create, |
| 5811 | .bind_conn = beiscsi_conn_bind, | 5809 | .bind_conn = beiscsi_conn_bind, |
| 5810 | .unbind_conn = iscsi_conn_unbind, | ||
| 5812 | .destroy_conn = iscsi_conn_teardown, | 5811 | .destroy_conn = iscsi_conn_teardown, |
| 5813 | .attr_is_visible = beiscsi_attr_is_visible, | 5812 | .attr_is_visible = beiscsi_attr_is_visible, |
| 5814 | .set_iface_param = beiscsi_iface_set_param, | 5813 | .set_iface_param = beiscsi_iface_set_param, |
| @@ -871,7 +871,7 @@ enum bfa_port_linkstate_rsn { · 870 unmodified lines | |||
| 871 | 871 | ||
| 872 | /* | 872 | /* |
| 873 | * Initially flash content may be fff. On making LUN mask enable and disable | 873 | * Initially flash content may be fff. On making LUN mask enable and disable |
| 874 | * state chnage. when report lun command is being processed it goes from | 874 | * state change. when report lun command is being processed it goes from |
| 875 | * BFA_LUN_MASK_ACTIVE to BFA_LUN_MASK_FETCH and comes back to | 875 | * BFA_LUN_MASK_ACTIVE to BFA_LUN_MASK_FETCH and comes back to |
| 876 | * BFA_LUN_MASK_ACTIVE. | 876 | * BFA_LUN_MASK_ACTIVE. |
| 877 | */ | 877 | */ |
| @@ -369,13 +369,10 @@ bfa_plog_fchdr(struct bfa_plog_s *plog, enum bfa_plog_mid mid, · 368 unmodified lines | |||
| 369 | enum bfa_plog_eid event, | 369 | enum bfa_plog_eid event, |
| 370 | u16 misc, struct fchs_s *fchdr) | 370 | u16 misc, struct fchs_s *fchdr) |
| 371 | { | 371 | { |
| 372 | struct bfa_plog_rec_s lp; | ||
| 373 | u32 *tmp_int = (u32 *) fchdr; | 372 | u32 *tmp_int = (u32 *) fchdr; |
| 374 | u32 ints[BFA_PL_INT_LOG_SZ]; | 373 | u32 ints[BFA_PL_INT_LOG_SZ]; |
| 375 | 374 | ||
| 376 | if (plog->plog_enabled) { | 375 | if (plog->plog_enabled) { |
| 377 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); | ||
| 378 | |||
| 379 | ints[0] = tmp_int[0]; | 376 | ints[0] = tmp_int[0]; |
| 380 | ints[1] = tmp_int[1]; | 377 | ints[1] = tmp_int[1]; |
| 381 | ints[2] = tmp_int[4]; | 378 | ints[2] = tmp_int[4]; |
| @@ -389,13 +386,10 @@ bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid, · 7 unmodified lines | |||
| 389 | enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr, | 386 | enum bfa_plog_eid event, u16 misc, struct fchs_s *fchdr, |
| 390 | u32 pld_w0) | 387 | u32 pld_w0) |
| 391 | { | 388 | { |
| 392 | struct bfa_plog_rec_s lp; | ||
| 393 | u32 *tmp_int = (u32 *) fchdr; | 389 | u32 *tmp_int = (u32 *) fchdr; |
| 394 | u32 ints[BFA_PL_INT_LOG_SZ]; | 390 | u32 ints[BFA_PL_INT_LOG_SZ]; |
| 395 | 391 | ||
| 396 | if (plog->plog_enabled) { | 392 | if (plog->plog_enabled) { |
| 397 | memset(&lp, 0, sizeof(struct bfa_plog_rec_s)); | ||
| 398 | |||
| 399 | ints[0] = tmp_int[0]; | 393 | ints[0] = tmp_int[0]; |
| 400 | ints[1] = tmp_int[1]; | 394 | ints[1] = tmp_int[1]; |
| 401 | ints[2] = tmp_int[4]; | 395 | ints[2] = tmp_int[4]; |
| @@ -3173,7 +3167,7 @@ bfa_fcport_send_enable(struct bfa_fcport_s *fcport) · 2771 unmodified lines | |||
| 3173 | m->port_cfg = fcport->cfg; | 3167 | m->port_cfg = fcport->cfg; |
| 3174 | m->msgtag = fcport->msgtag; | 3168 | m->msgtag = fcport->msgtag; |
| 3175 | m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize); | 3169 | m->port_cfg.maxfrsize = cpu_to_be16(fcport->cfg.maxfrsize); |
| 3176 | m->use_flash_cfg = fcport->use_flash_cfg; | 3170 | m->use_flash_cfg = fcport->use_flash_cfg; |
| 3177 | bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa); | 3171 | bfa_dma_be_addr_set(m->stats_dma_addr, fcport->stats_pa); |
| 3178 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo); | 3172 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_lo); |
| 3179 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi); | 3173 | bfa_trc(fcport->bfa, m->stats_dma_addr.a32.addr_hi); |
| @@ -791,7 +791,7 @@ struct bnx2i_hba *bnx2i_alloc_hba(struct cnic_dev *cnic) · 790 unmodified lines | |||
| 791 | return NULL; | 791 | return NULL; |
| 792 | shost->dma_boundary = cnic->pcidev->dma_mask; | 792 | shost->dma_boundary = cnic->pcidev->dma_mask; |
| 793 | shost->transportt = bnx2i_scsi_xport_template; | 793 | shost->transportt = bnx2i_scsi_xport_template; |
| 794 | shost->max_id = ISCSI_MAX_CONNS_PER_HBA; | 794 | shost->max_id = ISCSI_MAX_CONNS_PER_HBA - 1; |
| 795 | shost->max_channel = 0; | 795 | shost->max_channel = 0; |
| 796 | shost->max_lun = 512; | 796 | shost->max_lun = 512; |
| 797 | shost->max_cmd_len = 16; | 797 | shost->max_cmd_len = 16; |
| @@ -1420,17 +1420,23 @@ static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session, · 622 unmodified lines | |||
| 1420 | * Forcefully terminate all in progress connection recovery at the | 1420 | * Forcefully terminate all in progress connection recovery at the |
| 1421 | * earliest, either in bind(), send_pdu(LOGIN), or conn_start() | 1421 | * earliest, either in bind(), send_pdu(LOGIN), or conn_start() |
| 1422 | */ | 1422 | */ |
| 1423 | if (bnx2i_adapter_ready(hba)) | 1423 | if (bnx2i_adapter_ready(hba)) { |
| 1424 | return -EIO; | 1424 | ret_code = -EIO; |
| 1425 | goto put_ep; | ||
| 1426 | } | ||
| 1425 | 1427 | ||
| 1426 | bnx2i_ep = ep->dd_data; | 1428 | bnx2i_ep = ep->dd_data; |
| 1427 | if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) || | 1429 | if ((bnx2i_ep->state == EP_STATE_TCP_FIN_RCVD) || |
| 1428 | (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD)) | 1430 | (bnx2i_ep->state == EP_STATE_TCP_RST_RCVD)) { |
| 1429 | /* Peer disconnect via' FIN or RST */ | 1431 | /* Peer disconnect via' FIN or RST */ |
| 1430 | return -EINVAL; | 1432 | ret_code = -EINVAL; |
| 1433 | goto put_ep; | ||
| 1434 | } | ||
| 1431 | 1435 | ||
| 1432 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) | 1436 | if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) { |
| 1433 | return -EINVAL; | 1437 | ret_code = -EINVAL; |
| 1438 | goto put_ep; | ||
| 1439 | } | ||
| 1434 | 1440 | ||
| 1435 | if (bnx2i_ep->hba != hba) { | 1441 | if (bnx2i_ep->hba != hba) { |
| 1436 | /* Error - TCP connection does not belong to this device | 1442 | /* Error - TCP connection does not belong to this device |
| @@ -1441,7 +1447,8 @@ static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session, · 4 unmodified lines | |||
| 1441 | iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data, | 1447 | iscsi_conn_printk(KERN_ALERT, cls_conn->dd_data, |
| 1442 | "belong to hba (%s)\n", | 1448 | "belong to hba (%s)\n", |
| 1443 | hba->netdev->name); | 1449 | hba->netdev->name); |
| 1444 | return -EEXIST; | 1450 | ret_code = -EEXIST; |
| 1451 | goto put_ep; | ||
| 1445 | } | 1452 | } |
| 1446 | bnx2i_ep->conn = bnx2i_conn; | 1453 | bnx2i_ep->conn = bnx2i_conn; |
| 1447 | bnx2i_conn->ep = bnx2i_ep; | 1454 | bnx2i_conn->ep = bnx2i_ep; |
| @@ -1458,6 +1465,8 @@ static int bnx2i_conn_bind(struct iscsi_cls_session *cls_session, · 10 unmodified lines | |||
| 1458 | bnx2i_put_rq_buf(bnx2i_conn, 0); | 1465 | bnx2i_put_rq_buf(bnx2i_conn, 0); |
| 1459 | 1466 | ||
| 1460 | bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE); | 1467 | bnx2i_arm_cq_event_coalescing(bnx2i_conn->ep, CNIC_ARM_CQE); |
| 1468 | put_ep: | ||
| 1469 | iscsi_put_endpoint(ep); | ||
| 1461 | return ret_code; | 1470 | return ret_code; |
| 1462 | } | 1471 | } |
| 1463 | 1472 | ||
| @@ -2113,7 +2122,6 @@ static void bnx2i_ep_disconnect(struct iscsi_endpoint *ep) · 649 unmodified lines | |||
| 2113 | { | 2122 | { |
| 2114 | struct bnx2i_endpoint *bnx2i_ep; | 2123 | struct bnx2i_endpoint *bnx2i_ep; |
| 2115 | struct bnx2i_conn *bnx2i_conn = NULL; | 2124 | struct bnx2i_conn *bnx2i_conn = NULL; |
| 2116 | struct iscsi_conn *conn = NULL; | ||
| 2117 | struct bnx2i_hba *hba; | 2125 | struct bnx2i_hba *hba; |
| 2118 | 2126 | ||
| 2119 | bnx2i_ep = ep->dd_data; | 2127 | bnx2i_ep = ep->dd_data; |
| @@ -2126,11 +2134,8 @@ static void bnx2i_ep_disconnect(struct iscsi_endpoint *ep) · 6 unmodified lines | |||
| 2126 | !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ))) | 2134 | !time_after(jiffies, bnx2i_ep->timestamp + (12 * HZ))) |
| 2127 | msleep(250); | 2135 | msleep(250); |
| 2128 | 2136 | ||
| 2129 | if (bnx2i_ep->conn) { | 2137 | if (bnx2i_ep->conn) |
| 2130 | bnx2i_conn = bnx2i_ep->conn; | 2138 | bnx2i_conn = bnx2i_ep->conn; |
| 2131 | conn = bnx2i_conn->cls_conn->dd_data; | ||
| 2132 | iscsi_suspend_queue(conn); | ||
| 2133 | } | ||
| 2134 | hba = bnx2i_ep->hba; | 2139 | hba = bnx2i_ep->hba; |
| 2135 | 2140 | ||
| 2136 | mutex_lock(&hba->net_dev_lock); | 2141 | mutex_lock(&hba->net_dev_lock); |
| @@ -2276,6 +2281,7 @@ struct iscsi_transport bnx2i_iscsi_transport = { · 139 unmodified lines | |||
| 2276 | .destroy_session = bnx2i_session_destroy, | 2281 | .destroy_session = bnx2i_session_destroy, |
| 2277 | .create_conn = bnx2i_conn_create, | 2282 | .create_conn = bnx2i_conn_create, |
| 2278 | .bind_conn = bnx2i_conn_bind, | 2283 | .bind_conn = bnx2i_conn_bind, |
| 2284 | .unbind_conn = iscsi_conn_unbind, | ||
| 2279 | .destroy_conn = bnx2i_conn_destroy, | 2285 | .destroy_conn = bnx2i_conn_destroy, |
| 2280 | .attr_is_visible = bnx2i_attr_is_visible, | 2286 | .attr_is_visible = bnx2i_attr_is_visible, |
| 2281 | .set_param = iscsi_set_param, | 2287 | .set_param = iscsi_set_param, |
| @@ -198,8 +198,9 @@ ch_do_scsi(scsi_changer *ch, unsigned char *cmd, int cmd_len, · 197 unmodified lines | |||
| 198 | result = scsi_execute_req(ch->device, cmd, direction, buffer, | 198 | result = scsi_execute_req(ch->device, cmd, direction, buffer, |
| 199 | buflength, &sshdr, timeout * HZ, | 199 | buflength, &sshdr, timeout * HZ, |
| 200 | MAX_RETRIES, NULL); | 200 | MAX_RETRIES, NULL); |
| 201 | 201 | if (result < 0) | |
| 202 | if (driver_byte(result) == DRIVER_SENSE) { | 202 | return result; |
| 203 | if (scsi_sense_valid(&sshdr)) { | ||
| 203 | if (debug) | 204 | if (debug) |
| 204 | scsi_print_sense_hdr(ch->device, ch->name, &sshdr); | 205 | scsi_print_sense_hdr(ch->device, ch->name, &sshdr); |
| 205 | errno = ch_find_errno(&sshdr); | 206 | errno = ch_find_errno(&sshdr); |
| @@ -406,14 +406,10 @@ static const char * const hostbyte_table[]={ · 405 unmodified lines | |||
| 406 | "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE", | 406 | "DID_TRANSPORT_DISRUPTED", "DID_TRANSPORT_FAILFAST", "DID_TARGET_FAILURE", |
| 407 | "DID_NEXUS_FAILURE", "DID_ALLOC_FAILURE", "DID_MEDIUM_ERROR" }; | 407 | "DID_NEXUS_FAILURE", "DID_ALLOC_FAILURE", "DID_MEDIUM_ERROR" }; |
| 408 | 408 | ||
| 409 | static const char * const driverbyte_table[]={ | ||
| 410 | "DRIVER_OK", "DRIVER_BUSY", "DRIVER_SOFT", "DRIVER_MEDIA", "DRIVER_ERROR", | ||
| 411 | "DRIVER_INVALID", "DRIVER_TIMEOUT", "DRIVER_HARD", "DRIVER_SENSE"}; | ||
| 412 | |||
| 413 | const char *scsi_hostbyte_string(int result) | 409 | const char *scsi_hostbyte_string(int result) |
| 414 | { | 410 | { |
| 411 | enum scsi_host_status hb = host_byte(result); | ||
| 415 | const char *hb_string = NULL; | 412 | const char *hb_string = NULL; |
| 416 | int hb = host_byte(result); | ||
| 417 | 413 | ||
| 418 | if (hb < ARRAY_SIZE(hostbyte_table)) | 414 | if (hb < ARRAY_SIZE(hostbyte_table)) |
| 419 | hb_string = hostbyte_table[hb]; | 415 | hb_string = hostbyte_table[hb]; |
| @@ -421,17 +417,6 @@ const char *scsi_hostbyte_string(int result) · 1 unmodified line | |||
| 421 | } | 417 | } |
| 422 | EXPORT_SYMBOL(scsi_hostbyte_string); | 418 | EXPORT_SYMBOL(scsi_hostbyte_string); |
| 423 | 419 | ||
| 424 | const char *scsi_driverbyte_string(int result) | ||
| 425 | { | ||
| 426 | const char *db_string = NULL; | ||
| 427 | int db = driver_byte(result); | ||
| 428 | |||
| 429 | if (db < ARRAY_SIZE(driverbyte_table)) | ||
| 430 | db_string = driverbyte_table[db]; | ||
| 431 | return db_string; | ||
| 432 | } | ||
| 433 | EXPORT_SYMBOL(scsi_driverbyte_string); | ||
| 434 | |||
| 435 | #define scsi_mlreturn_name(result) { result, #result } | 420 | #define scsi_mlreturn_name(result) { result, #result } |
| 436 | static const struct value_name_pair scsi_mlreturn_arr[] = { | 421 | static const struct value_name_pair scsi_mlreturn_arr[] = { |
| 437 | scsi_mlreturn_name(NEEDS_RETRY), | 422 | scsi_mlreturn_name(NEEDS_RETRY), |
| @@ -117,6 +117,7 @@ static struct iscsi_transport cxgb3i_iscsi_transport = { · 116 unmodified lines | |||
| 117 | /* connection management */ | 117 | /* connection management */ |
| 118 | .create_conn = cxgbi_create_conn, | 118 | .create_conn = cxgbi_create_conn, |
| 119 | .bind_conn = cxgbi_bind_conn, | 119 | .bind_conn = cxgbi_bind_conn, |
| 120 | .unbind_conn = iscsi_conn_unbind, | ||
| 120 | .destroy_conn = iscsi_tcp_conn_teardown, | 121 | .destroy_conn = iscsi_tcp_conn_teardown, |
| 121 | .start_conn = iscsi_conn_start, | 122 | .start_conn = iscsi_conn_start, |
| 122 | .stop_conn = iscsi_conn_stop, | 123 | .stop_conn = iscsi_conn_stop, |
| @@ -134,6 +134,7 @@ static struct iscsi_transport cxgb4i_iscsi_transport = { · 133 unmodified lines | |||
| 134 | /* connection management */ | 134 | /* connection management */ |
| 135 | .create_conn = cxgbi_create_conn, | 135 | .create_conn = cxgbi_create_conn, |
| 136 | .bind_conn = cxgbi_bind_conn, | 136 | .bind_conn = cxgbi_bind_conn, |
| 137 | .unbind_conn = iscsi_conn_unbind, | ||
| 137 | .destroy_conn = iscsi_tcp_conn_teardown, | 138 | .destroy_conn = iscsi_tcp_conn_teardown, |
| 138 | .start_conn = iscsi_conn_start, | 139 | .start_conn = iscsi_conn_start, |
| 139 | .stop_conn = iscsi_conn_stop, | 140 | .stop_conn = iscsi_conn_stop, |
| @@ -337,7 +337,7 @@ void cxgbi_hbas_remove(struct cxgbi_device *cdev) · 336 unmodified lines | |||
| 337 | EXPORT_SYMBOL_GPL(cxgbi_hbas_remove); | 337 | EXPORT_SYMBOL_GPL(cxgbi_hbas_remove); |
| 338 | 338 | ||
| 339 | int cxgbi_hbas_add(struct cxgbi_device *cdev, u64 max_lun, | 339 | int cxgbi_hbas_add(struct cxgbi_device *cdev, u64 max_lun, |
| 340 | unsigned int max_id, struct scsi_host_template *sht, | 340 | unsigned int max_conns, struct scsi_host_template *sht, |
| 341 | struct scsi_transport_template *stt) | 341 | struct scsi_transport_template *stt) |
| 342 | { | 342 | { |
| 343 | struct cxgbi_hba *chba; | 343 | struct cxgbi_hba *chba; |
| @@ -357,7 +357,7 @@ int cxgbi_hbas_add(struct cxgbi_device *cdev, u64 max_lun, · 13 unmodified lines | |||
| 357 | 357 | ||
| 358 | shost->transportt = stt; | 358 | shost->transportt = stt; |
| 359 | shost->max_lun = max_lun; | 359 | shost->max_lun = max_lun; |
| 360 | shost->max_id = max_id; | 360 | shost->max_id = max_conns - 1; |
| 361 | shost->max_channel = 0; | 361 | shost->max_channel = 0; |
| 362 | shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE; | 362 | shost->max_cmd_len = SCSI_MAX_VARLEN_CDB_SIZE; |
| 363 | 363 | ||
| @@ -2690,11 +2690,13 @@ int cxgbi_bind_conn(struct iscsi_cls_session *cls_session, · 2326 unmodified lines | |||
| 2690 | err = csk->cdev->csk_ddp_setup_pgidx(csk, csk->tid, | 2690 | err = csk->cdev->csk_ddp_setup_pgidx(csk, csk->tid, |
| 2691 | ppm->tformat.pgsz_idx_dflt); | 2691 | ppm->tformat.pgsz_idx_dflt); |
| 2692 | if (err < 0) | 2692 | if (err < 0) |
| 2693 | return err; | 2693 | goto put_ep; |
| 2694 | 2694 | ||
| 2695 | err = iscsi_conn_bind(cls_session, cls_conn, is_leading); | 2695 | err = iscsi_conn_bind(cls_session, cls_conn, is_leading); |
| 2696 | if (err) | 2696 | if (err) { |
| 2697 | return -EINVAL; | 2697 | err = -EINVAL; |
| 2698 | goto put_ep; | ||
| 2699 | } | ||
| 2698 | 2700 | ||
| 2699 | /* calculate the tag idx bits needed for this conn based on cmds_max */ | 2701 | /* calculate the tag idx bits needed for this conn based on cmds_max */ |
| 2700 | cconn->task_idx_bits = (__ilog2_u32(conn->session->cmds_max - 1)) + 1; | 2702 | cconn->task_idx_bits = (__ilog2_u32(conn->session->cmds_max - 1)) + 1; |
| @@ -2715,7 +2717,9 @@ int cxgbi_bind_conn(struct iscsi_cls_session *cls_session, · 14 unmodified lines | |||
| 2715 | /* init recv engine */ | 2717 | /* init recv engine */ |
| 2716 | iscsi_tcp_hdr_recv_prep(tcp_conn); | 2718 | iscsi_tcp_hdr_recv_prep(tcp_conn); |
| 2717 | 2719 | ||
| 2718 | return 0; | 2720 | put_ep: |
| 2721 | iscsi_put_endpoint(ep); | ||
| 2722 | return err; | ||
| 2719 | } | 2723 | } |
| 2720 | EXPORT_SYMBOL_GPL(cxgbi_bind_conn); | 2724 | EXPORT_SYMBOL_GPL(cxgbi_bind_conn); |
| 2721 | 2725 | ||
| @@ -2968,7 +2972,6 @@ void cxgbi_ep_disconnect(struct iscsi_endpoint *ep) · 246 unmodified lines | |||
| 2968 | ep, cep, cconn, csk, csk->state, csk->flags); | 2972 | ep, cep, cconn, csk, csk->state, csk->flags); |
| 2969 | 2973 | ||
| 2970 | if (cconn && cconn->iconn) { | 2974 | if (cconn && cconn->iconn) { |
| 2971 | iscsi_suspend_tx(cconn->iconn); | ||
| 2972 | write_lock_bh(&csk->callback_lock); | 2975 | write_lock_bh(&csk->callback_lock); |
| 2973 | cep->csk->user_data = NULL; | 2976 | cep->csk->user_data = NULL; |
| 2974 | cconn->cep = NULL; | 2977 | cconn->cep = NULL; |
| @@ -369,8 +369,7 @@ retry: · 368 unmodified lines | |||
| 369 | goto out; | 369 | goto out; |
| 370 | } | 370 | } |
| 371 | 371 | ||
| 372 | if (driver_byte(result) == DRIVER_SENSE) { | 372 | if (result > 0 && scsi_sense_valid(&sshdr)) { |
| 373 | result &= ~(0xFF<<24); /* DRIVER_SENSE is not an error */ | ||
| 374 | if (result & SAM_STAT_CHECK_CONDITION) { | 373 | if (result & SAM_STAT_CHECK_CONDITION) { |
| 375 | switch (sshdr.sense_key) { | 374 | switch (sshdr.sense_key) { |
| 376 | case NO_SENSE: | 375 | case NO_SENSE: |
| @@ -160,22 +160,6 @@ · 159 unmodified lines | |||
| 160 | #define DC395x_write16(acb,address,value) outw((value), acb->io_port_base + (address)) | 160 | #define DC395x_write16(acb,address,value) outw((value), acb->io_port_base + (address)) |
| 161 | #define DC395x_write32(acb,address,value) outl((value), acb->io_port_base + (address)) | 161 | #define DC395x_write32(acb,address,value) outl((value), acb->io_port_base + (address)) |
| 162 | 162 | ||
| 163 | /* cmd->result */ | ||
| 164 | #define RES_TARGET 0x000000FF /* Target State */ | ||
| 165 | #define RES_TARGET_LNX STATUS_MASK /* Only official ... */ | ||
| 166 | #define RES_ENDMSG 0x0000FF00 /* End Message */ | ||
| 167 | #define RES_DID 0x00FF0000 /* DID_ codes */ | ||
| 168 | #define RES_DRV 0xFF000000 /* DRIVER_ codes */ | ||
| 169 | |||
| 170 | #define MK_RES(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)) | ||
| 171 | #define MK_RES_LNX(drv,did,msg,tgt) ((int)(drv)<<24 | (int)(did)<<16 | (int)(msg)<<8 | (int)(tgt)<<1) | ||
| 172 | |||
| 173 | #define SET_RES_TARGET(who,tgt) { who &= ~RES_TARGET; who |= (int)(tgt); } | ||
| 174 | #define SET_RES_TARGET_LNX(who,tgt) { who &= ~RES_TARGET_LNX; who |= (int)(tgt) << 1; } | ||
| 175 | #define SET_RES_MSG(who,msg) { who &= ~RES_ENDMSG; who |= (int)(msg) << 8; } | ||
| 176 | #define SET_RES_DID(who,did) { who &= ~RES_DID; who |= (int)(did) << 16; } | ||
| 177 | #define SET_RES_DRV(who,drv) { who &= ~RES_DRV; who |= (int)(drv) << 24; } | ||
| 178 | |||
| 179 | #define TAG_NONE 255 | 163 | #define TAG_NONE 255 |
| 180 | 164 | ||
| 181 | /* | 165 | /* |
| @@ -986,7 +970,7 @@ static int dc395x_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct s · 804 unmodified lines | |||
| 986 | cmd, cmd->device->id, (u8)cmd->device->lun, cmd->cmnd[0]); | 970 | cmd, cmd->device->id, (u8)cmd->device->lun, cmd->cmnd[0]); |
| 987 | 971 | ||
| 988 | /* Assume BAD_TARGET; will be cleared later */ | 972 | /* Assume BAD_TARGET; will be cleared later */ |
| 989 | cmd->result = DID_BAD_TARGET << 16; | 973 | set_host_byte(cmd, DID_BAD_TARGET); |
| 990 | 974 | ||
| 991 | /* ignore invalid targets */ | 975 | /* ignore invalid targets */ |
| 992 | if (cmd->device->id >= acb->scsi_host->max_id || | 976 | if (cmd->device->id >= acb->scsi_host->max_id || |
| @@ -1013,7 +997,8 @@ static int dc395x_queue_command_lck(struct scsi_cmnd *cmd, void (*done)(struct s · 20 unmodified lines | |||
| 1013 | 997 | ||
| 1014 | /* set callback and clear result in the command */ | 998 | /* set callback and clear result in the command */ |
| 1015 | cmd->scsi_done = done; | 999 | cmd->scsi_done = done; |
| 1016 | cmd->result = 0; | 1000 | set_host_byte(cmd, DID_OK); |
| 1001 | set_status_byte(cmd, SAM_STAT_GOOD); | ||
| 1017 | 1002 | ||
| 1018 | srb = list_first_entry_or_null(&acb->srb_free_list, | 1003 | srb = list_first_entry_or_null(&acb->srb_free_list, |
| 1019 | struct ScsiReqBlk, list); | 1004 | struct ScsiReqBlk, list); |
| @@ -1250,7 +1235,7 @@ static int dc395x_eh_abort(struct scsi_cmnd *cmd) · 230 unmodified lines | |||
| 1250 | free_tag(dcb, srb); | 1235 | free_tag(dcb, srb); |
| 1251 | list_add_tail(&srb->list, &acb->srb_free_list); | 1236 | list_add_tail(&srb->list, &acb->srb_free_list); |
| 1252 | dprintkl(KERN_DEBUG, "eh_abort: Command was waiting\n"); | 1237 | dprintkl(KERN_DEBUG, "eh_abort: Command was waiting\n"); |
| 1253 | cmd->result = DID_ABORT << 16; | 1238 | set_host_byte(cmd, DID_ABORT); |
| 1254 | return SUCCESS; | 1239 | return SUCCESS; |
| 1255 | } | 1240 | } |
| 1256 | srb = find_cmd(cmd, &dcb->srb_going_list); | 1241 | srb = find_cmd(cmd, &dcb->srb_going_list); |
| @@ -3178,6 +3163,8 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 1921 unmodified lines | |||
| 3178 | srb, scsi_sg_count(cmd), srb->sg_index, srb->sg_count, | 3163 | srb, scsi_sg_count(cmd), srb->sg_index, srb->sg_count, |
| 3179 | scsi_sgtalbe(cmd)); | 3164 | scsi_sgtalbe(cmd)); |
| 3180 | status = srb->target_status; | 3165 | status = srb->target_status; |
| 3166 | set_host_byte(cmd, DID_OK); | ||
| 3167 | set_status_byte(cmd, SAM_STAT_GOOD); | ||
| 3181 | if (srb->flag & AUTO_REQSENSE) { | 3168 | if (srb->flag & AUTO_REQSENSE) { |
| 3182 | dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE1\n"); | 3169 | dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE1\n"); |
| 3183 | pci_unmap_srb_sense(acb, srb); | 3170 | pci_unmap_srb_sense(acb, srb); |
| @@ -3186,7 +3173,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 2 unmodified lines | |||
| 3186 | */ | 3173 | */ |
| 3187 | srb->flag &= ~AUTO_REQSENSE; | 3174 | srb->flag &= ~AUTO_REQSENSE; |
| 3188 | srb->adapter_status = 0; | 3175 | srb->adapter_status = 0; |
| 3189 | srb->target_status = CHECK_CONDITION << 1; | 3176 | srb->target_status = SAM_STAT_CHECK_CONDITION; |
| 3190 | if (debug_enabled(DBG_1)) { | 3177 | if (debug_enabled(DBG_1)) { |
| 3191 | switch (cmd->sense_buffer[2] & 0x0f) { | 3178 | switch (cmd->sense_buffer[2] & 0x0f) { |
| 3192 | case NOT_READY: | 3179 | case NOT_READY: |
| @@ -3233,22 +3220,13 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 40 unmodified lines | |||
| 3233 | *((unsigned int *)(cmd->sense_buffer + 3))); | 3220 | *((unsigned int *)(cmd->sense_buffer + 3))); |
| 3234 | } | 3221 | } |
| 3235 | 3222 | ||
| 3236 | if (status == (CHECK_CONDITION << 1)) { | 3223 | if (status == SAM_STAT_CHECK_CONDITION) { |
| 3237 | cmd->result = DID_BAD_TARGET << 16; | 3224 | set_host_byte(cmd, DID_BAD_TARGET); |
| 3238 | goto ckc_e; | 3225 | goto ckc_e; |
| 3239 | } | 3226 | } |
| 3240 | dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n"); | 3227 | dprintkdbg(DBG_0, "srb_done: AUTO_REQSENSE2\n"); |
| 3241 | 3228 | ||
| 3242 | if (srb->total_xfer_length | 3229 | set_status_byte(cmd, SAM_STAT_CHECK_CONDITION); |
| 3243 | && srb->total_xfer_length >= cmd->underflow) | ||
| 3244 | cmd->result = | ||
| 3245 | MK_RES_LNX(DRIVER_SENSE, DID_OK, | ||
| 3246 | srb->end_message, CHECK_CONDITION); | ||
| 3247 | /*SET_RES_DID(cmd->result,DID_OK) */ | ||
| 3248 | else | ||
| 3249 | cmd->result = | ||
| 3250 | MK_RES_LNX(DRIVER_SENSE, DID_OK, | ||
| 3251 | srb->end_message, CHECK_CONDITION); | ||
| 3252 | 3230 | ||
| 3253 | goto ckc_e; | 3231 | goto ckc_e; |
| 3254 | } | 3232 | } |
| @@ -3258,10 +3236,10 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 3 unmodified lines | |||
| 3258 | /* | 3236 | /* |
| 3259 | * target status.......................... | 3237 | * target status.......................... |
| 3260 | */ | 3238 | */ |
| 3261 | if (status >> 1 == CHECK_CONDITION) { | 3239 | if (status == SAM_STAT_CHECK_CONDITION) { |
| 3262 | request_sense(acb, dcb, srb); | 3240 | request_sense(acb, dcb, srb); |
| 3263 | return; | 3241 | return; |
| 3264 | } else if (status >> 1 == QUEUE_FULL) { | 3242 | } else if (status == SAM_STAT_TASK_SET_FULL) { |
| 3265 | tempcnt = (u8)list_size(&dcb->srb_going_list); | 3243 | tempcnt = (u8)list_size(&dcb->srb_going_list); |
| 3266 | dprintkl(KERN_INFO, "QUEUE_FULL for dev <%02i-%i> with %i cmnds\n", | 3244 | dprintkl(KERN_INFO, "QUEUE_FULL for dev <%02i-%i> with %i cmnds\n", |
| 3267 | dcb->target_id, dcb->target_lun, tempcnt); | 3245 | dcb->target_id, dcb->target_lun, tempcnt); |
| @@ -3277,13 +3255,11 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 9 unmodified lines | |||
| 3277 | } else if (status == SCSI_STAT_SEL_TIMEOUT) { | 3255 | } else if (status == SCSI_STAT_SEL_TIMEOUT) { |
| 3278 | srb->adapter_status = H_SEL_TIMEOUT; | 3256 | srb->adapter_status = H_SEL_TIMEOUT; |
| 3279 | srb->target_status = 0; | 3257 | srb->target_status = 0; |
| 3280 | cmd->result = DID_NO_CONNECT << 16; | 3258 | set_host_byte(cmd, DID_NO_CONNECT); |
| 3281 | } else { | 3259 | } else { |
| 3282 | srb->adapter_status = 0; | 3260 | srb->adapter_status = 0; |
| 3283 | SET_RES_DID(cmd->result, DID_ERROR); | 3261 | set_host_byte(cmd, DID_ERROR); |
| 3284 | SET_RES_MSG(cmd->result, srb->end_message); | 3262 | set_status_byte(cmd, status); |
| 3285 | SET_RES_TARGET(cmd->result, status); | ||
| 3286 | |||
| 3287 | } | 3263 | } |
| 3288 | } else { | 3264 | } else { |
| 3289 | /* | 3265 | /* |
| @@ -3292,16 +3268,13 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 2 unmodified lines | |||
| 3292 | status = srb->adapter_status; | 3268 | status = srb->adapter_status; |
| 3293 | if (status & H_OVER_UNDER_RUN) { | 3269 | if (status & H_OVER_UNDER_RUN) { |
| 3294 | srb->target_status = 0; | 3270 | srb->target_status = 0; |
| 3295 | SET_RES_DID(cmd->result, DID_OK); | 3271 | scsi_msg_to_host_byte(cmd, srb->end_message); |
| 3296 | SET_RES_MSG(cmd->result, srb->end_message); | ||
| 3297 | } else if (srb->status & PARITY_ERROR) { | 3272 | } else if (srb->status & PARITY_ERROR) { |
| 3298 | SET_RES_DID(cmd->result, DID_PARITY); | 3273 | set_host_byte(cmd, DID_PARITY); |
| 3299 | SET_RES_MSG(cmd->result, srb->end_message); | ||
| 3300 | } else { /* No error */ | 3274 | } else { /* No error */ |
| 3301 | 3275 | ||
| 3302 | srb->adapter_status = 0; | 3276 | srb->adapter_status = 0; |
| 3303 | srb->target_status = 0; | 3277 | srb->target_status = 0; |
| 3304 | SET_RES_DID(cmd->result, DID_OK); | ||
| 3305 | } | 3278 | } |
| 3306 | } | 3279 | } |
| 3307 | 3280 | ||
| @@ -3322,15 +3295,15 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 14 unmodified lines | |||
| 3322 | base = scsi_kmap_atomic_sg(sg, scsi_sg_count(cmd), &offset, &len); | 3295 | base = scsi_kmap_atomic_sg(sg, scsi_sg_count(cmd), &offset, &len); |
| 3323 | ptr = (struct ScsiInqData *)(base + offset); | 3296 | ptr = (struct ScsiInqData *)(base + offset); |
| 3324 | 3297 | ||
| 3325 | if (!ckc_only && (cmd->result & RES_DID) == 0 | 3298 | if (!ckc_only && get_host_byte(cmd) == DID_OK |
| 3326 | && cmd->cmnd[2] == 0 && scsi_bufflen(cmd) >= 8 | 3299 | && cmd->cmnd[2] == 0 && scsi_bufflen(cmd) >= 8 |
| 3327 | && dir != DMA_NONE && ptr && (ptr->Vers & 0x07) >= 2) | 3300 | && dir != DMA_NONE && ptr && (ptr->Vers & 0x07) >= 2) |
| 3328 | dcb->inquiry7 = ptr->Flags; | 3301 | dcb->inquiry7 = ptr->Flags; |
| 3329 | 3302 | ||
| 3330 | /*if( srb->cmd->cmnd[0] == INQUIRY && */ | 3303 | /*if( srb->cmd->cmnd[0] == INQUIRY && */ |
| 3331 | /* (host_byte(cmd->result) == DID_OK || status_byte(cmd->result) & CHECK_CONDITION) ) */ | 3304 | /* (host_byte(cmd->result) == DID_OK || status_byte(cmd->result) & CHECK_CONDITION) ) */ |
| 3332 | if ((cmd->result == (DID_OK << 16) || | 3305 | if ((get_host_byte(cmd) == DID_OK) || |
| 3333 | status_byte(cmd->result) == CHECK_CONDITION)) { | 3306 | (get_status_byte(cmd) == SAM_STAT_CHECK_CONDITION)) { |
| 3334 | if (!dcb->init_tcq_flag) { | 3307 | if (!dcb->init_tcq_flag) { |
| 3335 | add_dev(acb, dcb, ptr); | 3308 | add_dev(acb, dcb, ptr); |
| 3336 | dcb->init_tcq_flag = 1; | 3309 | dcb->init_tcq_flag = 1; |
| @@ -3357,7 +3330,7 @@ static void srb_done(struct AdapterCtlBlk *acb, struct DeviceCtlBlk *dcb, · 20 unmodified lines | |||
| 3357 | if (srb != acb->tmp_srb) { | 3330 | if (srb != acb->tmp_srb) { |
| 3358 | /* Add to free list */ | 3331 | /* Add to free list */ |
| 3359 | dprintkdbg(DBG_0, "srb_done: (0x%p) done result=0x%08x\n", | 3332 | dprintkdbg(DBG_0, "srb_done: (0x%p) done result=0x%08x\n", |
| 3360 | cmd, cmd->result); | 3333 | cmd, cmd->result); |
| 3361 | list_move_tail(&srb->list, &acb->srb_free_list); | 3334 | list_move_tail(&srb->list, &acb->srb_free_list); |
| 3362 | } else { | 3335 | } else { |
| 3363 | dprintkl(KERN_ERR, "srb_done: ERROR! Completed cmd with tmp_srb\n"); | 3336 | dprintkl(KERN_ERR, "srb_done: ERROR! Completed cmd with tmp_srb\n"); |
| @@ -3381,16 +3354,14 @@ static void doing_srb_done(struct AdapterCtlBlk *acb, u8 did_flag, · 17 unmodified lines | |||
| 3381 | struct scsi_cmnd *p; | 3354 | struct scsi_cmnd *p; |
| 3382 | 3355 | ||
| 3383 | list_for_each_entry_safe(srb, tmp, &dcb->srb_going_list, list) { | 3356 | list_for_each_entry_safe(srb, tmp, &dcb->srb_going_list, list) { |
| 3384 | int result; | ||
| 3385 | |||
| 3386 | p = srb->cmd; | 3357 | p = srb->cmd; |
| 3387 | result = MK_RES(0, did_flag, 0, 0); | ||
| 3388 | printk("G:%p(%02i-%i) ", p, | 3358 | printk("G:%p(%02i-%i) ", p, |
| 3389 | p->device->id, (u8)p->device->lun); | 3359 | p->device->id, (u8)p->device->lun); |
| 3390 | list_del(&srb->list); | 3360 | list_del(&srb->list); |
| 3391 | free_tag(dcb, srb); | 3361 | free_tag(dcb, srb); |
| 3392 | list_add_tail(&srb->list, &acb->srb_free_list); | 3362 | list_add_tail(&srb->list, &acb->srb_free_list); |
| 3393 | p->result = result; | 3363 | set_host_byte(p, did_flag); |
| 3364 | set_status_byte(p, SAM_STAT_GOOD); | ||
| 3394 | pci_unmap_srb_sense(acb, srb); | 3365 | pci_unmap_srb_sense(acb, srb); |
| 3395 | pci_unmap_srb(acb, srb); | 3366 | pci_unmap_srb(acb, srb); |
| 3396 | if (force) { | 3367 | if (force) { |
| @@ -3411,14 +3382,13 @@ static void doing_srb_done(struct AdapterCtlBlk *acb, u8 did_flag, · 14 unmodified lines | |||
| 3411 | 3382 | ||
| 3412 | /* Waiting queue */ | 3383 | /* Waiting queue */ |
| 3413 | list_for_each_entry_safe(srb, tmp, &dcb->srb_waiting_list, list) { | 3384 | list_for_each_entry_safe(srb, tmp, &dcb->srb_waiting_list, list) { |
| 3414 | int result; | ||
| 3415 | p = srb->cmd; | 3385 | p = srb->cmd; |
| 3416 | 3386 | ||
| 3417 | result = MK_RES(0, did_flag, 0, 0); | ||
| 3418 | printk("W:%p<%02i-%i>", p, p->device->id, | 3387 | printk("W:%p<%02i-%i>", p, p->device->id, |
| 3419 | (u8)p->device->lun); | 3388 | (u8)p->device->lun); |
| 3420 | list_move_tail(&srb->list, &acb->srb_free_list); | 3389 | list_move_tail(&srb->list, &acb->srb_free_list); |
| 3421 | p->result = result; | 3390 | set_host_byte(p, did_flag); |
| 3391 | set_status_byte(p, SAM_STAT_GOOD); | ||
| 3422 | pci_unmap_srb_sense(acb, srb); | 3392 | pci_unmap_srb_sense(acb, srb); |
| 3423 | pci_unmap_srb(acb, srb); | 3393 | pci_unmap_srb(acb, srb); |
| 3424 | if (force) { | 3394 | if (force) { |
| @@ -88,6 +88,7 @@ struct alua_dh_data { · 87 unmodified lines | |||
| 88 | struct scsi_device *sdev; | 88 | struct scsi_device *sdev; |
| 89 | int init_error; | 89 | int init_error; |
| 90 | struct mutex init_mutex; | 90 | struct mutex init_mutex; |
| 91 | bool disabled; | ||
| 91 | }; | 92 | }; |
| 92 | 93 | ||
| 93 | struct alua_queue_data { | 94 | struct alua_queue_data { |
| @@ -517,7 +518,8 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) · 423 unmodified lines | |||
| 517 | int len, k, off, bufflen = ALUA_RTPG_SIZE; | 518 | int len, k, off, bufflen = ALUA_RTPG_SIZE; |
| 518 | int group_id_old, state_old, pref_old, valid_states_old; | 519 | int group_id_old, state_old, pref_old, valid_states_old; |
| 519 | unsigned char *desc, *buff; | 520 | unsigned char *desc, *buff; |
| 520 | unsigned err, retval; | 521 | unsigned err; |
| 522 | int retval; | ||
| 521 | unsigned int tpg_desc_tbl_off; | 523 | unsigned int tpg_desc_tbl_off; |
| 522 | unsigned char orig_transition_tmo; | 524 | unsigned char orig_transition_tmo; |
| 523 | unsigned long flags; | 525 | unsigned long flags; |
| @@ -562,13 +564,15 @@ static int alua_rtpg(struct scsi_device *sdev, struct alua_port_group *pg) · 38 unmodified lines | |||
| 562 | kfree(buff); | 564 | kfree(buff); |
| 563 | return SCSI_DH_OK; | 565 | return SCSI_DH_OK; |
| 564 | } | 566 | } |
| 565 | if (!scsi_sense_valid(&sense_hdr)) { | 567 | if (retval < 0 || !scsi_sense_valid(&sense_hdr)) { |
| 566 | sdev_printk(KERN_INFO, sdev, | 568 | sdev_printk(KERN_INFO, sdev, |
| 567 | "%s: rtpg failed, result %d\n", | 569 | "%s: rtpg failed, result %d\n", |
| 568 | ALUA_DH_NAME, retval); | 570 | ALUA_DH_NAME, retval); |
| 569 | kfree(buff); | 571 | kfree(buff); |
| 570 | if (driver_byte(retval) == DRIVER_ERROR) | 572 | if (retval < 0) |
| 571 | return SCSI_DH_DEV_TEMP_BUSY; | 573 | return SCSI_DH_DEV_TEMP_BUSY; |
| 574 | if (host_byte(retval) == DID_NO_CONNECT) | ||
| 575 | return SCSI_DH_RES_TEMP_UNAVAIL; | ||
| 572 | return SCSI_DH_IO; | 576 | return SCSI_DH_IO; |
| 573 | } | 577 | } |
| 574 | 578 | ||
| @@ -791,11 +795,11 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg) · 216 unmodified lines | |||
| 791 | retval = submit_stpg(sdev, pg->group_id, &sense_hdr); | 795 | retval = submit_stpg(sdev, pg->group_id, &sense_hdr); |
| 792 | 796 | ||
| 793 | if (retval) { | 797 | if (retval) { |
| 794 | if (!scsi_sense_valid(&sense_hdr)) { | 798 | if (retval < 0 || !scsi_sense_valid(&sense_hdr)) { |
| 795 | sdev_printk(KERN_INFO, sdev, | 799 | sdev_printk(KERN_INFO, sdev, |
| 796 | "%s: stpg failed, result %d", | 800 | "%s: stpg failed, result %d", |
| 797 | ALUA_DH_NAME, retval); | 801 | ALUA_DH_NAME, retval); |
| 798 | if (driver_byte(retval) == DRIVER_ERROR) | 802 | if (retval < 0) |
| 799 | return SCSI_DH_DEV_TEMP_BUSY; | 803 | return SCSI_DH_DEV_TEMP_BUSY; |
| 800 | } else { | 804 | } else { |
| 801 | sdev_printk(KERN_INFO, sdev, "%s: stpg failed\n", | 805 | sdev_printk(KERN_INFO, sdev, "%s: stpg failed\n", |
| @@ -807,6 +811,51 @@ static unsigned alua_stpg(struct scsi_device *sdev, struct alua_port_group *pg) · 5 unmodified lines | |||
| 807 | return SCSI_DH_RETRY; | 811 | return SCSI_DH_RETRY; |
| 808 | } | 812 | } |
| 809 | 813 | ||
| 814 | static bool alua_rtpg_select_sdev(struct alua_port_group *pg) | ||
| 815 | { | ||
| 816 | struct alua_dh_data *h; | ||
| 817 | struct scsi_device *sdev = NULL; | ||
| 818 | |||
| 819 | lockdep_assert_held(&pg->lock); | ||
| 820 | if (WARN_ON(!pg->rtpg_sdev)) | ||
| 821 | return false; | ||
| 822 | |||
| 823 | /* | ||
| 824 | * RCU protection isn't necessary for dh_list here | ||
| 825 | * as we hold pg->lock, but for access to h->pg. | ||
| 826 | */ | ||
| 827 | rcu_read_lock(); | ||
| 828 | list_for_each_entry_rcu(h, &pg->dh_list, node) { | ||
| 829 | if (!h->sdev) | ||
| 830 | continue; | ||
| 831 | if (h->sdev == pg->rtpg_sdev) { | ||
| 832 | h->disabled = true; | ||
| 833 | continue; | ||
| 834 | } | ||
| 835 | if (rcu_dereference(h->pg) == pg && | ||
| 836 | !h->disabled && | ||
| 837 | !scsi_device_get(h->sdev)) { | ||
| 838 | sdev = h->sdev; | ||
| 839 | break; | ||
| 840 | } | ||
| 841 | } | ||
| 842 | rcu_read_unlock(); | ||
| 843 | |||
| 844 | if (!sdev) { | ||
| 845 | pr_warn("%s: no device found for rtpg\n", | ||
| 846 | (pg->device_id_len ? | ||
| 847 | (char *)pg->device_id_str : "(nameless PG)")); | ||
| 848 | return false; | ||
| 849 | } | ||
| 850 | |||
| 851 | sdev_printk(KERN_INFO, sdev, "rtpg retry on different device\n"); | ||
| 852 | |||
| 853 | scsi_device_put(pg->rtpg_sdev); | ||
| 854 | pg->rtpg_sdev = sdev; | ||
| 855 | |||
| 856 | return true; | ||
| 857 | } | ||
| 858 | |||
| 810 | static void alua_rtpg_work(struct work_struct *work) | 859 | static void alua_rtpg_work(struct work_struct *work) |
| 811 | { | 860 | { |
| 812 | struct alua_port_group *pg = | 861 | struct alua_port_group *pg = |
| @@ -815,6 +864,7 @@ static void alua_rtpg_work(struct work_struct *work) · 2 unmodified lines | |||
| 815 | LIST_HEAD(qdata_list); | 864 | LIST_HEAD(qdata_list); |
| 816 | int err = SCSI_DH_OK; | 865 | int err = SCSI_DH_OK; |
| 817 | struct alua_queue_data *qdata, *tmp; | 866 | struct alua_queue_data *qdata, *tmp; |
| 867 | struct alua_dh_data *h; | ||
| 818 | unsigned long flags; | 868 | unsigned long flags; |
| 819 | 869 | ||
| 820 | spin_lock_irqsave(&pg->lock, flags); | 870 | spin_lock_irqsave(&pg->lock, flags); |
| @@ -848,9 +898,18 @@ static void alua_rtpg_work(struct work_struct *work) · 27 unmodified lines | |||
| 848 | } | 898 | } |
| 849 | err = alua_rtpg(sdev, pg); | 899 | err = alua_rtpg(sdev, pg); |
| 850 | spin_lock_irqsave(&pg->lock, flags); | 900 | spin_lock_irqsave(&pg->lock, flags); |
| 851 | if (err == SCSI_DH_RETRY || pg->flags & ALUA_PG_RUN_RTPG) { | 901 | |
| 902 | /* If RTPG failed on the current device, try using another */ | ||
| 903 | if (err == SCSI_DH_RES_TEMP_UNAVAIL && | ||
| 904 | alua_rtpg_select_sdev(pg)) | ||
| 905 | err = SCSI_DH_IMM_RETRY; | ||
| 906 | |||
| 907 | if (err == SCSI_DH_RETRY || err == SCSI_DH_IMM_RETRY || | ||
| 908 | pg->flags & ALUA_PG_RUN_RTPG) { | ||
| 852 | pg->flags &= ~ALUA_PG_RUNNING; | 909 | pg->flags &= ~ALUA_PG_RUNNING; |
| 853 | if (!pg->interval && !(pg->flags & ALUA_PG_RUN_RTPG)) | 910 | if (err == SCSI_DH_IMM_RETRY) |
| 911 | pg->interval = 0; | ||
| 912 | else if (!pg->interval && !(pg->flags & ALUA_PG_RUN_RTPG)) | ||
| 854 | pg->interval = ALUA_RTPG_RETRY_DELAY; | 913 | pg->interval = ALUA_RTPG_RETRY_DELAY; |
| 855 | pg->flags |= ALUA_PG_RUN_RTPG; | 914 | pg->flags |= ALUA_PG_RUN_RTPG; |
| 856 | spin_unlock_irqrestore(&pg->lock, flags); | 915 | spin_unlock_irqrestore(&pg->lock, flags); |
| @@ -878,6 +937,12 @@ static void alua_rtpg_work(struct work_struct *work) · 21 unmodified lines | |||
| 878 | } | 937 | } |
| 879 | 938 | ||
| 880 | list_splice_init(&pg->rtpg_list, &qdata_list); | 939 | list_splice_init(&pg->rtpg_list, &qdata_list); |
| 940 | /* | ||
| 941 | * We went through an RTPG, for good or bad. | ||
| 942 | * Re-enable all devices for the next attempt. | ||
| 943 | */ | ||
| 944 | list_for_each_entry(h, &pg->dh_list, node) | ||
| 945 | h->disabled = false; | ||
| 881 | pg->rtpg_sdev = NULL; | 946 | pg->rtpg_sdev = NULL; |
| 882 | spin_unlock_irqrestore(&pg->lock, flags); | 947 | spin_unlock_irqrestore(&pg->lock, flags); |
| 883 | 948 | ||
| @@ -962,6 +1027,7 @@ static int alua_initialize(struct scsi_device *sdev, struct alua_dh_data *h) · 78 unmodified lines | |||
| 962 | int err = SCSI_DH_DEV_UNSUPP, tpgs; | 1027 | int err = SCSI_DH_DEV_UNSUPP, tpgs; |
| 963 | 1028 | ||
| 964 | mutex_lock(&h->init_mutex); | 1029 | mutex_lock(&h->init_mutex); |
| 1030 | h->disabled = false; | ||
| 965 | tpgs = alua_check_tpgs(sdev); | 1031 | tpgs = alua_check_tpgs(sdev); |
| 966 | if (tpgs != TPGS_MODE_NONE) | 1032 | if (tpgs != TPGS_MODE_NONE) |
| 967 | err = alua_check_vpd(sdev, h, tpgs); | 1033 | err = alua_check_vpd(sdev, h, tpgs); |
| @@ -1080,7 +1146,6 @@ static void alua_check(struct scsi_device *sdev, bool force) · 112 unmodified lines | |||
| 1080 | return; | 1146 | return; |
| 1081 | } | 1147 | } |
| 1082 | rcu_read_unlock(); | 1148 | rcu_read_unlock(); |
| 1083 | |||
| 1084 | alua_rtpg_queue(pg, sdev, NULL, force); | 1149 | alua_rtpg_queue(pg, sdev, NULL, force); |
| 1085 | kref_put(&pg->kref, release_port_group); | 1150 | kref_put(&pg->kref, release_port_group); |
| 1086 | } | 1151 | } |
| @@ -0,0 +1,9 @@ | |||
| 1 | config SCSI_EFCT | ||
| 2 | tristate "Emulex Fibre Channel Target" | ||
| 3 | depends on PCI && SCSI | ||
| 4 | depends on TARGET_CORE | ||
| 5 | depends on SCSI_FC_ATTRS | ||
| 6 | select CRC_T10DIF | ||
| 7 | help | ||
| 8 | The efct driver provides enhanced SCSI Target Mode | ||
| 9 | support for specific SLI-4 adapters. | ||
| @@ -0,0 +1,18 @@ | |||
| 1 | #// SPDX-License-Identifier: GPL-2.0 | ||
| 2 | #/* | ||
| 3 | # * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | # * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | # */ | ||
| 6 | |||
| 7 | |||
| 8 | obj-$(CONFIG_SCSI_EFCT) := efct.o | ||
| 9 | |||
| 10 | efct-objs := efct/efct_driver.o efct/efct_io.o efct/efct_scsi.o \ | ||
| 11 | efct/efct_xport.o efct/efct_hw.o efct/efct_hw_queues.o \ | ||
| 12 | efct/efct_lio.o efct/efct_unsol.o | ||
| 13 | |||
| 14 | efct-objs += libefc/efc_cmds.o libefc/efc_domain.o libefc/efc_fabric.o \ | ||
| 15 | libefc/efc_node.o libefc/efc_nport.o libefc/efc_device.o \ | ||
| 16 | libefc/efclib.o libefc/efc_sm.o libefc/efc_els.o | ||
| 17 | |||
| 18 | efct-objs += libefc_sli/sli4.o | ||
| @@ -0,0 +1,786 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efct_driver.h" | ||
| 8 | |||
| 9 | #include "efct_hw.h" | ||
| 10 | #include "efct_unsol.h" | ||
| 11 | #include "efct_scsi.h" | ||
| 12 | |||
| 13 | LIST_HEAD(efct_devices); | ||
| 14 | |||
| 15 | static int logmask; | ||
| 16 | module_param(logmask, int, 0444); | ||
| 17 | MODULE_PARM_DESC(logmask, "logging bitmask (default 0)"); | ||
| 18 | |||
| 19 | static struct libefc_function_template efct_libefc_templ = { | ||
| 20 | .issue_mbox_rqst = efct_issue_mbox_rqst, | ||
| 21 | .send_els = efct_els_hw_srrs_send, | ||
| 22 | .send_bls = efct_efc_bls_send, | ||
| 23 | |||
| 24 | .new_nport = efct_scsi_tgt_new_nport, | ||
| 25 | .del_nport = efct_scsi_tgt_del_nport, | ||
| 26 | .scsi_new_node = efct_scsi_new_initiator, | ||
| 27 | .scsi_del_node = efct_scsi_del_initiator, | ||
| 28 | .hw_seq_free = efct_efc_hw_sequence_free, | ||
| 29 | }; | ||
| 30 | |||
| 31 | static int | ||
| 32 | efct_device_init(void) | ||
| 33 | { | ||
| 34 | int rc; | ||
| 35 | |||
| 36 | /* driver-wide init for target-server */ | ||
| 37 | rc = efct_scsi_tgt_driver_init(); | ||
| 38 | if (rc) { | ||
| 39 | pr_err("efct_scsi_tgt_init failed rc=%d\n", rc); | ||
| 40 | return rc; | ||
| 41 | } | ||
| 42 | |||
| 43 | rc = efct_scsi_reg_fc_transport(); | ||
| 44 | if (rc) { | ||
| 45 | pr_err("failed to register to FC host\n"); | ||
| 46 | return rc; | ||
| 47 | } | ||
| 48 | |||
| 49 | return 0; | ||
| 50 | } | ||
| 51 | |||
| 52 | static void | ||
| 53 | efct_device_shutdown(void) | ||
| 54 | { | ||
| 55 | efct_scsi_release_fc_transport(); | ||
| 56 | |||
| 57 | efct_scsi_tgt_driver_exit(); | ||
| 58 | } | ||
| 59 | |||
| 60 | static void * | ||
| 61 | efct_device_alloc(u32 nid) | ||
| 62 | { | ||
| 63 | struct efct *efct = NULL; | ||
| 64 | |||
| 65 | efct = kzalloc_node(sizeof(*efct), GFP_KERNEL, nid); | ||
| 66 | if (!efct) | ||
| 67 | return efct; | ||
| 68 | |||
| 69 | INIT_LIST_HEAD(&efct->list_entry); | ||
| 70 | list_add_tail(&efct->list_entry, &efct_devices); | ||
| 71 | |||
| 72 | return efct; | ||
| 73 | } | ||
| 74 | |||
| 75 | static void | ||
| 76 | efct_teardown_msix(struct efct *efct) | ||
| 77 | { | ||
| 78 | u32 i; | ||
| 79 | |||
| 80 | for (i = 0; i < efct->n_msix_vec; i++) { | ||
| 81 | free_irq(pci_irq_vector(efct->pci, i), | ||
| 82 | &efct->intr_context[i]); | ||
| 83 | } | ||
| 84 | |||
| 85 | pci_free_irq_vectors(efct->pci); | ||
| 86 | } | ||
| 87 | |||
| 88 | static int | ||
| 89 | efct_efclib_config(struct efct *efct, struct libefc_function_template *tt) | ||
| 90 | { | ||
| 91 | struct efc *efc; | ||
| 92 | struct sli4 *sli; | ||
| 93 | int rc = 0; | ||
| 94 | |||
| 95 | efc = kzalloc(sizeof(*efc), GFP_KERNEL); | ||
| 96 | if (!efc) | ||
| 97 | return -ENOMEM; | ||
| 98 | |||
| 99 | efct->efcport = efc; | ||
| 100 | |||
| 101 | memcpy(&efc->tt, tt, sizeof(*tt)); | ||
| 102 | efc->base = efct; | ||
| 103 | efc->pci = efct->pci; | ||
| 104 | |||
| 105 | efc->def_wwnn = efct_get_wwnn(&efct->hw); | ||
| 106 | efc->def_wwpn = efct_get_wwpn(&efct->hw); | ||
| 107 | efc->enable_tgt = 1; | ||
| 108 | efc->log_level = EFC_LOG_LIB; | ||
| 109 | |||
| 110 | sli = &efct->hw.sli; | ||
| 111 | efc->max_xfer_size = sli->sge_supported_length * | ||
| 112 | sli_get_max_sgl(&efct->hw.sli); | ||
| 113 | efc->sli = sli; | ||
| 114 | efc->fcfi = efct->hw.fcf_indicator; | ||
| 115 | |||
| 116 | rc = efcport_init(efc); | ||
| 117 | if (rc) | ||
| 118 | efc_log_err(efc, "efcport_init failed\n"); | ||
| 119 | |||
| 120 | return rc; | ||
| 121 | } | ||
| 122 | |||
| 123 | static int efct_request_firmware_update(struct efct *efct); | ||
| 124 | |||
| 125 | static const char* | ||
| 126 | efct_pci_model(u16 device) | ||
| 127 | { | ||
| 128 | switch (device) { | ||
| 129 | case EFCT_DEVICE_LANCER_G6: return "LPE31004"; | ||
| 130 | case EFCT_DEVICE_LANCER_G7: return "LPE36000"; | ||
| 131 | default: return "unknown"; | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | static int | ||
| 136 | efct_device_attach(struct efct *efct) | ||
| 137 | { | ||
| 138 | u32 rc = 0, i = 0; | ||
| 139 | |||
| 140 | if (efct->attached) { | ||
| 141 | efc_log_err(efct, "Device is already attached\n"); | ||
| 142 | return -EIO; | ||
| 143 | } | ||
| 144 | |||
| 145 | snprintf(efct->name, sizeof(efct->name), "[%s%d] ", "fc", | ||
| 146 | efct->instance_index); | ||
| 147 | |||
| 148 | efct->logmask = logmask; | ||
| 149 | efct->filter_def = EFCT_DEFAULT_FILTER; | ||
| 150 | efct->max_isr_time_msec = EFCT_OS_MAX_ISR_TIME_MSEC; | ||
| 151 | |||
| 152 | efct->model = efct_pci_model(efct->pci->device); | ||
| 153 | |||
| 154 | efct->efct_req_fw_upgrade = true; | ||
| 155 | |||
| 156 | /* Allocate transport object and bring online */ | ||
| 157 | efct->xport = efct_xport_alloc(efct); | ||
| 158 | if (!efct->xport) { | ||
| 159 | efc_log_err(efct, "failed to allocate transport object\n"); | ||
| 160 | rc = -ENOMEM; | ||
| 161 | goto out; | ||
| 162 | } | ||
| 163 | |||
| 164 | rc = efct_xport_attach(efct->xport); | ||
| 165 | if (rc) { | ||
| 166 | efc_log_err(efct, "failed to attach transport object\n"); | ||
| 167 | goto xport_out; | ||
| 168 | } | ||
| 169 | |||
| 170 | rc = efct_xport_initialize(efct->xport); | ||
| 171 | if (rc) { | ||
| 172 | efc_log_err(efct, "failed to initialize transport object\n"); | ||
| 173 | goto xport_out; | ||
| 174 | } | ||
| 175 | |||
| 176 | rc = efct_efclib_config(efct, &efct_libefc_templ); | ||
| 177 | if (rc) { | ||
| 178 | efc_log_err(efct, "failed to init efclib\n"); | ||
| 179 | goto efclib_out; | ||
| 180 | } | ||
| 181 | |||
| 182 | for (i = 0; i < efct->n_msix_vec; i++) { | ||
| 183 | efc_log_debug(efct, "irq %d enabled\n", i); | ||
| 184 | enable_irq(pci_irq_vector(efct->pci, i)); | ||
| 185 | } | ||
| 186 | |||
| 187 | efct->attached = true; | ||
| 188 | |||
| 189 | if (efct->efct_req_fw_upgrade) | ||
| 190 | efct_request_firmware_update(efct); | ||
| 191 | |||
| 192 | return rc; | ||
| 193 | |||
| 194 | efclib_out: | ||
| 195 | efct_xport_detach(efct->xport); | ||
| 196 | xport_out: | ||
| 197 | efct_xport_free(efct->xport); | ||
| 198 | efct->xport = NULL; | ||
| 199 | out: | ||
| 200 | return rc; | ||
| 201 | } | ||
| 202 | |||
| 203 | static int | ||
| 204 | efct_device_detach(struct efct *efct) | ||
| 205 | { | ||
| 206 | int i; | ||
| 207 | |||
| 208 | if (!efct || !efct->attached) { | ||
| 209 | pr_err("Device is not attached\n"); | ||
| 210 | return -EIO; | ||
| 211 | } | ||
| 212 | |||
| 213 | if (efct_xport_control(efct->xport, EFCT_XPORT_SHUTDOWN)) | ||
| 214 | efc_log_err(efct, "Transport Shutdown timed out\n"); | ||
| 215 | |||
| 216 | for (i = 0; i < efct->n_msix_vec; i++) | ||
| 217 | disable_irq(pci_irq_vector(efct->pci, i)); | ||
| 218 | |||
| 219 | efct_xport_detach(efct->xport); | ||
| 220 | |||
| 221 | efct_xport_free(efct->xport); | ||
| 222 | efct->xport = NULL; | ||
| 223 | |||
| 224 | efcport_destroy(efct->efcport); | ||
| 225 | kfree(efct->efcport); | ||
| 226 | |||
| 227 | efct->attached = false; | ||
| 228 | |||
| 229 | return 0; | ||
| 230 | } | ||
| 231 | |||
| 232 | static void | ||
| 233 | efct_fw_write_cb(int status, u32 actual_write_length, | ||
| 234 | u32 change_status, void *arg) | ||
| 235 | { | ||
| 236 | struct efct_fw_write_result *result = arg; | ||
| 237 | |||
| 238 | result->status = status; | ||
| 239 | result->actual_xfer = actual_write_length; | ||
| 240 | result->change_status = change_status; | ||
| 241 | |||
| 242 | complete(&result->done); | ||
| 243 | } | ||
| 244 | |||
| 245 | static int | ||
| 246 | efct_firmware_write(struct efct *efct, const u8 *buf, size_t buf_len, | ||
| 247 | u8 *change_status) | ||
| 248 | { | ||
| 249 | int rc = 0; | ||
| 250 | u32 bytes_left; | ||
| 251 | u32 xfer_size; | ||
| 252 | u32 offset; | ||
| 253 | struct efc_dma dma; | ||
| 254 | int last = 0; | ||
| 255 | struct efct_fw_write_result result; | ||
| 256 | |||
| 257 | init_completion(&result.done); | ||
| 258 | |||
| 259 | bytes_left = buf_len; | ||
| 260 | offset = 0; | ||
| 261 | |||
| 262 | dma.size = FW_WRITE_BUFSIZE; | ||
| 263 | dma.virt = dma_alloc_coherent(&efct->pci->dev, | ||
| 264 | dma.size, &dma.phys, GFP_DMA); | ||
| 265 | if (!dma.virt) | ||
| 266 | return -ENOMEM; | ||
| 267 | |||
| 268 | while (bytes_left > 0) { | ||
| 269 | if (bytes_left > FW_WRITE_BUFSIZE) | ||
| 270 | xfer_size = FW_WRITE_BUFSIZE; | ||
| 271 | else | ||
| 272 | xfer_size = bytes_left; | ||
| 273 | |||
| 274 | memcpy(dma.virt, buf + offset, xfer_size); | ||
| 275 | |||
| 276 | if (bytes_left == xfer_size) | ||
| 277 | last = 1; | ||
| 278 | |||
| 279 | efct_hw_firmware_write(&efct->hw, &dma, xfer_size, offset, | ||
| 280 | last, efct_fw_write_cb, &result); | ||
| 281 | |||
| 282 | if (wait_for_completion_interruptible(&result.done) != 0) { | ||
| 283 | rc = -ENXIO; | ||
| 284 | break; | ||
| 285 | } | ||
| 286 | |||
| 287 | if (result.actual_xfer == 0 || result.status != 0) { | ||
| 288 | rc = -EFAULT; | ||
| 289 | break; | ||
| 290 | } | ||
| 291 | |||
| 292 | if (last) | ||
| 293 | *change_status = result.change_status; | ||
| 294 | |||
| 295 | bytes_left -= result.actual_xfer; | ||
| 296 | offset += result.actual_xfer; | ||
| 297 | } | ||
| 298 | |||
| 299 | dma_free_coherent(&efct->pci->dev, dma.size, dma.virt, dma.phys); | ||
| 300 | return rc; | ||
| 301 | } | ||
| 302 | |||
| 303 | static int | ||
| 304 | efct_fw_reset(struct efct *efct) | ||
| 305 | { | ||
| 306 | /* | ||
| 307 | * Firmware reset to activate the new firmware. | ||
| 308 | * Function 0 will update and load the new firmware | ||
| 309 | * during attach. | ||
| 310 | */ | ||
| 311 | if (timer_pending(&efct->xport->stats_timer)) | ||
| 312 | del_timer(&efct->xport->stats_timer); | ||
| 313 | |||
| 314 | if (efct_hw_reset(&efct->hw, EFCT_HW_RESET_FIRMWARE)) { | ||
| 315 | efc_log_info(efct, "failed to reset firmware\n"); | ||
| 316 | return -EIO; | ||
| 317 | } | ||
| 318 | |||
| 319 | efc_log_info(efct, "successfully reset firmware.Now resetting port\n"); | ||
| 320 | |||
| 321 | efct_device_detach(efct); | ||
| 322 | return efct_device_attach(efct); | ||
| 323 | } | ||
| 324 | |||
| 325 | static int | ||
| 326 | efct_request_firmware_update(struct efct *efct) | ||
| 327 | { | ||
| 328 | int rc = 0; | ||
| 329 | u8 file_name[256], fw_change_status = 0; | ||
| 330 | const struct firmware *fw; | ||
| 331 | struct efct_hw_grp_hdr *fw_image; | ||
| 332 | |||
| 333 | snprintf(file_name, 256, "%s.grp", efct->model); | ||
| 334 | |||
| 335 | rc = request_firmware(&fw, file_name, &efct->pci->dev); | ||
| 336 | if (rc) { | ||
| 337 | efc_log_debug(efct, "Firmware file(%s) not found.\n", file_name); | ||
| 338 | return rc; | ||
| 339 | } | ||
| 340 | |||
| 341 | fw_image = (struct efct_hw_grp_hdr *)fw->data; | ||
| 342 | |||
| 343 | if (!strncmp(efct->hw.sli.fw_name[0], fw_image->revision, | ||
| 344 | strnlen(fw_image->revision, 16))) { | ||
| 345 | efc_log_debug(efct, | ||
| 346 | "Skip update. Firmware is already up to date.\n"); | ||
| 347 | goto exit; | ||
| 348 | } | ||
| 349 | |||
| 350 | efc_log_info(efct, "Firmware update is initiated. %s -> %s\n", | ||
| 351 | efct->hw.sli.fw_name[0], fw_image->revision); | ||
| 352 | |||
| 353 | rc = efct_firmware_write(efct, fw->data, fw->size, &fw_change_status); | ||
| 354 | if (rc) { | ||
| 355 | efc_log_err(efct, "Firmware update failed. rc = %d\n", rc); | ||
| 356 | goto exit; | ||
| 357 | } | ||
| 358 | |||
| 359 | efc_log_info(efct, "Firmware updated successfully\n"); | ||
| 360 | switch (fw_change_status) { | ||
| 361 | case 0x00: | ||
| 362 | efc_log_info(efct, "New firmware is active.\n"); | ||
| 363 | break; | ||
| 364 | case 0x01: | ||
| 365 | efc_log_info(efct, | ||
| 366 | "System reboot needed to activate the new firmware\n"); | ||
| 367 | break; | ||
| 368 | case 0x02: | ||
| 369 | case 0x03: | ||
| 370 | efc_log_info(efct, | ||
| 371 | "firmware reset to activate the new firmware\n"); | ||
| 372 | efct_fw_reset(efct); | ||
| 373 | break; | ||
| 374 | default: | ||
| 375 | efc_log_info(efct, "Unexpected value change_status:%d\n", | ||
| 376 | fw_change_status); | ||
| 377 | break; | ||
| 378 | } | ||
| 379 | |||
| 380 | exit: | ||
| 381 | release_firmware(fw); | ||
| 382 | |||
| 383 | return rc; | ||
| 384 | } | ||
| 385 | |||
| 386 | static void | ||
| 387 | efct_device_free(struct efct *efct) | ||
| 388 | { | ||
| 389 | if (efct) { | ||
| 390 | list_del(&efct->list_entry); | ||
| 391 | kfree(efct); | ||
| 392 | } | ||
| 393 | } | ||
| 394 | |||
| 395 | static int | ||
| 396 | efct_device_interrupts_required(struct efct *efct) | ||
| 397 | { | ||
| 398 | int rc; | ||
| 399 | |||
| 400 | rc = efct_hw_setup(&efct->hw, efct, efct->pci); | ||
| 401 | if (rc < 0) | ||
| 402 | return rc; | ||
| 403 | |||
| 404 | return efct->hw.config.n_eq; | ||
| 405 | } | ||
| 406 | |||
| 407 | static irqreturn_t | ||
| 408 | efct_intr_thread(int irq, void *handle) | ||
| 409 | { | ||
| 410 | struct efct_intr_context *intr_ctx = handle; | ||
| 411 | struct efct *efct = intr_ctx->efct; | ||
| 412 | |||
| 413 | efct_hw_process(&efct->hw, intr_ctx->index, efct->max_isr_time_msec); | ||
| 414 | return IRQ_HANDLED; | ||
| 415 | } | ||
| 416 | |||
| 417 | static irqreturn_t | ||
| 418 | efct_intr_msix(int irq, void *handle) | ||
| 419 | { | ||
| 420 | return IRQ_WAKE_THREAD; | ||
| 421 | } | ||
| 422 | |||
| 423 | static int | ||
| 424 | efct_setup_msix(struct efct *efct, u32 num_intrs) | ||
| 425 | { | ||
| 426 | int rc = 0, i; | ||
| 427 | |||
| 428 | if (!pci_find_capability(efct->pci, PCI_CAP_ID_MSIX)) { | ||
| 429 | dev_err(&efct->pci->dev, | ||
| 430 | "%s : MSI-X not available\n", __func__); | ||
| 431 | return -EIO; | ||
| 432 | } | ||
| 433 | |||
| 434 | efct->n_msix_vec = num_intrs; | ||
| 435 | |||
| 436 | rc = pci_alloc_irq_vectors(efct->pci, num_intrs, num_intrs, | ||
| 437 | PCI_IRQ_MSIX | PCI_IRQ_AFFINITY); | ||
| 438 | |||
| 439 | if (rc < 0) { | ||
| 440 | dev_err(&efct->pci->dev, "Failed to alloc irq : %d\n", rc); | ||
| 441 | return rc; | ||
| 442 | } | ||
| 443 | |||
| 444 | for (i = 0; i < num_intrs; i++) { | ||
| 445 | struct efct_intr_context *intr_ctx = NULL; | ||
| 446 | |||
| 447 | intr_ctx = &efct->intr_context[i]; | ||
| 448 | intr_ctx->efct = efct; | ||
| 449 | intr_ctx->index = i; | ||
| 450 | |||
| 451 | rc = request_threaded_irq(pci_irq_vector(efct->pci, i), | ||
| 452 | efct_intr_msix, efct_intr_thread, 0, | ||
| 453 | EFCT_DRIVER_NAME, intr_ctx); | ||
| 454 | if (rc) { | ||
| 455 | dev_err(&efct->pci->dev, | ||
| 456 | "Failed to register %d vector: %d\n", i, rc); | ||
| 457 | goto out; | ||
| 458 | } | ||
| 459 | } | ||
| 460 | |||
| 461 | return rc; | ||
| 462 | |||
| 463 | out: | ||
| 464 | while (--i >= 0) | ||
| 465 | free_irq(pci_irq_vector(efct->pci, i), | ||
| 466 | &efct->intr_context[i]); | ||
| 467 | |||
| 468 | pci_free_irq_vectors(efct->pci); | ||
| 469 | return rc; | ||
| 470 | } | ||
| 471 | |||
| 472 | static struct pci_device_id efct_pci_table[] = { | ||
| 473 | {PCI_DEVICE(EFCT_VENDOR_ID, EFCT_DEVICE_LANCER_G6), 0}, | ||
| 474 | {PCI_DEVICE(EFCT_VENDOR_ID, EFCT_DEVICE_LANCER_G7), 0}, | ||
| 475 | {} /* terminate list */ | ||
| 476 | }; | ||
| 477 | |||
| 478 | static int | ||
| 479 | efct_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent) | ||
| 480 | { | ||
| 481 | struct efct *efct = NULL; | ||
| 482 | int rc; | ||
| 483 | u32 i, r; | ||
| 484 | int num_interrupts = 0; | ||
| 485 | int nid; | ||
| 486 | |||
| 487 | dev_info(&pdev->dev, "%s\n", EFCT_DRIVER_NAME); | ||
| 488 | |||
| 489 | rc = pci_enable_device_mem(pdev); | ||
| 490 | if (rc) | ||
| 491 | return rc; | ||
| 492 | |||
| 493 | pci_set_master(pdev); | ||
| 494 | |||
| 495 | rc = pci_set_mwi(pdev); | ||
| 496 | if (rc) { | ||
| 497 | dev_info(&pdev->dev, "pci_set_mwi returned %d\n", rc); | ||
| 498 | goto mwi_out; | ||
| 499 | } | ||
| 500 | |||
| 501 | rc = pci_request_regions(pdev, EFCT_DRIVER_NAME); | ||
| 502 | if (rc) { | ||
| 503 | dev_err(&pdev->dev, "pci_request_regions failed %d\n", rc); | ||
| 504 | goto req_regions_out; | ||
| 505 | } | ||
| 506 | |||
| 507 | /* Fetch the Numa node id for this device */ | ||
| 508 | nid = dev_to_node(&pdev->dev); | ||
| 509 | if (nid < 0) { | ||
| 510 | dev_err(&pdev->dev, "Warning Numa node ID is %d\n", nid); | ||
| 511 | nid = 0; | ||
| 512 | } | ||
| 513 | |||
| 514 | /* Allocate efct */ | ||
| 515 | efct = efct_device_alloc(nid); | ||
| 516 | if (!efct) { | ||
| 517 | dev_err(&pdev->dev, "Failed to allocate efct\n"); | ||
| 518 | rc = -ENOMEM; | ||
| 519 | goto alloc_out; | ||
| 520 | } | ||
| 521 | |||
| 522 | efct->pci = pdev; | ||
| 523 | efct->numa_node = nid; | ||
| 524 | |||
| 525 | /* Map all memory BARs */ | ||
| 526 | for (i = 0, r = 0; i < EFCT_PCI_MAX_REGS; i++) { | ||
| 527 | if (pci_resource_flags(pdev, i) & IORESOURCE_MEM) { | ||
| 528 | efct->reg[r] = ioremap(pci_resource_start(pdev, i), | ||
| 529 | pci_resource_len(pdev, i)); | ||
| 530 | r++; | ||
| 531 | } | ||
| 532 | |||
| 533 | /* | ||
| 534 | * If the 64-bit attribute is set, both this BAR and the | ||
| 535 | * next form the complete address. Skip processing the | ||
| 536 | * next BAR. | ||
| 537 | */ | ||
| 538 | if (pci_resource_flags(pdev, i) & IORESOURCE_MEM_64) | ||
| 539 | i++; | ||
| 540 | } | ||
| 541 | |||
| 542 | pci_set_drvdata(pdev, efct); | ||
| 543 | |||
| 544 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) != 0 || | ||
| 545 | pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)) != 0) { | ||
| 546 | dev_warn(&pdev->dev, "trying DMA_BIT_MASK(32)\n"); | ||
| 547 | if (pci_set_dma_mask(pdev, DMA_BIT_MASK(32)) != 0 || | ||
| 548 | pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)) != 0) { | ||
| 549 | dev_err(&pdev->dev, "setting DMA_BIT_MASK failed\n"); | ||
| 550 | rc = -1; | ||
| 551 | goto dma_mask_out; | ||
| 552 | } | ||
| 553 | } | ||
| 554 | |||
| 555 | num_interrupts = efct_device_interrupts_required(efct); | ||
| 556 | if (num_interrupts < 0) { | ||
| 557 | efc_log_err(efct, "efct_device_interrupts_required failed\n"); | ||
| 558 | rc = -1; | ||
| 559 | goto dma_mask_out; | ||
| 560 | } | ||
| 561 | |||
| 562 | /* | ||
| 563 | * Initialize MSIX interrupts, note, | ||
| 564 | * efct_setup_msix() enables the interrupt | ||
| 565 | */ | ||
| 566 | rc = efct_setup_msix(efct, num_interrupts); | ||
| 567 | if (rc) { | ||
| 568 | dev_err(&pdev->dev, "Can't setup msix\n"); | ||
| 569 | goto dma_mask_out; | ||
| 570 | } | ||
| 571 | /* Disable interrupt for now */ | ||
| 572 | for (i = 0; i < efct->n_msix_vec; i++) { | ||
| 573 | efc_log_debug(efct, "irq %d disabled\n", i); | ||
| 574 | disable_irq(pci_irq_vector(efct->pci, i)); | ||
| 575 | } | ||
| 576 | |||
| 577 | rc = efct_device_attach(efct); | ||
| 578 | if (rc) | ||
| 579 | goto attach_out; | ||
| 580 | |||
| 581 | return 0; | ||
| 582 | |||
| 583 | attach_out: | ||
| 584 | efct_teardown_msix(efct); | ||
| 585 | dma_mask_out: | ||
| 586 | pci_set_drvdata(pdev, NULL); | ||
| 587 | |||
| 588 | for (i = 0; i < EFCT_PCI_MAX_REGS; i++) { | ||
| 589 | if (efct->reg[i]) | ||
| 590 | iounmap(efct->reg[i]); | ||
| 591 | } | ||
| 592 | efct_device_free(efct); | ||
| 593 | alloc_out: | ||
| 594 | pci_release_regions(pdev); | ||
| 595 | req_regions_out: | ||
| 596 | pci_clear_mwi(pdev); | ||
| 597 | mwi_out: | ||
| 598 | pci_disable_device(pdev); | ||
| 599 | return rc; | ||
| 600 | } | ||
| 601 | |||
| 602 | static void | ||
| 603 | efct_pci_remove(struct pci_dev *pdev) | ||
| 604 | { | ||
| 605 | struct efct *efct = pci_get_drvdata(pdev); | ||
| 606 | u32 i; | ||
| 607 | |||
| 608 | if (!efct) | ||
| 609 | return; | ||
| 610 | |||
| 611 | efct_device_detach(efct); | ||
| 612 | |||
| 613 | efct_teardown_msix(efct); | ||
| 614 | |||
| 615 | for (i = 0; i < EFCT_PCI_MAX_REGS; i++) { | ||
| 616 | if (efct->reg[i]) | ||
| 617 | iounmap(efct->reg[i]); | ||
| 618 | } | ||
| 619 | |||
| 620 | pci_set_drvdata(pdev, NULL); | ||
| 621 | |||
| 622 | efct_device_free(efct); | ||
| 623 | |||
| 624 | pci_release_regions(pdev); | ||
| 625 | |||
| 626 | pci_disable_device(pdev); | ||
| 627 | } | ||
| 628 | |||
| 629 | static void | ||
| 630 | efct_device_prep_for_reset(struct efct *efct, struct pci_dev *pdev) | ||
| 631 | { | ||
| 632 | if (efct) { | ||
| 633 | efc_log_debug(efct, | ||
| 634 | "PCI channel disable preparing for reset\n"); | ||
| 635 | efct_device_detach(efct); | ||
| 636 | /* Disable interrupt and pci device */ | ||
| 637 | efct_teardown_msix(efct); | ||
| 638 | } | ||
| 639 | pci_disable_device(pdev); | ||
| 640 | } | ||
| 641 | |||
| 642 | static void | ||
| 643 | efct_device_prep_for_recover(struct efct *efct) | ||
| 644 | { | ||
| 645 | if (efct) { | ||
| 646 | efc_log_debug(efct, "PCI channel preparing for recovery\n"); | ||
| 647 | efct_hw_io_abort_all(&efct->hw); | ||
| 648 | } | ||
| 649 | } | ||
| 650 | |||
| 651 | /** | ||
| 652 | * efct_pci_io_error_detected - method for handling PCI I/O error | ||
| 653 | * @pdev: pointer to PCI device. | ||
| 654 | * @state: the current PCI connection state. | ||
| 655 | * | ||
| 656 | * This routine is registered to the PCI subsystem for error handling. This | ||
| 657 | * function is called by the PCI subsystem after a PCI bus error affecting | ||
| 658 | * this device has been detected. When this routine is invoked, it dispatches | ||
| 659 | * device error detected handling routine, which will perform the proper | ||
| 660 | * error detected operation. | ||
| 661 | * | ||
| 662 | * Return codes | ||
| 663 | * PCI_ERS_RESULT_NEED_RESET - need to reset before recovery | ||
| 664 | * PCI_ERS_RESULT_DISCONNECT - device could not be recovered | ||
| 665 | */ | ||
| 666 | static pci_ers_result_t | ||
| 667 | efct_pci_io_error_detected(struct pci_dev *pdev, pci_channel_state_t state) | ||
| 668 | { | ||
| 669 | struct efct *efct = pci_get_drvdata(pdev); | ||
| 670 | pci_ers_result_t rc; | ||
| 671 | |||
| 672 | switch (state) { | ||
| 673 | case pci_channel_io_normal: | ||
| 674 | efct_device_prep_for_recover(efct); | ||
| 675 | rc = PCI_ERS_RESULT_CAN_RECOVER; | ||
| 676 | break; | ||
| 677 | case pci_channel_io_frozen: | ||
| 678 | efct_device_prep_for_reset(efct, pdev); | ||
| 679 | rc = PCI_ERS_RESULT_NEED_RESET; | ||
| 680 | break; | ||
| 681 | case pci_channel_io_perm_failure: | ||
| 682 | efct_device_detach(efct); | ||
| 683 | rc = PCI_ERS_RESULT_DISCONNECT; | ||
| 684 | break; | ||
| 685 | default: | ||
| 686 | efc_log_debug(efct, "Unknown PCI error state:0x%x\n", state); | ||
| 687 | efct_device_prep_for_reset(efct, pdev); | ||
| 688 | rc = PCI_ERS_RESULT_NEED_RESET; | ||
| 689 | break; | ||
| 690 | } | ||
| 691 | |||
| 692 | return rc; | ||
| 693 | } | ||
| 694 | |||
| 695 | static pci_ers_result_t | ||
| 696 | efct_pci_io_slot_reset(struct pci_dev *pdev) | ||
| 697 | { | ||
| 698 | int rc; | ||
| 699 | struct efct *efct = pci_get_drvdata(pdev); | ||
| 700 | |||
| 701 | rc = pci_enable_device_mem(pdev); | ||
| 702 | if (rc) { | ||
| 703 | efc_log_err(efct, "failed to enable PCI device after reset\n"); | ||
| 704 | return PCI_ERS_RESULT_DISCONNECT; | ||
| 705 | } | ||
| 706 | |||
| 707 | /* | ||
| 708 | * As the new kernel behavior of pci_restore_state() API call clears | ||
| 709 | * device saved_state flag, need to save the restored state again. | ||
| 710 | */ | ||
| 711 | |||
| 712 | pci_save_state(pdev); | ||
| 713 | |||
| 714 | pci_set_master(pdev); | ||
| 715 | |||
| 716 | rc = efct_setup_msix(efct, efct->n_msix_vec); | ||
| 717 | if (rc) | ||
| 718 | efc_log_err(efct, "rc %d returned, IRQ allocation failed\n", | ||
| 719 | rc); | ||
| 720 | |||
| 721 | /* Perform device reset */ | ||
| 722 | efct_device_detach(efct); | ||
| 723 | /* Bring device to online*/ | ||
| 724 | efct_device_attach(efct); | ||
| 725 | |||
| 726 | return PCI_ERS_RESULT_RECOVERED; | ||
| 727 | } | ||
| 728 | |||
| 729 | static void | ||
| 730 | efct_pci_io_resume(struct pci_dev *pdev) | ||
| 731 | { | ||
| 732 | struct efct *efct = pci_get_drvdata(pdev); | ||
| 733 | |||
| 734 | /* Perform device reset */ | ||
| 735 | efct_device_detach(efct); | ||
| 736 | /* Bring device to online*/ | ||
| 737 | efct_device_attach(efct); | ||
| 738 | } | ||
| 739 | |||
| 740 | MODULE_DEVICE_TABLE(pci, efct_pci_table); | ||
| 741 | |||
| 742 | static struct pci_error_handlers efct_pci_err_handler = { | ||
| 743 | .error_detected = efct_pci_io_error_detected, | ||
| 744 | .slot_reset = efct_pci_io_slot_reset, | ||
| 745 | .resume = efct_pci_io_resume, | ||
| 746 | }; | ||
| 747 | |||
| 748 | static struct pci_driver efct_pci_driver = { | ||
| 749 | .name = EFCT_DRIVER_NAME, | ||
| 750 | .id_table = efct_pci_table, | ||
| 751 | .probe = efct_pci_probe, | ||
| 752 | .remove = efct_pci_remove, | ||
| 753 | .err_handler = &efct_pci_err_handler, | ||
| 754 | }; | ||
| 755 | |||
| 756 | static | ||
| 757 | int __init efct_init(void) | ||
| 758 | { | ||
| 759 | int rc; | ||
| 760 | |||
| 761 | rc = efct_device_init(); | ||
| 762 | if (rc) { | ||
| 763 | pr_err("efct_device_init failed rc=%d\n", rc); | ||
| 764 | return rc; | ||
| 765 | } | ||
| 766 | |||
| 767 | rc = pci_register_driver(&efct_pci_driver); | ||
| 768 | if (rc) { | ||
| 769 | pr_err("pci_register_driver failed rc=%d\n", rc); | ||
| 770 | efct_device_shutdown(); | ||
| 771 | } | ||
| 772 | |||
| 773 | return rc; | ||
| 774 | } | ||
| 775 | |||
| 776 | static void __exit efct_exit(void) | ||
| 777 | { | ||
| 778 | pci_unregister_driver(&efct_pci_driver); | ||
| 779 | efct_device_shutdown(); | ||
| 780 | } | ||
| 781 | |||
| 782 | module_init(efct_init); | ||
| 783 | module_exit(efct_exit); | ||
| 784 | MODULE_VERSION(EFCT_DRIVER_VERSION); | ||
| 785 | MODULE_LICENSE("GPL"); | ||
| 786 | MODULE_AUTHOR("Broadcom"); | ||
| @@ -0,0 +1,109 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #if !defined(__EFCT_DRIVER_H__) | ||
| 8 | #define __EFCT_DRIVER_H__ | ||
| 9 | |||
| 10 | /*************************************************************************** | ||
| 11 | * OS specific includes | ||
| 12 | */ | ||
| 13 | #include <stdarg.h> | ||
| 14 | #include <linux/module.h> | ||
| 15 | #include <linux/debugfs.h> | ||
| 16 | #include <linux/firmware.h> | ||
| 17 | #include "../include/efc_common.h" | ||
| 18 | #include "../libefc/efclib.h" | ||
| 19 | #include "efct_hw.h" | ||
| 20 | #include "efct_io.h" | ||
| 21 | #include "efct_xport.h" | ||
| 22 | |||
| 23 | #define EFCT_DRIVER_NAME "efct" | ||
| 24 | #define EFCT_DRIVER_VERSION "1.0.0.0" | ||
| 25 | |||
| 26 | /* EFCT_DEFAULT_FILTER- | ||
| 27 | * MRQ filter to segregate the IO flow. | ||
| 28 | */ | ||
| 29 | #define EFCT_DEFAULT_FILTER "0x01ff22ff,0,0,0" | ||
| 30 | |||
| 31 | /* EFCT_OS_MAX_ISR_TIME_MSEC - | ||
| 32 | * maximum time driver code should spend in an interrupt | ||
| 33 | * or kernel thread context without yielding | ||
| 34 | */ | ||
| 35 | #define EFCT_OS_MAX_ISR_TIME_MSEC 1000 | ||
| 36 | |||
| 37 | #define EFCT_FC_MAX_SGL 64 | ||
| 38 | #define EFCT_FC_DIF_SEED 0 | ||
| 39 | |||
| 40 | /* Watermark */ | ||
| 41 | #define EFCT_WATERMARK_HIGH_PCT 90 | ||
| 42 | #define EFCT_WATERMARK_LOW_PCT 80 | ||
| 43 | #define EFCT_IO_WATERMARK_PER_INITIATOR 8 | ||
| 44 | |||
| 45 | #define EFCT_PCI_MAX_REGS 6 | ||
| 46 | #define MAX_PCI_INTERRUPTS 16 | ||
| 47 | |||
| 48 | struct efct_intr_context { | ||
| 49 | struct efct *efct; | ||
| 50 | u32 index; | ||
| 51 | }; | ||
| 52 | |||
| 53 | struct efct { | ||
| 54 | struct pci_dev *pci; | ||
| 55 | void __iomem *reg[EFCT_PCI_MAX_REGS]; | ||
| 56 | |||
| 57 | u32 n_msix_vec; | ||
| 58 | bool attached; | ||
| 59 | bool soft_wwn_enable; | ||
| 60 | u8 efct_req_fw_upgrade; | ||
| 61 | struct efct_intr_context intr_context[MAX_PCI_INTERRUPTS]; | ||
| 62 | u32 numa_node; | ||
| 63 | |||
| 64 | char name[EFC_NAME_LENGTH]; | ||
| 65 | u32 instance_index; | ||
| 66 | struct list_head list_entry; | ||
| 67 | struct efct_scsi_tgt tgt_efct; | ||
| 68 | struct efct_xport *xport; | ||
| 69 | struct efc *efcport; | ||
| 70 | struct Scsi_Host *shost; | ||
| 71 | int logmask; | ||
| 72 | u32 max_isr_time_msec; | ||
| 73 | |||
| 74 | const char *desc; | ||
| 75 | |||
| 76 | const char *model; | ||
| 77 | |||
| 78 | struct efct_hw hw; | ||
| 79 | |||
| 80 | u32 rq_selection_policy; | ||
| 81 | char *filter_def; | ||
| 82 | int topology; | ||
| 83 | |||
| 84 | /* Look up for target node */ | ||
| 85 | struct xarray lookup; | ||
| 86 | |||
| 87 | /* | ||
| 88 | * Target IO timer value: | ||
| 89 | * Zero: target command timeout disabled. | ||
| 90 | * Non-zero: Timeout value, in seconds, for target commands | ||
| 91 | */ | ||
| 92 | u32 target_io_timer_sec; | ||
| 93 | |||
| 94 | int speed; | ||
| 95 | struct dentry *sess_debugfs_dir; | ||
| 96 | }; | ||
| 97 | |||
| 98 | #define FW_WRITE_BUFSIZE (64 * 1024) | ||
| 99 | |||
| 100 | struct efct_fw_write_result { | ||
| 101 | struct completion done; | ||
| 102 | int status; | ||
| 103 | u32 actual_xfer; | ||
| 104 | u32 change_status; | ||
| 105 | }; | ||
| 106 | |||
| 107 | extern struct list_head efct_devices; | ||
| 108 | |||
| 109 | #endif /* __EFCT_DRIVER_H__ */ | ||
| @@ -0,0 +1,3581 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efct_driver.h" | ||
| 8 | #include "efct_hw.h" | ||
| 9 | #include "efct_unsol.h" | ||
| 10 | |||
| 11 | struct efct_hw_link_stat_cb_arg { | ||
| 12 | void (*cb)(int status, u32 num_counters, | ||
| 13 | struct efct_hw_link_stat_counts *counters, void *arg); | ||
| 14 | void *arg; | ||
| 15 | }; | ||
| 16 | |||
| 17 | struct efct_hw_host_stat_cb_arg { | ||
| 18 | void (*cb)(int status, u32 num_counters, | ||
| 19 | struct efct_hw_host_stat_counts *counters, void *arg); | ||
| 20 | void *arg; | ||
| 21 | }; | ||
| 22 | |||
| 23 | struct efct_hw_fw_wr_cb_arg { | ||
| 24 | void (*cb)(int status, u32 bytes_written, u32 change_status, void *arg); | ||
| 25 | void *arg; | ||
| 26 | }; | ||
| 27 | |||
| 28 | struct efct_mbox_rqst_ctx { | ||
| 29 | int (*callback)(struct efc *efc, int status, u8 *mqe, void *arg); | ||
| 30 | void *arg; | ||
| 31 | }; | ||
| 32 | |||
| 33 | static int | ||
| 34 | efct_hw_link_event_init(struct efct_hw *hw) | ||
| 35 | { | ||
| 36 | hw->link.status = SLI4_LINK_STATUS_MAX; | ||
| 37 | hw->link.topology = SLI4_LINK_TOPO_NONE; | ||
| 38 | hw->link.medium = SLI4_LINK_MEDIUM_MAX; | ||
| 39 | hw->link.speed = 0; | ||
| 40 | hw->link.loop_map = NULL; | ||
| 41 | hw->link.fc_id = U32_MAX; | ||
| 42 | |||
| 43 | return 0; | ||
| 44 | } | ||
| 45 | |||
| 46 | static int | ||
| 47 | efct_hw_read_max_dump_size(struct efct_hw *hw) | ||
| 48 | { | ||
| 49 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 50 | struct efct *efct = hw->os; | ||
| 51 | int rc = 0; | ||
| 52 | struct sli4_rsp_cmn_set_dump_location *rsp; | ||
| 53 | |||
| 54 | /* attempt to detemine the dump size for function 0 only. */ | ||
| 55 | if (PCI_FUNC(efct->pci->devfn) != 0) | ||
| 56 | return rc; | ||
| 57 | |||
| 58 | if (sli_cmd_common_set_dump_location(&hw->sli, buf, 1, 0, NULL, 0)) | ||
| 59 | return -EIO; | ||
| 60 | |||
| 61 | rsp = (struct sli4_rsp_cmn_set_dump_location *) | ||
| 62 | (buf + offsetof(struct sli4_cmd_sli_config, payload.embed)); | ||
| 63 | |||
| 64 | rc = efct_hw_command(hw, buf, EFCT_CMD_POLL, NULL, NULL); | ||
| 65 | if (rc != 0) { | ||
| 66 | efc_log_debug(hw->os, "set dump location cmd failed\n"); | ||
| 67 | return rc; | ||
| 68 | } | ||
| 69 | |||
| 70 | hw->dump_size = | ||
| 71 | le32_to_cpu(rsp->buffer_length_dword) & SLI4_CMN_SET_DUMP_BUFFER_LEN; | ||
| 72 | |||
| 73 | efc_log_debug(hw->os, "Dump size %x\n", hw->dump_size); | ||
| 74 | |||
| 75 | return rc; | ||
| 76 | } | ||
| 77 | |||
| 78 | static int | ||
| 79 | __efct_read_topology_cb(struct efct_hw *hw, int status, u8 *mqe, void *arg) | ||
| 80 | { | ||
| 81 | struct sli4_cmd_read_topology *read_topo = | ||
| 82 | (struct sli4_cmd_read_topology *)mqe; | ||
| 83 | u8 speed; | ||
| 84 | struct efc_domain_record drec = {0}; | ||
| 85 | struct efct *efct = hw->os; | ||
| 86 | |||
| 87 | if (status || le16_to_cpu(read_topo->hdr.status)) { | ||
| 88 | efc_log_debug(hw->os, "bad status cqe=%#x mqe=%#x\n", status, | ||
| 89 | le16_to_cpu(read_topo->hdr.status)); | ||
| 90 | return -EIO; | ||
| 91 | } | ||
| 92 | |||
| 93 | switch (le32_to_cpu(read_topo->dw2_attentype) & | ||
| 94 | SLI4_READTOPO_ATTEN_TYPE) { | ||
| 95 | case SLI4_READ_TOPOLOGY_LINK_UP: | ||
| 96 | hw->link.status = SLI4_LINK_STATUS_UP; | ||
| 97 | break; | ||
| 98 | case SLI4_READ_TOPOLOGY_LINK_DOWN: | ||
| 99 | hw->link.status = SLI4_LINK_STATUS_DOWN; | ||
| 100 | break; | ||
| 101 | case SLI4_READ_TOPOLOGY_LINK_NO_ALPA: | ||
| 102 | hw->link.status = SLI4_LINK_STATUS_NO_ALPA; | ||
| 103 | break; | ||
| 104 | default: | ||
| 105 | hw->link.status = SLI4_LINK_STATUS_MAX; | ||
| 106 | break; | ||
| 107 | } | ||
| 108 | |||
| 109 | switch (read_topo->topology) { | ||
| 110 | case SLI4_READ_TOPO_NON_FC_AL: | ||
| 111 | hw->link.topology = SLI4_LINK_TOPO_NON_FC_AL; | ||
| 112 | break; | ||
| 113 | case SLI4_READ_TOPO_FC_AL: | ||
| 114 | hw->link.topology = SLI4_LINK_TOPO_FC_AL; | ||
| 115 | if (hw->link.status == SLI4_LINK_STATUS_UP) | ||
| 116 | hw->link.loop_map = hw->loop_map.virt; | ||
| 117 | hw->link.fc_id = read_topo->acquired_al_pa; | ||
| 118 | break; | ||
| 119 | default: | ||
| 120 | hw->link.topology = SLI4_LINK_TOPO_MAX; | ||
| 121 | break; | ||
| 122 | } | ||
| 123 | |||
| 124 | hw->link.medium = SLI4_LINK_MEDIUM_FC; | ||
| 125 | |||
| 126 | speed = (le32_to_cpu(read_topo->currlink_state) & | ||
| 127 | SLI4_READTOPO_LINKSTATE_SPEED) >> 8; | ||
| 128 | switch (speed) { | ||
| 129 | case SLI4_READ_TOPOLOGY_SPEED_1G: | ||
| 130 | hw->link.speed = 1 * 1000; | ||
| 131 | break; | ||
| 132 | case SLI4_READ_TOPOLOGY_SPEED_2G: | ||
| 133 | hw->link.speed = 2 * 1000; | ||
| 134 | break; | ||
| 135 | case SLI4_READ_TOPOLOGY_SPEED_4G: | ||
| 136 | hw->link.speed = 4 * 1000; | ||
| 137 | break; | ||
| 138 | case SLI4_READ_TOPOLOGY_SPEED_8G: | ||
| 139 | hw->link.speed = 8 * 1000; | ||
| 140 | break; | ||
| 141 | case SLI4_READ_TOPOLOGY_SPEED_16G: | ||
| 142 | hw->link.speed = 16 * 1000; | ||
| 143 | break; | ||
| 144 | case SLI4_READ_TOPOLOGY_SPEED_32G: | ||
| 145 | hw->link.speed = 32 * 1000; | ||
| 146 | break; | ||
| 147 | case SLI4_READ_TOPOLOGY_SPEED_64G: | ||
| 148 | hw->link.speed = 64 * 1000; | ||
| 149 | break; | ||
| 150 | case SLI4_READ_TOPOLOGY_SPEED_128G: | ||
| 151 | hw->link.speed = 128 * 1000; | ||
| 152 | break; | ||
| 153 | } | ||
| 154 | |||
| 155 | drec.speed = hw->link.speed; | ||
| 156 | drec.fc_id = hw->link.fc_id; | ||
| 157 | drec.is_nport = true; | ||
| 158 | efc_domain_cb(efct->efcport, EFC_HW_DOMAIN_FOUND, &drec); | ||
| 159 | |||
| 160 | return 0; | ||
| 161 | } | ||
| 162 | |||
| 163 | static int | ||
| 164 | efct_hw_cb_link(void *ctx, void *e) | ||
| 165 | { | ||
| 166 | struct efct_hw *hw = ctx; | ||
| 167 | struct sli4_link_event *event = e; | ||
| 168 | struct efc_domain *d = NULL; | ||
| 169 | int rc = 0; | ||
| 170 | struct efct *efct = hw->os; | ||
| 171 | |||
| 172 | efct_hw_link_event_init(hw); | ||
| 173 | |||
| 174 | switch (event->status) { | ||
| 175 | case SLI4_LINK_STATUS_UP: | ||
| 176 | |||
| 177 | hw->link = *event; | ||
| 178 | efct->efcport->link_status = EFC_LINK_STATUS_UP; | ||
| 179 | |||
| 180 | if (event->topology == SLI4_LINK_TOPO_NON_FC_AL) { | ||
| 181 | struct efc_domain_record drec = {0}; | ||
| 182 | |||
| 183 | efc_log_info(hw->os, "Link Up, NPORT, speed is %d\n", | ||
| 184 | event->speed); | ||
| 185 | drec.speed = event->speed; | ||
| 186 | drec.fc_id = event->fc_id; | ||
| 187 | drec.is_nport = true; | ||
| 188 | efc_domain_cb(efct->efcport, EFC_HW_DOMAIN_FOUND, | ||
| 189 | &drec); | ||
| 190 | } else if (event->topology == SLI4_LINK_TOPO_FC_AL) { | ||
| 191 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 192 | |||
| 193 | efc_log_info(hw->os, "Link Up, LOOP, speed is %d\n", | ||
| 194 | event->speed); | ||
| 195 | |||
| 196 | if (!sli_cmd_read_topology(&hw->sli, buf, | ||
| 197 | &hw->loop_map)) { | ||
| 198 | rc = efct_hw_command(hw, buf, EFCT_CMD_NOWAIT, | ||
| 199 | __efct_read_topology_cb, NULL); | ||
| 200 | } | ||
| 201 | |||
| 202 | if (rc) | ||
| 203 | efc_log_debug(hw->os, "READ_TOPOLOGY failed\n"); | ||
| 204 | } else { | ||
| 205 | efc_log_info(hw->os, "%s(%#x), speed is %d\n", | ||
| 206 | "Link Up, unsupported topology ", | ||
| 207 | event->topology, event->speed); | ||
| 208 | } | ||
| 209 | break; | ||
| 210 | case SLI4_LINK_STATUS_DOWN: | ||
| 211 | efc_log_info(hw->os, "Link down\n"); | ||
| 212 | |||
| 213 | hw->link.status = event->status; | ||
| 214 | efct->efcport->link_status = EFC_LINK_STATUS_DOWN; | ||
| 215 | |||
| 216 | d = efct->efcport->domain; | ||
| 217 | if (d) | ||
| 218 | efc_domain_cb(efct->efcport, EFC_HW_DOMAIN_LOST, d); | ||
| 219 | break; | ||
| 220 | default: | ||
| 221 | efc_log_debug(hw->os, "unhandled link status %#x\n", | ||
| 222 | event->status); | ||
| 223 | break; | ||
| 224 | } | ||
| 225 | |||
| 226 | return 0; | ||
| 227 | } | ||
| 228 | |||
| 229 | int | ||
| 230 | efct_hw_setup(struct efct_hw *hw, void *os, struct pci_dev *pdev) | ||
| 231 | { | ||
| 232 | u32 i, max_sgl, cpus; | ||
| 233 | |||
| 234 | if (hw->hw_setup_called) | ||
| 235 | return 0; | ||
| 236 | |||
| 237 | /* | ||
| 238 | * efct_hw_init() relies on NULL pointers indicating that a structure | ||
| 239 | * needs allocation. If a structure is non-NULL, efct_hw_init() won't | ||
| 240 | * free/realloc that memory | ||
| 241 | */ | ||
| 242 | memset(hw, 0, sizeof(struct efct_hw)); | ||
| 243 | |||
| 244 | hw->hw_setup_called = true; | ||
| 245 | |||
| 246 | hw->os = os; | ||
| 247 | |||
| 248 | mutex_init(&hw->bmbx_lock); | ||
| 249 | spin_lock_init(&hw->cmd_lock); | ||
| 250 | INIT_LIST_HEAD(&hw->cmd_head); | ||
| 251 | INIT_LIST_HEAD(&hw->cmd_pending); | ||
| 252 | hw->cmd_head_count = 0; | ||
| 253 | |||
| 254 | /* Create mailbox command ctx pool */ | ||
| 255 | hw->cmd_ctx_pool = mempool_create_kmalloc_pool(EFCT_CMD_CTX_POOL_SZ, | ||
| 256 | sizeof(struct efct_command_ctx)); | ||
| 257 | if (!hw->cmd_ctx_pool) { | ||
| 258 | efc_log_err(hw->os, "failed to allocate mailbox buffer pool\n"); | ||
| 259 | return -EIO; | ||
| 260 | } | ||
| 261 | |||
| 262 | /* Create mailbox request ctx pool for library callback */ | ||
| 263 | hw->mbox_rqst_pool = mempool_create_kmalloc_pool(EFCT_CMD_CTX_POOL_SZ, | ||
| 264 | sizeof(struct efct_mbox_rqst_ctx)); | ||
| 265 | if (!hw->mbox_rqst_pool) { | ||
| 266 | efc_log_err(hw->os, "failed to allocate mbox request pool\n"); | ||
| 267 | return -EIO; | ||
| 268 | } | ||
| 269 | |||
| 270 | spin_lock_init(&hw->io_lock); | ||
| 271 | INIT_LIST_HEAD(&hw->io_inuse); | ||
| 272 | INIT_LIST_HEAD(&hw->io_free); | ||
| 273 | INIT_LIST_HEAD(&hw->io_wait_free); | ||
| 274 | |||
| 275 | atomic_set(&hw->io_alloc_failed_count, 0); | ||
| 276 | |||
| 277 | hw->config.speed = SLI4_LINK_SPEED_AUTO_16_8_4; | ||
| 278 | if (sli_setup(&hw->sli, hw->os, pdev, ((struct efct *)os)->reg)) { | ||
| 279 | efc_log_err(hw->os, "SLI setup failed\n"); | ||
| 280 | return -EIO; | ||
| 281 | } | ||
| 282 | |||
| 283 | efct_hw_link_event_init(hw); | ||
| 284 | |||
| 285 | sli_callback(&hw->sli, SLI4_CB_LINK, efct_hw_cb_link, hw); | ||
| 286 | |||
| 287 | /* | ||
| 288 | * Set all the queue sizes to the maximum allowed. | ||
| 289 | */ | ||
| 290 | for (i = 0; i < ARRAY_SIZE(hw->num_qentries); i++) | ||
| 291 | hw->num_qentries[i] = hw->sli.qinfo.max_qentries[i]; | ||
| 292 | /* | ||
| 293 | * Adjust the size of the WQs so that the CQ is twice as big as | ||
| 294 | * the WQ to allow for 2 completions per IO. This allows us to | ||
| 295 | * handle multi-phase as well as aborts. | ||
| 296 | */ | ||
| 297 | hw->num_qentries[SLI4_QTYPE_WQ] = hw->num_qentries[SLI4_QTYPE_CQ] / 2; | ||
| 298 | |||
| 299 | /* | ||
| 300 | * The RQ assignment for RQ pair mode. | ||
| 301 | */ | ||
| 302 | |||
| 303 | hw->config.rq_default_buffer_size = EFCT_HW_RQ_SIZE_PAYLOAD; | ||
| 304 | hw->config.n_io = hw->sli.ext[SLI4_RSRC_XRI].size; | ||
| 305 | |||
| 306 | cpus = num_possible_cpus(); | ||
| 307 | hw->config.n_eq = cpus > EFCT_HW_MAX_NUM_EQ ? EFCT_HW_MAX_NUM_EQ : cpus; | ||
| 308 | |||
| 309 | max_sgl = sli_get_max_sgl(&hw->sli) - SLI4_SGE_MAX_RESERVED; | ||
| 310 | max_sgl = (max_sgl > EFCT_FC_MAX_SGL) ? EFCT_FC_MAX_SGL : max_sgl; | ||
| 311 | hw->config.n_sgl = max_sgl; | ||
| 312 | |||
| 313 | (void)efct_hw_read_max_dump_size(hw); | ||
| 314 | |||
| 315 | return 0; | ||
| 316 | } | ||
| 317 | |||
| 318 | static void | ||
| 319 | efct_logfcfi(struct efct_hw *hw, u32 j, u32 i, u32 id) | ||
| 320 | { | ||
| 321 | efc_log_info(hw->os, | ||
| 322 | "REG_FCFI: filter[%d] %08X -> RQ[%d] id=%d\n", | ||
| 323 | j, hw->config.filter_def[j], i, id); | ||
| 324 | } | ||
| 325 | |||
| 326 | static inline void | ||
| 327 | efct_hw_init_free_io(struct efct_hw_io *io) | ||
| 328 | { | ||
| 329 | /* | ||
| 330 | * Set io->done to NULL, to avoid any callbacks, should | ||
| 331 | * a completion be received for one of these IOs | ||
| 332 | */ | ||
| 333 | io->done = NULL; | ||
| 334 | io->abort_done = NULL; | ||
| 335 | io->status_saved = false; | ||
| 336 | io->abort_in_progress = false; | ||
| 337 | io->type = 0xFFFF; | ||
| 338 | io->wq = NULL; | ||
| 339 | } | ||
| 340 | |||
| 341 | static bool efct_hw_iotype_is_originator(u16 io_type) | ||
| 342 | { | ||
| 343 | switch (io_type) { | ||
| 344 | case EFCT_HW_FC_CT: | ||
| 345 | case EFCT_HW_ELS_REQ: | ||
| 346 | return true; | ||
| 347 | default: | ||
| 348 | return false; | ||
| 349 | } | ||
| 350 | } | ||
| 351 | |||
| 352 | static void | ||
| 353 | efct_hw_io_restore_sgl(struct efct_hw *hw, struct efct_hw_io *io) | ||
| 354 | { | ||
| 355 | /* Restore the default */ | ||
| 356 | io->sgl = &io->def_sgl; | ||
| 357 | io->sgl_count = io->def_sgl_count; | ||
| 358 | } | ||
| 359 | |||
| 360 | static void | ||
| 361 | efct_hw_wq_process_io(void *arg, u8 *cqe, int status) | ||
| 362 | { | ||
| 363 | struct efct_hw_io *io = arg; | ||
| 364 | struct efct_hw *hw = io->hw; | ||
| 365 | struct sli4_fc_wcqe *wcqe = (void *)cqe; | ||
| 366 | u32 len = 0; | ||
| 367 | u32 ext = 0; | ||
| 368 | |||
| 369 | /* clear xbusy flag if WCQE[XB] is clear */ | ||
| 370 | if (io->xbusy && (wcqe->flags & SLI4_WCQE_XB) == 0) | ||
| 371 | io->xbusy = false; | ||
| 372 | |||
| 373 | /* get extended CQE status */ | ||
| 374 | switch (io->type) { | ||
| 375 | case EFCT_HW_BLS_ACC: | ||
| 376 | case EFCT_HW_BLS_RJT: | ||
| 377 | break; | ||
| 378 | case EFCT_HW_ELS_REQ: | ||
| 379 | sli_fc_els_did(&hw->sli, cqe, &ext); | ||
| 380 | len = sli_fc_response_length(&hw->sli, cqe); | ||
| 381 | break; | ||
| 382 | case EFCT_HW_ELS_RSP: | ||
| 383 | case EFCT_HW_FC_CT_RSP: | ||
| 384 | break; | ||
| 385 | case EFCT_HW_FC_CT: | ||
| 386 | len = sli_fc_response_length(&hw->sli, cqe); | ||
| 387 | break; | ||
| 388 | case EFCT_HW_IO_TARGET_WRITE: | ||
| 389 | len = sli_fc_io_length(&hw->sli, cqe); | ||
| 390 | break; | ||
| 391 | case EFCT_HW_IO_TARGET_READ: | ||
| 392 | len = sli_fc_io_length(&hw->sli, cqe); | ||
| 393 | break; | ||
| 394 | case EFCT_HW_IO_TARGET_RSP: | ||
| 395 | break; | ||
| 396 | case EFCT_HW_IO_DNRX_REQUEUE: | ||
| 397 | /* release the count for re-posting the buffer */ | ||
| 398 | /* efct_hw_io_free(hw, io); */ | ||
| 399 | break; | ||
| 400 | default: | ||
| 401 | efc_log_err(hw->os, "unhandled io type %#x for XRI 0x%x\n", | ||
| 402 | io->type, io->indicator); | ||
| 403 | break; | ||
| 404 | } | ||
| 405 | if (status) { | ||
| 406 | ext = sli_fc_ext_status(&hw->sli, cqe); | ||
| 407 | /* | ||
| 408 | * If we're not an originator IO, and XB is set, then issue | ||
| 409 | * abort for the IO from within the HW | ||
| 410 | */ | ||
| 411 | if (efct_hw_iotype_is_originator(io->type) && | ||
| 412 | wcqe->flags & SLI4_WCQE_XB) { | ||
| 413 | int rc; | ||
| 414 | |||
| 415 | efc_log_debug(hw->os, "aborting xri=%#x tag=%#x\n", | ||
| 416 | io->indicator, io->reqtag); | ||
| 417 | |||
| 418 | /* | ||
| 419 | * Because targets may send a response when the IO | ||
| 420 | * completes using the same XRI, we must wait for the | ||
| 421 | * XRI_ABORTED CQE to issue the IO callback | ||
| 422 | */ | ||
| 423 | rc = efct_hw_io_abort(hw, io, false, NULL, NULL); | ||
| 424 | if (rc == 0) { | ||
| 425 | /* | ||
| 426 | * latch status to return after abort is | ||
| 427 | * complete | ||
| 428 | */ | ||
| 429 | io->status_saved = true; | ||
| 430 | io->saved_status = status; | ||
| 431 | io->saved_ext = ext; | ||
| 432 | io->saved_len = len; | ||
| 433 | goto exit_efct_hw_wq_process_io; | ||
| 434 | } else if (rc == -EINPROGRESS) { | ||
| 435 | /* | ||
| 436 | * Already being aborted by someone else (ABTS | ||
| 437 | * perhaps). Just return original | ||
| 438 | * error. | ||
| 439 | */ | ||
| 440 | efc_log_debug(hw->os, "%s%#x tag=%#x\n", | ||
| 441 | "abort in progress xri=", | ||
| 442 | io->indicator, io->reqtag); | ||
| 443 | |||
| 444 | } else { | ||
| 445 | /* Failed to abort for some other reason, log | ||
| 446 | * error | ||
| 447 | */ | ||
| 448 | efc_log_debug(hw->os, "%s%#x tag=%#x rc=%d\n", | ||
| 449 | "Failed to abort xri=", | ||
| 450 | io->indicator, io->reqtag, rc); | ||
| 451 | } | ||
| 452 | } | ||
| 453 | } | ||
| 454 | |||
| 455 | if (io->done) { | ||
| 456 | efct_hw_done_t done = io->done; | ||
| 457 | |||
| 458 | io->done = NULL; | ||
| 459 | |||
| 460 | if (io->status_saved) { | ||
| 461 | /* use latched status if exists */ | ||
| 462 | status = io->saved_status; | ||
| 463 | len = io->saved_len; | ||
| 464 | ext = io->saved_ext; | ||
| 465 | io->status_saved = false; | ||
| 466 | } | ||
| 467 | |||
| 468 | /* Restore default SGL */ | ||
| 469 | efct_hw_io_restore_sgl(hw, io); | ||
| 470 | done(io, len, status, ext, io->arg); | ||
| 471 | } | ||
| 472 | |||
| 473 | exit_efct_hw_wq_process_io: | ||
| 474 | return; | ||
| 475 | } | ||
| 476 | |||
| 477 | static int | ||
| 478 | efct_hw_setup_io(struct efct_hw *hw) | ||
| 479 | { | ||
| 480 | u32 i = 0; | ||
| 481 | struct efct_hw_io *io = NULL; | ||
| 482 | uintptr_t xfer_virt = 0; | ||
| 483 | uintptr_t xfer_phys = 0; | ||
| 484 | u32 index; | ||
| 485 | bool new_alloc = true; | ||
| 486 | struct efc_dma *dma; | ||
| 487 | struct efct *efct = hw->os; | ||
| 488 | |||
| 489 | if (!hw->io) { | ||
| 490 | hw->io = kmalloc_array(hw->config.n_io, sizeof(io), GFP_KERNEL); | ||
| 491 | if (!hw->io) | ||
| 492 | return -ENOMEM; | ||
| 493 | |||
| 494 | memset(hw->io, 0, hw->config.n_io * sizeof(io)); | ||
| 495 | |||
| 496 | for (i = 0; i < hw->config.n_io; i++) { | ||
| 497 | hw->io[i] = kzalloc(sizeof(*io), GFP_KERNEL); | ||
| 498 | if (!hw->io[i]) | ||
| 499 | goto error; | ||
| 500 | } | ||
| 501 | |||
| 502 | /* Create WQE buffs for IO */ | ||
| 503 | hw->wqe_buffs = kzalloc((hw->config.n_io * hw->sli.wqe_size), | ||
| 504 | GFP_KERNEL); | ||
| 505 | if (!hw->wqe_buffs) { | ||
| 506 | kfree(hw->io); | ||
| 507 | return -ENOMEM; | ||
| 508 | } | ||
| 509 | |||
| 510 | } else { | ||
| 511 | /* re-use existing IOs, including SGLs */ | ||
| 512 | new_alloc = false; | ||
| 513 | } | ||
| 514 | |||
| 515 | if (new_alloc) { | ||
| 516 | dma = &hw->xfer_rdy; | ||
| 517 | dma->size = sizeof(struct fcp_txrdy) * hw->config.n_io; | ||
| 518 | dma->virt = dma_alloc_coherent(&efct->pci->dev, | ||
| 519 | dma->size, &dma->phys, GFP_DMA); | ||
| 520 | if (!dma->virt) | ||
| 521 | return -ENOMEM; | ||
| 522 | } | ||
| 523 | xfer_virt = (uintptr_t)hw->xfer_rdy.virt; | ||
| 524 | xfer_phys = hw->xfer_rdy.phys; | ||
| 525 | |||
| 526 | /* Initialize the pool of HW IO objects */ | ||
| 527 | for (i = 0; i < hw->config.n_io; i++) { | ||
| 528 | struct hw_wq_callback *wqcb; | ||
| 529 | |||
| 530 | io = hw->io[i]; | ||
| 531 | |||
| 532 | /* initialize IO fields */ | ||
| 533 | io->hw = hw; | ||
| 534 | |||
| 535 | /* Assign a WQE buff */ | ||
| 536 | io->wqe.wqebuf = &hw->wqe_buffs[i * hw->sli.wqe_size]; | ||
| 537 | |||
| 538 | /* Allocate the request tag for this IO */ | ||
| 539 | wqcb = efct_hw_reqtag_alloc(hw, efct_hw_wq_process_io, io); | ||
| 540 | if (!wqcb) { | ||
| 541 | efc_log_err(hw->os, "can't allocate request tag\n"); | ||
| 542 | return -ENOSPC; | ||
| 543 | } | ||
| 544 | io->reqtag = wqcb->instance_index; | ||
| 545 | |||
| 546 | /* Now for the fields that are initialized on each free */ | ||
| 547 | efct_hw_init_free_io(io); | ||
| 548 | |||
| 549 | /* The XB flag isn't cleared on IO free, so init to zero */ | ||
| 550 | io->xbusy = 0; | ||
| 551 | |||
| 552 | if (sli_resource_alloc(&hw->sli, SLI4_RSRC_XRI, | ||
| 553 | &io->indicator, &index)) { | ||
| 554 | efc_log_err(hw->os, | ||
| 555 | "sli_resource_alloc failed @ %d\n", i); | ||
| 556 | return -ENOMEM; | ||
| 557 | } | ||
| 558 | |||
| 559 | if (new_alloc) { | ||
| 560 | dma = &io->def_sgl; | ||
| 561 | dma->size = hw->config.n_sgl * | ||
| 562 | sizeof(struct sli4_sge); | ||
| 563 | dma->virt = dma_alloc_coherent(&efct->pci->dev, | ||
| 564 | dma->size, &dma->phys, | ||
| 565 | GFP_DMA); | ||
| 566 | if (!dma->virt) { | ||
| 567 | efc_log_err(hw->os, "dma_alloc fail %d\n", i); | ||
| 568 | memset(&io->def_sgl, 0, | ||
| 569 | sizeof(struct efc_dma)); | ||
| 570 | return -ENOMEM; | ||
| 571 | } | ||
| 572 | } | ||
| 573 | io->def_sgl_count = hw->config.n_sgl; | ||
| 574 | io->sgl = &io->def_sgl; | ||
| 575 | io->sgl_count = io->def_sgl_count; | ||
| 576 | |||
| 577 | if (hw->xfer_rdy.size) { | ||
| 578 | io->xfer_rdy.virt = (void *)xfer_virt; | ||
| 579 | io->xfer_rdy.phys = xfer_phys; | ||
| 580 | io->xfer_rdy.size = sizeof(struct fcp_txrdy); | ||
| 581 | |||
| 582 | xfer_virt += sizeof(struct fcp_txrdy); | ||
| 583 | xfer_phys += sizeof(struct fcp_txrdy); | ||
| 584 | } | ||
| 585 | } | ||
| 586 | |||
| 587 | return 0; | ||
| 588 | error: | ||
| 589 | for (i = 0; i < hw->config.n_io && hw->io[i]; i++) { | ||
| 590 | kfree(hw->io[i]); | ||
| 591 | hw->io[i] = NULL; | ||
| 592 | } | ||
| 593 | |||
| 594 | kfree(hw->io); | ||
| 595 | hw->io = NULL; | ||
| 596 | |||
| 597 | return -ENOMEM; | ||
| 598 | } | ||
| 599 | |||
| 600 | static int | ||
| 601 | efct_hw_init_prereg_io(struct efct_hw *hw) | ||
| 602 | { | ||
| 603 | u32 i, idx = 0; | ||
| 604 | struct efct_hw_io *io = NULL; | ||
| 605 | u8 cmd[SLI4_BMBX_SIZE]; | ||
| 606 | int rc = 0; | ||
| 607 | u32 n_rem; | ||
| 608 | u32 n = 0; | ||
| 609 | u32 sgls_per_request = 256; | ||
| 610 | struct efc_dma **sgls = NULL; | ||
| 611 | struct efc_dma req; | ||
| 612 | struct efct *efct = hw->os; | ||
| 613 | |||
| 614 | sgls = kmalloc_array(sgls_per_request, sizeof(*sgls), GFP_KERNEL); | ||
| 615 | if (!sgls) | ||
| 616 | return -ENOMEM; | ||
| 617 | |||
| 618 | memset(&req, 0, sizeof(struct efc_dma)); | ||
| 619 | req.size = 32 + sgls_per_request * 16; | ||
| 620 | req.virt = dma_alloc_coherent(&efct->pci->dev, req.size, &req.phys, | ||
| 621 | GFP_DMA); | ||
| 622 | if (!req.virt) { | ||
| 623 | kfree(sgls); | ||
| 624 | return -ENOMEM; | ||
| 625 | } | ||
| 626 | |||
| 627 | for (n_rem = hw->config.n_io; n_rem; n_rem -= n) { | ||
| 628 | /* Copy address of SGL's into local sgls[] array, break | ||
| 629 | * out if the xri is not contiguous. | ||
| 630 | */ | ||
| 631 | u32 min = (sgls_per_request < n_rem) ? sgls_per_request : n_rem; | ||
| 632 | |||
| 633 | for (n = 0; n < min; n++) { | ||
| 634 | /* Check that we have contiguous xri values */ | ||
| 635 | if (n > 0) { | ||
| 636 | if (hw->io[idx + n]->indicator != | ||
| 637 | hw->io[idx + n - 1]->indicator + 1) | ||
| 638 | break; | ||
| 639 | } | ||
| 640 | |||
| 641 | sgls[n] = hw->io[idx + n]->sgl; | ||
| 642 | } | ||
| 643 | |||
| 644 | if (sli_cmd_post_sgl_pages(&hw->sli, cmd, | ||
| 645 | hw->io[idx]->indicator, n, sgls, NULL, &req)) { | ||
| 646 | rc = -EIO; | ||
| 647 | break; | ||
| 648 | } | ||
| 649 | |||
| 650 | rc = efct_hw_command(hw, cmd, EFCT_CMD_POLL, NULL, NULL); | ||
| 651 | if (rc) { | ||
| 652 | efc_log_err(hw->os, "SGL post failed, rc=%d\n", rc); | ||
| 653 | break; | ||
| 654 | } | ||
| 655 | |||
| 656 | /* Add to tail if successful */ | ||
| 657 | for (i = 0; i < n; i++, idx++) { | ||
| 658 | io = hw->io[idx]; | ||
| 659 | io->state = EFCT_HW_IO_STATE_FREE; | ||
| 660 | INIT_LIST_HEAD(&io->list_entry); | ||
| 661 | list_add_tail(&io->list_entry, &hw->io_free); | ||
| 662 | } | ||
| 663 | } | ||
| 664 | |||
| 665 | dma_free_coherent(&efct->pci->dev, req.size, req.virt, req.phys); | ||
| 666 | memset(&req, 0, sizeof(struct efc_dma)); | ||
| 667 | kfree(sgls); | ||
| 668 | |||
| 669 | return rc; | ||
| 670 | } | ||
| 671 | |||
| 672 | static int | ||
| 673 | efct_hw_init_io(struct efct_hw *hw) | ||
| 674 | { | ||
| 675 | u32 i, idx = 0; | ||
| 676 | bool prereg = false; | ||
| 677 | struct efct_hw_io *io = NULL; | ||
| 678 | int rc = 0; | ||
| 679 | |||
| 680 | prereg = hw->sli.params.sgl_pre_registered; | ||
| 681 | |||
| 682 | if (prereg) | ||
| 683 | return efct_hw_init_prereg_io(hw); | ||
| 684 | |||
| 685 | for (i = 0; i < hw->config.n_io; i++, idx++) { | ||
| 686 | io = hw->io[idx]; | ||
| 687 | io->state = EFCT_HW_IO_STATE_FREE; | ||
| 688 | INIT_LIST_HEAD(&io->list_entry); | ||
| 689 | list_add_tail(&io->list_entry, &hw->io_free); | ||
| 690 | } | ||
| 691 | |||
| 692 | return rc; | ||
| 693 | } | ||
| 694 | |||
| 695 | static int | ||
| 696 | efct_hw_config_set_fdt_xfer_hint(struct efct_hw *hw, u32 fdt_xfer_hint) | ||
| 697 | { | ||
| 698 | int rc = 0; | ||
| 699 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 700 | struct sli4_rqst_cmn_set_features_set_fdt_xfer_hint param; | ||
| 701 | |||
| 702 | memset(¶m, 0, sizeof(param)); | ||
| 703 | param.fdt_xfer_hint = cpu_to_le32(fdt_xfer_hint); | ||
| 704 | /* build the set_features command */ | ||
| 705 | sli_cmd_common_set_features(&hw->sli, buf, | ||
| 706 | SLI4_SET_FEATURES_SET_FTD_XFER_HINT, sizeof(param), ¶m); | ||
| 707 | |||
| 708 | rc = efct_hw_command(hw, buf, EFCT_CMD_POLL, NULL, NULL); | ||
| 709 | if (rc) | ||
| 710 | efc_log_warn(hw->os, "set FDT hint %d failed: %d\n", | ||
| 711 | fdt_xfer_hint, rc); | ||
| 712 | else | ||
| 713 | efc_log_info(hw->os, "Set FTD transfer hint to %d\n", | ||
| 714 | le32_to_cpu(param.fdt_xfer_hint)); | ||
| 715 | |||
| 716 | return rc; | ||
| 717 | } | ||
| 718 | |||
| 719 | static int | ||
| 720 | efct_hw_config_rq(struct efct_hw *hw) | ||
| 721 | { | ||
| 722 | u32 min_rq_count, i, rc; | ||
| 723 | struct sli4_cmd_rq_cfg rq_cfg[SLI4_CMD_REG_FCFI_NUM_RQ_CFG]; | ||
| 724 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 725 | |||
| 726 | efc_log_info(hw->os, "using REG_FCFI standard\n"); | ||
| 727 | |||
| 728 | /* | ||
| 729 | * Set the filter match/mask values from hw's | ||
| 730 | * filter_def values | ||
| 731 | */ | ||
| 732 | for (i = 0; i < SLI4_CMD_REG_FCFI_NUM_RQ_CFG; i++) { | ||
| 733 | rq_cfg[i].rq_id = cpu_to_le16(0xffff); | ||
| 734 | rq_cfg[i].r_ctl_mask = (u8)hw->config.filter_def[i]; | ||
| 735 | rq_cfg[i].r_ctl_match = (u8)(hw->config.filter_def[i] >> 8); | ||
| 736 | rq_cfg[i].type_mask = (u8)(hw->config.filter_def[i] >> 16); | ||
| 737 | rq_cfg[i].type_match = (u8)(hw->config.filter_def[i] >> 24); | ||
| 738 | } | ||
| 739 | |||
| 740 | /* | ||
| 741 | * Update the rq_id's of the FCF configuration | ||
| 742 | * (don't update more than the number of rq_cfg | ||
| 743 | * elements) | ||
| 744 | */ | ||
| 745 | min_rq_count = (hw->hw_rq_count < SLI4_CMD_REG_FCFI_NUM_RQ_CFG) ? | ||
| 746 | hw->hw_rq_count : SLI4_CMD_REG_FCFI_NUM_RQ_CFG; | ||
| 747 | for (i = 0; i < min_rq_count; i++) { | ||
| 748 | struct hw_rq *rq = hw->hw_rq[i]; | ||
| 749 | u32 j; | ||
| 750 | |||
| 751 | for (j = 0; j < SLI4_CMD_REG_FCFI_NUM_RQ_CFG; j++) { | ||
| 752 | u32 mask = (rq->filter_mask != 0) ? | ||
| 753 | rq->filter_mask : 1; | ||
| 754 | |||
| 755 | if (!(mask & (1U << j))) | ||
| 756 | continue; | ||
| 757 | |||
| 758 | rq_cfg[i].rq_id = cpu_to_le16(rq->hdr->id); | ||
| 759 | efct_logfcfi(hw, j, i, rq->hdr->id); | ||
| 760 | } | ||
| 761 | } | ||
| 762 | |||
| 763 | rc = -EIO; | ||
| 764 | if (!sli_cmd_reg_fcfi(&hw->sli, buf, 0, rq_cfg)) | ||
| 765 | rc = efct_hw_command(hw, buf, EFCT_CMD_POLL, NULL, NULL); | ||
| 766 | |||
| 767 | if (rc != 0) { | ||
| 768 | efc_log_err(hw->os, "FCFI registration failed\n"); | ||
| 769 | return rc; | ||
| 770 | } | ||
| 771 | hw->fcf_indicator = | ||
| 772 | le16_to_cpu(((struct sli4_cmd_reg_fcfi *)buf)->fcfi); | ||
| 773 | |||
| 774 | return rc; | ||
| 775 | } | ||
| 776 | |||
| 777 | static int | ||
| 778 | efct_hw_config_mrq(struct efct_hw *hw, u8 mode, u16 fcf_index) | ||
| 779 | { | ||
| 780 | u8 buf[SLI4_BMBX_SIZE], mrq_bitmask = 0; | ||
| 781 | struct hw_rq *rq; | ||
| 782 | struct sli4_cmd_reg_fcfi_mrq *rsp = NULL; | ||
| 783 | struct sli4_cmd_rq_cfg rq_filter[SLI4_CMD_REG_FCFI_MRQ_NUM_RQ_CFG]; | ||
| 784 | u32 rc, i; | ||
| 785 | |||
| 786 | if (mode == SLI4_CMD_REG_FCFI_SET_FCFI_MODE) | ||
| 787 | goto issue_cmd; | ||
| 788 | |||
| 789 | /* Set the filter match/mask values from hw's filter_def values */ | ||
| 790 | for (i = 0; i < SLI4_CMD_REG_FCFI_NUM_RQ_CFG; i++) { | ||
| 791 | rq_filter[i].rq_id = cpu_to_le16(0xffff); | ||
| 792 | rq_filter[i].type_mask = (u8)hw->config.filter_def[i]; | ||
| 793 | rq_filter[i].type_match = (u8)(hw->config.filter_def[i] >> 8); | ||
| 794 | rq_filter[i].r_ctl_mask = (u8)(hw->config.filter_def[i] >> 16); | ||
| 795 | rq_filter[i].r_ctl_match = (u8)(hw->config.filter_def[i] >> 24); | ||
| 796 | } | ||
| 797 | |||
| 798 | rq = hw->hw_rq[0]; | ||
| 799 | rq_filter[0].rq_id = cpu_to_le16(rq->hdr->id); | ||
| 800 | rq_filter[1].rq_id = cpu_to_le16(rq->hdr->id); | ||
| 801 | |||
| 802 | mrq_bitmask = 0x2; | ||
| 803 | issue_cmd: | ||
| 804 | efc_log_debug(hw->os, "Issue reg_fcfi_mrq count:%d policy:%d mode:%d\n", | ||
| 805 | hw->hw_rq_count, hw->config.rq_selection_policy, mode); | ||
| 806 | /* Invoke REG_FCFI_MRQ */ | ||
| 807 | rc = sli_cmd_reg_fcfi_mrq(&hw->sli, buf, mode, fcf_index, | ||
| 808 | hw->config.rq_selection_policy, mrq_bitmask, | ||
| 809 | hw->hw_mrq_count, rq_filter); | ||
| 810 | if (rc) { | ||
| 811 | efc_log_err(hw->os, "sli_cmd_reg_fcfi_mrq() failed\n"); | ||
| 812 | return -EIO; | ||
| 813 | } | ||
| 814 | |||
| 815 | rc = efct_hw_command(hw, buf, EFCT_CMD_POLL, NULL, NULL); | ||
| 816 | |||
| 817 | rsp = (struct sli4_cmd_reg_fcfi_mrq *)buf; | ||
| 818 | |||
| 819 | if ((rc) || (le16_to_cpu(rsp->hdr.status))) { | ||
| 820 | efc_log_err(hw->os, "FCFI MRQ reg failed. cmd=%x status=%x\n", | ||
| 821 | rsp->hdr.command, le16_to_cpu(rsp->hdr.status)); | ||
| 822 | return -EIO; | ||
| 823 | } | ||
| 824 | |||
| 825 | if (mode == SLI4_CMD_REG_FCFI_SET_FCFI_MODE) | ||
| 826 | hw->fcf_indicator = le16_to_cpu(rsp->fcfi); | ||
| 827 | |||
| 828 | return 0; | ||
| 829 | } | ||
| 830 | |||
| 831 | static void | ||
| 832 | efct_hw_queue_hash_add(struct efct_queue_hash *hash, | ||
| 833 | u16 id, u16 index) | ||
| 834 | { | ||
| 835 | u32 hash_index = id & (EFCT_HW_Q_HASH_SIZE - 1); | ||
| 836 | |||
| 837 | /* | ||
| 838 | * Since the hash is always bigger than the number of queues, then we | ||
| 839 | * never have to worry about an infinite loop. | ||
| 840 | */ | ||
| 841 | while (hash[hash_index].in_use) | ||
| 842 | hash_index = (hash_index + 1) & (EFCT_HW_Q_HASH_SIZE - 1); | ||
| 843 | |||
| 844 | /* not used, claim the entry */ | ||
| 845 | hash[hash_index].id = id; | ||
| 846 | hash[hash_index].in_use = true; | ||
| 847 | hash[hash_index].index = index; | ||
| 848 | } | ||
| 849 | |||
| 850 | static int | ||
| 851 | efct_hw_config_sli_port_health_check(struct efct_hw *hw, u8 query, u8 enable) | ||
| 852 | { | ||
| 853 | int rc = 0; | ||
| 854 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 855 | struct sli4_rqst_cmn_set_features_health_check param; | ||
| 856 | u32 health_check_flag = 0; | ||
| 857 | |||
| 858 | memset(¶m, 0, sizeof(param)); | ||
| 859 | |||
| 860 | if (enable) | ||
| 861 | health_check_flag |= SLI4_RQ_HEALTH_CHECK_ENABLE; | ||
| 862 | |||
| 863 | if (query) | ||
| 864 | health_check_flag |= SLI4_RQ_HEALTH_CHECK_QUERY; | ||
| 865 | |||
| 866 | param.health_check_dword = cpu_to_le32(health_check_flag); | ||
| 867 | |||
| 868 | /* build the set_features command */ | ||
| 869 | sli_cmd_common_set_features(&hw->sli, buf, | ||
| 870 | SLI4_SET_FEATURES_SLI_PORT_HEALTH_CHECK, sizeof(param), ¶m); | ||
| 871 | |||
| 872 | rc = efct_hw_command(hw, buf, EFCT_CMD_POLL, NULL, NULL); | ||
| 873 | if (rc) | ||
| 874 | efc_log_err(hw->os, "efct_hw_command returns %d\n", rc); | ||
| 875 | else | ||
| 876 | efc_log_debug(hw->os, "SLI Port Health Check is enabled\n"); | ||
| 877 | |||
| 878 | return rc; | ||
| 879 | } | ||
| 880 | |||
| 881 | int | ||
| 882 | efct_hw_init(struct efct_hw *hw) | ||
| 883 | { | ||
| 884 | int rc; | ||
| 885 | u32 i = 0; | ||
| 886 | int rem_count; | ||
| 887 | unsigned long flags = 0; | ||
| 888 | struct efct_hw_io *temp; | ||
| 889 | struct efc_dma *dma; | ||
| 890 | |||
| 891 | /* | ||
| 892 | * Make sure the command lists are empty. If this is start-of-day, | ||
| 893 | * they'll be empty since they were just initialized in efct_hw_setup. | ||
| 894 | * If we've just gone through a reset, the command and command pending | ||
| 895 | * lists should have been cleaned up as part of the reset | ||
| 896 | * (efct_hw_reset()). | ||
| 897 | */ | ||
| 898 | spin_lock_irqsave(&hw->cmd_lock, flags); | ||
| 899 | if (!list_empty(&hw->cmd_head)) { | ||
| 900 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 901 | efc_log_err(hw->os, "command found on cmd list\n"); | ||
| 902 | return -EIO; | ||
| 903 | } | ||
| 904 | if (!list_empty(&hw->cmd_pending)) { | ||
| 905 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 906 | efc_log_err(hw->os, "command found on pending list\n"); | ||
| 907 | return -EIO; | ||
| 908 | } | ||
| 909 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 910 | |||
| 911 | /* Free RQ buffers if prevously allocated */ | ||
| 912 | efct_hw_rx_free(hw); | ||
| 913 | |||
| 914 | /* | ||
| 915 | * The IO queues must be initialized here for the reset case. The | ||
| 916 | * efct_hw_init_io() function will re-add the IOs to the free list. | ||
| 917 | * The cmd_head list should be OK since we free all entries in | ||
| 918 | * efct_hw_command_cancel() that is called in the efct_hw_reset(). | ||
| 919 | */ | ||
| 920 | |||
| 921 | /* If we are in this function due to a reset, there may be stale items | ||
| 922 | * on lists that need to be removed. Clean them up. | ||
| 923 | */ | ||
| 924 | rem_count = 0; | ||
| 925 | while ((!list_empty(&hw->io_wait_free))) { | ||
| 926 | rem_count++; | ||
| 927 | temp = list_first_entry(&hw->io_wait_free, struct efct_hw_io, | ||
| 928 | list_entry); | ||
| 929 | list_del_init(&temp->list_entry); | ||
| 930 | } | ||
| 931 | if (rem_count > 0) | ||
| 932 | efc_log_debug(hw->os, "rmvd %d items from io_wait_free list\n", | ||
| 933 | rem_count); | ||
| 934 | |||
| 935 | rem_count = 0; | ||
| 936 | while ((!list_empty(&hw->io_inuse))) { | ||
| 937 | rem_count++; | ||
| 938 | temp = list_first_entry(&hw->io_inuse, struct efct_hw_io, | ||
| 939 | list_entry); | ||
| 940 | list_del_init(&temp->list_entry); | ||
| 941 | } | ||
| 942 | if (rem_count > 0) | ||
| 943 | efc_log_debug(hw->os, "rmvd %d items from io_inuse list\n", | ||
| 944 | rem_count); | ||
| 945 | |||
| 946 | rem_count = 0; | ||
| 947 | while ((!list_empty(&hw->io_free))) { | ||
| 948 | rem_count++; | ||
| 949 | temp = list_first_entry(&hw->io_free, struct efct_hw_io, | ||
| 950 | list_entry); | ||
| 951 | list_del_init(&temp->list_entry); | ||
| 952 | } | ||
| 953 | if (rem_count > 0) | ||
| 954 | efc_log_debug(hw->os, "rmvd %d items from io_free list\n", | ||
| 955 | rem_count); | ||
| 956 | |||
| 957 | /* If MRQ not required, Make sure we dont request feature. */ | ||
| 958 | if (hw->config.n_rq == 1) | ||
| 959 | hw->sli.features &= (~SLI4_REQFEAT_MRQP); | ||
| 960 | |||
| 961 | if (sli_init(&hw->sli)) { | ||
| 962 | efc_log_err(hw->os, "SLI failed to initialize\n"); | ||
| 963 | return -EIO; | ||
| 964 | } | ||
| 965 | |||
| 966 | if (hw->sliport_healthcheck) { | ||
| 967 | rc = efct_hw_config_sli_port_health_check(hw, 0, 1); | ||
| 968 | if (rc != 0) { | ||
| 969 | efc_log_err(hw->os, "Enable port Health check fail\n"); | ||
| 970 | return rc; | ||
| 971 | } | ||
| 972 | } | ||
| 973 | |||
| 974 | /* | ||
| 975 | * Set FDT transfer hint, only works on Lancer | ||
| 976 | */ | ||
| 977 | if (hw->sli.if_type == SLI4_INTF_IF_TYPE_2) { | ||
| 978 | /* | ||
| 979 | * Non-fatal error. In particular, we can disregard failure to | ||
| 980 | * set EFCT_HW_FDT_XFER_HINT on devices with legacy firmware | ||
| 981 | * that do not support EFCT_HW_FDT_XFER_HINT feature. | ||
| 982 | */ | ||
| 983 | efct_hw_config_set_fdt_xfer_hint(hw, EFCT_HW_FDT_XFER_HINT); | ||
| 984 | } | ||
| 985 | |||
| 986 | /* zero the hashes */ | ||
| 987 | memset(hw->cq_hash, 0, sizeof(hw->cq_hash)); | ||
| 988 | efc_log_debug(hw->os, "Max CQs %d, hash size = %d\n", | ||
| 989 | EFCT_HW_MAX_NUM_CQ, EFCT_HW_Q_HASH_SIZE); | ||
| 990 | |||
| 991 | memset(hw->rq_hash, 0, sizeof(hw->rq_hash)); | ||
| 992 | efc_log_debug(hw->os, "Max RQs %d, hash size = %d\n", | ||
| 993 | EFCT_HW_MAX_NUM_RQ, EFCT_HW_Q_HASH_SIZE); | ||
| 994 | |||
| 995 | memset(hw->wq_hash, 0, sizeof(hw->wq_hash)); | ||
| 996 | efc_log_debug(hw->os, "Max WQs %d, hash size = %d\n", | ||
| 997 | EFCT_HW_MAX_NUM_WQ, EFCT_HW_Q_HASH_SIZE); | ||
| 998 | |||
| 999 | rc = efct_hw_init_queues(hw); | ||
| 1000 | if (rc) | ||
| 1001 | return rc; | ||
| 1002 | |||
| 1003 | rc = efct_hw_map_wq_cpu(hw); | ||
| 1004 | if (rc) | ||
| 1005 | return rc; | ||
| 1006 | |||
| 1007 | /* Allocate and p_st RQ buffers */ | ||
| 1008 | rc = efct_hw_rx_allocate(hw); | ||
| 1009 | if (rc) { | ||
| 1010 | efc_log_err(hw->os, "rx_allocate failed\n"); | ||
| 1011 | return rc; | ||
| 1012 | } | ||
| 1013 | |||
| 1014 | rc = efct_hw_rx_post(hw); | ||
| 1015 | if (rc) { | ||
| 1016 | efc_log_err(hw->os, "WARNING - error posting RQ buffers\n"); | ||
| 1017 | return rc; | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | if (hw->config.n_eq == 1) { | ||
| 1021 | rc = efct_hw_config_rq(hw); | ||
| 1022 | if (rc) { | ||
| 1023 | efc_log_err(hw->os, "config rq failed %d\n", rc); | ||
| 1024 | return rc; | ||
| 1025 | } | ||
| 1026 | } else { | ||
| 1027 | rc = efct_hw_config_mrq(hw, SLI4_CMD_REG_FCFI_SET_FCFI_MODE, 0); | ||
| 1028 | if (rc != 0) { | ||
| 1029 | efc_log_err(hw->os, "REG_FCFI_MRQ FCFI reg failed\n"); | ||
| 1030 | return rc; | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | rc = efct_hw_config_mrq(hw, SLI4_CMD_REG_FCFI_SET_MRQ_MODE, 0); | ||
| 1034 | if (rc != 0) { | ||
| 1035 | efc_log_err(hw->os, "REG_FCFI_MRQ MRQ reg failed\n"); | ||
| 1036 | return rc; | ||
| 1037 | } | ||
| 1038 | } | ||
| 1039 | |||
| 1040 | /* | ||
| 1041 | * Allocate the WQ request tag pool, if not previously allocated | ||
| 1042 | * (the request tag value is 16 bits, thus the pool allocation size | ||
| 1043 | * of 64k) | ||
| 1044 | */ | ||
| 1045 | hw->wq_reqtag_pool = efct_hw_reqtag_pool_alloc(hw); | ||
| 1046 | if (!hw->wq_reqtag_pool) { | ||
| 1047 | efc_log_err(hw->os, "efct_hw_reqtag_pool_alloc failed\n"); | ||
| 1048 | return -ENOMEM; | ||
| 1049 | } | ||
| 1050 | |||
| 1051 | rc = efct_hw_setup_io(hw); | ||
| 1052 | if (rc) { | ||
| 1053 | efc_log_err(hw->os, "IO allocation failure\n"); | ||
| 1054 | return rc; | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | rc = efct_hw_init_io(hw); | ||
| 1058 | if (rc) { | ||
| 1059 | efc_log_err(hw->os, "IO initialization failure\n"); | ||
| 1060 | return rc; | ||
| 1061 | } | ||
| 1062 | |||
| 1063 | dma = &hw->loop_map; | ||
| 1064 | dma->size = SLI4_MIN_LOOP_MAP_BYTES; | ||
| 1065 | dma->virt = dma_alloc_coherent(&hw->os->pci->dev, dma->size, &dma->phys, | ||
| 1066 | GFP_DMA); | ||
| 1067 | if (!dma->virt) | ||
| 1068 | return -EIO; | ||
| 1069 | |||
| 1070 | /* | ||
| 1071 | * Arming the EQ allows (e.g.) interrupts when CQ completions write EQ | ||
| 1072 | * entries | ||
| 1073 | */ | ||
| 1074 | for (i = 0; i < hw->eq_count; i++) | ||
| 1075 | sli_queue_arm(&hw->sli, &hw->eq[i], true); | ||
| 1076 | |||
| 1077 | /* | ||
| 1078 | * Initialize RQ hash | ||
| 1079 | */ | ||
| 1080 | for (i = 0; i < hw->rq_count; i++) | ||
| 1081 | efct_hw_queue_hash_add(hw->rq_hash, hw->rq[i].id, i); | ||
| 1082 | |||
| 1083 | /* | ||
| 1084 | * Initialize WQ hash | ||
| 1085 | */ | ||
| 1086 | for (i = 0; i < hw->wq_count; i++) | ||
| 1087 | efct_hw_queue_hash_add(hw->wq_hash, hw->wq[i].id, i); | ||
| 1088 | |||
| 1089 | /* | ||
| 1090 | * Arming the CQ allows (e.g.) MQ completions to write CQ entries | ||
| 1091 | */ | ||
| 1092 | for (i = 0; i < hw->cq_count; i++) { | ||
| 1093 | efct_hw_queue_hash_add(hw->cq_hash, hw->cq[i].id, i); | ||
| 1094 | sli_queue_arm(&hw->sli, &hw->cq[i], true); | ||
| 1095 | } | ||
| 1096 | |||
| 1097 | /* Set RQ process limit*/ | ||
| 1098 | for (i = 0; i < hw->hw_rq_count; i++) { | ||
| 1099 | struct hw_rq *rq = hw->hw_rq[i]; | ||
| 1100 | |||
| 1101 | hw->cq[rq->cq->instance].proc_limit = hw->config.n_io / 2; | ||
| 1102 | } | ||
| 1103 | |||
| 1104 | /* record the fact that the queues are functional */ | ||
| 1105 | hw->state = EFCT_HW_STATE_ACTIVE; | ||
| 1106 | /* | ||
| 1107 | * Allocate a HW IOs for send frame. | ||
| 1108 | */ | ||
| 1109 | hw->hw_wq[0]->send_frame_io = efct_hw_io_alloc(hw); | ||
| 1110 | if (!hw->hw_wq[0]->send_frame_io) | ||
| 1111 | efc_log_err(hw->os, "alloc for send_frame_io failed\n"); | ||
| 1112 | |||
| 1113 | /* Initialize send frame sequence id */ | ||
| 1114 | atomic_set(&hw->send_frame_seq_id, 0); | ||
| 1115 | |||
| 1116 | return 0; | ||
| 1117 | } | ||
| 1118 | |||
| 1119 | int | ||
| 1120 | efct_hw_parse_filter(struct efct_hw *hw, void *value) | ||
| 1121 | { | ||
| 1122 | int rc = 0; | ||
| 1123 | char *p = NULL; | ||
| 1124 | char *token; | ||
| 1125 | u32 idx = 0; | ||
| 1126 | |||
| 1127 | for (idx = 0; idx < ARRAY_SIZE(hw->config.filter_def); idx++) | ||
| 1128 | hw->config.filter_def[idx] = 0; | ||
| 1129 | |||
| 1130 | p = kstrdup(value, GFP_KERNEL); | ||
| 1131 | if (!p || !*p) { | ||
| 1132 | efc_log_err(hw->os, "p is NULL\n"); | ||
| 1133 | return -ENOMEM; | ||
| 1134 | } | ||
| 1135 | |||
| 1136 | idx = 0; | ||
| 1137 | while ((token = strsep(&p, ",")) && *token) { | ||
| 1138 | if (kstrtou32(token, 0, &hw->config.filter_def[idx++])) | ||
| 1139 | efc_log_err(hw->os, "kstrtoint failed\n"); | ||
| 1140 | |||
| 1141 | if (!p || !*p) | ||
| 1142 | break; | ||
| 1143 | |||
| 1144 | if (idx == ARRAY_SIZE(hw->config.filter_def)) | ||
| 1145 | break; | ||
| 1146 | } | ||
| 1147 | kfree(p); | ||
| 1148 | |||
| 1149 | return rc; | ||
| 1150 | } | ||
| 1151 | |||
| 1152 | u64 | ||
| 1153 | efct_get_wwnn(struct efct_hw *hw) | ||
| 1154 | { | ||
| 1155 | struct sli4 *sli = &hw->sli; | ||
| 1156 | u8 p[8]; | ||
| 1157 | |||
| 1158 | memcpy(p, sli->wwnn, sizeof(p)); | ||
| 1159 | return get_unaligned_be64(p); | ||
| 1160 | } | ||
| 1161 | |||
| 1162 | u64 | ||
| 1163 | efct_get_wwpn(struct efct_hw *hw) | ||
| 1164 | { | ||
| 1165 | struct sli4 *sli = &hw->sli; | ||
| 1166 | u8 p[8]; | ||
| 1167 | |||
| 1168 | memcpy(p, sli->wwpn, sizeof(p)); | ||
| 1169 | return get_unaligned_be64(p); | ||
| 1170 | } | ||
| 1171 | |||
| 1172 | static struct efc_hw_rq_buffer * | ||
| 1173 | efct_hw_rx_buffer_alloc(struct efct_hw *hw, u32 rqindex, u32 count, | ||
| 1174 | u32 size) | ||
| 1175 | { | ||
| 1176 | struct efct *efct = hw->os; | ||
| 1177 | struct efc_hw_rq_buffer *rq_buf = NULL; | ||
| 1178 | struct efc_hw_rq_buffer *prq; | ||
| 1179 | u32 i; | ||
| 1180 | |||
| 1181 | if (!count) | ||
| 1182 | return NULL; | ||
| 1183 | |||
| 1184 | rq_buf = kmalloc_array(count, sizeof(*rq_buf), GFP_KERNEL); | ||
| 1185 | if (!rq_buf) | ||
| 1186 | return NULL; | ||
| 1187 | memset(rq_buf, 0, sizeof(*rq_buf) * count); | ||
| 1188 | |||
| 1189 | for (i = 0, prq = rq_buf; i < count; i ++, prq++) { | ||
| 1190 | prq->rqindex = rqindex; | ||
| 1191 | prq->dma.size = size; | ||
| 1192 | prq->dma.virt = dma_alloc_coherent(&efct->pci->dev, | ||
| 1193 | prq->dma.size, | ||
| 1194 | &prq->dma.phys, | ||
| 1195 | GFP_DMA); | ||
| 1196 | if (!prq->dma.virt) { | ||
| 1197 | efc_log_err(hw->os, "DMA allocation failed\n"); | ||
| 1198 | kfree(rq_buf); | ||
| 1199 | return NULL; | ||
| 1200 | } | ||
| 1201 | } | ||
| 1202 | return rq_buf; | ||
| 1203 | } | ||
| 1204 | |||
| 1205 | static void | ||
| 1206 | efct_hw_rx_buffer_free(struct efct_hw *hw, | ||
| 1207 | struct efc_hw_rq_buffer *rq_buf, | ||
| 1208 | u32 count) | ||
| 1209 | { | ||
| 1210 | struct efct *efct = hw->os; | ||
| 1211 | u32 i; | ||
| 1212 | struct efc_hw_rq_buffer *prq; | ||
| 1213 | |||
| 1214 | if (rq_buf) { | ||
| 1215 | for (i = 0, prq = rq_buf; i < count; i++, prq++) { | ||
| 1216 | dma_free_coherent(&efct->pci->dev, | ||
| 1217 | prq->dma.size, prq->dma.virt, | ||
| 1218 | prq->dma.phys); | ||
| 1219 | memset(&prq->dma, 0, sizeof(struct efc_dma)); | ||
| 1220 | } | ||
| 1221 | |||
| 1222 | kfree(rq_buf); | ||
| 1223 | } | ||
| 1224 | } | ||
| 1225 | |||
| 1226 | int | ||
| 1227 | efct_hw_rx_allocate(struct efct_hw *hw) | ||
| 1228 | { | ||
| 1229 | struct efct *efct = hw->os; | ||
| 1230 | u32 i; | ||
| 1231 | int rc = 0; | ||
| 1232 | u32 rqindex = 0; | ||
| 1233 | u32 hdr_size = EFCT_HW_RQ_SIZE_HDR; | ||
| 1234 | u32 payload_size = hw->config.rq_default_buffer_size; | ||
| 1235 | |||
| 1236 | rqindex = 0; | ||
| 1237 | |||
| 1238 | for (i = 0; i < hw->hw_rq_count; i++) { | ||
| 1239 | struct hw_rq *rq = hw->hw_rq[i]; | ||
| 1240 | |||
| 1241 | /* Allocate header buffers */ | ||
| 1242 | rq->hdr_buf = efct_hw_rx_buffer_alloc(hw, rqindex, | ||
| 1243 | rq->entry_count, | ||
| 1244 | hdr_size); | ||
| 1245 | if (!rq->hdr_buf) { | ||
| 1246 | efc_log_err(efct, "rx_buffer_alloc hdr_buf failed\n"); | ||
| 1247 | rc = -EIO; | ||
| 1248 | break; | ||
| 1249 | } | ||
| 1250 | |||
| 1251 | efc_log_debug(hw->os, | ||
| 1252 | "rq[%2d] rq_id %02d header %4d by %4d bytes\n", | ||
| 1253 | i, rq->hdr->id, rq->entry_count, hdr_size); | ||
| 1254 | |||
| 1255 | rqindex++; | ||
| 1256 | |||
| 1257 | /* Allocate payload buffers */ | ||
| 1258 | rq->payload_buf = efct_hw_rx_buffer_alloc(hw, rqindex, | ||
| 1259 | rq->entry_count, | ||
| 1260 | payload_size); | ||
| 1261 | if (!rq->payload_buf) { | ||
| 1262 | efc_log_err(efct, "rx_buffer_alloc fb_buf failed\n"); | ||
| 1263 | rc = -EIO; | ||
| 1264 | break; | ||
| 1265 | } | ||
| 1266 | efc_log_debug(hw->os, | ||
| 1267 | "rq[%2d] rq_id %02d default %4d by %4d bytes\n", | ||
| 1268 | i, rq->data->id, rq->entry_count, payload_size); | ||
| 1269 | rqindex++; | ||
| 1270 | } | ||
| 1271 | |||
| 1272 | return rc ? -EIO : 0; | ||
| 1273 | } | ||
| 1274 | |||
| 1275 | int | ||
| 1276 | efct_hw_rx_post(struct efct_hw *hw) | ||
| 1277 | { | ||
| 1278 | u32 i; | ||
| 1279 | u32 idx; | ||
| 1280 | u32 rq_idx; | ||
| 1281 | int rc = 0; | ||
| 1282 | |||
| 1283 | if (!hw->seq_pool) { | ||
| 1284 | u32 count = 0; | ||
| 1285 | |||
| 1286 | for (i = 0; i < hw->hw_rq_count; i++) | ||
| 1287 | count += hw->hw_rq[i]->entry_count; | ||
| 1288 | |||
| 1289 | hw->seq_pool = kmalloc_array(count, | ||
| 1290 | sizeof(struct efc_hw_sequence), GFP_KERNEL); | ||
| 1291 | if (!hw->seq_pool) | ||
| 1292 | return -ENOMEM; | ||
| 1293 | } | ||
| 1294 | |||
| 1295 | /* | ||
| 1296 | * In RQ pair mode, we MUST post the header and payload buffer at the | ||
| 1297 | * same time. | ||
| 1298 | */ | ||
| 1299 | for (rq_idx = 0, idx = 0; rq_idx < hw->hw_rq_count; rq_idx++) { | ||
| 1300 | struct hw_rq *rq = hw->hw_rq[rq_idx]; | ||
| 1301 | |||
| 1302 | for (i = 0; i < rq->entry_count - 1; i++) { | ||
| 1303 | struct efc_hw_sequence *seq; | ||
| 1304 | |||
| 1305 | seq = hw->seq_pool + idx; | ||
| 1306 | idx++; | ||
| 1307 | seq->header = &rq->hdr_buf[i]; | ||
| 1308 | seq->payload = &rq->payload_buf[i]; | ||
| 1309 | rc = efct_hw_sequence_free(hw, seq); | ||
| 1310 | if (rc) | ||
| 1311 | break; | ||
| 1312 | } | ||
| 1313 | if (rc) | ||
| 1314 | break; | ||
| 1315 | } | ||
| 1316 | |||
| 1317 | if (rc && hw->seq_pool) | ||
| 1318 | kfree(hw->seq_pool); | ||
| 1319 | |||
| 1320 | return rc; | ||
| 1321 | } | ||
| 1322 | |||
| 1323 | void | ||
| 1324 | efct_hw_rx_free(struct efct_hw *hw) | ||
| 1325 | { | ||
| 1326 | u32 i; | ||
| 1327 | |||
| 1328 | /* Free hw_rq buffers */ | ||
| 1329 | for (i = 0; i < hw->hw_rq_count; i++) { | ||
| 1330 | struct hw_rq *rq = hw->hw_rq[i]; | ||
| 1331 | |||
| 1332 | if (rq) { | ||
| 1333 | efct_hw_rx_buffer_free(hw, rq->hdr_buf, | ||
| 1334 | rq->entry_count); | ||
| 1335 | rq->hdr_buf = NULL; | ||
| 1336 | efct_hw_rx_buffer_free(hw, rq->payload_buf, | ||
| 1337 | rq->entry_count); | ||
| 1338 | rq->payload_buf = NULL; | ||
| 1339 | } | ||
| 1340 | } | ||
| 1341 | } | ||
| 1342 | |||
| 1343 | static int | ||
| 1344 | efct_hw_cmd_submit_pending(struct efct_hw *hw) | ||
| 1345 | { | ||
| 1346 | int rc = 0; | ||
| 1347 | |||
| 1348 | /* Assumes lock held */ | ||
| 1349 | |||
| 1350 | /* Only submit MQE if there's room */ | ||
| 1351 | while (hw->cmd_head_count < (EFCT_HW_MQ_DEPTH - 1) && | ||
| 1352 | !list_empty(&hw->cmd_pending)) { | ||
| 1353 | struct efct_command_ctx *ctx; | ||
| 1354 | |||
| 1355 | ctx = list_first_entry(&hw->cmd_pending, | ||
| 1356 | struct efct_command_ctx, list_entry); | ||
| 1357 | if (!ctx) | ||
| 1358 | break; | ||
| 1359 | |||
| 1360 | list_del_init(&ctx->list_entry); | ||
| 1361 | |||
| 1362 | list_add_tail(&ctx->list_entry, &hw->cmd_head); | ||
| 1363 | hw->cmd_head_count++; | ||
| 1364 | if (sli_mq_write(&hw->sli, hw->mq, ctx->buf) < 0) { | ||
| 1365 | efc_log_debug(hw->os, | ||
| 1366 | "sli_queue_write failed: %d\n", rc); | ||
| 1367 | rc = -EIO; | ||
| 1368 | break; | ||
| 1369 | } | ||
| 1370 | } | ||
| 1371 | return rc; | ||
| 1372 | } | ||
| 1373 | |||
| 1374 | int | ||
| 1375 | efct_hw_command(struct efct_hw *hw, u8 *cmd, u32 opts, void *cb, void *arg) | ||
| 1376 | { | ||
| 1377 | int rc = -EIO; | ||
| 1378 | unsigned long flags = 0; | ||
| 1379 | void *bmbx = NULL; | ||
| 1380 | |||
| 1381 | /* | ||
| 1382 | * If the chip is in an error state (UE'd) then reject this mailbox | ||
| 1383 | * command. | ||
| 1384 | */ | ||
| 1385 | if (sli_fw_error_status(&hw->sli) > 0) { | ||
| 1386 | efc_log_crit(hw->os, "Chip in an error state - reset needed\n"); | ||
| 1387 | efc_log_crit(hw->os, "status=%#x error1=%#x error2=%#x\n", | ||
| 1388 | sli_reg_read_status(&hw->sli), | ||
| 1389 | sli_reg_read_err1(&hw->sli), | ||
| 1390 | sli_reg_read_err2(&hw->sli)); | ||
| 1391 | |||
| 1392 | return -EIO; | ||
| 1393 | } | ||
| 1394 | |||
| 1395 | /* | ||
| 1396 | * Send a mailbox command to the hardware, and either wait for | ||
| 1397 | * a completion (EFCT_CMD_POLL) or get an optional asynchronous | ||
| 1398 | * completion (EFCT_CMD_NOWAIT). | ||
| 1399 | */ | ||
| 1400 | |||
| 1401 | if (opts == EFCT_CMD_POLL) { | ||
| 1402 | mutex_lock(&hw->bmbx_lock); | ||
| 1403 | bmbx = hw->sli.bmbx.virt; | ||
| 1404 | |||
| 1405 | memset(bmbx, 0, SLI4_BMBX_SIZE); | ||
| 1406 | memcpy(bmbx, cmd, SLI4_BMBX_SIZE); | ||
| 1407 | |||
| 1408 | if (sli_bmbx_command(&hw->sli) == 0) { | ||
| 1409 | rc = 0; | ||
| 1410 | memcpy(cmd, bmbx, SLI4_BMBX_SIZE); | ||
| 1411 | } | ||
| 1412 | mutex_unlock(&hw->bmbx_lock); | ||
| 1413 | } else if (opts == EFCT_CMD_NOWAIT) { | ||
| 1414 | struct efct_command_ctx *ctx = NULL; | ||
| 1415 | |||
| 1416 | if (hw->state != EFCT_HW_STATE_ACTIVE) { | ||
| 1417 | efc_log_err(hw->os, "Can't send command, HW state=%d\n", | ||
| 1418 | hw->state); | ||
| 1419 | return -EIO; | ||
| 1420 | } | ||
| 1421 | |||
| 1422 | ctx = mempool_alloc(hw->cmd_ctx_pool, GFP_ATOMIC); | ||
| 1423 | if (!ctx) | ||
| 1424 | return -ENOSPC; | ||
| 1425 | |||
| 1426 | memset(ctx, 0, sizeof(struct efct_command_ctx)); | ||
| 1427 | |||
| 1428 | if (cb) { | ||
| 1429 | ctx->cb = cb; | ||
| 1430 | ctx->arg = arg; | ||
| 1431 | } | ||
| 1432 | |||
| 1433 | memcpy(ctx->buf, cmd, SLI4_BMBX_SIZE); | ||
| 1434 | ctx->ctx = hw; | ||
| 1435 | |||
| 1436 | spin_lock_irqsave(&hw->cmd_lock, flags); | ||
| 1437 | |||
| 1438 | /* Add to pending list */ | ||
| 1439 | INIT_LIST_HEAD(&ctx->list_entry); | ||
| 1440 | list_add_tail(&ctx->list_entry, &hw->cmd_pending); | ||
| 1441 | |||
| 1442 | /* Submit as much of the pending list as we can */ | ||
| 1443 | rc = efct_hw_cmd_submit_pending(hw); | ||
| 1444 | |||
| 1445 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 1446 | } | ||
| 1447 | |||
| 1448 | return rc; | ||
| 1449 | } | ||
| 1450 | |||
| 1451 | static int | ||
| 1452 | efct_hw_command_process(struct efct_hw *hw, int status, u8 *mqe, | ||
| 1453 | size_t size) | ||
| 1454 | { | ||
| 1455 | struct efct_command_ctx *ctx = NULL; | ||
| 1456 | unsigned long flags = 0; | ||
| 1457 | |||
| 1458 | spin_lock_irqsave(&hw->cmd_lock, flags); | ||
| 1459 | if (!list_empty(&hw->cmd_head)) { | ||
| 1460 | ctx = list_first_entry(&hw->cmd_head, | ||
| 1461 | struct efct_command_ctx, list_entry); | ||
| 1462 | list_del_init(&ctx->list_entry); | ||
| 1463 | } | ||
| 1464 | if (!ctx) { | ||
| 1465 | efc_log_err(hw->os, "no command context\n"); | ||
| 1466 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 1467 | return -EIO; | ||
| 1468 | } | ||
| 1469 | |||
| 1470 | hw->cmd_head_count--; | ||
| 1471 | |||
| 1472 | /* Post any pending requests */ | ||
| 1473 | efct_hw_cmd_submit_pending(hw); | ||
| 1474 | |||
| 1475 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 1476 | |||
| 1477 | if (ctx->cb) { | ||
| 1478 | memcpy(ctx->buf, mqe, size); | ||
| 1479 | ctx->cb(hw, status, ctx->buf, ctx->arg); | ||
| 1480 | } | ||
| 1481 | |||
| 1482 | mempool_free(ctx, hw->cmd_ctx_pool); | ||
| 1483 | |||
| 1484 | return 0; | ||
| 1485 | } | ||
| 1486 | |||
| 1487 | static int | ||
| 1488 | efct_hw_mq_process(struct efct_hw *hw, | ||
| 1489 | int status, struct sli4_queue *mq) | ||
| 1490 | { | ||
| 1491 | u8 mqe[SLI4_BMBX_SIZE]; | ||
| 1492 | int rc; | ||
| 1493 | |||
| 1494 | rc = sli_mq_read(&hw->sli, mq, mqe); | ||
| 1495 | if (!rc) | ||
| 1496 | rc = efct_hw_command_process(hw, status, mqe, mq->size); | ||
| 1497 | |||
| 1498 | return rc; | ||
| 1499 | } | ||
| 1500 | |||
| 1501 | static int | ||
| 1502 | efct_hw_command_cancel(struct efct_hw *hw) | ||
| 1503 | { | ||
| 1504 | unsigned long flags = 0; | ||
| 1505 | int rc = 0; | ||
| 1506 | |||
| 1507 | spin_lock_irqsave(&hw->cmd_lock, flags); | ||
| 1508 | |||
| 1509 | /* | ||
| 1510 | * Manually clean up remaining commands. Note: since this calls | ||
| 1511 | * efct_hw_command_process(), we'll also process the cmd_pending | ||
| 1512 | * list, so no need to manually clean that out. | ||
| 1513 | */ | ||
| 1514 | while (!list_empty(&hw->cmd_head)) { | ||
| 1515 | u8 mqe[SLI4_BMBX_SIZE] = { 0 }; | ||
| 1516 | struct efct_command_ctx *ctx; | ||
| 1517 | |||
| 1518 | ctx = list_first_entry(&hw->cmd_head, | ||
| 1519 | struct efct_command_ctx, list_entry); | ||
| 1520 | |||
| 1521 | efc_log_debug(hw->os, "hung command %08x\n", | ||
| 1522 | !ctx ? U32_MAX : *((u32 *)ctx->buf)); | ||
| 1523 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 1524 | rc = efct_hw_command_process(hw, -1, mqe, SLI4_BMBX_SIZE); | ||
| 1525 | spin_lock_irqsave(&hw->cmd_lock, flags); | ||
| 1526 | } | ||
| 1527 | |||
| 1528 | spin_unlock_irqrestore(&hw->cmd_lock, flags); | ||
| 1529 | |||
| 1530 | return rc; | ||
| 1531 | } | ||
| 1532 | |||
| 1533 | static void | ||
| 1534 | efct_mbox_rsp_cb(struct efct_hw *hw, int status, u8 *mqe, void *arg) | ||
| 1535 | { | ||
| 1536 | struct efct_mbox_rqst_ctx *ctx = arg; | ||
| 1537 | |||
| 1538 | if (ctx) { | ||
| 1539 | if (ctx->callback) | ||
| 1540 | (*ctx->callback)(hw->os->efcport, status, mqe, | ||
| 1541 | ctx->arg); | ||
| 1542 | |||
| 1543 | mempool_free(ctx, hw->mbox_rqst_pool); | ||
| 1544 | } | ||
| 1545 | } | ||
| 1546 | |||
| 1547 | int | ||
| 1548 | efct_issue_mbox_rqst(void *base, void *cmd, void *cb, void *arg) | ||
| 1549 | { | ||
| 1550 | struct efct_mbox_rqst_ctx *ctx; | ||
| 1551 | struct efct *efct = base; | ||
| 1552 | struct efct_hw *hw = &efct->hw; | ||
| 1553 | int rc; | ||
| 1554 | |||
| 1555 | /* | ||
| 1556 | * Allocate a callback context (which includes the mbox cmd buffer), | ||
| 1557 | * we need this to be persistent as the mbox cmd submission may be | ||
| 1558 | * queued and executed later execution. | ||
| 1559 | */ | ||
| 1560 | ctx = mempool_alloc(hw->mbox_rqst_pool, GFP_ATOMIC); | ||
| 1561 | if (!ctx) | ||
| 1562 | return -EIO; | ||
| 1563 | |||
| 1564 | ctx->callback = cb; | ||
| 1565 | ctx->arg = arg; | ||
| 1566 | |||
| 1567 | rc = efct_hw_command(hw, cmd, EFCT_CMD_NOWAIT, efct_mbox_rsp_cb, ctx); | ||
| 1568 | if (rc) { | ||
| 1569 | efc_log_err(efct, "issue mbox rqst failure rc:%d\n", rc); | ||
| 1570 | mempool_free(ctx, hw->mbox_rqst_pool); | ||
| 1571 | return -EIO; | ||
| 1572 | } | ||
| 1573 | |||
| 1574 | return 0; | ||
| 1575 | } | ||
| 1576 | |||
| 1577 | static inline struct efct_hw_io * | ||
| 1578 | _efct_hw_io_alloc(struct efct_hw *hw) | ||
| 1579 | { | ||
| 1580 | struct efct_hw_io *io = NULL; | ||
| 1581 | |||
| 1582 | if (!list_empty(&hw->io_free)) { | ||
| 1583 | io = list_first_entry(&hw->io_free, struct efct_hw_io, | ||
| 1584 | list_entry); | ||
| 1585 | list_del(&io->list_entry); | ||
| 1586 | } | ||
| 1587 | if (io) { | ||
| 1588 | INIT_LIST_HEAD(&io->list_entry); | ||
| 1589 | list_add_tail(&io->list_entry, &hw->io_inuse); | ||
| 1590 | io->state = EFCT_HW_IO_STATE_INUSE; | ||
| 1591 | io->abort_reqtag = U32_MAX; | ||
| 1592 | io->wq = hw->wq_cpu_array[raw_smp_processor_id()]; | ||
| 1593 | if (!io->wq) { | ||
| 1594 | efc_log_err(hw->os, "WQ not assigned for cpu:%d\n", | ||
| 1595 | raw_smp_processor_id()); | ||
| 1596 | io->wq = hw->hw_wq[0]; | ||
| 1597 | } | ||
| 1598 | kref_init(&io->ref); | ||
| 1599 | io->release = efct_hw_io_free_internal; | ||
| 1600 | } else { | ||
| 1601 | atomic_add(1, &hw->io_alloc_failed_count); | ||
| 1602 | } | ||
| 1603 | |||
| 1604 | return io; | ||
| 1605 | } | ||
| 1606 | |||
| 1607 | struct efct_hw_io * | ||
| 1608 | efct_hw_io_alloc(struct efct_hw *hw) | ||
| 1609 | { | ||
| 1610 | struct efct_hw_io *io = NULL; | ||
| 1611 | unsigned long flags = 0; | ||
| 1612 | |||
| 1613 | spin_lock_irqsave(&hw->io_lock, flags); | ||
| 1614 | io = _efct_hw_io_alloc(hw); | ||
| 1615 | spin_unlock_irqrestore(&hw->io_lock, flags); | ||
| 1616 | |||
| 1617 | return io; | ||
| 1618 | } | ||
| 1619 | |||
| 1620 | static void | ||
| 1621 | efct_hw_io_free_move_correct_list(struct efct_hw *hw, | ||
| 1622 | struct efct_hw_io *io) | ||
| 1623 | { | ||
| 1624 | /* | ||
| 1625 | * When an IO is freed, depending on the exchange busy flag, | ||
| 1626 | * move it to the correct list. | ||
| 1627 | */ | ||
| 1628 | if (io->xbusy) { | ||
| 1629 | /* | ||
| 1630 | * add to wait_free list and wait for XRI_ABORTED CQEs to clean | ||
| 1631 | * up | ||
| 1632 | */ | ||
| 1633 | INIT_LIST_HEAD(&io->list_entry); | ||
| 1634 | list_add_tail(&io->list_entry, &hw->io_wait_free); | ||
| 1635 | io->state = EFCT_HW_IO_STATE_WAIT_FREE; | ||
| 1636 | } else { | ||
| 1637 | /* IO not busy, add to free list */ | ||
| 1638 | INIT_LIST_HEAD(&io->list_entry); | ||
| 1639 | list_add_tail(&io->list_entry, &hw->io_free); | ||
| 1640 | io->state = EFCT_HW_IO_STATE_FREE; | ||
| 1641 | } | ||
| 1642 | } | ||
| 1643 | |||
| 1644 | static inline void | ||
| 1645 | efct_hw_io_free_common(struct efct_hw *hw, struct efct_hw_io *io) | ||
| 1646 | { | ||
| 1647 | /* initialize IO fields */ | ||
| 1648 | efct_hw_init_free_io(io); | ||
| 1649 | |||
| 1650 | /* Restore default SGL */ | ||
| 1651 | efct_hw_io_restore_sgl(hw, io); | ||
| 1652 | } | ||
| 1653 | |||
| 1654 | void | ||
| 1655 | efct_hw_io_free_internal(struct kref *arg) | ||
| 1656 | { | ||
| 1657 | unsigned long flags = 0; | ||
| 1658 | struct efct_hw_io *io = container_of(arg, struct efct_hw_io, ref); | ||
| 1659 | struct efct_hw *hw = io->hw; | ||
| 1660 | |||
| 1661 | /* perform common cleanup */ | ||
| 1662 | efct_hw_io_free_common(hw, io); | ||
| 1663 | |||
| 1664 | spin_lock_irqsave(&hw->io_lock, flags); | ||
| 1665 | /* remove from in-use list */ | ||
| 1666 | if (!list_empty(&io->list_entry) && !list_empty(&hw->io_inuse)) { | ||
| 1667 | list_del_init(&io->list_entry); | ||
| 1668 | efct_hw_io_free_move_correct_list(hw, io); | ||
| 1669 | } | ||
| 1670 | spin_unlock_irqrestore(&hw->io_lock, flags); | ||
| 1671 | } | ||
| 1672 | |||
| 1673 | int | ||
| 1674 | efct_hw_io_free(struct efct_hw *hw, struct efct_hw_io *io) | ||
| 1675 | { | ||
| 1676 | return kref_put(&io->ref, io->release); | ||
| 1677 | } | ||
| 1678 | |||
| 1679 | struct efct_hw_io * | ||
| 1680 | efct_hw_io_lookup(struct efct_hw *hw, u32 xri) | ||
| 1681 | { | ||
| 1682 | u32 ioindex; | ||
| 1683 | |||
| 1684 | ioindex = xri - hw->sli.ext[SLI4_RSRC_XRI].base[0]; | ||
| 1685 | return hw->io[ioindex]; | ||
| 1686 | } | ||
| 1687 | |||
| 1688 | int | ||
| 1689 | efct_hw_io_init_sges(struct efct_hw *hw, struct efct_hw_io *io, | ||
| 1690 | enum efct_hw_io_type type) | ||
| 1691 | { | ||
| 1692 | struct sli4_sge *data = NULL; | ||
| 1693 | u32 i = 0; | ||
| 1694 | u32 skips = 0; | ||
| 1695 | u32 sge_flags = 0; | ||
| 1696 | |||
| 1697 | if (!io) { | ||
| 1698 | efc_log_err(hw->os, "bad parameter hw=%p io=%p\n", hw, io); | ||
| 1699 | return -EIO; | ||
| 1700 | } | ||
| 1701 | |||
| 1702 | /* Clear / reset the scatter-gather list */ | ||
| 1703 | io->sgl = &io->def_sgl; | ||
| 1704 | io->sgl_count = io->def_sgl_count; | ||
| 1705 | io->first_data_sge = 0; | ||
| 1706 | |||
| 1707 | memset(io->sgl->virt, 0, 2 * sizeof(struct sli4_sge)); | ||
| 1708 | io->n_sge = 0; | ||
| 1709 | io->sge_offset = 0; | ||
| 1710 | |||
| 1711 | io->type = type; | ||
| 1712 | |||
| 1713 | data = io->sgl->virt; | ||
| 1714 | |||
| 1715 | /* | ||
| 1716 | * Some IO types have underlying hardware requirements on the order | ||
| 1717 | * of SGEs. Process all special entries here. | ||
| 1718 | */ | ||
| 1719 | switch (type) { | ||
| 1720 | case EFCT_HW_IO_TARGET_WRITE: | ||
| 1721 | |||
| 1722 | /* populate host resident XFER_RDY buffer */ | ||
| 1723 | sge_flags = le32_to_cpu(data->dw2_flags); | ||
| 1724 | sge_flags &= (~SLI4_SGE_TYPE_MASK); | ||
| 1725 | sge_flags |= (SLI4_SGE_TYPE_DATA << SLI4_SGE_TYPE_SHIFT); | ||
| 1726 | data->buffer_address_high = | ||
| 1727 | cpu_to_le32(upper_32_bits(io->xfer_rdy.phys)); | ||
| 1728 | data->buffer_address_low = | ||
| 1729 | cpu_to_le32(lower_32_bits(io->xfer_rdy.phys)); | ||
| 1730 | data->buffer_length = cpu_to_le32(io->xfer_rdy.size); | ||
| 1731 | data->dw2_flags = cpu_to_le32(sge_flags); | ||
| 1732 | data++; | ||
| 1733 | |||
| 1734 | skips = EFCT_TARGET_WRITE_SKIPS; | ||
| 1735 | |||
| 1736 | io->n_sge = 1; | ||
| 1737 | break; | ||
| 1738 | case EFCT_HW_IO_TARGET_READ: | ||
| 1739 | /* | ||
| 1740 | * For FCP_TSEND64, the first 2 entries are SKIP SGE's | ||
| 1741 | */ | ||
| 1742 | skips = EFCT_TARGET_READ_SKIPS; | ||
| 1743 | break; | ||
| 1744 | case EFCT_HW_IO_TARGET_RSP: | ||
| 1745 | /* | ||
| 1746 | * No skips, etc. for FCP_TRSP64 | ||
| 1747 | */ | ||
| 1748 | break; | ||
| 1749 | default: | ||
| 1750 | efc_log_err(hw->os, "unsupported IO type %#x\n", type); | ||
| 1751 | return -EIO; | ||
| 1752 | } | ||
| 1753 | |||
| 1754 | /* | ||
| 1755 | * Write skip entries | ||
| 1756 | */ | ||
| 1757 | for (i = 0; i < skips; i++) { | ||
| 1758 | sge_flags = le32_to_cpu(data->dw2_flags); | ||
| 1759 | sge_flags &= (~SLI4_SGE_TYPE_MASK); | ||
| 1760 | sge_flags |= (SLI4_SGE_TYPE_SKIP << SLI4_SGE_TYPE_SHIFT); | ||
| 1761 | data->dw2_flags = cpu_to_le32(sge_flags); | ||
| 1762 | data++; | ||
| 1763 | } | ||
| 1764 | |||
| 1765 | io->n_sge += skips; | ||
| 1766 | |||
| 1767 | /* | ||
| 1768 | * Set last | ||
| 1769 | */ | ||
| 1770 | sge_flags = le32_to_cpu(data->dw2_flags); | ||
| 1771 | sge_flags |= SLI4_SGE_LAST; | ||
| 1772 | data->dw2_flags = cpu_to_le32(sge_flags); | ||
| 1773 | |||
| 1774 | return 0; | ||
| 1775 | } | ||
| 1776 | |||
| 1777 | int | ||
| 1778 | efct_hw_io_add_sge(struct efct_hw *hw, struct efct_hw_io *io, | ||
| 1779 | uintptr_t addr, u32 length) | ||
| 1780 | { | ||
| 1781 | struct sli4_sge *data = NULL; | ||
| 1782 | u32 sge_flags = 0; | ||
| 1783 | |||
| 1784 | if (!io || !addr || !length) { | ||
| 1785 | efc_log_err(hw->os, | ||
| 1786 | "bad parameter hw=%p io=%p addr=%lx length=%u\n", | ||
| 1787 | hw, io, addr, length); | ||
| 1788 | return -EIO; | ||
| 1789 | } | ||
| 1790 | |||
| 1791 | if (length > hw->sli.sge_supported_length) { | ||
| 1792 | efc_log_err(hw->os, | ||
| 1793 | "length of SGE %d bigger than allowed %d\n", | ||
| 1794 | length, hw->sli.sge_supported_length); | ||
| 1795 | return -EIO; | ||
| 1796 | } | ||
| 1797 | |||
| 1798 | data = io->sgl->virt; | ||
| 1799 | data += io->n_sge; | ||
| 1800 | |||
| 1801 | sge_flags = le32_to_cpu(data->dw2_flags); | ||
| 1802 | sge_flags &= ~SLI4_SGE_TYPE_MASK; | ||
| 1803 | sge_flags |= SLI4_SGE_TYPE_DATA << SLI4_SGE_TYPE_SHIFT; | ||
| 1804 | sge_flags &= ~SLI4_SGE_DATA_OFFSET_MASK; | ||
| 1805 | sge_flags |= SLI4_SGE_DATA_OFFSET_MASK & io->sge_offset; | ||
| 1806 | |||
| 1807 | data->buffer_address_high = cpu_to_le32(upper_32_bits(addr)); | ||
| 1808 | data->buffer_address_low = cpu_to_le32(lower_32_bits(addr)); | ||
| 1809 | data->buffer_length = cpu_to_le32(length); | ||
| 1810 | |||
| 1811 | /* | ||
| 1812 | * Always assume this is the last entry and mark as such. | ||
| 1813 | * If this is not the first entry unset the "last SGE" | ||
| 1814 | * indication for the previous entry | ||
| 1815 | */ | ||
| 1816 | sge_flags |= SLI4_SGE_LAST; | ||
| 1817 | data->dw2_flags = cpu_to_le32(sge_flags); | ||
| 1818 | |||
| 1819 | if (io->n_sge) { | ||
| 1820 | sge_flags = le32_to_cpu(data[-1].dw2_flags); | ||
| 1821 | sge_flags &= ~SLI4_SGE_LAST; | ||
| 1822 | data[-1].dw2_flags = cpu_to_le32(sge_flags); | ||
| 1823 | } | ||
| 1824 | |||
| 1825 | /* Set first_data_bde if not previously set */ | ||
| 1826 | if (io->first_data_sge == 0) | ||
| 1827 | io->first_data_sge = io->n_sge; | ||
| 1828 | |||
| 1829 | io->sge_offset += length; | ||
| 1830 | io->n_sge++; | ||
| 1831 | |||
| 1832 | return 0; | ||
| 1833 | } | ||
| 1834 | |||
| 1835 | void | ||
| 1836 | efct_hw_io_abort_all(struct efct_hw *hw) | ||
| 1837 | { | ||
| 1838 | struct efct_hw_io *io_to_abort = NULL; | ||
| 1839 | struct efct_hw_io *next_io = NULL; | ||
| 1840 | |||
| 1841 | list_for_each_entry_safe(io_to_abort, next_io, | ||
| 1842 | &hw->io_inuse, list_entry) { | ||
| 1843 | efct_hw_io_abort(hw, io_to_abort, true, NULL, NULL); | ||
| 1844 | } | ||
| 1845 | } | ||
| 1846 | |||
| 1847 | static void | ||
| 1848 | efct_hw_wq_process_abort(void *arg, u8 *cqe, int status) | ||
| 1849 | { | ||
| 1850 | struct efct_hw_io *io = arg; | ||
| 1851 | struct efct_hw *hw = io->hw; | ||
| 1852 | u32 ext = 0; | ||
| 1853 | u32 len = 0; | ||
| 1854 | struct hw_wq_callback *wqcb; | ||
| 1855 | |||
| 1856 | /* | ||
| 1857 | * For IOs that were aborted internally, we may need to issue the | ||
| 1858 | * callback here depending on whether a XRI_ABORTED CQE is expected ot | ||
| 1859 | * not. If the status is Local Reject/No XRI, then | ||
| 1860 | * issue the callback now. | ||
| 1861 | */ | ||
| 1862 | ext = sli_fc_ext_status(&hw->sli, cqe); | ||
| 1863 | if (status == SLI4_FC_WCQE_STATUS_LOCAL_REJECT && | ||
| 1864 | ext == SLI4_FC_LOCAL_REJECT_NO_XRI && io->done) { | ||
| 1865 | efct_hw_done_t done = io->done; | ||
| 1866 | |||
| 1867 | io->done = NULL; | ||
| 1868 | |||
| 1869 | /* | ||
| 1870 | * Use latched status as this is always saved for an internal | ||
| 1871 | * abort Note: We won't have both a done and abort_done | ||
| 1872 | * function, so don't worry about | ||
| 1873 | * clobbering the len, status and ext fields. | ||
| 1874 | */ | ||
| 1875 | status = io->saved_status; | ||
| 1876 | len = io->saved_len; | ||
| 1877 | ext = io->saved_ext; | ||
| 1878 | io->status_saved = false; | ||
| 1879 | done(io, len, status, ext, io->arg); | ||
| 1880 | } | ||
| 1881 | |||
| 1882 | if (io->abort_done) { | ||
| 1883 | efct_hw_done_t done = io->abort_done; | ||
| 1884 | |||
| 1885 | io->abort_done = NULL; | ||
| 1886 | done(io, len, status, ext, io->abort_arg); | ||
| 1887 | } | ||
| 1888 | |||
| 1889 | /* clear abort bit to indicate abort is complete */ | ||
| 1890 | io->abort_in_progress = false; | ||
| 1891 | |||
| 1892 | /* Free the WQ callback */ | ||
| 1893 | if (io->abort_reqtag == U32_MAX) { | ||
| 1894 | efc_log_err(hw->os, "HW IO already freed\n"); | ||
| 1895 | return; | ||
| 1896 | } | ||
| 1897 | |||
| 1898 | wqcb = efct_hw_reqtag_get_instance(hw, io->abort_reqtag); | ||
| 1899 | efct_hw_reqtag_free(hw, wqcb); | ||
| 1900 | |||
| 1901 | /* | ||
| 1902 | * Call efct_hw_io_free() because this releases the WQ reservation as | ||
| 1903 | * well as doing the refcount put. Don't duplicate the code here. | ||
| 1904 | */ | ||
| 1905 | (void)efct_hw_io_free(hw, io); | ||
| 1906 | } | ||
| 1907 | |||
| 1908 | static void | ||
| 1909 | efct_hw_fill_abort_wqe(struct efct_hw *hw, struct efct_hw_wqe *wqe) | ||
| 1910 | { | ||
| 1911 | struct sli4_abort_wqe *abort = (void *)wqe->wqebuf; | ||
| 1912 | |||
| 1913 | memset(abort, 0, hw->sli.wqe_size); | ||
| 1914 | |||
| 1915 | abort->criteria = SLI4_ABORT_CRITERIA_XRI_TAG; | ||
| 1916 | abort->ia_ir_byte |= wqe->send_abts ? 0 : 1; | ||
| 1917 | |||
| 1918 | /* Suppress ABTS retries */ | ||
| 1919 | abort->ia_ir_byte |= SLI4_ABRT_WQE_IR; | ||
| 1920 | |||
| 1921 | abort->t_tag = cpu_to_le32(wqe->id); | ||
| 1922 | abort->command = SLI4_WQE_ABORT; | ||
| 1923 | abort->request_tag = cpu_to_le16(wqe->abort_reqtag); | ||
| 1924 | |||
| 1925 | abort->dw10w0_flags = cpu_to_le16(SLI4_ABRT_WQE_QOSD); | ||
| 1926 | |||
| 1927 | abort->cq_id = cpu_to_le16(SLI4_CQ_DEFAULT); | ||
| 1928 | } | ||
| 1929 | |||
| 1930 | int | ||
| 1931 | efct_hw_io_abort(struct efct_hw *hw, struct efct_hw_io *io_to_abort, | ||
| 1932 | bool send_abts, void *cb, void *arg) | ||
| 1933 | { | ||
| 1934 | struct hw_wq_callback *wqcb; | ||
| 1935 | unsigned long flags = 0; | ||
| 1936 | |||
| 1937 | if (!io_to_abort) { | ||
| 1938 | efc_log_err(hw->os, "bad parameter hw=%p io=%p\n", | ||
| 1939 | hw, io_to_abort); | ||
| 1940 | return -EIO; | ||
| 1941 | } | ||
| 1942 | |||
| 1943 | if (hw->state != EFCT_HW_STATE_ACTIVE) { | ||
| 1944 | efc_log_err(hw->os, "cannot send IO abort, HW state=%d\n", | ||
| 1945 | hw->state); | ||
| 1946 | return -EIO; | ||
| 1947 | } | ||
| 1948 | |||
| 1949 | /* take a reference on IO being aborted */ | ||
| 1950 | if (kref_get_unless_zero(&io_to_abort->ref) == 0) { | ||
| 1951 | /* command no longer active */ | ||
| 1952 | efc_log_debug(hw->os, | ||
| 1953 | "io not active xri=0x%x tag=0x%x\n", | ||
| 1954 | io_to_abort->indicator, io_to_abort->reqtag); | ||
| 1955 | return -ENOENT; | ||
| 1956 | } | ||
| 1957 | |||
| 1958 | /* Must have a valid WQ reference */ | ||
| 1959 | if (!io_to_abort->wq) { | ||
| 1960 | efc_log_debug(hw->os, "io_to_abort xri=0x%x not active on WQ\n", | ||
| 1961 | io_to_abort->indicator); | ||
| 1962 | /* efct_ref_get(): same function */ | ||
| 1963 | kref_put(&io_to_abort->ref, io_to_abort->release); | ||
| 1964 | return -ENOENT; | ||
| 1965 | } | ||
| 1966 | |||
| 1967 | /* | ||
| 1968 | * Validation checks complete; now check to see if already being | ||
| 1969 | * aborted, if not set the flag. | ||
| 1970 | */ | ||
| 1971 | if (cmpxchg(&io_to_abort->abort_in_progress, false, true)) { | ||
| 1972 | /* efct_ref_get(): same function */ | ||
| 1973 | kref_put(&io_to_abort->ref, io_to_abort->release); | ||
| 1974 | efc_log_debug(hw->os, | ||
| 1975 | "io already being aborted xri=0x%x tag=0x%x\n", | ||
| 1976 | io_to_abort->indicator, io_to_abort->reqtag); | ||
| 1977 | return -EINPROGRESS; | ||
| 1978 | } | ||
| 1979 | |||
| 1980 | /* | ||
| 1981 | * If we got here, the possibilities are: | ||
| 1982 | * - host owned xri | ||
| 1983 | * - io_to_abort->wq_index != U32_MAX | ||
| 1984 | * - submit ABORT_WQE to same WQ | ||
| 1985 | * - port owned xri: | ||
| 1986 | * - rxri: io_to_abort->wq_index == U32_MAX | ||
| 1987 | * - submit ABORT_WQE to any WQ | ||
| 1988 | * - non-rxri | ||
| 1989 | * - io_to_abort->index != U32_MAX | ||
| 1990 | * - submit ABORT_WQE to same WQ | ||
| 1991 | * - io_to_abort->index == U32_MAX | ||
| 1992 | * - submit ABORT_WQE to any WQ | ||
| 1993 | */ | ||
| 1994 | io_to_abort->abort_done = cb; | ||
| 1995 | io_to_abort->abort_arg = arg; | ||
| 1996 | |||
| 1997 | /* Allocate a request tag for the abort portion of this IO */ | ||
| 1998 | wqcb = efct_hw_reqtag_alloc(hw, efct_hw_wq_process_abort, io_to_abort); | ||
| 1999 | if (!wqcb) { | ||
| 2000 | efc_log_err(hw->os, "can't allocate request tag\n"); | ||
| 2001 | return -ENOSPC; | ||
| 2002 | } | ||
| 2003 | |||
| 2004 | io_to_abort->abort_reqtag = wqcb->instance_index; | ||
| 2005 | io_to_abort->wqe.send_abts = send_abts; | ||
| 2006 | io_to_abort->wqe.id = io_to_abort->indicator; | ||
| 2007 | io_to_abort->wqe.abort_reqtag = io_to_abort->abort_reqtag; | ||
| 2008 | |||
| 2009 | /* | ||
| 2010 | * If the wqe is on the pending list, then set this wqe to be | ||
| 2011 | * aborted when the IO's wqe is removed from the list. | ||
| 2012 | */ | ||
| 2013 | if (io_to_abort->wq) { | ||
| 2014 | spin_lock_irqsave(&io_to_abort->wq->queue->lock, flags); | ||
| 2015 | if (io_to_abort->wqe.list_entry.next) { | ||
| 2016 | io_to_abort->wqe.abort_wqe_submit_needed = true; | ||
| 2017 | spin_unlock_irqrestore(&io_to_abort->wq->queue->lock, | ||
| 2018 | flags); | ||
| 2019 | return 0; | ||
| 2020 | } | ||
| 2021 | spin_unlock_irqrestore(&io_to_abort->wq->queue->lock, flags); | ||
| 2022 | } | ||
| 2023 | |||
| 2024 | efct_hw_fill_abort_wqe(hw, &io_to_abort->wqe); | ||
| 2025 | |||
| 2026 | /* ABORT_WQE does not actually utilize an XRI on the Port, | ||
| 2027 | * therefore, keep xbusy as-is to track the exchange's state, | ||
| 2028 | * not the ABORT_WQE's state | ||
| 2029 | */ | ||
| 2030 | if (efct_hw_wq_write(io_to_abort->wq, &io_to_abort->wqe)) { | ||
| 2031 | io_to_abort->abort_in_progress = false; | ||
| 2032 | /* efct_ref_get(): same function */ | ||
| 2033 | kref_put(&io_to_abort->ref, io_to_abort->release); | ||
| 2034 | return -EIO; | ||
| 2035 | } | ||
| 2036 | |||
| 2037 | return 0; | ||
| 2038 | } | ||
| 2039 | |||
| 2040 | void | ||
| 2041 | efct_hw_reqtag_pool_free(struct efct_hw *hw) | ||
| 2042 | { | ||
| 2043 | u32 i; | ||
| 2044 | struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; | ||
| 2045 | struct hw_wq_callback *wqcb = NULL; | ||
| 2046 | |||
| 2047 | if (reqtag_pool) { | ||
| 2048 | for (i = 0; i < U16_MAX; i++) { | ||
| 2049 | wqcb = reqtag_pool->tags[i]; | ||
| 2050 | if (!wqcb) | ||
| 2051 | continue; | ||
| 2052 | |||
| 2053 | kfree(wqcb); | ||
| 2054 | } | ||
| 2055 | kfree(reqtag_pool); | ||
| 2056 | hw->wq_reqtag_pool = NULL; | ||
| 2057 | } | ||
| 2058 | } | ||
| 2059 | |||
| 2060 | struct reqtag_pool * | ||
| 2061 | efct_hw_reqtag_pool_alloc(struct efct_hw *hw) | ||
| 2062 | { | ||
| 2063 | u32 i = 0; | ||
| 2064 | struct reqtag_pool *reqtag_pool; | ||
| 2065 | struct hw_wq_callback *wqcb; | ||
| 2066 | |||
| 2067 | reqtag_pool = kzalloc(sizeof(*reqtag_pool), GFP_KERNEL); | ||
| 2068 | if (!reqtag_pool) | ||
| 2069 | return NULL; | ||
| 2070 | |||
| 2071 | INIT_LIST_HEAD(&reqtag_pool->freelist); | ||
| 2072 | /* initialize reqtag pool lock */ | ||
| 2073 | spin_lock_init(&reqtag_pool->lock); | ||
| 2074 | for (i = 0; i < U16_MAX; i++) { | ||
| 2075 | wqcb = kmalloc(sizeof(*wqcb), GFP_KERNEL); | ||
| 2076 | if (!wqcb) | ||
| 2077 | break; | ||
| 2078 | |||
| 2079 | reqtag_pool->tags[i] = wqcb; | ||
| 2080 | wqcb->instance_index = i; | ||
| 2081 | wqcb->callback = NULL; | ||
| 2082 | wqcb->arg = NULL; | ||
| 2083 | INIT_LIST_HEAD(&wqcb->list_entry); | ||
| 2084 | list_add_tail(&wqcb->list_entry, &reqtag_pool->freelist); | ||
| 2085 | } | ||
| 2086 | |||
| 2087 | return reqtag_pool; | ||
| 2088 | } | ||
| 2089 | |||
| 2090 | struct hw_wq_callback * | ||
| 2091 | efct_hw_reqtag_alloc(struct efct_hw *hw, | ||
| 2092 | void (*callback)(void *arg, u8 *cqe, int status), | ||
| 2093 | void *arg) | ||
| 2094 | { | ||
| 2095 | struct hw_wq_callback *wqcb = NULL; | ||
| 2096 | struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; | ||
| 2097 | unsigned long flags = 0; | ||
| 2098 | |||
| 2099 | if (!callback) | ||
| 2100 | return wqcb; | ||
| 2101 | |||
| 2102 | spin_lock_irqsave(&reqtag_pool->lock, flags); | ||
| 2103 | |||
| 2104 | if (!list_empty(&reqtag_pool->freelist)) { | ||
| 2105 | wqcb = list_first_entry(&reqtag_pool->freelist, | ||
| 2106 | struct hw_wq_callback, list_entry); | ||
| 2107 | } | ||
| 2108 | |||
| 2109 | if (wqcb) { | ||
| 2110 | list_del_init(&wqcb->list_entry); | ||
| 2111 | spin_unlock_irqrestore(&reqtag_pool->lock, flags); | ||
| 2112 | wqcb->callback = callback; | ||
| 2113 | wqcb->arg = arg; | ||
| 2114 | } else { | ||
| 2115 | spin_unlock_irqrestore(&reqtag_pool->lock, flags); | ||
| 2116 | } | ||
| 2117 | |||
| 2118 | return wqcb; | ||
| 2119 | } | ||
| 2120 | |||
| 2121 | void | ||
| 2122 | efct_hw_reqtag_free(struct efct_hw *hw, struct hw_wq_callback *wqcb) | ||
| 2123 | { | ||
| 2124 | unsigned long flags = 0; | ||
| 2125 | struct reqtag_pool *reqtag_pool = hw->wq_reqtag_pool; | ||
| 2126 | |||
| 2127 | if (!wqcb->callback) | ||
| 2128 | efc_log_err(hw->os, "WQCB is already freed\n"); | ||
| 2129 | |||
| 2130 | spin_lock_irqsave(&reqtag_pool->lock, flags); | ||
| 2131 | wqcb->callback = NULL; | ||
| 2132 | wqcb->arg = NULL; | ||
| 2133 | INIT_LIST_HEAD(&wqcb->list_entry); | ||
| 2134 | list_add(&wqcb->list_entry, &hw->wq_reqtag_pool->freelist); | ||
| 2135 | spin_unlock_irqrestore(&reqtag_pool->lock, flags); | ||
| 2136 | } | ||
| 2137 | |||
| 2138 | struct hw_wq_callback * | ||
| 2139 | efct_hw_reqtag_get_instance(struct efct_hw *hw, u32 instance_index) | ||
| 2140 | { | ||
| 2141 | struct hw_wq_callback *wqcb; | ||
| 2142 | |||
| 2143 | wqcb = hw->wq_reqtag_pool->tags[instance_index]; | ||
| 2144 | if (!wqcb) | ||
| 2145 | efc_log_err(hw->os, "wqcb for instance %d is null\n", | ||
| 2146 | instance_index); | ||
| 2147 | |||
| 2148 | return wqcb; | ||
| 2149 | } | ||
| 2150 | |||
| 2151 | int | ||
| 2152 | efct_hw_queue_hash_find(struct efct_queue_hash *hash, u16 id) | ||
| 2153 | { | ||
| 2154 | int index = -1; | ||
| 2155 | int i = id & (EFCT_HW_Q_HASH_SIZE - 1); | ||
| 2156 | |||
| 2157 | /* | ||
| 2158 | * Since the hash is always bigger than the maximum number of Qs, then | ||
| 2159 | * we never have to worry about an infinite loop. We will always find | ||
| 2160 | * an unused entry. | ||
| 2161 | */ | ||
| 2162 | do { | ||
| 2163 | if (hash[i].in_use && hash[i].id == id) | ||
| 2164 | index = hash[i].index; | ||
| 2165 | else | ||
| 2166 | i = (i + 1) & (EFCT_HW_Q_HASH_SIZE - 1); | ||
| 2167 | } while (index == -1 && hash[i].in_use); | ||
| 2168 | |||
| 2169 | return index; | ||
| 2170 | } | ||
| 2171 | |||
| 2172 | int | ||
| 2173 | efct_hw_process(struct efct_hw *hw, u32 vector, | ||
| 2174 | u32 max_isr_time_msec) | ||
| 2175 | { | ||
| 2176 | struct hw_eq *eq; | ||
| 2177 | |||
| 2178 | /* | ||
| 2179 | * The caller should disable interrupts if they wish to prevent us | ||
| 2180 | * from processing during a shutdown. The following states are defined: | ||
| 2181 | * EFCT_HW_STATE_UNINITIALIZED - No queues allocated | ||
| 2182 | * EFCT_HW_STATE_QUEUES_ALLOCATED - The state after a chip reset, | ||
| 2183 | * queues are cleared. | ||
| 2184 | * EFCT_HW_STATE_ACTIVE - Chip and queues are operational | ||
| 2185 | * EFCT_HW_STATE_RESET_IN_PROGRESS - reset, we still want completions | ||
| 2186 | * EFCT_HW_STATE_TEARDOWN_IN_PROGRESS - We still want mailbox | ||
| 2187 | * completions. | ||
| 2188 | */ | ||
| 2189 | if (hw->state == EFCT_HW_STATE_UNINITIALIZED) | ||
| 2190 | return 0; | ||
| 2191 | |||
| 2192 | /* Get pointer to struct hw_eq */ | ||
| 2193 | eq = hw->hw_eq[vector]; | ||
| 2194 | if (!eq) | ||
| 2195 | return 0; | ||
| 2196 | |||
| 2197 | eq->use_count++; | ||
| 2198 | |||
| 2199 | return efct_hw_eq_process(hw, eq, max_isr_time_msec); | ||
| 2200 | } | ||
| 2201 | |||
| 2202 | int | ||
| 2203 | efct_hw_eq_process(struct efct_hw *hw, struct hw_eq *eq, | ||
| 2204 | u32 max_isr_time_msec) | ||
| 2205 | { | ||
| 2206 | u8 eqe[sizeof(struct sli4_eqe)] = { 0 }; | ||
| 2207 | u32 tcheck_count; | ||
| 2208 | u64 tstart; | ||
| 2209 | u64 telapsed; | ||
| 2210 | bool done = false; | ||
| 2211 | |||
| 2212 | tcheck_count = EFCT_HW_TIMECHECK_ITERATIONS; | ||
| 2213 | tstart = jiffies_to_msecs(jiffies); | ||
| 2214 | |||
| 2215 | while (!done && !sli_eq_read(&hw->sli, eq->queue, eqe)) { | ||
| 2216 | u16 cq_id = 0; | ||
| 2217 | int rc; | ||
| 2218 | |||
| 2219 | rc = sli_eq_parse(&hw->sli, eqe, &cq_id); | ||
| 2220 | if (unlikely(rc)) { | ||
| 2221 | if (rc == SLI4_EQE_STATUS_EQ_FULL) { | ||
| 2222 | u32 i; | ||
| 2223 | |||
| 2224 | /* | ||
| 2225 | * Received a sentinel EQE indicating the | ||
| 2226 | * EQ is full. Process all CQs | ||
| 2227 | */ | ||
| 2228 | for (i = 0; i < hw->cq_count; i++) | ||
| 2229 | efct_hw_cq_process(hw, hw->hw_cq[i]); | ||
| 2230 | continue; | ||
| 2231 | } else { | ||
| 2232 | return rc; | ||
| 2233 | } | ||
| 2234 | } else { | ||
| 2235 | int index; | ||
| 2236 | |||
| 2237 | index = efct_hw_queue_hash_find(hw->cq_hash, cq_id); | ||
| 2238 | |||
| 2239 | if (likely(index >= 0)) | ||
| 2240 | efct_hw_cq_process(hw, hw->hw_cq[index]); | ||
| 2241 | else | ||
| 2242 | efc_log_err(hw->os, "bad CQ_ID %#06x\n", cq_id); | ||
| 2243 | } | ||
| 2244 | |||
| 2245 | if (eq->queue->n_posted > eq->queue->posted_limit) | ||
| 2246 | sli_queue_arm(&hw->sli, eq->queue, false); | ||
| 2247 | |||
| 2248 | if (tcheck_count && (--tcheck_count == 0)) { | ||
| 2249 | tcheck_count = EFCT_HW_TIMECHECK_ITERATIONS; | ||
| 2250 | telapsed = jiffies_to_msecs(jiffies) - tstart; | ||
| 2251 | if (telapsed >= max_isr_time_msec) | ||
| 2252 | done = true; | ||
| 2253 | } | ||
| 2254 | } | ||
| 2255 | sli_queue_eq_arm(&hw->sli, eq->queue, true); | ||
| 2256 | |||
| 2257 | return 0; | ||
| 2258 | } | ||
| 2259 | |||
| 2260 | static int | ||
| 2261 | _efct_hw_wq_write(struct hw_wq *wq, struct efct_hw_wqe *wqe) | ||
| 2262 | { | ||
| 2263 | int queue_rc; | ||
| 2264 | |||
| 2265 | /* Every so often, set the wqec bit to generate comsummed completions */ | ||
| 2266 | if (wq->wqec_count) | ||
| 2267 | wq->wqec_count--; | ||
| 2268 | |||
| 2269 | if (wq->wqec_count == 0) { | ||
| 2270 | struct sli4_generic_wqe *genwqe = (void *)wqe->wqebuf; | ||
| 2271 | |||
| 2272 | genwqe->cmdtype_wqec_byte |= SLI4_GEN_WQE_WQEC; | ||
| 2273 | wq->wqec_count = wq->wqec_set_count; | ||
| 2274 | } | ||
| 2275 | |||
| 2276 | /* Decrement WQ free count */ | ||
| 2277 | wq->free_count--; | ||
| 2278 | |||
| 2279 | queue_rc = sli_wq_write(&wq->hw->sli, wq->queue, wqe->wqebuf); | ||
| 2280 | |||
| 2281 | return (queue_rc < 0) ? -EIO : 0; | ||
| 2282 | } | ||
| 2283 | |||
| 2284 | static void | ||
| 2285 | hw_wq_submit_pending(struct hw_wq *wq, u32 update_free_count) | ||
| 2286 | { | ||
| 2287 | struct efct_hw_wqe *wqe; | ||
| 2288 | unsigned long flags = 0; | ||
| 2289 | |||
| 2290 | spin_lock_irqsave(&wq->queue->lock, flags); | ||
| 2291 | |||
| 2292 | /* Update free count with value passed in */ | ||
| 2293 | wq->free_count += update_free_count; | ||
| 2294 | |||
| 2295 | while ((wq->free_count > 0) && (!list_empty(&wq->pending_list))) { | ||
| 2296 | wqe = list_first_entry(&wq->pending_list, | ||
| 2297 | struct efct_hw_wqe, list_entry); | ||
| 2298 | list_del_init(&wqe->list_entry); | ||
| 2299 | _efct_hw_wq_write(wq, wqe); | ||
| 2300 | |||
| 2301 | if (wqe->abort_wqe_submit_needed) { | ||
| 2302 | wqe->abort_wqe_submit_needed = false; | ||
| 2303 | efct_hw_fill_abort_wqe(wq->hw, wqe); | ||
| 2304 | INIT_LIST_HEAD(&wqe->list_entry); | ||
| 2305 | list_add_tail(&wqe->list_entry, &wq->pending_list); | ||
| 2306 | wq->wq_pending_count++; | ||
| 2307 | } | ||
| 2308 | } | ||
| 2309 | |||
| 2310 | spin_unlock_irqrestore(&wq->queue->lock, flags); | ||
| 2311 | } | ||
| 2312 | |||
| 2313 | void | ||
| 2314 | efct_hw_cq_process(struct efct_hw *hw, struct hw_cq *cq) | ||
| 2315 | { | ||
| 2316 | u8 cqe[sizeof(struct sli4_mcqe)]; | ||
| 2317 | u16 rid = U16_MAX; | ||
| 2318 | /* completion type */ | ||
| 2319 | enum sli4_qentry ctype; | ||
| 2320 | u32 n_processed = 0; | ||
| 2321 | u32 tstart, telapsed; | ||
| 2322 | |||
| 2323 | tstart = jiffies_to_msecs(jiffies); | ||
| 2324 | |||
| 2325 | while (!sli_cq_read(&hw->sli, cq->queue, cqe)) { | ||
| 2326 | int status; | ||
| 2327 | |||
| 2328 | status = sli_cq_parse(&hw->sli, cq->queue, cqe, &ctype, &rid); | ||
| 2329 | /* | ||
| 2330 | * The sign of status is significant. If status is: | ||
| 2331 | * == 0 : call completed correctly and | ||
| 2332 | * the CQE indicated success | ||
| 2333 | * > 0 : call completed correctly and | ||
| 2334 | * the CQE indicated an error | ||
| 2335 | * < 0 : call failed and no information is available about the | ||
| 2336 | * CQE | ||
| 2337 | */ | ||
| 2338 | if (status < 0) { | ||
| 2339 | if (status == SLI4_MCQE_STATUS_NOT_COMPLETED) | ||
| 2340 | /* | ||
| 2341 | * Notification that an entry was consumed, | ||
| 2342 | * but not completed | ||
| 2343 | */ | ||
| 2344 | continue; | ||
| 2345 | |||
| 2346 | break; | ||
| 2347 | } | ||
| 2348 | |||
| 2349 | switch (ctype) { | ||
| 2350 | case SLI4_QENTRY_ASYNC: | ||
| 2351 | sli_cqe_async(&hw->sli, cqe); | ||
| 2352 | break; | ||
| 2353 | case SLI4_QENTRY_MQ: | ||
| 2354 | /* | ||
| 2355 | * Process MQ entry. Note there is no way to determine | ||
| 2356 | * the MQ_ID from the completion entry. | ||
| 2357 | */ | ||
| 2358 | efct_hw_mq_process(hw, status, hw->mq); | ||
| 2359 | break; | ||
| 2360 | case SLI4_QENTRY_WQ: | ||
| 2361 | efct_hw_wq_process(hw, cq, cqe, status, rid); | ||
| 2362 | break; | ||
| 2363 | case SLI4_QENTRY_WQ_RELEASE: { | ||
| 2364 | u32 wq_id = rid; | ||
| 2365 | int index; | ||
| 2366 | struct hw_wq *wq = NULL; | ||
| 2367 | |||
| 2368 | index = efct_hw_queue_hash_find(hw->wq_hash, wq_id); | ||
| 2369 | |||
| 2370 | if (likely(index >= 0)) { | ||
| 2371 | wq = hw->hw_wq[index]; | ||
| 2372 | } else { | ||
| 2373 | efc_log_err(hw->os, "bad WQ_ID %#06x\n", wq_id); | ||
| 2374 | break; | ||
| 2375 | } | ||
| 2376 | /* Submit any HW IOs that are on the WQ pending list */ | ||
| 2377 | hw_wq_submit_pending(wq, wq->wqec_set_count); | ||
| 2378 | |||
| 2379 | break; | ||
| 2380 | } | ||
| 2381 | |||
| 2382 | case SLI4_QENTRY_RQ: | ||
| 2383 | efct_hw_rqpair_process_rq(hw, cq, cqe); | ||
| 2384 | break; | ||
| 2385 | case SLI4_QENTRY_XABT: { | ||
| 2386 | efct_hw_xabt_process(hw, cq, cqe, rid); | ||
| 2387 | break; | ||
| 2388 | } | ||
| 2389 | default: | ||
| 2390 | efc_log_debug(hw->os, "unhandled ctype=%#x rid=%#x\n", | ||
| 2391 | ctype, rid); | ||
| 2392 | break; | ||
| 2393 | } | ||
| 2394 | |||
| 2395 | n_processed++; | ||
| 2396 | if (n_processed == cq->queue->proc_limit) | ||
| 2397 | break; | ||
| 2398 | |||
| 2399 | if (cq->queue->n_posted >= cq->queue->posted_limit) | ||
| 2400 | sli_queue_arm(&hw->sli, cq->queue, false); | ||
| 2401 | } | ||
| 2402 | |||
| 2403 | sli_queue_arm(&hw->sli, cq->queue, true); | ||
| 2404 | |||
| 2405 | if (n_processed > cq->queue->max_num_processed) | ||
| 2406 | cq->queue->max_num_processed = n_processed; | ||
| 2407 | telapsed = jiffies_to_msecs(jiffies) - tstart; | ||
| 2408 | if (telapsed > cq->queue->max_process_time) | ||
| 2409 | cq->queue->max_process_time = telapsed; | ||
| 2410 | } | ||
| 2411 | |||
| 2412 | void | ||
| 2413 | efct_hw_wq_process(struct efct_hw *hw, struct hw_cq *cq, | ||
| 2414 | u8 *cqe, int status, u16 rid) | ||
| 2415 | { | ||
| 2416 | struct hw_wq_callback *wqcb; | ||
| 2417 | |||
| 2418 | if (rid == EFCT_HW_REQUE_XRI_REGTAG) { | ||
| 2419 | if (status) | ||
| 2420 | efc_log_err(hw->os, "reque xri failed, status = %d\n", | ||
| 2421 | status); | ||
| 2422 | return; | ||
| 2423 | } | ||
| 2424 | |||
| 2425 | wqcb = efct_hw_reqtag_get_instance(hw, rid); | ||
| 2426 | if (!wqcb) { | ||
| 2427 | efc_log_err(hw->os, "invalid request tag: x%x\n", rid); | ||
| 2428 | return; | ||
| 2429 | } | ||
| 2430 | |||
| 2431 | if (!wqcb->callback) { | ||
| 2432 | efc_log_err(hw->os, "wqcb callback is NULL\n"); | ||
| 2433 | return; | ||
| 2434 | } | ||
| 2435 | |||
| 2436 | (*wqcb->callback)(wqcb->arg, cqe, status); | ||
| 2437 | } | ||
| 2438 | |||
| 2439 | void | ||
| 2440 | efct_hw_xabt_process(struct efct_hw *hw, struct hw_cq *cq, | ||
| 2441 | u8 *cqe, u16 rid) | ||
| 2442 | { | ||
| 2443 | /* search IOs wait free list */ | ||
| 2444 | struct efct_hw_io *io = NULL; | ||
| 2445 | unsigned long flags = 0; | ||
| 2446 | |||
| 2447 | io = efct_hw_io_lookup(hw, rid); | ||
| 2448 | if (!io) { | ||
| 2449 | /* IO lookup failure should never happen */ | ||
| 2450 | efc_log_err(hw->os, "xabt io lookup failed rid=%#x\n", rid); | ||
| 2451 | return; | ||
| 2452 | } | ||
| 2453 | |||
| 2454 | if (!io->xbusy) | ||
| 2455 | efc_log_debug(hw->os, "xabt io not busy rid=%#x\n", rid); | ||
| 2456 | else | ||
| 2457 | /* mark IO as no longer busy */ | ||
| 2458 | io->xbusy = false; | ||
| 2459 | |||
| 2460 | /* | ||
| 2461 | * For IOs that were aborted internally, we need to issue any pending | ||
| 2462 | * callback here. | ||
| 2463 | */ | ||
| 2464 | if (io->done) { | ||
| 2465 | efct_hw_done_t done = io->done; | ||
| 2466 | void *arg = io->arg; | ||
| 2467 | |||
| 2468 | /* | ||
| 2469 | * Use latched status as this is always saved for an internal | ||
| 2470 | * abort | ||
| 2471 | */ | ||
| 2472 | int status = io->saved_status; | ||
| 2473 | u32 len = io->saved_len; | ||
| 2474 | u32 ext = io->saved_ext; | ||
| 2475 | |||
| 2476 | io->done = NULL; | ||
| 2477 | io->status_saved = false; | ||
| 2478 | |||
| 2479 | done(io, len, status, ext, arg); | ||
| 2480 | } | ||
| 2481 | |||
| 2482 | spin_lock_irqsave(&hw->io_lock, flags); | ||
| 2483 | if (io->state == EFCT_HW_IO_STATE_INUSE || | ||
| 2484 | io->state == EFCT_HW_IO_STATE_WAIT_FREE) { | ||
| 2485 | /* if on wait_free list, caller has already freed IO; | ||
| 2486 | * remove from wait_free list and add to free list. | ||
| 2487 | * if on in-use list, already marked as no longer busy; | ||
| 2488 | * just leave there and wait for caller to free. | ||
| 2489 | */ | ||
| 2490 | if (io->state == EFCT_HW_IO_STATE_WAIT_FREE) { | ||
| 2491 | io->state = EFCT_HW_IO_STATE_FREE; | ||
| 2492 | list_del_init(&io->list_entry); | ||
| 2493 | efct_hw_io_free_move_correct_list(hw, io); | ||
| 2494 | } | ||
| 2495 | } | ||
| 2496 | spin_unlock_irqrestore(&hw->io_lock, flags); | ||
| 2497 | } | ||
| 2498 | |||
| 2499 | static int | ||
| 2500 | efct_hw_flush(struct efct_hw *hw) | ||
| 2501 | { | ||
| 2502 | u32 i = 0; | ||
| 2503 | |||
| 2504 | /* Process any remaining completions */ | ||
| 2505 | for (i = 0; i < hw->eq_count; i++) | ||
| 2506 | efct_hw_process(hw, i, ~0); | ||
| 2507 | |||
| 2508 | return 0; | ||
| 2509 | } | ||
| 2510 | |||
| 2511 | int | ||
| 2512 | efct_hw_wq_write(struct hw_wq *wq, struct efct_hw_wqe *wqe) | ||
| 2513 | { | ||
| 2514 | int rc = 0; | ||
| 2515 | unsigned long flags = 0; | ||
| 2516 | |||
| 2517 | spin_lock_irqsave(&wq->queue->lock, flags); | ||
| 2518 | if (list_empty(&wq->pending_list)) { | ||
| 2519 | if (wq->free_count > 0) { | ||
| 2520 | rc = _efct_hw_wq_write(wq, wqe); | ||
| 2521 | } else { | ||
| 2522 | INIT_LIST_HEAD(&wqe->list_entry); | ||
| 2523 | list_add_tail(&wqe->list_entry, &wq->pending_list); | ||
| 2524 | wq->wq_pending_count++; | ||
| 2525 | } | ||
| 2526 | |||
| 2527 | spin_unlock_irqrestore(&wq->queue->lock, flags); | ||
| 2528 | return rc; | ||
| 2529 | } | ||
| 2530 | |||
| 2531 | INIT_LIST_HEAD(&wqe->list_entry); | ||
| 2532 | list_add_tail(&wqe->list_entry, &wq->pending_list); | ||
| 2533 | wq->wq_pending_count++; | ||
| 2534 | while (wq->free_count > 0) { | ||
| 2535 | wqe = list_first_entry(&wq->pending_list, struct efct_hw_wqe, | ||
| 2536 | list_entry); | ||
| 2537 | if (!wqe) | ||
| 2538 | break; | ||
| 2539 | |||
| 2540 | list_del_init(&wqe->list_entry); | ||
| 2541 | rc = _efct_hw_wq_write(wq, wqe); | ||
| 2542 | if (rc) | ||
| 2543 | break; | ||
| 2544 | |||
| 2545 | if (wqe->abort_wqe_submit_needed) { | ||
| 2546 | wqe->abort_wqe_submit_needed = false; | ||
| 2547 | efct_hw_fill_abort_wqe(wq->hw, wqe); | ||
| 2548 | |||
| 2549 | INIT_LIST_HEAD(&wqe->list_entry); | ||
| 2550 | list_add_tail(&wqe->list_entry, &wq->pending_list); | ||
| 2551 | wq->wq_pending_count++; | ||
| 2552 | } | ||
| 2553 | } | ||
| 2554 | |||
| 2555 | spin_unlock_irqrestore(&wq->queue->lock, flags); | ||
| 2556 | |||
| 2557 | return rc; | ||
| 2558 | } | ||
| 2559 | |||
| 2560 | int | ||
| 2561 | efct_efc_bls_send(struct efc *efc, u32 type, struct sli_bls_params *bls) | ||
| 2562 | { | ||
| 2563 | struct efct *efct = efc->base; | ||
| 2564 | |||
| 2565 | return efct_hw_bls_send(efct, type, bls, NULL, NULL); | ||
| 2566 | } | ||
| 2567 | |||
| 2568 | int | ||
| 2569 | efct_hw_bls_send(struct efct *efct, u32 type, struct sli_bls_params *bls_params, | ||
| 2570 | void *cb, void *arg) | ||
| 2571 | { | ||
| 2572 | struct efct_hw *hw = &efct->hw; | ||
| 2573 | struct efct_hw_io *hio; | ||
| 2574 | struct sli_bls_payload bls; | ||
| 2575 | int rc; | ||
| 2576 | |||
| 2577 | if (hw->state != EFCT_HW_STATE_ACTIVE) { | ||
| 2578 | efc_log_err(hw->os, | ||
| 2579 | "cannot send BLS, HW state=%d\n", hw->state); | ||
| 2580 | return -EIO; | ||
| 2581 | } | ||
| 2582 | |||
| 2583 | hio = efct_hw_io_alloc(hw); | ||
| 2584 | if (!hio) { | ||
| 2585 | efc_log_err(hw->os, "HIO allocation failed\n"); | ||
| 2586 | return -EIO; | ||
| 2587 | } | ||
| 2588 | |||
| 2589 | hio->done = cb; | ||
| 2590 | hio->arg = arg; | ||
| 2591 | |||
| 2592 | bls_params->xri = hio->indicator; | ||
| 2593 | bls_params->tag = hio->reqtag; | ||
| 2594 | |||
| 2595 | if (type == FC_RCTL_BA_ACC) { | ||
| 2596 | hio->type = EFCT_HW_BLS_ACC; | ||
| 2597 | bls.type = SLI4_SLI_BLS_ACC; | ||
| 2598 | memcpy(&bls.u.acc, bls_params->payload, sizeof(bls.u.acc)); | ||
| 2599 | } else { | ||
| 2600 | hio->type = EFCT_HW_BLS_RJT; | ||
| 2601 | bls.type = SLI4_SLI_BLS_RJT; | ||
| 2602 | memcpy(&bls.u.rjt, bls_params->payload, sizeof(bls.u.rjt)); | ||
| 2603 | } | ||
| 2604 | |||
| 2605 | bls.ox_id = cpu_to_le16(bls_params->ox_id); | ||
| 2606 | bls.rx_id = cpu_to_le16(bls_params->rx_id); | ||
| 2607 | |||
| 2608 | if (sli_xmit_bls_rsp64_wqe(&hw->sli, hio->wqe.wqebuf, | ||
| 2609 | &bls, bls_params)) { | ||
| 2610 | efc_log_err(hw->os, "XMIT_BLS_RSP64 WQE error\n"); | ||
| 2611 | return -EIO; | ||
| 2612 | } | ||
| 2613 | |||
| 2614 | hio->xbusy = true; | ||
| 2615 | |||
| 2616 | /* | ||
| 2617 | * Add IO to active io wqe list before submitting, in case the | ||
| 2618 | * wcqe processing preempts this thread. | ||
| 2619 | */ | ||
| 2620 | hio->wq->use_count++; | ||
| 2621 | rc = efct_hw_wq_write(hio->wq, &hio->wqe); | ||
| 2622 | if (rc >= 0) { | ||
| 2623 | /* non-negative return is success */ | ||
| 2624 | rc = 0; | ||
| 2625 | } else { | ||
| 2626 | /* failed to write wqe, remove from active wqe list */ | ||
| 2627 | efc_log_err(hw->os, | ||
| 2628 | "sli_queue_write failed: %d\n", rc); | ||
| 2629 | hio->xbusy = false; | ||
| 2630 | } | ||
| 2631 | |||
| 2632 | return rc; | ||
| 2633 | } | ||
| 2634 | |||
| 2635 | static int | ||
| 2636 | efct_els_ssrs_send_cb(struct efct_hw_io *hio, u32 length, int status, | ||
| 2637 | u32 ext_status, void *arg) | ||
| 2638 | { | ||
| 2639 | struct efc_disc_io *io = arg; | ||
| 2640 | |||
| 2641 | efc_disc_io_complete(io, length, status, ext_status); | ||
| 2642 | return 0; | ||
| 2643 | } | ||
| 2644 | |||
| 2645 | static inline void | ||
| 2646 | efct_fill_els_params(struct efc_disc_io *io, struct sli_els_params *params) | ||
| 2647 | { | ||
| 2648 | u8 *cmd = io->req.virt; | ||
| 2649 | |||
| 2650 | params->cmd = *cmd; | ||
| 2651 | params->s_id = io->s_id; | ||
| 2652 | params->d_id = io->d_id; | ||
| 2653 | params->ox_id = io->iparam.els.ox_id; | ||
| 2654 | params->rpi = io->rpi; | ||
| 2655 | params->vpi = io->vpi; | ||
| 2656 | params->rpi_registered = io->rpi_registered; | ||
| 2657 | params->xmit_len = io->xmit_len; | ||
| 2658 | params->rsp_len = io->rsp_len; | ||
| 2659 | params->timeout = io->iparam.els.timeout; | ||
| 2660 | } | ||
| 2661 | |||
| 2662 | static inline void | ||
| 2663 | efct_fill_ct_params(struct efc_disc_io *io, struct sli_ct_params *params) | ||
| 2664 | { | ||
| 2665 | params->r_ctl = io->iparam.ct.r_ctl; | ||
| 2666 | params->type = io->iparam.ct.type; | ||
| 2667 | params->df_ctl = io->iparam.ct.df_ctl; | ||
| 2668 | params->d_id = io->d_id; | ||
| 2669 | params->ox_id = io->iparam.ct.ox_id; | ||
| 2670 | params->rpi = io->rpi; | ||
| 2671 | params->vpi = io->vpi; | ||
| 2672 | params->rpi_registered = io->rpi_registered; | ||
| 2673 | params->xmit_len = io->xmit_len; | ||
| 2674 | params->rsp_len = io->rsp_len; | ||
| 2675 | params->timeout = io->iparam.ct.timeout; | ||
| 2676 | } | ||
| 2677 | |||
| 2678 | /** | ||
| 2679 | * efct_els_hw_srrs_send() - Send a single request and response cmd. | ||
| 2680 | * @efc: efc library structure | ||
| 2681 | * @io: Discovery IO used to hold els and ct cmd context. | ||
| 2682 | * | ||
| 2683 | * This routine supports communication sequences consisting of a single | ||
| 2684 | * request and single response between two endpoints. Examples include: | ||
| 2685 | * - Sending an ELS request. | ||
| 2686 | * - Sending an ELS response - To send an ELS response, the caller must provide | ||
| 2687 | * the OX_ID from the received request. | ||
| 2688 | * - Sending a FC Common Transport (FC-CT) request - To send a FC-CT request, | ||
| 2689 | * the caller must provide the R_CTL, TYPE, and DF_CTL | ||
| 2690 | * values to place in the FC frame header. | ||
| 2691 | * | ||
| 2692 | * Return: Status of the request. | ||
| 2693 | */ | ||
| 2694 | int | ||
| 2695 | efct_els_hw_srrs_send(struct efc *efc, struct efc_disc_io *io) | ||
| 2696 | { | ||
| 2697 | struct efct *efct = efc->base; | ||
| 2698 | struct efct_hw_io *hio; | ||
| 2699 | struct efct_hw *hw = &efct->hw; | ||
| 2700 | struct efc_dma *send = &io->req; | ||
| 2701 | struct efc_dma *receive = &io->rsp; | ||
| 2702 | struct sli4_sge *sge = NULL; | ||
| 2703 | int rc = 0; | ||
| 2704 | u32 len = io->xmit_len; | ||
| 2705 | u32 sge0_flags; | ||
| 2706 | u32 sge1_flags; | ||
| 2707 | |||
| 2708 | hio = efct_hw_io_alloc(hw); | ||
| 2709 | if (!hio) { | ||
| 2710 | pr_err("HIO alloc failed\n"); | ||
| 2711 | return -EIO; | ||
| 2712 | } | ||
| 2713 | |||
| 2714 | if (hw->state != EFCT_HW_STATE_ACTIVE) { | ||
| 2715 | efc_log_debug(hw->os, | ||
| 2716 | "cannot send SRRS, HW state=%d\n", hw->state); | ||
| 2717 | return -EIO; | ||
| 2718 | } | ||
| 2719 | |||
| 2720 | hio->done = efct_els_ssrs_send_cb; | ||
| 2721 | hio->arg = io; | ||
| 2722 | |||
| 2723 | sge = hio->sgl->virt; | ||
| 2724 | |||
| 2725 | /* clear both SGE */ | ||
| 2726 | memset(hio->sgl->virt, 0, 2 * sizeof(struct sli4_sge)); | ||
| 2727 | |||
| 2728 | sge0_flags = le32_to_cpu(sge[0].dw2_flags); | ||
| 2729 | sge1_flags = le32_to_cpu(sge[1].dw2_flags); | ||
| 2730 | if (send->size) { | ||
| 2731 | sge[0].buffer_address_high = | ||
| 2732 | cpu_to_le32(upper_32_bits(send->phys)); | ||
| 2733 | sge[0].buffer_address_low = | ||
| 2734 | cpu_to_le32(lower_32_bits(send->phys)); | ||
| 2735 | |||
| 2736 | sge0_flags |= (SLI4_SGE_TYPE_DATA << SLI4_SGE_TYPE_SHIFT); | ||
| 2737 | |||
| 2738 | sge[0].buffer_length = cpu_to_le32(len); | ||
| 2739 | } | ||
| 2740 | |||
| 2741 | if (io->io_type == EFC_DISC_IO_ELS_REQ || | ||
| 2742 | io->io_type == EFC_DISC_IO_CT_REQ) { | ||
| 2743 | sge[1].buffer_address_high = | ||
| 2744 | cpu_to_le32(upper_32_bits(receive->phys)); | ||
| 2745 | sge[1].buffer_address_low = | ||
| 2746 | cpu_to_le32(lower_32_bits(receive->phys)); | ||
| 2747 | |||
| 2748 | sge1_flags |= (SLI4_SGE_TYPE_DATA << SLI4_SGE_TYPE_SHIFT); | ||
| 2749 | sge1_flags |= SLI4_SGE_LAST; | ||
| 2750 | |||
| 2751 | sge[1].buffer_length = cpu_to_le32(receive->size); | ||
| 2752 | } else { | ||
| 2753 | sge0_flags |= SLI4_SGE_LAST; | ||
| 2754 | } | ||
| 2755 | |||
| 2756 | sge[0].dw2_flags = cpu_to_le32(sge0_flags); | ||
| 2757 | sge[1].dw2_flags = cpu_to_le32(sge1_flags); | ||
| 2758 | |||
| 2759 | switch (io->io_type) { | ||
| 2760 | case EFC_DISC_IO_ELS_REQ: { | ||
| 2761 | struct sli_els_params els_params; | ||
| 2762 | |||
| 2763 | hio->type = EFCT_HW_ELS_REQ; | ||
| 2764 | efct_fill_els_params(io, &els_params); | ||
| 2765 | els_params.xri = hio->indicator; | ||
| 2766 | els_params.tag = hio->reqtag; | ||
| 2767 | |||
| 2768 | if (sli_els_request64_wqe(&hw->sli, hio->wqe.wqebuf, hio->sgl, | ||
| 2769 | &els_params)) { | ||
| 2770 | efc_log_err(hw->os, "REQ WQE error\n"); | ||
| 2771 | rc = -EIO; | ||
| 2772 | } | ||
| 2773 | break; | ||
| 2774 | } | ||
| 2775 | case EFC_DISC_IO_ELS_RESP: { | ||
| 2776 | struct sli_els_params els_params; | ||
| 2777 | |||
| 2778 | hio->type = EFCT_HW_ELS_RSP; | ||
| 2779 | efct_fill_els_params(io, &els_params); | ||
| 2780 | els_params.xri = hio->indicator; | ||
| 2781 | els_params.tag = hio->reqtag; | ||
| 2782 | if (sli_xmit_els_rsp64_wqe(&hw->sli, hio->wqe.wqebuf, send, | ||
| 2783 | &els_params)){ | ||
| 2784 | efc_log_err(hw->os, "RSP WQE error\n"); | ||
| 2785 | rc = -EIO; | ||
| 2786 | } | ||
| 2787 | break; | ||
| 2788 | } | ||
| 2789 | case EFC_DISC_IO_CT_REQ: { | ||
| 2790 | struct sli_ct_params ct_params; | ||
| 2791 | |||
| 2792 | hio->type = EFCT_HW_FC_CT; | ||
| 2793 | efct_fill_ct_params(io, &ct_params); | ||
| 2794 | ct_params.xri = hio->indicator; | ||
| 2795 | ct_params.tag = hio->reqtag; | ||
| 2796 | if (sli_gen_request64_wqe(&hw->sli, hio->wqe.wqebuf, hio->sgl, | ||
| 2797 | &ct_params)){ | ||
| 2798 | efc_log_err(hw->os, "GEN WQE error\n"); | ||
| 2799 | rc = -EIO; | ||
| 2800 | } | ||
| 2801 | break; | ||
| 2802 | } | ||
| 2803 | case EFC_DISC_IO_CT_RESP: { | ||
| 2804 | struct sli_ct_params ct_params; | ||
| 2805 | |||
| 2806 | hio->type = EFCT_HW_FC_CT_RSP; | ||
| 2807 | efct_fill_ct_params(io, &ct_params); | ||
| 2808 | ct_params.xri = hio->indicator; | ||
| 2809 | ct_params.tag = hio->reqtag; | ||
| 2810 | if (sli_xmit_sequence64_wqe(&hw->sli, hio->wqe.wqebuf, hio->sgl, | ||
| 2811 | &ct_params)){ | ||
| 2812 | efc_log_err(hw->os, "XMIT SEQ WQE error\n"); | ||
| 2813 | rc = -EIO; | ||
| 2814 | } | ||
| 2815 | break; | ||
| 2816 | } | ||
| 2817 | default: | ||
| 2818 | efc_log_err(hw->os, "bad SRRS type %#x\n", io->io_type); | ||
| 2819 | rc = -EIO; | ||
| 2820 | } | ||
| 2821 | |||
| 2822 | if (rc == 0) { | ||
| 2823 | hio->xbusy = true; | ||
| 2824 | |||
| 2825 | /* | ||
| 2826 | * Add IO to active io wqe list before submitting, in case the | ||
| 2827 | * wcqe processing preempts this thread. | ||
| 2828 | */ | ||
| 2829 | hio->wq->use_count++; | ||
| 2830 | rc = efct_hw_wq_write(hio->wq, &hio->wqe); | ||
| 2831 | if (rc >= 0) { | ||
| 2832 | /* non-negative return is success */ | ||
| 2833 | rc = 0; | ||
| 2834 | } else { | ||
| 2835 | /* failed to write wqe, remove from active wqe list */ | ||
| 2836 | efc_log_err(hw->os, | ||
| 2837 | "sli_queue_write failed: %d\n", rc); | ||
| 2838 | hio->xbusy = false; | ||
| 2839 | } | ||
| 2840 | } | ||
| 2841 | |||
| 2842 | return rc; | ||
| 2843 | } | ||
| 2844 | |||
| 2845 | int | ||
| 2846 | efct_hw_io_send(struct efct_hw *hw, enum efct_hw_io_type type, | ||
| 2847 | struct efct_hw_io *io, union efct_hw_io_param_u *iparam, | ||
| 2848 | void *cb, void *arg) | ||
| 2849 | { | ||
| 2850 | int rc = 0; | ||
| 2851 | bool send_wqe = true; | ||
| 2852 | |||
| 2853 | if (!io) { | ||
| 2854 | pr_err("bad parm hw=%p io=%p\n", hw, io); | ||
| 2855 | return -EIO; | ||
| 2856 | } | ||
| 2857 | |||
| 2858 | if (hw->state != EFCT_HW_STATE_ACTIVE) { | ||
| 2859 | efc_log_err(hw->os, "cannot send IO, HW state=%d\n", hw->state); | ||
| 2860 | return -EIO; | ||
| 2861 | } | ||
| 2862 | |||
| 2863 | /* | ||
| 2864 | * Save state needed during later stages | ||
| 2865 | */ | ||
| 2866 | io->type = type; | ||
| 2867 | io->done = cb; | ||
| 2868 | io->arg = arg; | ||
| 2869 | |||
| 2870 | /* | ||
| 2871 | * Format the work queue entry used to send the IO | ||
| 2872 | */ | ||
| 2873 | switch (type) { | ||
| 2874 | case EFCT_HW_IO_TARGET_WRITE: { | ||
| 2875 | u16 *flags = &iparam->fcp_tgt.flags; | ||
| 2876 | struct fcp_txrdy *xfer = io->xfer_rdy.virt; | ||
| 2877 | |||
| 2878 | /* | ||
| 2879 | * Fill in the XFER_RDY for IF_TYPE 0 devices | ||
| 2880 | */ | ||
| 2881 | xfer->ft_data_ro = cpu_to_be32(iparam->fcp_tgt.offset); | ||
| 2882 | xfer->ft_burst_len = cpu_to_be32(iparam->fcp_tgt.xmit_len); | ||
| 2883 | |||
| 2884 | if (io->xbusy) | ||
| 2885 | *flags |= SLI4_IO_CONTINUATION; | ||
| 2886 | else | ||
| 2887 | *flags &= ~SLI4_IO_CONTINUATION; | ||
| 2888 | iparam->fcp_tgt.xri = io->indicator; | ||
| 2889 | iparam->fcp_tgt.tag = io->reqtag; | ||
| 2890 | |||
| 2891 | if (sli_fcp_treceive64_wqe(&hw->sli, io->wqe.wqebuf, | ||
| 2892 | &io->def_sgl, io->first_data_sge, | ||
| 2893 | SLI4_CQ_DEFAULT, | ||
| 2894 | 0, 0, &iparam->fcp_tgt)) { | ||
| 2895 | efc_log_err(hw->os, "TRECEIVE WQE error\n"); | ||
| 2896 | rc = -EIO; | ||
| 2897 | } | ||
| 2898 | break; | ||
| 2899 | } | ||
| 2900 | case EFCT_HW_IO_TARGET_READ: { | ||
| 2901 | u16 *flags = &iparam->fcp_tgt.flags; | ||
| 2902 | |||
| 2903 | if (io->xbusy) | ||
| 2904 | *flags |= SLI4_IO_CONTINUATION; | ||
| 2905 | else | ||
| 2906 | *flags &= ~SLI4_IO_CONTINUATION; | ||
| 2907 | |||
| 2908 | iparam->fcp_tgt.xri = io->indicator; | ||
| 2909 | iparam->fcp_tgt.tag = io->reqtag; | ||
| 2910 | |||
| 2911 | if (sli_fcp_tsend64_wqe(&hw->sli, io->wqe.wqebuf, | ||
| 2912 | &io->def_sgl, io->first_data_sge, | ||
| 2913 | SLI4_CQ_DEFAULT, | ||
| 2914 | 0, 0, &iparam->fcp_tgt)) { | ||
| 2915 | efc_log_err(hw->os, "TSEND WQE error\n"); | ||
| 2916 | rc = -EIO; | ||
| 2917 | } | ||
| 2918 | break; | ||
| 2919 | } | ||
| 2920 | case EFCT_HW_IO_TARGET_RSP: { | ||
| 2921 | u16 *flags = &iparam->fcp_tgt.flags; | ||
| 2922 | |||
| 2923 | if (io->xbusy) | ||
| 2924 | *flags |= SLI4_IO_CONTINUATION; | ||
| 2925 | else | ||
| 2926 | *flags &= ~SLI4_IO_CONTINUATION; | ||
| 2927 | |||
| 2928 | iparam->fcp_tgt.xri = io->indicator; | ||
| 2929 | iparam->fcp_tgt.tag = io->reqtag; | ||
| 2930 | |||
| 2931 | if (sli_fcp_trsp64_wqe(&hw->sli, io->wqe.wqebuf, | ||
| 2932 | &io->def_sgl, SLI4_CQ_DEFAULT, | ||
| 2933 | 0, &iparam->fcp_tgt)) { | ||
| 2934 | efc_log_err(hw->os, "TRSP WQE error\n"); | ||
| 2935 | rc = -EIO; | ||
| 2936 | } | ||
| 2937 | |||
| 2938 | break; | ||
| 2939 | } | ||
| 2940 | default: | ||
| 2941 | efc_log_err(hw->os, "unsupported IO type %#x\n", type); | ||
| 2942 | rc = -EIO; | ||
| 2943 | } | ||
| 2944 | |||
| 2945 | if (send_wqe && rc == 0) { | ||
| 2946 | io->xbusy = true; | ||
| 2947 | |||
| 2948 | /* | ||
| 2949 | * Add IO to active io wqe list before submitting, in case the | ||
| 2950 | * wcqe processing preempts this thread. | ||
| 2951 | */ | ||
| 2952 | hw->tcmd_wq_submit[io->wq->instance]++; | ||
| 2953 | io->wq->use_count++; | ||
| 2954 | rc = efct_hw_wq_write(io->wq, &io->wqe); | ||
| 2955 | if (rc >= 0) { | ||
| 2956 | /* non-negative return is success */ | ||
| 2957 | rc = 0; | ||
| 2958 | } else { | ||
| 2959 | /* failed to write wqe, remove from active wqe list */ | ||
| 2960 | efc_log_err(hw->os, | ||
| 2961 | "sli_queue_write failed: %d\n", rc); | ||
| 2962 | io->xbusy = false; | ||
| 2963 | } | ||
| 2964 | } | ||
| 2965 | |||
| 2966 | return rc; | ||
| 2967 | } | ||
| 2968 | |||
| 2969 | int | ||
| 2970 | efct_hw_send_frame(struct efct_hw *hw, struct fc_frame_header *hdr, | ||
| 2971 | u8 sof, u8 eof, struct efc_dma *payload, | ||
| 2972 | struct efct_hw_send_frame_context *ctx, | ||
| 2973 | void (*callback)(void *arg, u8 *cqe, int status), | ||
| 2974 | void *arg) | ||
| 2975 | { | ||
| 2976 | int rc; | ||
| 2977 | struct efct_hw_wqe *wqe; | ||
| 2978 | u32 xri; | ||
| 2979 | struct hw_wq *wq; | ||
| 2980 | |||
| 2981 | wqe = &ctx->wqe; | ||
| 2982 | |||
| 2983 | /* populate the callback object */ | ||
| 2984 | ctx->hw = hw; | ||
| 2985 | |||
| 2986 | /* Fetch and populate request tag */ | ||
| 2987 | ctx->wqcb = efct_hw_reqtag_alloc(hw, callback, arg); | ||
| 2988 | if (!ctx->wqcb) { | ||
| 2989 | efc_log_err(hw->os, "can't allocate request tag\n"); | ||
| 2990 | return -ENOSPC; | ||
| 2991 | } | ||
| 2992 | |||
| 2993 | wq = hw->hw_wq[0]; | ||
| 2994 | |||
| 2995 | /* Set XRI and RX_ID in the header based on which WQ, and which | ||
| 2996 | * send_frame_io we are using | ||
| 2997 | */ | ||
| 2998 | xri = wq->send_frame_io->indicator; | ||
| 2999 | |||
| 3000 | /* Build the send frame WQE */ | ||
| 3001 | rc = sli_send_frame_wqe(&hw->sli, wqe->wqebuf, | ||
| 3002 | sof, eof, (u32 *)hdr, payload, payload->len, | ||
| 3003 | EFCT_HW_SEND_FRAME_TIMEOUT, xri, | ||
| 3004 | ctx->wqcb->instance_index); | ||
| 3005 | if (rc) { | ||
| 3006 | efc_log_err(hw->os, "sli_send_frame_wqe failed: %d\n", rc); | ||
| 3007 | return -EIO; | ||
| 3008 | } | ||
| 3009 | |||
| 3010 | /* Write to WQ */ | ||
| 3011 | rc = efct_hw_wq_write(wq, wqe); | ||
| 3012 | if (rc) { | ||
| 3013 | efc_log_err(hw->os, "efct_hw_wq_write failed: %d\n", rc); | ||
| 3014 | return -EIO; | ||
| 3015 | } | ||
| 3016 | |||
| 3017 | wq->use_count++; | ||
| 3018 | |||
| 3019 | return 0; | ||
| 3020 | } | ||
| 3021 | |||
| 3022 | static int | ||
| 3023 | efct_hw_cb_link_stat(struct efct_hw *hw, int status, | ||
| 3024 | u8 *mqe, void *arg) | ||
| 3025 | { | ||
| 3026 | struct sli4_cmd_read_link_stats *mbox_rsp; | ||
| 3027 | struct efct_hw_link_stat_cb_arg *cb_arg = arg; | ||
| 3028 | struct efct_hw_link_stat_counts counts[EFCT_HW_LINK_STAT_MAX]; | ||
| 3029 | u32 num_counters, i; | ||
| 3030 | u32 mbox_rsp_flags = 0; | ||
| 3031 | |||
| 3032 | mbox_rsp = (struct sli4_cmd_read_link_stats *)mqe; | ||
| 3033 | mbox_rsp_flags = le32_to_cpu(mbox_rsp->dw1_flags); | ||
| 3034 | num_counters = (mbox_rsp_flags & SLI4_READ_LNKSTAT_GEC) ? 20 : 13; | ||
| 3035 | memset(counts, 0, sizeof(struct efct_hw_link_stat_counts) * | ||
| 3036 | EFCT_HW_LINK_STAT_MAX); | ||
| 3037 | |||
| 3038 | /* Fill overflow counts, mask starts from SLI4_READ_LNKSTAT_W02OF*/ | ||
| 3039 | for (i = 0; i < EFCT_HW_LINK_STAT_MAX; i++) | ||
| 3040 | counts[i].overflow = (mbox_rsp_flags & (1 << (i + 2))); | ||
| 3041 | |||
| 3042 | counts[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT].counter = | ||
| 3043 | le32_to_cpu(mbox_rsp->linkfail_errcnt); | ||
| 3044 | counts[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT].counter = | ||
| 3045 | le32_to_cpu(mbox_rsp->losssync_errcnt); | ||
| 3046 | counts[EFCT_HW_LINK_STAT_LOSS_OF_SIGNAL_COUNT].counter = | ||
| 3047 | le32_to_cpu(mbox_rsp->losssignal_errcnt); | ||
| 3048 | counts[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT].counter = | ||
| 3049 | le32_to_cpu(mbox_rsp->primseq_errcnt); | ||
| 3050 | counts[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT].counter = | ||
| 3051 | le32_to_cpu(mbox_rsp->inval_txword_errcnt); | ||
| 3052 | counts[EFCT_HW_LINK_STAT_CRC_COUNT].counter = | ||
| 3053 | le32_to_cpu(mbox_rsp->crc_errcnt); | ||
| 3054 | counts[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_TIMEOUT_COUNT].counter = | ||
| 3055 | le32_to_cpu(mbox_rsp->primseq_eventtimeout_cnt); | ||
| 3056 | counts[EFCT_HW_LINK_STAT_ELASTIC_BUFFER_OVERRUN_COUNT].counter = | ||
| 3057 | le32_to_cpu(mbox_rsp->elastic_bufoverrun_errcnt); | ||
| 3058 | counts[EFCT_HW_LINK_STAT_ARB_TIMEOUT_COUNT].counter = | ||
| 3059 | le32_to_cpu(mbox_rsp->arbit_fc_al_timeout_cnt); | ||
| 3060 | counts[EFCT_HW_LINK_STAT_ADVERTISED_RCV_B2B_CREDIT].counter = | ||
| 3061 | le32_to_cpu(mbox_rsp->adv_rx_buftor_to_buf_credit); | ||
| 3062 | counts[EFCT_HW_LINK_STAT_CURR_RCV_B2B_CREDIT].counter = | ||
| 3063 | le32_to_cpu(mbox_rsp->curr_rx_buf_to_buf_credit); | ||
| 3064 | counts[EFCT_HW_LINK_STAT_ADVERTISED_XMIT_B2B_CREDIT].counter = | ||
| 3065 | le32_to_cpu(mbox_rsp->adv_tx_buf_to_buf_credit); | ||
| 3066 | counts[EFCT_HW_LINK_STAT_CURR_XMIT_B2B_CREDIT].counter = | ||
| 3067 | le32_to_cpu(mbox_rsp->curr_tx_buf_to_buf_credit); | ||
| 3068 | counts[EFCT_HW_LINK_STAT_RCV_EOFA_COUNT].counter = | ||
| 3069 | le32_to_cpu(mbox_rsp->rx_eofa_cnt); | ||
| 3070 | counts[EFCT_HW_LINK_STAT_RCV_EOFDTI_COUNT].counter = | ||
| 3071 | le32_to_cpu(mbox_rsp->rx_eofdti_cnt); | ||
| 3072 | counts[EFCT_HW_LINK_STAT_RCV_EOFNI_COUNT].counter = | ||
| 3073 | le32_to_cpu(mbox_rsp->rx_eofni_cnt); | ||
| 3074 | counts[EFCT_HW_LINK_STAT_RCV_SOFF_COUNT].counter = | ||
| 3075 | le32_to_cpu(mbox_rsp->rx_soff_cnt); | ||
| 3076 | counts[EFCT_HW_LINK_STAT_RCV_DROPPED_NO_AER_COUNT].counter = | ||
| 3077 | le32_to_cpu(mbox_rsp->rx_dropped_no_aer_cnt); | ||
| 3078 | counts[EFCT_HW_LINK_STAT_RCV_DROPPED_NO_RPI_COUNT].counter = | ||
| 3079 | le32_to_cpu(mbox_rsp->rx_dropped_no_avail_rpi_rescnt); | ||
| 3080 | counts[EFCT_HW_LINK_STAT_RCV_DROPPED_NO_XRI_COUNT].counter = | ||
| 3081 | le32_to_cpu(mbox_rsp->rx_dropped_no_avail_xri_rescnt); | ||
| 3082 | |||
| 3083 | if (cb_arg) { | ||
| 3084 | if (cb_arg->cb) { | ||
| 3085 | if (status == 0 && le16_to_cpu(mbox_rsp->hdr.status)) | ||
| 3086 | status = le16_to_cpu(mbox_rsp->hdr.status); | ||
| 3087 | cb_arg->cb(status, num_counters, counts, cb_arg->arg); | ||
| 3088 | } | ||
| 3089 | |||
| 3090 | kfree(cb_arg); | ||
| 3091 | } | ||
| 3092 | |||
| 3093 | return 0; | ||
| 3094 | } | ||
| 3095 | |||
| 3096 | int | ||
| 3097 | efct_hw_get_link_stats(struct efct_hw *hw, u8 req_ext_counters, | ||
| 3098 | u8 clear_overflow_flags, u8 clear_all_counters, | ||
| 3099 | void (*cb)(int status, u32 num_counters, | ||
| 3100 | struct efct_hw_link_stat_counts *counters, | ||
| 3101 | void *arg), | ||
| 3102 | void *arg) | ||
| 3103 | { | ||
| 3104 | int rc = -EIO; | ||
| 3105 | struct efct_hw_link_stat_cb_arg *cb_arg; | ||
| 3106 | u8 mbxdata[SLI4_BMBX_SIZE]; | ||
| 3107 | |||
| 3108 | cb_arg = kzalloc(sizeof(*cb_arg), GFP_ATOMIC); | ||
| 3109 | if (!cb_arg) | ||
| 3110 | return -ENOMEM; | ||
| 3111 | |||
| 3112 | cb_arg->cb = cb; | ||
| 3113 | cb_arg->arg = arg; | ||
| 3114 | |||
| 3115 | /* Send the HW command */ | ||
| 3116 | if (!sli_cmd_read_link_stats(&hw->sli, mbxdata, req_ext_counters, | ||
| 3117 | clear_overflow_flags, clear_all_counters)) | ||
| 3118 | rc = efct_hw_command(hw, mbxdata, EFCT_CMD_NOWAIT, | ||
| 3119 | efct_hw_cb_link_stat, cb_arg); | ||
| 3120 | |||
| 3121 | if (rc) | ||
| 3122 | kfree(cb_arg); | ||
| 3123 | |||
| 3124 | return rc; | ||
| 3125 | } | ||
| 3126 | |||
| 3127 | static int | ||
| 3128 | efct_hw_cb_host_stat(struct efct_hw *hw, int status, u8 *mqe, void *arg) | ||
| 3129 | { | ||
| 3130 | struct sli4_cmd_read_status *mbox_rsp = | ||
| 3131 | (struct sli4_cmd_read_status *)mqe; | ||
| 3132 | struct efct_hw_host_stat_cb_arg *cb_arg = arg; | ||
| 3133 | struct efct_hw_host_stat_counts counts[EFCT_HW_HOST_STAT_MAX]; | ||
| 3134 | u32 num_counters = EFCT_HW_HOST_STAT_MAX; | ||
| 3135 | |||
| 3136 | memset(counts, 0, sizeof(struct efct_hw_host_stat_counts) * | ||
| 3137 | EFCT_HW_HOST_STAT_MAX); | ||
| 3138 | |||
| 3139 | counts[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT].counter = | ||
| 3140 | le32_to_cpu(mbox_rsp->trans_kbyte_cnt); | ||
| 3141 | counts[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT].counter = | ||
| 3142 | le32_to_cpu(mbox_rsp->recv_kbyte_cnt); | ||
| 3143 | counts[EFCT_HW_HOST_STAT_TX_FRAME_COUNT].counter = | ||
| 3144 | le32_to_cpu(mbox_rsp->trans_frame_cnt); | ||
| 3145 | counts[EFCT_HW_HOST_STAT_RX_FRAME_COUNT].counter = | ||
| 3146 | le32_to_cpu(mbox_rsp->recv_frame_cnt); | ||
| 3147 | counts[EFCT_HW_HOST_STAT_TX_SEQ_COUNT].counter = | ||
| 3148 | le32_to_cpu(mbox_rsp->trans_seq_cnt); | ||
| 3149 | counts[EFCT_HW_HOST_STAT_RX_SEQ_COUNT].counter = | ||
| 3150 | le32_to_cpu(mbox_rsp->recv_seq_cnt); | ||
| 3151 | counts[EFCT_HW_HOST_STAT_TOTAL_EXCH_ORIG].counter = | ||
| 3152 | le32_to_cpu(mbox_rsp->tot_exchanges_orig); | ||
| 3153 | counts[EFCT_HW_HOST_STAT_TOTAL_EXCH_RESP].counter = | ||
| 3154 | le32_to_cpu(mbox_rsp->tot_exchanges_resp); | ||
| 3155 | counts[EFCT_HW_HOSY_STAT_RX_P_BSY_COUNT].counter = | ||
| 3156 | le32_to_cpu(mbox_rsp->recv_p_bsy_cnt); | ||
| 3157 | counts[EFCT_HW_HOST_STAT_RX_F_BSY_COUNT].counter = | ||
| 3158 | le32_to_cpu(mbox_rsp->recv_f_bsy_cnt); | ||
| 3159 | counts[EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_RQ_BUF_COUNT].counter = | ||
| 3160 | le32_to_cpu(mbox_rsp->no_rq_buf_dropped_frames_cnt); | ||
| 3161 | counts[EFCT_HW_HOST_STAT_EMPTY_RQ_TIMEOUT_COUNT].counter = | ||
| 3162 | le32_to_cpu(mbox_rsp->empty_rq_timeout_cnt); | ||
| 3163 | counts[EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_XRI_COUNT].counter = | ||
| 3164 | le32_to_cpu(mbox_rsp->no_xri_dropped_frames_cnt); | ||
| 3165 | counts[EFCT_HW_HOST_STAT_EMPTY_XRI_POOL_COUNT].counter = | ||
| 3166 | le32_to_cpu(mbox_rsp->empty_xri_pool_cnt); | ||
| 3167 | |||
| 3168 | if (cb_arg) { | ||
| 3169 | if (cb_arg->cb) { | ||
| 3170 | if (status == 0 && le16_to_cpu(mbox_rsp->hdr.status)) | ||
| 3171 | status = le16_to_cpu(mbox_rsp->hdr.status); | ||
| 3172 | cb_arg->cb(status, num_counters, counts, cb_arg->arg); | ||
| 3173 | } | ||
| 3174 | |||
| 3175 | kfree(cb_arg); | ||
| 3176 | } | ||
| 3177 | |||
| 3178 | return 0; | ||
| 3179 | } | ||
| 3180 | |||
| 3181 | int | ||
| 3182 | efct_hw_get_host_stats(struct efct_hw *hw, u8 cc, | ||
| 3183 | void (*cb)(int status, u32 num_counters, | ||
| 3184 | struct efct_hw_host_stat_counts *counters, | ||
| 3185 | void *arg), | ||
| 3186 | void *arg) | ||
| 3187 | { | ||
| 3188 | int rc = -EIO; | ||
| 3189 | struct efct_hw_host_stat_cb_arg *cb_arg; | ||
| 3190 | u8 mbxdata[SLI4_BMBX_SIZE]; | ||
| 3191 | |||
| 3192 | cb_arg = kmalloc(sizeof(*cb_arg), GFP_ATOMIC); | ||
| 3193 | if (!cb_arg) | ||
| 3194 | return -ENOMEM; | ||
| 3195 | |||
| 3196 | cb_arg->cb = cb; | ||
| 3197 | cb_arg->arg = arg; | ||
| 3198 | |||
| 3199 | /* Send the HW command to get the host stats */ | ||
| 3200 | if (!sli_cmd_read_status(&hw->sli, mbxdata, cc)) | ||
| 3201 | rc = efct_hw_command(hw, mbxdata, EFCT_CMD_NOWAIT, | ||
| 3202 | efct_hw_cb_host_stat, cb_arg); | ||
| 3203 | |||
| 3204 | if (rc) { | ||
| 3205 | efc_log_debug(hw->os, "READ_HOST_STATS failed\n"); | ||
| 3206 | kfree(cb_arg); | ||
| 3207 | } | ||
| 3208 | |||
| 3209 | return rc; | ||
| 3210 | } | ||
| 3211 | |||
| 3212 | struct efct_hw_async_call_ctx { | ||
| 3213 | efct_hw_async_cb_t callback; | ||
| 3214 | void *arg; | ||
| 3215 | u8 cmd[SLI4_BMBX_SIZE]; | ||
| 3216 | }; | ||
| 3217 | |||
| 3218 | static void | ||
| 3219 | efct_hw_async_cb(struct efct_hw *hw, int status, u8 *mqe, void *arg) | ||
| 3220 | { | ||
| 3221 | struct efct_hw_async_call_ctx *ctx = arg; | ||
| 3222 | |||
| 3223 | if (ctx) { | ||
| 3224 | if (ctx->callback) | ||
| 3225 | (*ctx->callback)(hw, status, mqe, ctx->arg); | ||
| 3226 | |||
| 3227 | kfree(ctx); | ||
| 3228 | } | ||
| 3229 | } | ||
| 3230 | |||
| 3231 | int | ||
| 3232 | efct_hw_async_call(struct efct_hw *hw, efct_hw_async_cb_t callback, void *arg) | ||
| 3233 | { | ||
| 3234 | struct efct_hw_async_call_ctx *ctx; | ||
| 3235 | int rc; | ||
| 3236 | |||
| 3237 | /* | ||
| 3238 | * Allocate a callback context (which includes the mbox cmd buffer), | ||
| 3239 | * we need this to be persistent as the mbox cmd submission may be | ||
| 3240 | * queued and executed later execution. | ||
| 3241 | */ | ||
| 3242 | ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); | ||
| 3243 | if (!ctx) | ||
| 3244 | return -ENOMEM; | ||
| 3245 | |||
| 3246 | ctx->callback = callback; | ||
| 3247 | ctx->arg = arg; | ||
| 3248 | |||
| 3249 | /* Build and send a NOP mailbox command */ | ||
| 3250 | if (sli_cmd_common_nop(&hw->sli, ctx->cmd, 0)) { | ||
| 3251 | efc_log_err(hw->os, "COMMON_NOP format failure\n"); | ||
| 3252 | kfree(ctx); | ||
| 3253 | return -EIO; | ||
| 3254 | } | ||
| 3255 | |||
| 3256 | rc = efct_hw_command(hw, ctx->cmd, EFCT_CMD_NOWAIT, efct_hw_async_cb, | ||
| 3257 | ctx); | ||
| 3258 | if (rc) { | ||
| 3259 | efc_log_err(hw->os, "COMMON_NOP command failure, rc=%d\n", rc); | ||
| 3260 | kfree(ctx); | ||
| 3261 | return -EIO; | ||
| 3262 | } | ||
| 3263 | return 0; | ||
| 3264 | } | ||
| 3265 | |||
| 3266 | static int | ||
| 3267 | efct_hw_cb_fw_write(struct efct_hw *hw, int status, u8 *mqe, void *arg) | ||
| 3268 | { | ||
| 3269 | struct sli4_cmd_sli_config *mbox_rsp = | ||
| 3270 | (struct sli4_cmd_sli_config *)mqe; | ||
| 3271 | struct sli4_rsp_cmn_write_object *wr_obj_rsp; | ||
| 3272 | struct efct_hw_fw_wr_cb_arg *cb_arg = arg; | ||
| 3273 | u32 bytes_written; | ||
| 3274 | u16 mbox_status; | ||
| 3275 | u32 change_status; | ||
| 3276 | |||
| 3277 | wr_obj_rsp = (struct sli4_rsp_cmn_write_object *) | ||
| 3278 | &mbox_rsp->payload.embed; | ||
| 3279 | bytes_written = le32_to_cpu(wr_obj_rsp->actual_write_length); | ||
| 3280 | mbox_status = le16_to_cpu(mbox_rsp->hdr.status); | ||
| 3281 | change_status = (le32_to_cpu(wr_obj_rsp->change_status_dword) & | ||
| 3282 | RSP_CHANGE_STATUS); | ||
| 3283 | |||
| 3284 | if (cb_arg) { | ||
| 3285 | if (cb_arg->cb) { | ||
| 3286 | if (!status && mbox_status) | ||
| 3287 | status = mbox_status; | ||
| 3288 | cb_arg->cb(status, bytes_written, change_status, | ||
| 3289 | cb_arg->arg); | ||
| 3290 | } | ||
| 3291 | |||
| 3292 | kfree(cb_arg); | ||
| 3293 | } | ||
| 3294 | |||
| 3295 | return 0; | ||
| 3296 | } | ||
| 3297 | |||
| 3298 | int | ||
| 3299 | efct_hw_firmware_write(struct efct_hw *hw, struct efc_dma *dma, u32 size, | ||
| 3300 | u32 offset, int last, | ||
| 3301 | void (*cb)(int status, u32 bytes_written, | ||
| 3302 | u32 change_status, void *arg), | ||
| 3303 | void *arg) | ||
| 3304 | { | ||
| 3305 | int rc = -EIO; | ||
| 3306 | u8 mbxdata[SLI4_BMBX_SIZE]; | ||
| 3307 | struct efct_hw_fw_wr_cb_arg *cb_arg; | ||
| 3308 | int noc = 0; | ||
| 3309 | |||
| 3310 | cb_arg = kzalloc(sizeof(*cb_arg), GFP_KERNEL); | ||
| 3311 | if (!cb_arg) | ||
| 3312 | return -ENOMEM; | ||
| 3313 | |||
| 3314 | cb_arg->cb = cb; | ||
| 3315 | cb_arg->arg = arg; | ||
| 3316 | |||
| 3317 | /* Write a portion of a firmware image to the device */ | ||
| 3318 | if (!sli_cmd_common_write_object(&hw->sli, mbxdata, | ||
| 3319 | noc, last, size, offset, "/prg/", | ||
| 3320 | dma)) | ||
| 3321 | rc = efct_hw_command(hw, mbxdata, EFCT_CMD_NOWAIT, | ||
| 3322 | efct_hw_cb_fw_write, cb_arg); | ||
| 3323 | |||
| 3324 | if (rc != 0) { | ||
| 3325 | efc_log_debug(hw->os, "COMMON_WRITE_OBJECT failed\n"); | ||
| 3326 | kfree(cb_arg); | ||
| 3327 | } | ||
| 3328 | |||
| 3329 | return rc; | ||
| 3330 | } | ||
| 3331 | |||
| 3332 | static int | ||
| 3333 | efct_hw_cb_port_control(struct efct_hw *hw, int status, u8 *mqe, | ||
| 3334 | void *arg) | ||
| 3335 | { | ||
| 3336 | return 0; | ||
| 3337 | } | ||
| 3338 | |||
| 3339 | int | ||
| 3340 | efct_hw_port_control(struct efct_hw *hw, enum efct_hw_port ctrl, | ||
| 3341 | uintptr_t value, | ||
| 3342 | void (*cb)(int status, uintptr_t value, void *arg), | ||
| 3343 | void *arg) | ||
| 3344 | { | ||
| 3345 | int rc = -EIO; | ||
| 3346 | u8 link[SLI4_BMBX_SIZE]; | ||
| 3347 | u32 speed = 0; | ||
| 3348 | u8 reset_alpa = 0; | ||
| 3349 | |||
| 3350 | switch (ctrl) { | ||
| 3351 | case EFCT_HW_PORT_INIT: | ||
| 3352 | if (!sli_cmd_config_link(&hw->sli, link)) | ||
| 3353 | rc = efct_hw_command(hw, link, EFCT_CMD_NOWAIT, | ||
| 3354 | efct_hw_cb_port_control, NULL); | ||
| 3355 | |||
| 3356 | if (rc != 0) { | ||
| 3357 | efc_log_err(hw->os, "CONFIG_LINK failed\n"); | ||
| 3358 | break; | ||
| 3359 | } | ||
| 3360 | speed = hw->config.speed; | ||
| 3361 | reset_alpa = (u8)(value & 0xff); | ||
| 3362 | |||
| 3363 | rc = -EIO; | ||
| 3364 | if (!sli_cmd_init_link(&hw->sli, link, speed, reset_alpa)) | ||
| 3365 | rc = efct_hw_command(hw, link, EFCT_CMD_NOWAIT, | ||
| 3366 | efct_hw_cb_port_control, NULL); | ||
| 3367 | /* Free buffer on error, since no callback is coming */ | ||
| 3368 | if (rc) | ||
| 3369 | efc_log_err(hw->os, "INIT_LINK failed\n"); | ||
| 3370 | break; | ||
| 3371 | |||
| 3372 | case EFCT_HW_PORT_SHUTDOWN: | ||
| 3373 | if (!sli_cmd_down_link(&hw->sli, link)) | ||
| 3374 | rc = efct_hw_command(hw, link, EFCT_CMD_NOWAIT, | ||
| 3375 | efct_hw_cb_port_control, NULL); | ||
| 3376 | /* Free buffer on error, since no callback is coming */ | ||
| 3377 | if (rc) | ||
| 3378 | efc_log_err(hw->os, "DOWN_LINK failed\n"); | ||
| 3379 | break; | ||
| 3380 | |||
| 3381 | default: | ||
| 3382 | efc_log_debug(hw->os, "unhandled control %#x\n", ctrl); | ||
| 3383 | break; | ||
| 3384 | } | ||
| 3385 | |||
| 3386 | return rc; | ||
| 3387 | } | ||
| 3388 | |||
| 3389 | void | ||
| 3390 | efct_hw_teardown(struct efct_hw *hw) | ||
| 3391 | { | ||
| 3392 | u32 i = 0; | ||
| 3393 | u32 destroy_queues; | ||
| 3394 | u32 free_memory; | ||
| 3395 | struct efc_dma *dma; | ||
| 3396 | struct efct *efct = hw->os; | ||
| 3397 | |||
| 3398 | destroy_queues = (hw->state == EFCT_HW_STATE_ACTIVE); | ||
| 3399 | free_memory = (hw->state != EFCT_HW_STATE_UNINITIALIZED); | ||
| 3400 | |||
| 3401 | /* Cancel Sliport Healthcheck */ | ||
| 3402 | if (hw->sliport_healthcheck) { | ||
| 3403 | hw->sliport_healthcheck = 0; | ||
| 3404 | efct_hw_config_sli_port_health_check(hw, 0, 0); | ||
| 3405 | } | ||
| 3406 | |||
| 3407 | if (hw->state != EFCT_HW_STATE_QUEUES_ALLOCATED) { | ||
| 3408 | hw->state = EFCT_HW_STATE_TEARDOWN_IN_PROGRESS; | ||
| 3409 | |||
| 3410 | efct_hw_flush(hw); | ||
| 3411 | |||
| 3412 | if (list_empty(&hw->cmd_head)) | ||
| 3413 | efc_log_debug(hw->os, | ||
| 3414 | "All commands completed on MQ queue\n"); | ||
| 3415 | else | ||
| 3416 | efc_log_debug(hw->os, | ||
| 3417 | "Some cmds still pending on MQ queue\n"); | ||
| 3418 | |||
| 3419 | /* Cancel any remaining commands */ | ||
| 3420 | efct_hw_command_cancel(hw); | ||
| 3421 | } else { | ||
| 3422 | hw->state = EFCT_HW_STATE_TEARDOWN_IN_PROGRESS; | ||
| 3423 | } | ||
| 3424 | |||
| 3425 | dma_free_coherent(&efct->pci->dev, | ||
| 3426 | hw->rnode_mem.size, hw->rnode_mem.virt, | ||
| 3427 | hw->rnode_mem.phys); | ||
| 3428 | memset(&hw->rnode_mem, 0, sizeof(struct efc_dma)); | ||
| 3429 | |||
| 3430 | if (hw->io) { | ||
| 3431 | for (i = 0; i < hw->config.n_io; i++) { | ||
| 3432 | if (hw->io[i] && hw->io[i]->sgl && | ||
| 3433 | hw->io[i]->sgl->virt) { | ||
| 3434 | dma_free_coherent(&efct->pci->dev, | ||
| 3435 | hw->io[i]->sgl->size, | ||
| 3436 | hw->io[i]->sgl->virt, | ||
| 3437 | hw->io[i]->sgl->phys); | ||
| 3438 | } | ||
| 3439 | kfree(hw->io[i]); | ||
| 3440 | hw->io[i] = NULL; | ||
| 3441 | } | ||
| 3442 | kfree(hw->io); | ||
| 3443 | hw->io = NULL; | ||
| 3444 | kfree(hw->wqe_buffs); | ||
| 3445 | hw->wqe_buffs = NULL; | ||
| 3446 | } | ||
| 3447 | |||
| 3448 | dma = &hw->xfer_rdy; | ||
| 3449 | dma_free_coherent(&efct->pci->dev, | ||
| 3450 | dma->size, dma->virt, dma->phys); | ||
| 3451 | memset(dma, 0, sizeof(struct efc_dma)); | ||
| 3452 | |||
| 3453 | dma = &hw->loop_map; | ||
| 3454 | dma_free_coherent(&efct->pci->dev, | ||
| 3455 | dma->size, dma->virt, dma->phys); | ||
| 3456 | memset(dma, 0, sizeof(struct efc_dma)); | ||
| 3457 | |||
| 3458 | for (i = 0; i < hw->wq_count; i++) | ||
| 3459 | sli_queue_free(&hw->sli, &hw->wq[i], destroy_queues, | ||
| 3460 | free_memory); | ||
| 3461 | |||
| 3462 | for (i = 0; i < hw->rq_count; i++) | ||
| 3463 | sli_queue_free(&hw->sli, &hw->rq[i], destroy_queues, | ||
| 3464 | free_memory); | ||
| 3465 | |||
| 3466 | for (i = 0; i < hw->mq_count; i++) | ||
| 3467 | sli_queue_free(&hw->sli, &hw->mq[i], destroy_queues, | ||
| 3468 | free_memory); | ||
| 3469 | |||
| 3470 | for (i = 0; i < hw->cq_count; i++) | ||
| 3471 | sli_queue_free(&hw->sli, &hw->cq[i], destroy_queues, | ||
| 3472 | free_memory); | ||
| 3473 | |||
| 3474 | for (i = 0; i < hw->eq_count; i++) | ||
| 3475 | sli_queue_free(&hw->sli, &hw->eq[i], destroy_queues, | ||
| 3476 | free_memory); | ||
| 3477 | |||
| 3478 | /* Free rq buffers */ | ||
| 3479 | efct_hw_rx_free(hw); | ||
| 3480 | |||
| 3481 | efct_hw_queue_teardown(hw); | ||
| 3482 | |||
| 3483 | kfree(hw->wq_cpu_array); | ||
| 3484 | |||
| 3485 | sli_teardown(&hw->sli); | ||
| 3486 | |||
| 3487 | /* record the fact that the queues are non-functional */ | ||
| 3488 | hw->state = EFCT_HW_STATE_UNINITIALIZED; | ||
| 3489 | |||
| 3490 | /* free sequence free pool */ | ||
| 3491 | kfree(hw->seq_pool); | ||
| 3492 | hw->seq_pool = NULL; | ||
| 3493 | |||
| 3494 | /* free hw_wq_callback pool */ | ||
| 3495 | efct_hw_reqtag_pool_free(hw); | ||
| 3496 | |||
| 3497 | mempool_destroy(hw->cmd_ctx_pool); | ||
| 3498 | mempool_destroy(hw->mbox_rqst_pool); | ||
| 3499 | |||
| 3500 | /* Mark HW setup as not having been called */ | ||
| 3501 | hw->hw_setup_called = false; | ||
| 3502 | } | ||
| 3503 | |||
| 3504 | static int | ||
| 3505 | efct_hw_sli_reset(struct efct_hw *hw, enum efct_hw_reset reset, | ||
| 3506 | enum efct_hw_state prev_state) | ||
| 3507 | { | ||
| 3508 | int rc = 0; | ||
| 3509 | |||
| 3510 | switch (reset) { | ||
| 3511 | case EFCT_HW_RESET_FUNCTION: | ||
| 3512 | efc_log_debug(hw->os, "issuing function level reset\n"); | ||
| 3513 | if (sli_reset(&hw->sli)) { | ||
| 3514 | efc_log_err(hw->os, "sli_reset failed\n"); | ||
| 3515 | rc = -EIO; | ||
| 3516 | } | ||
| 3517 | break; | ||
| 3518 | case EFCT_HW_RESET_FIRMWARE: | ||
| 3519 | efc_log_debug(hw->os, "issuing firmware reset\n"); | ||
| 3520 | if (sli_fw_reset(&hw->sli)) { | ||
| 3521 | efc_log_err(hw->os, "sli_soft_reset failed\n"); | ||
| 3522 | rc = -EIO; | ||
| 3523 | } | ||
| 3524 | /* | ||
| 3525 | * Because the FW reset leaves the FW in a non-running state, | ||
| 3526 | * follow that with a regular reset. | ||
| 3527 | */ | ||
| 3528 | efc_log_debug(hw->os, "issuing function level reset\n"); | ||
| 3529 | if (sli_reset(&hw->sli)) { | ||
| 3530 | efc_log_err(hw->os, "sli_reset failed\n"); | ||
| 3531 | rc = -EIO; | ||
| 3532 | } | ||
| 3533 | break; | ||
| 3534 | default: | ||
| 3535 | efc_log_err(hw->os, "unknown type - no reset performed\n"); | ||
| 3536 | hw->state = prev_state; | ||
| 3537 | rc = -EINVAL; | ||
| 3538 | break; | ||
| 3539 | } | ||
| 3540 | |||
| 3541 | return rc; | ||
| 3542 | } | ||
| 3543 | |||
| 3544 | int | ||
| 3545 | efct_hw_reset(struct efct_hw *hw, enum efct_hw_reset reset) | ||
| 3546 | { | ||
| 3547 | int rc = 0; | ||
| 3548 | enum efct_hw_state prev_state = hw->state; | ||
| 3549 | |||
| 3550 | if (hw->state != EFCT_HW_STATE_ACTIVE) | ||
| 3551 | efc_log_debug(hw->os, | ||
| 3552 | "HW state %d is not active\n", hw->state); | ||
| 3553 | |||
| 3554 | hw->state = EFCT_HW_STATE_RESET_IN_PROGRESS; | ||
| 3555 | |||
| 3556 | /* | ||
| 3557 | * If the prev_state is already reset/teardown in progress, | ||
| 3558 | * don't continue further | ||
| 3559 | */ | ||
| 3560 | if (prev_state == EFCT_HW_STATE_RESET_IN_PROGRESS || | ||
| 3561 | prev_state == EFCT_HW_STATE_TEARDOWN_IN_PROGRESS) | ||
| 3562 | return efct_hw_sli_reset(hw, reset, prev_state); | ||
| 3563 | |||
| 3564 | if (prev_state != EFCT_HW_STATE_UNINITIALIZED) { | ||
| 3565 | efct_hw_flush(hw); | ||
| 3566 | |||
| 3567 | if (list_empty(&hw->cmd_head)) | ||
| 3568 | efc_log_debug(hw->os, | ||
| 3569 | "All commands completed on MQ queue\n"); | ||
| 3570 | else | ||
| 3571 | efc_log_err(hw->os, | ||
| 3572 | "Some commands still pending on MQ queue\n"); | ||
| 3573 | } | ||
| 3574 | |||
| 3575 | /* Reset the chip */ | ||
| 3576 | rc = efct_hw_sli_reset(hw, reset, prev_state); | ||
| 3577 | if (rc == -EINVAL) | ||
| 3578 | return -EIO; | ||
| 3579 | |||
| 3580 | return rc; | ||
| 3581 | } | ||
| @@ -0,0 +1,764 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef _EFCT_HW_H | ||
| 8 | #define _EFCT_HW_H | ||
| 9 | |||
| 10 | #include "../libefc_sli/sli4.h" | ||
| 11 | |||
| 12 | /* | ||
| 13 | * EFCT PCI IDs | ||
| 14 | */ | ||
| 15 | #define EFCT_VENDOR_ID 0x10df | ||
| 16 | /* LightPulse 16Gb x 4 FC (lancer-g6) */ | ||
| 17 | #define EFCT_DEVICE_LANCER_G6 0xe307 | ||
| 18 | /* LightPulse 32Gb x 4 FC (lancer-g7) */ | ||
| 19 | #define EFCT_DEVICE_LANCER_G7 0xf407 | ||
| 20 | |||
| 21 | /*Default RQ entries len used by driver*/ | ||
| 22 | #define EFCT_HW_RQ_ENTRIES_MIN 512 | ||
| 23 | #define EFCT_HW_RQ_ENTRIES_DEF 1024 | ||
| 24 | #define EFCT_HW_RQ_ENTRIES_MAX 4096 | ||
| 25 | |||
| 26 | /*Defines the size of the RQ buffers used for each RQ*/ | ||
| 27 | #define EFCT_HW_RQ_SIZE_HDR 128 | ||
| 28 | #define EFCT_HW_RQ_SIZE_PAYLOAD 1024 | ||
| 29 | |||
| 30 | /*Define the maximum number of multi-receive queues*/ | ||
| 31 | #define EFCT_HW_MAX_MRQS 8 | ||
| 32 | |||
| 33 | /* | ||
| 34 | * Define count of when to set the WQEC bit in a submitted | ||
| 35 | * WQE, causing a consummed/released completion to be posted. | ||
| 36 | */ | ||
| 37 | #define EFCT_HW_WQEC_SET_COUNT 32 | ||
| 38 | |||
| 39 | /*Send frame timeout in seconds*/ | ||
| 40 | #define EFCT_HW_SEND_FRAME_TIMEOUT 10 | ||
| 41 | |||
| 42 | /* | ||
| 43 | * FDT Transfer Hint value, reads greater than this value | ||
| 44 | * will be segmented to implement fairness. A value of zero disables | ||
| 45 | * the feature. | ||
| 46 | */ | ||
| 47 | #define EFCT_HW_FDT_XFER_HINT 8192 | ||
| 48 | |||
| 49 | #define EFCT_HW_TIMECHECK_ITERATIONS 100 | ||
| 50 | #define EFCT_HW_MAX_NUM_MQ 1 | ||
| 51 | #define EFCT_HW_MAX_NUM_RQ 32 | ||
| 52 | #define EFCT_HW_MAX_NUM_EQ 16 | ||
| 53 | #define EFCT_HW_MAX_NUM_WQ 32 | ||
| 54 | #define EFCT_HW_DEF_NUM_EQ 1 | ||
| 55 | |||
| 56 | #define OCE_HW_MAX_NUM_MRQ_PAIRS 16 | ||
| 57 | |||
| 58 | #define EFCT_HW_MQ_DEPTH 128 | ||
| 59 | #define EFCT_HW_EQ_DEPTH 1024 | ||
| 60 | |||
| 61 | /* | ||
| 62 | * A CQ will be assinged to each WQ | ||
| 63 | * (CQ must have 2X entries of the WQ for abort | ||
| 64 | * processing), plus a separate one for each RQ PAIR and one for MQ | ||
| 65 | */ | ||
| 66 | #define EFCT_HW_MAX_NUM_CQ \ | ||
| 67 | ((EFCT_HW_MAX_NUM_WQ * 2) + 1 + (OCE_HW_MAX_NUM_MRQ_PAIRS * 2)) | ||
| 68 | |||
| 69 | #define EFCT_HW_Q_HASH_SIZE 128 | ||
| 70 | #define EFCT_HW_RQ_HEADER_SIZE 128 | ||
| 71 | #define EFCT_HW_RQ_HEADER_INDEX 0 | ||
| 72 | |||
| 73 | #define EFCT_HW_REQUE_XRI_REGTAG 65534 | ||
| 74 | |||
| 75 | /* Options for efct_hw_command() */ | ||
| 76 | enum efct_cmd_opts { | ||
| 77 | /* command executes synchronously and busy-waits for completion */ | ||
| 78 | EFCT_CMD_POLL, | ||
| 79 | /* command executes asynchronously. Uses callback */ | ||
| 80 | EFCT_CMD_NOWAIT, | ||
| 81 | }; | ||
| 82 | |||
| 83 | enum efct_hw_reset { | ||
| 84 | EFCT_HW_RESET_FUNCTION, | ||
| 85 | EFCT_HW_RESET_FIRMWARE, | ||
| 86 | EFCT_HW_RESET_MAX | ||
| 87 | }; | ||
| 88 | |||
| 89 | enum efct_hw_topo { | ||
| 90 | EFCT_HW_TOPOLOGY_AUTO, | ||
| 91 | EFCT_HW_TOPOLOGY_NPORT, | ||
| 92 | EFCT_HW_TOPOLOGY_LOOP, | ||
| 93 | EFCT_HW_TOPOLOGY_NONE, | ||
| 94 | EFCT_HW_TOPOLOGY_MAX | ||
| 95 | }; | ||
| 96 | |||
| 97 | /* pack fw revision values into a single uint64_t */ | ||
| 98 | #define HW_FWREV(a, b, c, d) (((uint64_t)(a) << 48) | ((uint64_t)(b) << 32) \ | ||
| 99 | | ((uint64_t)(c) << 16) | ((uint64_t)(d))) | ||
| 100 | |||
| 101 | #define EFCT_FW_VER_STR(a, b, c, d) (#a "." #b "." #c "." #d) | ||
| 102 | |||
| 103 | enum efct_hw_io_type { | ||
| 104 | EFCT_HW_ELS_REQ, | ||
| 105 | EFCT_HW_ELS_RSP, | ||
| 106 | EFCT_HW_FC_CT, | ||
| 107 | EFCT_HW_FC_CT_RSP, | ||
| 108 | EFCT_HW_BLS_ACC, | ||
| 109 | EFCT_HW_BLS_RJT, | ||
| 110 | EFCT_HW_IO_TARGET_READ, | ||
| 111 | EFCT_HW_IO_TARGET_WRITE, | ||
| 112 | EFCT_HW_IO_TARGET_RSP, | ||
| 113 | EFCT_HW_IO_DNRX_REQUEUE, | ||
| 114 | EFCT_HW_IO_MAX, | ||
| 115 | }; | ||
| 116 | |||
| 117 | enum efct_hw_io_state { | ||
| 118 | EFCT_HW_IO_STATE_FREE, | ||
| 119 | EFCT_HW_IO_STATE_INUSE, | ||
| 120 | EFCT_HW_IO_STATE_WAIT_FREE, | ||
| 121 | EFCT_HW_IO_STATE_WAIT_SEC_HIO, | ||
| 122 | }; | ||
| 123 | |||
| 124 | #define EFCT_TARGET_WRITE_SKIPS 1 | ||
| 125 | #define EFCT_TARGET_READ_SKIPS 2 | ||
| 126 | |||
| 127 | struct efct_hw; | ||
| 128 | struct efct_io; | ||
| 129 | |||
| 130 | #define EFCT_CMD_CTX_POOL_SZ 32 | ||
| 131 | /** | ||
| 132 | * HW command context. | ||
| 133 | * Stores the state for the asynchronous commands sent to the hardware. | ||
| 134 | */ | ||
| 135 | struct efct_command_ctx { | ||
| 136 | struct list_head list_entry; | ||
| 137 | int (*cb)(struct efct_hw *hw, int status, u8 *mqe, void *arg); | ||
| 138 | void *arg; /* Argument for callback */ | ||
| 139 | /* buffer holding command / results */ | ||
| 140 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 141 | void *ctx; /* upper layer context */ | ||
| 142 | }; | ||
| 143 | |||
| 144 | struct efct_hw_sgl { | ||
| 145 | uintptr_t addr; | ||
| 146 | size_t len; | ||
| 147 | }; | ||
| 148 | |||
| 149 | union efct_hw_io_param_u { | ||
| 150 | struct sli_bls_params bls; | ||
| 151 | struct sli_els_params els; | ||
| 152 | struct sli_ct_params fc_ct; | ||
| 153 | struct sli_fcp_tgt_params fcp_tgt; | ||
| 154 | }; | ||
| 155 | |||
| 156 | /* WQ steering mode */ | ||
| 157 | enum efct_hw_wq_steering { | ||
| 158 | EFCT_HW_WQ_STEERING_CLASS, | ||
| 159 | EFCT_HW_WQ_STEERING_REQUEST, | ||
| 160 | EFCT_HW_WQ_STEERING_CPU, | ||
| 161 | }; | ||
| 162 | |||
| 163 | /* HW wqe object */ | ||
| 164 | struct efct_hw_wqe { | ||
| 165 | struct list_head list_entry; | ||
| 166 | bool abort_wqe_submit_needed; | ||
| 167 | bool send_abts; | ||
| 168 | u32 id; | ||
| 169 | u32 abort_reqtag; | ||
| 170 | u8 *wqebuf; | ||
| 171 | }; | ||
| 172 | |||
| 173 | struct efct_hw_io; | ||
| 174 | /* Typedef for HW "done" callback */ | ||
| 175 | typedef int (*efct_hw_done_t)(struct efct_hw_io *, u32 len, int status, | ||
| 176 | u32 ext, void *ul_arg); | ||
| 177 | |||
| 178 | /** | ||
| 179 | * HW IO object. | ||
| 180 | * | ||
| 181 | * Stores the per-IO information necessary | ||
| 182 | * for both SLI and efct. | ||
| 183 | * @ref: reference counter for hw io object | ||
| 184 | * @state: state of IO: free, busy, wait_free | ||
| 185 | * @list_entry used for busy, wait_free, free lists | ||
| 186 | * @wqe Work queue object, with link for pending | ||
| 187 | * @hw pointer back to hardware context | ||
| 188 | * @xfer_rdy transfer ready data | ||
| 189 | * @type IO type | ||
| 190 | * @xbusy Exchange is active in FW | ||
| 191 | * @abort_in_progress if TRUE, abort is in progress | ||
| 192 | * @status_saved if TRUE, latched status should be returned | ||
| 193 | * @wq_class WQ class if steering mode is Class | ||
| 194 | * @reqtag request tag for this HW IO | ||
| 195 | * @wq WQ assigned to the exchange | ||
| 196 | * @done Function called on IO completion | ||
| 197 | * @arg argument passed to IO done callback | ||
| 198 | * @abort_done Function called on abort completion | ||
| 199 | * @abort_arg argument passed to abort done callback | ||
| 200 | * @wq_steering WQ steering mode request | ||
| 201 | * @saved_status Saved status | ||
| 202 | * @saved_len Status length | ||
| 203 | * @saved_ext Saved extended status | ||
| 204 | * @eq EQ on which this HIO came up | ||
| 205 | * @sge_offset SGE data offset | ||
| 206 | * @def_sgl_count Count of SGEs in default SGL | ||
| 207 | * @abort_reqtag request tag for an abort of this HW IO | ||
| 208 | * @indicator Exchange indicator | ||
| 209 | * @def_sgl default SGL | ||
| 210 | * @sgl pointer to current active SGL | ||
| 211 | * @sgl_count count of SGEs in io->sgl | ||
| 212 | * @first_data_sge index of first data SGE | ||
| 213 | * @n_sge number of active SGEs | ||
| 214 | */ | ||
| 215 | struct efct_hw_io { | ||
| 216 | struct kref ref; | ||
| 217 | enum efct_hw_io_state state; | ||
| 218 | void (*release)(struct kref *arg); | ||
| 219 | struct list_head list_entry; | ||
| 220 | struct efct_hw_wqe wqe; | ||
| 221 | |||
| 222 | struct efct_hw *hw; | ||
| 223 | struct efc_dma xfer_rdy; | ||
| 224 | u16 type; | ||
| 225 | bool xbusy; | ||
| 226 | int abort_in_progress; | ||
| 227 | bool status_saved; | ||
| 228 | u8 wq_class; | ||
| 229 | u16 reqtag; | ||
| 230 | |||
| 231 | struct hw_wq *wq; | ||
| 232 | efct_hw_done_t done; | ||
| 233 | void *arg; | ||
| 234 | efct_hw_done_t abort_done; | ||
| 235 | void *abort_arg; | ||
| 236 | |||
| 237 | enum efct_hw_wq_steering wq_steering; | ||
| 238 | |||
| 239 | u32 saved_status; | ||
| 240 | u32 saved_len; | ||
| 241 | u32 saved_ext; | ||
| 242 | |||
| 243 | struct hw_eq *eq; | ||
| 244 | u32 sge_offset; | ||
| 245 | u32 def_sgl_count; | ||
| 246 | u32 abort_reqtag; | ||
| 247 | u32 indicator; | ||
| 248 | struct efc_dma def_sgl; | ||
| 249 | struct efc_dma *sgl; | ||
| 250 | u32 sgl_count; | ||
| 251 | u32 first_data_sge; | ||
| 252 | u32 n_sge; | ||
| 253 | }; | ||
| 254 | |||
| 255 | enum efct_hw_port { | ||
| 256 | EFCT_HW_PORT_INIT, | ||
| 257 | EFCT_HW_PORT_SHUTDOWN, | ||
| 258 | }; | ||
| 259 | |||
| 260 | /* Node group rpi reference */ | ||
| 261 | struct efct_hw_rpi_ref { | ||
| 262 | atomic_t rpi_count; | ||
| 263 | atomic_t rpi_attached; | ||
| 264 | }; | ||
| 265 | |||
| 266 | enum efct_hw_link_stat { | ||
| 267 | EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT, | ||
| 268 | EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT, | ||
| 269 | EFCT_HW_LINK_STAT_LOSS_OF_SIGNAL_COUNT, | ||
| 270 | EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT, | ||
| 271 | EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT, | ||
| 272 | EFCT_HW_LINK_STAT_CRC_COUNT, | ||
| 273 | EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_TIMEOUT_COUNT, | ||
| 274 | EFCT_HW_LINK_STAT_ELASTIC_BUFFER_OVERRUN_COUNT, | ||
| 275 | EFCT_HW_LINK_STAT_ARB_TIMEOUT_COUNT, | ||
| 276 | EFCT_HW_LINK_STAT_ADVERTISED_RCV_B2B_CREDIT, | ||
| 277 | EFCT_HW_LINK_STAT_CURR_RCV_B2B_CREDIT, | ||
| 278 | EFCT_HW_LINK_STAT_ADVERTISED_XMIT_B2B_CREDIT, | ||
| 279 | EFCT_HW_LINK_STAT_CURR_XMIT_B2B_CREDIT, | ||
| 280 | EFCT_HW_LINK_STAT_RCV_EOFA_COUNT, | ||
| 281 | EFCT_HW_LINK_STAT_RCV_EOFDTI_COUNT, | ||
| 282 | EFCT_HW_LINK_STAT_RCV_EOFNI_COUNT, | ||
| 283 | EFCT_HW_LINK_STAT_RCV_SOFF_COUNT, | ||
| 284 | EFCT_HW_LINK_STAT_RCV_DROPPED_NO_AER_COUNT, | ||
| 285 | EFCT_HW_LINK_STAT_RCV_DROPPED_NO_RPI_COUNT, | ||
| 286 | EFCT_HW_LINK_STAT_RCV_DROPPED_NO_XRI_COUNT, | ||
| 287 | EFCT_HW_LINK_STAT_MAX, | ||
| 288 | }; | ||
| 289 | |||
| 290 | enum efct_hw_host_stat { | ||
| 291 | EFCT_HW_HOST_STAT_TX_KBYTE_COUNT, | ||
| 292 | EFCT_HW_HOST_STAT_RX_KBYTE_COUNT, | ||
| 293 | EFCT_HW_HOST_STAT_TX_FRAME_COUNT, | ||
| 294 | EFCT_HW_HOST_STAT_RX_FRAME_COUNT, | ||
| 295 | EFCT_HW_HOST_STAT_TX_SEQ_COUNT, | ||
| 296 | EFCT_HW_HOST_STAT_RX_SEQ_COUNT, | ||
| 297 | EFCT_HW_HOST_STAT_TOTAL_EXCH_ORIG, | ||
| 298 | EFCT_HW_HOST_STAT_TOTAL_EXCH_RESP, | ||
| 299 | EFCT_HW_HOSY_STAT_RX_P_BSY_COUNT, | ||
| 300 | EFCT_HW_HOST_STAT_RX_F_BSY_COUNT, | ||
| 301 | EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_RQ_BUF_COUNT, | ||
| 302 | EFCT_HW_HOST_STAT_EMPTY_RQ_TIMEOUT_COUNT, | ||
| 303 | EFCT_HW_HOST_STAT_DROP_FRM_DUE_TO_NO_XRI_COUNT, | ||
| 304 | EFCT_HW_HOST_STAT_EMPTY_XRI_POOL_COUNT, | ||
| 305 | EFCT_HW_HOST_STAT_MAX, | ||
| 306 | }; | ||
| 307 | |||
| 308 | enum efct_hw_state { | ||
| 309 | EFCT_HW_STATE_UNINITIALIZED, | ||
| 310 | EFCT_HW_STATE_QUEUES_ALLOCATED, | ||
| 311 | EFCT_HW_STATE_ACTIVE, | ||
| 312 | EFCT_HW_STATE_RESET_IN_PROGRESS, | ||
| 313 | EFCT_HW_STATE_TEARDOWN_IN_PROGRESS, | ||
| 314 | }; | ||
| 315 | |||
| 316 | struct efct_hw_link_stat_counts { | ||
| 317 | u8 overflow; | ||
| 318 | u32 counter; | ||
| 319 | }; | ||
| 320 | |||
| 321 | struct efct_hw_host_stat_counts { | ||
| 322 | u32 counter; | ||
| 323 | }; | ||
| 324 | |||
| 325 | /* Structure used for the hash lookup of queue IDs */ | ||
| 326 | struct efct_queue_hash { | ||
| 327 | bool in_use; | ||
| 328 | u16 id; | ||
| 329 | u16 index; | ||
| 330 | }; | ||
| 331 | |||
| 332 | /* WQ callback object */ | ||
| 333 | struct hw_wq_callback { | ||
| 334 | u16 instance_index; /* use for request tag */ | ||
| 335 | void (*callback)(void *arg, u8 *cqe, int status); | ||
| 336 | void *arg; | ||
| 337 | struct list_head list_entry; | ||
| 338 | }; | ||
| 339 | |||
| 340 | struct reqtag_pool { | ||
| 341 | spinlock_t lock; /* pool lock */ | ||
| 342 | struct hw_wq_callback *tags[U16_MAX]; | ||
| 343 | struct list_head freelist; | ||
| 344 | }; | ||
| 345 | |||
| 346 | struct efct_hw_config { | ||
| 347 | u32 n_eq; | ||
| 348 | u32 n_cq; | ||
| 349 | u32 n_mq; | ||
| 350 | u32 n_rq; | ||
| 351 | u32 n_wq; | ||
| 352 | u32 n_io; | ||
| 353 | u32 n_sgl; | ||
| 354 | u32 speed; | ||
| 355 | u32 topology; | ||
| 356 | /* size of the buffers for first burst */ | ||
| 357 | u32 rq_default_buffer_size; | ||
| 358 | u8 esoc; | ||
| 359 | /* MRQ RQ selection policy */ | ||
| 360 | u8 rq_selection_policy; | ||
| 361 | /* RQ quanta if rq_selection_policy == 2 */ | ||
| 362 | u8 rr_quanta; | ||
| 363 | u32 filter_def[SLI4_CMD_REG_FCFI_NUM_RQ_CFG]; | ||
| 364 | }; | ||
| 365 | |||
| 366 | struct efct_hw { | ||
| 367 | struct efct *os; | ||
| 368 | struct sli4 sli; | ||
| 369 | u16 ulp_start; | ||
| 370 | u16 ulp_max; | ||
| 371 | u32 dump_size; | ||
| 372 | enum efct_hw_state state; | ||
| 373 | bool hw_setup_called; | ||
| 374 | u8 sliport_healthcheck; | ||
| 375 | u16 fcf_indicator; | ||
| 376 | |||
| 377 | /* HW configuration */ | ||
| 378 | struct efct_hw_config config; | ||
| 379 | |||
| 380 | /* calculated queue sizes for each type */ | ||
| 381 | u32 num_qentries[SLI4_QTYPE_MAX]; | ||
| 382 | |||
| 383 | /* Storage for SLI queue objects */ | ||
| 384 | struct sli4_queue wq[EFCT_HW_MAX_NUM_WQ]; | ||
| 385 | struct sli4_queue rq[EFCT_HW_MAX_NUM_RQ]; | ||
| 386 | u16 hw_rq_lookup[EFCT_HW_MAX_NUM_RQ]; | ||
| 387 | struct sli4_queue mq[EFCT_HW_MAX_NUM_MQ]; | ||
| 388 | struct sli4_queue cq[EFCT_HW_MAX_NUM_CQ]; | ||
| 389 | struct sli4_queue eq[EFCT_HW_MAX_NUM_EQ]; | ||
| 390 | |||
| 391 | /* HW queue */ | ||
| 392 | u32 eq_count; | ||
| 393 | u32 cq_count; | ||
| 394 | u32 mq_count; | ||
| 395 | u32 wq_count; | ||
| 396 | u32 rq_count; | ||
| 397 | u32 cmd_head_count; | ||
| 398 | struct list_head eq_list; | ||
| 399 | |||
| 400 | struct efct_queue_hash cq_hash[EFCT_HW_Q_HASH_SIZE]; | ||
| 401 | struct efct_queue_hash rq_hash[EFCT_HW_Q_HASH_SIZE]; | ||
| 402 | struct efct_queue_hash wq_hash[EFCT_HW_Q_HASH_SIZE]; | ||
| 403 | |||
| 404 | /* Storage for HW queue objects */ | ||
| 405 | struct hw_wq *hw_wq[EFCT_HW_MAX_NUM_WQ]; | ||
| 406 | struct hw_rq *hw_rq[EFCT_HW_MAX_NUM_RQ]; | ||
| 407 | struct hw_mq *hw_mq[EFCT_HW_MAX_NUM_MQ]; | ||
| 408 | struct hw_cq *hw_cq[EFCT_HW_MAX_NUM_CQ]; | ||
| 409 | struct hw_eq *hw_eq[EFCT_HW_MAX_NUM_EQ]; | ||
| 410 | /* count of hw_rq[] entries */ | ||
| 411 | u32 hw_rq_count; | ||
| 412 | /* count of multirq RQs */ | ||
| 413 | u32 hw_mrq_count; | ||
| 414 | |||
| 415 | struct hw_wq **wq_cpu_array; | ||
| 416 | |||
| 417 | /* Sequence objects used in incoming frame processing */ | ||
| 418 | struct efc_hw_sequence *seq_pool; | ||
| 419 | |||
| 420 | /* Maintain an ordered, linked list of outstanding HW commands. */ | ||
| 421 | struct mutex bmbx_lock; | ||
| 422 | spinlock_t cmd_lock; | ||
| 423 | struct list_head cmd_head; | ||
| 424 | struct list_head cmd_pending; | ||
| 425 | mempool_t *cmd_ctx_pool; | ||
| 426 | mempool_t *mbox_rqst_pool; | ||
| 427 | |||
| 428 | struct sli4_link_event link; | ||
| 429 | |||
| 430 | /* pointer array of IO objects */ | ||
| 431 | struct efct_hw_io **io; | ||
| 432 | /* array of WQE buffs mapped to IO objects */ | ||
| 433 | u8 *wqe_buffs; | ||
| 434 | |||
| 435 | /* IO lock to synchronize list access */ | ||
| 436 | spinlock_t io_lock; | ||
| 437 | /* List of IO objects in use */ | ||
| 438 | struct list_head io_inuse; | ||
| 439 | /* List of IO objects waiting to be freed */ | ||
| 440 | struct list_head io_wait_free; | ||
| 441 | /* List of IO objects available for allocation */ | ||
| 442 | struct list_head io_free; | ||
| 443 | |||
| 444 | struct efc_dma loop_map; | ||
| 445 | |||
| 446 | struct efc_dma xfer_rdy; | ||
| 447 | |||
| 448 | struct efc_dma rnode_mem; | ||
| 449 | |||
| 450 | atomic_t io_alloc_failed_count; | ||
| 451 | |||
| 452 | /* stat: wq sumbit count */ | ||
| 453 | u32 tcmd_wq_submit[EFCT_HW_MAX_NUM_WQ]; | ||
| 454 | /* stat: wq complete count */ | ||
| 455 | u32 tcmd_wq_complete[EFCT_HW_MAX_NUM_WQ]; | ||
| 456 | |||
| 457 | atomic_t send_frame_seq_id; | ||
| 458 | struct reqtag_pool *wq_reqtag_pool; | ||
| 459 | }; | ||
| 460 | |||
| 461 | enum efct_hw_io_count_type { | ||
| 462 | EFCT_HW_IO_INUSE_COUNT, | ||
| 463 | EFCT_HW_IO_FREE_COUNT, | ||
| 464 | EFCT_HW_IO_WAIT_FREE_COUNT, | ||
| 465 | EFCT_HW_IO_N_TOTAL_IO_COUNT, | ||
| 466 | }; | ||
| 467 | |||
| 468 | /* HW queue data structures */ | ||
| 469 | struct hw_eq { | ||
| 470 | struct list_head list_entry; | ||
| 471 | enum sli4_qtype type; | ||
| 472 | u32 instance; | ||
| 473 | u32 entry_count; | ||
| 474 | u32 entry_size; | ||
| 475 | struct efct_hw *hw; | ||
| 476 | struct sli4_queue *queue; | ||
| 477 | struct list_head cq_list; | ||
| 478 | u32 use_count; | ||
| 479 | }; | ||
| 480 | |||
| 481 | struct hw_cq { | ||
| 482 | struct list_head list_entry; | ||
| 483 | enum sli4_qtype type; | ||
| 484 | u32 instance; | ||
| 485 | u32 entry_count; | ||
| 486 | u32 entry_size; | ||
| 487 | struct hw_eq *eq; | ||
| 488 | struct sli4_queue *queue; | ||
| 489 | struct list_head q_list; | ||
| 490 | u32 use_count; | ||
| 491 | }; | ||
| 492 | |||
| 493 | struct hw_q { | ||
| 494 | struct list_head list_entry; | ||
| 495 | enum sli4_qtype type; | ||
| 496 | }; | ||
| 497 | |||
| 498 | struct hw_mq { | ||
| 499 | struct list_head list_entry; | ||
| 500 | enum sli4_qtype type; | ||
| 501 | u32 instance; | ||
| 502 | |||
| 503 | u32 entry_count; | ||
| 504 | u32 entry_size; | ||
| 505 | struct hw_cq *cq; | ||
| 506 | struct sli4_queue *queue; | ||
| 507 | |||
| 508 | u32 use_count; | ||
| 509 | }; | ||
| 510 | |||
| 511 | struct hw_wq { | ||
| 512 | struct list_head list_entry; | ||
| 513 | enum sli4_qtype type; | ||
| 514 | u32 instance; | ||
| 515 | struct efct_hw *hw; | ||
| 516 | |||
| 517 | u32 entry_count; | ||
| 518 | u32 entry_size; | ||
| 519 | struct hw_cq *cq; | ||
| 520 | struct sli4_queue *queue; | ||
| 521 | u32 class; | ||
| 522 | |||
| 523 | /* WQ consumed */ | ||
| 524 | u32 wqec_set_count; | ||
| 525 | u32 wqec_count; | ||
| 526 | u32 free_count; | ||
| 527 | u32 total_submit_count; | ||
| 528 | struct list_head pending_list; | ||
| 529 | |||
| 530 | /* HW IO allocated for use with Send Frame */ | ||
| 531 | struct efct_hw_io *send_frame_io; | ||
| 532 | |||
| 533 | /* Stats */ | ||
| 534 | u32 use_count; | ||
| 535 | u32 wq_pending_count; | ||
| 536 | }; | ||
| 537 | |||
| 538 | struct hw_rq { | ||
| 539 | struct list_head list_entry; | ||
| 540 | enum sli4_qtype type; | ||
| 541 | u32 instance; | ||
| 542 | |||
| 543 | u32 entry_count; | ||
| 544 | u32 use_count; | ||
| 545 | u32 hdr_entry_size; | ||
| 546 | u32 first_burst_entry_size; | ||
| 547 | u32 data_entry_size; | ||
| 548 | bool is_mrq; | ||
| 549 | u32 base_mrq_id; | ||
| 550 | |||
| 551 | struct hw_cq *cq; | ||
| 552 | |||
| 553 | u8 filter_mask; | ||
| 554 | struct sli4_queue *hdr; | ||
| 555 | struct sli4_queue *first_burst; | ||
| 556 | struct sli4_queue *data; | ||
| 557 | |||
| 558 | struct efc_hw_rq_buffer *hdr_buf; | ||
| 559 | struct efc_hw_rq_buffer *fb_buf; | ||
| 560 | struct efc_hw_rq_buffer *payload_buf; | ||
| 561 | /* RQ tracker for this RQ */ | ||
| 562 | struct efc_hw_sequence **rq_tracker; | ||
| 563 | }; | ||
| 564 | |||
| 565 | struct efct_hw_send_frame_context { | ||
| 566 | struct efct_hw *hw; | ||
| 567 | struct hw_wq_callback *wqcb; | ||
| 568 | struct efct_hw_wqe wqe; | ||
| 569 | void (*callback)(int status, void *arg); | ||
| 570 | void *arg; | ||
| 571 | |||
| 572 | /* General purpose elements */ | ||
| 573 | struct efc_hw_sequence *seq; | ||
| 574 | struct efc_dma payload; | ||
| 575 | }; | ||
| 576 | |||
| 577 | struct efct_hw_grp_hdr { | ||
| 578 | u32 size; | ||
| 579 | __be32 magic_number; | ||
| 580 | u32 word2; | ||
| 581 | u8 rev_name[128]; | ||
| 582 | u8 date[12]; | ||
| 583 | u8 revision[32]; | ||
| 584 | }; | ||
| 585 | |||
| 586 | static inline int | ||
| 587 | efct_hw_get_link_speed(struct efct_hw *hw) { | ||
| 588 | return hw->link.speed; | ||
| 589 | } | ||
| 590 | |||
| 591 | int | ||
| 592 | efct_hw_setup(struct efct_hw *hw, void *os, struct pci_dev *pdev); | ||
| 593 | int efct_hw_init(struct efct_hw *hw); | ||
| 594 | int | ||
| 595 | efct_hw_parse_filter(struct efct_hw *hw, void *value); | ||
| 596 | int | ||
| 597 | efct_hw_init_queues(struct efct_hw *hw); | ||
| 598 | int | ||
| 599 | efct_hw_map_wq_cpu(struct efct_hw *hw); | ||
| 600 | uint64_t | ||
| 601 | efct_get_wwnn(struct efct_hw *hw); | ||
| 602 | uint64_t | ||
| 603 | efct_get_wwpn(struct efct_hw *hw); | ||
| 604 | |||
| 605 | int efct_hw_rx_allocate(struct efct_hw *hw); | ||
| 606 | int efct_hw_rx_post(struct efct_hw *hw); | ||
| 607 | void efct_hw_rx_free(struct efct_hw *hw); | ||
| 608 | int | ||
| 609 | efct_hw_command(struct efct_hw *hw, u8 *cmd, u32 opts, void *cb, | ||
| 610 | void *arg); | ||
| 611 | int | ||
| 612 | efct_issue_mbox_rqst(void *base, void *cmd, void *cb, void *arg); | ||
| 613 | |||
| 614 | struct efct_hw_io *efct_hw_io_alloc(struct efct_hw *hw); | ||
| 615 | int efct_hw_io_free(struct efct_hw *hw, struct efct_hw_io *io); | ||
| 616 | u8 efct_hw_io_inuse(struct efct_hw *hw, struct efct_hw_io *io); | ||
| 617 | int | ||
| 618 | efct_hw_io_send(struct efct_hw *hw, enum efct_hw_io_type type, | ||
| 619 | struct efct_hw_io *io, union efct_hw_io_param_u *iparam, | ||
| 620 | void *cb, void *arg); | ||
| 621 | int | ||
| 622 | efct_hw_io_register_sgl(struct efct_hw *hw, struct efct_hw_io *io, | ||
| 623 | struct efc_dma *sgl, | ||
| 624 | u32 sgl_count); | ||
| 625 | int | ||
| 626 | efct_hw_io_init_sges(struct efct_hw *hw, | ||
| 627 | struct efct_hw_io *io, enum efct_hw_io_type type); | ||
| 628 | |||
| 629 | int | ||
| 630 | efct_hw_io_add_sge(struct efct_hw *hw, struct efct_hw_io *io, | ||
| 631 | uintptr_t addr, u32 length); | ||
| 632 | int | ||
| 633 | efct_hw_io_abort(struct efct_hw *hw, struct efct_hw_io *io_to_abort, | ||
| 634 | bool send_abts, void *cb, void *arg); | ||
| 635 | u32 | ||
| 636 | efct_hw_io_get_count(struct efct_hw *hw, | ||
| 637 | enum efct_hw_io_count_type io_count_type); | ||
| 638 | struct efct_hw_io | ||
| 639 | *efct_hw_io_lookup(struct efct_hw *hw, u32 indicator); | ||
| 640 | void efct_hw_io_abort_all(struct efct_hw *hw); | ||
| 641 | void efct_hw_io_free_internal(struct kref *arg); | ||
| 642 | |||
| 643 | /* HW WQ request tag API */ | ||
| 644 | struct reqtag_pool *efct_hw_reqtag_pool_alloc(struct efct_hw *hw); | ||
| 645 | void efct_hw_reqtag_pool_free(struct efct_hw *hw); | ||
| 646 | struct hw_wq_callback | ||
| 647 | *efct_hw_reqtag_alloc(struct efct_hw *hw, | ||
| 648 | void (*callback)(void *arg, u8 *cqe, | ||
| 649 | int status), void *arg); | ||
| 650 | void | ||
| 651 | efct_hw_reqtag_free(struct efct_hw *hw, struct hw_wq_callback *wqcb); | ||
| 652 | struct hw_wq_callback | ||
| 653 | *efct_hw_reqtag_get_instance(struct efct_hw *hw, u32 instance_index); | ||
| 654 | |||
| 655 | /* RQ completion handlers for RQ pair mode */ | ||
| 656 | int | ||
| 657 | efct_hw_rqpair_process_rq(struct efct_hw *hw, | ||
| 658 | struct hw_cq *cq, u8 *cqe); | ||
| 659 | int | ||
| 660 | efct_hw_rqpair_sequence_free(struct efct_hw *hw, struct efc_hw_sequence *seq); | ||
| 661 | static inline void | ||
| 662 | efct_hw_sequence_copy(struct efc_hw_sequence *dst, | ||
| 663 | struct efc_hw_sequence *src) | ||
| 664 | { | ||
| 665 | /* Copy src to dst, then zero out the linked list link */ | ||
| 666 | *dst = *src; | ||
| 667 | } | ||
| 668 | |||
| 669 | int | ||
| 670 | efct_efc_hw_sequence_free(struct efc *efc, struct efc_hw_sequence *seq); | ||
| 671 | |||
| 672 | static inline int | ||
| 673 | efct_hw_sequence_free(struct efct_hw *hw, struct efc_hw_sequence *seq) | ||
| 674 | { | ||
| 675 | /* Only RQ pair mode is supported */ | ||
| 676 | return efct_hw_rqpair_sequence_free(hw, seq); | ||
| 677 | } | ||
| 678 | |||
| 679 | int | ||
| 680 | efct_hw_eq_process(struct efct_hw *hw, struct hw_eq *eq, | ||
| 681 | u32 max_isr_time_msec); | ||
| 682 | void efct_hw_cq_process(struct efct_hw *hw, struct hw_cq *cq); | ||
| 683 | void | ||
| 684 | efct_hw_wq_process(struct efct_hw *hw, struct hw_cq *cq, | ||
| 685 | u8 *cqe, int status, u16 rid); | ||
| 686 | void | ||
| 687 | efct_hw_xabt_process(struct efct_hw *hw, struct hw_cq *cq, | ||
| 688 | u8 *cqe, u16 rid); | ||
| 689 | int | ||
| 690 | efct_hw_process(struct efct_hw *hw, u32 vector, u32 max_isr_time_msec); | ||
| 691 | int | ||
| 692 | efct_hw_queue_hash_find(struct efct_queue_hash *hash, u16 id); | ||
| 693 | int efct_hw_wq_write(struct hw_wq *wq, struct efct_hw_wqe *wqe); | ||
| 694 | int | ||
| 695 | efct_hw_send_frame(struct efct_hw *hw, struct fc_frame_header *hdr, | ||
| 696 | u8 sof, u8 eof, struct efc_dma *payload, | ||
| 697 | struct efct_hw_send_frame_context *ctx, | ||
| 698 | void (*callback)(void *arg, u8 *cqe, int status), | ||
| 699 | void *arg); | ||
| 700 | int | ||
| 701 | efct_els_hw_srrs_send(struct efc *efc, struct efc_disc_io *io); | ||
| 702 | int | ||
| 703 | efct_efc_bls_send(struct efc *efc, u32 type, struct sli_bls_params *bls); | ||
| 704 | int | ||
| 705 | efct_hw_bls_send(struct efct *efct, u32 type, struct sli_bls_params *bls_params, | ||
| 706 | void *cb, void *arg); | ||
| 707 | |||
| 708 | /* Function for retrieving link statistics */ | ||
| 709 | int | ||
| 710 | efct_hw_get_link_stats(struct efct_hw *hw, | ||
| 711 | u8 req_ext_counters, | ||
| 712 | u8 clear_overflow_flags, | ||
| 713 | u8 clear_all_counters, | ||
| 714 | void (*efct_hw_link_stat_cb_t)(int status, | ||
| 715 | u32 num_counters, | ||
| 716 | struct efct_hw_link_stat_counts *counters, void *arg), | ||
| 717 | void *arg); | ||
| 718 | /* Function for retrieving host statistics */ | ||
| 719 | int | ||
| 720 | efct_hw_get_host_stats(struct efct_hw *hw, | ||
| 721 | u8 cc, | ||
| 722 | void (*efct_hw_host_stat_cb_t)(int status, | ||
| 723 | u32 num_counters, | ||
| 724 | struct efct_hw_host_stat_counts *counters, void *arg), | ||
| 725 | void *arg); | ||
| 726 | int | ||
| 727 | efct_hw_firmware_write(struct efct_hw *hw, struct efc_dma *dma, | ||
| 728 | u32 size, u32 offset, int last, | ||
| 729 | void (*cb)(int status, u32 bytes_written, | ||
| 730 | u32 change_status, void *arg), | ||
| 731 | void *arg); | ||
| 732 | typedef void (*efct_hw_async_cb_t)(struct efct_hw *hw, int status, | ||
| 733 | u8 *mqe, void *arg); | ||
| 734 | int | ||
| 735 | efct_hw_async_call(struct efct_hw *hw, efct_hw_async_cb_t callback, void *arg); | ||
| 736 | |||
| 737 | struct hw_eq *efct_hw_new_eq(struct efct_hw *hw, u32 entry_count); | ||
| 738 | struct hw_cq *efct_hw_new_cq(struct hw_eq *eq, u32 entry_count); | ||
| 739 | u32 | ||
| 740 | efct_hw_new_cq_set(struct hw_eq *eqs[], struct hw_cq *cqs[], | ||
| 741 | u32 num_cqs, u32 entry_count); | ||
| 742 | struct hw_mq *efct_hw_new_mq(struct hw_cq *cq, u32 entry_count); | ||
| 743 | struct hw_wq | ||
| 744 | *efct_hw_new_wq(struct hw_cq *cq, u32 entry_count); | ||
| 745 | u32 | ||
| 746 | efct_hw_new_rq_set(struct hw_cq *cqs[], struct hw_rq *rqs[], | ||
| 747 | u32 num_rq_pairs, u32 entry_count); | ||
| 748 | void efct_hw_del_eq(struct hw_eq *eq); | ||
| 749 | void efct_hw_del_cq(struct hw_cq *cq); | ||
| 750 | void efct_hw_del_mq(struct hw_mq *mq); | ||
| 751 | void efct_hw_del_wq(struct hw_wq *wq); | ||
| 752 | void efct_hw_del_rq(struct hw_rq *rq); | ||
| 753 | void efct_hw_queue_teardown(struct efct_hw *hw); | ||
| 754 | void efct_hw_teardown(struct efct_hw *hw); | ||
| 755 | int | ||
| 756 | efct_hw_reset(struct efct_hw *hw, enum efct_hw_reset reset); | ||
| 757 | |||
| 758 | int | ||
| 759 | efct_hw_port_control(struct efct_hw *hw, enum efct_hw_port ctrl, | ||
| 760 | uintptr_t value, | ||
| 761 | void (*cb)(int status, uintptr_t value, void *arg), | ||
| 762 | void *arg); | ||
| 763 | |||
| 764 | #endif /* __EFCT_H__ */ | ||
| @@ -0,0 +1,677 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efct_driver.h" | ||
| 8 | #include "efct_hw.h" | ||
| 9 | #include "efct_unsol.h" | ||
| 10 | |||
| 11 | int | ||
| 12 | efct_hw_init_queues(struct efct_hw *hw) | ||
| 13 | { | ||
| 14 | struct hw_eq *eq = NULL; | ||
| 15 | struct hw_cq *cq = NULL; | ||
| 16 | struct hw_wq *wq = NULL; | ||
| 17 | struct hw_mq *mq = NULL; | ||
| 18 | |||
| 19 | struct hw_eq *eqs[EFCT_HW_MAX_NUM_EQ]; | ||
| 20 | struct hw_cq *cqs[EFCT_HW_MAX_NUM_EQ]; | ||
| 21 | struct hw_rq *rqs[EFCT_HW_MAX_NUM_EQ]; | ||
| 22 | u32 i = 0, j; | ||
| 23 | |||
| 24 | hw->eq_count = 0; | ||
| 25 | hw->cq_count = 0; | ||
| 26 | hw->mq_count = 0; | ||
| 27 | hw->wq_count = 0; | ||
| 28 | hw->rq_count = 0; | ||
| 29 | hw->hw_rq_count = 0; | ||
| 30 | INIT_LIST_HEAD(&hw->eq_list); | ||
| 31 | |||
| 32 | for (i = 0; i < hw->config.n_eq; i++) { | ||
| 33 | /* Create EQ */ | ||
| 34 | eq = efct_hw_new_eq(hw, EFCT_HW_EQ_DEPTH); | ||
| 35 | if (!eq) { | ||
| 36 | efct_hw_queue_teardown(hw); | ||
| 37 | return -ENOMEM; | ||
| 38 | } | ||
| 39 | |||
| 40 | eqs[i] = eq; | ||
| 41 | |||
| 42 | /* Create one MQ */ | ||
| 43 | if (!i) { | ||
| 44 | cq = efct_hw_new_cq(eq, | ||
| 45 | hw->num_qentries[SLI4_QTYPE_CQ]); | ||
| 46 | if (!cq) { | ||
| 47 | efct_hw_queue_teardown(hw); | ||
| 48 | return -ENOMEM; | ||
| 49 | } | ||
| 50 | |||
| 51 | mq = efct_hw_new_mq(cq, EFCT_HW_MQ_DEPTH); | ||
| 52 | if (!mq) { | ||
| 53 | efct_hw_queue_teardown(hw); | ||
| 54 | return -ENOMEM; | ||
| 55 | } | ||
| 56 | } | ||
| 57 | |||
| 58 | /* Create WQ */ | ||
| 59 | cq = efct_hw_new_cq(eq, hw->num_qentries[SLI4_QTYPE_CQ]); | ||
| 60 | if (!cq) { | ||
| 61 | efct_hw_queue_teardown(hw); | ||
| 62 | return -ENOMEM; | ||
| 63 | } | ||
| 64 | |||
| 65 | wq = efct_hw_new_wq(cq, hw->num_qentries[SLI4_QTYPE_WQ]); | ||
| 66 | if (!wq) { | ||
| 67 | efct_hw_queue_teardown(hw); | ||
| 68 | return -ENOMEM; | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | /* Create CQ set */ | ||
| 73 | if (efct_hw_new_cq_set(eqs, cqs, i, hw->num_qentries[SLI4_QTYPE_CQ])) { | ||
| 74 | efct_hw_queue_teardown(hw); | ||
| 75 | return -EIO; | ||
| 76 | } | ||
| 77 | |||
| 78 | /* Create RQ set */ | ||
| 79 | if (efct_hw_new_rq_set(cqs, rqs, i, EFCT_HW_RQ_ENTRIES_DEF)) { | ||
| 80 | efct_hw_queue_teardown(hw); | ||
| 81 | return -EIO; | ||
| 82 | } | ||
| 83 | |||
| 84 | for (j = 0; j < i ; j++) { | ||
| 85 | rqs[j]->filter_mask = 0; | ||
| 86 | rqs[j]->is_mrq = true; | ||
| 87 | rqs[j]->base_mrq_id = rqs[0]->hdr->id; | ||
| 88 | } | ||
| 89 | |||
| 90 | hw->hw_mrq_count = i; | ||
| 91 | |||
| 92 | return 0; | ||
| 93 | } | ||
| 94 | |||
| 95 | int | ||
| 96 | efct_hw_map_wq_cpu(struct efct_hw *hw) | ||
| 97 | { | ||
| 98 | struct efct *efct = hw->os; | ||
| 99 | u32 cpu = 0, i; | ||
| 100 | |||
| 101 | /* Init cpu_map array */ | ||
| 102 | hw->wq_cpu_array = kcalloc(num_possible_cpus(), sizeof(void *), | ||
| 103 | GFP_KERNEL); | ||
| 104 | if (!hw->wq_cpu_array) | ||
| 105 | return -ENOMEM; | ||
| 106 | |||
| 107 | for (i = 0; i < hw->config.n_eq; i++) { | ||
| 108 | const struct cpumask *maskp; | ||
| 109 | |||
| 110 | /* Get a CPU mask for all CPUs affinitized to this vector */ | ||
| 111 | maskp = pci_irq_get_affinity(efct->pci, i); | ||
| 112 | if (!maskp) { | ||
| 113 | efc_log_debug(efct, "maskp null for vector:%d\n", i); | ||
| 114 | continue; | ||
| 115 | } | ||
| 116 | |||
| 117 | /* Loop through all CPUs associated with vector idx */ | ||
| 118 | for_each_cpu_and(cpu, maskp, cpu_present_mask) { | ||
| 119 | efc_log_debug(efct, "CPU:%d irq vector:%d\n", cpu, i); | ||
| 120 | hw->wq_cpu_array[cpu] = hw->hw_wq[i]; | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | return 0; | ||
| 125 | } | ||
| 126 | |||
| 127 | struct hw_eq * | ||
| 128 | efct_hw_new_eq(struct efct_hw *hw, u32 entry_count) | ||
| 129 | { | ||
| 130 | struct hw_eq *eq = kzalloc(sizeof(*eq), GFP_KERNEL); | ||
| 131 | |||
| 132 | if (!eq) | ||
| 133 | return NULL; | ||
| 134 | |||
| 135 | eq->type = SLI4_QTYPE_EQ; | ||
| 136 | eq->hw = hw; | ||
| 137 | eq->entry_count = entry_count; | ||
| 138 | eq->instance = hw->eq_count++; | ||
| 139 | eq->queue = &hw->eq[eq->instance]; | ||
| 140 | INIT_LIST_HEAD(&eq->cq_list); | ||
| 141 | |||
| 142 | if (sli_queue_alloc(&hw->sli, SLI4_QTYPE_EQ, eq->queue, entry_count, | ||
| 143 | NULL)) { | ||
| 144 | efc_log_err(hw->os, "EQ[%d] alloc failure\n", eq->instance); | ||
| 145 | kfree(eq); | ||
| 146 | return NULL; | ||
| 147 | } | ||
| 148 | |||
| 149 | sli_eq_modify_delay(&hw->sli, eq->queue, 1, 0, 8); | ||
| 150 | hw->hw_eq[eq->instance] = eq; | ||
| 151 | INIT_LIST_HEAD(&eq->list_entry); | ||
| 152 | list_add_tail(&eq->list_entry, &hw->eq_list); | ||
| 153 | efc_log_debug(hw->os, "create eq[%2d] id %3d len %4d\n", eq->instance, | ||
| 154 | eq->queue->id, eq->entry_count); | ||
| 155 | return eq; | ||
| 156 | } | ||
| 157 | |||
| 158 | struct hw_cq * | ||
| 159 | efct_hw_new_cq(struct hw_eq *eq, u32 entry_count) | ||
| 160 | { | ||
| 161 | struct efct_hw *hw = eq->hw; | ||
| 162 | struct hw_cq *cq = kzalloc(sizeof(*cq), GFP_KERNEL); | ||
| 163 | |||
| 164 | if (!cq) | ||
| 165 | return NULL; | ||
| 166 | |||
| 167 | cq->eq = eq; | ||
| 168 | cq->type = SLI4_QTYPE_CQ; | ||
| 169 | cq->instance = eq->hw->cq_count++; | ||
| 170 | cq->entry_count = entry_count; | ||
| 171 | cq->queue = &hw->cq[cq->instance]; | ||
| 172 | |||
| 173 | INIT_LIST_HEAD(&cq->q_list); | ||
| 174 | |||
| 175 | if (sli_queue_alloc(&hw->sli, SLI4_QTYPE_CQ, cq->queue, | ||
| 176 | cq->entry_count, eq->queue)) { | ||
| 177 | efc_log_err(hw->os, "CQ[%d] allocation failure len=%d\n", | ||
| 178 | eq->instance, eq->entry_count); | ||
| 179 | kfree(cq); | ||
| 180 | return NULL; | ||
| 181 | } | ||
| 182 | |||
| 183 | hw->hw_cq[cq->instance] = cq; | ||
| 184 | INIT_LIST_HEAD(&cq->list_entry); | ||
| 185 | list_add_tail(&cq->list_entry, &eq->cq_list); | ||
| 186 | efc_log_debug(hw->os, "create cq[%2d] id %3d len %4d\n", cq->instance, | ||
| 187 | cq->queue->id, cq->entry_count); | ||
| 188 | return cq; | ||
| 189 | } | ||
| 190 | |||
| 191 | u32 | ||
| 192 | efct_hw_new_cq_set(struct hw_eq *eqs[], struct hw_cq *cqs[], | ||
| 193 | u32 num_cqs, u32 entry_count) | ||
| 194 | { | ||
| 195 | u32 i; | ||
| 196 | struct efct_hw *hw = eqs[0]->hw; | ||
| 197 | struct sli4 *sli4 = &hw->sli; | ||
| 198 | struct hw_cq *cq = NULL; | ||
| 199 | struct sli4_queue *qs[SLI4_MAX_CQ_SET_COUNT]; | ||
| 200 | struct sli4_queue *assefct[SLI4_MAX_CQ_SET_COUNT]; | ||
| 201 | |||
| 202 | /* Initialise CQS pointers to NULL */ | ||
| 203 | for (i = 0; i < num_cqs; i++) | ||
| 204 | cqs[i] = NULL; | ||
| 205 | |||
| 206 | for (i = 0; i < num_cqs; i++) { | ||
| 207 | cq = kzalloc(sizeof(*cq), GFP_KERNEL); | ||
| 208 | if (!cq) | ||
| 209 | goto error; | ||
| 210 | |||
| 211 | cqs[i] = cq; | ||
| 212 | cq->eq = eqs[i]; | ||
| 213 | cq->type = SLI4_QTYPE_CQ; | ||
| 214 | cq->instance = hw->cq_count++; | ||
| 215 | cq->entry_count = entry_count; | ||
| 216 | cq->queue = &hw->cq[cq->instance]; | ||
| 217 | qs[i] = cq->queue; | ||
| 218 | assefct[i] = eqs[i]->queue; | ||
| 219 | INIT_LIST_HEAD(&cq->q_list); | ||
| 220 | } | ||
| 221 | |||
| 222 | if (sli_cq_alloc_set(sli4, qs, num_cqs, entry_count, assefct)) { | ||
| 223 | efc_log_err(hw->os, "Failed to create CQ Set.\n"); | ||
| 224 | goto error; | ||
| 225 | } | ||
| 226 | |||
| 227 | for (i = 0; i < num_cqs; i++) { | ||
| 228 | hw->hw_cq[cqs[i]->instance] = cqs[i]; | ||
| 229 | INIT_LIST_HEAD(&cqs[i]->list_entry); | ||
| 230 | list_add_tail(&cqs[i]->list_entry, &cqs[i]->eq->cq_list); | ||
| 231 | } | ||
| 232 | |||
| 233 | return 0; | ||
| 234 | |||
| 235 | error: | ||
| 236 | for (i = 0; i < num_cqs; i++) { | ||
| 237 | kfree(cqs[i]); | ||
| 238 | cqs[i] = NULL; | ||
| 239 | } | ||
| 240 | return -EIO; | ||
| 241 | } | ||
| 242 | |||
| 243 | struct hw_mq * | ||
| 244 | efct_hw_new_mq(struct hw_cq *cq, u32 entry_count) | ||
| 245 | { | ||
| 246 | struct efct_hw *hw = cq->eq->hw; | ||
| 247 | struct hw_mq *mq = kzalloc(sizeof(*mq), GFP_KERNEL); | ||
| 248 | |||
| 249 | if (!mq) | ||
| 250 | return NULL; | ||
| 251 | |||
| 252 | mq->cq = cq; | ||
| 253 | mq->type = SLI4_QTYPE_MQ; | ||
| 254 | mq->instance = cq->eq->hw->mq_count++; | ||
| 255 | mq->entry_count = entry_count; | ||
| 256 | mq->entry_size = EFCT_HW_MQ_DEPTH; | ||
| 257 | mq->queue = &hw->mq[mq->instance]; | ||
| 258 | |||
| 259 | if (sli_queue_alloc(&hw->sli, SLI4_QTYPE_MQ, mq->queue, mq->entry_size, | ||
| 260 | cq->queue)) { | ||
| 261 | efc_log_err(hw->os, "MQ allocation failure\n"); | ||
| 262 | kfree(mq); | ||
| 263 | return NULL; | ||
| 264 | } | ||
| 265 | |||
| 266 | hw->hw_mq[mq->instance] = mq; | ||
| 267 | INIT_LIST_HEAD(&mq->list_entry); | ||
| 268 | list_add_tail(&mq->list_entry, &cq->q_list); | ||
| 269 | efc_log_debug(hw->os, "create mq[%2d] id %3d len %4d\n", mq->instance, | ||
| 270 | mq->queue->id, mq->entry_count); | ||
| 271 | return mq; | ||
| 272 | } | ||
| 273 | |||
| 274 | struct hw_wq * | ||
| 275 | efct_hw_new_wq(struct hw_cq *cq, u32 entry_count) | ||
| 276 | { | ||
| 277 | struct efct_hw *hw = cq->eq->hw; | ||
| 278 | struct hw_wq *wq = kzalloc(sizeof(*wq), GFP_KERNEL); | ||
| 279 | |||
| 280 | if (!wq) | ||
| 281 | return NULL; | ||
| 282 | |||
| 283 | wq->hw = cq->eq->hw; | ||
| 284 | wq->cq = cq; | ||
| 285 | wq->type = SLI4_QTYPE_WQ; | ||
| 286 | wq->instance = cq->eq->hw->wq_count++; | ||
| 287 | wq->entry_count = entry_count; | ||
| 288 | wq->queue = &hw->wq[wq->instance]; | ||
| 289 | wq->wqec_set_count = EFCT_HW_WQEC_SET_COUNT; | ||
| 290 | wq->wqec_count = wq->wqec_set_count; | ||
| 291 | wq->free_count = wq->entry_count - 1; | ||
| 292 | INIT_LIST_HEAD(&wq->pending_list); | ||
| 293 | |||
| 294 | if (sli_queue_alloc(&hw->sli, SLI4_QTYPE_WQ, wq->queue, | ||
| 295 | wq->entry_count, cq->queue)) { | ||
| 296 | efc_log_err(hw->os, "WQ allocation failure\n"); | ||
| 297 | kfree(wq); | ||
| 298 | return NULL; | ||
| 299 | } | ||
| 300 | |||
| 301 | hw->hw_wq[wq->instance] = wq; | ||
| 302 | INIT_LIST_HEAD(&wq->list_entry); | ||
| 303 | list_add_tail(&wq->list_entry, &cq->q_list); | ||
| 304 | efc_log_debug(hw->os, "create wq[%2d] id %3d len %4d cls %d\n", | ||
| 305 | wq->instance, wq->queue->id, wq->entry_count, wq->class); | ||
| 306 | return wq; | ||
| 307 | } | ||
| 308 | |||
| 309 | u32 | ||
| 310 | efct_hw_new_rq_set(struct hw_cq *cqs[], struct hw_rq *rqs[], | ||
| 311 | u32 num_rq_pairs, u32 entry_count) | ||
| 312 | { | ||
| 313 | struct efct_hw *hw = cqs[0]->eq->hw; | ||
| 314 | struct hw_rq *rq = NULL; | ||
| 315 | struct sli4_queue *qs[SLI4_MAX_RQ_SET_COUNT * 2] = { NULL }; | ||
| 316 | u32 i, q_count, size; | ||
| 317 | |||
| 318 | /* Initialise RQS pointers */ | ||
| 319 | for (i = 0; i < num_rq_pairs; i++) | ||
| 320 | rqs[i] = NULL; | ||
| 321 | |||
| 322 | /* | ||
| 323 | * Allocate an RQ object SET, where each element in set | ||
| 324 | * encapsulates 2 SLI queues (for rq pair) | ||
| 325 | */ | ||
| 326 | for (i = 0, q_count = 0; i < num_rq_pairs; i++, q_count += 2) { | ||
| 327 | rq = kzalloc(sizeof(*rq), GFP_KERNEL); | ||
| 328 | if (!rq) | ||
| 329 | goto error; | ||
| 330 | |||
| 331 | rqs[i] = rq; | ||
| 332 | rq->instance = hw->hw_rq_count++; | ||
| 333 | rq->cq = cqs[i]; | ||
| 334 | rq->type = SLI4_QTYPE_RQ; | ||
| 335 | rq->entry_count = entry_count; | ||
| 336 | |||
| 337 | /* Header RQ */ | ||
| 338 | rq->hdr = &hw->rq[hw->rq_count]; | ||
| 339 | rq->hdr_entry_size = EFCT_HW_RQ_HEADER_SIZE; | ||
| 340 | hw->hw_rq_lookup[hw->rq_count] = rq->instance; | ||
| 341 | hw->rq_count++; | ||
| 342 | qs[q_count] = rq->hdr; | ||
| 343 | |||
| 344 | /* Data RQ */ | ||
| 345 | rq->data = &hw->rq[hw->rq_count]; | ||
| 346 | rq->data_entry_size = hw->config.rq_default_buffer_size; | ||
| 347 | hw->hw_rq_lookup[hw->rq_count] = rq->instance; | ||
| 348 | hw->rq_count++; | ||
| 349 | qs[q_count + 1] = rq->data; | ||
| 350 | |||
| 351 | rq->rq_tracker = NULL; | ||
| 352 | } | ||
| 353 | |||
| 354 | if (sli_fc_rq_set_alloc(&hw->sli, num_rq_pairs, qs, | ||
| 355 | cqs[0]->queue->id, | ||
| 356 | rqs[0]->entry_count, | ||
| 357 | rqs[0]->hdr_entry_size, | ||
| 358 | rqs[0]->data_entry_size)) { | ||
| 359 | efc_log_err(hw->os, "RQ Set alloc failure for base CQ=%d\n", | ||
| 360 | cqs[0]->queue->id); | ||
| 361 | goto error; | ||
| 362 | } | ||
| 363 | |||
| 364 | for (i = 0; i < num_rq_pairs; i++) { | ||
| 365 | hw->hw_rq[rqs[i]->instance] = rqs[i]; | ||
| 366 | INIT_LIST_HEAD(&rqs[i]->list_entry); | ||
| 367 | list_add_tail(&rqs[i]->list_entry, &cqs[i]->q_list); | ||
| 368 | size = sizeof(struct efc_hw_sequence *) * rqs[i]->entry_count; | ||
| 369 | rqs[i]->rq_tracker = kzalloc(size, GFP_KERNEL); | ||
| 370 | if (!rqs[i]->rq_tracker) | ||
| 371 | goto error; | ||
| 372 | } | ||
| 373 | |||
| 374 | return 0; | ||
| 375 | |||
| 376 | error: | ||
| 377 | for (i = 0; i < num_rq_pairs; i++) { | ||
| 378 | if (rqs[i]) { | ||
| 379 | kfree(rqs[i]->rq_tracker); | ||
| 380 | kfree(rqs[i]); | ||
| 381 | } | ||
| 382 | } | ||
| 383 | |||
| 384 | return -EIO; | ||
| 385 | } | ||
| 386 | |||
| 387 | void | ||
| 388 | efct_hw_del_eq(struct hw_eq *eq) | ||
| 389 | { | ||
| 390 | struct hw_cq *cq; | ||
| 391 | struct hw_cq *cq_next; | ||
| 392 | |||
| 393 | if (!eq) | ||
| 394 | return; | ||
| 395 | |||
| 396 | list_for_each_entry_safe(cq, cq_next, &eq->cq_list, list_entry) | ||
| 397 | efct_hw_del_cq(cq); | ||
| 398 | list_del(&eq->list_entry); | ||
| 399 | eq->hw->hw_eq[eq->instance] = NULL; | ||
| 400 | kfree(eq); | ||
| 401 | } | ||
| 402 | |||
| 403 | void | ||
| 404 | efct_hw_del_cq(struct hw_cq *cq) | ||
| 405 | { | ||
| 406 | struct hw_q *q; | ||
| 407 | struct hw_q *q_next; | ||
| 408 | |||
| 409 | if (!cq) | ||
| 410 | return; | ||
| 411 | |||
| 412 | list_for_each_entry_safe(q, q_next, &cq->q_list, list_entry) { | ||
| 413 | switch (q->type) { | ||
| 414 | case SLI4_QTYPE_MQ: | ||
| 415 | efct_hw_del_mq((struct hw_mq *)q); | ||
| 416 | break; | ||
| 417 | case SLI4_QTYPE_WQ: | ||
| 418 | efct_hw_del_wq((struct hw_wq *)q); | ||
| 419 | break; | ||
| 420 | case SLI4_QTYPE_RQ: | ||
| 421 | efct_hw_del_rq((struct hw_rq *)q); | ||
| 422 | break; | ||
| 423 | default: | ||
| 424 | break; | ||
| 425 | } | ||
| 426 | } | ||
| 427 | list_del(&cq->list_entry); | ||
| 428 | cq->eq->hw->hw_cq[cq->instance] = NULL; | ||
| 429 | kfree(cq); | ||
| 430 | } | ||
| 431 | |||
| 432 | void | ||
| 433 | efct_hw_del_mq(struct hw_mq *mq) | ||
| 434 | { | ||
| 435 | if (!mq) | ||
| 436 | return; | ||
| 437 | |||
| 438 | list_del(&mq->list_entry); | ||
| 439 | mq->cq->eq->hw->hw_mq[mq->instance] = NULL; | ||
| 440 | kfree(mq); | ||
| 441 | } | ||
| 442 | |||
| 443 | void | ||
| 444 | efct_hw_del_wq(struct hw_wq *wq) | ||
| 445 | { | ||
| 446 | if (!wq) | ||
| 447 | return; | ||
| 448 | |||
| 449 | list_del(&wq->list_entry); | ||
| 450 | wq->cq->eq->hw->hw_wq[wq->instance] = NULL; | ||
| 451 | kfree(wq); | ||
| 452 | } | ||
| 453 | |||
| 454 | void | ||
| 455 | efct_hw_del_rq(struct hw_rq *rq) | ||
| 456 | { | ||
| 457 | struct efct_hw *hw = NULL; | ||
| 458 | |||
| 459 | if (!rq) | ||
| 460 | return; | ||
| 461 | /* Free RQ tracker */ | ||
| 462 | kfree(rq->rq_tracker); | ||
| 463 | rq->rq_tracker = NULL; | ||
| 464 | list_del(&rq->list_entry); | ||
| 465 | hw = rq->cq->eq->hw; | ||
| 466 | hw->hw_rq[rq->instance] = NULL; | ||
| 467 | kfree(rq); | ||
| 468 | } | ||
| 469 | |||
| 470 | void | ||
| 471 | efct_hw_queue_teardown(struct efct_hw *hw) | ||
| 472 | { | ||
| 473 | struct hw_eq *eq; | ||
| 474 | struct hw_eq *eq_next; | ||
| 475 | |||
| 476 | if (!hw->eq_list.next) | ||
| 477 | return; | ||
| 478 | |||
| 479 | list_for_each_entry_safe(eq, eq_next, &hw->eq_list, list_entry) | ||
| 480 | efct_hw_del_eq(eq); | ||
| 481 | } | ||
| 482 | |||
| 483 | static inline int | ||
| 484 | efct_hw_rqpair_find(struct efct_hw *hw, u16 rq_id) | ||
| 485 | { | ||
| 486 | return efct_hw_queue_hash_find(hw->rq_hash, rq_id); | ||
| 487 | } | ||
| 488 | |||
| 489 | static struct efc_hw_sequence * | ||
| 490 | efct_hw_rqpair_get(struct efct_hw *hw, u16 rqindex, u16 bufindex) | ||
| 491 | { | ||
| 492 | struct sli4_queue *rq_hdr = &hw->rq[rqindex]; | ||
| 493 | struct efc_hw_sequence *seq = NULL; | ||
| 494 | struct hw_rq *rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; | ||
| 495 | unsigned long flags = 0; | ||
| 496 | |||
| 497 | if (bufindex >= rq_hdr->length) { | ||
| 498 | efc_log_err(hw->os, | ||
| 499 | "RQidx %d bufidx %d exceed ring len %d for id %d\n", | ||
| 500 | rqindex, bufindex, rq_hdr->length, rq_hdr->id); | ||
| 501 | return NULL; | ||
| 502 | } | ||
| 503 | |||
| 504 | /* rq_hdr lock also covers rqindex+1 queue */ | ||
| 505 | spin_lock_irqsave(&rq_hdr->lock, flags); | ||
| 506 | |||
| 507 | seq = rq->rq_tracker[bufindex]; | ||
| 508 | rq->rq_tracker[bufindex] = NULL; | ||
| 509 | |||
| 510 | if (!seq) { | ||
| 511 | efc_log_err(hw->os, | ||
| 512 | "RQbuf NULL, rqidx %d, bufidx %d, cur q idx = %d\n", | ||
| 513 | rqindex, bufindex, rq_hdr->index); | ||
| 514 | } | ||
| 515 | |||
| 516 | spin_unlock_irqrestore(&rq_hdr->lock, flags); | ||
| 517 | return seq; | ||
| 518 | } | ||
| 519 | |||
| 520 | int | ||
| 521 | efct_hw_rqpair_process_rq(struct efct_hw *hw, struct hw_cq *cq, | ||
| 522 | u8 *cqe) | ||
| 523 | { | ||
| 524 | u16 rq_id; | ||
| 525 | u32 index; | ||
| 526 | int rqindex; | ||
| 527 | int rq_status; | ||
| 528 | u32 h_len; | ||
| 529 | u32 p_len; | ||
| 530 | struct efc_hw_sequence *seq; | ||
| 531 | struct hw_rq *rq; | ||
| 532 | |||
| 533 | rq_status = sli_fc_rqe_rqid_and_index(&hw->sli, cqe, | ||
| 534 | &rq_id, &index); | ||
| 535 | if (rq_status != 0) { | ||
| 536 | switch (rq_status) { | ||
| 537 | case SLI4_FC_ASYNC_RQ_BUF_LEN_EXCEEDED: | ||
| 538 | case SLI4_FC_ASYNC_RQ_DMA_FAILURE: | ||
| 539 | /* just get RQ buffer then return to chip */ | ||
| 540 | rqindex = efct_hw_rqpair_find(hw, rq_id); | ||
| 541 | if (rqindex < 0) { | ||
| 542 | efc_log_debug(hw->os, | ||
| 543 | "status=%#x: lookup fail id=%#x\n", | ||
| 544 | rq_status, rq_id); | ||
| 545 | break; | ||
| 546 | } | ||
| 547 | |||
| 548 | /* get RQ buffer */ | ||
| 549 | seq = efct_hw_rqpair_get(hw, rqindex, index); | ||
| 550 | |||
| 551 | /* return to chip */ | ||
| 552 | if (efct_hw_rqpair_sequence_free(hw, seq)) { | ||
| 553 | efc_log_debug(hw->os, | ||
| 554 | "status=%#x,fail rtrn buf to RQ\n", | ||
| 555 | rq_status); | ||
| 556 | break; | ||
| 557 | } | ||
| 558 | break; | ||
| 559 | case SLI4_FC_ASYNC_RQ_INSUFF_BUF_NEEDED: | ||
| 560 | case SLI4_FC_ASYNC_RQ_INSUFF_BUF_FRM_DISC: | ||
| 561 | /* | ||
| 562 | * since RQ buffers were not consumed, cannot return | ||
| 563 | * them to chip | ||
| 564 | */ | ||
| 565 | efc_log_debug(hw->os, "Warning: RCQE status=%#x,\n", | ||
| 566 | rq_status); | ||
| 567 | fallthrough; | ||
| 568 | default: | ||
| 569 | break; | ||
| 570 | } | ||
| 571 | return -EIO; | ||
| 572 | } | ||
| 573 | |||
| 574 | rqindex = efct_hw_rqpair_find(hw, rq_id); | ||
| 575 | if (rqindex < 0) { | ||
| 576 | efc_log_debug(hw->os, "Error: rq_id lookup failed for id=%#x\n", | ||
| 577 | rq_id); | ||
| 578 | return -EIO; | ||
| 579 | } | ||
| 580 | |||
| 581 | rq = hw->hw_rq[hw->hw_rq_lookup[rqindex]]; | ||
| 582 | rq->use_count++; | ||
| 583 | |||
| 584 | seq = efct_hw_rqpair_get(hw, rqindex, index); | ||
| 585 | if (WARN_ON(!seq)) | ||
| 586 | return -EIO; | ||
| 587 | |||
| 588 | seq->hw = hw; | ||
| 589 | |||
| 590 | sli_fc_rqe_length(&hw->sli, cqe, &h_len, &p_len); | ||
| 591 | seq->header->dma.len = h_len; | ||
| 592 | seq->payload->dma.len = p_len; | ||
| 593 | seq->fcfi = sli_fc_rqe_fcfi(&hw->sli, cqe); | ||
| 594 | seq->hw_priv = cq->eq; | ||
| 595 | |||
| 596 | efct_unsolicited_cb(hw->os, seq); | ||
| 597 | |||
| 598 | return 0; | ||
| 599 | } | ||
| 600 | |||
| 601 | static int | ||
| 602 | efct_hw_rqpair_put(struct efct_hw *hw, struct efc_hw_sequence *seq) | ||
| 603 | { | ||
| 604 | struct sli4_queue *rq_hdr = &hw->rq[seq->header->rqindex]; | ||
| 605 | struct sli4_queue *rq_payload = &hw->rq[seq->payload->rqindex]; | ||
| 606 | u32 hw_rq_index = hw->hw_rq_lookup[seq->header->rqindex]; | ||
| 607 | struct hw_rq *rq = hw->hw_rq[hw_rq_index]; | ||
| 608 | u32 phys_hdr[2]; | ||
| 609 | u32 phys_payload[2]; | ||
| 610 | int qindex_hdr; | ||
| 611 | int qindex_payload; | ||
| 612 | unsigned long flags = 0; | ||
| 613 | |||
| 614 | /* Update the RQ verification lookup tables */ | ||
| 615 | phys_hdr[0] = upper_32_bits(seq->header->dma.phys); | ||
| 616 | phys_hdr[1] = lower_32_bits(seq->header->dma.phys); | ||
| 617 | phys_payload[0] = upper_32_bits(seq->payload->dma.phys); | ||
| 618 | phys_payload[1] = lower_32_bits(seq->payload->dma.phys); | ||
| 619 | |||
| 620 | /* rq_hdr lock also covers payload / header->rqindex+1 queue */ | ||
| 621 | spin_lock_irqsave(&rq_hdr->lock, flags); | ||
| 622 | |||
| 623 | /* | ||
| 624 | * Note: The header must be posted last for buffer pair mode because | ||
| 625 | * posting on the header queue posts the payload queue as well. | ||
| 626 | * We do not ring the payload queue independently in RQ pair mode. | ||
| 627 | */ | ||
| 628 | qindex_payload = sli_rq_write(&hw->sli, rq_payload, | ||
| 629 | (void *)phys_payload); | ||
| 630 | qindex_hdr = sli_rq_write(&hw->sli, rq_hdr, (void *)phys_hdr); | ||
| 631 | if (qindex_hdr < 0 || | ||
| 632 | qindex_payload < 0) { | ||
| 633 | efc_log_err(hw->os, "RQ_ID=%#x write failed\n", rq_hdr->id); | ||
| 634 | spin_unlock_irqrestore(&rq_hdr->lock, flags); | ||
| 635 | return -EIO; | ||
| 636 | } | ||
| 637 | |||
| 638 | /* ensure the indexes are the same */ | ||
| 639 | WARN_ON(qindex_hdr != qindex_payload); | ||
| 640 | |||
| 641 | /* Update the lookup table */ | ||
| 642 | if (!rq->rq_tracker[qindex_hdr]) { | ||
| 643 | rq->rq_tracker[qindex_hdr] = seq; | ||
| 644 | } else { | ||
| 645 | efc_log_debug(hw->os, | ||
| 646 | "expected rq_tracker[%d][%d] buffer to be NULL\n", | ||
| 647 | hw_rq_index, qindex_hdr); | ||
| 648 | } | ||
| 649 | |||
| 650 | spin_unlock_irqrestore(&rq_hdr->lock, flags); | ||
| 651 | return 0; | ||
| 652 | } | ||
| 653 | |||
| 654 | int | ||
| 655 | efct_hw_rqpair_sequence_free(struct efct_hw *hw, struct efc_hw_sequence *seq) | ||
| 656 | { | ||
| 657 | int rc = 0; | ||
| 658 | |||
| 659 | /* | ||
| 660 | * Post the data buffer first. Because in RQ pair mode, ringing the | ||
| 661 | * doorbell of the header ring will post the data buffer as well. | ||
| 662 | */ | ||
| 663 | if (efct_hw_rqpair_put(hw, seq)) { | ||
| 664 | efc_log_err(hw->os, "error writing buffers\n"); | ||
| 665 | return -EIO; | ||
| 666 | } | ||
| 667 | |||
| 668 | return rc; | ||
| 669 | } | ||
| 670 | |||
| 671 | int | ||
| 672 | efct_efc_hw_sequence_free(struct efc *efc, struct efc_hw_sequence *seq) | ||
| 673 | { | ||
| 674 | struct efct *efct = efc->base; | ||
| 675 | |||
| 676 | return efct_hw_rqpair_sequence_free(&efct->hw, seq); | ||
| 677 | } | ||
| @@ -0,0 +1,191 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efct_driver.h" | ||
| 8 | #include "efct_hw.h" | ||
| 9 | #include "efct_io.h" | ||
| 10 | |||
| 11 | struct efct_io_pool { | ||
| 12 | struct efct *efct; | ||
| 13 | spinlock_t lock; /* IO pool lock */ | ||
| 14 | u32 io_num_ios; /* Total IOs allocated */ | ||
| 15 | struct efct_io *ios[EFCT_NUM_SCSI_IOS]; | ||
| 16 | struct list_head freelist; | ||
| 17 | |||
| 18 | }; | ||
| 19 | |||
| 20 | struct efct_io_pool * | ||
| 21 | efct_io_pool_create(struct efct *efct, u32 num_sgl) | ||
| 22 | { | ||
| 23 | u32 i = 0; | ||
| 24 | struct efct_io_pool *io_pool; | ||
| 25 | struct efct_io *io; | ||
| 26 | |||
| 27 | /* Allocate the IO pool */ | ||
| 28 | io_pool = kzalloc(sizeof(*io_pool), GFP_KERNEL); | ||
| 29 | if (!io_pool) | ||
| 30 | return NULL; | ||
| 31 | |||
| 32 | io_pool->efct = efct; | ||
| 33 | INIT_LIST_HEAD(&io_pool->freelist); | ||
| 34 | /* initialize IO pool lock */ | ||
| 35 | spin_lock_init(&io_pool->lock); | ||
| 36 | |||
| 37 | for (i = 0; i < EFCT_NUM_SCSI_IOS; i++) { | ||
| 38 | io = kzalloc(sizeof(*io), GFP_KERNEL); | ||
| 39 | if (!io) | ||
| 40 | break; | ||
| 41 | |||
| 42 | io_pool->io_num_ios++; | ||
| 43 | io_pool->ios[i] = io; | ||
| 44 | io->tag = i; | ||
| 45 | io->instance_index = i; | ||
| 46 | |||
| 47 | /* Allocate a response buffer */ | ||
| 48 | io->rspbuf.size = SCSI_RSP_BUF_LENGTH; | ||
| 49 | io->rspbuf.virt = dma_alloc_coherent(&efct->pci->dev, | ||
| 50 | io->rspbuf.size, | ||
| 51 | &io->rspbuf.phys, GFP_DMA); | ||
| 52 | if (!io->rspbuf.virt) { | ||
| 53 | efc_log_err(efct, "dma_alloc rspbuf failed\n"); | ||
| 54 | efct_io_pool_free(io_pool); | ||
| 55 | return NULL; | ||
| 56 | } | ||
| 57 | |||
| 58 | /* Allocate SGL */ | ||
| 59 | io->sgl = kzalloc(sizeof(*io->sgl) * num_sgl, GFP_KERNEL); | ||
| 60 | if (!io->sgl) { | ||
| 61 | efct_io_pool_free(io_pool); | ||
| 62 | return NULL; | ||
| 63 | } | ||
| 64 | |||
| 65 | memset(io->sgl, 0, sizeof(*io->sgl) * num_sgl); | ||
| 66 | io->sgl_allocated = num_sgl; | ||
| 67 | io->sgl_count = 0; | ||
| 68 | |||
| 69 | INIT_LIST_HEAD(&io->list_entry); | ||
| 70 | list_add_tail(&io->list_entry, &io_pool->freelist); | ||
| 71 | } | ||
| 72 | |||
| 73 | return io_pool; | ||
| 74 | } | ||
| 75 | |||
| 76 | int | ||
| 77 | efct_io_pool_free(struct efct_io_pool *io_pool) | ||
| 78 | { | ||
| 79 | struct efct *efct; | ||
| 80 | u32 i; | ||
| 81 | struct efct_io *io; | ||
| 82 | |||
| 83 | if (io_pool) { | ||
| 84 | efct = io_pool->efct; | ||
| 85 | |||
| 86 | for (i = 0; i < io_pool->io_num_ios; i++) { | ||
| 87 | io = io_pool->ios[i]; | ||
| 88 | if (!io) | ||
| 89 | continue; | ||
| 90 | |||
| 91 | kfree(io->sgl); | ||
| 92 | dma_free_coherent(&efct->pci->dev, | ||
| 93 | io->rspbuf.size, io->rspbuf.virt, | ||
| 94 | io->rspbuf.phys); | ||
| 95 | memset(&io->rspbuf, 0, sizeof(struct efc_dma)); | ||
| 96 | } | ||
| 97 | |||
| 98 | kfree(io_pool); | ||
| 99 | efct->xport->io_pool = NULL; | ||
| 100 | } | ||
| 101 | |||
| 102 | return 0; | ||
| 103 | } | ||
| 104 | |||
| 105 | struct efct_io * | ||
| 106 | efct_io_pool_io_alloc(struct efct_io_pool *io_pool) | ||
| 107 | { | ||
| 108 | struct efct_io *io = NULL; | ||
| 109 | struct efct *efct; | ||
| 110 | unsigned long flags = 0; | ||
| 111 | |||
| 112 | efct = io_pool->efct; | ||
| 113 | |||
| 114 | spin_lock_irqsave(&io_pool->lock, flags); | ||
| 115 | |||
| 116 | if (!list_empty(&io_pool->freelist)) { | ||
| 117 | io = list_first_entry(&io_pool->freelist, struct efct_io, | ||
| 118 | list_entry); | ||
| 119 | list_del_init(&io->list_entry); | ||
| 120 | } | ||
| 121 | |||
| 122 | spin_unlock_irqrestore(&io_pool->lock, flags); | ||
| 123 | |||
| 124 | if (!io) | ||
| 125 | return NULL; | ||
| 126 | |||
| 127 | io->io_type = EFCT_IO_TYPE_MAX; | ||
| 128 | io->hio_type = EFCT_HW_IO_MAX; | ||
| 129 | io->hio = NULL; | ||
| 130 | io->transferred = 0; | ||
| 131 | io->efct = efct; | ||
| 132 | io->timeout = 0; | ||
| 133 | io->sgl_count = 0; | ||
| 134 | io->tgt_task_tag = 0; | ||
| 135 | io->init_task_tag = 0; | ||
| 136 | io->hw_tag = 0; | ||
| 137 | io->display_name = "pending"; | ||
| 138 | io->seq_init = 0; | ||
| 139 | io->io_free = 0; | ||
| 140 | io->release = NULL; | ||
| 141 | atomic_add_return(1, &efct->xport->io_active_count); | ||
| 142 | atomic_add_return(1, &efct->xport->io_total_alloc); | ||
| 143 | return io; | ||
| 144 | } | ||
| 145 | |||
| 146 | /* Free an object used to track an IO */ | ||
| 147 | void | ||
| 148 | efct_io_pool_io_free(struct efct_io_pool *io_pool, struct efct_io *io) | ||
| 149 | { | ||
| 150 | struct efct *efct; | ||
| 151 | struct efct_hw_io *hio = NULL; | ||
| 152 | unsigned long flags = 0; | ||
| 153 | |||
| 154 | efct = io_pool->efct; | ||
| 155 | |||
| 156 | spin_lock_irqsave(&io_pool->lock, flags); | ||
| 157 | hio = io->hio; | ||
| 158 | io->hio = NULL; | ||
| 159 | io->io_free = 1; | ||
| 160 | INIT_LIST_HEAD(&io->list_entry); | ||
| 161 | list_add(&io->list_entry, &io_pool->freelist); | ||
| 162 | spin_unlock_irqrestore(&io_pool->lock, flags); | ||
| 163 | |||
| 164 | if (hio) | ||
| 165 | efct_hw_io_free(&efct->hw, hio); | ||
| 166 | |||
| 167 | atomic_sub_return(1, &efct->xport->io_active_count); | ||
| 168 | atomic_add_return(1, &efct->xport->io_total_free); | ||
| 169 | } | ||
| 170 | |||
| 171 | /* Find an I/O given it's node and ox_id */ | ||
| 172 | struct efct_io * | ||
| 173 | efct_io_find_tgt_io(struct efct *efct, struct efct_node *node, | ||
| 174 | u16 ox_id, u16 rx_id) | ||
| 175 | { | ||
| 176 | struct efct_io *io = NULL; | ||
| 177 | unsigned long flags = 0; | ||
| 178 | u8 found = false; | ||
| 179 | |||
| 180 | spin_lock_irqsave(&node->active_ios_lock, flags); | ||
| 181 | list_for_each_entry(io, &node->active_ios, list_entry) { | ||
| 182 | if ((io->cmd_tgt && io->init_task_tag == ox_id) && | ||
| 183 | (rx_id == 0xffff || io->tgt_task_tag == rx_id)) { | ||
| 184 | if (kref_get_unless_zero(&io->ref)) | ||
| 185 | found = true; | ||
| 186 | break; | ||
| 187 | } | ||
| 188 | } | ||
| 189 | spin_unlock_irqrestore(&node->active_ios_lock, flags); | ||
| 190 | return found ? io : NULL; | ||
| 191 | } | ||
| @@ -0,0 +1,174 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #if !defined(__EFCT_IO_H__) | ||
| 8 | #define __EFCT_IO_H__ | ||
| 9 | |||
| 10 | #include "efct_lio.h" | ||
| 11 | |||
| 12 | #define EFCT_LOG_ENABLE_IO_ERRORS(efct) \ | ||
| 13 | (((efct) != NULL) ? (((efct)->logmask & (1U << 6)) != 0) : 0) | ||
| 14 | |||
| 15 | #define io_error_log(io, fmt, ...) \ | ||
| 16 | do { \ | ||
| 17 | if (EFCT_LOG_ENABLE_IO_ERRORS(io->efct)) \ | ||
| 18 | efc_log_warn(io->efct, fmt, ##__VA_ARGS__); \ | ||
| 19 | } while (0) | ||
| 20 | |||
| 21 | #define SCSI_CMD_BUF_LENGTH 48 | ||
| 22 | #define SCSI_RSP_BUF_LENGTH (FCP_RESP_WITH_EXT + SCSI_SENSE_BUFFERSIZE) | ||
| 23 | #define EFCT_NUM_SCSI_IOS 8192 | ||
| 24 | |||
| 25 | enum efct_io_type { | ||
| 26 | EFCT_IO_TYPE_IO = 0, | ||
| 27 | EFCT_IO_TYPE_ELS, | ||
| 28 | EFCT_IO_TYPE_CT, | ||
| 29 | EFCT_IO_TYPE_CT_RESP, | ||
| 30 | EFCT_IO_TYPE_BLS_RESP, | ||
| 31 | EFCT_IO_TYPE_ABORT, | ||
| 32 | |||
| 33 | EFCT_IO_TYPE_MAX, | ||
| 34 | }; | ||
| 35 | |||
| 36 | enum efct_els_state { | ||
| 37 | EFCT_ELS_REQUEST = 0, | ||
| 38 | EFCT_ELS_REQUEST_DELAYED, | ||
| 39 | EFCT_ELS_REQUEST_DELAY_ABORT, | ||
| 40 | EFCT_ELS_REQ_ABORT, | ||
| 41 | EFCT_ELS_REQ_ABORTED, | ||
| 42 | EFCT_ELS_ABORT_IO_COMPL, | ||
| 43 | }; | ||
| 44 | |||
| 45 | /** | ||
| 46 | * Scsi target IO object | ||
| 47 | * @efct: pointer back to efct | ||
| 48 | * @instance_index: unique instance index value | ||
| 49 | * @io: IO display name | ||
| 50 | * @node: pointer to node | ||
| 51 | * @list_entry: io list entry | ||
| 52 | * @io_pending_link: io pending list entry | ||
| 53 | * @ref: reference counter | ||
| 54 | * @release: release callback function | ||
| 55 | * @init_task_tag: initiator task tag (OX_ID) for back-end and SCSI logging | ||
| 56 | * @tgt_task_tag: target task tag (RX_ID) for back-end and SCSI logging | ||
| 57 | * @hw_tag: HW layer unique IO id | ||
| 58 | * @tag: unique IO identifier | ||
| 59 | * @sgl: SGL | ||
| 60 | * @sgl_allocated: Number of allocated SGEs | ||
| 61 | * @sgl_count: Number of SGEs in this SGL | ||
| 62 | * @tgt_io: backend target private IO data | ||
| 63 | * @exp_xfer_len: expected data transfer length, based on FC header | ||
| 64 | * @hw_priv: Declarations private to HW/SLI | ||
| 65 | * @io_type: indicates what this struct efct_io structure is used for | ||
| 66 | * @hio: hw io object | ||
| 67 | * @transferred: Number of bytes transferred | ||
| 68 | * @auto_resp: set if auto_trsp was set | ||
| 69 | * @low_latency: set if low latency request | ||
| 70 | * @wq_steering: selected WQ steering request | ||
| 71 | * @wq_class: selected WQ class if steering is class | ||
| 72 | * @xfer_req: transfer size for current request | ||
| 73 | * @scsi_tgt_cb: target callback function | ||
| 74 | * @scsi_tgt_cb_arg: target callback function argument | ||
| 75 | * @abort_cb: abort callback function | ||
| 76 | * @abort_cb_arg: abort callback function argument | ||
| 77 | * @bls_cb: BLS callback function | ||
| 78 | * @bls_cb_arg: BLS callback function argument | ||
| 79 | * @tmf_cmd: TMF command being processed | ||
| 80 | * @abort_rx_id: rx_id from the ABTS that initiated the command abort | ||
| 81 | * @cmd_tgt: True if this is a Target command | ||
| 82 | * @send_abts: when aborting, indicates ABTS is to be sent | ||
| 83 | * @cmd_ini: True if this is an Initiator command | ||
| 84 | * @seq_init: True if local node has sequence initiative | ||
| 85 | * @iparam: iparams for hw io send call | ||
| 86 | * @hio_type: HW IO type | ||
| 87 | * @wire_len: wire length | ||
| 88 | * @hw_cb: saved HW callback | ||
| 89 | * @io_to_abort: for abort handling, pointer to IO to abort | ||
| 90 | * @rspbuf: SCSI Response buffer | ||
| 91 | * @timeout: Timeout value in seconds for this IO | ||
| 92 | * @cs_ctl: CS_CTL priority for this IO | ||
| 93 | * @io_free: Is io object in freelist | ||
| 94 | * @app_id: application id | ||
| 95 | */ | ||
| 96 | struct efct_io { | ||
| 97 | struct efct *efct; | ||
| 98 | u32 instance_index; | ||
| 99 | const char *display_name; | ||
| 100 | struct efct_node *node; | ||
| 101 | |||
| 102 | struct list_head list_entry; | ||
| 103 | struct list_head io_pending_link; | ||
| 104 | struct kref ref; | ||
| 105 | void (*release)(struct kref *arg); | ||
| 106 | u32 init_task_tag; | ||
| 107 | u32 tgt_task_tag; | ||
| 108 | u32 hw_tag; | ||
| 109 | u32 tag; | ||
| 110 | struct efct_scsi_sgl *sgl; | ||
| 111 | u32 sgl_allocated; | ||
| 112 | u32 sgl_count; | ||
| 113 | struct efct_scsi_tgt_io tgt_io; | ||
| 114 | u32 exp_xfer_len; | ||
| 115 | |||
| 116 | void *hw_priv; | ||
| 117 | |||
| 118 | enum efct_io_type io_type; | ||
| 119 | struct efct_hw_io *hio; | ||
| 120 | size_t transferred; | ||
| 121 | |||
| 122 | bool auto_resp; | ||
| 123 | bool low_latency; | ||
| 124 | u8 wq_steering; | ||
| 125 | u8 wq_class; | ||
| 126 | u64 xfer_req; | ||
| 127 | efct_scsi_io_cb_t scsi_tgt_cb; | ||
| 128 | void *scsi_tgt_cb_arg; | ||
| 129 | efct_scsi_io_cb_t abort_cb; | ||
| 130 | void *abort_cb_arg; | ||
| 131 | efct_scsi_io_cb_t bls_cb; | ||
| 132 | void *bls_cb_arg; | ||
| 133 | enum efct_scsi_tmf_cmd tmf_cmd; | ||
| 134 | u16 abort_rx_id; | ||
| 135 | |||
| 136 | bool cmd_tgt; | ||
| 137 | bool send_abts; | ||
| 138 | bool cmd_ini; | ||
| 139 | bool seq_init; | ||
| 140 | union efct_hw_io_param_u iparam; | ||
| 141 | enum efct_hw_io_type hio_type; | ||
| 142 | u64 wire_len; | ||
| 143 | void *hw_cb; | ||
| 144 | |||
| 145 | struct efct_io *io_to_abort; | ||
| 146 | |||
| 147 | struct efc_dma rspbuf; | ||
| 148 | u32 timeout; | ||
| 149 | u8 cs_ctl; | ||
| 150 | u8 io_free; | ||
| 151 | u32 app_id; | ||
| 152 | }; | ||
| 153 | |||
| 154 | struct efct_io_cb_arg { | ||
| 155 | int status; | ||
| 156 | int ext_status; | ||
| 157 | void *app; | ||
| 158 | }; | ||
| 159 | |||
| 160 | struct efct_io_pool * | ||
| 161 | efct_io_pool_create(struct efct *efct, u32 num_sgl); | ||
| 162 | int | ||
| 163 | efct_io_pool_free(struct efct_io_pool *io_pool); | ||
| 164 | u32 | ||
| 165 | efct_io_pool_allocated(struct efct_io_pool *io_pool); | ||
| 166 | |||
| 167 | struct efct_io * | ||
| 168 | efct_io_pool_io_alloc(struct efct_io_pool *io_pool); | ||
| 169 | void | ||
| 170 | efct_io_pool_io_free(struct efct_io_pool *io_pool, struct efct_io *io); | ||
| 171 | struct efct_io * | ||
| 172 | efct_io_find_tgt_io(struct efct *efct, struct efct_node *node, | ||
| 173 | u16 ox_id, u16 rx_id); | ||
| 174 | #endif /* __EFCT_IO_H__ */ | ||
| @@ -0,0 +1,1698 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <target/target_core_base.h> | ||
| 8 | #include <target/target_core_fabric.h> | ||
| 9 | #include "efct_driver.h" | ||
| 10 | #include "efct_lio.h" | ||
| 11 | |||
| 12 | /* | ||
| 13 | * lio_wq is used to call the LIO backed during creation or deletion of | ||
| 14 | * sessions. This brings serialization to the session management as we create | ||
| 15 | * single threaded work queue. | ||
| 16 | */ | ||
| 17 | static struct workqueue_struct *lio_wq; | ||
| 18 | |||
| 19 | static int | ||
| 20 | efct_format_wwn(char *str, size_t len, const char *pre, u64 wwn) | ||
| 21 | { | ||
| 22 | u8 a[8]; | ||
| 23 | |||
| 24 | put_unaligned_be64(wwn, a); | ||
| 25 | return snprintf(str, len, "%s%8phC", pre, a); | ||
| 26 | } | ||
| 27 | |||
| 28 | static int | ||
| 29 | efct_lio_parse_wwn(const char *name, u64 *wwp, u8 npiv) | ||
| 30 | { | ||
| 31 | int num; | ||
| 32 | u8 b[8]; | ||
| 33 | |||
| 34 | if (npiv) { | ||
| 35 | num = sscanf(name, | ||
| 36 | "%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx%02hhx", | ||
| 37 | &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6], | ||
| 38 | &b[7]); | ||
| 39 | } else { | ||
| 40 | num = sscanf(name, | ||
| 41 | "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", | ||
| 42 | &b[0], &b[1], &b[2], &b[3], &b[4], &b[5], &b[6], | ||
| 43 | &b[7]); | ||
| 44 | } | ||
| 45 | |||
| 46 | if (num != 8) | ||
| 47 | return -EINVAL; | ||
| 48 | |||
| 49 | *wwp = get_unaligned_be64(b); | ||
| 50 | return 0; | ||
| 51 | } | ||
| 52 | |||
| 53 | static int | ||
| 54 | efct_lio_parse_npiv_wwn(const char *name, size_t size, u64 *wwpn, u64 *wwnn) | ||
| 55 | { | ||
| 56 | unsigned int cnt = size; | ||
| 57 | int rc; | ||
| 58 | |||
| 59 | *wwpn = *wwnn = 0; | ||
| 60 | if (name[cnt - 1] == '\n' || name[cnt - 1] == 0) | ||
| 61 | cnt--; | ||
| 62 | |||
| 63 | /* validate we have enough characters for WWPN */ | ||
| 64 | if ((cnt != (16 + 1 + 16)) || (name[16] != ':')) | ||
| 65 | return -EINVAL; | ||
| 66 | |||
| 67 | rc = efct_lio_parse_wwn(&name[0], wwpn, 1); | ||
| 68 | if (rc) | ||
| 69 | return rc; | ||
| 70 | |||
| 71 | rc = efct_lio_parse_wwn(&name[17], wwnn, 1); | ||
| 72 | if (rc) | ||
| 73 | return rc; | ||
| 74 | |||
| 75 | return 0; | ||
| 76 | } | ||
| 77 | |||
| 78 | static ssize_t | ||
| 79 | efct_lio_tpg_enable_show(struct config_item *item, char *page) | ||
| 80 | { | ||
| 81 | struct se_portal_group *se_tpg = to_tpg(item); | ||
| 82 | struct efct_lio_tpg *tpg = | ||
| 83 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 84 | |||
| 85 | return snprintf(page, PAGE_SIZE, "%d\n", tpg->enabled); | ||
| 86 | } | ||
| 87 | |||
| 88 | static ssize_t | ||
| 89 | efct_lio_tpg_enable_store(struct config_item *item, const char *page, | ||
| 90 | size_t count) | ||
| 91 | { | ||
| 92 | struct se_portal_group *se_tpg = to_tpg(item); | ||
| 93 | struct efct_lio_tpg *tpg = | ||
| 94 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 95 | struct efct *efct; | ||
| 96 | struct efc *efc; | ||
| 97 | unsigned long op; | ||
| 98 | |||
| 99 | if (!tpg->nport || !tpg->nport->efct) { | ||
| 100 | pr_err("%s: Unable to find EFCT device\n", __func__); | ||
| 101 | return -EINVAL; | ||
| 102 | } | ||
| 103 | |||
| 104 | efct = tpg->nport->efct; | ||
| 105 | efc = efct->efcport; | ||
| 106 | |||
| 107 | if (kstrtoul(page, 0, &op) < 0) | ||
| 108 | return -EINVAL; | ||
| 109 | |||
| 110 | if (op == 1) { | ||
| 111 | int ret; | ||
| 112 | |||
| 113 | tpg->enabled = true; | ||
| 114 | efc_log_debug(efct, "enable portal group %d\n", tpg->tpgt); | ||
| 115 | |||
| 116 | ret = efct_xport_control(efct->xport, EFCT_XPORT_PORT_ONLINE); | ||
| 117 | if (ret) { | ||
| 118 | efct->tgt_efct.lio_nport = NULL; | ||
| 119 | efc_log_debug(efct, "cannot bring port online\n"); | ||
| 120 | return ret; | ||
| 121 | } | ||
| 122 | } else if (op == 0) { | ||
| 123 | efc_log_debug(efct, "disable portal group %d\n", tpg->tpgt); | ||
| 124 | |||
| 125 | if (efc->domain && efc->domain->nport) | ||
| 126 | efct_scsi_tgt_del_nport(efc, efc->domain->nport); | ||
| 127 | |||
| 128 | tpg->enabled = false; | ||
| 129 | } else { | ||
| 130 | return -EINVAL; | ||
| 131 | } | ||
| 132 | |||
| 133 | return count; | ||
| 134 | } | ||
| 135 | |||
| 136 | static ssize_t | ||
| 137 | efct_lio_npiv_tpg_enable_show(struct config_item *item, char *page) | ||
| 138 | { | ||
| 139 | struct se_portal_group *se_tpg = to_tpg(item); | ||
| 140 | struct efct_lio_tpg *tpg = | ||
| 141 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 142 | |||
| 143 | return snprintf(page, PAGE_SIZE, "%d\n", tpg->enabled); | ||
| 144 | } | ||
| 145 | |||
| 146 | static ssize_t | ||
| 147 | efct_lio_npiv_tpg_enable_store(struct config_item *item, const char *page, | ||
| 148 | size_t count) | ||
| 149 | { | ||
| 150 | struct se_portal_group *se_tpg = to_tpg(item); | ||
| 151 | struct efct_lio_tpg *tpg = | ||
| 152 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 153 | struct efct_lio_vport *lio_vport = tpg->vport; | ||
| 154 | struct efct *efct; | ||
| 155 | struct efc *efc; | ||
| 156 | unsigned long op; | ||
| 157 | |||
| 158 | if (kstrtoul(page, 0, &op) < 0) | ||
| 159 | return -EINVAL; | ||
| 160 | |||
| 161 | if (!lio_vport) { | ||
| 162 | pr_err("Unable to find vport\n"); | ||
| 163 | return -EINVAL; | ||
| 164 | } | ||
| 165 | |||
| 166 | efct = lio_vport->efct; | ||
| 167 | efc = efct->efcport; | ||
| 168 | |||
| 169 | if (op == 1) { | ||
| 170 | tpg->enabled = true; | ||
| 171 | efc_log_debug(efct, "enable portal group %d\n", tpg->tpgt); | ||
| 172 | |||
| 173 | if (efc->domain) { | ||
| 174 | int ret; | ||
| 175 | |||
| 176 | ret = efc_nport_vport_new(efc->domain, | ||
| 177 | lio_vport->npiv_wwpn, | ||
| 178 | lio_vport->npiv_wwnn, | ||
| 179 | U32_MAX, false, true, | ||
| 180 | NULL, NULL); | ||
| 181 | if (ret != 0) { | ||
| 182 | efc_log_err(efct, "Failed to create Vport\n"); | ||
| 183 | return ret; | ||
| 184 | } | ||
| 185 | return count; | ||
| 186 | } | ||
| 187 | |||
| 188 | if (!(efc_vport_create_spec(efc, lio_vport->npiv_wwnn, | ||
| 189 | lio_vport->npiv_wwpn, U32_MAX, | ||
| 190 | false, true, NULL, NULL))) | ||
| 191 | return -ENOMEM; | ||
| 192 | |||
| 193 | } else if (op == 0) { | ||
| 194 | efc_log_debug(efct, "disable portal group %d\n", tpg->tpgt); | ||
| 195 | |||
| 196 | tpg->enabled = false; | ||
| 197 | /* only physical nport should exist, free lio_nport | ||
| 198 | * allocated in efct_lio_make_nport | ||
| 199 | */ | ||
| 200 | if (efc->domain) { | ||
| 201 | efc_nport_vport_del(efct->efcport, efc->domain, | ||
| 202 | lio_vport->npiv_wwpn, | ||
| 203 | lio_vport->npiv_wwnn); | ||
| 204 | return count; | ||
| 205 | } | ||
| 206 | } else { | ||
| 207 | return -EINVAL; | ||
| 208 | } | ||
| 209 | return count; | ||
| 210 | } | ||
| 211 | |||
| 212 | static char *efct_lio_get_fabric_wwn(struct se_portal_group *se_tpg) | ||
| 213 | { | ||
| 214 | struct efct_lio_tpg *tpg = | ||
| 215 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 216 | |||
| 217 | return tpg->nport->wwpn_str; | ||
| 218 | } | ||
| 219 | |||
| 220 | static char *efct_lio_get_npiv_fabric_wwn(struct se_portal_group *se_tpg) | ||
| 221 | { | ||
| 222 | struct efct_lio_tpg *tpg = | ||
| 223 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 224 | |||
| 225 | return tpg->vport->wwpn_str; | ||
| 226 | } | ||
| 227 | |||
| 228 | static u16 efct_lio_get_tag(struct se_portal_group *se_tpg) | ||
| 229 | { | ||
| 230 | struct efct_lio_tpg *tpg = | ||
| 231 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 232 | |||
| 233 | return tpg->tpgt; | ||
| 234 | } | ||
| 235 | |||
| 236 | static u16 efct_lio_get_npiv_tag(struct se_portal_group *se_tpg) | ||
| 237 | { | ||
| 238 | struct efct_lio_tpg *tpg = | ||
| 239 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 240 | |||
| 241 | return tpg->tpgt; | ||
| 242 | } | ||
| 243 | |||
| 244 | static int efct_lio_check_demo_mode(struct se_portal_group *se_tpg) | ||
| 245 | { | ||
| 246 | return 1; | ||
| 247 | } | ||
| 248 | |||
| 249 | static int efct_lio_check_demo_mode_cache(struct se_portal_group *se_tpg) | ||
| 250 | { | ||
| 251 | return 1; | ||
| 252 | } | ||
| 253 | |||
| 254 | static int efct_lio_check_demo_write_protect(struct se_portal_group *se_tpg) | ||
| 255 | { | ||
| 256 | struct efct_lio_tpg *tpg = | ||
| 257 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 258 | |||
| 259 | return tpg->tpg_attrib.demo_mode_write_protect; | ||
| 260 | } | ||
| 261 | |||
| 262 | static int | ||
| 263 | efct_lio_npiv_check_demo_write_protect(struct se_portal_group *se_tpg) | ||
| 264 | { | ||
| 265 | struct efct_lio_tpg *tpg = | ||
| 266 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 267 | |||
| 268 | return tpg->tpg_attrib.demo_mode_write_protect; | ||
| 269 | } | ||
| 270 | |||
| 271 | static int efct_lio_check_prod_write_protect(struct se_portal_group *se_tpg) | ||
| 272 | { | ||
| 273 | struct efct_lio_tpg *tpg = | ||
| 274 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 275 | |||
| 276 | return tpg->tpg_attrib.prod_mode_write_protect; | ||
| 277 | } | ||
| 278 | |||
| 279 | static int | ||
| 280 | efct_lio_npiv_check_prod_write_protect(struct se_portal_group *se_tpg) | ||
| 281 | { | ||
| 282 | struct efct_lio_tpg *tpg = | ||
| 283 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 284 | |||
| 285 | return tpg->tpg_attrib.prod_mode_write_protect; | ||
| 286 | } | ||
| 287 | |||
| 288 | static u32 efct_lio_tpg_get_inst_index(struct se_portal_group *se_tpg) | ||
| 289 | { | ||
| 290 | return 1; | ||
| 291 | } | ||
| 292 | |||
| 293 | static int efct_lio_check_stop_free(struct se_cmd *se_cmd) | ||
| 294 | { | ||
| 295 | struct efct_scsi_tgt_io *ocp = | ||
| 296 | container_of(se_cmd, struct efct_scsi_tgt_io, cmd); | ||
| 297 | struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); | ||
| 298 | |||
| 299 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_CHK_STOP_FREE); | ||
| 300 | return target_put_sess_cmd(se_cmd); | ||
| 301 | } | ||
| 302 | |||
| 303 | static int | ||
| 304 | efct_lio_abort_tgt_cb(struct efct_io *io, | ||
| 305 | enum efct_scsi_io_status scsi_status, | ||
| 306 | u32 flags, void *arg) | ||
| 307 | { | ||
| 308 | efct_lio_io_printf(io, "Abort done, status:%d\n", scsi_status); | ||
| 309 | return 0; | ||
| 310 | } | ||
| 311 | |||
| 312 | static void | ||
| 313 | efct_lio_aborted_task(struct se_cmd *se_cmd) | ||
| 314 | { | ||
| 315 | struct efct_scsi_tgt_io *ocp = | ||
| 316 | container_of(se_cmd, struct efct_scsi_tgt_io, cmd); | ||
| 317 | struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); | ||
| 318 | |||
| 319 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_ABORTED_TASK); | ||
| 320 | |||
| 321 | if (ocp->rsp_sent) | ||
| 322 | return; | ||
| 323 | |||
| 324 | /* command has been aborted, cleanup here */ | ||
| 325 | ocp->aborting = true; | ||
| 326 | ocp->err = EFCT_SCSI_STATUS_ABORTED; | ||
| 327 | /* terminate the exchange */ | ||
| 328 | efct_scsi_tgt_abort_io(io, efct_lio_abort_tgt_cb, NULL); | ||
| 329 | } | ||
| 330 | |||
| 331 | static void efct_lio_release_cmd(struct se_cmd *se_cmd) | ||
| 332 | { | ||
| 333 | struct efct_scsi_tgt_io *ocp = | ||
| 334 | container_of(se_cmd, struct efct_scsi_tgt_io, cmd); | ||
| 335 | struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); | ||
| 336 | struct efct *efct = io->efct; | ||
| 337 | |||
| 338 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_RELEASE_CMD); | ||
| 339 | efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_CMPL_CMD); | ||
| 340 | efct_scsi_io_complete(io); | ||
| 341 | atomic_sub_return(1, &efct->tgt_efct.ios_in_use); | ||
| 342 | } | ||
| 343 | |||
| 344 | static void efct_lio_close_session(struct se_session *se_sess) | ||
| 345 | { | ||
| 346 | struct efc_node *node = se_sess->fabric_sess_ptr; | ||
| 347 | |||
| 348 | pr_debug("se_sess=%p node=%p", se_sess, node); | ||
| 349 | |||
| 350 | if (!node) { | ||
| 351 | pr_debug("node is NULL"); | ||
| 352 | return; | ||
| 353 | } | ||
| 354 | |||
| 355 | efc_node_post_shutdown(node, NULL); | ||
| 356 | } | ||
| 357 | |||
| 358 | static u32 efct_lio_sess_get_index(struct se_session *se_sess) | ||
| 359 | { | ||
| 360 | return 0; | ||
| 361 | } | ||
| 362 | |||
| 363 | static void efct_lio_set_default_node_attrs(struct se_node_acl *nacl) | ||
| 364 | { | ||
| 365 | } | ||
| 366 | |||
| 367 | static int efct_lio_get_cmd_state(struct se_cmd *cmd) | ||
| 368 | { | ||
| 369 | struct efct_scsi_tgt_io *ocp = | ||
| 370 | container_of(cmd, struct efct_scsi_tgt_io, cmd); | ||
| 371 | struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); | ||
| 372 | |||
| 373 | if (!io) | ||
| 374 | return 0; | ||
| 375 | |||
| 376 | return io->tgt_io.state; | ||
| 377 | } | ||
| 378 | |||
| 379 | static int | ||
| 380 | efct_lio_sg_map(struct efct_io *io) | ||
| 381 | { | ||
| 382 | struct efct_scsi_tgt_io *ocp = &io->tgt_io; | ||
| 383 | struct se_cmd *cmd = &ocp->cmd; | ||
| 384 | |||
| 385 | ocp->seg_map_cnt = pci_map_sg(io->efct->pci, cmd->t_data_sg, | ||
| 386 | cmd->t_data_nents, cmd->data_direction); | ||
| 387 | if (ocp->seg_map_cnt == 0) | ||
| 388 | return -EFAULT; | ||
| 389 | return 0; | ||
| 390 | } | ||
| 391 | |||
| 392 | static void | ||
| 393 | efct_lio_sg_unmap(struct efct_io *io) | ||
| 394 | { | ||
| 395 | struct efct_scsi_tgt_io *ocp = &io->tgt_io; | ||
| 396 | struct se_cmd *cmd = &ocp->cmd; | ||
| 397 | |||
| 398 | if (WARN_ON(!ocp->seg_map_cnt || !cmd->t_data_sg)) | ||
| 399 | return; | ||
| 400 | |||
| 401 | pci_unmap_sg(io->efct->pci, cmd->t_data_sg, | ||
| 402 | ocp->seg_map_cnt, cmd->data_direction); | ||
| 403 | ocp->seg_map_cnt = 0; | ||
| 404 | } | ||
| 405 | |||
| 406 | static int | ||
| 407 | efct_lio_status_done(struct efct_io *io, | ||
| 408 | enum efct_scsi_io_status scsi_status, | ||
| 409 | u32 flags, void *arg) | ||
| 410 | { | ||
| 411 | struct efct_scsi_tgt_io *ocp = &io->tgt_io; | ||
| 412 | |||
| 413 | efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_RSP_DONE); | ||
| 414 | if (scsi_status != EFCT_SCSI_STATUS_GOOD) { | ||
| 415 | efct_lio_io_printf(io, "callback completed with error=%d\n", | ||
| 416 | scsi_status); | ||
| 417 | ocp->err = scsi_status; | ||
| 418 | } | ||
| 419 | if (ocp->seg_map_cnt) | ||
| 420 | efct_lio_sg_unmap(io); | ||
| 421 | |||
| 422 | efct_lio_io_printf(io, "status=%d, err=%d flags=0x%x, dir=%d\n", | ||
| 423 | scsi_status, ocp->err, flags, ocp->ddir); | ||
| 424 | |||
| 425 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE); | ||
| 426 | transport_generic_free_cmd(&io->tgt_io.cmd, 0); | ||
| 427 | return 0; | ||
| 428 | } | ||
| 429 | |||
| 430 | static int | ||
| 431 | efct_lio_datamove_done(struct efct_io *io, enum efct_scsi_io_status scsi_status, | ||
| 432 | u32 flags, void *arg); | ||
| 433 | |||
| 434 | static int | ||
| 435 | efct_lio_write_pending(struct se_cmd *cmd) | ||
| 436 | { | ||
| 437 | struct efct_scsi_tgt_io *ocp = | ||
| 438 | container_of(cmd, struct efct_scsi_tgt_io, cmd); | ||
| 439 | struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); | ||
| 440 | struct efct_scsi_sgl *sgl = io->sgl; | ||
| 441 | struct scatterlist *sg; | ||
| 442 | u32 flags = 0, cnt, curcnt; | ||
| 443 | u64 length = 0; | ||
| 444 | |||
| 445 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_WRITE_PENDING); | ||
| 446 | efct_lio_io_printf(io, "trans_state=0x%x se_cmd_flags=0x%x\n", | ||
| 447 | cmd->transport_state, cmd->se_cmd_flags); | ||
| 448 | |||
| 449 | if (ocp->seg_cnt == 0) { | ||
| 450 | ocp->seg_cnt = cmd->t_data_nents; | ||
| 451 | ocp->cur_seg = 0; | ||
| 452 | if (efct_lio_sg_map(io)) { | ||
| 453 | efct_lio_io_printf(io, "efct_lio_sg_map failed\n"); | ||
| 454 | return -EFAULT; | ||
| 455 | } | ||
| 456 | } | ||
| 457 | curcnt = (ocp->seg_map_cnt - ocp->cur_seg); | ||
| 458 | curcnt = (curcnt < io->sgl_allocated) ? curcnt : io->sgl_allocated; | ||
| 459 | /* find current sg */ | ||
| 460 | for (cnt = 0, sg = cmd->t_data_sg; cnt < ocp->cur_seg; cnt++, | ||
| 461 | sg = sg_next(sg)) | ||
| 462 | ;/* do nothing */ | ||
| 463 | |||
| 464 | for (cnt = 0; cnt < curcnt; cnt++, sg = sg_next(sg)) { | ||
| 465 | sgl[cnt].addr = sg_dma_address(sg); | ||
| 466 | sgl[cnt].dif_addr = 0; | ||
| 467 | sgl[cnt].len = sg_dma_len(sg); | ||
| 468 | length += sgl[cnt].len; | ||
| 469 | ocp->cur_seg++; | ||
| 470 | } | ||
| 471 | |||
| 472 | if (ocp->cur_seg == ocp->seg_cnt) | ||
| 473 | flags = EFCT_SCSI_LAST_DATAPHASE; | ||
| 474 | |||
| 475 | return efct_scsi_recv_wr_data(io, flags, sgl, curcnt, length, | ||
| 476 | efct_lio_datamove_done, NULL); | ||
| 477 | } | ||
| 478 | |||
| 479 | static int | ||
| 480 | efct_lio_queue_data_in(struct se_cmd *cmd) | ||
| 481 | { | ||
| 482 | struct efct_scsi_tgt_io *ocp = | ||
| 483 | container_of(cmd, struct efct_scsi_tgt_io, cmd); | ||
| 484 | struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); | ||
| 485 | struct efct_scsi_sgl *sgl = io->sgl; | ||
| 486 | struct scatterlist *sg = NULL; | ||
| 487 | uint flags = 0, cnt = 0, curcnt = 0; | ||
| 488 | u64 length = 0; | ||
| 489 | |||
| 490 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_QUEUE_DATA_IN); | ||
| 491 | |||
| 492 | if (ocp->seg_cnt == 0) { | ||
| 493 | if (cmd->data_length) { | ||
| 494 | ocp->seg_cnt = cmd->t_data_nents; | ||
| 495 | ocp->cur_seg = 0; | ||
| 496 | if (efct_lio_sg_map(io)) { | ||
| 497 | efct_lio_io_printf(io, | ||
| 498 | "efct_lio_sg_map failed\n"); | ||
| 499 | return -EAGAIN; | ||
| 500 | } | ||
| 501 | } else { | ||
| 502 | /* If command length is 0, send the response status */ | ||
| 503 | struct efct_scsi_cmd_resp rsp; | ||
| 504 | |||
| 505 | memset(&rsp, 0, sizeof(rsp)); | ||
| 506 | efct_lio_io_printf(io, | ||
| 507 | "cmd : %p length 0, send status\n", | ||
| 508 | cmd); | ||
| 509 | return efct_scsi_send_resp(io, 0, &rsp, | ||
| 510 | efct_lio_status_done, NULL); | ||
| 511 | } | ||
| 512 | } | ||
| 513 | curcnt = min(ocp->seg_map_cnt - ocp->cur_seg, io->sgl_allocated); | ||
| 514 | |||
| 515 | while (cnt < curcnt) { | ||
| 516 | sg = &cmd->t_data_sg[ocp->cur_seg]; | ||
| 517 | sgl[cnt].addr = sg_dma_address(sg); | ||
| 518 | sgl[cnt].dif_addr = 0; | ||
| 519 | if (ocp->transferred_len + sg_dma_len(sg) >= cmd->data_length) | ||
| 520 | sgl[cnt].len = cmd->data_length - ocp->transferred_len; | ||
| 521 | else | ||
| 522 | sgl[cnt].len = sg_dma_len(sg); | ||
| 523 | |||
| 524 | ocp->transferred_len += sgl[cnt].len; | ||
| 525 | length += sgl[cnt].len; | ||
| 526 | ocp->cur_seg++; | ||
| 527 | cnt++; | ||
| 528 | if (ocp->transferred_len == cmd->data_length) | ||
| 529 | break; | ||
| 530 | } | ||
| 531 | |||
| 532 | if (ocp->transferred_len == cmd->data_length) { | ||
| 533 | flags = EFCT_SCSI_LAST_DATAPHASE; | ||
| 534 | ocp->seg_cnt = ocp->cur_seg; | ||
| 535 | } | ||
| 536 | |||
| 537 | /* If there is residual, disable Auto Good Response */ | ||
| 538 | if (cmd->residual_count) | ||
| 539 | flags |= EFCT_SCSI_NO_AUTO_RESPONSE; | ||
| 540 | |||
| 541 | efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_SEND_RD_DATA); | ||
| 542 | |||
| 543 | return efct_scsi_send_rd_data(io, flags, sgl, curcnt, length, | ||
| 544 | efct_lio_datamove_done, NULL); | ||
| 545 | } | ||
| 546 | |||
| 547 | static void | ||
| 548 | efct_lio_send_resp(struct efct_io *io, enum efct_scsi_io_status scsi_status, | ||
| 549 | u32 flags) | ||
| 550 | { | ||
| 551 | struct efct_scsi_cmd_resp rsp; | ||
| 552 | struct efct_scsi_tgt_io *ocp = &io->tgt_io; | ||
| 553 | struct se_cmd *cmd = &io->tgt_io.cmd; | ||
| 554 | int rc; | ||
| 555 | |||
| 556 | if (flags & EFCT_SCSI_IO_CMPL_RSP_SENT) { | ||
| 557 | ocp->rsp_sent = true; | ||
| 558 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE); | ||
| 559 | transport_generic_free_cmd(&io->tgt_io.cmd, 0); | ||
| 560 | return; | ||
| 561 | } | ||
| 562 | |||
| 563 | /* send check condition if an error occurred */ | ||
| 564 | memset(&rsp, 0, sizeof(rsp)); | ||
| 565 | rsp.scsi_status = cmd->scsi_status; | ||
| 566 | rsp.sense_data = (uint8_t *)io->tgt_io.sense_buffer; | ||
| 567 | rsp.sense_data_length = cmd->scsi_sense_length; | ||
| 568 | |||
| 569 | /* Check for residual underrun or overrun */ | ||
| 570 | if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) | ||
| 571 | rsp.residual = -cmd->residual_count; | ||
| 572 | else if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) | ||
| 573 | rsp.residual = cmd->residual_count; | ||
| 574 | |||
| 575 | rc = efct_scsi_send_resp(io, 0, &rsp, efct_lio_status_done, NULL); | ||
| 576 | efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_SEND_RSP); | ||
| 577 | if (rc != 0) { | ||
| 578 | efct_lio_io_printf(io, "Read done, send rsp failed %d\n", rc); | ||
| 579 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE); | ||
| 580 | transport_generic_free_cmd(&io->tgt_io.cmd, 0); | ||
| 581 | } else { | ||
| 582 | ocp->rsp_sent = true; | ||
| 583 | } | ||
| 584 | } | ||
| 585 | |||
| 586 | static int | ||
| 587 | efct_lio_datamove_done(struct efct_io *io, enum efct_scsi_io_status scsi_status, | ||
| 588 | u32 flags, void *arg) | ||
| 589 | { | ||
| 590 | struct efct_scsi_tgt_io *ocp = &io->tgt_io; | ||
| 591 | |||
| 592 | efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_DATA_DONE); | ||
| 593 | if (scsi_status != EFCT_SCSI_STATUS_GOOD) { | ||
| 594 | efct_lio_io_printf(io, "callback completed with error=%d\n", | ||
| 595 | scsi_status); | ||
| 596 | ocp->err = scsi_status; | ||
| 597 | } | ||
| 598 | efct_lio_io_printf(io, "seg_map_cnt=%d\n", ocp->seg_map_cnt); | ||
| 599 | if (ocp->seg_map_cnt) { | ||
| 600 | if (ocp->err == EFCT_SCSI_STATUS_GOOD && | ||
| 601 | ocp->cur_seg < ocp->seg_cnt) { | ||
| 602 | int rc; | ||
| 603 | |||
| 604 | efct_lio_io_printf(io, "continuing cmd at segm=%d\n", | ||
| 605 | ocp->cur_seg); | ||
| 606 | if (ocp->ddir == DMA_TO_DEVICE) | ||
| 607 | rc = efct_lio_write_pending(&ocp->cmd); | ||
| 608 | else | ||
| 609 | rc = efct_lio_queue_data_in(&ocp->cmd); | ||
| 610 | if (!rc) | ||
| 611 | return 0; | ||
| 612 | |||
| 613 | ocp->err = EFCT_SCSI_STATUS_ERROR; | ||
| 614 | efct_lio_io_printf(io, "could not continue command\n"); | ||
| 615 | } | ||
| 616 | efct_lio_sg_unmap(io); | ||
| 617 | } | ||
| 618 | |||
| 619 | if (io->tgt_io.aborting) { | ||
| 620 | efct_lio_io_printf(io, "IO done aborted\n"); | ||
| 621 | return 0; | ||
| 622 | } | ||
| 623 | |||
| 624 | if (ocp->ddir == DMA_TO_DEVICE) { | ||
| 625 | efct_lio_io_printf(io, "Write done, trans_state=0x%x\n", | ||
| 626 | io->tgt_io.cmd.transport_state); | ||
| 627 | if (scsi_status != EFCT_SCSI_STATUS_GOOD) { | ||
| 628 | transport_generic_request_failure(&io->tgt_io.cmd, | ||
| 629 | TCM_CHECK_CONDITION_ABORT_CMD); | ||
| 630 | efct_set_lio_io_state(io, | ||
| 631 | EFCT_LIO_STATE_TGT_GENERIC_REQ_FAILURE); | ||
| 632 | } else { | ||
| 633 | efct_set_lio_io_state(io, | ||
| 634 | EFCT_LIO_STATE_TGT_EXECUTE_CMD); | ||
| 635 | target_execute_cmd(&io->tgt_io.cmd); | ||
| 636 | } | ||
| 637 | } else { | ||
| 638 | efct_lio_send_resp(io, scsi_status, flags); | ||
| 639 | } | ||
| 640 | return 0; | ||
| 641 | } | ||
| 642 | |||
| 643 | static int | ||
| 644 | efct_lio_tmf_done(struct efct_io *io, enum efct_scsi_io_status scsi_status, | ||
| 645 | u32 flags, void *arg) | ||
| 646 | { | ||
| 647 | efct_lio_tmfio_printf(io, "cmd=%p status=%d, flags=0x%x\n", | ||
| 648 | &io->tgt_io.cmd, scsi_status, flags); | ||
| 649 | |||
| 650 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_GENERIC_FREE); | ||
| 651 | transport_generic_free_cmd(&io->tgt_io.cmd, 0); | ||
| 652 | return 0; | ||
| 653 | } | ||
| 654 | |||
| 655 | static int | ||
| 656 | efct_lio_null_tmf_done(struct efct_io *tmfio, | ||
| 657 | enum efct_scsi_io_status scsi_status, | ||
| 658 | u32 flags, void *arg) | ||
| 659 | { | ||
| 660 | efct_lio_tmfio_printf(tmfio, "cmd=%p status=%d, flags=0x%x\n", | ||
| 661 | &tmfio->tgt_io.cmd, scsi_status, flags); | ||
| 662 | |||
| 663 | /* free struct efct_io only, no active se_cmd */ | ||
| 664 | efct_scsi_io_complete(tmfio); | ||
| 665 | return 0; | ||
| 666 | } | ||
| 667 | |||
| 668 | static int | ||
| 669 | efct_lio_queue_status(struct se_cmd *cmd) | ||
| 670 | { | ||
| 671 | struct efct_scsi_cmd_resp rsp; | ||
| 672 | struct efct_scsi_tgt_io *ocp = | ||
| 673 | container_of(cmd, struct efct_scsi_tgt_io, cmd); | ||
| 674 | struct efct_io *io = container_of(ocp, struct efct_io, tgt_io); | ||
| 675 | int rc = 0; | ||
| 676 | |||
| 677 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TFO_QUEUE_STATUS); | ||
| 678 | efct_lio_io_printf(io, | ||
| 679 | "status=0x%x trans_state=0x%x se_cmd_flags=0x%x sns_len=%d\n", | ||
| 680 | cmd->scsi_status, cmd->transport_state, cmd->se_cmd_flags, | ||
| 681 | cmd->scsi_sense_length); | ||
| 682 | |||
| 683 | memset(&rsp, 0, sizeof(rsp)); | ||
| 684 | rsp.scsi_status = cmd->scsi_status; | ||
| 685 | rsp.sense_data = (u8 *)io->tgt_io.sense_buffer; | ||
| 686 | rsp.sense_data_length = cmd->scsi_sense_length; | ||
| 687 | |||
| 688 | /* Check for residual underrun or overrun, mark negitive value for | ||
| 689 | * underrun to recognize in HW | ||
| 690 | */ | ||
| 691 | if (cmd->se_cmd_flags & SCF_OVERFLOW_BIT) | ||
| 692 | rsp.residual = -cmd->residual_count; | ||
| 693 | else if (cmd->se_cmd_flags & SCF_UNDERFLOW_BIT) | ||
| 694 | rsp.residual = cmd->residual_count; | ||
| 695 | |||
| 696 | rc = efct_scsi_send_resp(io, 0, &rsp, efct_lio_status_done, NULL); | ||
| 697 | efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_SEND_RSP); | ||
| 698 | if (rc == 0) | ||
| 699 | ocp->rsp_sent = true; | ||
| 700 | return rc; | ||
| 701 | } | ||
| 702 | |||
| 703 | static void efct_lio_queue_tm_rsp(struct se_cmd *cmd) | ||
| 704 | { | ||
| 705 | struct efct_scsi_tgt_io *ocp = | ||
| 706 | container_of(cmd, struct efct_scsi_tgt_io, cmd); | ||
| 707 | struct efct_io *tmfio = container_of(ocp, struct efct_io, tgt_io); | ||
| 708 | struct se_tmr_req *se_tmr = cmd->se_tmr_req; | ||
| 709 | u8 rspcode; | ||
| 710 | |||
| 711 | efct_lio_tmfio_printf(tmfio, "cmd=%p function=0x%x tmr->response=%d\n", | ||
| 712 | cmd, se_tmr->function, se_tmr->response); | ||
| 713 | switch (se_tmr->response) { | ||
| 714 | case TMR_FUNCTION_COMPLETE: | ||
| 715 | rspcode = EFCT_SCSI_TMF_FUNCTION_COMPLETE; | ||
| 716 | break; | ||
| 717 | case TMR_TASK_DOES_NOT_EXIST: | ||
| 718 | rspcode = EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND; | ||
| 719 | break; | ||
| 720 | case TMR_LUN_DOES_NOT_EXIST: | ||
| 721 | rspcode = EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER; | ||
| 722 | break; | ||
| 723 | case TMR_FUNCTION_REJECTED: | ||
| 724 | default: | ||
| 725 | rspcode = EFCT_SCSI_TMF_FUNCTION_REJECTED; | ||
| 726 | break; | ||
| 727 | } | ||
| 728 | efct_scsi_send_tmf_resp(tmfio, rspcode, NULL, efct_lio_tmf_done, NULL); | ||
| 729 | } | ||
| 730 | |||
| 731 | static struct efct *efct_find_wwpn(u64 wwpn) | ||
| 732 | { | ||
| 733 | struct efct *efct; | ||
| 734 | |||
| 735 | /* Search for the HBA that has this WWPN */ | ||
| 736 | list_for_each_entry(efct, &efct_devices, list_entry) { | ||
| 737 | |||
| 738 | if (wwpn == efct_get_wwpn(&efct->hw)) | ||
| 739 | return efct; | ||
| 740 | } | ||
| 741 | |||
| 742 | return NULL; | ||
| 743 | } | ||
| 744 | |||
| 745 | static struct se_wwn * | ||
| 746 | efct_lio_make_nport(struct target_fabric_configfs *tf, | ||
| 747 | struct config_group *group, const char *name) | ||
| 748 | { | ||
| 749 | struct efct_lio_nport *lio_nport; | ||
| 750 | struct efct *efct; | ||
| 751 | int ret; | ||
| 752 | u64 wwpn; | ||
| 753 | |||
| 754 | ret = efct_lio_parse_wwn(name, &wwpn, 0); | ||
| 755 | if (ret) | ||
| 756 | return ERR_PTR(ret); | ||
| 757 | |||
| 758 | efct = efct_find_wwpn(wwpn); | ||
| 759 | if (!efct) { | ||
| 760 | pr_err("cannot find EFCT for base wwpn %s\n", name); | ||
| 761 | return ERR_PTR(-ENXIO); | ||
| 762 | } | ||
| 763 | |||
| 764 | lio_nport = kzalloc(sizeof(*lio_nport), GFP_KERNEL); | ||
| 765 | if (!lio_nport) | ||
| 766 | return ERR_PTR(-ENOMEM); | ||
| 767 | |||
| 768 | lio_nport->efct = efct; | ||
| 769 | lio_nport->wwpn = wwpn; | ||
| 770 | efct_format_wwn(lio_nport->wwpn_str, sizeof(lio_nport->wwpn_str), | ||
| 771 | "naa.", wwpn); | ||
| 772 | efct->tgt_efct.lio_nport = lio_nport; | ||
| 773 | |||
| 774 | return &lio_nport->nport_wwn; | ||
| 775 | } | ||
| 776 | |||
| 777 | static struct se_wwn * | ||
| 778 | efct_lio_npiv_make_nport(struct target_fabric_configfs *tf, | ||
| 779 | struct config_group *group, const char *name) | ||
| 780 | { | ||
| 781 | struct efct_lio_vport *lio_vport; | ||
| 782 | struct efct *efct; | ||
| 783 | int ret = -1; | ||
| 784 | u64 p_wwpn, npiv_wwpn, npiv_wwnn; | ||
| 785 | char *p, *pbuf, tmp[128]; | ||
| 786 | struct efct_lio_vport_list_t *vport_list; | ||
| 787 | struct fc_vport *new_fc_vport; | ||
| 788 | struct fc_vport_identifiers vport_id; | ||
| 789 | unsigned long flags = 0; | ||
| 790 | |||
| 791 | snprintf(tmp, sizeof(tmp), "%s", name); | ||
| 792 | pbuf = &tmp[0]; | ||
| 793 | |||
| 794 | p = strsep(&pbuf, "@"); | ||
| 795 | |||
| 796 | if (!p || !pbuf) { | ||
| 797 | pr_err("Unable to find separator operator(@)\n"); | ||
| 798 | return ERR_PTR(-EINVAL); | ||
| 799 | } | ||
| 800 | |||
| 801 | ret = efct_lio_parse_wwn(p, &p_wwpn, 0); | ||
| 802 | if (ret) | ||
| 803 | return ERR_PTR(ret); | ||
| 804 | |||
| 805 | ret = efct_lio_parse_npiv_wwn(pbuf, strlen(pbuf), &npiv_wwpn, | ||
| 806 | &npiv_wwnn); | ||
| 807 | if (ret) | ||
| 808 | return ERR_PTR(ret); | ||
| 809 | |||
| 810 | efct = efct_find_wwpn(p_wwpn); | ||
| 811 | if (!efct) { | ||
| 812 | pr_err("cannot find EFCT for base wwpn %s\n", name); | ||
| 813 | return ERR_PTR(-ENXIO); | ||
| 814 | } | ||
| 815 | |||
| 816 | lio_vport = kzalloc(sizeof(*lio_vport), GFP_KERNEL); | ||
| 817 | if (!lio_vport) | ||
| 818 | return ERR_PTR(-ENOMEM); | ||
| 819 | |||
| 820 | lio_vport->efct = efct; | ||
| 821 | lio_vport->wwpn = p_wwpn; | ||
| 822 | lio_vport->npiv_wwpn = npiv_wwpn; | ||
| 823 | lio_vport->npiv_wwnn = npiv_wwnn; | ||
| 824 | |||
| 825 | efct_format_wwn(lio_vport->wwpn_str, sizeof(lio_vport->wwpn_str), | ||
| 826 | "naa.", npiv_wwpn); | ||
| 827 | |||
| 828 | vport_list = kzalloc(sizeof(*vport_list), GFP_KERNEL); | ||
| 829 | if (!vport_list) { | ||
| 830 | kfree(lio_vport); | ||
| 831 | return ERR_PTR(-ENOMEM); | ||
| 832 | } | ||
| 833 | |||
| 834 | vport_list->lio_vport = lio_vport; | ||
| 835 | spin_lock_irqsave(&efct->tgt_efct.efct_lio_lock, flags); | ||
| 836 | INIT_LIST_HEAD(&vport_list->list_entry); | ||
| 837 | list_add_tail(&vport_list->list_entry, &efct->tgt_efct.vport_list); | ||
| 838 | spin_unlock_irqrestore(&efct->tgt_efct.efct_lio_lock, flags); | ||
| 839 | |||
| 840 | memset(&vport_id, 0, sizeof(vport_id)); | ||
| 841 | vport_id.port_name = npiv_wwpn; | ||
| 842 | vport_id.node_name = npiv_wwnn; | ||
| 843 | vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR; | ||
| 844 | vport_id.vport_type = FC_PORTTYPE_NPIV; | ||
| 845 | vport_id.disable = false; | ||
| 846 | |||
| 847 | new_fc_vport = fc_vport_create(efct->shost, 0, &vport_id); | ||
| 848 | if (!new_fc_vport) { | ||
| 849 | efc_log_err(efct, "fc_vport_create failed\n"); | ||
| 850 | kfree(lio_vport); | ||
| 851 | kfree(vport_list); | ||
| 852 | return ERR_PTR(-ENOMEM); | ||
| 853 | } | ||
| 854 | |||
| 855 | lio_vport->fc_vport = new_fc_vport; | ||
| 856 | |||
| 857 | return &lio_vport->vport_wwn; | ||
| 858 | } | ||
| 859 | |||
| 860 | static void | ||
| 861 | efct_lio_drop_nport(struct se_wwn *wwn) | ||
| 862 | { | ||
| 863 | struct efct_lio_nport *lio_nport = | ||
| 864 | container_of(wwn, struct efct_lio_nport, nport_wwn); | ||
| 865 | struct efct *efct = lio_nport->efct; | ||
| 866 | |||
| 867 | /* only physical nport should exist, free lio_nport allocated | ||
| 868 | * in efct_lio_make_nport. | ||
| 869 | */ | ||
| 870 | kfree(efct->tgt_efct.lio_nport); | ||
| 871 | efct->tgt_efct.lio_nport = NULL; | ||
| 872 | } | ||
| 873 | |||
| 874 | static void | ||
| 875 | efct_lio_npiv_drop_nport(struct se_wwn *wwn) | ||
| 876 | { | ||
| 877 | struct efct_lio_vport *lio_vport = | ||
| 878 | container_of(wwn, struct efct_lio_vport, vport_wwn); | ||
| 879 | struct efct_lio_vport_list_t *vport, *next_vport; | ||
| 880 | struct efct *efct = lio_vport->efct; | ||
| 881 | unsigned long flags = 0; | ||
| 882 | |||
| 883 | spin_lock_irqsave(&efct->tgt_efct.efct_lio_lock, flags); | ||
| 884 | |||
| 885 | if (lio_vport->fc_vport) | ||
| 886 | fc_vport_terminate(lio_vport->fc_vport); | ||
| 887 | |||
| 888 | list_for_each_entry_safe(vport, next_vport, &efct->tgt_efct.vport_list, | ||
| 889 | list_entry) { | ||
| 890 | if (vport->lio_vport == lio_vport) { | ||
| 891 | list_del(&vport->list_entry); | ||
| 892 | kfree(vport->lio_vport); | ||
| 893 | kfree(vport); | ||
| 894 | break; | ||
| 895 | } | ||
| 896 | } | ||
| 897 | spin_unlock_irqrestore(&efct->tgt_efct.efct_lio_lock, flags); | ||
| 898 | } | ||
| 899 | |||
| 900 | static struct se_portal_group * | ||
| 901 | efct_lio_make_tpg(struct se_wwn *wwn, const char *name) | ||
| 902 | { | ||
| 903 | struct efct_lio_nport *lio_nport = | ||
| 904 | container_of(wwn, struct efct_lio_nport, nport_wwn); | ||
| 905 | struct efct_lio_tpg *tpg; | ||
| 906 | struct efct *efct; | ||
| 907 | unsigned long n; | ||
| 908 | int ret; | ||
| 909 | |||
| 910 | if (strstr(name, "tpgt_") != name) | ||
| 911 | return ERR_PTR(-EINVAL); | ||
| 912 | if (kstrtoul(name + 5, 10, &n) || n > USHRT_MAX) | ||
| 913 | return ERR_PTR(-EINVAL); | ||
| 914 | |||
| 915 | tpg = kzalloc(sizeof(*tpg), GFP_KERNEL); | ||
| 916 | if (!tpg) | ||
| 917 | return ERR_PTR(-ENOMEM); | ||
| 918 | |||
| 919 | tpg->nport = lio_nport; | ||
| 920 | tpg->tpgt = n; | ||
| 921 | tpg->enabled = false; | ||
| 922 | |||
| 923 | tpg->tpg_attrib.generate_node_acls = 1; | ||
| 924 | tpg->tpg_attrib.demo_mode_write_protect = 1; | ||
| 925 | tpg->tpg_attrib.cache_dynamic_acls = 1; | ||
| 926 | tpg->tpg_attrib.demo_mode_login_only = 1; | ||
| 927 | tpg->tpg_attrib.session_deletion_wait = 1; | ||
| 928 | |||
| 929 | ret = core_tpg_register(wwn, &tpg->tpg, SCSI_PROTOCOL_FCP); | ||
| 930 | if (ret < 0) { | ||
| 931 | kfree(tpg); | ||
| 932 | return NULL; | ||
| 933 | } | ||
| 934 | efct = lio_nport->efct; | ||
| 935 | efct->tgt_efct.tpg = tpg; | ||
| 936 | efc_log_debug(efct, "create portal group %d\n", tpg->tpgt); | ||
| 937 | |||
| 938 | xa_init(&efct->lookup); | ||
| 939 | return &tpg->tpg; | ||
| 940 | } | ||
| 941 | |||
| 942 | static void | ||
| 943 | efct_lio_drop_tpg(struct se_portal_group *se_tpg) | ||
| 944 | { | ||
| 945 | struct efct_lio_tpg *tpg = | ||
| 946 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 947 | |||
| 948 | struct efct *efct = tpg->nport->efct; | ||
| 949 | |||
| 950 | efc_log_debug(efct, "drop portal group %d\n", tpg->tpgt); | ||
| 951 | tpg->nport->efct->tgt_efct.tpg = NULL; | ||
| 952 | core_tpg_deregister(se_tpg); | ||
| 953 | xa_destroy(&efct->lookup); | ||
| 954 | kfree(tpg); | ||
| 955 | } | ||
| 956 | |||
| 957 | static struct se_portal_group * | ||
| 958 | efct_lio_npiv_make_tpg(struct se_wwn *wwn, const char *name) | ||
| 959 | { | ||
| 960 | struct efct_lio_vport *lio_vport = | ||
| 961 | container_of(wwn, struct efct_lio_vport, vport_wwn); | ||
| 962 | struct efct_lio_tpg *tpg; | ||
| 963 | struct efct *efct; | ||
| 964 | unsigned long n; | ||
| 965 | int ret; | ||
| 966 | |||
| 967 | efct = lio_vport->efct; | ||
| 968 | if (strstr(name, "tpgt_") != name) | ||
| 969 | return ERR_PTR(-EINVAL); | ||
| 970 | if (kstrtoul(name + 5, 10, &n) || n > USHRT_MAX) | ||
| 971 | return ERR_PTR(-EINVAL); | ||
| 972 | |||
| 973 | if (n != 1) { | ||
| 974 | efc_log_err(efct, "Invalid tpgt index: %ld provided\n", n); | ||
| 975 | return ERR_PTR(-EINVAL); | ||
| 976 | } | ||
| 977 | |||
| 978 | tpg = kzalloc(sizeof(*tpg), GFP_KERNEL); | ||
| 979 | if (!tpg) | ||
| 980 | return ERR_PTR(-ENOMEM); | ||
| 981 | |||
| 982 | tpg->vport = lio_vport; | ||
| 983 | tpg->tpgt = n; | ||
| 984 | tpg->enabled = false; | ||
| 985 | |||
| 986 | tpg->tpg_attrib.generate_node_acls = 1; | ||
| 987 | tpg->tpg_attrib.demo_mode_write_protect = 1; | ||
| 988 | tpg->tpg_attrib.cache_dynamic_acls = 1; | ||
| 989 | tpg->tpg_attrib.demo_mode_login_only = 1; | ||
| 990 | tpg->tpg_attrib.session_deletion_wait = 1; | ||
| 991 | |||
| 992 | ret = core_tpg_register(wwn, &tpg->tpg, SCSI_PROTOCOL_FCP); | ||
| 993 | |||
| 994 | if (ret < 0) { | ||
| 995 | kfree(tpg); | ||
| 996 | return NULL; | ||
| 997 | } | ||
| 998 | lio_vport->tpg = tpg; | ||
| 999 | efc_log_debug(efct, "create vport portal group %d\n", tpg->tpgt); | ||
| 1000 | |||
| 1001 | return &tpg->tpg; | ||
| 1002 | } | ||
| 1003 | |||
| 1004 | static void | ||
| 1005 | efct_lio_npiv_drop_tpg(struct se_portal_group *se_tpg) | ||
| 1006 | { | ||
| 1007 | struct efct_lio_tpg *tpg = | ||
| 1008 | container_of(se_tpg, struct efct_lio_tpg, tpg); | ||
| 1009 | |||
| 1010 | efc_log_debug(tpg->vport->efct, "drop npiv portal group %d\n", | ||
| 1011 | tpg->tpgt); | ||
| 1012 | core_tpg_deregister(se_tpg); | ||
| 1013 | kfree(tpg); | ||
| 1014 | } | ||
| 1015 | |||
| 1016 | static int | ||
| 1017 | efct_lio_init_nodeacl(struct se_node_acl *se_nacl, const char *name) | ||
| 1018 | { | ||
| 1019 | struct efct_lio_nacl *nacl; | ||
| 1020 | u64 wwnn; | ||
| 1021 | |||
| 1022 | if (efct_lio_parse_wwn(name, &wwnn, 0) < 0) | ||
| 1023 | return -EINVAL; | ||
| 1024 | |||
| 1025 | nacl = container_of(se_nacl, struct efct_lio_nacl, se_node_acl); | ||
| 1026 | nacl->nport_wwnn = wwnn; | ||
| 1027 | |||
| 1028 | efct_format_wwn(nacl->nport_name, sizeof(nacl->nport_name), "", wwnn); | ||
| 1029 | return 0; | ||
| 1030 | } | ||
| 1031 | |||
| 1032 | static int efct_lio_check_demo_mode_login_only(struct se_portal_group *stpg) | ||
| 1033 | { | ||
| 1034 | struct efct_lio_tpg *tpg = container_of(stpg, struct efct_lio_tpg, tpg); | ||
| 1035 | |||
| 1036 | return tpg->tpg_attrib.demo_mode_login_only; | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | static int | ||
| 1040 | efct_lio_npiv_check_demo_mode_login_only(struct se_portal_group *stpg) | ||
| 1041 | { | ||
| 1042 | struct efct_lio_tpg *tpg = container_of(stpg, struct efct_lio_tpg, tpg); | ||
| 1043 | |||
| 1044 | return tpg->tpg_attrib.demo_mode_login_only; | ||
| 1045 | } | ||
| 1046 | |||
| 1047 | static struct efct_lio_tpg * | ||
| 1048 | efct_get_vport_tpg(struct efc_node *node) | ||
| 1049 | { | ||
| 1050 | struct efct *efct; | ||
| 1051 | u64 wwpn = node->nport->wwpn; | ||
| 1052 | struct efct_lio_vport_list_t *vport, *next; | ||
| 1053 | struct efct_lio_vport *lio_vport = NULL; | ||
| 1054 | struct efct_lio_tpg *tpg = NULL; | ||
| 1055 | unsigned long flags = 0; | ||
| 1056 | |||
| 1057 | efct = node->efc->base; | ||
| 1058 | spin_lock_irqsave(&efct->tgt_efct.efct_lio_lock, flags); | ||
| 1059 | list_for_each_entry_safe(vport, next, &efct->tgt_efct.vport_list, | ||
| 1060 | list_entry) { | ||
| 1061 | lio_vport = vport->lio_vport; | ||
| 1062 | if (wwpn && lio_vport && lio_vport->npiv_wwpn == wwpn) { | ||
| 1063 | efc_log_debug(efct, "found tpg on vport\n"); | ||
| 1064 | tpg = lio_vport->tpg; | ||
| 1065 | break; | ||
| 1066 | } | ||
| 1067 | } | ||
| 1068 | spin_unlock_irqrestore(&efct->tgt_efct.efct_lio_lock, flags); | ||
| 1069 | return tpg; | ||
| 1070 | } | ||
| 1071 | |||
| 1072 | static void | ||
| 1073 | _efct_tgt_node_free(struct kref *arg) | ||
| 1074 | { | ||
| 1075 | struct efct_node *tgt_node = container_of(arg, struct efct_node, ref); | ||
| 1076 | struct efc_node *node = tgt_node->node; | ||
| 1077 | |||
| 1078 | efc_scsi_del_initiator_complete(node->efc, node); | ||
| 1079 | kfree(tgt_node); | ||
| 1080 | } | ||
| 1081 | |||
| 1082 | static int efct_session_cb(struct se_portal_group *se_tpg, | ||
| 1083 | struct se_session *se_sess, void *private) | ||
| 1084 | { | ||
| 1085 | struct efc_node *node = private; | ||
| 1086 | struct efct_node *tgt_node; | ||
| 1087 | struct efct *efct = node->efc->base; | ||
| 1088 | |||
| 1089 | tgt_node = kzalloc(sizeof(*tgt_node), GFP_KERNEL); | ||
| 1090 | if (!tgt_node) | ||
| 1091 | return -ENOMEM; | ||
| 1092 | |||
| 1093 | kref_init(&tgt_node->ref); | ||
| 1094 | tgt_node->release = _efct_tgt_node_free; | ||
| 1095 | |||
| 1096 | tgt_node->session = se_sess; | ||
| 1097 | node->tgt_node = tgt_node; | ||
| 1098 | tgt_node->efct = efct; | ||
| 1099 | |||
| 1100 | tgt_node->node = node; | ||
| 1101 | |||
| 1102 | tgt_node->node_fc_id = node->rnode.fc_id; | ||
| 1103 | tgt_node->port_fc_id = node->nport->fc_id; | ||
| 1104 | tgt_node->vpi = node->nport->indicator; | ||
| 1105 | tgt_node->rpi = node->rnode.indicator; | ||
| 1106 | |||
| 1107 | spin_lock_init(&tgt_node->active_ios_lock); | ||
| 1108 | INIT_LIST_HEAD(&tgt_node->active_ios); | ||
| 1109 | |||
| 1110 | return 0; | ||
| 1111 | } | ||
| 1112 | |||
| 1113 | int efct_scsi_tgt_new_device(struct efct *efct) | ||
| 1114 | { | ||
| 1115 | u32 total_ios; | ||
| 1116 | |||
| 1117 | /* Get the max settings */ | ||
| 1118 | efct->tgt_efct.max_sge = sli_get_max_sge(&efct->hw.sli); | ||
| 1119 | efct->tgt_efct.max_sgl = sli_get_max_sgl(&efct->hw.sli); | ||
| 1120 | |||
| 1121 | /* initialize IO watermark fields */ | ||
| 1122 | atomic_set(&efct->tgt_efct.ios_in_use, 0); | ||
| 1123 | total_ios = efct->hw.config.n_io; | ||
| 1124 | efc_log_debug(efct, "total_ios=%d\n", total_ios); | ||
| 1125 | efct->tgt_efct.watermark_min = | ||
| 1126 | (total_ios * EFCT_WATERMARK_LOW_PCT) / 100; | ||
| 1127 | efct->tgt_efct.watermark_max = | ||
| 1128 | (total_ios * EFCT_WATERMARK_HIGH_PCT) / 100; | ||
| 1129 | atomic_set(&efct->tgt_efct.io_high_watermark, | ||
| 1130 | efct->tgt_efct.watermark_max); | ||
| 1131 | atomic_set(&efct->tgt_efct.watermark_hit, 0); | ||
| 1132 | atomic_set(&efct->tgt_efct.initiator_count, 0); | ||
| 1133 | |||
| 1134 | lio_wq = create_singlethread_workqueue("efct_lio_worker"); | ||
| 1135 | if (!lio_wq) { | ||
| 1136 | efc_log_err(efct, "workqueue create failed\n"); | ||
| 1137 | return -EIO; | ||
| 1138 | } | ||
| 1139 | |||
| 1140 | spin_lock_init(&efct->tgt_efct.efct_lio_lock); | ||
| 1141 | INIT_LIST_HEAD(&efct->tgt_efct.vport_list); | ||
| 1142 | |||
| 1143 | return 0; | ||
| 1144 | } | ||
| 1145 | |||
| 1146 | int efct_scsi_tgt_del_device(struct efct *efct) | ||
| 1147 | { | ||
| 1148 | flush_workqueue(lio_wq); | ||
| 1149 | |||
| 1150 | return 0; | ||
| 1151 | } | ||
| 1152 | |||
| 1153 | int | ||
| 1154 | efct_scsi_tgt_new_nport(struct efc *efc, struct efc_nport *nport) | ||
| 1155 | { | ||
| 1156 | struct efct *efct = nport->efc->base; | ||
| 1157 | |||
| 1158 | efc_log_debug(efct, "New SPORT: %s bound to %s\n", nport->display_name, | ||
| 1159 | efct->tgt_efct.lio_nport->wwpn_str); | ||
| 1160 | |||
| 1161 | return 0; | ||
| 1162 | } | ||
| 1163 | |||
| 1164 | void | ||
| 1165 | efct_scsi_tgt_del_nport(struct efc *efc, struct efc_nport *nport) | ||
| 1166 | { | ||
| 1167 | efc_log_debug(efc, "Del SPORT: %s\n", nport->display_name); | ||
| 1168 | } | ||
| 1169 | |||
| 1170 | static void efct_lio_setup_session(struct work_struct *work) | ||
| 1171 | { | ||
| 1172 | struct efct_lio_wq_data *wq_data = | ||
| 1173 | container_of(work, struct efct_lio_wq_data, work); | ||
| 1174 | struct efct *efct = wq_data->efct; | ||
| 1175 | struct efc_node *node = wq_data->ptr; | ||
| 1176 | char wwpn[WWN_NAME_LEN]; | ||
| 1177 | struct efct_lio_tpg *tpg; | ||
| 1178 | struct efct_node *tgt_node; | ||
| 1179 | struct se_portal_group *se_tpg; | ||
| 1180 | struct se_session *se_sess; | ||
| 1181 | int watermark; | ||
| 1182 | int ini_count; | ||
| 1183 | u64 id; | ||
| 1184 | |||
| 1185 | /* Check to see if it's belongs to vport, | ||
| 1186 | * if not get physical port | ||
| 1187 | */ | ||
| 1188 | tpg = efct_get_vport_tpg(node); | ||
| 1189 | if (tpg) { | ||
| 1190 | se_tpg = &tpg->tpg; | ||
| 1191 | } else if (efct->tgt_efct.tpg) { | ||
| 1192 | tpg = efct->tgt_efct.tpg; | ||
| 1193 | se_tpg = &tpg->tpg; | ||
| 1194 | } else { | ||
| 1195 | efc_log_err(efct, "failed to init session\n"); | ||
| 1196 | return; | ||
| 1197 | } | ||
| 1198 | |||
| 1199 | /* | ||
| 1200 | * Format the FCP Initiator port_name into colon | ||
| 1201 | * separated values to match the format by our explicit | ||
| 1202 | * ConfigFS NodeACLs. | ||
| 1203 | */ | ||
| 1204 | efct_format_wwn(wwpn, sizeof(wwpn), "", efc_node_get_wwpn(node)); | ||
| 1205 | |||
| 1206 | se_sess = target_setup_session(se_tpg, 0, 0, TARGET_PROT_NORMAL, wwpn, | ||
| 1207 | node, efct_session_cb); | ||
| 1208 | if (IS_ERR(se_sess)) { | ||
| 1209 | efc_log_err(efct, "failed to setup session\n"); | ||
| 1210 | kfree(wq_data); | ||
| 1211 | efc_scsi_sess_reg_complete(node, -EIO); | ||
| 1212 | return; | ||
| 1213 | } | ||
| 1214 | |||
| 1215 | tgt_node = node->tgt_node; | ||
| 1216 | id = (u64) tgt_node->port_fc_id << 32 | tgt_node->node_fc_id; | ||
| 1217 | |||
| 1218 | efc_log_debug(efct, "new initiator sess=%p node=%p id: %llx\n", | ||
| 1219 | se_sess, node, id); | ||
| 1220 | |||
| 1221 | if (xa_err(xa_store(&efct->lookup, id, tgt_node, GFP_KERNEL))) | ||
| 1222 | efc_log_err(efct, "Node lookup store failed\n"); | ||
| 1223 | |||
| 1224 | efc_scsi_sess_reg_complete(node, 0); | ||
| 1225 | |||
| 1226 | /* update IO watermark: increment initiator count */ | ||
| 1227 | ini_count = atomic_add_return(1, &efct->tgt_efct.initiator_count); | ||
| 1228 | watermark = efct->tgt_efct.watermark_max - | ||
| 1229 | ini_count * EFCT_IO_WATERMARK_PER_INITIATOR; | ||
| 1230 | watermark = (efct->tgt_efct.watermark_min > watermark) ? | ||
| 1231 | efct->tgt_efct.watermark_min : watermark; | ||
| 1232 | atomic_set(&efct->tgt_efct.io_high_watermark, watermark); | ||
| 1233 | |||
| 1234 | kfree(wq_data); | ||
| 1235 | } | ||
| 1236 | |||
| 1237 | int efct_scsi_new_initiator(struct efc *efc, struct efc_node *node) | ||
| 1238 | { | ||
| 1239 | struct efct *efct = node->efc->base; | ||
| 1240 | struct efct_lio_wq_data *wq_data; | ||
| 1241 | |||
| 1242 | /* | ||
| 1243 | * Since LIO only supports initiator validation at thread level, | ||
| 1244 | * we are open minded and accept all callers. | ||
| 1245 | */ | ||
| 1246 | wq_data = kzalloc(sizeof(*wq_data), GFP_ATOMIC); | ||
| 1247 | if (!wq_data) | ||
| 1248 | return -ENOMEM; | ||
| 1249 | |||
| 1250 | wq_data->ptr = node; | ||
| 1251 | wq_data->efct = efct; | ||
| 1252 | INIT_WORK(&wq_data->work, efct_lio_setup_session); | ||
| 1253 | queue_work(lio_wq, &wq_data->work); | ||
| 1254 | return EFC_SCSI_CALL_ASYNC; | ||
| 1255 | } | ||
| 1256 | |||
| 1257 | static void efct_lio_remove_session(struct work_struct *work) | ||
| 1258 | { | ||
| 1259 | struct efct_lio_wq_data *wq_data = | ||
| 1260 | container_of(work, struct efct_lio_wq_data, work); | ||
| 1261 | struct efct *efct = wq_data->efct; | ||
| 1262 | struct efc_node *node = wq_data->ptr; | ||
| 1263 | struct efct_node *tgt_node; | ||
| 1264 | struct se_session *se_sess; | ||
| 1265 | |||
| 1266 | tgt_node = node->tgt_node; | ||
| 1267 | if (!tgt_node) { | ||
| 1268 | /* base driver has sent back-to-back requests | ||
| 1269 | * to unreg session with no intervening | ||
| 1270 | * register | ||
| 1271 | */ | ||
| 1272 | efc_log_err(efct, "unreg session for NULL session\n"); | ||
| 1273 | efc_scsi_del_initiator_complete(node->efc, node); | ||
| 1274 | return; | ||
| 1275 | } | ||
| 1276 | |||
| 1277 | se_sess = tgt_node->session; | ||
| 1278 | efc_log_debug(efct, "unreg session se_sess=%p node=%p\n", | ||
| 1279 | se_sess, node); | ||
| 1280 | |||
| 1281 | /* first flag all session commands to complete */ | ||
| 1282 | target_stop_session(se_sess); | ||
| 1283 | |||
| 1284 | /* now wait for session commands to complete */ | ||
| 1285 | target_wait_for_sess_cmds(se_sess); | ||
| 1286 | target_remove_session(se_sess); | ||
| 1287 | tgt_node->session = NULL; | ||
| 1288 | node->tgt_node = NULL; | ||
| 1289 | kref_put(&tgt_node->ref, tgt_node->release); | ||
| 1290 | |||
| 1291 | kfree(wq_data); | ||
| 1292 | } | ||
| 1293 | |||
| 1294 | int efct_scsi_del_initiator(struct efc *efc, struct efc_node *node, int reason) | ||
| 1295 | { | ||
| 1296 | struct efct *efct = node->efc->base; | ||
| 1297 | struct efct_node *tgt_node = node->tgt_node; | ||
| 1298 | struct efct_lio_wq_data *wq_data; | ||
| 1299 | int watermark; | ||
| 1300 | int ini_count; | ||
| 1301 | u64 id; | ||
| 1302 | |||
| 1303 | if (reason == EFCT_SCSI_INITIATOR_MISSING) | ||
| 1304 | return EFC_SCSI_CALL_COMPLETE; | ||
| 1305 | |||
| 1306 | if (!tgt_node) { | ||
| 1307 | efc_log_err(efct, "tgt_node is NULL\n"); | ||
| 1308 | return -EIO; | ||
| 1309 | } | ||
| 1310 | |||
| 1311 | wq_data = kzalloc(sizeof(*wq_data), GFP_ATOMIC); | ||
| 1312 | if (!wq_data) | ||
| 1313 | return -ENOMEM; | ||
| 1314 | |||
| 1315 | id = (u64) tgt_node->port_fc_id << 32 | tgt_node->node_fc_id; | ||
| 1316 | xa_erase(&efct->lookup, id); | ||
| 1317 | |||
| 1318 | wq_data->ptr = node; | ||
| 1319 | wq_data->efct = efct; | ||
| 1320 | INIT_WORK(&wq_data->work, efct_lio_remove_session); | ||
| 1321 | queue_work(lio_wq, &wq_data->work); | ||
| 1322 | |||
| 1323 | /* | ||
| 1324 | * update IO watermark: decrement initiator count | ||
| 1325 | */ | ||
| 1326 | ini_count = atomic_sub_return(1, &efct->tgt_efct.initiator_count); | ||
| 1327 | |||
| 1328 | watermark = efct->tgt_efct.watermark_max - | ||
| 1329 | ini_count * EFCT_IO_WATERMARK_PER_INITIATOR; | ||
| 1330 | watermark = (efct->tgt_efct.watermark_min > watermark) ? | ||
| 1331 | efct->tgt_efct.watermark_min : watermark; | ||
| 1332 | atomic_set(&efct->tgt_efct.io_high_watermark, watermark); | ||
| 1333 | |||
| 1334 | return EFC_SCSI_CALL_ASYNC; | ||
| 1335 | } | ||
| 1336 | |||
| 1337 | void efct_scsi_recv_cmd(struct efct_io *io, uint64_t lun, u8 *cdb, | ||
| 1338 | u32 cdb_len, u32 flags) | ||
| 1339 | { | ||
| 1340 | struct efct_scsi_tgt_io *ocp = &io->tgt_io; | ||
| 1341 | struct se_cmd *se_cmd = &io->tgt_io.cmd; | ||
| 1342 | struct efct *efct = io->efct; | ||
| 1343 | char *ddir; | ||
| 1344 | struct efct_node *tgt_node; | ||
| 1345 | struct se_session *se_sess; | ||
| 1346 | int rc = 0; | ||
| 1347 | |||
| 1348 | memset(ocp, 0, sizeof(struct efct_scsi_tgt_io)); | ||
| 1349 | efct_set_lio_io_state(io, EFCT_LIO_STATE_SCSI_RECV_CMD); | ||
| 1350 | atomic_add_return(1, &efct->tgt_efct.ios_in_use); | ||
| 1351 | |||
| 1352 | /* set target timeout */ | ||
| 1353 | io->timeout = efct->target_io_timer_sec; | ||
| 1354 | |||
| 1355 | if (flags & EFCT_SCSI_CMD_SIMPLE) | ||
| 1356 | ocp->task_attr = TCM_SIMPLE_TAG; | ||
| 1357 | else if (flags & EFCT_SCSI_CMD_HEAD_OF_QUEUE) | ||
| 1358 | ocp->task_attr = TCM_HEAD_TAG; | ||
| 1359 | else if (flags & EFCT_SCSI_CMD_ORDERED) | ||
| 1360 | ocp->task_attr = TCM_ORDERED_TAG; | ||
| 1361 | else if (flags & EFCT_SCSI_CMD_ACA) | ||
| 1362 | ocp->task_attr = TCM_ACA_TAG; | ||
| 1363 | |||
| 1364 | switch (flags & (EFCT_SCSI_CMD_DIR_IN | EFCT_SCSI_CMD_DIR_OUT)) { | ||
| 1365 | case EFCT_SCSI_CMD_DIR_IN: | ||
| 1366 | ddir = "FROM_INITIATOR"; | ||
| 1367 | ocp->ddir = DMA_TO_DEVICE; | ||
| 1368 | break; | ||
| 1369 | case EFCT_SCSI_CMD_DIR_OUT: | ||
| 1370 | ddir = "TO_INITIATOR"; | ||
| 1371 | ocp->ddir = DMA_FROM_DEVICE; | ||
| 1372 | break; | ||
| 1373 | case EFCT_SCSI_CMD_DIR_IN | EFCT_SCSI_CMD_DIR_OUT: | ||
| 1374 | ddir = "BIDIR"; | ||
| 1375 | ocp->ddir = DMA_BIDIRECTIONAL; | ||
| 1376 | break; | ||
| 1377 | default: | ||
| 1378 | ddir = "NONE"; | ||
| 1379 | ocp->ddir = DMA_NONE; | ||
| 1380 | break; | ||
| 1381 | } | ||
| 1382 | |||
| 1383 | ocp->lun = lun; | ||
| 1384 | efct_lio_io_printf(io, "new cmd=0x%x ddir=%s dl=%u\n", | ||
| 1385 | cdb[0], ddir, io->exp_xfer_len); | ||
| 1386 | |||
| 1387 | tgt_node = io->node; | ||
| 1388 | se_sess = tgt_node->session; | ||
| 1389 | if (!se_sess) { | ||
| 1390 | efc_log_err(efct, "No session found to submit IO se_cmd: %p\n", | ||
| 1391 | &ocp->cmd); | ||
| 1392 | efct_scsi_io_free(io); | ||
| 1393 | return; | ||
| 1394 | } | ||
| 1395 | |||
| 1396 | efct_set_lio_io_state(io, EFCT_LIO_STATE_TGT_SUBMIT_CMD); | ||
| 1397 | rc = target_init_cmd(se_cmd, se_sess, &io->tgt_io.sense_buffer[0], | ||
| 1398 | ocp->lun, io->exp_xfer_len, ocp->task_attr, | ||
| 1399 | ocp->ddir, TARGET_SCF_ACK_KREF); | ||
| 1400 | if (rc) { | ||
| 1401 | efc_log_err(efct, "failed to init cmd se_cmd: %p\n", se_cmd); | ||
| 1402 | efct_scsi_io_free(io); | ||
| 1403 | return; | ||
| 1404 | } | ||
| 1405 | |||
| 1406 | if (target_submit_prep(se_cmd, cdb, NULL, 0, NULL, 0, | ||
| 1407 | NULL, 0, GFP_ATOMIC)) | ||
| 1408 | return; | ||
| 1409 | |||
| 1410 | target_submit(se_cmd); | ||
| 1411 | } | ||
| 1412 | |||
| 1413 | int | ||
| 1414 | efct_scsi_recv_tmf(struct efct_io *tmfio, u32 lun, enum efct_scsi_tmf_cmd cmd, | ||
| 1415 | struct efct_io *io_to_abort, u32 flags) | ||
| 1416 | { | ||
| 1417 | unsigned char tmr_func; | ||
| 1418 | struct efct *efct = tmfio->efct; | ||
| 1419 | struct efct_scsi_tgt_io *ocp = &tmfio->tgt_io; | ||
| 1420 | struct efct_node *tgt_node; | ||
| 1421 | struct se_session *se_sess; | ||
| 1422 | int rc; | ||
| 1423 | |||
| 1424 | memset(ocp, 0, sizeof(struct efct_scsi_tgt_io)); | ||
| 1425 | efct_set_lio_io_state(tmfio, EFCT_LIO_STATE_SCSI_RECV_TMF); | ||
| 1426 | atomic_add_return(1, &efct->tgt_efct.ios_in_use); | ||
| 1427 | efct_lio_tmfio_printf(tmfio, "%s: new tmf %x lun=%u\n", | ||
| 1428 | tmfio->display_name, cmd, lun); | ||
| 1429 | |||
| 1430 | switch (cmd) { | ||
| 1431 | case EFCT_SCSI_TMF_ABORT_TASK: | ||
| 1432 | tmr_func = TMR_ABORT_TASK; | ||
| 1433 | break; | ||
| 1434 | case EFCT_SCSI_TMF_ABORT_TASK_SET: | ||
| 1435 | tmr_func = TMR_ABORT_TASK_SET; | ||
| 1436 | break; | ||
| 1437 | case EFCT_SCSI_TMF_CLEAR_TASK_SET: | ||
| 1438 | tmr_func = TMR_CLEAR_TASK_SET; | ||
| 1439 | break; | ||
| 1440 | case EFCT_SCSI_TMF_LOGICAL_UNIT_RESET: | ||
| 1441 | tmr_func = TMR_LUN_RESET; | ||
| 1442 | break; | ||
| 1443 | case EFCT_SCSI_TMF_CLEAR_ACA: | ||
| 1444 | tmr_func = TMR_CLEAR_ACA; | ||
| 1445 | break; | ||
| 1446 | case EFCT_SCSI_TMF_TARGET_RESET: | ||
| 1447 | tmr_func = TMR_TARGET_WARM_RESET; | ||
| 1448 | break; | ||
| 1449 | case EFCT_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT: | ||
| 1450 | case EFCT_SCSI_TMF_QUERY_TASK_SET: | ||
| 1451 | default: | ||
| 1452 | goto tmf_fail; | ||
| 1453 | } | ||
| 1454 | |||
| 1455 | tmfio->tgt_io.tmf = tmr_func; | ||
| 1456 | tmfio->tgt_io.lun = lun; | ||
| 1457 | tmfio->tgt_io.io_to_abort = io_to_abort; | ||
| 1458 | |||
| 1459 | tgt_node = tmfio->node; | ||
| 1460 | |||
| 1461 | se_sess = tgt_node->session; | ||
| 1462 | if (!se_sess) | ||
| 1463 | return 0; | ||
| 1464 | |||
| 1465 | rc = target_submit_tmr(&ocp->cmd, se_sess, NULL, lun, ocp, tmr_func, | ||
| 1466 | GFP_ATOMIC, tmfio->init_task_tag, TARGET_SCF_ACK_KREF); | ||
| 1467 | |||
| 1468 | efct_set_lio_io_state(tmfio, EFCT_LIO_STATE_TGT_SUBMIT_TMR); | ||
| 1469 | if (rc) | ||
| 1470 | goto tmf_fail; | ||
| 1471 | |||
| 1472 | return 0; | ||
| 1473 | |||
| 1474 | tmf_fail: | ||
| 1475 | efct_scsi_send_tmf_resp(tmfio, EFCT_SCSI_TMF_FUNCTION_REJECTED, | ||
| 1476 | NULL, efct_lio_null_tmf_done, NULL); | ||
| 1477 | return 0; | ||
| 1478 | } | ||
| 1479 | |||
| 1480 | /* Start items for efct_lio_tpg_attrib_cit */ | ||
| 1481 | |||
| 1482 | #define DEF_EFCT_TPG_ATTRIB(name) \ | ||
| 1483 | \ | ||
| 1484 | static ssize_t efct_lio_tpg_attrib_##name##_show( \ | ||
| 1485 | struct config_item *item, char *page) \ | ||
| 1486 | { \ | ||
| 1487 | struct se_portal_group *se_tpg = to_tpg(item); \ | ||
| 1488 | struct efct_lio_tpg *tpg = container_of(se_tpg, \ | ||
| 1489 | struct efct_lio_tpg, tpg); \ | ||
| 1490 | \ | ||
| 1491 | return sprintf(page, "%u\n", tpg->tpg_attrib.name); \ | ||
| 1492 | } \ | ||
| 1493 | \ | ||
| 1494 | static ssize_t efct_lio_tpg_attrib_##name##_store( \ | ||
| 1495 | struct config_item *item, const char *page, size_t count) \ | ||
| 1496 | { \ | ||
| 1497 | struct se_portal_group *se_tpg = to_tpg(item); \ | ||
| 1498 | struct efct_lio_tpg *tpg = container_of(se_tpg, \ | ||
| 1499 | struct efct_lio_tpg, tpg); \ | ||
| 1500 | struct efct_lio_tpg_attrib *a = &tpg->tpg_attrib; \ | ||
| 1501 | unsigned long val; \ | ||
| 1502 | int ret; \ | ||
| 1503 | \ | ||
| 1504 | ret = kstrtoul(page, 0, &val); \ | ||
| 1505 | if (ret < 0) { \ | ||
| 1506 | pr_err("kstrtoul() failed with ret: %d\n", ret); \ | ||
| 1507 | return ret; \ | ||
| 1508 | } \ | ||
| 1509 | \ | ||
| 1510 | if (val != 0 && val != 1) { \ | ||
| 1511 | pr_err("Illegal boolean value %lu\n", val); \ | ||
| 1512 | return -EINVAL; \ | ||
| 1513 | } \ | ||
| 1514 | \ | ||
| 1515 | a->name = val; \ | ||
| 1516 | \ | ||
| 1517 | return count; \ | ||
| 1518 | } \ | ||
| 1519 | CONFIGFS_ATTR(efct_lio_tpg_attrib_, name) | ||
| 1520 | |||
| 1521 | DEF_EFCT_TPG_ATTRIB(generate_node_acls); | ||
| 1522 | DEF_EFCT_TPG_ATTRIB(cache_dynamic_acls); | ||
| 1523 | DEF_EFCT_TPG_ATTRIB(demo_mode_write_protect); | ||
| 1524 | DEF_EFCT_TPG_ATTRIB(prod_mode_write_protect); | ||
| 1525 | DEF_EFCT_TPG_ATTRIB(demo_mode_login_only); | ||
| 1526 | DEF_EFCT_TPG_ATTRIB(session_deletion_wait); | ||
| 1527 | |||
| 1528 | static struct configfs_attribute *efct_lio_tpg_attrib_attrs[] = { | ||
| 1529 | &efct_lio_tpg_attrib_attr_generate_node_acls, | ||
| 1530 | &efct_lio_tpg_attrib_attr_cache_dynamic_acls, | ||
| 1531 | &efct_lio_tpg_attrib_attr_demo_mode_write_protect, | ||
| 1532 | &efct_lio_tpg_attrib_attr_prod_mode_write_protect, | ||
| 1533 | &efct_lio_tpg_attrib_attr_demo_mode_login_only, | ||
| 1534 | &efct_lio_tpg_attrib_attr_session_deletion_wait, | ||
| 1535 | NULL, | ||
| 1536 | }; | ||
| 1537 | |||
| 1538 | #define DEF_EFCT_NPIV_TPG_ATTRIB(name) \ | ||
| 1539 | \ | ||
| 1540 | static ssize_t efct_lio_npiv_tpg_attrib_##name##_show( \ | ||
| 1541 | struct config_item *item, char *page) \ | ||
| 1542 | { \ | ||
| 1543 | struct se_portal_group *se_tpg = to_tpg(item); \ | ||
| 1544 | struct efct_lio_tpg *tpg = container_of(se_tpg, \ | ||
| 1545 | struct efct_lio_tpg, tpg); \ | ||
| 1546 | \ | ||
| 1547 | return sprintf(page, "%u\n", tpg->tpg_attrib.name); \ | ||
| 1548 | } \ | ||
| 1549 | \ | ||
| 1550 | static ssize_t efct_lio_npiv_tpg_attrib_##name##_store( \ | ||
| 1551 | struct config_item *item, const char *page, size_t count) \ | ||
| 1552 | { \ | ||
| 1553 | struct se_portal_group *se_tpg = to_tpg(item); \ | ||
| 1554 | struct efct_lio_tpg *tpg = container_of(se_tpg, \ | ||
| 1555 | struct efct_lio_tpg, tpg); \ | ||
| 1556 | struct efct_lio_tpg_attrib *a = &tpg->tpg_attrib; \ | ||
| 1557 | unsigned long val; \ | ||
| 1558 | int ret; \ | ||
| 1559 | \ | ||
| 1560 | ret = kstrtoul(page, 0, &val); \ | ||
| 1561 | if (ret < 0) { \ | ||
| 1562 | pr_err("kstrtoul() failed with ret: %d\n", ret); \ | ||
| 1563 | return ret; \ | ||
| 1564 | } \ | ||
| 1565 | \ | ||
| 1566 | if (val != 0 && val != 1) { \ | ||
| 1567 | pr_err("Illegal boolean value %lu\n", val); \ | ||
| 1568 | return -EINVAL; \ | ||
| 1569 | } \ | ||
| 1570 | \ | ||
| 1571 | a->name = val; \ | ||
| 1572 | \ | ||
| 1573 | return count; \ | ||
| 1574 | } \ | ||
| 1575 | CONFIGFS_ATTR(efct_lio_npiv_tpg_attrib_, name) | ||
| 1576 | |||
| 1577 | DEF_EFCT_NPIV_TPG_ATTRIB(generate_node_acls); | ||
| 1578 | DEF_EFCT_NPIV_TPG_ATTRIB(cache_dynamic_acls); | ||
| 1579 | DEF_EFCT_NPIV_TPG_ATTRIB(demo_mode_write_protect); | ||
| 1580 | DEF_EFCT_NPIV_TPG_ATTRIB(prod_mode_write_protect); | ||
| 1581 | DEF_EFCT_NPIV_TPG_ATTRIB(demo_mode_login_only); | ||
| 1582 | DEF_EFCT_NPIV_TPG_ATTRIB(session_deletion_wait); | ||
| 1583 | |||
| 1584 | static struct configfs_attribute *efct_lio_npiv_tpg_attrib_attrs[] = { | ||
| 1585 | &efct_lio_npiv_tpg_attrib_attr_generate_node_acls, | ||
| 1586 | &efct_lio_npiv_tpg_attrib_attr_cache_dynamic_acls, | ||
| 1587 | &efct_lio_npiv_tpg_attrib_attr_demo_mode_write_protect, | ||
| 1588 | &efct_lio_npiv_tpg_attrib_attr_prod_mode_write_protect, | ||
| 1589 | &efct_lio_npiv_tpg_attrib_attr_demo_mode_login_only, | ||
| 1590 | &efct_lio_npiv_tpg_attrib_attr_session_deletion_wait, | ||
| 1591 | NULL, | ||
| 1592 | }; | ||
| 1593 | |||
| 1594 | CONFIGFS_ATTR(efct_lio_tpg_, enable); | ||
| 1595 | static struct configfs_attribute *efct_lio_tpg_attrs[] = { | ||
| 1596 | &efct_lio_tpg_attr_enable, NULL }; | ||
| 1597 | CONFIGFS_ATTR(efct_lio_npiv_tpg_, enable); | ||
| 1598 | static struct configfs_attribute *efct_lio_npiv_tpg_attrs[] = { | ||
| 1599 | &efct_lio_npiv_tpg_attr_enable, NULL }; | ||
| 1600 | |||
| 1601 | static const struct target_core_fabric_ops efct_lio_ops = { | ||
| 1602 | .module = THIS_MODULE, | ||
| 1603 | .fabric_name = "efct", | ||
| 1604 | .node_acl_size = sizeof(struct efct_lio_nacl), | ||
| 1605 | .max_data_sg_nents = 65535, | ||
| 1606 | .tpg_get_wwn = efct_lio_get_fabric_wwn, | ||
| 1607 | .tpg_get_tag = efct_lio_get_tag, | ||
| 1608 | .fabric_init_nodeacl = efct_lio_init_nodeacl, | ||
| 1609 | .tpg_check_demo_mode = efct_lio_check_demo_mode, | ||
| 1610 | .tpg_check_demo_mode_cache = efct_lio_check_demo_mode_cache, | ||
| 1611 | .tpg_check_demo_mode_write_protect = efct_lio_check_demo_write_protect, | ||
| 1612 | .tpg_check_prod_mode_write_protect = efct_lio_check_prod_write_protect, | ||
| 1613 | .tpg_get_inst_index = efct_lio_tpg_get_inst_index, | ||
| 1614 | .check_stop_free = efct_lio_check_stop_free, | ||
| 1615 | .aborted_task = efct_lio_aborted_task, | ||
| 1616 | .release_cmd = efct_lio_release_cmd, | ||
| 1617 | .close_session = efct_lio_close_session, | ||
| 1618 | .sess_get_index = efct_lio_sess_get_index, | ||
| 1619 | .write_pending = efct_lio_write_pending, | ||
| 1620 | .set_default_node_attributes = efct_lio_set_default_node_attrs, | ||
| 1621 | .get_cmd_state = efct_lio_get_cmd_state, | ||
| 1622 | .queue_data_in = efct_lio_queue_data_in, | ||
| 1623 | .queue_status = efct_lio_queue_status, | ||
| 1624 | .queue_tm_rsp = efct_lio_queue_tm_rsp, | ||
| 1625 | .fabric_make_wwn = efct_lio_make_nport, | ||
| 1626 | .fabric_drop_wwn = efct_lio_drop_nport, | ||
| 1627 | .fabric_make_tpg = efct_lio_make_tpg, | ||
| 1628 | .fabric_drop_tpg = efct_lio_drop_tpg, | ||
| 1629 | .tpg_check_demo_mode_login_only = efct_lio_check_demo_mode_login_only, | ||
| 1630 | .tpg_check_prot_fabric_only = NULL, | ||
| 1631 | .sess_get_initiator_sid = NULL, | ||
| 1632 | .tfc_tpg_base_attrs = efct_lio_tpg_attrs, | ||
| 1633 | .tfc_tpg_attrib_attrs = efct_lio_tpg_attrib_attrs, | ||
| 1634 | }; | ||
| 1635 | |||
| 1636 | static const struct target_core_fabric_ops efct_lio_npiv_ops = { | ||
| 1637 | .module = THIS_MODULE, | ||
| 1638 | .fabric_name = "efct_npiv", | ||
| 1639 | .node_acl_size = sizeof(struct efct_lio_nacl), | ||
| 1640 | .max_data_sg_nents = 65535, | ||
| 1641 | .tpg_get_wwn = efct_lio_get_npiv_fabric_wwn, | ||
| 1642 | .tpg_get_tag = efct_lio_get_npiv_tag, | ||
| 1643 | .fabric_init_nodeacl = efct_lio_init_nodeacl, | ||
| 1644 | .tpg_check_demo_mode = efct_lio_check_demo_mode, | ||
| 1645 | .tpg_check_demo_mode_cache = efct_lio_check_demo_mode_cache, | ||
| 1646 | .tpg_check_demo_mode_write_protect = | ||
| 1647 | efct_lio_npiv_check_demo_write_protect, | ||
| 1648 | .tpg_check_prod_mode_write_protect = | ||
| 1649 | efct_lio_npiv_check_prod_write_protect, | ||
| 1650 | .tpg_get_inst_index = efct_lio_tpg_get_inst_index, | ||
| 1651 | .check_stop_free = efct_lio_check_stop_free, | ||
| 1652 | .aborted_task = efct_lio_aborted_task, | ||
| 1653 | .release_cmd = efct_lio_release_cmd, | ||
| 1654 | .close_session = efct_lio_close_session, | ||
| 1655 | .sess_get_index = efct_lio_sess_get_index, | ||
| 1656 | .write_pending = efct_lio_write_pending, | ||
| 1657 | .set_default_node_attributes = efct_lio_set_default_node_attrs, | ||
| 1658 | .get_cmd_state = efct_lio_get_cmd_state, | ||
| 1659 | .queue_data_in = efct_lio_queue_data_in, | ||
| 1660 | .queue_status = efct_lio_queue_status, | ||
| 1661 | .queue_tm_rsp = efct_lio_queue_tm_rsp, | ||
| 1662 | .fabric_make_wwn = efct_lio_npiv_make_nport, | ||
| 1663 | .fabric_drop_wwn = efct_lio_npiv_drop_nport, | ||
| 1664 | .fabric_make_tpg = efct_lio_npiv_make_tpg, | ||
| 1665 | .fabric_drop_tpg = efct_lio_npiv_drop_tpg, | ||
| 1666 | .tpg_check_demo_mode_login_only = | ||
| 1667 | efct_lio_npiv_check_demo_mode_login_only, | ||
| 1668 | .tpg_check_prot_fabric_only = NULL, | ||
| 1669 | .sess_get_initiator_sid = NULL, | ||
| 1670 | .tfc_tpg_base_attrs = efct_lio_npiv_tpg_attrs, | ||
| 1671 | .tfc_tpg_attrib_attrs = efct_lio_npiv_tpg_attrib_attrs, | ||
| 1672 | }; | ||
| 1673 | |||
| 1674 | int efct_scsi_tgt_driver_init(void) | ||
| 1675 | { | ||
| 1676 | int rc; | ||
| 1677 | |||
| 1678 | /* Register the top level struct config_item_type with TCM core */ | ||
| 1679 | rc = target_register_template(&efct_lio_ops); | ||
| 1680 | if (rc < 0) { | ||
| 1681 | pr_err("target_fabric_configfs_register failed with %d\n", rc); | ||
| 1682 | return rc; | ||
| 1683 | } | ||
| 1684 | rc = target_register_template(&efct_lio_npiv_ops); | ||
| 1685 | if (rc < 0) { | ||
| 1686 | pr_err("target_fabric_configfs_register failed with %d\n", rc); | ||
| 1687 | target_unregister_template(&efct_lio_ops); | ||
| 1688 | return rc; | ||
| 1689 | } | ||
| 1690 | return 0; | ||
| 1691 | } | ||
| 1692 | |||
| 1693 | int efct_scsi_tgt_driver_exit(void) | ||
| 1694 | { | ||
| 1695 | target_unregister_template(&efct_lio_ops); | ||
| 1696 | target_unregister_template(&efct_lio_npiv_ops); | ||
| 1697 | return 0; | ||
| 1698 | } | ||
| @@ -0,0 +1,189 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef __EFCT_LIO_H__ | ||
| 8 | #define __EFCT_LIO_H__ | ||
| 9 | |||
| 10 | #include "efct_scsi.h" | ||
| 11 | #include <target/target_core_base.h> | ||
| 12 | |||
| 13 | #define efct_lio_io_printf(io, fmt, ...) \ | ||
| 14 | efc_log_debug(io->efct, \ | ||
| 15 | "[%s] [%04x][i:%04x t:%04x h:%04x]" fmt,\ | ||
| 16 | io->node->display_name, io->instance_index, \ | ||
| 17 | io->init_task_tag, io->tgt_task_tag, io->hw_tag,\ | ||
| 18 | ##__VA_ARGS__) | ||
| 19 | |||
| 20 | #define efct_lio_tmfio_printf(io, fmt, ...) \ | ||
| 21 | efc_log_debug(io->efct, \ | ||
| 22 | "[%s] [%04x][i:%04x t:%04x h:%04x][f:%02x]" fmt,\ | ||
| 23 | io->node->display_name, io->instance_index, \ | ||
| 24 | io->init_task_tag, io->tgt_task_tag, io->hw_tag,\ | ||
| 25 | io->tgt_io.tmf, ##__VA_ARGS__) | ||
| 26 | |||
| 27 | #define efct_set_lio_io_state(io, value) (io->tgt_io.state |= value) | ||
| 28 | |||
| 29 | struct efct_lio_wq_data { | ||
| 30 | struct efct *efct; | ||
| 31 | void *ptr; | ||
| 32 | struct work_struct work; | ||
| 33 | }; | ||
| 34 | |||
| 35 | /* Target private efct structure */ | ||
| 36 | struct efct_scsi_tgt { | ||
| 37 | u32 max_sge; | ||
| 38 | u32 max_sgl; | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Variables used to send task set full. We are using a high watermark | ||
| 42 | * method to send task set full. We will reserve a fixed number of IOs | ||
| 43 | * per initiator plus a fudge factor. Once we reach this number, | ||
| 44 | * then the target will start sending task set full/busy responses. | ||
| 45 | */ | ||
| 46 | atomic_t initiator_count; | ||
| 47 | atomic_t ios_in_use; | ||
| 48 | atomic_t io_high_watermark; | ||
| 49 | |||
| 50 | atomic_t watermark_hit; | ||
| 51 | int watermark_min; | ||
| 52 | int watermark_max; | ||
| 53 | |||
| 54 | struct efct_lio_nport *lio_nport; | ||
| 55 | struct efct_lio_tpg *tpg; | ||
| 56 | |||
| 57 | struct list_head vport_list; | ||
| 58 | /* Protects vport list*/ | ||
| 59 | spinlock_t efct_lio_lock; | ||
| 60 | |||
| 61 | u64 wwnn; | ||
| 62 | }; | ||
| 63 | |||
| 64 | struct efct_scsi_tgt_nport { | ||
| 65 | struct efct_lio_nport *lio_nport; | ||
| 66 | }; | ||
| 67 | |||
| 68 | struct efct_node { | ||
| 69 | struct list_head list_entry; | ||
| 70 | struct kref ref; | ||
| 71 | void (*release)(struct kref *arg); | ||
| 72 | struct efct *efct; | ||
| 73 | struct efc_node *node; | ||
| 74 | struct se_session *session; | ||
| 75 | spinlock_t active_ios_lock; | ||
| 76 | struct list_head active_ios; | ||
| 77 | char display_name[EFC_NAME_LENGTH]; | ||
| 78 | u32 port_fc_id; | ||
| 79 | u32 node_fc_id; | ||
| 80 | u32 vpi; | ||
| 81 | u32 rpi; | ||
| 82 | u32 abort_cnt; | ||
| 83 | }; | ||
| 84 | |||
| 85 | #define EFCT_LIO_STATE_SCSI_RECV_CMD (1 << 0) | ||
| 86 | #define EFCT_LIO_STATE_TGT_SUBMIT_CMD (1 << 1) | ||
| 87 | #define EFCT_LIO_STATE_TFO_QUEUE_DATA_IN (1 << 2) | ||
| 88 | #define EFCT_LIO_STATE_TFO_WRITE_PENDING (1 << 3) | ||
| 89 | #define EFCT_LIO_STATE_TGT_EXECUTE_CMD (1 << 4) | ||
| 90 | #define EFCT_LIO_STATE_SCSI_SEND_RD_DATA (1 << 5) | ||
| 91 | #define EFCT_LIO_STATE_TFO_CHK_STOP_FREE (1 << 6) | ||
| 92 | #define EFCT_LIO_STATE_SCSI_DATA_DONE (1 << 7) | ||
| 93 | #define EFCT_LIO_STATE_TFO_QUEUE_STATUS (1 << 8) | ||
| 94 | #define EFCT_LIO_STATE_SCSI_SEND_RSP (1 << 9) | ||
| 95 | #define EFCT_LIO_STATE_SCSI_RSP_DONE (1 << 10) | ||
| 96 | #define EFCT_LIO_STATE_TGT_GENERIC_FREE (1 << 11) | ||
| 97 | #define EFCT_LIO_STATE_SCSI_RECV_TMF (1 << 12) | ||
| 98 | #define EFCT_LIO_STATE_TGT_SUBMIT_TMR (1 << 13) | ||
| 99 | #define EFCT_LIO_STATE_TFO_WRITE_PEND_STATUS (1 << 14) | ||
| 100 | #define EFCT_LIO_STATE_TGT_GENERIC_REQ_FAILURE (1 << 15) | ||
| 101 | |||
| 102 | #define EFCT_LIO_STATE_TFO_ABORTED_TASK (1 << 29) | ||
| 103 | #define EFCT_LIO_STATE_TFO_RELEASE_CMD (1 << 30) | ||
| 104 | #define EFCT_LIO_STATE_SCSI_CMPL_CMD (1u << 31) | ||
| 105 | |||
| 106 | struct efct_scsi_tgt_io { | ||
| 107 | struct se_cmd cmd; | ||
| 108 | unsigned char sense_buffer[TRANSPORT_SENSE_BUFFER]; | ||
| 109 | enum dma_data_direction ddir; | ||
| 110 | int task_attr; | ||
| 111 | u64 lun; | ||
| 112 | |||
| 113 | u32 state; | ||
| 114 | u8 tmf; | ||
| 115 | struct efct_io *io_to_abort; | ||
| 116 | u32 seg_map_cnt; | ||
| 117 | u32 seg_cnt; | ||
| 118 | u32 cur_seg; | ||
| 119 | enum efct_scsi_io_status err; | ||
| 120 | bool aborting; | ||
| 121 | bool rsp_sent; | ||
| 122 | u32 transferred_len; | ||
| 123 | }; | ||
| 124 | |||
| 125 | /* Handler return codes */ | ||
| 126 | enum { | ||
| 127 | SCSI_HANDLER_DATAPHASE_STARTED = 1, | ||
| 128 | SCSI_HANDLER_RESP_STARTED, | ||
| 129 | SCSI_HANDLER_VALIDATED_DATAPHASE_STARTED, | ||
| 130 | SCSI_CMD_NOT_SUPPORTED, | ||
| 131 | }; | ||
| 132 | |||
| 133 | #define WWN_NAME_LEN 32 | ||
| 134 | struct efct_lio_vport { | ||
| 135 | u64 wwpn; | ||
| 136 | u64 npiv_wwpn; | ||
| 137 | u64 npiv_wwnn; | ||
| 138 | unsigned char wwpn_str[WWN_NAME_LEN]; | ||
| 139 | struct se_wwn vport_wwn; | ||
| 140 | struct efct_lio_tpg *tpg; | ||
| 141 | struct efct *efct; | ||
| 142 | struct Scsi_Host *shost; | ||
| 143 | struct fc_vport *fc_vport; | ||
| 144 | atomic_t enable; | ||
| 145 | }; | ||
| 146 | |||
| 147 | struct efct_lio_nport { | ||
| 148 | u64 wwpn; | ||
| 149 | unsigned char wwpn_str[WWN_NAME_LEN]; | ||
| 150 | struct se_wwn nport_wwn; | ||
| 151 | struct efct_lio_tpg *tpg; | ||
| 152 | struct efct *efct; | ||
| 153 | atomic_t enable; | ||
| 154 | }; | ||
| 155 | |||
| 156 | struct efct_lio_tpg_attrib { | ||
| 157 | u32 generate_node_acls; | ||
| 158 | u32 cache_dynamic_acls; | ||
| 159 | u32 demo_mode_write_protect; | ||
| 160 | u32 prod_mode_write_protect; | ||
| 161 | u32 demo_mode_login_only; | ||
| 162 | bool session_deletion_wait; | ||
| 163 | }; | ||
| 164 | |||
| 165 | struct efct_lio_tpg { | ||
| 166 | struct se_portal_group tpg; | ||
| 167 | struct efct_lio_nport *nport; | ||
| 168 | struct efct_lio_vport *vport; | ||
| 169 | struct efct_lio_tpg_attrib tpg_attrib; | ||
| 170 | unsigned short tpgt; | ||
| 171 | bool enabled; | ||
| 172 | }; | ||
| 173 | |||
| 174 | struct efct_lio_nacl { | ||
| 175 | u64 nport_wwnn; | ||
| 176 | char nport_name[WWN_NAME_LEN]; | ||
| 177 | struct se_session *session; | ||
| 178 | struct se_node_acl se_node_acl; | ||
| 179 | }; | ||
| 180 | |||
| 181 | struct efct_lio_vport_list_t { | ||
| 182 | struct list_head list_entry; | ||
| 183 | struct efct_lio_vport *lio_vport; | ||
| 184 | }; | ||
| 185 | |||
| 186 | int efct_scsi_tgt_driver_init(void); | ||
| 187 | int efct_scsi_tgt_driver_exit(void); | ||
| 188 | |||
| 189 | #endif /*__EFCT_LIO_H__ */ | ||
| @@ -0,0 +1,1159 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efct_driver.h" | ||
| 8 | #include "efct_hw.h" | ||
| 9 | |||
| 10 | #define enable_tsend_auto_resp(efct) 1 | ||
| 11 | #define enable_treceive_auto_resp(efct) 0 | ||
| 12 | |||
| 13 | #define SCSI_IOFMT "[%04x][i:%04x t:%04x h:%04x]" | ||
| 14 | |||
| 15 | #define scsi_io_printf(io, fmt, ...) \ | ||
| 16 | efc_log_debug(io->efct, "[%s]" SCSI_IOFMT fmt, \ | ||
| 17 | io->node->display_name, io->instance_index,\ | ||
| 18 | io->init_task_tag, io->tgt_task_tag, io->hw_tag, ##__VA_ARGS__) | ||
| 19 | |||
| 20 | #define EFCT_LOG_ENABLE_SCSI_TRACE(efct) \ | ||
| 21 | (((efct) != NULL) ? (((efct)->logmask & (1U << 2)) != 0) : 0) | ||
| 22 | |||
| 23 | #define scsi_io_trace(io, fmt, ...) \ | ||
| 24 | do { \ | ||
| 25 | if (EFCT_LOG_ENABLE_SCSI_TRACE(io->efct)) \ | ||
| 26 | scsi_io_printf(io, fmt, ##__VA_ARGS__); \ | ||
| 27 | } while (0) | ||
| 28 | |||
| 29 | struct efct_io * | ||
| 30 | efct_scsi_io_alloc(struct efct_node *node) | ||
| 31 | { | ||
| 32 | struct efct *efct; | ||
| 33 | struct efct_xport *xport; | ||
| 34 | struct efct_io *io; | ||
| 35 | unsigned long flags = 0; | ||
| 36 | |||
| 37 | efct = node->efct; | ||
| 38 | |||
| 39 | xport = efct->xport; | ||
| 40 | |||
| 41 | spin_lock_irqsave(&node->active_ios_lock, flags); | ||
| 42 | |||
| 43 | io = efct_io_pool_io_alloc(efct->xport->io_pool); | ||
| 44 | if (!io) { | ||
| 45 | efc_log_err(efct, "IO alloc Failed\n"); | ||
| 46 | atomic_add_return(1, &xport->io_alloc_failed_count); | ||
| 47 | spin_unlock_irqrestore(&node->active_ios_lock, flags); | ||
| 48 | return NULL; | ||
| 49 | } | ||
| 50 | |||
| 51 | /* initialize refcount */ | ||
| 52 | kref_init(&io->ref); | ||
| 53 | io->release = _efct_scsi_io_free; | ||
| 54 | |||
| 55 | /* set generic fields */ | ||
| 56 | io->efct = efct; | ||
| 57 | io->node = node; | ||
| 58 | kref_get(&node->ref); | ||
| 59 | |||
| 60 | /* set type and name */ | ||
| 61 | io->io_type = EFCT_IO_TYPE_IO; | ||
| 62 | io->display_name = "scsi_io"; | ||
| 63 | |||
| 64 | io->cmd_ini = false; | ||
| 65 | io->cmd_tgt = true; | ||
| 66 | |||
| 67 | /* Add to node's active_ios list */ | ||
| 68 | INIT_LIST_HEAD(&io->list_entry); | ||
| 69 | list_add(&io->list_entry, &node->active_ios); | ||
| 70 | |||
| 71 | spin_unlock_irqrestore(&node->active_ios_lock, flags); | ||
| 72 | |||
| 73 | return io; | ||
| 74 | } | ||
| 75 | |||
| 76 | void | ||
| 77 | _efct_scsi_io_free(struct kref *arg) | ||
| 78 | { | ||
| 79 | struct efct_io *io = container_of(arg, struct efct_io, ref); | ||
| 80 | struct efct *efct = io->efct; | ||
| 81 | struct efct_node *node = io->node; | ||
| 82 | unsigned long flags = 0; | ||
| 83 | |||
| 84 | scsi_io_trace(io, "freeing io 0x%p %s\n", io, io->display_name); | ||
| 85 | |||
| 86 | if (io->io_free) { | ||
| 87 | efc_log_err(efct, "IO already freed.\n"); | ||
| 88 | return; | ||
| 89 | } | ||
| 90 | |||
| 91 | spin_lock_irqsave(&node->active_ios_lock, flags); | ||
| 92 | list_del_init(&io->list_entry); | ||
| 93 | spin_unlock_irqrestore(&node->active_ios_lock, flags); | ||
| 94 | |||
| 95 | kref_put(&node->ref, node->release); | ||
| 96 | io->node = NULL; | ||
| 97 | efct_io_pool_io_free(efct->xport->io_pool, io); | ||
| 98 | } | ||
| 99 | |||
| 100 | void | ||
| 101 | efct_scsi_io_free(struct efct_io *io) | ||
| 102 | { | ||
| 103 | scsi_io_trace(io, "freeing io 0x%p %s\n", io, io->display_name); | ||
| 104 | WARN_ON(!refcount_read(&io->ref.refcount)); | ||
| 105 | kref_put(&io->ref, io->release); | ||
| 106 | } | ||
| 107 | |||
| 108 | static void | ||
| 109 | efct_target_io_cb(struct efct_hw_io *hio, u32 length, int status, | ||
| 110 | u32 ext_status, void *app) | ||
| 111 | { | ||
| 112 | u32 flags = 0; | ||
| 113 | struct efct_io *io = app; | ||
| 114 | struct efct *efct; | ||
| 115 | enum efct_scsi_io_status scsi_stat = EFCT_SCSI_STATUS_GOOD; | ||
| 116 | efct_scsi_io_cb_t cb; | ||
| 117 | |||
| 118 | if (!io || !io->efct) { | ||
| 119 | pr_err("%s: IO can not be NULL\n", __func__); | ||
| 120 | return; | ||
| 121 | } | ||
| 122 | |||
| 123 | scsi_io_trace(io, "status x%x ext_status x%x\n", status, ext_status); | ||
| 124 | |||
| 125 | efct = io->efct; | ||
| 126 | |||
| 127 | io->transferred += length; | ||
| 128 | |||
| 129 | if (!io->scsi_tgt_cb) { | ||
| 130 | efct_scsi_check_pending(efct); | ||
| 131 | return; | ||
| 132 | } | ||
| 133 | |||
| 134 | /* Call target server completion */ | ||
| 135 | cb = io->scsi_tgt_cb; | ||
| 136 | |||
| 137 | /* Clear the callback before invoking the callback */ | ||
| 138 | io->scsi_tgt_cb = NULL; | ||
| 139 | |||
| 140 | /* if status was good, and auto-good-response was set, | ||
| 141 | * then callback target-server with IO_CMPL_RSP_SENT, | ||
| 142 | * otherwise send IO_CMPL | ||
| 143 | */ | ||
| 144 | if (status == 0 && io->auto_resp) | ||
| 145 | flags |= EFCT_SCSI_IO_CMPL_RSP_SENT; | ||
| 146 | else | ||
| 147 | flags |= EFCT_SCSI_IO_CMPL; | ||
| 148 | |||
| 149 | switch (status) { | ||
| 150 | case SLI4_FC_WCQE_STATUS_SUCCESS: | ||
| 151 | scsi_stat = EFCT_SCSI_STATUS_GOOD; | ||
| 152 | break; | ||
| 153 | case SLI4_FC_WCQE_STATUS_DI_ERROR: | ||
| 154 | if (ext_status & SLI4_FC_DI_ERROR_GE) | ||
| 155 | scsi_stat = EFCT_SCSI_STATUS_DIF_GUARD_ERR; | ||
| 156 | else if (ext_status & SLI4_FC_DI_ERROR_AE) | ||
| 157 | scsi_stat = EFCT_SCSI_STATUS_DIF_APP_TAG_ERROR; | ||
| 158 | else if (ext_status & SLI4_FC_DI_ERROR_RE) | ||
| 159 | scsi_stat = EFCT_SCSI_STATUS_DIF_REF_TAG_ERROR; | ||
| 160 | else | ||
| 161 | scsi_stat = EFCT_SCSI_STATUS_DIF_UNKNOWN_ERROR; | ||
| 162 | break; | ||
| 163 | case SLI4_FC_WCQE_STATUS_LOCAL_REJECT: | ||
| 164 | switch (ext_status) { | ||
| 165 | case SLI4_FC_LOCAL_REJECT_INVALID_RELOFFSET: | ||
| 166 | case SLI4_FC_LOCAL_REJECT_ABORT_REQUESTED: | ||
| 167 | scsi_stat = EFCT_SCSI_STATUS_ABORTED; | ||
| 168 | break; | ||
| 169 | case SLI4_FC_LOCAL_REJECT_INVALID_RPI: | ||
| 170 | scsi_stat = EFCT_SCSI_STATUS_NEXUS_LOST; | ||
| 171 | break; | ||
| 172 | case SLI4_FC_LOCAL_REJECT_NO_XRI: | ||
| 173 | scsi_stat = EFCT_SCSI_STATUS_NO_IO; | ||
| 174 | break; | ||
| 175 | default: | ||
| 176 | /*we have seen 0x0d(TX_DMA_FAILED err)*/ | ||
| 177 | scsi_stat = EFCT_SCSI_STATUS_ERROR; | ||
| 178 | break; | ||
| 179 | } | ||
| 180 | break; | ||
| 181 | |||
| 182 | case SLI4_FC_WCQE_STATUS_TARGET_WQE_TIMEOUT: | ||
| 183 | /* target IO timed out */ | ||
| 184 | scsi_stat = EFCT_SCSI_STATUS_TIMEDOUT_AND_ABORTED; | ||
| 185 | break; | ||
| 186 | |||
| 187 | case SLI4_FC_WCQE_STATUS_SHUTDOWN: | ||
| 188 | /* Target IO cancelled by HW */ | ||
| 189 | scsi_stat = EFCT_SCSI_STATUS_SHUTDOWN; | ||
| 190 | break; | ||
| 191 | |||
| 192 | default: | ||
| 193 | scsi_stat = EFCT_SCSI_STATUS_ERROR; | ||
| 194 | break; | ||
| 195 | } | ||
| 196 | |||
| 197 | cb(io, scsi_stat, flags, io->scsi_tgt_cb_arg); | ||
| 198 | |||
| 199 | efct_scsi_check_pending(efct); | ||
| 200 | } | ||
| 201 | |||
| 202 | static int | ||
| 203 | efct_scsi_build_sgls(struct efct_hw *hw, struct efct_hw_io *hio, | ||
| 204 | struct efct_scsi_sgl *sgl, u32 sgl_count, | ||
| 205 | enum efct_hw_io_type type) | ||
| 206 | { | ||
| 207 | int rc; | ||
| 208 | u32 i; | ||
| 209 | struct efct *efct = hw->os; | ||
| 210 | |||
| 211 | /* Initialize HW SGL */ | ||
| 212 | rc = efct_hw_io_init_sges(hw, hio, type); | ||
| 213 | if (rc) { | ||
| 214 | efc_log_err(efct, "efct_hw_io_init_sges failed: %d\n", rc); | ||
| 215 | return -EIO; | ||
| 216 | } | ||
| 217 | |||
| 218 | for (i = 0; i < sgl_count; i++) { | ||
| 219 | /* Add data SGE */ | ||
| 220 | rc = efct_hw_io_add_sge(hw, hio, sgl[i].addr, sgl[i].len); | ||
| 221 | if (rc) { | ||
| 222 | efc_log_err(efct, "add sge failed cnt=%d rc=%d\n", | ||
| 223 | sgl_count, rc); | ||
| 224 | return rc; | ||
| 225 | } | ||
| 226 | } | ||
| 227 | |||
| 228 | return 0; | ||
| 229 | } | ||
| 230 | |||
| 231 | static void efc_log_sgl(struct efct_io *io) | ||
| 232 | { | ||
| 233 | struct efct_hw_io *hio = io->hio; | ||
| 234 | struct sli4_sge *data = NULL; | ||
| 235 | u32 *dword = NULL; | ||
| 236 | u32 i; | ||
| 237 | u32 n_sge; | ||
| 238 | |||
| 239 | scsi_io_trace(io, "def_sgl at 0x%x 0x%08x\n", | ||
| 240 | upper_32_bits(hio->def_sgl.phys), | ||
| 241 | lower_32_bits(hio->def_sgl.phys)); | ||
| 242 | n_sge = (hio->sgl == &hio->def_sgl) ? hio->n_sge : hio->def_sgl_count; | ||
| 243 | for (i = 0, data = hio->def_sgl.virt; i < n_sge; i++, data++) { | ||
| 244 | dword = (u32 *)data; | ||
| 245 | |||
| 246 | scsi_io_trace(io, "SGL %2d 0x%08x 0x%08x 0x%08x 0x%08x\n", | ||
| 247 | i, dword[0], dword[1], dword[2], dword[3]); | ||
| 248 | |||
| 249 | if (dword[2] & (1U << 31)) | ||
| 250 | break; | ||
| 251 | } | ||
| 252 | } | ||
| 253 | |||
| 254 | static void | ||
| 255 | efct_scsi_check_pending_async_cb(struct efct_hw *hw, int status, | ||
| 256 | u8 *mqe, void *arg) | ||
| 257 | { | ||
| 258 | struct efct_io *io = arg; | ||
| 259 | |||
| 260 | if (io) { | ||
| 261 | efct_hw_done_t cb = io->hw_cb; | ||
| 262 | |||
| 263 | if (!io->hw_cb) | ||
| 264 | return; | ||
| 265 | |||
| 266 | io->hw_cb = NULL; | ||
| 267 | (cb)(io->hio, 0, SLI4_FC_WCQE_STATUS_DISPATCH_ERROR, 0, io); | ||
| 268 | } | ||
| 269 | } | ||
| 270 | |||
| 271 | static int | ||
| 272 | efct_scsi_io_dispatch_hw_io(struct efct_io *io, struct efct_hw_io *hio) | ||
| 273 | { | ||
| 274 | int rc = 0; | ||
| 275 | struct efct *efct = io->efct; | ||
| 276 | |||
| 277 | /* Got a HW IO; | ||
| 278 | * update ini/tgt_task_tag with HW IO info and dispatch | ||
| 279 | */ | ||
| 280 | io->hio = hio; | ||
| 281 | if (io->cmd_tgt) | ||
| 282 | io->tgt_task_tag = hio->indicator; | ||
| 283 | else if (io->cmd_ini) | ||
| 284 | io->init_task_tag = hio->indicator; | ||
| 285 | io->hw_tag = hio->reqtag; | ||
| 286 | |||
| 287 | hio->eq = io->hw_priv; | ||
| 288 | |||
| 289 | /* Copy WQ steering */ | ||
| 290 | switch (io->wq_steering) { | ||
| 291 | case EFCT_SCSI_WQ_STEERING_CLASS >> EFCT_SCSI_WQ_STEERING_SHIFT: | ||
| 292 | hio->wq_steering = EFCT_HW_WQ_STEERING_CLASS; | ||
| 293 | break; | ||
| 294 | case EFCT_SCSI_WQ_STEERING_REQUEST >> EFCT_SCSI_WQ_STEERING_SHIFT: | ||
| 295 | hio->wq_steering = EFCT_HW_WQ_STEERING_REQUEST; | ||
| 296 | break; | ||
| 297 | case EFCT_SCSI_WQ_STEERING_CPU >> EFCT_SCSI_WQ_STEERING_SHIFT: | ||
| 298 | hio->wq_steering = EFCT_HW_WQ_STEERING_CPU; | ||
| 299 | break; | ||
| 300 | } | ||
| 301 | |||
| 302 | switch (io->io_type) { | ||
| 303 | case EFCT_IO_TYPE_IO: | ||
| 304 | rc = efct_scsi_build_sgls(&efct->hw, io->hio, | ||
| 305 | io->sgl, io->sgl_count, io->hio_type); | ||
| 306 | if (rc) | ||
| 307 | break; | ||
| 308 | |||
| 309 | if (EFCT_LOG_ENABLE_SCSI_TRACE(efct)) | ||
| 310 | efc_log_sgl(io); | ||
| 311 | |||
| 312 | if (io->app_id) | ||
| 313 | io->iparam.fcp_tgt.app_id = io->app_id; | ||
| 314 | |||
| 315 | io->iparam.fcp_tgt.vpi = io->node->vpi; | ||
| 316 | io->iparam.fcp_tgt.rpi = io->node->rpi; | ||
| 317 | io->iparam.fcp_tgt.s_id = io->node->port_fc_id; | ||
| 318 | io->iparam.fcp_tgt.d_id = io->node->node_fc_id; | ||
| 319 | io->iparam.fcp_tgt.xmit_len = io->wire_len; | ||
| 320 | |||
| 321 | rc = efct_hw_io_send(&io->efct->hw, io->hio_type, io->hio, | ||
| 322 | &io->iparam, io->hw_cb, io); | ||
| 323 | break; | ||
| 324 | default: | ||
| 325 | scsi_io_printf(io, "Unknown IO type=%d\n", io->io_type); | ||
| 326 | rc = -EIO; | ||
| 327 | break; | ||
| 328 | } | ||
| 329 | return rc; | ||
| 330 | } | ||
| 331 | |||
| 332 | static int | ||
| 333 | efct_scsi_io_dispatch_no_hw_io(struct efct_io *io) | ||
| 334 | { | ||
| 335 | int rc; | ||
| 336 | |||
| 337 | switch (io->io_type) { | ||
| 338 | case EFCT_IO_TYPE_ABORT: { | ||
| 339 | struct efct_hw_io *hio_to_abort = NULL; | ||
| 340 | |||
| 341 | hio_to_abort = io->io_to_abort->hio; | ||
| 342 | |||
| 343 | if (!hio_to_abort) { | ||
| 344 | /* | ||
| 345 | * If "IO to abort" does not have an | ||
| 346 | * associated HW IO, immediately make callback with | ||
| 347 | * success. The command must have been sent to | ||
| 348 | * the backend, but the data phase has not yet | ||
| 349 | * started, so we don't have a HW IO. | ||
| 350 | * | ||
| 351 | * Note: since the backend shims should be | ||
| 352 | * taking a reference on io_to_abort, it should not | ||
| 353 | * be possible to have been completed and freed by | ||
| 354 | * the backend before the abort got here. | ||
| 355 | */ | ||
| 356 | scsi_io_printf(io, "IO: not active\n"); | ||
| 357 | ((efct_hw_done_t)io->hw_cb)(io->hio, 0, | ||
| 358 | SLI4_FC_WCQE_STATUS_SUCCESS, 0, io); | ||
| 359 | rc = 0; | ||
| 360 | break; | ||
| 361 | } | ||
| 362 | |||
| 363 | /* HW IO is valid, abort it */ | ||
| 364 | scsi_io_printf(io, "aborting\n"); | ||
| 365 | rc = efct_hw_io_abort(&io->efct->hw, hio_to_abort, | ||
| 366 | io->send_abts, io->hw_cb, io); | ||
| 367 | if (rc) { | ||
| 368 | int status = SLI4_FC_WCQE_STATUS_SUCCESS; | ||
| 369 | efct_hw_done_t cb = io->hw_cb; | ||
| 370 | |||
| 371 | if (rc != -ENOENT && rc != -EINPROGRESS) { | ||
| 372 | status = -1; | ||
| 373 | scsi_io_printf(io, "Failed to abort IO rc=%d\n", | ||
| 374 | rc); | ||
| 375 | } | ||
| 376 | cb(io->hio, 0, status, 0, io); | ||
| 377 | rc = 0; | ||
| 378 | } | ||
| 379 | |||
| 380 | break; | ||
| 381 | } | ||
| 382 | default: | ||
| 383 | scsi_io_printf(io, "Unknown IO type=%d\n", io->io_type); | ||
| 384 | rc = -EIO; | ||
| 385 | break; | ||
| 386 | } | ||
| 387 | return rc; | ||
| 388 | } | ||
| 389 | |||
| 390 | static struct efct_io * | ||
| 391 | efct_scsi_dispatch_pending(struct efct *efct) | ||
| 392 | { | ||
| 393 | struct efct_xport *xport = efct->xport; | ||
| 394 | struct efct_io *io = NULL; | ||
| 395 | struct efct_hw_io *hio; | ||
| 396 | unsigned long flags = 0; | ||
| 397 | int status; | ||
| 398 | |||
| 399 | spin_lock_irqsave(&xport->io_pending_lock, flags); | ||
| 400 | |||
| 401 | if (!list_empty(&xport->io_pending_list)) { | ||
| 402 | io = list_first_entry(&xport->io_pending_list, struct efct_io, | ||
| 403 | io_pending_link); | ||
| 404 | list_del_init(&io->io_pending_link); | ||
| 405 | } | ||
| 406 | |||
| 407 | if (!io) { | ||
| 408 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 409 | return NULL; | ||
| 410 | } | ||
| 411 | |||
| 412 | if (io->io_type == EFCT_IO_TYPE_ABORT) { | ||
| 413 | hio = NULL; | ||
| 414 | } else { | ||
| 415 | hio = efct_hw_io_alloc(&efct->hw); | ||
| 416 | if (!hio) { | ||
| 417 | /* | ||
| 418 | * No HW IO available.Put IO back on | ||
| 419 | * the front of pending list | ||
| 420 | */ | ||
| 421 | list_add(&xport->io_pending_list, &io->io_pending_link); | ||
| 422 | io = NULL; | ||
| 423 | } else { | ||
| 424 | hio->eq = io->hw_priv; | ||
| 425 | } | ||
| 426 | } | ||
| 427 | |||
| 428 | /* Must drop the lock before dispatching the IO */ | ||
| 429 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 430 | |||
| 431 | if (!io) | ||
| 432 | return NULL; | ||
| 433 | |||
| 434 | /* | ||
| 435 | * We pulled an IO off the pending list, | ||
| 436 | * and either got an HW IO or don't need one | ||
| 437 | */ | ||
| 438 | atomic_sub_return(1, &xport->io_pending_count); | ||
| 439 | if (!hio) | ||
| 440 | status = efct_scsi_io_dispatch_no_hw_io(io); | ||
| 441 | else | ||
| 442 | status = efct_scsi_io_dispatch_hw_io(io, hio); | ||
| 443 | if (status) { | ||
| 444 | /* | ||
| 445 | * Invoke the HW callback, but do so in the | ||
| 446 | * separate execution context,provided by the | ||
| 447 | * NOP mailbox completion processing context | ||
| 448 | * by using efct_hw_async_call() | ||
| 449 | */ | ||
| 450 | if (efct_hw_async_call(&efct->hw, | ||
| 451 | efct_scsi_check_pending_async_cb, io)) { | ||
| 452 | efc_log_debug(efct, "call hw async failed\n"); | ||
| 453 | } | ||
| 454 | } | ||
| 455 | |||
| 456 | return io; | ||
| 457 | } | ||
| 458 | |||
| 459 | void | ||
| 460 | efct_scsi_check_pending(struct efct *efct) | ||
| 461 | { | ||
| 462 | struct efct_xport *xport = efct->xport; | ||
| 463 | struct efct_io *io = NULL; | ||
| 464 | int count = 0; | ||
| 465 | unsigned long flags = 0; | ||
| 466 | int dispatch = 0; | ||
| 467 | |||
| 468 | /* Guard against recursion */ | ||
| 469 | if (atomic_add_return(1, &xport->io_pending_recursing)) { | ||
| 470 | /* This function is already running. Decrement and return. */ | ||
| 471 | atomic_sub_return(1, &xport->io_pending_recursing); | ||
| 472 | return; | ||
| 473 | } | ||
| 474 | |||
| 475 | while (efct_scsi_dispatch_pending(efct)) | ||
| 476 | count++; | ||
| 477 | |||
| 478 | if (count) { | ||
| 479 | atomic_sub_return(1, &xport->io_pending_recursing); | ||
| 480 | return; | ||
| 481 | } | ||
| 482 | |||
| 483 | /* | ||
| 484 | * If nothing was removed from the list, | ||
| 485 | * we might be in a case where we need to abort an | ||
| 486 | * active IO and the abort is on the pending list. | ||
| 487 | * Look for an abort we can dispatch. | ||
| 488 | */ | ||
| 489 | |||
| 490 | spin_lock_irqsave(&xport->io_pending_lock, flags); | ||
| 491 | |||
| 492 | list_for_each_entry(io, &xport->io_pending_list, io_pending_link) { | ||
| 493 | if (io->io_type == EFCT_IO_TYPE_ABORT && io->io_to_abort->hio) { | ||
| 494 | /* This IO has a HW IO, so it is | ||
| 495 | * active. Dispatch the abort. | ||
| 496 | */ | ||
| 497 | dispatch = 1; | ||
| 498 | list_del_init(&io->io_pending_link); | ||
| 499 | atomic_sub_return(1, &xport->io_pending_count); | ||
| 500 | break; | ||
| 501 | } | ||
| 502 | } | ||
| 503 | |||
| 504 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 505 | |||
| 506 | if (dispatch) { | ||
| 507 | if (efct_scsi_io_dispatch_no_hw_io(io)) { | ||
| 508 | if (efct_hw_async_call(&efct->hw, | ||
| 509 | efct_scsi_check_pending_async_cb, io)) { | ||
| 510 | efc_log_debug(efct, "hw async failed\n"); | ||
| 511 | } | ||
| 512 | } | ||
| 513 | } | ||
| 514 | |||
| 515 | atomic_sub_return(1, &xport->io_pending_recursing); | ||
| 516 | } | ||
| 517 | |||
| 518 | int | ||
| 519 | efct_scsi_io_dispatch(struct efct_io *io, void *cb) | ||
| 520 | { | ||
| 521 | struct efct_hw_io *hio; | ||
| 522 | struct efct *efct = io->efct; | ||
| 523 | struct efct_xport *xport = efct->xport; | ||
| 524 | unsigned long flags = 0; | ||
| 525 | |||
| 526 | io->hw_cb = cb; | ||
| 527 | |||
| 528 | /* | ||
| 529 | * if this IO already has a HW IO, then this is either | ||
| 530 | * not the first phase of the IO. Send it to the HW. | ||
| 531 | */ | ||
| 532 | if (io->hio) | ||
| 533 | return efct_scsi_io_dispatch_hw_io(io, io->hio); | ||
| 534 | |||
| 535 | /* | ||
| 536 | * We don't already have a HW IO associated with the IO. First check | ||
| 537 | * the pending list. If not empty, add IO to the tail and process the | ||
| 538 | * pending list. | ||
| 539 | */ | ||
| 540 | spin_lock_irqsave(&xport->io_pending_lock, flags); | ||
| 541 | if (!list_empty(&xport->io_pending_list)) { | ||
| 542 | /* | ||
| 543 | * If this is a low latency request, | ||
| 544 | * the put at the front of the IO pending | ||
| 545 | * queue, otherwise put it at the end of the queue. | ||
| 546 | */ | ||
| 547 | if (io->low_latency) { | ||
| 548 | INIT_LIST_HEAD(&io->io_pending_link); | ||
| 549 | list_add(&xport->io_pending_list, &io->io_pending_link); | ||
| 550 | } else { | ||
| 551 | INIT_LIST_HEAD(&io->io_pending_link); | ||
| 552 | list_add_tail(&io->io_pending_link, | ||
| 553 | &xport->io_pending_list); | ||
| 554 | } | ||
| 555 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 556 | atomic_add_return(1, &xport->io_pending_count); | ||
| 557 | atomic_add_return(1, &xport->io_total_pending); | ||
| 558 | |||
| 559 | /* process pending list */ | ||
| 560 | efct_scsi_check_pending(efct); | ||
| 561 | return 0; | ||
| 562 | } | ||
| 563 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 564 | |||
| 565 | /* | ||
| 566 | * We don't have a HW IO associated with the IO and there's nothing | ||
| 567 | * on the pending list. Attempt to allocate a HW IO and dispatch it. | ||
| 568 | */ | ||
| 569 | hio = efct_hw_io_alloc(&io->efct->hw); | ||
| 570 | if (!hio) { | ||
| 571 | /* Couldn't get a HW IO. Save this IO on the pending list */ | ||
| 572 | spin_lock_irqsave(&xport->io_pending_lock, flags); | ||
| 573 | INIT_LIST_HEAD(&io->io_pending_link); | ||
| 574 | list_add_tail(&io->io_pending_link, &xport->io_pending_list); | ||
| 575 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 576 | |||
| 577 | atomic_add_return(1, &xport->io_total_pending); | ||
| 578 | atomic_add_return(1, &xport->io_pending_count); | ||
| 579 | return 0; | ||
| 580 | } | ||
| 581 | |||
| 582 | /* We successfully allocated a HW IO; dispatch to HW */ | ||
| 583 | return efct_scsi_io_dispatch_hw_io(io, hio); | ||
| 584 | } | ||
| 585 | |||
| 586 | int | ||
| 587 | efct_scsi_io_dispatch_abort(struct efct_io *io, void *cb) | ||
| 588 | { | ||
| 589 | struct efct *efct = io->efct; | ||
| 590 | struct efct_xport *xport = efct->xport; | ||
| 591 | unsigned long flags = 0; | ||
| 592 | |||
| 593 | io->hw_cb = cb; | ||
| 594 | |||
| 595 | /* | ||
| 596 | * For aborts, we don't need a HW IO, but we still want | ||
| 597 | * to pass through the pending list to preserve ordering. | ||
| 598 | * Thus, if the pending list is not empty, add this abort | ||
| 599 | * to the pending list and process the pending list. | ||
| 600 | */ | ||
| 601 | spin_lock_irqsave(&xport->io_pending_lock, flags); | ||
| 602 | if (!list_empty(&xport->io_pending_list)) { | ||
| 603 | INIT_LIST_HEAD(&io->io_pending_link); | ||
| 604 | list_add_tail(&io->io_pending_link, &xport->io_pending_list); | ||
| 605 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 606 | atomic_add_return(1, &xport->io_pending_count); | ||
| 607 | atomic_add_return(1, &xport->io_total_pending); | ||
| 608 | |||
| 609 | /* process pending list */ | ||
| 610 | efct_scsi_check_pending(efct); | ||
| 611 | return 0; | ||
| 612 | } | ||
| 613 | spin_unlock_irqrestore(&xport->io_pending_lock, flags); | ||
| 614 | |||
| 615 | /* nothing on pending list, dispatch abort */ | ||
| 616 | return efct_scsi_io_dispatch_no_hw_io(io); | ||
| 617 | } | ||
| 618 | |||
| 619 | static inline int | ||
| 620 | efct_scsi_xfer_data(struct efct_io *io, u32 flags, | ||
| 621 | struct efct_scsi_sgl *sgl, u32 sgl_count, u64 xwire_len, | ||
| 622 | enum efct_hw_io_type type, int enable_ar, | ||
| 623 | efct_scsi_io_cb_t cb, void *arg) | ||
| 624 | { | ||
| 625 | struct efct *efct; | ||
| 626 | size_t residual = 0; | ||
| 627 | |||
| 628 | io->sgl_count = sgl_count; | ||
| 629 | |||
| 630 | efct = io->efct; | ||
| 631 | |||
| 632 | scsi_io_trace(io, "%s wire_len %llu\n", | ||
| 633 | (type == EFCT_HW_IO_TARGET_READ) ? "send" : "recv", | ||
| 634 | xwire_len); | ||
| 635 | |||
| 636 | io->hio_type = type; | ||
| 637 | |||
| 638 | io->scsi_tgt_cb = cb; | ||
| 639 | io->scsi_tgt_cb_arg = arg; | ||
| 640 | |||
| 641 | residual = io->exp_xfer_len - io->transferred; | ||
| 642 | io->wire_len = (xwire_len < residual) ? xwire_len : residual; | ||
| 643 | residual = (xwire_len - io->wire_len); | ||
| 644 | |||
| 645 | memset(&io->iparam, 0, sizeof(io->iparam)); | ||
| 646 | io->iparam.fcp_tgt.ox_id = io->init_task_tag; | ||
| 647 | io->iparam.fcp_tgt.offset = io->transferred; | ||
| 648 | io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; | ||
| 649 | io->iparam.fcp_tgt.timeout = io->timeout; | ||
| 650 | |||
| 651 | /* if this is the last data phase and there is no residual, enable | ||
| 652 | * auto-good-response | ||
| 653 | */ | ||
| 654 | if (enable_ar && (flags & EFCT_SCSI_LAST_DATAPHASE) && residual == 0 && | ||
| 655 | ((io->transferred + io->wire_len) == io->exp_xfer_len) && | ||
| 656 | (!(flags & EFCT_SCSI_NO_AUTO_RESPONSE))) { | ||
| 657 | io->iparam.fcp_tgt.flags |= SLI4_IO_AUTO_GOOD_RESPONSE; | ||
| 658 | io->auto_resp = true; | ||
| 659 | } else { | ||
| 660 | io->auto_resp = false; | ||
| 661 | } | ||
| 662 | |||
| 663 | /* save this transfer length */ | ||
| 664 | io->xfer_req = io->wire_len; | ||
| 665 | |||
| 666 | /* Adjust the transferred count to account for overrun | ||
| 667 | * when the residual is calculated in efct_scsi_send_resp | ||
| 668 | */ | ||
| 669 | io->transferred += residual; | ||
| 670 | |||
| 671 | /* Adjust the SGL size if there is overrun */ | ||
| 672 | |||
| 673 | if (residual) { | ||
| 674 | struct efct_scsi_sgl *sgl_ptr = &io->sgl[sgl_count - 1]; | ||
| 675 | |||
| 676 | while (residual) { | ||
| 677 | size_t len = sgl_ptr->len; | ||
| 678 | |||
| 679 | if (len > residual) { | ||
| 680 | sgl_ptr->len = len - residual; | ||
| 681 | residual = 0; | ||
| 682 | } else { | ||
| 683 | sgl_ptr->len = 0; | ||
| 684 | residual -= len; | ||
| 685 | io->sgl_count--; | ||
| 686 | } | ||
| 687 | sgl_ptr--; | ||
| 688 | } | ||
| 689 | } | ||
| 690 | |||
| 691 | /* Set latency and WQ steering */ | ||
| 692 | io->low_latency = (flags & EFCT_SCSI_LOW_LATENCY) != 0; | ||
| 693 | io->wq_steering = (flags & EFCT_SCSI_WQ_STEERING_MASK) >> | ||
| 694 | EFCT_SCSI_WQ_STEERING_SHIFT; | ||
| 695 | io->wq_class = (flags & EFCT_SCSI_WQ_CLASS_MASK) >> | ||
| 696 | EFCT_SCSI_WQ_CLASS_SHIFT; | ||
| 697 | |||
| 698 | if (efct->xport) { | ||
| 699 | struct efct_xport *xport = efct->xport; | ||
| 700 | |||
| 701 | if (type == EFCT_HW_IO_TARGET_READ) { | ||
| 702 | xport->fcp_stats.input_requests++; | ||
| 703 | xport->fcp_stats.input_bytes += xwire_len; | ||
| 704 | } else if (type == EFCT_HW_IO_TARGET_WRITE) { | ||
| 705 | xport->fcp_stats.output_requests++; | ||
| 706 | xport->fcp_stats.output_bytes += xwire_len; | ||
| 707 | } | ||
| 708 | } | ||
| 709 | return efct_scsi_io_dispatch(io, efct_target_io_cb); | ||
| 710 | } | ||
| 711 | |||
| 712 | int | ||
| 713 | efct_scsi_send_rd_data(struct efct_io *io, u32 flags, | ||
| 714 | struct efct_scsi_sgl *sgl, u32 sgl_count, u64 len, | ||
| 715 | efct_scsi_io_cb_t cb, void *arg) | ||
| 716 | { | ||
| 717 | return efct_scsi_xfer_data(io, flags, sgl, sgl_count, | ||
| 718 | len, EFCT_HW_IO_TARGET_READ, | ||
| 719 | enable_tsend_auto_resp(io->efct), cb, arg); | ||
| 720 | } | ||
| 721 | |||
| 722 | int | ||
| 723 | efct_scsi_recv_wr_data(struct efct_io *io, u32 flags, | ||
| 724 | struct efct_scsi_sgl *sgl, u32 sgl_count, u64 len, | ||
| 725 | efct_scsi_io_cb_t cb, void *arg) | ||
| 726 | { | ||
| 727 | return efct_scsi_xfer_data(io, flags, sgl, sgl_count, len, | ||
| 728 | EFCT_HW_IO_TARGET_WRITE, | ||
| 729 | enable_treceive_auto_resp(io->efct), cb, arg); | ||
| 730 | } | ||
| 731 | |||
| 732 | int | ||
| 733 | efct_scsi_send_resp(struct efct_io *io, u32 flags, | ||
| 734 | struct efct_scsi_cmd_resp *rsp, | ||
| 735 | efct_scsi_io_cb_t cb, void *arg) | ||
| 736 | { | ||
| 737 | struct efct *efct; | ||
| 738 | int residual; | ||
| 739 | /* Always try auto resp */ | ||
| 740 | bool auto_resp = true; | ||
| 741 | u8 scsi_status = 0; | ||
| 742 | u16 scsi_status_qualifier = 0; | ||
| 743 | u8 *sense_data = NULL; | ||
| 744 | u32 sense_data_length = 0; | ||
| 745 | |||
| 746 | efct = io->efct; | ||
| 747 | |||
| 748 | if (rsp) { | ||
| 749 | scsi_status = rsp->scsi_status; | ||
| 750 | scsi_status_qualifier = rsp->scsi_status_qualifier; | ||
| 751 | sense_data = rsp->sense_data; | ||
| 752 | sense_data_length = rsp->sense_data_length; | ||
| 753 | residual = rsp->residual; | ||
| 754 | } else { | ||
| 755 | residual = io->exp_xfer_len - io->transferred; | ||
| 756 | } | ||
| 757 | |||
| 758 | io->wire_len = 0; | ||
| 759 | io->hio_type = EFCT_HW_IO_TARGET_RSP; | ||
| 760 | |||
| 761 | io->scsi_tgt_cb = cb; | ||
| 762 | io->scsi_tgt_cb_arg = arg; | ||
| 763 | |||
| 764 | memset(&io->iparam, 0, sizeof(io->iparam)); | ||
| 765 | io->iparam.fcp_tgt.ox_id = io->init_task_tag; | ||
| 766 | io->iparam.fcp_tgt.offset = 0; | ||
| 767 | io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; | ||
| 768 | io->iparam.fcp_tgt.timeout = io->timeout; | ||
| 769 | |||
| 770 | /* Set low latency queueing request */ | ||
| 771 | io->low_latency = (flags & EFCT_SCSI_LOW_LATENCY) != 0; | ||
| 772 | io->wq_steering = (flags & EFCT_SCSI_WQ_STEERING_MASK) >> | ||
| 773 | EFCT_SCSI_WQ_STEERING_SHIFT; | ||
| 774 | io->wq_class = (flags & EFCT_SCSI_WQ_CLASS_MASK) >> | ||
| 775 | EFCT_SCSI_WQ_CLASS_SHIFT; | ||
| 776 | |||
| 777 | if (scsi_status != 0 || residual || sense_data_length) { | ||
| 778 | struct fcp_resp_with_ext *fcprsp = io->rspbuf.virt; | ||
| 779 | u8 *sns_data; | ||
| 780 | |||
| 781 | if (!fcprsp) { | ||
| 782 | efc_log_err(efct, "NULL response buffer\n"); | ||
| 783 | return -EIO; | ||
| 784 | } | ||
| 785 | |||
| 786 | sns_data = (u8 *)io->rspbuf.virt + sizeof(*fcprsp); | ||
| 787 | |||
| 788 | auto_resp = false; | ||
| 789 | |||
| 790 | memset(fcprsp, 0, sizeof(*fcprsp)); | ||
| 791 | |||
| 792 | io->wire_len += sizeof(*fcprsp); | ||
| 793 | |||
| 794 | fcprsp->resp.fr_status = scsi_status; | ||
| 795 | fcprsp->resp.fr_retry_delay = | ||
| 796 | cpu_to_be16(scsi_status_qualifier); | ||
| 797 | |||
| 798 | /* set residual status if necessary */ | ||
| 799 | if (residual != 0) { | ||
| 800 | /* FCP: if data transferred is less than the | ||
| 801 | * amount expected, then this is an underflow. | ||
| 802 | * If data transferred would have been greater | ||
| 803 | * than the amount expected this is an overflow | ||
| 804 | */ | ||
| 805 | if (residual > 0) { | ||
| 806 | fcprsp->resp.fr_flags |= FCP_RESID_UNDER; | ||
| 807 | fcprsp->ext.fr_resid = cpu_to_be32(residual); | ||
| 808 | } else { | ||
| 809 | fcprsp->resp.fr_flags |= FCP_RESID_OVER; | ||
| 810 | fcprsp->ext.fr_resid = cpu_to_be32(-residual); | ||
| 811 | } | ||
| 812 | } | ||
| 813 | |||
| 814 | if (EFCT_SCSI_SNS_BUF_VALID(sense_data) && sense_data_length) { | ||
| 815 | if (sense_data_length > SCSI_SENSE_BUFFERSIZE) { | ||
| 816 | efc_log_err(efct, "Sense exceeds max size.\n"); | ||
| 817 | return -EIO; | ||
| 818 | } | ||
| 819 | |||
| 820 | fcprsp->resp.fr_flags |= FCP_SNS_LEN_VAL; | ||
| 821 | memcpy(sns_data, sense_data, sense_data_length); | ||
| 822 | fcprsp->ext.fr_sns_len = cpu_to_be32(sense_data_length); | ||
| 823 | io->wire_len += sense_data_length; | ||
| 824 | } | ||
| 825 | |||
| 826 | io->sgl[0].addr = io->rspbuf.phys; | ||
| 827 | io->sgl[0].dif_addr = 0; | ||
| 828 | io->sgl[0].len = io->wire_len; | ||
| 829 | io->sgl_count = 1; | ||
| 830 | } | ||
| 831 | |||
| 832 | if (auto_resp) | ||
| 833 | io->iparam.fcp_tgt.flags |= SLI4_IO_AUTO_GOOD_RESPONSE; | ||
| 834 | |||
| 835 | return efct_scsi_io_dispatch(io, efct_target_io_cb); | ||
| 836 | } | ||
| 837 | |||
| 838 | static int | ||
| 839 | efct_target_bls_resp_cb(struct efct_hw_io *hio, u32 length, int status, | ||
| 840 | u32 ext_status, void *app) | ||
| 841 | { | ||
| 842 | struct efct_io *io = app; | ||
| 843 | struct efct *efct; | ||
| 844 | enum efct_scsi_io_status bls_status; | ||
| 845 | |||
| 846 | efct = io->efct; | ||
| 847 | |||
| 848 | /* BLS isn't really a "SCSI" concept, but use SCSI status */ | ||
| 849 | if (status) { | ||
| 850 | io_error_log(io, "s=%#x x=%#x\n", status, ext_status); | ||
| 851 | bls_status = EFCT_SCSI_STATUS_ERROR; | ||
| 852 | } else { | ||
| 853 | bls_status = EFCT_SCSI_STATUS_GOOD; | ||
| 854 | } | ||
| 855 | |||
| 856 | if (io->bls_cb) { | ||
| 857 | efct_scsi_io_cb_t bls_cb = io->bls_cb; | ||
| 858 | void *bls_cb_arg = io->bls_cb_arg; | ||
| 859 | |||
| 860 | io->bls_cb = NULL; | ||
| 861 | io->bls_cb_arg = NULL; | ||
| 862 | |||
| 863 | /* invoke callback */ | ||
| 864 | bls_cb(io, bls_status, 0, bls_cb_arg); | ||
| 865 | } | ||
| 866 | |||
| 867 | efct_scsi_check_pending(efct); | ||
| 868 | return 0; | ||
| 869 | } | ||
| 870 | |||
| 871 | static int | ||
| 872 | efct_target_send_bls_resp(struct efct_io *io, | ||
| 873 | efct_scsi_io_cb_t cb, void *arg) | ||
| 874 | { | ||
| 875 | struct efct_node *node = io->node; | ||
| 876 | struct sli_bls_params *bls = &io->iparam.bls; | ||
| 877 | struct efct *efct = node->efct; | ||
| 878 | struct fc_ba_acc *acc; | ||
| 879 | int rc; | ||
| 880 | |||
| 881 | /* fill out IO structure with everything needed to send BA_ACC */ | ||
| 882 | memset(&io->iparam, 0, sizeof(io->iparam)); | ||
| 883 | bls->ox_id = io->init_task_tag; | ||
| 884 | bls->rx_id = io->abort_rx_id; | ||
| 885 | bls->vpi = io->node->vpi; | ||
| 886 | bls->rpi = io->node->rpi; | ||
| 887 | bls->s_id = U32_MAX; | ||
| 888 | bls->d_id = io->node->node_fc_id; | ||
| 889 | bls->rpi_registered = true; | ||
| 890 | |||
| 891 | acc = (void *)bls->payload; | ||
| 892 | acc->ba_ox_id = cpu_to_be16(bls->ox_id); | ||
| 893 | acc->ba_rx_id = cpu_to_be16(bls->rx_id); | ||
| 894 | acc->ba_high_seq_cnt = cpu_to_be16(U16_MAX); | ||
| 895 | |||
| 896 | /* generic io fields have already been populated */ | ||
| 897 | |||
| 898 | /* set type and BLS-specific fields */ | ||
| 899 | io->io_type = EFCT_IO_TYPE_BLS_RESP; | ||
| 900 | io->display_name = "bls_rsp"; | ||
| 901 | io->hio_type = EFCT_HW_BLS_ACC; | ||
| 902 | io->bls_cb = cb; | ||
| 903 | io->bls_cb_arg = arg; | ||
| 904 | |||
| 905 | /* dispatch IO */ | ||
| 906 | rc = efct_hw_bls_send(efct, FC_RCTL_BA_ACC, bls, | ||
| 907 | efct_target_bls_resp_cb, io); | ||
| 908 | return rc; | ||
| 909 | } | ||
| 910 | |||
| 911 | static int efct_bls_send_rjt_cb(struct efct_hw_io *hio, u32 length, int status, | ||
| 912 | u32 ext_status, void *app) | ||
| 913 | { | ||
| 914 | struct efct_io *io = app; | ||
| 915 | |||
| 916 | efct_scsi_io_free(io); | ||
| 917 | return 0; | ||
| 918 | } | ||
| 919 | |||
| 920 | struct efct_io * | ||
| 921 | efct_bls_send_rjt(struct efct_io *io, struct fc_frame_header *hdr) | ||
| 922 | { | ||
| 923 | struct efct_node *node = io->node; | ||
| 924 | struct sli_bls_params *bls = &io->iparam.bls; | ||
| 925 | struct efct *efct = node->efct; | ||
| 926 | struct fc_ba_rjt *acc; | ||
| 927 | int rc; | ||
| 928 | |||
| 929 | /* fill out BLS Response-specific fields */ | ||
| 930 | io->io_type = EFCT_IO_TYPE_BLS_RESP; | ||
| 931 | io->display_name = "ba_rjt"; | ||
| 932 | io->hio_type = EFCT_HW_BLS_RJT; | ||
| 933 | io->init_task_tag = be16_to_cpu(hdr->fh_ox_id); | ||
| 934 | |||
| 935 | /* fill out iparam fields */ | ||
| 936 | memset(&io->iparam, 0, sizeof(io->iparam)); | ||
| 937 | bls->ox_id = be16_to_cpu(hdr->fh_ox_id); | ||
| 938 | bls->rx_id = be16_to_cpu(hdr->fh_rx_id); | ||
| 939 | bls->vpi = io->node->vpi; | ||
| 940 | bls->rpi = io->node->rpi; | ||
| 941 | bls->s_id = U32_MAX; | ||
| 942 | bls->d_id = io->node->node_fc_id; | ||
| 943 | bls->rpi_registered = true; | ||
| 944 | |||
| 945 | acc = (void *)bls->payload; | ||
| 946 | acc->br_reason = ELS_RJT_UNAB; | ||
| 947 | acc->br_explan = ELS_EXPL_NONE; | ||
| 948 | |||
| 949 | rc = efct_hw_bls_send(efct, FC_RCTL_BA_RJT, bls, efct_bls_send_rjt_cb, | ||
| 950 | io); | ||
| 951 | if (rc) { | ||
| 952 | efc_log_err(efct, "efct_scsi_io_dispatch() failed: %d\n", rc); | ||
| 953 | efct_scsi_io_free(io); | ||
| 954 | io = NULL; | ||
| 955 | } | ||
| 956 | return io; | ||
| 957 | } | ||
| 958 | |||
| 959 | int | ||
| 960 | efct_scsi_send_tmf_resp(struct efct_io *io, | ||
| 961 | enum efct_scsi_tmf_resp rspcode, | ||
| 962 | u8 addl_rsp_info[3], | ||
| 963 | efct_scsi_io_cb_t cb, void *arg) | ||
| 964 | { | ||
| 965 | int rc; | ||
| 966 | struct { | ||
| 967 | struct fcp_resp_with_ext rsp_ext; | ||
| 968 | struct fcp_resp_rsp_info info; | ||
| 969 | } *fcprsp; | ||
| 970 | u8 fcp_rspcode; | ||
| 971 | |||
| 972 | io->wire_len = 0; | ||
| 973 | |||
| 974 | switch (rspcode) { | ||
| 975 | case EFCT_SCSI_TMF_FUNCTION_COMPLETE: | ||
| 976 | fcp_rspcode = FCP_TMF_CMPL; | ||
| 977 | break; | ||
| 978 | case EFCT_SCSI_TMF_FUNCTION_SUCCEEDED: | ||
| 979 | case EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND: | ||
| 980 | fcp_rspcode = FCP_TMF_CMPL; | ||
| 981 | break; | ||
| 982 | case EFCT_SCSI_TMF_FUNCTION_REJECTED: | ||
| 983 | fcp_rspcode = FCP_TMF_REJECTED; | ||
| 984 | break; | ||
| 985 | case EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER: | ||
| 986 | fcp_rspcode = FCP_TMF_INVALID_LUN; | ||
| 987 | break; | ||
| 988 | case EFCT_SCSI_TMF_SERVICE_DELIVERY: | ||
| 989 | fcp_rspcode = FCP_TMF_FAILED; | ||
| 990 | break; | ||
| 991 | default: | ||
| 992 | fcp_rspcode = FCP_TMF_REJECTED; | ||
| 993 | break; | ||
| 994 | } | ||
| 995 | |||
| 996 | io->hio_type = EFCT_HW_IO_TARGET_RSP; | ||
| 997 | |||
| 998 | io->scsi_tgt_cb = cb; | ||
| 999 | io->scsi_tgt_cb_arg = arg; | ||
| 1000 | |||
| 1001 | if (io->tmf_cmd == EFCT_SCSI_TMF_ABORT_TASK) { | ||
| 1002 | rc = efct_target_send_bls_resp(io, cb, arg); | ||
| 1003 | return rc; | ||
| 1004 | } | ||
| 1005 | |||
| 1006 | /* populate the FCP TMF response */ | ||
| 1007 | fcprsp = io->rspbuf.virt; | ||
| 1008 | memset(fcprsp, 0, sizeof(*fcprsp)); | ||
| 1009 | |||
| 1010 | fcprsp->rsp_ext.resp.fr_flags |= FCP_SNS_LEN_VAL; | ||
| 1011 | |||
| 1012 | if (addl_rsp_info) { | ||
| 1013 | memcpy(fcprsp->info._fr_resvd, addl_rsp_info, | ||
| 1014 | sizeof(fcprsp->info._fr_resvd)); | ||
| 1015 | } | ||
| 1016 | fcprsp->info.rsp_code = fcp_rspcode; | ||
| 1017 | |||
| 1018 | io->wire_len = sizeof(*fcprsp); | ||
| 1019 | |||
| 1020 | fcprsp->rsp_ext.ext.fr_rsp_len = | ||
| 1021 | cpu_to_be32(sizeof(struct fcp_resp_rsp_info)); | ||
| 1022 | |||
| 1023 | io->sgl[0].addr = io->rspbuf.phys; | ||
| 1024 | io->sgl[0].dif_addr = 0; | ||
| 1025 | io->sgl[0].len = io->wire_len; | ||
| 1026 | io->sgl_count = 1; | ||
| 1027 | |||
| 1028 | memset(&io->iparam, 0, sizeof(io->iparam)); | ||
| 1029 | io->iparam.fcp_tgt.ox_id = io->init_task_tag; | ||
| 1030 | io->iparam.fcp_tgt.offset = 0; | ||
| 1031 | io->iparam.fcp_tgt.cs_ctl = io->cs_ctl; | ||
| 1032 | io->iparam.fcp_tgt.timeout = io->timeout; | ||
| 1033 | |||
| 1034 | rc = efct_scsi_io_dispatch(io, efct_target_io_cb); | ||
| 1035 | |||
| 1036 | return rc; | ||
| 1037 | } | ||
| 1038 | |||
| 1039 | static int | ||
| 1040 | efct_target_abort_cb(struct efct_hw_io *hio, u32 length, int status, | ||
| 1041 | u32 ext_status, void *app) | ||
| 1042 | { | ||
| 1043 | struct efct_io *io = app; | ||
| 1044 | struct efct *efct; | ||
| 1045 | enum efct_scsi_io_status scsi_status; | ||
| 1046 | efct_scsi_io_cb_t abort_cb; | ||
| 1047 | void *abort_cb_arg; | ||
| 1048 | |||
| 1049 | efct = io->efct; | ||
| 1050 | |||
| 1051 | if (!io->abort_cb) | ||
| 1052 | goto done; | ||
| 1053 | |||
| 1054 | abort_cb = io->abort_cb; | ||
| 1055 | abort_cb_arg = io->abort_cb_arg; | ||
| 1056 | |||
| 1057 | io->abort_cb = NULL; | ||
| 1058 | io->abort_cb_arg = NULL; | ||
| 1059 | |||
| 1060 | switch (status) { | ||
| 1061 | case SLI4_FC_WCQE_STATUS_SUCCESS: | ||
| 1062 | scsi_status = EFCT_SCSI_STATUS_GOOD; | ||
| 1063 | break; | ||
| 1064 | case SLI4_FC_WCQE_STATUS_LOCAL_REJECT: | ||
| 1065 | switch (ext_status) { | ||
| 1066 | case SLI4_FC_LOCAL_REJECT_NO_XRI: | ||
| 1067 | scsi_status = EFCT_SCSI_STATUS_NO_IO; | ||
| 1068 | break; | ||
| 1069 | case SLI4_FC_LOCAL_REJECT_ABORT_IN_PROGRESS: | ||
| 1070 | scsi_status = EFCT_SCSI_STATUS_ABORT_IN_PROGRESS; | ||
| 1071 | break; | ||
| 1072 | default: | ||
| 1073 | /*we have seen 0x15 (abort in progress)*/ | ||
| 1074 | scsi_status = EFCT_SCSI_STATUS_ERROR; | ||
| 1075 | break; | ||
| 1076 | } | ||
| 1077 | break; | ||
| 1078 | case SLI4_FC_WCQE_STATUS_FCP_RSP_FAILURE: | ||
| 1079 | scsi_status = EFCT_SCSI_STATUS_CHECK_RESPONSE; | ||
| 1080 | break; | ||
| 1081 | default: | ||
| 1082 | scsi_status = EFCT_SCSI_STATUS_ERROR; | ||
| 1083 | break; | ||
| 1084 | } | ||
| 1085 | /* invoke callback */ | ||
| 1086 | abort_cb(io->io_to_abort, scsi_status, 0, abort_cb_arg); | ||
| 1087 | |||
| 1088 | done: | ||
| 1089 | /* done with IO to abort,efct_ref_get(): efct_scsi_tgt_abort_io() */ | ||
| 1090 | kref_put(&io->io_to_abort->ref, io->io_to_abort->release); | ||
| 1091 | |||
| 1092 | efct_io_pool_io_free(efct->xport->io_pool, io); | ||
| 1093 | |||
| 1094 | efct_scsi_check_pending(efct); | ||
| 1095 | return 0; | ||
| 1096 | } | ||
| 1097 | |||
| 1098 | int | ||
| 1099 | efct_scsi_tgt_abort_io(struct efct_io *io, efct_scsi_io_cb_t cb, void *arg) | ||
| 1100 | { | ||
| 1101 | struct efct *efct; | ||
| 1102 | struct efct_xport *xport; | ||
| 1103 | int rc; | ||
| 1104 | struct efct_io *abort_io = NULL; | ||
| 1105 | |||
| 1106 | efct = io->efct; | ||
| 1107 | xport = efct->xport; | ||
| 1108 | |||
| 1109 | /* take a reference on IO being aborted */ | ||
| 1110 | if (kref_get_unless_zero(&io->ref) == 0) { | ||
| 1111 | /* command no longer active */ | ||
| 1112 | scsi_io_printf(io, "command no longer active\n"); | ||
| 1113 | return -EIO; | ||
| 1114 | } | ||
| 1115 | |||
| 1116 | /* | ||
| 1117 | * allocate a new IO to send the abort request. Use efct_io_alloc() | ||
| 1118 | * directly, as we need an IO object that will not fail allocation | ||
| 1119 | * due to allocations being disabled (in efct_scsi_io_alloc()) | ||
| 1120 | */ | ||
| 1121 | abort_io = efct_io_pool_io_alloc(efct->xport->io_pool); | ||
| 1122 | if (!abort_io) { | ||
| 1123 | atomic_add_return(1, &xport->io_alloc_failed_count); | ||
| 1124 | kref_put(&io->ref, io->release); | ||
| 1125 | return -EIO; | ||
| 1126 | } | ||
| 1127 | |||
| 1128 | /* Save the target server callback and argument */ | ||
| 1129 | /* set generic fields */ | ||
| 1130 | abort_io->cmd_tgt = true; | ||
| 1131 | abort_io->node = io->node; | ||
| 1132 | |||
| 1133 | /* set type and abort-specific fields */ | ||
| 1134 | abort_io->io_type = EFCT_IO_TYPE_ABORT; | ||
| 1135 | abort_io->display_name = "tgt_abort"; | ||
| 1136 | abort_io->io_to_abort = io; | ||
| 1137 | abort_io->send_abts = false; | ||
| 1138 | abort_io->abort_cb = cb; | ||
| 1139 | abort_io->abort_cb_arg = arg; | ||
| 1140 | |||
| 1141 | /* now dispatch IO */ | ||
| 1142 | rc = efct_scsi_io_dispatch_abort(abort_io, efct_target_abort_cb); | ||
| 1143 | if (rc) | ||
| 1144 | kref_put(&io->ref, io->release); | ||
| 1145 | return rc; | ||
| 1146 | } | ||
| 1147 | |||
| 1148 | void | ||
| 1149 | efct_scsi_io_complete(struct efct_io *io) | ||
| 1150 | { | ||
| 1151 | if (io->io_free) { | ||
| 1152 | efc_log_debug(io->efct, "completion for non-busy io tag 0x%x\n", | ||
| 1153 | io->tag); | ||
| 1154 | return; | ||
| 1155 | } | ||
| 1156 | |||
| 1157 | scsi_io_trace(io, "freeing io 0x%p %s\n", io, io->display_name); | ||
| 1158 | kref_put(&io->ref, io->release); | ||
| 1159 | } | ||
| @@ -0,0 +1,203 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #if !defined(__EFCT_SCSI_H__) | ||
| 8 | #define __EFCT_SCSI_H__ | ||
| 9 | #include <scsi/scsi_host.h> | ||
| 10 | #include <scsi/scsi_transport_fc.h> | ||
| 11 | |||
| 12 | /* efct_scsi_rcv_cmd() efct_scsi_rcv_tmf() flags */ | ||
| 13 | #define EFCT_SCSI_CMD_DIR_IN (1 << 0) | ||
| 14 | #define EFCT_SCSI_CMD_DIR_OUT (1 << 1) | ||
| 15 | #define EFCT_SCSI_CMD_SIMPLE (1 << 2) | ||
| 16 | #define EFCT_SCSI_CMD_HEAD_OF_QUEUE (1 << 3) | ||
| 17 | #define EFCT_SCSI_CMD_ORDERED (1 << 4) | ||
| 18 | #define EFCT_SCSI_CMD_UNTAGGED (1 << 5) | ||
| 19 | #define EFCT_SCSI_CMD_ACA (1 << 6) | ||
| 20 | #define EFCT_SCSI_FIRST_BURST_ERR (1 << 7) | ||
| 21 | #define EFCT_SCSI_FIRST_BURST_ABORTED (1 << 8) | ||
| 22 | |||
| 23 | /* efct_scsi_send_rd_data/recv_wr_data/send_resp flags */ | ||
| 24 | #define EFCT_SCSI_LAST_DATAPHASE (1 << 0) | ||
| 25 | #define EFCT_SCSI_NO_AUTO_RESPONSE (1 << 1) | ||
| 26 | #define EFCT_SCSI_LOW_LATENCY (1 << 2) | ||
| 27 | |||
| 28 | #define EFCT_SCSI_SNS_BUF_VALID(sense) ((sense) && \ | ||
| 29 | (0x70 == (((const u8 *)(sense))[0] & 0x70))) | ||
| 30 | |||
| 31 | #define EFCT_SCSI_WQ_STEERING_SHIFT 16 | ||
| 32 | #define EFCT_SCSI_WQ_STEERING_MASK (0xf << EFCT_SCSI_WQ_STEERING_SHIFT) | ||
| 33 | #define EFCT_SCSI_WQ_STEERING_CLASS (0 << EFCT_SCSI_WQ_STEERING_SHIFT) | ||
| 34 | #define EFCT_SCSI_WQ_STEERING_REQUEST (1 << EFCT_SCSI_WQ_STEERING_SHIFT) | ||
| 35 | #define EFCT_SCSI_WQ_STEERING_CPU (2 << EFCT_SCSI_WQ_STEERING_SHIFT) | ||
| 36 | |||
| 37 | #define EFCT_SCSI_WQ_CLASS_SHIFT (20) | ||
| 38 | #define EFCT_SCSI_WQ_CLASS_MASK (0xf << EFCT_SCSI_WQ_CLASS_SHIFT) | ||
| 39 | #define EFCT_SCSI_WQ_CLASS(x) ((x & EFCT_SCSI_WQ_CLASS_MASK) << \ | ||
| 40 | EFCT_SCSI_WQ_CLASS_SHIFT) | ||
| 41 | |||
| 42 | #define EFCT_SCSI_WQ_CLASS_LOW_LATENCY 1 | ||
| 43 | |||
| 44 | struct efct_scsi_cmd_resp { | ||
| 45 | u8 scsi_status; | ||
| 46 | u16 scsi_status_qualifier; | ||
| 47 | u8 *response_data; | ||
| 48 | u32 response_data_length; | ||
| 49 | u8 *sense_data; | ||
| 50 | u32 sense_data_length; | ||
| 51 | int residual; | ||
| 52 | u32 response_wire_length; | ||
| 53 | }; | ||
| 54 | |||
| 55 | struct efct_vport { | ||
| 56 | struct efct *efct; | ||
| 57 | bool is_vport; | ||
| 58 | struct fc_host_statistics fc_host_stats; | ||
| 59 | struct Scsi_Host *shost; | ||
| 60 | struct fc_vport *fc_vport; | ||
| 61 | u64 npiv_wwpn; | ||
| 62 | u64 npiv_wwnn; | ||
| 63 | }; | ||
| 64 | |||
| 65 | /* Status values returned by IO callbacks */ | ||
| 66 | enum efct_scsi_io_status { | ||
| 67 | EFCT_SCSI_STATUS_GOOD = 0, | ||
| 68 | EFCT_SCSI_STATUS_ABORTED, | ||
| 69 | EFCT_SCSI_STATUS_ERROR, | ||
| 70 | EFCT_SCSI_STATUS_DIF_GUARD_ERR, | ||
| 71 | EFCT_SCSI_STATUS_DIF_REF_TAG_ERROR, | ||
| 72 | EFCT_SCSI_STATUS_DIF_APP_TAG_ERROR, | ||
| 73 | EFCT_SCSI_STATUS_DIF_UNKNOWN_ERROR, | ||
| 74 | EFCT_SCSI_STATUS_PROTOCOL_CRC_ERROR, | ||
| 75 | EFCT_SCSI_STATUS_NO_IO, | ||
| 76 | EFCT_SCSI_STATUS_ABORT_IN_PROGRESS, | ||
| 77 | EFCT_SCSI_STATUS_CHECK_RESPONSE, | ||
| 78 | EFCT_SCSI_STATUS_COMMAND_TIMEOUT, | ||
| 79 | EFCT_SCSI_STATUS_TIMEDOUT_AND_ABORTED, | ||
| 80 | EFCT_SCSI_STATUS_SHUTDOWN, | ||
| 81 | EFCT_SCSI_STATUS_NEXUS_LOST, | ||
| 82 | }; | ||
| 83 | |||
| 84 | struct efct_node; | ||
| 85 | struct efct_io; | ||
| 86 | struct efc_node; | ||
| 87 | struct efc_nport; | ||
| 88 | |||
| 89 | /* Callback used by send_rd_data(), recv_wr_data(), send_resp() */ | ||
| 90 | typedef int (*efct_scsi_io_cb_t)(struct efct_io *io, | ||
| 91 | enum efct_scsi_io_status status, | ||
| 92 | u32 flags, void *arg); | ||
| 93 | |||
| 94 | /* Callback used by send_rd_io(), send_wr_io() */ | ||
| 95 | typedef int (*efct_scsi_rsp_io_cb_t)(struct efct_io *io, | ||
| 96 | enum efct_scsi_io_status status, | ||
| 97 | struct efct_scsi_cmd_resp *rsp, | ||
| 98 | u32 flags, void *arg); | ||
| 99 | |||
| 100 | /* efct_scsi_cb_t flags */ | ||
| 101 | #define EFCT_SCSI_IO_CMPL (1 << 0) | ||
| 102 | /* IO completed, response sent */ | ||
| 103 | #define EFCT_SCSI_IO_CMPL_RSP_SENT (1 << 1) | ||
| 104 | #define EFCT_SCSI_IO_ABORTED (1 << 2) | ||
| 105 | |||
| 106 | /* efct_scsi_recv_tmf() request values */ | ||
| 107 | enum efct_scsi_tmf_cmd { | ||
| 108 | EFCT_SCSI_TMF_ABORT_TASK = 1, | ||
| 109 | EFCT_SCSI_TMF_QUERY_TASK_SET, | ||
| 110 | EFCT_SCSI_TMF_ABORT_TASK_SET, | ||
| 111 | EFCT_SCSI_TMF_CLEAR_TASK_SET, | ||
| 112 | EFCT_SCSI_TMF_QUERY_ASYNCHRONOUS_EVENT, | ||
| 113 | EFCT_SCSI_TMF_LOGICAL_UNIT_RESET, | ||
| 114 | EFCT_SCSI_TMF_CLEAR_ACA, | ||
| 115 | EFCT_SCSI_TMF_TARGET_RESET, | ||
| 116 | }; | ||
| 117 | |||
| 118 | /* efct_scsi_send_tmf_resp() response values */ | ||
| 119 | enum efct_scsi_tmf_resp { | ||
| 120 | EFCT_SCSI_TMF_FUNCTION_COMPLETE = 1, | ||
| 121 | EFCT_SCSI_TMF_FUNCTION_SUCCEEDED, | ||
| 122 | EFCT_SCSI_TMF_FUNCTION_IO_NOT_FOUND, | ||
| 123 | EFCT_SCSI_TMF_FUNCTION_REJECTED, | ||
| 124 | EFCT_SCSI_TMF_INCORRECT_LOGICAL_UNIT_NUMBER, | ||
| 125 | EFCT_SCSI_TMF_SERVICE_DELIVERY, | ||
| 126 | }; | ||
| 127 | |||
| 128 | struct efct_scsi_sgl { | ||
| 129 | uintptr_t addr; | ||
| 130 | uintptr_t dif_addr; | ||
| 131 | size_t len; | ||
| 132 | }; | ||
| 133 | |||
| 134 | enum efct_scsi_io_role { | ||
| 135 | EFCT_SCSI_IO_ROLE_ORIGINATOR, | ||
| 136 | EFCT_SCSI_IO_ROLE_RESPONDER, | ||
| 137 | }; | ||
| 138 | |||
| 139 | struct efct_io * | ||
| 140 | efct_scsi_io_alloc(struct efct_node *node); | ||
| 141 | void efct_scsi_io_free(struct efct_io *io); | ||
| 142 | struct efct_io *efct_io_get_instance(struct efct *efct, u32 index); | ||
| 143 | |||
| 144 | int efct_scsi_tgt_driver_init(void); | ||
| 145 | int efct_scsi_tgt_driver_exit(void); | ||
| 146 | int efct_scsi_tgt_new_device(struct efct *efct); | ||
| 147 | int efct_scsi_tgt_del_device(struct efct *efct); | ||
| 148 | int | ||
| 149 | efct_scsi_tgt_new_nport(struct efc *efc, struct efc_nport *nport); | ||
| 150 | void | ||
| 151 | efct_scsi_tgt_del_nport(struct efc *efc, struct efc_nport *nport); | ||
| 152 | |||
| 153 | int | ||
| 154 | efct_scsi_new_initiator(struct efc *efc, struct efc_node *node); | ||
| 155 | |||
| 156 | enum efct_scsi_del_initiator_reason { | ||
| 157 | EFCT_SCSI_INITIATOR_DELETED, | ||
| 158 | EFCT_SCSI_INITIATOR_MISSING, | ||
| 159 | }; | ||
| 160 | |||
| 161 | int | ||
| 162 | efct_scsi_del_initiator(struct efc *efc, struct efc_node *node, int reason); | ||
| 163 | void | ||
| 164 | efct_scsi_recv_cmd(struct efct_io *io, uint64_t lun, u8 *cdb, u32 cdb_len, | ||
| 165 | u32 flags); | ||
| 166 | int | ||
| 167 | efct_scsi_recv_tmf(struct efct_io *tmfio, u32 lun, enum efct_scsi_tmf_cmd cmd, | ||
| 168 | struct efct_io *abortio, u32 flags); | ||
| 169 | int | ||
| 170 | efct_scsi_send_rd_data(struct efct_io *io, u32 flags, struct efct_scsi_sgl *sgl, | ||
| 171 | u32 sgl_count, u64 wire_len, efct_scsi_io_cb_t cb, void *arg); | ||
| 172 | int | ||
| 173 | efct_scsi_recv_wr_data(struct efct_io *io, u32 flags, struct efct_scsi_sgl *sgl, | ||
| 174 | u32 sgl_count, u64 wire_len, efct_scsi_io_cb_t cb, void *arg); | ||
| 175 | int | ||
| 176 | efct_scsi_send_resp(struct efct_io *io, u32 flags, | ||
| 177 | struct efct_scsi_cmd_resp *rsp, efct_scsi_io_cb_t cb, void *arg); | ||
| 178 | int | ||
| 179 | efct_scsi_send_tmf_resp(struct efct_io *io, enum efct_scsi_tmf_resp rspcode, | ||
| 180 | u8 addl_rsp_info[3], efct_scsi_io_cb_t cb, void *arg); | ||
| 181 | int | ||
| 182 | efct_scsi_tgt_abort_io(struct efct_io *io, efct_scsi_io_cb_t cb, void *arg); | ||
| 183 | |||
| 184 | void efct_scsi_io_complete(struct efct_io *io); | ||
| 185 | |||
| 186 | int efct_scsi_reg_fc_transport(void); | ||
| 187 | void efct_scsi_release_fc_transport(void); | ||
| 188 | int efct_scsi_new_device(struct efct *efct); | ||
| 189 | void efct_scsi_del_device(struct efct *efct); | ||
| 190 | void _efct_scsi_io_free(struct kref *arg); | ||
| 191 | |||
| 192 | int | ||
| 193 | efct_scsi_del_vport(struct efct *efct, struct Scsi_Host *shost); | ||
| 194 | struct efct_vport * | ||
| 195 | efct_scsi_new_vport(struct efct *efct, struct device *dev); | ||
| 196 | |||
| 197 | int efct_scsi_io_dispatch(struct efct_io *io, void *cb); | ||
| 198 | int efct_scsi_io_dispatch_abort(struct efct_io *io, void *cb); | ||
| 199 | void efct_scsi_check_pending(struct efct *efct); | ||
| 200 | struct efct_io * | ||
| 201 | efct_bls_send_rjt(struct efct_io *io, struct fc_frame_header *hdr); | ||
| 202 | |||
| 203 | #endif /* __EFCT_SCSI_H__ */ | ||
| @@ -0,0 +1,492 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efct_driver.h" | ||
| 8 | #include "efct_unsol.h" | ||
| 9 | |||
| 10 | #define frame_printf(efct, hdr, fmt, ...) \ | ||
| 11 | do { \ | ||
| 12 | char s_id_text[16]; \ | ||
| 13 | efc_node_fcid_display(ntoh24((hdr)->fh_s_id), \ | ||
| 14 | s_id_text, sizeof(s_id_text)); \ | ||
| 15 | efc_log_debug(efct, "[%06x.%s] %02x/%04x/%04x: " fmt, \ | ||
| 16 | ntoh24((hdr)->fh_d_id), s_id_text, \ | ||
| 17 | (hdr)->fh_r_ctl, be16_to_cpu((hdr)->fh_ox_id), \ | ||
| 18 | be16_to_cpu((hdr)->fh_rx_id), ##__VA_ARGS__); \ | ||
| 19 | } while (0) | ||
| 20 | |||
| 21 | static struct efct_node * | ||
| 22 | efct_node_find(struct efct *efct, u32 port_id, u32 node_id) | ||
| 23 | { | ||
| 24 | struct efct_node *node; | ||
| 25 | u64 id = (u64)port_id << 32 | node_id; | ||
| 26 | |||
| 27 | /* | ||
| 28 | * During node shutdown, Lookup will be removed first, | ||
| 29 | * before announcing to backend. So, no new IOs will be allowed | ||
| 30 | */ | ||
| 31 | /* Find a target node, given s_id and d_id */ | ||
| 32 | node = xa_load(&efct->lookup, id); | ||
| 33 | if (node) | ||
| 34 | kref_get(&node->ref); | ||
| 35 | |||
| 36 | return node; | ||
| 37 | } | ||
| 38 | |||
| 39 | static int | ||
| 40 | efct_dispatch_frame(struct efct *efct, struct efc_hw_sequence *seq) | ||
| 41 | { | ||
| 42 | struct efct_node *node; | ||
| 43 | struct fc_frame_header *hdr; | ||
| 44 | u32 s_id, d_id; | ||
| 45 | |||
| 46 | hdr = seq->header->dma.virt; | ||
| 47 | |||
| 48 | /* extract the s_id and d_id */ | ||
| 49 | s_id = ntoh24(hdr->fh_s_id); | ||
| 50 | d_id = ntoh24(hdr->fh_d_id); | ||
| 51 | |||
| 52 | if (!(hdr->fh_type == FC_TYPE_FCP || hdr->fh_type == FC_TYPE_BLS)) | ||
| 53 | return -EIO; | ||
| 54 | |||
| 55 | if (hdr->fh_type == FC_TYPE_FCP) { | ||
| 56 | node = efct_node_find(efct, d_id, s_id); | ||
| 57 | if (!node) { | ||
| 58 | efc_log_err(efct, | ||
| 59 | "Node not found, drop cmd d_id:%x s_id:%x\n", | ||
| 60 | d_id, s_id); | ||
| 61 | efct_hw_sequence_free(&efct->hw, seq); | ||
| 62 | return 0; | ||
| 63 | } | ||
| 64 | |||
| 65 | efct_dispatch_fcp_cmd(node, seq); | ||
| 66 | } else { | ||
| 67 | node = efct_node_find(efct, d_id, s_id); | ||
| 68 | if (!node) { | ||
| 69 | efc_log_err(efct, "ABTS: Node not found, d_id:%x s_id:%x\n", | ||
| 70 | d_id, s_id); | ||
| 71 | return -EIO; | ||
| 72 | } | ||
| 73 | |||
| 74 | efc_log_err(efct, "Received ABTS for Node:%p\n", node); | ||
| 75 | efct_node_recv_abts_frame(node, seq); | ||
| 76 | } | ||
| 77 | |||
| 78 | kref_put(&node->ref, node->release); | ||
| 79 | efct_hw_sequence_free(&efct->hw, seq); | ||
| 80 | return 0; | ||
| 81 | } | ||
| 82 | |||
| 83 | int | ||
| 84 | efct_unsolicited_cb(void *arg, struct efc_hw_sequence *seq) | ||
| 85 | { | ||
| 86 | struct efct *efct = arg; | ||
| 87 | |||
| 88 | /* Process FCP command */ | ||
| 89 | if (!efct_dispatch_frame(efct, seq)) | ||
| 90 | return 0; | ||
| 91 | |||
| 92 | /* Forward frame to discovery lib */ | ||
| 93 | efc_dispatch_frame(efct->efcport, seq); | ||
| 94 | return 0; | ||
| 95 | } | ||
| 96 | |||
| 97 | static int | ||
| 98 | efct_fc_tmf_rejected_cb(struct efct_io *io, | ||
| 99 | enum efct_scsi_io_status scsi_status, | ||
| 100 | u32 flags, void *arg) | ||
| 101 | { | ||
| 102 | efct_scsi_io_free(io); | ||
| 103 | return 0; | ||
| 104 | } | ||
| 105 | |||
| 106 | static void | ||
| 107 | efct_dispatch_unsol_tmf(struct efct_io *io, u8 tm_flags, u32 lun) | ||
| 108 | { | ||
| 109 | u32 i; | ||
| 110 | struct { | ||
| 111 | u32 mask; | ||
| 112 | enum efct_scsi_tmf_cmd cmd; | ||
| 113 | } tmflist[] = { | ||
| 114 | {FCP_TMF_ABT_TASK_SET, EFCT_SCSI_TMF_ABORT_TASK_SET}, | ||
| 115 | {FCP_TMF_CLR_TASK_SET, EFCT_SCSI_TMF_CLEAR_TASK_SET}, | ||
| 116 | {FCP_TMF_LUN_RESET, EFCT_SCSI_TMF_LOGICAL_UNIT_RESET}, | ||
| 117 | {FCP_TMF_TGT_RESET, EFCT_SCSI_TMF_TARGET_RESET}, | ||
| 118 | {FCP_TMF_CLR_ACA, EFCT_SCSI_TMF_CLEAR_ACA} }; | ||
| 119 | |||
| 120 | io->exp_xfer_len = 0; | ||
| 121 | |||
| 122 | for (i = 0; i < ARRAY_SIZE(tmflist); i++) { | ||
| 123 | if (tmflist[i].mask & tm_flags) { | ||
| 124 | io->tmf_cmd = tmflist[i].cmd; | ||
| 125 | efct_scsi_recv_tmf(io, lun, tmflist[i].cmd, NULL, 0); | ||
| 126 | break; | ||
| 127 | } | ||
| 128 | } | ||
| 129 | if (i == ARRAY_SIZE(tmflist)) { | ||
| 130 | /* Not handled */ | ||
| 131 | efc_log_err(io->node->efct, "TMF x%x rejected\n", tm_flags); | ||
| 132 | efct_scsi_send_tmf_resp(io, EFCT_SCSI_TMF_FUNCTION_REJECTED, | ||
| 133 | NULL, efct_fc_tmf_rejected_cb, NULL); | ||
| 134 | } | ||
| 135 | } | ||
| 136 | |||
| 137 | static int | ||
| 138 | efct_validate_fcp_cmd(struct efct *efct, struct efc_hw_sequence *seq) | ||
| 139 | { | ||
| 140 | /* | ||
| 141 | * If we received less than FCP_CMND_IU bytes, assume that the frame is | ||
| 142 | * corrupted in some way and drop it. | ||
| 143 | * This was seen when jamming the FCTL | ||
| 144 | * fill bytes field. | ||
| 145 | */ | ||
| 146 | if (seq->payload->dma.len < sizeof(struct fcp_cmnd)) { | ||
| 147 | struct fc_frame_header *fchdr = seq->header->dma.virt; | ||
| 148 | |||
| 149 | efc_log_debug(efct, | ||
| 150 | "drop ox_id %04x payload (%zd) less than (%zd)\n", | ||
| 151 | be16_to_cpu(fchdr->fh_ox_id), | ||
| 152 | seq->payload->dma.len, sizeof(struct fcp_cmnd)); | ||
| 153 | return -EIO; | ||
| 154 | } | ||
| 155 | return 0; | ||
| 156 | } | ||
| 157 | |||
| 158 | static void | ||
| 159 | efct_populate_io_fcp_cmd(struct efct_io *io, struct fcp_cmnd *cmnd, | ||
| 160 | struct fc_frame_header *fchdr, bool sit) | ||
| 161 | { | ||
| 162 | io->init_task_tag = be16_to_cpu(fchdr->fh_ox_id); | ||
| 163 | /* note, tgt_task_tag, hw_tag set when HW io is allocated */ | ||
| 164 | io->exp_xfer_len = be32_to_cpu(cmnd->fc_dl); | ||
| 165 | io->transferred = 0; | ||
| 166 | |||
| 167 | /* The upper 7 bits of CS_CTL is the frame priority thru the SAN. | ||
| 168 | * Our assertion here is, the priority given to a frame containing | ||
| 169 | * the FCP cmd should be the priority given to ALL frames contained | ||
| 170 | * in that IO. Thus we need to save the incoming CS_CTL here. | ||
| 171 | */ | ||
| 172 | if (ntoh24(fchdr->fh_f_ctl) & FC_FC_RES_B17) | ||
| 173 | io->cs_ctl = fchdr->fh_cs_ctl; | ||
| 174 | else | ||
| 175 | io->cs_ctl = 0; | ||
| 176 | |||
| 177 | io->seq_init = sit; | ||
| 178 | } | ||
| 179 | |||
| 180 | static u32 | ||
| 181 | efct_get_flags_fcp_cmd(struct fcp_cmnd *cmnd) | ||
| 182 | { | ||
| 183 | u32 flags = 0; | ||
| 184 | |||
| 185 | switch (cmnd->fc_pri_ta & FCP_PTA_MASK) { | ||
| 186 | case FCP_PTA_SIMPLE: | ||
| 187 | flags |= EFCT_SCSI_CMD_SIMPLE; | ||
| 188 | break; | ||
| 189 | case FCP_PTA_HEADQ: | ||
| 190 | flags |= EFCT_SCSI_CMD_HEAD_OF_QUEUE; | ||
| 191 | break; | ||
| 192 | case FCP_PTA_ORDERED: | ||
| 193 | flags |= EFCT_SCSI_CMD_ORDERED; | ||
| 194 | break; | ||
| 195 | case FCP_PTA_ACA: | ||
| 196 | flags |= EFCT_SCSI_CMD_ACA; | ||
| 197 | break; | ||
| 198 | } | ||
| 199 | if (cmnd->fc_flags & FCP_CFL_WRDATA) | ||
| 200 | flags |= EFCT_SCSI_CMD_DIR_IN; | ||
| 201 | if (cmnd->fc_flags & FCP_CFL_RDDATA) | ||
| 202 | flags |= EFCT_SCSI_CMD_DIR_OUT; | ||
| 203 | |||
| 204 | return flags; | ||
| 205 | } | ||
| 206 | |||
| 207 | static void | ||
| 208 | efct_sframe_common_send_cb(void *arg, u8 *cqe, int status) | ||
| 209 | { | ||
| 210 | struct efct_hw_send_frame_context *ctx = arg; | ||
| 211 | struct efct_hw *hw = ctx->hw; | ||
| 212 | |||
| 213 | /* Free WQ completion callback */ | ||
| 214 | efct_hw_reqtag_free(hw, ctx->wqcb); | ||
| 215 | |||
| 216 | /* Free sequence */ | ||
| 217 | efct_hw_sequence_free(hw, ctx->seq); | ||
| 218 | } | ||
| 219 | |||
| 220 | static int | ||
| 221 | efct_sframe_common_send(struct efct_node *node, | ||
| 222 | struct efc_hw_sequence *seq, | ||
| 223 | enum fc_rctl r_ctl, u32 f_ctl, | ||
| 224 | u8 type, void *payload, u32 payload_len) | ||
| 225 | { | ||
| 226 | struct efct *efct = node->efct; | ||
| 227 | struct efct_hw *hw = &efct->hw; | ||
| 228 | int rc = 0; | ||
| 229 | struct fc_frame_header *req_hdr = seq->header->dma.virt; | ||
| 230 | struct fc_frame_header hdr; | ||
| 231 | struct efct_hw_send_frame_context *ctx; | ||
| 232 | |||
| 233 | u32 heap_size = seq->payload->dma.size; | ||
| 234 | uintptr_t heap_phys_base = seq->payload->dma.phys; | ||
| 235 | u8 *heap_virt_base = seq->payload->dma.virt; | ||
| 236 | u32 heap_offset = 0; | ||
| 237 | |||
| 238 | /* Build the FC header reusing the RQ header DMA buffer */ | ||
| 239 | memset(&hdr, 0, sizeof(hdr)); | ||
| 240 | hdr.fh_r_ctl = r_ctl; | ||
| 241 | /* send it back to whomever sent it to us */ | ||
| 242 | memcpy(hdr.fh_d_id, req_hdr->fh_s_id, sizeof(hdr.fh_d_id)); | ||
| 243 | memcpy(hdr.fh_s_id, req_hdr->fh_d_id, sizeof(hdr.fh_s_id)); | ||
| 244 | hdr.fh_type = type; | ||
| 245 | hton24(hdr.fh_f_ctl, f_ctl); | ||
| 246 | hdr.fh_ox_id = req_hdr->fh_ox_id; | ||
| 247 | hdr.fh_rx_id = req_hdr->fh_rx_id; | ||
| 248 | hdr.fh_cs_ctl = 0; | ||
| 249 | hdr.fh_df_ctl = 0; | ||
| 250 | hdr.fh_seq_cnt = 0; | ||
| 251 | hdr.fh_parm_offset = 0; | ||
| 252 | |||
| 253 | /* | ||
| 254 | * send_frame_seq_id is an atomic, we just let it increment, | ||
| 255 | * while storing only the low 8 bits to hdr->seq_id | ||
| 256 | */ | ||
| 257 | hdr.fh_seq_id = (u8)atomic_add_return(1, &hw->send_frame_seq_id); | ||
| 258 | hdr.fh_seq_id--; | ||
| 259 | |||
| 260 | /* Allocate and fill in the send frame request context */ | ||
| 261 | ctx = (void *)(heap_virt_base + heap_offset); | ||
| 262 | heap_offset += sizeof(*ctx); | ||
| 263 | if (heap_offset > heap_size) { | ||
| 264 | efc_log_err(efct, "Fill send frame failed offset %d size %d\n", | ||
| 265 | heap_offset, heap_size); | ||
| 266 | return -EIO; | ||
| 267 | } | ||
| 268 | |||
| 269 | memset(ctx, 0, sizeof(*ctx)); | ||
| 270 | |||
| 271 | /* Save sequence */ | ||
| 272 | ctx->seq = seq; | ||
| 273 | |||
| 274 | /* Allocate a response payload DMA buffer from the heap */ | ||
| 275 | ctx->payload.phys = heap_phys_base + heap_offset; | ||
| 276 | ctx->payload.virt = heap_virt_base + heap_offset; | ||
| 277 | ctx->payload.size = payload_len; | ||
| 278 | ctx->payload.len = payload_len; | ||
| 279 | heap_offset += payload_len; | ||
| 280 | if (heap_offset > heap_size) { | ||
| 281 | efc_log_err(efct, "Fill send frame failed offset %d size %d\n", | ||
| 282 | heap_offset, heap_size); | ||
| 283 | return -EIO; | ||
| 284 | } | ||
| 285 | |||
| 286 | /* Copy the payload in */ | ||
| 287 | memcpy(ctx->payload.virt, payload, payload_len); | ||
| 288 | |||
| 289 | /* Send */ | ||
| 290 | rc = efct_hw_send_frame(&efct->hw, (void *)&hdr, FC_SOF_N3, | ||
| 291 | FC_EOF_T, &ctx->payload, ctx, | ||
| 292 | efct_sframe_common_send_cb, ctx); | ||
| 293 | if (rc) | ||
| 294 | efc_log_debug(efct, "efct_hw_send_frame failed: %d\n", rc); | ||
| 295 | |||
| 296 | return rc; | ||
| 297 | } | ||
| 298 | |||
| 299 | static int | ||
| 300 | efct_sframe_send_fcp_rsp(struct efct_node *node, struct efc_hw_sequence *seq, | ||
| 301 | void *rsp, u32 rsp_len) | ||
| 302 | { | ||
| 303 | return efct_sframe_common_send(node, seq, FC_RCTL_DD_CMD_STATUS, | ||
| 304 | FC_FC_EX_CTX | | ||
| 305 | FC_FC_LAST_SEQ | | ||
| 306 | FC_FC_END_SEQ | | ||
| 307 | FC_FC_SEQ_INIT, | ||
| 308 | FC_TYPE_FCP, | ||
| 309 | rsp, rsp_len); | ||
| 310 | } | ||
| 311 | |||
| 312 | static int | ||
| 313 | efct_sframe_send_task_set_full_or_busy(struct efct_node *node, | ||
| 314 | struct efc_hw_sequence *seq) | ||
| 315 | { | ||
| 316 | struct fcp_resp_with_ext fcprsp; | ||
| 317 | struct fcp_cmnd *fcpcmd = seq->payload->dma.virt; | ||
| 318 | int rc = 0; | ||
| 319 | unsigned long flags = 0; | ||
| 320 | struct efct *efct = node->efct; | ||
| 321 | |||
| 322 | /* construct task set full or busy response */ | ||
| 323 | memset(&fcprsp, 0, sizeof(fcprsp)); | ||
| 324 | spin_lock_irqsave(&node->active_ios_lock, flags); | ||
| 325 | fcprsp.resp.fr_status = list_empty(&node->active_ios) ? | ||
| 326 | SAM_STAT_BUSY : SAM_STAT_TASK_SET_FULL; | ||
| 327 | spin_unlock_irqrestore(&node->active_ios_lock, flags); | ||
| 328 | *((u32 *)&fcprsp.ext.fr_resid) = be32_to_cpu(fcpcmd->fc_dl); | ||
| 329 | |||
| 330 | /* send it using send_frame */ | ||
| 331 | rc = efct_sframe_send_fcp_rsp(node, seq, &fcprsp, sizeof(fcprsp)); | ||
| 332 | if (rc) | ||
| 333 | efc_log_debug(efct, "efct_sframe_send_fcp_rsp failed %d\n", rc); | ||
| 334 | |||
| 335 | return rc; | ||
| 336 | } | ||
| 337 | |||
| 338 | int | ||
| 339 | efct_dispatch_fcp_cmd(struct efct_node *node, struct efc_hw_sequence *seq) | ||
| 340 | { | ||
| 341 | struct efct *efct = node->efct; | ||
| 342 | struct fc_frame_header *fchdr = seq->header->dma.virt; | ||
| 343 | struct fcp_cmnd *cmnd = NULL; | ||
| 344 | struct efct_io *io = NULL; | ||
| 345 | u32 lun; | ||
| 346 | |||
| 347 | if (!seq->payload) { | ||
| 348 | efc_log_err(efct, "Sequence payload is NULL.\n"); | ||
| 349 | return -EIO; | ||
| 350 | } | ||
| 351 | |||
| 352 | cmnd = seq->payload->dma.virt; | ||
| 353 | |||
| 354 | /* perform FCP_CMND validation check(s) */ | ||
| 355 | if (efct_validate_fcp_cmd(efct, seq)) | ||
| 356 | return -EIO; | ||
| 357 | |||
| 358 | lun = scsilun_to_int(&cmnd->fc_lun); | ||
| 359 | if (lun == U32_MAX) | ||
| 360 | return -EIO; | ||
| 361 | |||
| 362 | io = efct_scsi_io_alloc(node); | ||
| 363 | if (!io) { | ||
| 364 | int rc; | ||
| 365 | |||
| 366 | /* Use SEND_FRAME to send task set full or busy */ | ||
| 367 | rc = efct_sframe_send_task_set_full_or_busy(node, seq); | ||
| 368 | if (rc) | ||
| 369 | efc_log_err(efct, "Failed to send busy task: %d\n", rc); | ||
| 370 | |||
| 371 | return rc; | ||
| 372 | } | ||
| 373 | |||
| 374 | io->hw_priv = seq->hw_priv; | ||
| 375 | |||
| 376 | io->app_id = 0; | ||
| 377 | |||
| 378 | /* RQ pair, if we got here, SIT=1 */ | ||
| 379 | efct_populate_io_fcp_cmd(io, cmnd, fchdr, true); | ||
| 380 | |||
| 381 | if (cmnd->fc_tm_flags) { | ||
| 382 | efct_dispatch_unsol_tmf(io, cmnd->fc_tm_flags, lun); | ||
| 383 | } else { | ||
| 384 | u32 flags = efct_get_flags_fcp_cmd(cmnd); | ||
| 385 | |||
| 386 | if (cmnd->fc_flags & FCP_CFL_LEN_MASK) { | ||
| 387 | efc_log_err(efct, "Additional CDB not supported\n"); | ||
| 388 | return -EIO; | ||
| 389 | } | ||
| 390 | /* | ||
| 391 | * Can return failure for things like task set full and UAs, | ||
| 392 | * no need to treat as a dropped frame if rc != 0 | ||
| 393 | */ | ||
| 394 | efct_scsi_recv_cmd(io, lun, cmnd->fc_cdb, | ||
| 395 | sizeof(cmnd->fc_cdb), flags); | ||
| 396 | } | ||
| 397 | |||
| 398 | return 0; | ||
| 399 | } | ||
| 400 | |||
| 401 | static int | ||
| 402 | efct_process_abts(struct efct_io *io, struct fc_frame_header *hdr) | ||
| 403 | { | ||
| 404 | struct efct_node *node = io->node; | ||
| 405 | struct efct *efct = io->efct; | ||
| 406 | u16 ox_id = be16_to_cpu(hdr->fh_ox_id); | ||
| 407 | u16 rx_id = be16_to_cpu(hdr->fh_rx_id); | ||
| 408 | struct efct_io *abortio; | ||
| 409 | |||
| 410 | /* Find IO and attempt to take a reference on it */ | ||
| 411 | abortio = efct_io_find_tgt_io(efct, node, ox_id, rx_id); | ||
| 412 | |||
| 413 | if (abortio) { | ||
| 414 | /* Got a reference on the IO. Hold it until backend | ||
| 415 | * is notified below | ||
| 416 | */ | ||
| 417 | efc_log_info(node->efct, "Abort ox_id [%04x] rx_id [%04x]\n", | ||
| 418 | ox_id, rx_id); | ||
| 419 | |||
| 420 | /* | ||
| 421 | * Save the ox_id for the ABTS as the init_task_tag in our | ||
| 422 | * manufactured | ||
| 423 | * TMF IO object | ||
| 424 | */ | ||
| 425 | io->display_name = "abts"; | ||
| 426 | io->init_task_tag = ox_id; | ||
| 427 | /* don't set tgt_task_tag, don't want to confuse with XRI */ | ||
| 428 | |||
| 429 | /* | ||
| 430 | * Save the rx_id from the ABTS as it is | ||
| 431 | * needed for the BLS response, | ||
| 432 | * regardless of the IO context's rx_id | ||
| 433 | */ | ||
| 434 | io->abort_rx_id = rx_id; | ||
| 435 | |||
| 436 | /* Call target server command abort */ | ||
| 437 | io->tmf_cmd = EFCT_SCSI_TMF_ABORT_TASK; | ||
| 438 | efct_scsi_recv_tmf(io, abortio->tgt_io.lun, | ||
| 439 | EFCT_SCSI_TMF_ABORT_TASK, abortio, 0); | ||
| 440 | |||
| 441 | /* | ||
| 442 | * Backend will have taken an additional | ||
| 443 | * reference on the IO if needed; | ||
| 444 | * done with current reference. | ||
| 445 | */ | ||
| 446 | kref_put(&abortio->ref, abortio->release); | ||
| 447 | } else { | ||
| 448 | /* | ||
| 449 | * Either IO was not found or it has been | ||
| 450 | * freed between finding it | ||
| 451 | * and attempting to get the reference, | ||
| 452 | */ | ||
| 453 | efc_log_info(node->efct, "Abort: ox_id [%04x], IO not found\n", | ||
| 454 | ox_id); | ||
| 455 | |||
| 456 | /* Send a BA_RJT */ | ||
| 457 | efct_bls_send_rjt(io, hdr); | ||
| 458 | } | ||
| 459 | return 0; | ||
| 460 | } | ||
| 461 | |||
| 462 | int | ||
| 463 | efct_node_recv_abts_frame(struct efct_node *node, struct efc_hw_sequence *seq) | ||
| 464 | { | ||
| 465 | struct efct *efct = node->efct; | ||
| 466 | struct fc_frame_header *hdr = seq->header->dma.virt; | ||
| 467 | struct efct_io *io = NULL; | ||
| 468 | |||
| 469 | node->abort_cnt++; | ||
| 470 | io = efct_scsi_io_alloc(node); | ||
| 471 | if (io) { | ||
| 472 | io->hw_priv = seq->hw_priv; | ||
| 473 | /* If we got this far, SIT=1 */ | ||
| 474 | io->seq_init = 1; | ||
| 475 | |||
| 476 | /* fill out generic fields */ | ||
| 477 | io->efct = efct; | ||
| 478 | io->node = node; | ||
| 479 | io->cmd_tgt = true; | ||
| 480 | |||
| 481 | efct_process_abts(io, seq->header->dma.virt); | ||
| 482 | } else { | ||
| 483 | efc_log_err(efct, | ||
| 484 | "SCSI IO allocation failed for ABTS received "); | ||
| 485 | efc_log_err(efct, "s_id %06x d_id %06x ox_id %04x rx_id %04x\n", | ||
| 486 | ntoh24(hdr->fh_s_id), ntoh24(hdr->fh_d_id), | ||
| 487 | be16_to_cpu(hdr->fh_ox_id), | ||
| 488 | be16_to_cpu(hdr->fh_rx_id)); | ||
| 489 | } | ||
| 490 | |||
| 491 | return 0; | ||
| 492 | } | ||
| @@ -0,0 +1,17 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #if !defined(__OSC_UNSOL_H__) | ||
| 8 | #define __OSC_UNSOL_H__ | ||
| 9 | |||
| 10 | int | ||
| 11 | efct_unsolicited_cb(void *arg, struct efc_hw_sequence *seq); | ||
| 12 | int | ||
| 13 | efct_dispatch_fcp_cmd(struct efct_node *node, struct efc_hw_sequence *seq); | ||
| 14 | int | ||
| 15 | efct_node_recv_abts_frame(struct efct_node *node, struct efc_hw_sequence *seq); | ||
| 16 | |||
| 17 | #endif /* __OSC_UNSOL_H__ */ | ||
| @@ -0,0 +1,1111 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efct_driver.h" | ||
| 8 | #include "efct_unsol.h" | ||
| 9 | |||
| 10 | static struct dentry *efct_debugfs_root; | ||
| 11 | static atomic_t efct_debugfs_count; | ||
| 12 | |||
| 13 | static struct scsi_host_template efct_template = { | ||
| 14 | .module = THIS_MODULE, | ||
| 15 | .name = EFCT_DRIVER_NAME, | ||
| 16 | .supported_mode = MODE_TARGET, | ||
| 17 | }; | ||
| 18 | |||
| 19 | /* globals */ | ||
| 20 | static struct fc_function_template efct_xport_functions; | ||
| 21 | static struct fc_function_template efct_vport_functions; | ||
| 22 | |||
| 23 | static struct scsi_transport_template *efct_xport_fc_tt; | ||
| 24 | static struct scsi_transport_template *efct_vport_fc_tt; | ||
| 25 | |||
| 26 | struct efct_xport * | ||
| 27 | efct_xport_alloc(struct efct *efct) | ||
| 28 | { | ||
| 29 | struct efct_xport *xport; | ||
| 30 | |||
| 31 | xport = kzalloc(sizeof(*xport), GFP_KERNEL); | ||
| 32 | if (!xport) | ||
| 33 | return xport; | ||
| 34 | |||
| 35 | xport->efct = efct; | ||
| 36 | return xport; | ||
| 37 | } | ||
| 38 | |||
| 39 | static int | ||
| 40 | efct_xport_init_debugfs(struct efct *efct) | ||
| 41 | { | ||
| 42 | /* Setup efct debugfs root directory */ | ||
| 43 | if (!efct_debugfs_root) { | ||
| 44 | efct_debugfs_root = debugfs_create_dir("efct", NULL); | ||
| 45 | atomic_set(&efct_debugfs_count, 0); | ||
| 46 | } | ||
| 47 | |||
| 48 | /* Create a directory for sessions in root */ | ||
| 49 | if (!efct->sess_debugfs_dir) { | ||
| 50 | efct->sess_debugfs_dir = debugfs_create_dir("sessions", | ||
| 51 | efct_debugfs_root); | ||
| 52 | if (IS_ERR(efct->sess_debugfs_dir)) { | ||
| 53 | efc_log_err(efct, | ||
| 54 | "failed to create debugfs entry for sessions\n"); | ||
| 55 | goto debugfs_fail; | ||
| 56 | } | ||
| 57 | atomic_inc(&efct_debugfs_count); | ||
| 58 | } | ||
| 59 | |||
| 60 | return 0; | ||
| 61 | |||
| 62 | debugfs_fail: | ||
| 63 | return -EIO; | ||
| 64 | } | ||
| 65 | |||
| 66 | static void efct_xport_delete_debugfs(struct efct *efct) | ||
| 67 | { | ||
| 68 | /* Remove session debugfs directory */ | ||
| 69 | debugfs_remove(efct->sess_debugfs_dir); | ||
| 70 | efct->sess_debugfs_dir = NULL; | ||
| 71 | atomic_dec(&efct_debugfs_count); | ||
| 72 | |||
| 73 | if (atomic_read(&efct_debugfs_count) == 0) { | ||
| 74 | /* remove root debugfs directory */ | ||
| 75 | debugfs_remove(efct_debugfs_root); | ||
| 76 | efct_debugfs_root = NULL; | ||
| 77 | } | ||
| 78 | } | ||
| 79 | |||
| 80 | int | ||
| 81 | efct_xport_attach(struct efct_xport *xport) | ||
| 82 | { | ||
| 83 | struct efct *efct = xport->efct; | ||
| 84 | int rc; | ||
| 85 | |||
| 86 | rc = efct_hw_setup(&efct->hw, efct, efct->pci); | ||
| 87 | if (rc) { | ||
| 88 | efc_log_err(efct, "%s: Can't setup hardware\n", efct->desc); | ||
| 89 | return rc; | ||
| 90 | } | ||
| 91 | |||
| 92 | efct_hw_parse_filter(&efct->hw, (void *)efct->filter_def); | ||
| 93 | |||
| 94 | xport->io_pool = efct_io_pool_create(efct, efct->hw.config.n_sgl); | ||
| 95 | if (!xport->io_pool) { | ||
| 96 | efc_log_err(efct, "Can't allocate IO pool\n"); | ||
| 97 | return -ENOMEM; | ||
| 98 | } | ||
| 99 | |||
| 100 | return 0; | ||
| 101 | } | ||
| 102 | |||
| 103 | static void | ||
| 104 | efct_xport_link_stats_cb(int status, u32 num_counters, | ||
| 105 | struct efct_hw_link_stat_counts *counters, void *arg) | ||
| 106 | { | ||
| 107 | union efct_xport_stats_u *result = arg; | ||
| 108 | |||
| 109 | result->stats.link_stats.link_failure_error_count = | ||
| 110 | counters[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT].counter; | ||
| 111 | result->stats.link_stats.loss_of_sync_error_count = | ||
| 112 | counters[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT].counter; | ||
| 113 | result->stats.link_stats.primitive_sequence_error_count = | ||
| 114 | counters[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT].counter; | ||
| 115 | result->stats.link_stats.invalid_transmission_word_error_count = | ||
| 116 | counters[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT].counter; | ||
| 117 | result->stats.link_stats.crc_error_count = | ||
| 118 | counters[EFCT_HW_LINK_STAT_CRC_COUNT].counter; | ||
| 119 | |||
| 120 | complete(&result->stats.done); | ||
| 121 | } | ||
| 122 | |||
| 123 | static void | ||
| 124 | efct_xport_host_stats_cb(int status, u32 num_counters, | ||
| 125 | struct efct_hw_host_stat_counts *counters, void *arg) | ||
| 126 | { | ||
| 127 | union efct_xport_stats_u *result = arg; | ||
| 128 | |||
| 129 | result->stats.host_stats.transmit_kbyte_count = | ||
| 130 | counters[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT].counter; | ||
| 131 | result->stats.host_stats.receive_kbyte_count = | ||
| 132 | counters[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT].counter; | ||
| 133 | result->stats.host_stats.transmit_frame_count = | ||
| 134 | counters[EFCT_HW_HOST_STAT_TX_FRAME_COUNT].counter; | ||
| 135 | result->stats.host_stats.receive_frame_count = | ||
| 136 | counters[EFCT_HW_HOST_STAT_RX_FRAME_COUNT].counter; | ||
| 137 | |||
| 138 | complete(&result->stats.done); | ||
| 139 | } | ||
| 140 | |||
| 141 | static void | ||
| 142 | efct_xport_async_link_stats_cb(int status, u32 num_counters, | ||
| 143 | struct efct_hw_link_stat_counts *counters, | ||
| 144 | void *arg) | ||
| 145 | { | ||
| 146 | union efct_xport_stats_u *result = arg; | ||
| 147 | |||
| 148 | result->stats.link_stats.link_failure_error_count = | ||
| 149 | counters[EFCT_HW_LINK_STAT_LINK_FAILURE_COUNT].counter; | ||
| 150 | result->stats.link_stats.loss_of_sync_error_count = | ||
| 151 | counters[EFCT_HW_LINK_STAT_LOSS_OF_SYNC_COUNT].counter; | ||
| 152 | result->stats.link_stats.primitive_sequence_error_count = | ||
| 153 | counters[EFCT_HW_LINK_STAT_PRIMITIVE_SEQ_COUNT].counter; | ||
| 154 | result->stats.link_stats.invalid_transmission_word_error_count = | ||
| 155 | counters[EFCT_HW_LINK_STAT_INVALID_XMIT_WORD_COUNT].counter; | ||
| 156 | result->stats.link_stats.crc_error_count = | ||
| 157 | counters[EFCT_HW_LINK_STAT_CRC_COUNT].counter; | ||
| 158 | } | ||
| 159 | |||
| 160 | static void | ||
| 161 | efct_xport_async_host_stats_cb(int status, u32 num_counters, | ||
| 162 | struct efct_hw_host_stat_counts *counters, | ||
| 163 | void *arg) | ||
| 164 | { | ||
| 165 | union efct_xport_stats_u *result = arg; | ||
| 166 | |||
| 167 | result->stats.host_stats.transmit_kbyte_count = | ||
| 168 | counters[EFCT_HW_HOST_STAT_TX_KBYTE_COUNT].counter; | ||
| 169 | result->stats.host_stats.receive_kbyte_count = | ||
| 170 | counters[EFCT_HW_HOST_STAT_RX_KBYTE_COUNT].counter; | ||
| 171 | result->stats.host_stats.transmit_frame_count = | ||
| 172 | counters[EFCT_HW_HOST_STAT_TX_FRAME_COUNT].counter; | ||
| 173 | result->stats.host_stats.receive_frame_count = | ||
| 174 | counters[EFCT_HW_HOST_STAT_RX_FRAME_COUNT].counter; | ||
| 175 | } | ||
| 176 | |||
| 177 | static void | ||
| 178 | efct_xport_config_stats_timer(struct efct *efct); | ||
| 179 | |||
| 180 | static void | ||
| 181 | efct_xport_stats_timer_cb(struct timer_list *t) | ||
| 182 | { | ||
| 183 | struct efct_xport *xport = from_timer(xport, t, stats_timer); | ||
| 184 | struct efct *efct = xport->efct; | ||
| 185 | |||
| 186 | efct_xport_config_stats_timer(efct); | ||
| 187 | } | ||
| 188 | |||
| 189 | static void | ||
| 190 | efct_xport_config_stats_timer(struct efct *efct) | ||
| 191 | { | ||
| 192 | u32 timeout = 3 * 1000; | ||
| 193 | struct efct_xport *xport = NULL; | ||
| 194 | |||
| 195 | if (!efct) { | ||
| 196 | pr_err("%s: failed to locate EFCT device\n", __func__); | ||
| 197 | return; | ||
| 198 | } | ||
| 199 | |||
| 200 | xport = efct->xport; | ||
| 201 | efct_hw_get_link_stats(&efct->hw, 0, 0, 0, | ||
| 202 | efct_xport_async_link_stats_cb, | ||
| 203 | &xport->fc_xport_stats); | ||
| 204 | efct_hw_get_host_stats(&efct->hw, 0, efct_xport_async_host_stats_cb, | ||
| 205 | &xport->fc_xport_stats); | ||
| 206 | |||
| 207 | timer_setup(&xport->stats_timer, | ||
| 208 | &efct_xport_stats_timer_cb, 0); | ||
| 209 | mod_timer(&xport->stats_timer, | ||
| 210 | jiffies + msecs_to_jiffies(timeout)); | ||
| 211 | } | ||
| 212 | |||
| 213 | int | ||
| 214 | efct_xport_initialize(struct efct_xport *xport) | ||
| 215 | { | ||
| 216 | struct efct *efct = xport->efct; | ||
| 217 | int rc = 0; | ||
| 218 | |||
| 219 | /* Initialize io lists */ | ||
| 220 | spin_lock_init(&xport->io_pending_lock); | ||
| 221 | INIT_LIST_HEAD(&xport->io_pending_list); | ||
| 222 | atomic_set(&xport->io_active_count, 0); | ||
| 223 | atomic_set(&xport->io_pending_count, 0); | ||
| 224 | atomic_set(&xport->io_total_free, 0); | ||
| 225 | atomic_set(&xport->io_total_pending, 0); | ||
| 226 | atomic_set(&xport->io_alloc_failed_count, 0); | ||
| 227 | atomic_set(&xport->io_pending_recursing, 0); | ||
| 228 | |||
| 229 | rc = efct_hw_init(&efct->hw); | ||
| 230 | if (rc) { | ||
| 231 | efc_log_err(efct, "efct_hw_init failure\n"); | ||
| 232 | goto out; | ||
| 233 | } | ||
| 234 | |||
| 235 | rc = efct_scsi_tgt_new_device(efct); | ||
| 236 | if (rc) { | ||
| 237 | efc_log_err(efct, "failed to initialize target\n"); | ||
| 238 | goto hw_init_out; | ||
| 239 | } | ||
| 240 | |||
| 241 | rc = efct_scsi_new_device(efct); | ||
| 242 | if (rc) { | ||
| 243 | efc_log_err(efct, "failed to initialize initiator\n"); | ||
| 244 | goto tgt_dev_out; | ||
| 245 | } | ||
| 246 | |||
| 247 | /* Get FC link and host statistics perodically*/ | ||
| 248 | efct_xport_config_stats_timer(efct); | ||
| 249 | |||
| 250 | efct_xport_init_debugfs(efct); | ||
| 251 | |||
| 252 | return rc; | ||
| 253 | |||
| 254 | tgt_dev_out: | ||
| 255 | efct_scsi_tgt_del_device(efct); | ||
| 256 | |||
| 257 | hw_init_out: | ||
| 258 | efct_hw_teardown(&efct->hw); | ||
| 259 | out: | ||
| 260 | return rc; | ||
| 261 | } | ||
| 262 | |||
| 263 | int | ||
| 264 | efct_xport_status(struct efct_xport *xport, enum efct_xport_status cmd, | ||
| 265 | union efct_xport_stats_u *result) | ||
| 266 | { | ||
| 267 | int rc = 0; | ||
| 268 | struct efct *efct = NULL; | ||
| 269 | union efct_xport_stats_u value; | ||
| 270 | |||
| 271 | efct = xport->efct; | ||
| 272 | |||
| 273 | switch (cmd) { | ||
| 274 | case EFCT_XPORT_CONFIG_PORT_STATUS: | ||
| 275 | if (xport->configured_link_state == 0) { | ||
| 276 | /* | ||
| 277 | * Initial state is offline. configured_link_state is | ||
| 278 | * set to online explicitly when port is brought online | ||
| 279 | */ | ||
| 280 | xport->configured_link_state = EFCT_XPORT_PORT_OFFLINE; | ||
| 281 | } | ||
| 282 | result->value = xport->configured_link_state; | ||
| 283 | break; | ||
| 284 | |||
| 285 | case EFCT_XPORT_PORT_STATUS: | ||
| 286 | /* Determine port status based on link speed. */ | ||
| 287 | value.value = efct_hw_get_link_speed(&efct->hw); | ||
| 288 | if (value.value == 0) | ||
| 289 | result->value = EFCT_XPORT_PORT_OFFLINE; | ||
| 290 | else | ||
| 291 | result->value = EFCT_XPORT_PORT_ONLINE; | ||
| 292 | break; | ||
| 293 | |||
| 294 | case EFCT_XPORT_LINK_SPEED: | ||
| 295 | result->value = efct_hw_get_link_speed(&efct->hw); | ||
| 296 | break; | ||
| 297 | |||
| 298 | case EFCT_XPORT_LINK_STATISTICS: | ||
| 299 | memcpy((void *)result, &efct->xport->fc_xport_stats, | ||
| 300 | sizeof(union efct_xport_stats_u)); | ||
| 301 | break; | ||
| 302 | case EFCT_XPORT_LINK_STAT_RESET: { | ||
| 303 | /* Create a completion to synchronize the stat reset process */ | ||
| 304 | init_completion(&result->stats.done); | ||
| 305 | |||
| 306 | /* First reset the link stats */ | ||
| 307 | rc = efct_hw_get_link_stats(&efct->hw, 0, 1, 1, | ||
| 308 | efct_xport_link_stats_cb, result); | ||
| 309 | if (rc) | ||
| 310 | break; | ||
| 311 | |||
| 312 | /* Wait for completion to be signaled when the cmd completes */ | ||
| 313 | if (wait_for_completion_interruptible(&result->stats.done)) { | ||
| 314 | /* Undefined failure */ | ||
| 315 | efc_log_debug(efct, "sem wait failed\n"); | ||
| 316 | rc = -EIO; | ||
| 317 | break; | ||
| 318 | } | ||
| 319 | |||
| 320 | /* Next reset the host stats */ | ||
| 321 | rc = efct_hw_get_host_stats(&efct->hw, 1, | ||
| 322 | efct_xport_host_stats_cb, result); | ||
| 323 | |||
| 324 | if (rc) | ||
| 325 | break; | ||
| 326 | |||
| 327 | /* Wait for completion to be signaled when the cmd completes */ | ||
| 328 | if (wait_for_completion_interruptible(&result->stats.done)) { | ||
| 329 | /* Undefined failure */ | ||
| 330 | efc_log_debug(efct, "sem wait failed\n"); | ||
| 331 | rc = -EIO; | ||
| 332 | break; | ||
| 333 | } | ||
| 334 | break; | ||
| 335 | } | ||
| 336 | default: | ||
| 337 | rc = -EIO; | ||
| 338 | break; | ||
| 339 | } | ||
| 340 | |||
| 341 | return rc; | ||
| 342 | } | ||
| 343 | |||
| 344 | static int | ||
| 345 | efct_get_link_supported_speeds(struct efct *efct) | ||
| 346 | { | ||
| 347 | u32 supported_speeds = 0; | ||
| 348 | u32 link_module_type, i; | ||
| 349 | struct { | ||
| 350 | u32 lmt_speed; | ||
| 351 | u32 speed; | ||
| 352 | } supported_speed_list[] = { | ||
| 353 | {SLI4_LINK_MODULE_TYPE_1GB, FC_PORTSPEED_1GBIT}, | ||
| 354 | {SLI4_LINK_MODULE_TYPE_2GB, FC_PORTSPEED_2GBIT}, | ||
| 355 | {SLI4_LINK_MODULE_TYPE_4GB, FC_PORTSPEED_4GBIT}, | ||
| 356 | {SLI4_LINK_MODULE_TYPE_8GB, FC_PORTSPEED_8GBIT}, | ||
| 357 | {SLI4_LINK_MODULE_TYPE_16GB, FC_PORTSPEED_16GBIT}, | ||
| 358 | {SLI4_LINK_MODULE_TYPE_32GB, FC_PORTSPEED_32GBIT}, | ||
| 359 | {SLI4_LINK_MODULE_TYPE_64GB, FC_PORTSPEED_64GBIT}, | ||
| 360 | {SLI4_LINK_MODULE_TYPE_128GB, FC_PORTSPEED_128GBIT}, | ||
| 361 | }; | ||
| 362 | |||
| 363 | link_module_type = sli_get_lmt(&efct->hw.sli); | ||
| 364 | |||
| 365 | /* populate link supported speeds */ | ||
| 366 | for (i = 0; i < ARRAY_SIZE(supported_speed_list); i++) { | ||
| 367 | if (link_module_type & supported_speed_list[i].lmt_speed) | ||
| 368 | supported_speeds |= supported_speed_list[i].speed; | ||
| 369 | } | ||
| 370 | |||
| 371 | return supported_speeds; | ||
| 372 | } | ||
| 373 | |||
| 374 | int | ||
| 375 | efct_scsi_new_device(struct efct *efct) | ||
| 376 | { | ||
| 377 | struct Scsi_Host *shost = NULL; | ||
| 378 | int error = 0; | ||
| 379 | struct efct_vport *vport = NULL; | ||
| 380 | |||
| 381 | shost = scsi_host_alloc(&efct_template, sizeof(*vport)); | ||
| 382 | if (!shost) { | ||
| 383 | efc_log_err(efct, "failed to allocate Scsi_Host struct\n"); | ||
| 384 | return -ENOMEM; | ||
| 385 | } | ||
| 386 | |||
| 387 | /* save shost to initiator-client context */ | ||
| 388 | efct->shost = shost; | ||
| 389 | |||
| 390 | /* save efct information to shost LLD-specific space */ | ||
| 391 | vport = (struct efct_vport *)shost->hostdata; | ||
| 392 | vport->efct = efct; | ||
| 393 | |||
| 394 | /* | ||
| 395 | * Set initial can_queue value to the max SCSI IOs. This is the maximum | ||
| 396 | * global queue depth (as opposed to the per-LUN queue depth -- | ||
| 397 | * .cmd_per_lun This may need to be adjusted for I+T mode. | ||
| 398 | */ | ||
| 399 | shost->can_queue = efct->hw.config.n_io; | ||
| 400 | shost->max_cmd_len = 16; /* 16-byte CDBs */ | ||
| 401 | shost->max_id = 0xffff; | ||
| 402 | shost->max_lun = 0xffffffff; | ||
| 403 | |||
| 404 | /* | ||
| 405 | * can only accept (from mid-layer) as many SGEs as we've | ||
| 406 | * pre-registered | ||
| 407 | */ | ||
| 408 | shost->sg_tablesize = sli_get_max_sgl(&efct->hw.sli); | ||
| 409 | |||
| 410 | /* attach FC Transport template to shost */ | ||
| 411 | shost->transportt = efct_xport_fc_tt; | ||
| 412 | efc_log_debug(efct, "transport template=%p\n", efct_xport_fc_tt); | ||
| 413 | |||
| 414 | /* get pci_dev structure and add host to SCSI ML */ | ||
| 415 | error = scsi_add_host_with_dma(shost, &efct->pci->dev, | ||
| 416 | &efct->pci->dev); | ||
| 417 | if (error) { | ||
| 418 | efc_log_debug(efct, "failed scsi_add_host_with_dma\n"); | ||
| 419 | return -EIO; | ||
| 420 | } | ||
| 421 | |||
| 422 | /* Set symbolic name for host port */ | ||
| 423 | snprintf(fc_host_symbolic_name(shost), | ||
| 424 | sizeof(fc_host_symbolic_name(shost)), | ||
| 425 | "Emulex %s FV%s DV%s", efct->model, | ||
| 426 | efct->hw.sli.fw_name[0], EFCT_DRIVER_VERSION); | ||
| 427 | |||
| 428 | /* Set host port supported classes */ | ||
| 429 | fc_host_supported_classes(shost) = FC_COS_CLASS3; | ||
| 430 | |||
| 431 | fc_host_supported_speeds(shost) = efct_get_link_supported_speeds(efct); | ||
| 432 | |||
| 433 | fc_host_node_name(shost) = efct_get_wwnn(&efct->hw); | ||
| 434 | fc_host_port_name(shost) = efct_get_wwpn(&efct->hw); | ||
| 435 | fc_host_max_npiv_vports(shost) = 128; | ||
| 436 | |||
| 437 | return 0; | ||
| 438 | } | ||
| 439 | |||
| 440 | struct scsi_transport_template * | ||
| 441 | efct_attach_fc_transport(void) | ||
| 442 | { | ||
| 443 | struct scsi_transport_template *efct_fc_template = NULL; | ||
| 444 | |||
| 445 | efct_fc_template = fc_attach_transport(&efct_xport_functions); | ||
| 446 | |||
| 447 | if (!efct_fc_template) | ||
| 448 | pr_err("failed to attach EFCT with fc transport\n"); | ||
| 449 | |||
| 450 | return efct_fc_template; | ||
| 451 | } | ||
| 452 | |||
| 453 | struct scsi_transport_template * | ||
| 454 | efct_attach_vport_fc_transport(void) | ||
| 455 | { | ||
| 456 | struct scsi_transport_template *efct_fc_template = NULL; | ||
| 457 | |||
| 458 | efct_fc_template = fc_attach_transport(&efct_vport_functions); | ||
| 459 | |||
| 460 | if (!efct_fc_template) | ||
| 461 | pr_err("failed to attach EFCT with fc transport\n"); | ||
| 462 | |||
| 463 | return efct_fc_template; | ||
| 464 | } | ||
| 465 | |||
| 466 | int | ||
| 467 | efct_scsi_reg_fc_transport(void) | ||
| 468 | { | ||
| 469 | /* attach to appropriate scsi_tranport_* module */ | ||
| 470 | efct_xport_fc_tt = efct_attach_fc_transport(); | ||
| 471 | if (!efct_xport_fc_tt) { | ||
| 472 | pr_err("%s: failed to attach to scsi_transport_*", __func__); | ||
| 473 | return -EIO; | ||
| 474 | } | ||
| 475 | |||
| 476 | efct_vport_fc_tt = efct_attach_vport_fc_transport(); | ||
| 477 | if (!efct_vport_fc_tt) { | ||
| 478 | pr_err("%s: failed to attach to scsi_transport_*", __func__); | ||
| 479 | efct_release_fc_transport(efct_xport_fc_tt); | ||
| 480 | efct_xport_fc_tt = NULL; | ||
| 481 | return -EIO; | ||
| 482 | } | ||
| 483 | |||
| 484 | return 0; | ||
| 485 | } | ||
| 486 | |||
| 487 | void | ||
| 488 | efct_scsi_release_fc_transport(void) | ||
| 489 | { | ||
| 490 | /* detach from scsi_transport_* */ | ||
| 491 | efct_release_fc_transport(efct_xport_fc_tt); | ||
| 492 | efct_xport_fc_tt = NULL; | ||
| 493 | if (efct_vport_fc_tt) | ||
| 494 | efct_release_fc_transport(efct_vport_fc_tt); | ||
| 495 | |||
| 496 | efct_vport_fc_tt = NULL; | ||
| 497 | } | ||
| 498 | |||
| 499 | void | ||
| 500 | efct_xport_detach(struct efct_xport *xport) | ||
| 501 | { | ||
| 502 | struct efct *efct = xport->efct; | ||
| 503 | |||
| 504 | /* free resources associated with target-server and initiator-client */ | ||
| 505 | efct_scsi_tgt_del_device(efct); | ||
| 506 | |||
| 507 | efct_scsi_del_device(efct); | ||
| 508 | |||
| 509 | /*Shutdown FC Statistics timer*/ | ||
| 510 | if (timer_pending(&xport->stats_timer)) | ||
| 511 | del_timer(&xport->stats_timer); | ||
| 512 | |||
| 513 | efct_hw_teardown(&efct->hw); | ||
| 514 | |||
| 515 | efct_xport_delete_debugfs(efct); | ||
| 516 | } | ||
| 517 | |||
| 518 | static void | ||
| 519 | efct_xport_domain_free_cb(struct efc *efc, void *arg) | ||
| 520 | { | ||
| 521 | struct completion *done = arg; | ||
| 522 | |||
| 523 | complete(done); | ||
| 524 | } | ||
| 525 | |||
| 526 | int | ||
| 527 | efct_xport_control(struct efct_xport *xport, enum efct_xport_ctrl cmd, ...) | ||
| 528 | { | ||
| 529 | u32 rc = 0; | ||
| 530 | struct efct *efct = NULL; | ||
| 531 | va_list argp; | ||
| 532 | |||
| 533 | efct = xport->efct; | ||
| 534 | |||
| 535 | switch (cmd) { | ||
| 536 | case EFCT_XPORT_PORT_ONLINE: { | ||
| 537 | /* Bring the port on-line */ | ||
| 538 | rc = efct_hw_port_control(&efct->hw, EFCT_HW_PORT_INIT, 0, | ||
| 539 | NULL, NULL); | ||
| 540 | if (rc) | ||
| 541 | efc_log_err(efct, | ||
| 542 | "%s: Can't init port\n", efct->desc); | ||
| 543 | else | ||
| 544 | xport->configured_link_state = cmd; | ||
| 545 | break; | ||
| 546 | } | ||
| 547 | case EFCT_XPORT_PORT_OFFLINE: { | ||
| 548 | if (efct_hw_port_control(&efct->hw, EFCT_HW_PORT_SHUTDOWN, 0, | ||
| 549 | NULL, NULL)) | ||
| 550 | efc_log_err(efct, "port shutdown failed\n"); | ||
| 551 | else | ||
| 552 | xport->configured_link_state = cmd; | ||
| 553 | break; | ||
| 554 | } | ||
| 555 | |||
| 556 | case EFCT_XPORT_SHUTDOWN: { | ||
| 557 | struct completion done; | ||
| 558 | unsigned long timeout; | ||
| 559 | |||
| 560 | /* if a PHYSDEV reset was performed (e.g. hw dump), will affect | ||
| 561 | * all PCI functions; orderly shutdown won't work, | ||
| 562 | * just force free | ||
| 563 | */ | ||
| 564 | if (sli_reset_required(&efct->hw.sli)) { | ||
| 565 | struct efc_domain *domain = efct->efcport->domain; | ||
| 566 | |||
| 567 | if (domain) | ||
| 568 | efc_domain_cb(efct->efcport, EFC_HW_DOMAIN_LOST, | ||
| 569 | domain); | ||
| 570 | } else { | ||
| 571 | efct_hw_port_control(&efct->hw, EFCT_HW_PORT_SHUTDOWN, | ||
| 572 | 0, NULL, NULL); | ||
| 573 | } | ||
| 574 | |||
| 575 | init_completion(&done); | ||
| 576 | |||
| 577 | efc_register_domain_free_cb(efct->efcport, | ||
| 578 | efct_xport_domain_free_cb, &done); | ||
| 579 | |||
| 580 | efc_log_debug(efct, "Waiting %d seconds for domain shutdown\n", | ||
| 581 | (EFC_SHUTDOWN_TIMEOUT_USEC / 1000000)); | ||
| 582 | |||
| 583 | timeout = usecs_to_jiffies(EFC_SHUTDOWN_TIMEOUT_USEC); | ||
| 584 | if (!wait_for_completion_timeout(&done, timeout)) { | ||
| 585 | efc_log_err(efct, "Domain shutdown timed out!!\n"); | ||
| 586 | WARN_ON(1); | ||
| 587 | } | ||
| 588 | |||
| 589 | efc_register_domain_free_cb(efct->efcport, NULL, NULL); | ||
| 590 | |||
| 591 | /* Free up any saved virtual ports */ | ||
| 592 | efc_vport_del_all(efct->efcport); | ||
| 593 | break; | ||
| 594 | } | ||
| 595 | |||
| 596 | /* | ||
| 597 | * Set wwnn for the port. This will be used instead of the default | ||
| 598 | * provided by FW. | ||
| 599 | */ | ||
| 600 | case EFCT_XPORT_WWNN_SET: { | ||
| 601 | u64 wwnn; | ||
| 602 | |||
| 603 | /* Retrieve arguments */ | ||
| 604 | va_start(argp, cmd); | ||
| 605 | wwnn = va_arg(argp, uint64_t); | ||
| 606 | va_end(argp); | ||
| 607 | |||
| 608 | efc_log_debug(efct, " WWNN %016llx\n", wwnn); | ||
| 609 | xport->req_wwnn = wwnn; | ||
| 610 | |||
| 611 | break; | ||
| 612 | } | ||
| 613 | /* | ||
| 614 | * Set wwpn for the port. This will be used instead of the default | ||
| 615 | * provided by FW. | ||
| 616 | */ | ||
| 617 | case EFCT_XPORT_WWPN_SET: { | ||
| 618 | u64 wwpn; | ||
| 619 | |||
| 620 | /* Retrieve arguments */ | ||
| 621 | va_start(argp, cmd); | ||
| 622 | wwpn = va_arg(argp, uint64_t); | ||
| 623 | va_end(argp); | ||
| 624 | |||
| 625 | efc_log_debug(efct, " WWPN %016llx\n", wwpn); | ||
| 626 | xport->req_wwpn = wwpn; | ||
| 627 | |||
| 628 | break; | ||
| 629 | } | ||
| 630 | |||
| 631 | default: | ||
| 632 | break; | ||
| 633 | } | ||
| 634 | return rc; | ||
| 635 | } | ||
| 636 | |||
| 637 | void | ||
| 638 | efct_xport_free(struct efct_xport *xport) | ||
| 639 | { | ||
| 640 | if (xport) { | ||
| 641 | efct_io_pool_free(xport->io_pool); | ||
| 642 | |||
| 643 | kfree(xport); | ||
| 644 | } | ||
| 645 | } | ||
| 646 | |||
| 647 | void | ||
| 648 | efct_release_fc_transport(struct scsi_transport_template *transport_template) | ||
| 649 | { | ||
| 650 | if (transport_template) | ||
| 651 | pr_err("releasing transport layer\n"); | ||
| 652 | |||
| 653 | /* Releasing FC transport */ | ||
| 654 | fc_release_transport(transport_template); | ||
| 655 | } | ||
| 656 | |||
| 657 | static void | ||
| 658 | efct_xport_remove_host(struct Scsi_Host *shost) | ||
| 659 | { | ||
| 660 | fc_remove_host(shost); | ||
| 661 | } | ||
| 662 | |||
| 663 | void | ||
| 664 | efct_scsi_del_device(struct efct *efct) | ||
| 665 | { | ||
| 666 | if (!efct->shost) | ||
| 667 | return; | ||
| 668 | |||
| 669 | efc_log_debug(efct, "Unregistering with Transport Layer\n"); | ||
| 670 | efct_xport_remove_host(efct->shost); | ||
| 671 | efc_log_debug(efct, "Unregistering with SCSI Midlayer\n"); | ||
| 672 | scsi_remove_host(efct->shost); | ||
| 673 | scsi_host_put(efct->shost); | ||
| 674 | efct->shost = NULL; | ||
| 675 | } | ||
| 676 | |||
| 677 | static void | ||
| 678 | efct_get_host_port_id(struct Scsi_Host *shost) | ||
| 679 | { | ||
| 680 | struct efct_vport *vport = (struct efct_vport *)shost->hostdata; | ||
| 681 | struct efct *efct = vport->efct; | ||
| 682 | struct efc *efc = efct->efcport; | ||
| 683 | struct efc_nport *nport; | ||
| 684 | |||
| 685 | if (efc->domain && efc->domain->nport) { | ||
| 686 | nport = efc->domain->nport; | ||
| 687 | fc_host_port_id(shost) = nport->fc_id; | ||
| 688 | } | ||
| 689 | } | ||
| 690 | |||
| 691 | static void | ||
| 692 | efct_get_host_port_type(struct Scsi_Host *shost) | ||
| 693 | { | ||
| 694 | struct efct_vport *vport = (struct efct_vport *)shost->hostdata; | ||
| 695 | struct efct *efct = vport->efct; | ||
| 696 | struct efc *efc = efct->efcport; | ||
| 697 | int type = FC_PORTTYPE_UNKNOWN; | ||
| 698 | |||
| 699 | if (efc->domain && efc->domain->nport) { | ||
| 700 | if (efc->domain->is_loop) { | ||
| 701 | type = FC_PORTTYPE_LPORT; | ||
| 702 | } else { | ||
| 703 | struct efc_nport *nport = efc->domain->nport; | ||
| 704 | |||
| 705 | if (nport->is_vport) | ||
| 706 | type = FC_PORTTYPE_NPIV; | ||
| 707 | else if (nport->topology == EFC_NPORT_TOPO_P2P) | ||
| 708 | type = FC_PORTTYPE_PTP; | ||
| 709 | else if (nport->topology == EFC_NPORT_TOPO_UNKNOWN) | ||
| 710 | type = FC_PORTTYPE_UNKNOWN; | ||
| 711 | else | ||
| 712 | type = FC_PORTTYPE_NPORT; | ||
| 713 | } | ||
| 714 | } | ||
| 715 | fc_host_port_type(shost) = type; | ||
| 716 | } | ||
| 717 | |||
| 718 | static void | ||
| 719 | efct_get_host_vport_type(struct Scsi_Host *shost) | ||
| 720 | { | ||
| 721 | fc_host_port_type(shost) = FC_PORTTYPE_NPIV; | ||
| 722 | } | ||
| 723 | |||
| 724 | static void | ||
| 725 | efct_get_host_port_state(struct Scsi_Host *shost) | ||
| 726 | { | ||
| 727 | struct efct_vport *vport = (struct efct_vport *)shost->hostdata; | ||
| 728 | struct efct *efct = vport->efct; | ||
| 729 | union efct_xport_stats_u status; | ||
| 730 | int rc; | ||
| 731 | |||
| 732 | rc = efct_xport_status(efct->xport, EFCT_XPORT_PORT_STATUS, &status); | ||
| 733 | if ((!rc) && (status.value == EFCT_XPORT_PORT_ONLINE)) | ||
| 734 | fc_host_port_state(shost) = FC_PORTSTATE_ONLINE; | ||
| 735 | else | ||
| 736 | fc_host_port_state(shost) = FC_PORTSTATE_OFFLINE; | ||
| 737 | } | ||
| 738 | |||
| 739 | static void | ||
| 740 | efct_get_host_speed(struct Scsi_Host *shost) | ||
| 741 | { | ||
| 742 | struct efct_vport *vport = (struct efct_vport *)shost->hostdata; | ||
| 743 | struct efct *efct = vport->efct; | ||
| 744 | struct efc *efc = efct->efcport; | ||
| 745 | union efct_xport_stats_u speed; | ||
| 746 | u32 fc_speed = FC_PORTSPEED_UNKNOWN; | ||
| 747 | int rc; | ||
| 748 | |||
| 749 | if (!efc->domain || !efc->domain->nport) { | ||
| 750 | fc_host_speed(shost) = fc_speed; | ||
| 751 | return; | ||
| 752 | } | ||
| 753 | |||
| 754 | rc = efct_xport_status(efct->xport, EFCT_XPORT_LINK_SPEED, &speed); | ||
| 755 | if (!rc) { | ||
| 756 | switch (speed.value) { | ||
| 757 | case 1000: | ||
| 758 | fc_speed = FC_PORTSPEED_1GBIT; | ||
| 759 | break; | ||
| 760 | case 2000: | ||
| 761 | fc_speed = FC_PORTSPEED_2GBIT; | ||
| 762 | break; | ||
| 763 | case 4000: | ||
| 764 | fc_speed = FC_PORTSPEED_4GBIT; | ||
| 765 | break; | ||
| 766 | case 8000: | ||
| 767 | fc_speed = FC_PORTSPEED_8GBIT; | ||
| 768 | break; | ||
| 769 | case 10000: | ||
| 770 | fc_speed = FC_PORTSPEED_10GBIT; | ||
| 771 | break; | ||
| 772 | case 16000: | ||
| 773 | fc_speed = FC_PORTSPEED_16GBIT; | ||
| 774 | break; | ||
| 775 | case 32000: | ||
| 776 | fc_speed = FC_PORTSPEED_32GBIT; | ||
| 777 | break; | ||
| 778 | case 64000: | ||
| 779 | fc_speed = FC_PORTSPEED_64GBIT; | ||
| 780 | break; | ||
| 781 | case 128000: | ||
| 782 | fc_speed = FC_PORTSPEED_128GBIT; | ||
| 783 | break; | ||
| 784 | } | ||
| 785 | } | ||
| 786 | |||
| 787 | fc_host_speed(shost) = fc_speed; | ||
| 788 | } | ||
| 789 | |||
| 790 | static void | ||
| 791 | efct_get_host_fabric_name(struct Scsi_Host *shost) | ||
| 792 | { | ||
| 793 | struct efct_vport *vport = (struct efct_vport *)shost->hostdata; | ||
| 794 | struct efct *efct = vport->efct; | ||
| 795 | struct efc *efc = efct->efcport; | ||
| 796 | |||
| 797 | if (efc->domain) { | ||
| 798 | struct fc_els_flogi *sp = | ||
| 799 | (struct fc_els_flogi *) | ||
| 800 | efc->domain->flogi_service_params; | ||
| 801 | |||
| 802 | fc_host_fabric_name(shost) = be64_to_cpu(sp->fl_wwnn); | ||
| 803 | } | ||
| 804 | } | ||
| 805 | |||
| 806 | static struct fc_host_statistics * | ||
| 807 | efct_get_stats(struct Scsi_Host *shost) | ||
| 808 | { | ||
| 809 | struct efct_vport *vport = (struct efct_vport *)shost->hostdata; | ||
| 810 | struct efct *efct = vport->efct; | ||
| 811 | union efct_xport_stats_u stats; | ||
| 812 | struct efct_xport *xport = efct->xport; | ||
| 813 | int rc = 0; | ||
| 814 | |||
| 815 | rc = efct_xport_status(xport, EFCT_XPORT_LINK_STATISTICS, &stats); | ||
| 816 | if (rc) { | ||
| 817 | pr_err("efct_xport_status returned non 0 - %d\n", rc); | ||
| 818 | return NULL; | ||
| 819 | } | ||
| 820 | |||
| 821 | vport->fc_host_stats.loss_of_sync_count = | ||
| 822 | stats.stats.link_stats.loss_of_sync_error_count; | ||
| 823 | vport->fc_host_stats.link_failure_count = | ||
| 824 | stats.stats.link_stats.link_failure_error_count; | ||
| 825 | vport->fc_host_stats.prim_seq_protocol_err_count = | ||
| 826 | stats.stats.link_stats.primitive_sequence_error_count; | ||
| 827 | vport->fc_host_stats.invalid_tx_word_count = | ||
| 828 | stats.stats.link_stats.invalid_transmission_word_error_count; | ||
| 829 | vport->fc_host_stats.invalid_crc_count = | ||
| 830 | stats.stats.link_stats.crc_error_count; | ||
| 831 | /* mbox returns kbyte count so we need to convert to words */ | ||
| 832 | vport->fc_host_stats.tx_words = | ||
| 833 | stats.stats.host_stats.transmit_kbyte_count * 256; | ||
| 834 | /* mbox returns kbyte count so we need to convert to words */ | ||
| 835 | vport->fc_host_stats.rx_words = | ||
| 836 | stats.stats.host_stats.receive_kbyte_count * 256; | ||
| 837 | vport->fc_host_stats.tx_frames = | ||
| 838 | stats.stats.host_stats.transmit_frame_count; | ||
| 839 | vport->fc_host_stats.rx_frames = | ||
| 840 | stats.stats.host_stats.receive_frame_count; | ||
| 841 | |||
| 842 | vport->fc_host_stats.fcp_input_requests = | ||
| 843 | xport->fcp_stats.input_requests; | ||
| 844 | vport->fc_host_stats.fcp_output_requests = | ||
| 845 | xport->fcp_stats.output_requests; | ||
| 846 | vport->fc_host_stats.fcp_output_megabytes = | ||
| 847 | xport->fcp_stats.output_bytes >> 20; | ||
| 848 | vport->fc_host_stats.fcp_input_megabytes = | ||
| 849 | xport->fcp_stats.input_bytes >> 20; | ||
| 850 | vport->fc_host_stats.fcp_control_requests = | ||
| 851 | xport->fcp_stats.control_requests; | ||
| 852 | |||
| 853 | return &vport->fc_host_stats; | ||
| 854 | } | ||
| 855 | |||
| 856 | static void | ||
| 857 | efct_reset_stats(struct Scsi_Host *shost) | ||
| 858 | { | ||
| 859 | struct efct_vport *vport = (struct efct_vport *)shost->hostdata; | ||
| 860 | struct efct *efct = vport->efct; | ||
| 861 | /* argument has no purpose for this action */ | ||
| 862 | union efct_xport_stats_u dummy; | ||
| 863 | int rc; | ||
| 864 | |||
| 865 | rc = efct_xport_status(efct->xport, EFCT_XPORT_LINK_STAT_RESET, &dummy); | ||
| 866 | if (rc) | ||
| 867 | pr_err("efct_xport_status returned non 0 - %d\n", rc); | ||
| 868 | } | ||
| 869 | |||
| 870 | static int | ||
| 871 | efct_issue_lip(struct Scsi_Host *shost) | ||
| 872 | { | ||
| 873 | struct efct_vport *vport = | ||
| 874 | shost ? (struct efct_vport *)shost->hostdata : NULL; | ||
| 875 | struct efct *efct = vport ? vport->efct : NULL; | ||
| 876 | |||
| 877 | if (!shost || !vport || !efct) { | ||
| 878 | pr_err("%s: shost=%p vport=%p efct=%p\n", __func__, | ||
| 879 | shost, vport, efct); | ||
| 880 | return -EPERM; | ||
| 881 | } | ||
| 882 | |||
| 883 | /* | ||
| 884 | * Bring the link down gracefully then re-init the link. | ||
| 885 | * The firmware will re-initialize the Fibre Channel interface as | ||
| 886 | * required. It does not issue a LIP. | ||
| 887 | */ | ||
| 888 | |||
| 889 | if (efct_xport_control(efct->xport, EFCT_XPORT_PORT_OFFLINE)) | ||
| 890 | efc_log_debug(efct, "EFCT_XPORT_PORT_OFFLINE failed\n"); | ||
| 891 | |||
| 892 | if (efct_xport_control(efct->xport, EFCT_XPORT_PORT_ONLINE)) | ||
| 893 | efc_log_debug(efct, "EFCT_XPORT_PORT_ONLINE failed\n"); | ||
| 894 | |||
| 895 | return 0; | ||
| 896 | } | ||
| 897 | |||
| 898 | struct efct_vport * | ||
| 899 | efct_scsi_new_vport(struct efct *efct, struct device *dev) | ||
| 900 | { | ||
| 901 | struct Scsi_Host *shost = NULL; | ||
| 902 | int error = 0; | ||
| 903 | struct efct_vport *vport = NULL; | ||
| 904 | |||
| 905 | shost = scsi_host_alloc(&efct_template, sizeof(*vport)); | ||
| 906 | if (!shost) { | ||
| 907 | efc_log_err(efct, "failed to allocate Scsi_Host struct\n"); | ||
| 908 | return NULL; | ||
| 909 | } | ||
| 910 | |||
| 911 | /* save efct information to shost LLD-specific space */ | ||
| 912 | vport = (struct efct_vport *)shost->hostdata; | ||
| 913 | vport->efct = efct; | ||
| 914 | vport->is_vport = true; | ||
| 915 | |||
| 916 | shost->can_queue = efct->hw.config.n_io; | ||
| 917 | shost->max_cmd_len = 16; /* 16-byte CDBs */ | ||
| 918 | shost->max_id = 0xffff; | ||
| 919 | shost->max_lun = 0xffffffff; | ||
| 920 | |||
| 921 | /* can only accept (from mid-layer) as many SGEs as we've pre-regited*/ | ||
| 922 | shost->sg_tablesize = sli_get_max_sgl(&efct->hw.sli); | ||
| 923 | |||
| 924 | /* attach FC Transport template to shost */ | ||
| 925 | shost->transportt = efct_vport_fc_tt; | ||
| 926 | efc_log_debug(efct, "vport transport template=%p\n", | ||
| 927 | efct_vport_fc_tt); | ||
| 928 | |||
| 929 | /* get pci_dev structure and add host to SCSI ML */ | ||
| 930 | error = scsi_add_host_with_dma(shost, dev, &efct->pci->dev); | ||
| 931 | if (error) { | ||
| 932 | efc_log_debug(efct, "failed scsi_add_host_with_dma\n"); | ||
| 933 | return NULL; | ||
| 934 | } | ||
| 935 | |||
| 936 | /* Set symbolic name for host port */ | ||
| 937 | snprintf(fc_host_symbolic_name(shost), | ||
| 938 | sizeof(fc_host_symbolic_name(shost)), | ||
| 939 | "Emulex %s FV%s DV%s", efct->model, efct->hw.sli.fw_name[0], | ||
| 940 | EFCT_DRIVER_VERSION); | ||
| 941 | |||
| 942 | /* Set host port supported classes */ | ||
| 943 | fc_host_supported_classes(shost) = FC_COS_CLASS3; | ||
| 944 | |||
| 945 | fc_host_supported_speeds(shost) = efct_get_link_supported_speeds(efct); | ||
| 946 | vport->shost = shost; | ||
| 947 | |||
| 948 | return vport; | ||
| 949 | } | ||
| 950 | |||
| 951 | int efct_scsi_del_vport(struct efct *efct, struct Scsi_Host *shost) | ||
| 952 | { | ||
| 953 | if (shost) { | ||
| 954 | efc_log_debug(efct, | ||
| 955 | "Unregistering vport with Transport Layer\n"); | ||
| 956 | efct_xport_remove_host(shost); | ||
| 957 | efc_log_debug(efct, "Unregistering vport with SCSI Midlayer\n"); | ||
| 958 | scsi_remove_host(shost); | ||
| 959 | scsi_host_put(shost); | ||
| 960 | return 0; | ||
| 961 | } | ||
| 962 | return -EIO; | ||
| 963 | } | ||
| 964 | |||
| 965 | static int | ||
| 966 | efct_vport_create(struct fc_vport *fc_vport, bool disable) | ||
| 967 | { | ||
| 968 | struct Scsi_Host *shost = fc_vport ? fc_vport->shost : NULL; | ||
| 969 | struct efct_vport *pport = shost ? | ||
| 970 | (struct efct_vport *)shost->hostdata : | ||
| 971 | NULL; | ||
| 972 | struct efct *efct = pport ? pport->efct : NULL; | ||
| 973 | struct efct_vport *vport = NULL; | ||
| 974 | |||
| 975 | if (!fc_vport || !shost || !efct) | ||
| 976 | goto fail; | ||
| 977 | |||
| 978 | vport = efct_scsi_new_vport(efct, &fc_vport->dev); | ||
| 979 | if (!vport) { | ||
| 980 | efc_log_err(efct, "failed to create vport\n"); | ||
| 981 | goto fail; | ||
| 982 | } | ||
| 983 | |||
| 984 | vport->fc_vport = fc_vport; | ||
| 985 | vport->npiv_wwpn = fc_vport->port_name; | ||
| 986 | vport->npiv_wwnn = fc_vport->node_name; | ||
| 987 | fc_host_node_name(vport->shost) = vport->npiv_wwnn; | ||
| 988 | fc_host_port_name(vport->shost) = vport->npiv_wwpn; | ||
| 989 | *(struct efct_vport **)fc_vport->dd_data = vport; | ||
| 990 | |||
| 991 | return 0; | ||
| 992 | |||
| 993 | fail: | ||
| 994 | return -EIO; | ||
| 995 | } | ||
| 996 | |||
| 997 | static int | ||
| 998 | efct_vport_delete(struct fc_vport *fc_vport) | ||
| 999 | { | ||
| 1000 | struct efct_vport *vport = *(struct efct_vport **)fc_vport->dd_data; | ||
| 1001 | struct Scsi_Host *shost = vport ? vport->shost : NULL; | ||
| 1002 | struct efct *efct = vport ? vport->efct : NULL; | ||
| 1003 | int rc; | ||
| 1004 | |||
| 1005 | rc = efct_scsi_del_vport(efct, shost); | ||
| 1006 | |||
| 1007 | if (rc) | ||
| 1008 | pr_err("%s: vport delete failed\n", __func__); | ||
| 1009 | |||
| 1010 | return rc; | ||
| 1011 | } | ||
| 1012 | |||
| 1013 | static int | ||
| 1014 | efct_vport_disable(struct fc_vport *fc_vport, bool disable) | ||
| 1015 | { | ||
| 1016 | return 0; | ||
| 1017 | } | ||
| 1018 | |||
| 1019 | static struct fc_function_template efct_xport_functions = { | ||
| 1020 | .get_host_port_id = efct_get_host_port_id, | ||
| 1021 | .get_host_port_type = efct_get_host_port_type, | ||
| 1022 | .get_host_port_state = efct_get_host_port_state, | ||
| 1023 | .get_host_speed = efct_get_host_speed, | ||
| 1024 | .get_host_fabric_name = efct_get_host_fabric_name, | ||
| 1025 | |||
| 1026 | .get_fc_host_stats = efct_get_stats, | ||
| 1027 | .reset_fc_host_stats = efct_reset_stats, | ||
| 1028 | |||
| 1029 | .issue_fc_host_lip = efct_issue_lip, | ||
| 1030 | |||
| 1031 | .vport_disable = efct_vport_disable, | ||
| 1032 | |||
| 1033 | /* allocation lengths for host-specific data */ | ||
| 1034 | .dd_fcrport_size = sizeof(struct efct_rport_data), | ||
| 1035 | .dd_fcvport_size = 128, /* should be sizeof(...) */ | ||
| 1036 | |||
| 1037 | /* remote port fixed attributes */ | ||
| 1038 | .show_rport_maxframe_size = 1, | ||
| 1039 | .show_rport_supported_classes = 1, | ||
| 1040 | .show_rport_dev_loss_tmo = 1, | ||
| 1041 | |||
| 1042 | /* target dynamic attributes */ | ||
| 1043 | .show_starget_node_name = 1, | ||
| 1044 | .show_starget_port_name = 1, | ||
| 1045 | .show_starget_port_id = 1, | ||
| 1046 | |||
| 1047 | /* host fixed attributes */ | ||
| 1048 | .show_host_node_name = 1, | ||
| 1049 | .show_host_port_name = 1, | ||
| 1050 | .show_host_supported_classes = 1, | ||
| 1051 | .show_host_supported_fc4s = 1, | ||
| 1052 | .show_host_supported_speeds = 1, | ||
| 1053 | .show_host_maxframe_size = 1, | ||
| 1054 | |||
| 1055 | /* host dynamic attributes */ | ||
| 1056 | .show_host_port_id = 1, | ||
| 1057 | .show_host_port_type = 1, | ||
| 1058 | .show_host_port_state = 1, | ||
| 1059 | /* active_fc4s is shown but doesn't change (thus no get function) */ | ||
| 1060 | .show_host_active_fc4s = 1, | ||
| 1061 | .show_host_speed = 1, | ||
| 1062 | .show_host_fabric_name = 1, | ||
| 1063 | .show_host_symbolic_name = 1, | ||
| 1064 | .vport_create = efct_vport_create, | ||
| 1065 | .vport_delete = efct_vport_delete, | ||
| 1066 | }; | ||
| 1067 | |||
| 1068 | static struct fc_function_template efct_vport_functions = { | ||
| 1069 | .get_host_port_id = efct_get_host_port_id, | ||
| 1070 | .get_host_port_type = efct_get_host_vport_type, | ||
| 1071 | .get_host_port_state = efct_get_host_port_state, | ||
| 1072 | .get_host_speed = efct_get_host_speed, | ||
| 1073 | .get_host_fabric_name = efct_get_host_fabric_name, | ||
| 1074 | |||
| 1075 | .get_fc_host_stats = efct_get_stats, | ||
| 1076 | .reset_fc_host_stats = efct_reset_stats, | ||
| 1077 | |||
| 1078 | .issue_fc_host_lip = efct_issue_lip, | ||
| 1079 | |||
| 1080 | /* allocation lengths for host-specific data */ | ||
| 1081 | .dd_fcrport_size = sizeof(struct efct_rport_data), | ||
| 1082 | .dd_fcvport_size = 128, /* should be sizeof(...) */ | ||
| 1083 | |||
| 1084 | /* remote port fixed attributes */ | ||
| 1085 | .show_rport_maxframe_size = 1, | ||
| 1086 | .show_rport_supported_classes = 1, | ||
| 1087 | .show_rport_dev_loss_tmo = 1, | ||
| 1088 | |||
| 1089 | /* target dynamic attributes */ | ||
| 1090 | .show_starget_node_name = 1, | ||
| 1091 | .show_starget_port_name = 1, | ||
| 1092 | .show_starget_port_id = 1, | ||
| 1093 | |||
| 1094 | /* host fixed attributes */ | ||
| 1095 | .show_host_node_name = 1, | ||
| 1096 | .show_host_port_name = 1, | ||
| 1097 | .show_host_supported_classes = 1, | ||
| 1098 | .show_host_supported_fc4s = 1, | ||
| 1099 | .show_host_supported_speeds = 1, | ||
| 1100 | .show_host_maxframe_size = 1, | ||
| 1101 | |||
| 1102 | /* host dynamic attributes */ | ||
| 1103 | .show_host_port_id = 1, | ||
| 1104 | .show_host_port_type = 1, | ||
| 1105 | .show_host_port_state = 1, | ||
| 1106 | /* active_fc4s is shown but doesn't change (thus no get function) */ | ||
| 1107 | .show_host_active_fc4s = 1, | ||
| 1108 | .show_host_speed = 1, | ||
| 1109 | .show_host_fabric_name = 1, | ||
| 1110 | .show_host_symbolic_name = 1, | ||
| 1111 | }; | ||
| @@ -0,0 +1,186 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #if !defined(__EFCT_XPORT_H__) | ||
| 8 | #define __EFCT_XPORT_H__ | ||
| 9 | |||
| 10 | enum efct_xport_ctrl { | ||
| 11 | EFCT_XPORT_PORT_ONLINE = 1, | ||
| 12 | EFCT_XPORT_PORT_OFFLINE, | ||
| 13 | EFCT_XPORT_SHUTDOWN, | ||
| 14 | EFCT_XPORT_POST_NODE_EVENT, | ||
| 15 | EFCT_XPORT_WWNN_SET, | ||
| 16 | EFCT_XPORT_WWPN_SET, | ||
| 17 | }; | ||
| 18 | |||
| 19 | enum efct_xport_status { | ||
| 20 | EFCT_XPORT_PORT_STATUS, | ||
| 21 | EFCT_XPORT_CONFIG_PORT_STATUS, | ||
| 22 | EFCT_XPORT_LINK_SPEED, | ||
| 23 | EFCT_XPORT_IS_SUPPORTED_LINK_SPEED, | ||
| 24 | EFCT_XPORT_LINK_STATISTICS, | ||
| 25 | EFCT_XPORT_LINK_STAT_RESET, | ||
| 26 | EFCT_XPORT_IS_QUIESCED | ||
| 27 | }; | ||
| 28 | |||
| 29 | struct efct_xport_link_stats { | ||
| 30 | bool rec; | ||
| 31 | bool gec; | ||
| 32 | bool w02of; | ||
| 33 | bool w03of; | ||
| 34 | bool w04of; | ||
| 35 | bool w05of; | ||
| 36 | bool w06of; | ||
| 37 | bool w07of; | ||
| 38 | bool w08of; | ||
| 39 | bool w09of; | ||
| 40 | bool w10of; | ||
| 41 | bool w11of; | ||
| 42 | bool w12of; | ||
| 43 | bool w13of; | ||
| 44 | bool w14of; | ||
| 45 | bool w15of; | ||
| 46 | bool w16of; | ||
| 47 | bool w17of; | ||
| 48 | bool w18of; | ||
| 49 | bool w19of; | ||
| 50 | bool w20of; | ||
| 51 | bool w21of; | ||
| 52 | bool clrc; | ||
| 53 | bool clof1; | ||
| 54 | u32 link_failure_error_count; | ||
| 55 | u32 loss_of_sync_error_count; | ||
| 56 | u32 loss_of_signal_error_count; | ||
| 57 | u32 primitive_sequence_error_count; | ||
| 58 | u32 invalid_transmission_word_error_count; | ||
| 59 | u32 crc_error_count; | ||
| 60 | u32 primitive_sequence_event_timeout_count; | ||
| 61 | u32 elastic_buffer_overrun_error_count; | ||
| 62 | u32 arbitration_fc_al_timeout_count; | ||
| 63 | u32 advertised_receive_bufftor_to_buffer_credit; | ||
| 64 | u32 current_receive_buffer_to_buffer_credit; | ||
| 65 | u32 advertised_transmit_buffer_to_buffer_credit; | ||
| 66 | u32 current_transmit_buffer_to_buffer_credit; | ||
| 67 | u32 received_eofa_count; | ||
| 68 | u32 received_eofdti_count; | ||
| 69 | u32 received_eofni_count; | ||
| 70 | u32 received_soff_count; | ||
| 71 | u32 received_dropped_no_aer_count; | ||
| 72 | u32 received_dropped_no_available_rpi_resources_count; | ||
| 73 | u32 received_dropped_no_available_xri_resources_count; | ||
| 74 | }; | ||
| 75 | |||
| 76 | struct efct_xport_host_stats { | ||
| 77 | bool cc; | ||
| 78 | u32 transmit_kbyte_count; | ||
| 79 | u32 receive_kbyte_count; | ||
| 80 | u32 transmit_frame_count; | ||
| 81 | u32 receive_frame_count; | ||
| 82 | u32 transmit_sequence_count; | ||
| 83 | u32 receive_sequence_count; | ||
| 84 | u32 total_exchanges_originator; | ||
| 85 | u32 total_exchanges_responder; | ||
| 86 | u32 receive_p_bsy_count; | ||
| 87 | u32 receive_f_bsy_count; | ||
| 88 | u32 dropped_frames_due_to_no_rq_buffer_count; | ||
| 89 | u32 empty_rq_timeout_count; | ||
| 90 | u32 dropped_frames_due_to_no_xri_count; | ||
| 91 | u32 empty_xri_pool_count; | ||
| 92 | }; | ||
| 93 | |||
| 94 | struct efct_xport_host_statistics { | ||
| 95 | struct completion done; | ||
| 96 | struct efct_xport_link_stats link_stats; | ||
| 97 | struct efct_xport_host_stats host_stats; | ||
| 98 | }; | ||
| 99 | |||
| 100 | union efct_xport_stats_u { | ||
| 101 | u32 value; | ||
| 102 | struct efct_xport_host_statistics stats; | ||
| 103 | }; | ||
| 104 | |||
| 105 | struct efct_xport_fcp_stats { | ||
| 106 | u64 input_bytes; | ||
| 107 | u64 output_bytes; | ||
| 108 | u64 input_requests; | ||
| 109 | u64 output_requests; | ||
| 110 | u64 control_requests; | ||
| 111 | }; | ||
| 112 | |||
| 113 | struct efct_xport { | ||
| 114 | struct efct *efct; | ||
| 115 | /* wwpn requested by user for primary nport */ | ||
| 116 | u64 req_wwpn; | ||
| 117 | /* wwnn requested by user for primary nport */ | ||
| 118 | u64 req_wwnn; | ||
| 119 | |||
| 120 | /* Nodes */ | ||
| 121 | /* number of allocated nodes */ | ||
| 122 | u32 nodes_count; | ||
| 123 | /* used to track how often IO pool is empty */ | ||
| 124 | atomic_t io_alloc_failed_count; | ||
| 125 | /* array of pointers to nodes */ | ||
| 126 | struct efc_node **nodes; | ||
| 127 | |||
| 128 | /* Io pool and counts */ | ||
| 129 | /* pointer to IO pool */ | ||
| 130 | struct efct_io_pool *io_pool; | ||
| 131 | /* lock for io_pending_list */ | ||
| 132 | spinlock_t io_pending_lock; | ||
| 133 | /* list of IOs waiting for HW resources | ||
| 134 | * lock: xport->io_pending_lock | ||
| 135 | * link: efct_io_s->io_pending_link | ||
| 136 | */ | ||
| 137 | struct list_head io_pending_list; | ||
| 138 | /* count of totals IOS allocated */ | ||
| 139 | atomic_t io_total_alloc; | ||
| 140 | /* count of totals IOS free'd */ | ||
| 141 | atomic_t io_total_free; | ||
| 142 | /* count of totals IOS that were pended */ | ||
| 143 | atomic_t io_total_pending; | ||
| 144 | /* count of active IOS */ | ||
| 145 | atomic_t io_active_count; | ||
| 146 | /* count of pending IOS */ | ||
| 147 | atomic_t io_pending_count; | ||
| 148 | /* non-zero if efct_scsi_check_pending is executing */ | ||
| 149 | atomic_t io_pending_recursing; | ||
| 150 | |||
| 151 | /* Port */ | ||
| 152 | /* requested link state */ | ||
| 153 | u32 configured_link_state; | ||
| 154 | |||
| 155 | /* Timer for Statistics */ | ||
| 156 | struct timer_list stats_timer; | ||
| 157 | union efct_xport_stats_u fc_xport_stats; | ||
| 158 | struct efct_xport_fcp_stats fcp_stats; | ||
| 159 | }; | ||
| 160 | |||
| 161 | struct efct_rport_data { | ||
| 162 | struct efc_node *node; | ||
| 163 | }; | ||
| 164 | |||
| 165 | struct efct_xport * | ||
| 166 | efct_xport_alloc(struct efct *efct); | ||
| 167 | int | ||
| 168 | efct_xport_attach(struct efct_xport *xport); | ||
| 169 | int | ||
| 170 | efct_xport_initialize(struct efct_xport *xport); | ||
| 171 | void | ||
| 172 | efct_xport_detach(struct efct_xport *xport); | ||
| 173 | int | ||
| 174 | efct_xport_control(struct efct_xport *xport, enum efct_xport_ctrl cmd, ...); | ||
| 175 | int | ||
| 176 | efct_xport_status(struct efct_xport *xport, enum efct_xport_status cmd, | ||
| 177 | union efct_xport_stats_u *result); | ||
| 178 | void | ||
| 179 | efct_xport_free(struct efct_xport *xport); | ||
| 180 | |||
| 181 | struct scsi_transport_template *efct_attach_fc_transport(void); | ||
| 182 | struct scsi_transport_template *efct_attach_vport_fc_transport(void); | ||
| 183 | void | ||
| 184 | efct_release_fc_transport(struct scsi_transport_template *transport_template); | ||
| 185 | |||
| 186 | #endif /* __EFCT_XPORT_H__ */ | ||
| @@ -0,0 +1,37 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef __EFC_COMMON_H__ | ||
| 8 | #define __EFC_COMMON_H__ | ||
| 9 | |||
| 10 | #include <linux/pci.h> | ||
| 11 | |||
| 12 | struct efc_dma { | ||
| 13 | void *virt; | ||
| 14 | void *alloc; | ||
| 15 | dma_addr_t phys; | ||
| 16 | |||
| 17 | size_t size; | ||
| 18 | size_t len; | ||
| 19 | struct pci_dev *pdev; | ||
| 20 | }; | ||
| 21 | |||
| 22 | #define efc_log_crit(efc, fmt, args...) \ | ||
| 23 | dev_crit(&((efc)->pci)->dev, fmt, ##args) | ||
| 24 | |||
| 25 | #define efc_log_err(efc, fmt, args...) \ | ||
| 26 | dev_err(&((efc)->pci)->dev, fmt, ##args) | ||
| 27 | |||
| 28 | #define efc_log_warn(efc, fmt, args...) \ | ||
| 29 | dev_warn(&((efc)->pci)->dev, fmt, ##args) | ||
| 30 | |||
| 31 | #define efc_log_info(efc, fmt, args...) \ | ||
| 32 | dev_info(&((efc)->pci)->dev, fmt, ##args) | ||
| 33 | |||
| 34 | #define efc_log_debug(efc, fmt, args...) \ | ||
| 35 | dev_dbg(&((efc)->pci)->dev, fmt, ##args) | ||
| 36 | |||
| 37 | #endif /* __EFC_COMMON_H__ */ | ||
| @@ -0,0 +1,52 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef __EFC_H__ | ||
| 8 | #define __EFC_H__ | ||
| 9 | |||
| 10 | #include "../include/efc_common.h" | ||
| 11 | #include "efclib.h" | ||
| 12 | #include "efc_sm.h" | ||
| 13 | #include "efc_cmds.h" | ||
| 14 | #include "efc_domain.h" | ||
| 15 | #include "efc_nport.h" | ||
| 16 | #include "efc_node.h" | ||
| 17 | #include "efc_fabric.h" | ||
| 18 | #include "efc_device.h" | ||
| 19 | #include "efc_els.h" | ||
| 20 | |||
| 21 | #define EFC_MAX_REMOTE_NODES 2048 | ||
| 22 | #define NODE_SPARAMS_SIZE 256 | ||
| 23 | |||
| 24 | enum efc_scsi_del_initiator_reason { | ||
| 25 | EFC_SCSI_INITIATOR_DELETED, | ||
| 26 | EFC_SCSI_INITIATOR_MISSING, | ||
| 27 | }; | ||
| 28 | |||
| 29 | enum efc_scsi_del_target_reason { | ||
| 30 | EFC_SCSI_TARGET_DELETED, | ||
| 31 | EFC_SCSI_TARGET_MISSING, | ||
| 32 | }; | ||
| 33 | |||
| 34 | #define EFC_FC_ELS_DEFAULT_RETRIES 3 | ||
| 35 | |||
| 36 | #define domain_sm_trace(domain) \ | ||
| 37 | efc_log_debug(domain->efc, "[domain:%s] %-20s %-20s\n", \ | ||
| 38 | domain->display_name, __func__, efc_sm_event_name(evt)) \ | ||
| 39 | |||
| 40 | #define domain_trace(domain, fmt, ...) \ | ||
| 41 | efc_log_debug(domain->efc, \ | ||
| 42 | "[%s]" fmt, domain->display_name, ##__VA_ARGS__) \ | ||
| 43 | |||
| 44 | #define node_sm_trace() \ | ||
| 45 | efc_log_debug(node->efc, "[%s] %-20s %-20s\n", \ | ||
| 46 | node->display_name, __func__, efc_sm_event_name(evt)) \ | ||
| 47 | |||
| 48 | #define nport_sm_trace(nport) \ | ||
| 49 | efc_log_debug(nport->efc, \ | ||
| 50 | "[%s] %-20s\n", nport->display_name, efc_sm_event_name(evt)) \ | ||
| 51 | |||
| 52 | #endif /* __EFC_H__ */ | ||
| @@ -0,0 +1,777 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include "efclib.h" | ||
| 8 | #include "../libefc_sli/sli4.h" | ||
| 9 | #include "efc_cmds.h" | ||
| 10 | #include "efc_sm.h" | ||
| 11 | |||
| 12 | static void | ||
| 13 | efc_nport_free_resources(struct efc_nport *nport, int evt, void *data) | ||
| 14 | { | ||
| 15 | struct efc *efc = nport->efc; | ||
| 16 | |||
| 17 | /* Clear the nport attached flag */ | ||
| 18 | nport->attached = false; | ||
| 19 | |||
| 20 | /* Free the service parameters buffer */ | ||
| 21 | if (nport->dma.virt) { | ||
| 22 | dma_free_coherent(&efc->pci->dev, nport->dma.size, | ||
| 23 | nport->dma.virt, nport->dma.phys); | ||
| 24 | memset(&nport->dma, 0, sizeof(struct efc_dma)); | ||
| 25 | } | ||
| 26 | |||
| 27 | /* Free the SLI resources */ | ||
| 28 | sli_resource_free(efc->sli, SLI4_RSRC_VPI, nport->indicator); | ||
| 29 | |||
| 30 | efc_nport_cb(efc, evt, nport); | ||
| 31 | } | ||
| 32 | |||
| 33 | static int | ||
| 34 | efc_nport_get_mbox_status(struct efc_nport *nport, u8 *mqe, int status) | ||
| 35 | { | ||
| 36 | struct efc *efc = nport->efc; | ||
| 37 | struct sli4_mbox_command_header *hdr = | ||
| 38 | (struct sli4_mbox_command_header *)mqe; | ||
| 39 | |||
| 40 | if (status || le16_to_cpu(hdr->status)) { | ||
| 41 | efc_log_debug(efc, "bad status vpi=%#x st=%x hdr=%x\n", | ||
| 42 | nport->indicator, status, le16_to_cpu(hdr->status)); | ||
| 43 | return -EIO; | ||
| 44 | } | ||
| 45 | |||
| 46 | return 0; | ||
| 47 | } | ||
| 48 | |||
| 49 | static int | ||
| 50 | efc_nport_free_unreg_vpi_cb(struct efc *efc, int status, u8 *mqe, void *arg) | ||
| 51 | { | ||
| 52 | struct efc_nport *nport = arg; | ||
| 53 | int evt = EFC_EVT_NPORT_FREE_OK; | ||
| 54 | int rc; | ||
| 55 | |||
| 56 | rc = efc_nport_get_mbox_status(nport, mqe, status); | ||
| 57 | if (rc) | ||
| 58 | evt = EFC_EVT_NPORT_FREE_FAIL; | ||
| 59 | |||
| 60 | efc_nport_free_resources(nport, evt, mqe); | ||
| 61 | return rc; | ||
| 62 | } | ||
| 63 | |||
| 64 | static void | ||
| 65 | efc_nport_free_unreg_vpi(struct efc_nport *nport) | ||
| 66 | { | ||
| 67 | struct efc *efc = nport->efc; | ||
| 68 | int rc; | ||
| 69 | u8 data[SLI4_BMBX_SIZE]; | ||
| 70 | |||
| 71 | rc = sli_cmd_unreg_vpi(efc->sli, data, nport->indicator, | ||
| 72 | SLI4_UNREG_TYPE_PORT); | ||
| 73 | if (rc) { | ||
| 74 | efc_log_err(efc, "UNREG_VPI format failure\n"); | ||
| 75 | efc_nport_free_resources(nport, EFC_EVT_NPORT_FREE_FAIL, data); | ||
| 76 | return; | ||
| 77 | } | ||
| 78 | |||
| 79 | rc = efc->tt.issue_mbox_rqst(efc->base, data, | ||
| 80 | efc_nport_free_unreg_vpi_cb, nport); | ||
| 81 | if (rc) { | ||
| 82 | efc_log_err(efc, "UNREG_VPI command failure\n"); | ||
| 83 | efc_nport_free_resources(nport, EFC_EVT_NPORT_FREE_FAIL, data); | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | static void | ||
| 88 | efc_nport_send_evt(struct efc_nport *nport, int evt, void *data) | ||
| 89 | { | ||
| 90 | struct efc *efc = nport->efc; | ||
| 91 | |||
| 92 | /* Now inform the registered callbacks */ | ||
| 93 | efc_nport_cb(efc, evt, nport); | ||
| 94 | |||
| 95 | /* Set the nport attached flag */ | ||
| 96 | if (evt == EFC_EVT_NPORT_ATTACH_OK) | ||
| 97 | nport->attached = true; | ||
| 98 | |||
| 99 | /* If there is a pending free request, then handle it now */ | ||
| 100 | if (nport->free_req_pending) | ||
| 101 | efc_nport_free_unreg_vpi(nport); | ||
| 102 | } | ||
| 103 | |||
| 104 | static int | ||
| 105 | efc_nport_alloc_init_vpi_cb(struct efc *efc, int status, u8 *mqe, void *arg) | ||
| 106 | { | ||
| 107 | struct efc_nport *nport = arg; | ||
| 108 | |||
| 109 | if (efc_nport_get_mbox_status(nport, mqe, status)) { | ||
| 110 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ALLOC_FAIL, mqe); | ||
| 111 | return -EIO; | ||
| 112 | } | ||
| 113 | |||
| 114 | efc_nport_send_evt(nport, EFC_EVT_NPORT_ALLOC_OK, mqe); | ||
| 115 | return 0; | ||
| 116 | } | ||
| 117 | |||
| 118 | static void | ||
| 119 | efc_nport_alloc_init_vpi(struct efc_nport *nport) | ||
| 120 | { | ||
| 121 | struct efc *efc = nport->efc; | ||
| 122 | u8 data[SLI4_BMBX_SIZE]; | ||
| 123 | int rc; | ||
| 124 | |||
| 125 | /* If there is a pending free request, then handle it now */ | ||
| 126 | if (nport->free_req_pending) { | ||
| 127 | efc_nport_free_resources(nport, EFC_EVT_NPORT_FREE_OK, data); | ||
| 128 | return; | ||
| 129 | } | ||
| 130 | |||
| 131 | rc = sli_cmd_init_vpi(efc->sli, data, | ||
| 132 | nport->indicator, nport->domain->indicator); | ||
| 133 | if (rc) { | ||
| 134 | efc_log_err(efc, "INIT_VPI format failure\n"); | ||
| 135 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ALLOC_FAIL, data); | ||
| 136 | return; | ||
| 137 | } | ||
| 138 | |||
| 139 | rc = efc->tt.issue_mbox_rqst(efc->base, data, | ||
| 140 | efc_nport_alloc_init_vpi_cb, nport); | ||
| 141 | if (rc) { | ||
| 142 | efc_log_err(efc, "INIT_VPI command failure\n"); | ||
| 143 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ALLOC_FAIL, data); | ||
| 144 | } | ||
| 145 | } | ||
| 146 | |||
| 147 | static int | ||
| 148 | efc_nport_alloc_read_sparm64_cb(struct efc *efc, int status, u8 *mqe, void *arg) | ||
| 149 | { | ||
| 150 | struct efc_nport *nport = arg; | ||
| 151 | u8 *payload = NULL; | ||
| 152 | |||
| 153 | if (efc_nport_get_mbox_status(nport, mqe, status)) { | ||
| 154 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ALLOC_FAIL, mqe); | ||
| 155 | return -EIO; | ||
| 156 | } | ||
| 157 | |||
| 158 | payload = nport->dma.virt; | ||
| 159 | |||
| 160 | memcpy(&nport->sli_wwpn, payload + SLI4_READ_SPARM64_WWPN_OFFSET, | ||
| 161 | sizeof(nport->sli_wwpn)); | ||
| 162 | memcpy(&nport->sli_wwnn, payload + SLI4_READ_SPARM64_WWNN_OFFSET, | ||
| 163 | sizeof(nport->sli_wwnn)); | ||
| 164 | |||
| 165 | dma_free_coherent(&efc->pci->dev, nport->dma.size, nport->dma.virt, | ||
| 166 | nport->dma.phys); | ||
| 167 | memset(&nport->dma, 0, sizeof(struct efc_dma)); | ||
| 168 | efc_nport_alloc_init_vpi(nport); | ||
| 169 | return 0; | ||
| 170 | } | ||
| 171 | |||
| 172 | static void | ||
| 173 | efc_nport_alloc_read_sparm64(struct efc *efc, struct efc_nport *nport) | ||
| 174 | { | ||
| 175 | u8 data[SLI4_BMBX_SIZE]; | ||
| 176 | int rc; | ||
| 177 | |||
| 178 | /* Allocate memory for the service parameters */ | ||
| 179 | nport->dma.size = EFC_SPARAM_DMA_SZ; | ||
| 180 | nport->dma.virt = dma_alloc_coherent(&efc->pci->dev, | ||
| 181 | nport->dma.size, &nport->dma.phys, | ||
| 182 | GFP_DMA); | ||
| 183 | if (!nport->dma.virt) { | ||
| 184 | efc_log_err(efc, "Failed to allocate DMA memory\n"); | ||
| 185 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ALLOC_FAIL, data); | ||
| 186 | return; | ||
| 187 | } | ||
| 188 | |||
| 189 | rc = sli_cmd_read_sparm64(efc->sli, data, | ||
| 190 | &nport->dma, nport->indicator); | ||
| 191 | if (rc) { | ||
| 192 | efc_log_err(efc, "READ_SPARM64 format failure\n"); | ||
| 193 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ALLOC_FAIL, data); | ||
| 194 | return; | ||
| 195 | } | ||
| 196 | |||
| 197 | rc = efc->tt.issue_mbox_rqst(efc->base, data, | ||
| 198 | efc_nport_alloc_read_sparm64_cb, nport); | ||
| 199 | if (rc) { | ||
| 200 | efc_log_err(efc, "READ_SPARM64 command failure\n"); | ||
| 201 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ALLOC_FAIL, data); | ||
| 202 | } | ||
| 203 | } | ||
| 204 | |||
| 205 | int | ||
| 206 | efc_cmd_nport_alloc(struct efc *efc, struct efc_nport *nport, | ||
| 207 | struct efc_domain *domain, u8 *wwpn) | ||
| 208 | { | ||
| 209 | u32 index; | ||
| 210 | |||
| 211 | nport->indicator = U32_MAX; | ||
| 212 | nport->free_req_pending = false; | ||
| 213 | |||
| 214 | if (wwpn) | ||
| 215 | memcpy(&nport->sli_wwpn, wwpn, sizeof(nport->sli_wwpn)); | ||
| 216 | |||
| 217 | /* | ||
| 218 | * allocate a VPI object for the port and stores it in the | ||
| 219 | * indicator field of the port object. | ||
| 220 | */ | ||
| 221 | if (sli_resource_alloc(efc->sli, SLI4_RSRC_VPI, | ||
| 222 | &nport->indicator, &index)) { | ||
| 223 | efc_log_err(efc, "VPI allocation failure\n"); | ||
| 224 | return -EIO; | ||
| 225 | } | ||
| 226 | |||
| 227 | if (domain) { | ||
| 228 | /* | ||
| 229 | * If the WWPN is NULL, fetch the default | ||
| 230 | * WWPN and WWNN before initializing the VPI | ||
| 231 | */ | ||
| 232 | if (!wwpn) | ||
| 233 | efc_nport_alloc_read_sparm64(efc, nport); | ||
| 234 | else | ||
| 235 | efc_nport_alloc_init_vpi(nport); | ||
| 236 | } else if (!wwpn) { | ||
| 237 | /* domain NULL and wwpn non-NULL */ | ||
| 238 | efc_log_err(efc, "need WWN for physical port\n"); | ||
| 239 | sli_resource_free(efc->sli, SLI4_RSRC_VPI, nport->indicator); | ||
| 240 | return -EIO; | ||
| 241 | } | ||
| 242 | |||
| 243 | return 0; | ||
| 244 | } | ||
| 245 | |||
| 246 | static int | ||
| 247 | efc_nport_attach_reg_vpi_cb(struct efc *efc, int status, u8 *mqe, | ||
| 248 | void *arg) | ||
| 249 | { | ||
| 250 | struct efc_nport *nport = arg; | ||
| 251 | |||
| 252 | if (efc_nport_get_mbox_status(nport, mqe, status)) { | ||
| 253 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ATTACH_FAIL, mqe); | ||
| 254 | return -EIO; | ||
| 255 | } | ||
| 256 | |||
| 257 | efc_nport_send_evt(nport, EFC_EVT_NPORT_ATTACH_OK, mqe); | ||
| 258 | return 0; | ||
| 259 | } | ||
| 260 | |||
| 261 | int | ||
| 262 | efc_cmd_nport_attach(struct efc *efc, struct efc_nport *nport, u32 fc_id) | ||
| 263 | { | ||
| 264 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 265 | int rc = 0; | ||
| 266 | |||
| 267 | if (!nport) { | ||
| 268 | efc_log_err(efc, "bad param(s) nport=%p\n", nport); | ||
| 269 | return -EIO; | ||
| 270 | } | ||
| 271 | |||
| 272 | nport->fc_id = fc_id; | ||
| 273 | |||
| 274 | /* register previously-allocated VPI with the device */ | ||
| 275 | rc = sli_cmd_reg_vpi(efc->sli, buf, nport->fc_id, | ||
| 276 | nport->sli_wwpn, nport->indicator, | ||
| 277 | nport->domain->indicator, false); | ||
| 278 | if (rc) { | ||
| 279 | efc_log_err(efc, "REG_VPI format failure\n"); | ||
| 280 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ATTACH_FAIL, buf); | ||
| 281 | return rc; | ||
| 282 | } | ||
| 283 | |||
| 284 | rc = efc->tt.issue_mbox_rqst(efc->base, buf, | ||
| 285 | efc_nport_attach_reg_vpi_cb, nport); | ||
| 286 | if (rc) { | ||
| 287 | efc_log_err(efc, "REG_VPI command failure\n"); | ||
| 288 | efc_nport_free_resources(nport, EFC_EVT_NPORT_ATTACH_FAIL, buf); | ||
| 289 | } | ||
| 290 | |||
| 291 | return rc; | ||
| 292 | } | ||
| 293 | |||
| 294 | int | ||
| 295 | efc_cmd_nport_free(struct efc *efc, struct efc_nport *nport) | ||
| 296 | { | ||
| 297 | if (!nport) { | ||
| 298 | efc_log_err(efc, "bad parameter(s) nport=%p\n", nport); | ||
| 299 | return -EIO; | ||
| 300 | } | ||
| 301 | |||
| 302 | /* Issue the UNREG_VPI command to free the assigned VPI context */ | ||
| 303 | if (nport->attached) | ||
| 304 | efc_nport_free_unreg_vpi(nport); | ||
| 305 | else | ||
| 306 | nport->free_req_pending = true; | ||
| 307 | |||
| 308 | return 0; | ||
| 309 | } | ||
| 310 | |||
| 311 | static int | ||
| 312 | efc_domain_get_mbox_status(struct efc_domain *domain, u8 *mqe, int status) | ||
| 313 | { | ||
| 314 | struct efc *efc = domain->efc; | ||
| 315 | struct sli4_mbox_command_header *hdr = | ||
| 316 | (struct sli4_mbox_command_header *)mqe; | ||
| 317 | |||
| 318 | if (status || le16_to_cpu(hdr->status)) { | ||
| 319 | efc_log_debug(efc, "bad status vfi=%#x st=%x hdr=%x\n", | ||
| 320 | domain->indicator, status, | ||
| 321 | le16_to_cpu(hdr->status)); | ||
| 322 | return -EIO; | ||
| 323 | } | ||
| 324 | |||
| 325 | return 0; | ||
| 326 | } | ||
| 327 | |||
| 328 | static void | ||
| 329 | efc_domain_free_resources(struct efc_domain *domain, int evt, void *data) | ||
| 330 | { | ||
| 331 | struct efc *efc = domain->efc; | ||
| 332 | |||
| 333 | /* Free the service parameters buffer */ | ||
| 334 | if (domain->dma.virt) { | ||
| 335 | dma_free_coherent(&efc->pci->dev, | ||
| 336 | domain->dma.size, domain->dma.virt, | ||
| 337 | domain->dma.phys); | ||
| 338 | memset(&domain->dma, 0, sizeof(struct efc_dma)); | ||
| 339 | } | ||
| 340 | |||
| 341 | /* Free the SLI resources */ | ||
| 342 | sli_resource_free(efc->sli, SLI4_RSRC_VFI, domain->indicator); | ||
| 343 | |||
| 344 | efc_domain_cb(efc, evt, domain); | ||
| 345 | } | ||
| 346 | |||
| 347 | static void | ||
| 348 | efc_domain_send_nport_evt(struct efc_domain *domain, | ||
| 349 | int port_evt, int domain_evt, void *data) | ||
| 350 | { | ||
| 351 | struct efc *efc = domain->efc; | ||
| 352 | |||
| 353 | /* Send alloc/attach ok to the physical nport */ | ||
| 354 | efc_nport_send_evt(domain->nport, port_evt, NULL); | ||
| 355 | |||
| 356 | /* Now inform the registered callbacks */ | ||
| 357 | efc_domain_cb(efc, domain_evt, domain); | ||
| 358 | } | ||
| 359 | |||
| 360 | static int | ||
| 361 | efc_domain_alloc_read_sparm64_cb(struct efc *efc, int status, u8 *mqe, | ||
| 362 | void *arg) | ||
| 363 | { | ||
| 364 | struct efc_domain *domain = arg; | ||
| 365 | |||
| 366 | if (efc_domain_get_mbox_status(domain, mqe, status)) { | ||
| 367 | efc_domain_free_resources(domain, | ||
| 368 | EFC_HW_DOMAIN_ALLOC_FAIL, mqe); | ||
| 369 | return -EIO; | ||
| 370 | } | ||
| 371 | |||
| 372 | efc_domain_send_nport_evt(domain, EFC_EVT_NPORT_ALLOC_OK, | ||
| 373 | EFC_HW_DOMAIN_ALLOC_OK, mqe); | ||
| 374 | return 0; | ||
| 375 | } | ||
| 376 | |||
| 377 | static void | ||
| 378 | efc_domain_alloc_read_sparm64(struct efc_domain *domain) | ||
| 379 | { | ||
| 380 | struct efc *efc = domain->efc; | ||
| 381 | u8 data[SLI4_BMBX_SIZE]; | ||
| 382 | int rc; | ||
| 383 | |||
| 384 | rc = sli_cmd_read_sparm64(efc->sli, data, &domain->dma, 0); | ||
| 385 | if (rc) { | ||
| 386 | efc_log_err(efc, "READ_SPARM64 format failure\n"); | ||
| 387 | efc_domain_free_resources(domain, | ||
| 388 | EFC_HW_DOMAIN_ALLOC_FAIL, data); | ||
| 389 | return; | ||
| 390 | } | ||
| 391 | |||
| 392 | rc = efc->tt.issue_mbox_rqst(efc->base, data, | ||
| 393 | efc_domain_alloc_read_sparm64_cb, domain); | ||
| 394 | if (rc) { | ||
| 395 | efc_log_err(efc, "READ_SPARM64 command failure\n"); | ||
| 396 | efc_domain_free_resources(domain, | ||
| 397 | EFC_HW_DOMAIN_ALLOC_FAIL, data); | ||
| 398 | } | ||
| 399 | } | ||
| 400 | |||
| 401 | static int | ||
| 402 | efc_domain_alloc_init_vfi_cb(struct efc *efc, int status, u8 *mqe, | ||
| 403 | void *arg) | ||
| 404 | { | ||
| 405 | struct efc_domain *domain = arg; | ||
| 406 | |||
| 407 | if (efc_domain_get_mbox_status(domain, mqe, status)) { | ||
| 408 | efc_domain_free_resources(domain, | ||
| 409 | EFC_HW_DOMAIN_ALLOC_FAIL, mqe); | ||
| 410 | return -EIO; | ||
| 411 | } | ||
| 412 | |||
| 413 | efc_domain_alloc_read_sparm64(domain); | ||
| 414 | return 0; | ||
| 415 | } | ||
| 416 | |||
| 417 | static void | ||
| 418 | efc_domain_alloc_init_vfi(struct efc_domain *domain) | ||
| 419 | { | ||
| 420 | struct efc *efc = domain->efc; | ||
| 421 | struct efc_nport *nport = domain->nport; | ||
| 422 | u8 data[SLI4_BMBX_SIZE]; | ||
| 423 | int rc; | ||
| 424 | |||
| 425 | /* | ||
| 426 | * For FC, the HW alread registered an FCFI. | ||
| 427 | * Copy FCF information into the domain and jump to INIT_VFI. | ||
| 428 | */ | ||
| 429 | domain->fcf_indicator = efc->fcfi; | ||
| 430 | rc = sli_cmd_init_vfi(efc->sli, data, domain->indicator, | ||
| 431 | domain->fcf_indicator, nport->indicator); | ||
| 432 | if (rc) { | ||
| 433 | efc_log_err(efc, "INIT_VFI format failure\n"); | ||
| 434 | efc_domain_free_resources(domain, | ||
| 435 | EFC_HW_DOMAIN_ALLOC_FAIL, data); | ||
| 436 | return; | ||
| 437 | } | ||
| 438 | |||
| 439 | efc_log_err(efc, "%s issue mbox\n", __func__); | ||
| 440 | rc = efc->tt.issue_mbox_rqst(efc->base, data, | ||
| 441 | efc_domain_alloc_init_vfi_cb, domain); | ||
| 442 | if (rc) { | ||
| 443 | efc_log_err(efc, "INIT_VFI command failure\n"); | ||
| 444 | efc_domain_free_resources(domain, | ||
| 445 | EFC_HW_DOMAIN_ALLOC_FAIL, data); | ||
| 446 | } | ||
| 447 | } | ||
| 448 | |||
| 449 | int | ||
| 450 | efc_cmd_domain_alloc(struct efc *efc, struct efc_domain *domain, u32 fcf) | ||
| 451 | { | ||
| 452 | u32 index; | ||
| 453 | |||
| 454 | if (!domain || !domain->nport) { | ||
| 455 | efc_log_err(efc, "bad parameter(s) domain=%p nport=%p\n", | ||
| 456 | domain, domain ? domain->nport : NULL); | ||
| 457 | return -EIO; | ||
| 458 | } | ||
| 459 | |||
| 460 | /* allocate memory for the service parameters */ | ||
| 461 | domain->dma.size = EFC_SPARAM_DMA_SZ; | ||
| 462 | domain->dma.virt = dma_alloc_coherent(&efc->pci->dev, | ||
| 463 | domain->dma.size, | ||
| 464 | &domain->dma.phys, GFP_DMA); | ||
| 465 | if (!domain->dma.virt) { | ||
| 466 | efc_log_err(efc, "Failed to allocate DMA memory\n"); | ||
| 467 | return -EIO; | ||
| 468 | } | ||
| 469 | |||
| 470 | domain->fcf = fcf; | ||
| 471 | domain->fcf_indicator = U32_MAX; | ||
| 472 | domain->indicator = U32_MAX; | ||
| 473 | |||
| 474 | if (sli_resource_alloc(efc->sli, SLI4_RSRC_VFI, &domain->indicator, | ||
| 475 | &index)) { | ||
| 476 | efc_log_err(efc, "VFI allocation failure\n"); | ||
| 477 | |||
| 478 | dma_free_coherent(&efc->pci->dev, | ||
| 479 | domain->dma.size, domain->dma.virt, | ||
| 480 | domain->dma.phys); | ||
| 481 | memset(&domain->dma, 0, sizeof(struct efc_dma)); | ||
| 482 | |||
| 483 | return -EIO; | ||
| 484 | } | ||
| 485 | |||
| 486 | efc_domain_alloc_init_vfi(domain); | ||
| 487 | return 0; | ||
| 488 | } | ||
| 489 | |||
| 490 | static int | ||
| 491 | efc_domain_attach_reg_vfi_cb(struct efc *efc, int status, u8 *mqe, | ||
| 492 | void *arg) | ||
| 493 | { | ||
| 494 | struct efc_domain *domain = arg; | ||
| 495 | |||
| 496 | if (efc_domain_get_mbox_status(domain, mqe, status)) { | ||
| 497 | efc_domain_free_resources(domain, | ||
| 498 | EFC_HW_DOMAIN_ATTACH_FAIL, mqe); | ||
| 499 | return -EIO; | ||
| 500 | } | ||
| 501 | |||
| 502 | efc_domain_send_nport_evt(domain, EFC_EVT_NPORT_ATTACH_OK, | ||
| 503 | EFC_HW_DOMAIN_ATTACH_OK, mqe); | ||
| 504 | return 0; | ||
| 505 | } | ||
| 506 | |||
| 507 | int | ||
| 508 | efc_cmd_domain_attach(struct efc *efc, struct efc_domain *domain, u32 fc_id) | ||
| 509 | { | ||
| 510 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 511 | int rc = 0; | ||
| 512 | |||
| 513 | if (!domain) { | ||
| 514 | efc_log_err(efc, "bad param(s) domain=%p\n", domain); | ||
| 515 | return -EIO; | ||
| 516 | } | ||
| 517 | |||
| 518 | domain->nport->fc_id = fc_id; | ||
| 519 | |||
| 520 | rc = sli_cmd_reg_vfi(efc->sli, buf, SLI4_BMBX_SIZE, domain->indicator, | ||
| 521 | domain->fcf_indicator, domain->dma, | ||
| 522 | domain->nport->indicator, domain->nport->sli_wwpn, | ||
| 523 | domain->nport->fc_id); | ||
| 524 | if (rc) { | ||
| 525 | efc_log_err(efc, "REG_VFI format failure\n"); | ||
| 526 | goto cleanup; | ||
| 527 | } | ||
| 528 | |||
| 529 | rc = efc->tt.issue_mbox_rqst(efc->base, buf, | ||
| 530 | efc_domain_attach_reg_vfi_cb, domain); | ||
| 531 | if (rc) { | ||
| 532 | efc_log_err(efc, "REG_VFI command failure\n"); | ||
| 533 | goto cleanup; | ||
| 534 | } | ||
| 535 | |||
| 536 | return rc; | ||
| 537 | |||
| 538 | cleanup: | ||
| 539 | efc_domain_free_resources(domain, EFC_HW_DOMAIN_ATTACH_FAIL, buf); | ||
| 540 | |||
| 541 | return rc; | ||
| 542 | } | ||
| 543 | |||
| 544 | static int | ||
| 545 | efc_domain_free_unreg_vfi_cb(struct efc *efc, int status, u8 *mqe, void *arg) | ||
| 546 | { | ||
| 547 | struct efc_domain *domain = arg; | ||
| 548 | int evt = EFC_HW_DOMAIN_FREE_OK; | ||
| 549 | int rc; | ||
| 550 | |||
| 551 | rc = efc_domain_get_mbox_status(domain, mqe, status); | ||
| 552 | if (rc) { | ||
| 553 | evt = EFC_HW_DOMAIN_FREE_FAIL; | ||
| 554 | rc = -EIO; | ||
| 555 | } | ||
| 556 | |||
| 557 | efc_domain_free_resources(domain, evt, mqe); | ||
| 558 | return rc; | ||
| 559 | } | ||
| 560 | |||
| 561 | static void | ||
| 562 | efc_domain_free_unreg_vfi(struct efc_domain *domain) | ||
| 563 | { | ||
| 564 | struct efc *efc = domain->efc; | ||
| 565 | int rc; | ||
| 566 | u8 data[SLI4_BMBX_SIZE]; | ||
| 567 | |||
| 568 | rc = sli_cmd_unreg_vfi(efc->sli, data, domain->indicator, | ||
| 569 | SLI4_UNREG_TYPE_DOMAIN); | ||
| 570 | if (rc) { | ||
| 571 | efc_log_err(efc, "UNREG_VFI format failure\n"); | ||
| 572 | goto cleanup; | ||
| 573 | } | ||
| 574 | |||
| 575 | rc = efc->tt.issue_mbox_rqst(efc->base, data, | ||
| 576 | efc_domain_free_unreg_vfi_cb, domain); | ||
| 577 | if (rc) { | ||
| 578 | efc_log_err(efc, "UNREG_VFI command failure\n"); | ||
| 579 | goto cleanup; | ||
| 580 | } | ||
| 581 | |||
| 582 | return; | ||
| 583 | |||
| 584 | cleanup: | ||
| 585 | efc_domain_free_resources(domain, EFC_HW_DOMAIN_FREE_FAIL, data); | ||
| 586 | } | ||
| 587 | |||
| 588 | int | ||
| 589 | efc_cmd_domain_free(struct efc *efc, struct efc_domain *domain) | ||
| 590 | { | ||
| 591 | if (!domain) { | ||
| 592 | efc_log_err(efc, "bad parameter(s) domain=%p\n", domain); | ||
| 593 | return -EIO; | ||
| 594 | } | ||
| 595 | |||
| 596 | efc_domain_free_unreg_vfi(domain); | ||
| 597 | return 0; | ||
| 598 | } | ||
| 599 | |||
| 600 | int | ||
| 601 | efc_cmd_node_alloc(struct efc *efc, struct efc_remote_node *rnode, u32 fc_addr, | ||
| 602 | struct efc_nport *nport) | ||
| 603 | { | ||
| 604 | /* Check for invalid indicator */ | ||
| 605 | if (rnode->indicator != U32_MAX) { | ||
| 606 | efc_log_err(efc, | ||
| 607 | "RPI allocation failure addr=%#x rpi=%#x\n", | ||
| 608 | fc_addr, rnode->indicator); | ||
| 609 | return -EIO; | ||
| 610 | } | ||
| 611 | |||
| 612 | /* NULL SLI port indicates an unallocated remote node */ | ||
| 613 | rnode->nport = NULL; | ||
| 614 | |||
| 615 | if (sli_resource_alloc(efc->sli, SLI4_RSRC_RPI, | ||
| 616 | &rnode->indicator, &rnode->index)) { | ||
| 617 | efc_log_err(efc, "RPI allocation failure addr=%#x\n", | ||
| 618 | fc_addr); | ||
| 619 | return -EIO; | ||
| 620 | } | ||
| 621 | |||
| 622 | rnode->fc_id = fc_addr; | ||
| 623 | rnode->nport = nport; | ||
| 624 | |||
| 625 | return 0; | ||
| 626 | } | ||
| 627 | |||
| 628 | static int | ||
| 629 | efc_cmd_node_attach_cb(struct efc *efc, int status, u8 *mqe, void *arg) | ||
| 630 | { | ||
| 631 | struct efc_remote_node *rnode = arg; | ||
| 632 | struct sli4_mbox_command_header *hdr = | ||
| 633 | (struct sli4_mbox_command_header *)mqe; | ||
| 634 | int evt = 0; | ||
| 635 | |||
| 636 | if (status || le16_to_cpu(hdr->status)) { | ||
| 637 | efc_log_debug(efc, "bad status cqe=%#x mqe=%#x\n", status, | ||
| 638 | le16_to_cpu(hdr->status)); | ||
| 639 | rnode->attached = false; | ||
| 640 | evt = EFC_EVT_NODE_ATTACH_FAIL; | ||
| 641 | } else { | ||
| 642 | rnode->attached = true; | ||
| 643 | evt = EFC_EVT_NODE_ATTACH_OK; | ||
| 644 | } | ||
| 645 | |||
| 646 | efc_remote_node_cb(efc, evt, rnode); | ||
| 647 | |||
| 648 | return 0; | ||
| 649 | } | ||
| 650 | |||
| 651 | int | ||
| 652 | efc_cmd_node_attach(struct efc *efc, struct efc_remote_node *rnode, | ||
| 653 | struct efc_dma *sparms) | ||
| 654 | { | ||
| 655 | int rc = -EIO; | ||
| 656 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 657 | |||
| 658 | if (!rnode || !sparms) { | ||
| 659 | efc_log_err(efc, "bad parameter(s) rnode=%p sparms=%p\n", | ||
| 660 | rnode, sparms); | ||
| 661 | return -EIO; | ||
| 662 | } | ||
| 663 | |||
| 664 | /* | ||
| 665 | * If the attach count is non-zero, this RPI has already been reg'd. | ||
| 666 | * Otherwise, register the RPI | ||
| 667 | */ | ||
| 668 | if (rnode->index == U32_MAX) { | ||
| 669 | efc_log_err(efc, "bad parameter rnode->index invalid\n"); | ||
| 670 | return -EIO; | ||
| 671 | } | ||
| 672 | |||
| 673 | /* Update a remote node object with the remote port's service params */ | ||
| 674 | if (!sli_cmd_reg_rpi(efc->sli, buf, rnode->indicator, | ||
| 675 | rnode->nport->indicator, rnode->fc_id, sparms, 0, 0)) | ||
| 676 | rc = efc->tt.issue_mbox_rqst(efc->base, buf, | ||
| 677 | efc_cmd_node_attach_cb, rnode); | ||
| 678 | |||
| 679 | return rc; | ||
| 680 | } | ||
| 681 | |||
| 682 | int | ||
| 683 | efc_node_free_resources(struct efc *efc, struct efc_remote_node *rnode) | ||
| 684 | { | ||
| 685 | int rc = 0; | ||
| 686 | |||
| 687 | if (!rnode) { | ||
| 688 | efc_log_err(efc, "bad parameter rnode=%p\n", rnode); | ||
| 689 | return -EIO; | ||
| 690 | } | ||
| 691 | |||
| 692 | if (rnode->nport) { | ||
| 693 | if (rnode->attached) { | ||
| 694 | efc_log_err(efc, "rnode is still attached\n"); | ||
| 695 | return -EIO; | ||
| 696 | } | ||
| 697 | if (rnode->indicator != U32_MAX) { | ||
| 698 | if (sli_resource_free(efc->sli, SLI4_RSRC_RPI, | ||
| 699 | rnode->indicator)) { | ||
| 700 | efc_log_err(efc, | ||
| 701 | "RPI free fail RPI %d addr=%#x\n", | ||
| 702 | rnode->indicator, rnode->fc_id); | ||
| 703 | rc = -EIO; | ||
| 704 | } else { | ||
| 705 | rnode->indicator = U32_MAX; | ||
| 706 | rnode->index = U32_MAX; | ||
| 707 | } | ||
| 708 | } | ||
| 709 | } | ||
| 710 | |||
| 711 | return rc; | ||
| 712 | } | ||
| 713 | |||
| 714 | static int | ||
| 715 | efc_cmd_node_free_cb(struct efc *efc, int status, u8 *mqe, void *arg) | ||
| 716 | { | ||
| 717 | struct efc_remote_node *rnode = arg; | ||
| 718 | struct sli4_mbox_command_header *hdr = | ||
| 719 | (struct sli4_mbox_command_header *)mqe; | ||
| 720 | int evt = EFC_EVT_NODE_FREE_FAIL; | ||
| 721 | int rc = 0; | ||
| 722 | |||
| 723 | if (status || le16_to_cpu(hdr->status)) { | ||
| 724 | efc_log_debug(efc, "bad status cqe=%#x mqe=%#x\n", status, | ||
| 725 | le16_to_cpu(hdr->status)); | ||
| 726 | |||
| 727 | /* | ||
| 728 | * In certain cases, a non-zero MQE status is OK (all must be | ||
| 729 | * true): | ||
| 730 | * - node is attached | ||
| 731 | * - status is 0x1400 | ||
| 732 | */ | ||
| 733 | if (!rnode->attached || | ||
| 734 | (le16_to_cpu(hdr->status) != SLI4_MBX_STATUS_RPI_NOT_REG)) | ||
| 735 | rc = -EIO; | ||
| 736 | } | ||
| 737 | |||
| 738 | if (!rc) { | ||
| 739 | rnode->attached = false; | ||
| 740 | evt = EFC_EVT_NODE_FREE_OK; | ||
| 741 | } | ||
| 742 | |||
| 743 | efc_remote_node_cb(efc, evt, rnode); | ||
| 744 | |||
| 745 | return rc; | ||
| 746 | } | ||
| 747 | |||
| 748 | int | ||
| 749 | efc_cmd_node_detach(struct efc *efc, struct efc_remote_node *rnode) | ||
| 750 | { | ||
| 751 | u8 buf[SLI4_BMBX_SIZE]; | ||
| 752 | int rc = -EIO; | ||
| 753 | |||
| 754 | if (!rnode) { | ||
| 755 | efc_log_err(efc, "bad parameter rnode=%p\n", rnode); | ||
| 756 | return -EIO; | ||
| 757 | } | ||
| 758 | |||
| 759 | if (rnode->nport) { | ||
| 760 | if (!rnode->attached) | ||
| 761 | return -EIO; | ||
| 762 | |||
| 763 | rc = -EIO; | ||
| 764 | |||
| 765 | if (!sli_cmd_unreg_rpi(efc->sli, buf, rnode->indicator, | ||
| 766 | SLI4_RSRC_RPI, U32_MAX)) | ||
| 767 | rc = efc->tt.issue_mbox_rqst(efc->base, buf, | ||
| 768 | efc_cmd_node_free_cb, rnode); | ||
| 769 | |||
| 770 | if (rc != 0) { | ||
| 771 | efc_log_err(efc, "UNREG_RPI failed\n"); | ||
| 772 | rc = -EIO; | ||
| 773 | } | ||
| 774 | } | ||
| 775 | |||
| 776 | return rc; | ||
| 777 | } | ||
| @@ -0,0 +1,35 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef __EFC_CMDS_H__ | ||
| 8 | #define __EFC_CMDS_H__ | ||
| 9 | |||
| 10 | #define EFC_SPARAM_DMA_SZ 112 | ||
| 11 | int | ||
| 12 | efc_cmd_nport_alloc(struct efc *efc, struct efc_nport *nport, | ||
| 13 | struct efc_domain *domain, u8 *wwpn); | ||
| 14 | int | ||
| 15 | efc_cmd_nport_attach(struct efc *efc, struct efc_nport *nport, u32 fc_id); | ||
| 16 | int | ||
| 17 | efc_cmd_nport_free(struct efc *efc, struct efc_nport *nport); | ||
| 18 | int | ||
| 19 | efc_cmd_domain_alloc(struct efc *efc, struct efc_domain *domain, u32 fcf); | ||
| 20 | int | ||
| 21 | efc_cmd_domain_attach(struct efc *efc, struct efc_domain *domain, u32 fc_id); | ||
| 22 | int | ||
| 23 | efc_cmd_domain_free(struct efc *efc, struct efc_domain *domain); | ||
| 24 | int | ||
| 25 | efc_cmd_node_detach(struct efc *efc, struct efc_remote_node *rnode); | ||
| 26 | int | ||
| 27 | efc_node_free_resources(struct efc *efc, struct efc_remote_node *rnode); | ||
| 28 | int | ||
| 29 | efc_cmd_node_attach(struct efc *efc, struct efc_remote_node *rnode, | ||
| 30 | struct efc_dma *sparms); | ||
| 31 | int | ||
| 32 | efc_cmd_node_alloc(struct efc *efc, struct efc_remote_node *rnode, u32 fc_addr, | ||
| 33 | struct efc_nport *nport); | ||
| 34 | |||
| 35 | #endif /* __EFC_CMDS_H */ | ||
| @@ -0,0 +1,1603 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * device_sm Node State Machine: Remote Device States | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include "efc.h" | ||
| 12 | #include "efc_device.h" | ||
| 13 | #include "efc_fabric.h" | ||
| 14 | |||
| 15 | void | ||
| 16 | efc_d_send_prli_rsp(struct efc_node *node, u16 ox_id) | ||
| 17 | { | ||
| 18 | int rc = EFC_SCSI_CALL_COMPLETE; | ||
| 19 | struct efc *efc = node->efc; | ||
| 20 | |||
| 21 | node->ls_acc_oxid = ox_id; | ||
| 22 | node->send_ls_acc = EFC_NODE_SEND_LS_ACC_PRLI; | ||
| 23 | |||
| 24 | /* | ||
| 25 | * Wait for backend session registration | ||
| 26 | * to complete before sending PRLI resp | ||
| 27 | */ | ||
| 28 | |||
| 29 | if (node->init) { | ||
| 30 | efc_log_info(efc, "[%s] found(initiator) WWPN:%s WWNN:%s\n", | ||
| 31 | node->display_name, node->wwpn, node->wwnn); | ||
| 32 | if (node->nport->enable_tgt) | ||
| 33 | rc = efc->tt.scsi_new_node(efc, node); | ||
| 34 | } | ||
| 35 | |||
| 36 | if (rc < 0) | ||
| 37 | efc_node_post_event(node, EFC_EVT_NODE_SESS_REG_FAIL, NULL); | ||
| 38 | |||
| 39 | if (rc == EFC_SCSI_CALL_COMPLETE) | ||
| 40 | efc_node_post_event(node, EFC_EVT_NODE_SESS_REG_OK, NULL); | ||
| 41 | } | ||
| 42 | |||
| 43 | static void | ||
| 44 | __efc_d_common(const char *funcname, struct efc_sm_ctx *ctx, | ||
| 45 | enum efc_sm_event evt, void *arg) | ||
| 46 | { | ||
| 47 | struct efc_node *node = NULL; | ||
| 48 | struct efc *efc = NULL; | ||
| 49 | |||
| 50 | node = ctx->app; | ||
| 51 | efc = node->efc; | ||
| 52 | |||
| 53 | switch (evt) { | ||
| 54 | /* Handle shutdown events */ | ||
| 55 | case EFC_EVT_SHUTDOWN: | ||
| 56 | efc_log_debug(efc, "[%s] %-20s %-20s\n", node->display_name, | ||
| 57 | funcname, efc_sm_event_name(evt)); | ||
| 58 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 59 | efc_node_transition(node, __efc_d_initiate_shutdown, NULL); | ||
| 60 | break; | ||
| 61 | case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO: | ||
| 62 | efc_log_debug(efc, "[%s] %-20s %-20s\n", | ||
| 63 | node->display_name, funcname, | ||
| 64 | efc_sm_event_name(evt)); | ||
| 65 | node->shutdown_reason = EFC_NODE_SHUTDOWN_EXPLICIT_LOGO; | ||
| 66 | efc_node_transition(node, __efc_d_initiate_shutdown, NULL); | ||
| 67 | break; | ||
| 68 | case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO: | ||
| 69 | efc_log_debug(efc, "[%s] %-20s %-20s\n", node->display_name, | ||
| 70 | funcname, efc_sm_event_name(evt)); | ||
| 71 | node->shutdown_reason = EFC_NODE_SHUTDOWN_IMPLICIT_LOGO; | ||
| 72 | efc_node_transition(node, __efc_d_initiate_shutdown, NULL); | ||
| 73 | break; | ||
| 74 | |||
| 75 | default: | ||
| 76 | /* call default event handler common to all nodes */ | ||
| 77 | __efc_node_common(funcname, ctx, evt, arg); | ||
| 78 | } | ||
| 79 | } | ||
| 80 | |||
| 81 | static void | ||
| 82 | __efc_d_wait_del_node(struct efc_sm_ctx *ctx, | ||
| 83 | enum efc_sm_event evt, void *arg) | ||
| 84 | { | ||
| 85 | struct efc_node *node = ctx->app; | ||
| 86 | |||
| 87 | efc_node_evt_set(ctx, evt, __func__); | ||
| 88 | |||
| 89 | /* | ||
| 90 | * State is entered when a node sends a delete initiator/target call | ||
| 91 | * to the target-server/initiator-client and needs to wait for that | ||
| 92 | * work to complete. | ||
| 93 | */ | ||
| 94 | node_sm_trace(); | ||
| 95 | |||
| 96 | switch (evt) { | ||
| 97 | case EFC_EVT_ENTER: | ||
| 98 | efc_node_hold_frames(node); | ||
| 99 | fallthrough; | ||
| 100 | |||
| 101 | case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY: | ||
| 102 | case EFC_EVT_ALL_CHILD_NODES_FREE: | ||
| 103 | /* These are expected events. */ | ||
| 104 | break; | ||
| 105 | |||
| 106 | case EFC_EVT_NODE_DEL_INI_COMPLETE: | ||
| 107 | case EFC_EVT_NODE_DEL_TGT_COMPLETE: | ||
| 108 | /* | ||
| 109 | * node has either been detached or is in the process | ||
| 110 | * of being detached, | ||
| 111 | * call common node's initiate cleanup function | ||
| 112 | */ | ||
| 113 | efc_node_initiate_cleanup(node); | ||
| 114 | break; | ||
| 115 | |||
| 116 | case EFC_EVT_EXIT: | ||
| 117 | efc_node_accept_frames(node); | ||
| 118 | break; | ||
| 119 | |||
| 120 | case EFC_EVT_SRRS_ELS_REQ_FAIL: | ||
| 121 | /* Can happen as ELS IO IO's complete */ | ||
| 122 | WARN_ON(!node->els_req_cnt); | ||
| 123 | node->els_req_cnt--; | ||
| 124 | break; | ||
| 125 | |||
| 126 | /* ignore shutdown events as we're already in shutdown path */ | ||
| 127 | case EFC_EVT_SHUTDOWN: | ||
| 128 | /* have default shutdown event take precedence */ | ||
| 129 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 130 | fallthrough; | ||
| 131 | |||
| 132 | case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO: | ||
| 133 | case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO: | ||
| 134 | node_printf(node, "%s received\n", efc_sm_event_name(evt)); | ||
| 135 | break; | ||
| 136 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 137 | /* don't care about domain_attach_ok */ | ||
| 138 | break; | ||
| 139 | default: | ||
| 140 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | |||
| 144 | static void | ||
| 145 | __efc_d_wait_del_ini_tgt(struct efc_sm_ctx *ctx, | ||
| 146 | enum efc_sm_event evt, void *arg) | ||
| 147 | { | ||
| 148 | struct efc_node *node = ctx->app; | ||
| 149 | |||
| 150 | efc_node_evt_set(ctx, evt, __func__); | ||
| 151 | |||
| 152 | node_sm_trace(); | ||
| 153 | |||
| 154 | switch (evt) { | ||
| 155 | case EFC_EVT_ENTER: | ||
| 156 | efc_node_hold_frames(node); | ||
| 157 | fallthrough; | ||
| 158 | |||
| 159 | case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY: | ||
| 160 | case EFC_EVT_ALL_CHILD_NODES_FREE: | ||
| 161 | /* These are expected events. */ | ||
| 162 | break; | ||
| 163 | |||
| 164 | case EFC_EVT_NODE_DEL_INI_COMPLETE: | ||
| 165 | case EFC_EVT_NODE_DEL_TGT_COMPLETE: | ||
| 166 | efc_node_transition(node, __efc_d_wait_del_node, NULL); | ||
| 167 | break; | ||
| 168 | |||
| 169 | case EFC_EVT_EXIT: | ||
| 170 | efc_node_accept_frames(node); | ||
| 171 | break; | ||
| 172 | |||
| 173 | case EFC_EVT_SRRS_ELS_REQ_FAIL: | ||
| 174 | /* Can happen as ELS IO IO's complete */ | ||
| 175 | WARN_ON(!node->els_req_cnt); | ||
| 176 | node->els_req_cnt--; | ||
| 177 | break; | ||
| 178 | |||
| 179 | /* ignore shutdown events as we're already in shutdown path */ | ||
| 180 | case EFC_EVT_SHUTDOWN: | ||
| 181 | /* have default shutdown event take precedence */ | ||
| 182 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 183 | fallthrough; | ||
| 184 | |||
| 185 | case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO: | ||
| 186 | case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO: | ||
| 187 | node_printf(node, "%s received\n", efc_sm_event_name(evt)); | ||
| 188 | break; | ||
| 189 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 190 | /* don't care about domain_attach_ok */ | ||
| 191 | break; | ||
| 192 | default: | ||
| 193 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 194 | } | ||
| 195 | } | ||
| 196 | |||
| 197 | void | ||
| 198 | __efc_d_initiate_shutdown(struct efc_sm_ctx *ctx, | ||
| 199 | enum efc_sm_event evt, void *arg) | ||
| 200 | { | ||
| 201 | struct efc_node *node = ctx->app; | ||
| 202 | struct efc *efc = node->efc; | ||
| 203 | |||
| 204 | efc_node_evt_set(ctx, evt, __func__); | ||
| 205 | |||
| 206 | node_sm_trace(); | ||
| 207 | |||
| 208 | switch (evt) { | ||
| 209 | case EFC_EVT_ENTER: { | ||
| 210 | int rc = EFC_SCSI_CALL_COMPLETE; | ||
| 211 | |||
| 212 | /* assume no wait needed */ | ||
| 213 | node->els_io_enabled = false; | ||
| 214 | |||
| 215 | /* make necessary delete upcall(s) */ | ||
| 216 | if (node->init && !node->targ) { | ||
| 217 | efc_log_info(node->efc, | ||
| 218 | "[%s] delete (initiator) WWPN %s WWNN %s\n", | ||
| 219 | node->display_name, | ||
| 220 | node->wwpn, node->wwnn); | ||
| 221 | efc_node_transition(node, | ||
| 222 | __efc_d_wait_del_node, | ||
| 223 | NULL); | ||
| 224 | if (node->nport->enable_tgt) | ||
| 225 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 226 | EFC_SCSI_INITIATOR_DELETED); | ||
| 227 | |||
| 228 | if (rc == EFC_SCSI_CALL_COMPLETE || rc < 0) | ||
| 229 | efc_node_post_event(node, | ||
| 230 | EFC_EVT_NODE_DEL_INI_COMPLETE, NULL); | ||
| 231 | |||
| 232 | } else if (node->targ && !node->init) { | ||
| 233 | efc_log_info(node->efc, | ||
| 234 | "[%s] delete (target) WWPN %s WWNN %s\n", | ||
| 235 | node->display_name, | ||
| 236 | node->wwpn, node->wwnn); | ||
| 237 | efc_node_transition(node, | ||
| 238 | __efc_d_wait_del_node, | ||
| 239 | NULL); | ||
| 240 | if (node->nport->enable_ini) | ||
| 241 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 242 | EFC_SCSI_TARGET_DELETED); | ||
| 243 | |||
| 244 | if (rc == EFC_SCSI_CALL_COMPLETE) | ||
| 245 | efc_node_post_event(node, | ||
| 246 | EFC_EVT_NODE_DEL_TGT_COMPLETE, NULL); | ||
| 247 | |||
| 248 | } else if (node->init && node->targ) { | ||
| 249 | efc_log_info(node->efc, | ||
| 250 | "[%s] delete (I+T) WWPN %s WWNN %s\n", | ||
| 251 | node->display_name, node->wwpn, node->wwnn); | ||
| 252 | efc_node_transition(node, __efc_d_wait_del_ini_tgt, | ||
| 253 | NULL); | ||
| 254 | if (node->nport->enable_tgt) | ||
| 255 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 256 | EFC_SCSI_INITIATOR_DELETED); | ||
| 257 | |||
| 258 | if (rc == EFC_SCSI_CALL_COMPLETE) | ||
| 259 | efc_node_post_event(node, | ||
| 260 | EFC_EVT_NODE_DEL_INI_COMPLETE, NULL); | ||
| 261 | /* assume no wait needed */ | ||
| 262 | rc = EFC_SCSI_CALL_COMPLETE; | ||
| 263 | if (node->nport->enable_ini) | ||
| 264 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 265 | EFC_SCSI_TARGET_DELETED); | ||
| 266 | |||
| 267 | if (rc == EFC_SCSI_CALL_COMPLETE) | ||
| 268 | efc_node_post_event(node, | ||
| 269 | EFC_EVT_NODE_DEL_TGT_COMPLETE, NULL); | ||
| 270 | } | ||
| 271 | |||
| 272 | /* we've initiated the upcalls as needed, now kick off the node | ||
| 273 | * detach to precipitate the aborting of outstanding exchanges | ||
| 274 | * associated with said node | ||
| 275 | * | ||
| 276 | * Beware: if we've made upcall(s), we've already transitioned | ||
| 277 | * to a new state by the time we execute this. | ||
| 278 | * consider doing this before the upcalls? | ||
| 279 | */ | ||
| 280 | if (node->attached) { | ||
| 281 | /* issue hw node free; don't care if succeeds right | ||
| 282 | * away or sometime later, will check node->attached | ||
| 283 | * later in shutdown process | ||
| 284 | */ | ||
| 285 | rc = efc_cmd_node_detach(efc, &node->rnode); | ||
| 286 | if (rc < 0) | ||
| 287 | node_printf(node, | ||
| 288 | "Failed freeing HW node, rc=%d\n", | ||
| 289 | rc); | ||
| 290 | } | ||
| 291 | |||
| 292 | /* if neither initiator nor target, proceed to cleanup */ | ||
| 293 | if (!node->init && !node->targ) { | ||
| 294 | /* | ||
| 295 | * node has either been detached or is in | ||
| 296 | * the process of being detached, | ||
| 297 | * call common node's initiate cleanup function | ||
| 298 | */ | ||
| 299 | efc_node_initiate_cleanup(node); | ||
| 300 | } | ||
| 301 | break; | ||
| 302 | } | ||
| 303 | case EFC_EVT_ALL_CHILD_NODES_FREE: | ||
| 304 | /* Ignore, this can happen if an ELS is | ||
| 305 | * aborted while in a delay/retry state | ||
| 306 | */ | ||
| 307 | break; | ||
| 308 | default: | ||
| 309 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 310 | } | ||
| 311 | } | ||
| 312 | |||
| 313 | void | ||
| 314 | __efc_d_wait_loop(struct efc_sm_ctx *ctx, | ||
| 315 | enum efc_sm_event evt, void *arg) | ||
| 316 | { | ||
| 317 | struct efc_node *node = ctx->app; | ||
| 318 | |||
| 319 | efc_node_evt_set(ctx, evt, __func__); | ||
| 320 | |||
| 321 | node_sm_trace(); | ||
| 322 | |||
| 323 | switch (evt) { | ||
| 324 | case EFC_EVT_ENTER: | ||
| 325 | efc_node_hold_frames(node); | ||
| 326 | break; | ||
| 327 | |||
| 328 | case EFC_EVT_EXIT: | ||
| 329 | efc_node_accept_frames(node); | ||
| 330 | break; | ||
| 331 | |||
| 332 | case EFC_EVT_DOMAIN_ATTACH_OK: { | ||
| 333 | /* send PLOGI automatically if initiator */ | ||
| 334 | efc_node_init_device(node, true); | ||
| 335 | break; | ||
| 336 | } | ||
| 337 | default: | ||
| 338 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 339 | } | ||
| 340 | } | ||
| 341 | |||
| 342 | void | ||
| 343 | efc_send_ls_acc_after_attach(struct efc_node *node, | ||
| 344 | struct fc_frame_header *hdr, | ||
| 345 | enum efc_node_send_ls_acc ls) | ||
| 346 | { | ||
| 347 | u16 ox_id = be16_to_cpu(hdr->fh_ox_id); | ||
| 348 | |||
| 349 | /* Save the OX_ID for sending LS_ACC sometime later */ | ||
| 350 | WARN_ON(node->send_ls_acc != EFC_NODE_SEND_LS_ACC_NONE); | ||
| 351 | |||
| 352 | node->ls_acc_oxid = ox_id; | ||
| 353 | node->send_ls_acc = ls; | ||
| 354 | node->ls_acc_did = ntoh24(hdr->fh_d_id); | ||
| 355 | } | ||
| 356 | |||
| 357 | void | ||
| 358 | efc_process_prli_payload(struct efc_node *node, void *prli) | ||
| 359 | { | ||
| 360 | struct { | ||
| 361 | struct fc_els_prli prli; | ||
| 362 | struct fc_els_spp sp; | ||
| 363 | } *pp; | ||
| 364 | |||
| 365 | pp = prli; | ||
| 366 | node->init = (pp->sp.spp_flags & FCP_SPPF_INIT_FCN) != 0; | ||
| 367 | node->targ = (pp->sp.spp_flags & FCP_SPPF_TARG_FCN) != 0; | ||
| 368 | } | ||
| 369 | |||
| 370 | void | ||
| 371 | __efc_d_wait_plogi_acc_cmpl(struct efc_sm_ctx *ctx, | ||
| 372 | enum efc_sm_event evt, void *arg) | ||
| 373 | { | ||
| 374 | struct efc_node *node = ctx->app; | ||
| 375 | |||
| 376 | efc_node_evt_set(ctx, evt, __func__); | ||
| 377 | |||
| 378 | node_sm_trace(); | ||
| 379 | |||
| 380 | switch (evt) { | ||
| 381 | case EFC_EVT_ENTER: | ||
| 382 | efc_node_hold_frames(node); | ||
| 383 | break; | ||
| 384 | |||
| 385 | case EFC_EVT_EXIT: | ||
| 386 | efc_node_accept_frames(node); | ||
| 387 | break; | ||
| 388 | |||
| 389 | case EFC_EVT_SRRS_ELS_CMPL_FAIL: | ||
| 390 | WARN_ON(!node->els_cmpl_cnt); | ||
| 391 | node->els_cmpl_cnt--; | ||
| 392 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 393 | efc_node_transition(node, __efc_d_initiate_shutdown, NULL); | ||
| 394 | break; | ||
| 395 | |||
| 396 | case EFC_EVT_SRRS_ELS_CMPL_OK: /* PLOGI ACC completions */ | ||
| 397 | WARN_ON(!node->els_cmpl_cnt); | ||
| 398 | node->els_cmpl_cnt--; | ||
| 399 | efc_node_transition(node, __efc_d_port_logged_in, NULL); | ||
| 400 | break; | ||
| 401 | |||
| 402 | default: | ||
| 403 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 404 | } | ||
| 405 | } | ||
| 406 | |||
| 407 | void | ||
| 408 | __efc_d_wait_logo_rsp(struct efc_sm_ctx *ctx, | ||
| 409 | enum efc_sm_event evt, void *arg) | ||
| 410 | { | ||
| 411 | struct efc_node *node = ctx->app; | ||
| 412 | |||
| 413 | efc_node_evt_set(ctx, evt, __func__); | ||
| 414 | |||
| 415 | node_sm_trace(); | ||
| 416 | |||
| 417 | switch (evt) { | ||
| 418 | case EFC_EVT_ENTER: | ||
| 419 | efc_node_hold_frames(node); | ||
| 420 | break; | ||
| 421 | |||
| 422 | case EFC_EVT_EXIT: | ||
| 423 | efc_node_accept_frames(node); | ||
| 424 | break; | ||
| 425 | |||
| 426 | case EFC_EVT_SRRS_ELS_REQ_OK: | ||
| 427 | case EFC_EVT_SRRS_ELS_REQ_RJT: | ||
| 428 | case EFC_EVT_SRRS_ELS_REQ_FAIL: | ||
| 429 | /* LOGO response received, sent shutdown */ | ||
| 430 | if (efc_node_check_els_req(ctx, evt, arg, ELS_LOGO, | ||
| 431 | __efc_d_common, __func__)) | ||
| 432 | return; | ||
| 433 | |||
| 434 | WARN_ON(!node->els_req_cnt); | ||
| 435 | node->els_req_cnt--; | ||
| 436 | node_printf(node, | ||
| 437 | "LOGO sent (evt=%s), shutdown node\n", | ||
| 438 | efc_sm_event_name(evt)); | ||
| 439 | /* sm: / post explicit logout */ | ||
| 440 | efc_node_post_event(node, EFC_EVT_SHUTDOWN_EXPLICIT_LOGO, | ||
| 441 | NULL); | ||
| 442 | break; | ||
| 443 | |||
| 444 | default: | ||
| 445 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 446 | } | ||
| 447 | } | ||
| 448 | |||
| 449 | void | ||
| 450 | efc_node_init_device(struct efc_node *node, bool send_plogi) | ||
| 451 | { | ||
| 452 | node->send_plogi = send_plogi; | ||
| 453 | if ((node->efc->nodedb_mask & EFC_NODEDB_PAUSE_NEW_NODES) && | ||
| 454 | (node->rnode.fc_id != FC_FID_DOM_MGR)) { | ||
| 455 | node->nodedb_state = __efc_d_init; | ||
| 456 | efc_node_transition(node, __efc_node_paused, NULL); | ||
| 457 | } else { | ||
| 458 | efc_node_transition(node, __efc_d_init, NULL); | ||
| 459 | } | ||
| 460 | } | ||
| 461 | |||
| 462 | static void | ||
| 463 | efc_d_check_plogi_topology(struct efc_node *node, u32 d_id) | ||
| 464 | { | ||
| 465 | switch (node->nport->topology) { | ||
| 466 | case EFC_NPORT_TOPO_P2P: | ||
| 467 | /* we're not attached and nport is p2p, | ||
| 468 | * need to attach | ||
| 469 | */ | ||
| 470 | efc_domain_attach(node->nport->domain, d_id); | ||
| 471 | efc_node_transition(node, __efc_d_wait_domain_attach, NULL); | ||
| 472 | break; | ||
| 473 | case EFC_NPORT_TOPO_FABRIC: | ||
| 474 | /* we're not attached and nport is fabric, domain | ||
| 475 | * attach should have already been requested as part | ||
| 476 | * of the fabric state machine, wait for it | ||
| 477 | */ | ||
| 478 | efc_node_transition(node, __efc_d_wait_domain_attach, NULL); | ||
| 479 | break; | ||
| 480 | case EFC_NPORT_TOPO_UNKNOWN: | ||
| 481 | /* Two possibilities: | ||
| 482 | * 1. received a PLOGI before our FLOGI has completed | ||
| 483 | * (possible since completion comes in on another | ||
| 484 | * CQ), thus we don't know what we're connected to | ||
| 485 | * yet; transition to a state to wait for the | ||
| 486 | * fabric node to tell us; | ||
| 487 | * 2. PLOGI received before link went down and we | ||
| 488 | * haven't performed domain attach yet. | ||
| 489 | * Note: we cannot distinguish between 1. and 2. | ||
| 490 | * so have to assume PLOGI | ||
| 491 | * was received after link back up. | ||
| 492 | */ | ||
| 493 | node_printf(node, "received PLOGI, unknown topology did=0x%x\n", | ||
| 494 | d_id); | ||
| 495 | efc_node_transition(node, __efc_d_wait_topology_notify, NULL); | ||
| 496 | break; | ||
| 497 | default: | ||
| 498 | node_printf(node, "received PLOGI, unexpected topology %d\n", | ||
| 499 | node->nport->topology); | ||
| 500 | } | ||
| 501 | } | ||
| 502 | |||
| 503 | void | ||
| 504 | __efc_d_init(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg) | ||
| 505 | { | ||
| 506 | struct efc_node_cb *cbdata = arg; | ||
| 507 | struct efc_node *node = ctx->app; | ||
| 508 | |||
| 509 | efc_node_evt_set(ctx, evt, __func__); | ||
| 510 | |||
| 511 | node_sm_trace(); | ||
| 512 | |||
| 513 | /* | ||
| 514 | * This state is entered when a node is instantiated, | ||
| 515 | * either having been discovered from a name services query, | ||
| 516 | * or having received a PLOGI/FLOGI. | ||
| 517 | */ | ||
| 518 | switch (evt) { | ||
| 519 | case EFC_EVT_ENTER: | ||
| 520 | if (!node->send_plogi) | ||
| 521 | break; | ||
| 522 | /* only send if we have initiator capability, | ||
| 523 | * and domain is attached | ||
| 524 | */ | ||
| 525 | if (node->nport->enable_ini && | ||
| 526 | node->nport->domain->attached) { | ||
| 527 | efc_send_plogi(node); | ||
| 528 | |||
| 529 | efc_node_transition(node, __efc_d_wait_plogi_rsp, NULL); | ||
| 530 | } else { | ||
| 531 | node_printf(node, "not sending plogi nport.ini=%d,", | ||
| 532 | node->nport->enable_ini); | ||
| 533 | node_printf(node, "domain attached=%d\n", | ||
| 534 | node->nport->domain->attached); | ||
| 535 | } | ||
| 536 | break; | ||
| 537 | case EFC_EVT_PLOGI_RCVD: { | ||
| 538 | /* T, or I+T */ | ||
| 539 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 540 | int rc; | ||
| 541 | |||
| 542 | efc_node_save_sparms(node, cbdata->payload->dma.virt); | ||
| 543 | efc_send_ls_acc_after_attach(node, | ||
| 544 | cbdata->header->dma.virt, | ||
| 545 | EFC_NODE_SEND_LS_ACC_PLOGI); | ||
| 546 | |||
| 547 | /* domain not attached; several possibilities: */ | ||
| 548 | if (!node->nport->domain->attached) { | ||
| 549 | efc_d_check_plogi_topology(node, ntoh24(hdr->fh_d_id)); | ||
| 550 | break; | ||
| 551 | } | ||
| 552 | |||
| 553 | /* domain already attached */ | ||
| 554 | rc = efc_node_attach(node); | ||
| 555 | efc_node_transition(node, __efc_d_wait_node_attach, NULL); | ||
| 556 | if (rc < 0) | ||
| 557 | efc_node_post_event(node, EFC_EVT_NODE_ATTACH_FAIL, NULL); | ||
| 558 | |||
| 559 | break; | ||
| 560 | } | ||
| 561 | |||
| 562 | case EFC_EVT_FDISC_RCVD: { | ||
| 563 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 564 | break; | ||
| 565 | } | ||
| 566 | |||
| 567 | case EFC_EVT_FLOGI_RCVD: { | ||
| 568 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 569 | u32 d_id = ntoh24(hdr->fh_d_id); | ||
| 570 | |||
| 571 | /* sm: / save sparams, send FLOGI acc */ | ||
| 572 | memcpy(node->nport->domain->flogi_service_params, | ||
| 573 | cbdata->payload->dma.virt, | ||
| 574 | sizeof(struct fc_els_flogi)); | ||
| 575 | |||
| 576 | /* send FC LS_ACC response, override s_id */ | ||
| 577 | efc_fabric_set_topology(node, EFC_NPORT_TOPO_P2P); | ||
| 578 | |||
| 579 | efc_send_flogi_p2p_acc(node, be16_to_cpu(hdr->fh_ox_id), d_id); | ||
| 580 | |||
| 581 | if (efc_p2p_setup(node->nport)) { | ||
| 582 | node_printf(node, "p2p failed, shutting down node\n"); | ||
| 583 | efc_node_post_event(node, EFC_EVT_SHUTDOWN, NULL); | ||
| 584 | break; | ||
| 585 | } | ||
| 586 | |||
| 587 | efc_node_transition(node, __efc_p2p_wait_flogi_acc_cmpl, NULL); | ||
| 588 | break; | ||
| 589 | } | ||
| 590 | |||
| 591 | case EFC_EVT_LOGO_RCVD: { | ||
| 592 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 593 | |||
| 594 | if (!node->nport->domain->attached) { | ||
| 595 | /* most likely a frame left over from before a link | ||
| 596 | * down; drop and | ||
| 597 | * shut node down w/ "explicit logout" so pending | ||
| 598 | * frames are processed | ||
| 599 | */ | ||
| 600 | node_printf(node, "%s domain not attached, dropping\n", | ||
| 601 | efc_sm_event_name(evt)); | ||
| 602 | efc_node_post_event(node, | ||
| 603 | EFC_EVT_SHUTDOWN_EXPLICIT_LOGO, NULL); | ||
| 604 | break; | ||
| 605 | } | ||
| 606 | |||
| 607 | efc_send_logo_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 608 | efc_node_transition(node, __efc_d_wait_logo_acc_cmpl, NULL); | ||
| 609 | break; | ||
| 610 | } | ||
| 611 | |||
| 612 | case EFC_EVT_PRLI_RCVD: | ||
| 613 | case EFC_EVT_PRLO_RCVD: | ||
| 614 | case EFC_EVT_PDISC_RCVD: | ||
| 615 | case EFC_EVT_ADISC_RCVD: | ||
| 616 | case EFC_EVT_RSCN_RCVD: { | ||
| 617 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 618 | |||
| 619 | if (!node->nport->domain->attached) { | ||
| 620 | /* most likely a frame left over from before a link | ||
| 621 | * down; drop and shut node down w/ "explicit logout" | ||
| 622 | * so pending frames are processed | ||
| 623 | */ | ||
| 624 | node_printf(node, "%s domain not attached, dropping\n", | ||
| 625 | efc_sm_event_name(evt)); | ||
| 626 | |||
| 627 | efc_node_post_event(node, | ||
| 628 | EFC_EVT_SHUTDOWN_EXPLICIT_LOGO, | ||
| 629 | NULL); | ||
| 630 | break; | ||
| 631 | } | ||
| 632 | node_printf(node, "%s received, sending reject\n", | ||
| 633 | efc_sm_event_name(evt)); | ||
| 634 | |||
| 635 | efc_send_ls_rjt(node, be16_to_cpu(hdr->fh_ox_id), | ||
| 636 | ELS_RJT_UNAB, ELS_EXPL_PLOGI_REQD, 0); | ||
| 637 | |||
| 638 | break; | ||
| 639 | } | ||
| 640 | |||
| 641 | case EFC_EVT_FCP_CMD_RCVD: { | ||
| 642 | /* note: problem, we're now expecting an ELS REQ completion | ||
| 643 | * from both the LOGO and PLOGI | ||
| 644 | */ | ||
| 645 | if (!node->nport->domain->attached) { | ||
| 646 | /* most likely a frame left over from before a | ||
| 647 | * link down; drop and | ||
| 648 | * shut node down w/ "explicit logout" so pending | ||
| 649 | * frames are processed | ||
| 650 | */ | ||
| 651 | node_printf(node, "%s domain not attached, dropping\n", | ||
| 652 | efc_sm_event_name(evt)); | ||
| 653 | efc_node_post_event(node, | ||
| 654 | EFC_EVT_SHUTDOWN_EXPLICIT_LOGO, | ||
| 655 | NULL); | ||
| 656 | break; | ||
| 657 | } | ||
| 658 | |||
| 659 | /* Send LOGO */ | ||
| 660 | node_printf(node, "FCP_CMND received, send LOGO\n"); | ||
| 661 | if (efc_send_logo(node)) { | ||
| 662 | /* | ||
| 663 | * failed to send LOGO, go ahead and cleanup node | ||
| 664 | * anyways | ||
| 665 | */ | ||
| 666 | node_printf(node, "Failed to send LOGO\n"); | ||
| 667 | efc_node_post_event(node, | ||
| 668 | EFC_EVT_SHUTDOWN_EXPLICIT_LOGO, | ||
| 669 | NULL); | ||
| 670 | } else { | ||
| 671 | /* sent LOGO, wait for response */ | ||
| 672 | efc_node_transition(node, | ||
| 673 | __efc_d_wait_logo_rsp, NULL); | ||
| 674 | } | ||
| 675 | break; | ||
| 676 | } | ||
| 677 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 678 | /* don't care about domain_attach_ok */ | ||
| 679 | break; | ||
| 680 | |||
| 681 | default: | ||
| 682 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 683 | } | ||
| 684 | } | ||
| 685 | |||
| 686 | void | ||
| 687 | __efc_d_wait_plogi_rsp(struct efc_sm_ctx *ctx, | ||
| 688 | enum efc_sm_event evt, void *arg) | ||
| 689 | { | ||
| 690 | int rc; | ||
| 691 | struct efc_node_cb *cbdata = arg; | ||
| 692 | struct efc_node *node = ctx->app; | ||
| 693 | |||
| 694 | efc_node_evt_set(ctx, evt, __func__); | ||
| 695 | |||
| 696 | node_sm_trace(); | ||
| 697 | |||
| 698 | switch (evt) { | ||
| 699 | case EFC_EVT_PLOGI_RCVD: { | ||
| 700 | /* T, or I+T */ | ||
| 701 | /* received PLOGI with svc parms, go ahead and attach node | ||
| 702 | * when PLOGI that was sent ultimately completes, it'll be a | ||
| 703 | * no-op | ||
| 704 | * | ||
| 705 | * If there is an outstanding PLOGI sent, can we set a flag | ||
| 706 | * to indicate that we don't want to retry it if it times out? | ||
| 707 | */ | ||
| 708 | efc_node_save_sparms(node, cbdata->payload->dma.virt); | ||
| 709 | efc_send_ls_acc_after_attach(node, | ||
| 710 | cbdata->header->dma.virt, | ||
| 711 | EFC_NODE_SEND_LS_ACC_PLOGI); | ||
| 712 | /* sm: domain->attached / efc_node_attach */ | ||
| 713 | rc = efc_node_attach(node); | ||
| 714 | efc_node_transition(node, __efc_d_wait_node_attach, NULL); | ||
| 715 | if (rc < 0) | ||
| 716 | efc_node_post_event(node, | ||
| 717 | EFC_EVT_NODE_ATTACH_FAIL, NULL); | ||
| 718 | |||
| 719 | break; | ||
| 720 | } | ||
| 721 | |||
| 722 | case EFC_EVT_PRLI_RCVD: | ||
| 723 | /* I, or I+T */ | ||
| 724 | /* sent PLOGI and before completion was seen, received the | ||
| 725 | * PRLI from the remote node (WCQEs and RCQEs come in on | ||
| 726 | * different queues and order of processing cannot be assumed) | ||
| 727 | * Save OXID so PRLI can be sent after the attach and continue | ||
| 728 | * to wait for PLOGI response | ||
| 729 | */ | ||
| 730 | efc_process_prli_payload(node, cbdata->payload->dma.virt); | ||
| 731 | efc_send_ls_acc_after_attach(node, | ||
| 732 | cbdata->header->dma.virt, | ||
| 733 | EFC_NODE_SEND_LS_ACC_PRLI); | ||
| 734 | efc_node_transition(node, __efc_d_wait_plogi_rsp_recvd_prli, | ||
| 735 | NULL); | ||
| 736 | break; | ||
| 737 | |||
| 738 | case EFC_EVT_LOGO_RCVD: /* why don't we do a shutdown here?? */ | ||
| 739 | case EFC_EVT_PRLO_RCVD: | ||
| 740 | case EFC_EVT_PDISC_RCVD: | ||
| 741 | case EFC_EVT_FDISC_RCVD: | ||
| 742 | case EFC_EVT_ADISC_RCVD: | ||
| 743 | case EFC_EVT_RSCN_RCVD: | ||
| 744 | case EFC_EVT_SCR_RCVD: { | ||
| 745 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 746 | |||
| 747 | node_printf(node, "%s received, sending reject\n", | ||
| 748 | efc_sm_event_name(evt)); | ||
| 749 | |||
| 750 | efc_send_ls_rjt(node, be16_to_cpu(hdr->fh_ox_id), | ||
| 751 | ELS_RJT_UNAB, ELS_EXPL_PLOGI_REQD, 0); | ||
| 752 | |||
| 753 | break; | ||
| 754 | } | ||
| 755 | |||
| 756 | case EFC_EVT_SRRS_ELS_REQ_OK: /* PLOGI response received */ | ||
| 757 | /* Completion from PLOGI sent */ | ||
| 758 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PLOGI, | ||
| 759 | __efc_d_common, __func__)) | ||
| 760 | return; | ||
| 761 | |||
| 762 | WARN_ON(!node->els_req_cnt); | ||
| 763 | node->els_req_cnt--; | ||
| 764 | /* sm: / save sparams, efc_node_attach */ | ||
| 765 | efc_node_save_sparms(node, cbdata->els_rsp.virt); | ||
| 766 | rc = efc_node_attach(node); | ||
| 767 | efc_node_transition(node, __efc_d_wait_node_attach, NULL); | ||
| 768 | if (rc < 0) | ||
| 769 | efc_node_post_event(node, | ||
| 770 | EFC_EVT_NODE_ATTACH_FAIL, NULL); | ||
| 771 | |||
| 772 | break; | ||
| 773 | |||
| 774 | case EFC_EVT_SRRS_ELS_REQ_FAIL: /* PLOGI response received */ | ||
| 775 | /* PLOGI failed, shutdown the node */ | ||
| 776 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PLOGI, | ||
| 777 | __efc_d_common, __func__)) | ||
| 778 | return; | ||
| 779 | |||
| 780 | WARN_ON(!node->els_req_cnt); | ||
| 781 | node->els_req_cnt--; | ||
| 782 | efc_node_post_event(node, EFC_EVT_SHUTDOWN, NULL); | ||
| 783 | break; | ||
| 784 | |||
| 785 | case EFC_EVT_SRRS_ELS_REQ_RJT: | ||
| 786 | /* Our PLOGI was rejected, this is ok in some cases */ | ||
| 787 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PLOGI, | ||
| 788 | __efc_d_common, __func__)) | ||
| 789 | return; | ||
| 790 | |||
| 791 | WARN_ON(!node->els_req_cnt); | ||
| 792 | node->els_req_cnt--; | ||
| 793 | break; | ||
| 794 | |||
| 795 | case EFC_EVT_FCP_CMD_RCVD: { | ||
| 796 | /* not logged in yet and outstanding PLOGI so don't send LOGO, | ||
| 797 | * just drop | ||
| 798 | */ | ||
| 799 | node_printf(node, "FCP_CMND received, drop\n"); | ||
| 800 | break; | ||
| 801 | } | ||
| 802 | |||
| 803 | default: | ||
| 804 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 805 | } | ||
| 806 | } | ||
| 807 | |||
| 808 | void | ||
| 809 | __efc_d_wait_plogi_rsp_recvd_prli(struct efc_sm_ctx *ctx, | ||
| 810 | enum efc_sm_event evt, void *arg) | ||
| 811 | { | ||
| 812 | int rc; | ||
| 813 | struct efc_node_cb *cbdata = arg; | ||
| 814 | struct efc_node *node = ctx->app; | ||
| 815 | |||
| 816 | efc_node_evt_set(ctx, evt, __func__); | ||
| 817 | |||
| 818 | node_sm_trace(); | ||
| 819 | |||
| 820 | switch (evt) { | ||
| 821 | case EFC_EVT_ENTER: | ||
| 822 | /* | ||
| 823 | * Since we've received a PRLI, we have a port login and will | ||
| 824 | * just need to wait for the PLOGI response to do the node | ||
| 825 | * attach and then we can send the LS_ACC for the PRLI. If, | ||
| 826 | * during this time, we receive FCP_CMNDs (which is possible | ||
| 827 | * since we've already sent a PRLI and our peer may have | ||
| 828 | * accepted). At this time, we are not waiting on any other | ||
| 829 | * unsolicited frames to continue with the login process. Thus, | ||
| 830 | * it will not hurt to hold frames here. | ||
| 831 | */ | ||
| 832 | efc_node_hold_frames(node); | ||
| 833 | break; | ||
| 834 | |||
| 835 | case EFC_EVT_EXIT: | ||
| 836 | efc_node_accept_frames(node); | ||
| 837 | break; | ||
| 838 | |||
| 839 | case EFC_EVT_SRRS_ELS_REQ_OK: /* PLOGI response received */ | ||
| 840 | /* Completion from PLOGI sent */ | ||
| 841 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PLOGI, | ||
| 842 | __efc_d_common, __func__)) | ||
| 843 | return; | ||
| 844 | |||
| 845 | WARN_ON(!node->els_req_cnt); | ||
| 846 | node->els_req_cnt--; | ||
| 847 | /* sm: / save sparams, efc_node_attach */ | ||
| 848 | efc_node_save_sparms(node, cbdata->els_rsp.virt); | ||
| 849 | rc = efc_node_attach(node); | ||
| 850 | efc_node_transition(node, __efc_d_wait_node_attach, NULL); | ||
| 851 | if (rc < 0) | ||
| 852 | efc_node_post_event(node, EFC_EVT_NODE_ATTACH_FAIL, | ||
| 853 | NULL); | ||
| 854 | |||
| 855 | break; | ||
| 856 | |||
| 857 | case EFC_EVT_SRRS_ELS_REQ_FAIL: /* PLOGI response received */ | ||
| 858 | case EFC_EVT_SRRS_ELS_REQ_RJT: | ||
| 859 | /* PLOGI failed, shutdown the node */ | ||
| 860 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PLOGI, | ||
| 861 | __efc_d_common, __func__)) | ||
| 862 | return; | ||
| 863 | |||
| 864 | WARN_ON(!node->els_req_cnt); | ||
| 865 | node->els_req_cnt--; | ||
| 866 | efc_node_post_event(node, EFC_EVT_SHUTDOWN, NULL); | ||
| 867 | break; | ||
| 868 | |||
| 869 | default: | ||
| 870 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 871 | } | ||
| 872 | } | ||
| 873 | |||
| 874 | void | ||
| 875 | __efc_d_wait_domain_attach(struct efc_sm_ctx *ctx, | ||
| 876 | enum efc_sm_event evt, void *arg) | ||
| 877 | { | ||
| 878 | int rc; | ||
| 879 | struct efc_node *node = ctx->app; | ||
| 880 | |||
| 881 | efc_node_evt_set(ctx, evt, __func__); | ||
| 882 | |||
| 883 | node_sm_trace(); | ||
| 884 | |||
| 885 | switch (evt) { | ||
| 886 | case EFC_EVT_ENTER: | ||
| 887 | efc_node_hold_frames(node); | ||
| 888 | break; | ||
| 889 | |||
| 890 | case EFC_EVT_EXIT: | ||
| 891 | efc_node_accept_frames(node); | ||
| 892 | break; | ||
| 893 | |||
| 894 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 895 | WARN_ON(!node->nport->domain->attached); | ||
| 896 | /* sm: / efc_node_attach */ | ||
| 897 | rc = efc_node_attach(node); | ||
| 898 | efc_node_transition(node, __efc_d_wait_node_attach, NULL); | ||
| 899 | if (rc < 0) | ||
| 900 | efc_node_post_event(node, EFC_EVT_NODE_ATTACH_FAIL, | ||
| 901 | NULL); | ||
| 902 | |||
| 903 | break; | ||
| 904 | |||
| 905 | default: | ||
| 906 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 907 | } | ||
| 908 | } | ||
| 909 | |||
| 910 | void | ||
| 911 | __efc_d_wait_topology_notify(struct efc_sm_ctx *ctx, | ||
| 912 | enum efc_sm_event evt, void *arg) | ||
| 913 | { | ||
| 914 | int rc; | ||
| 915 | struct efc_node *node = ctx->app; | ||
| 916 | |||
| 917 | efc_node_evt_set(ctx, evt, __func__); | ||
| 918 | |||
| 919 | node_sm_trace(); | ||
| 920 | |||
| 921 | switch (evt) { | ||
| 922 | case EFC_EVT_ENTER: | ||
| 923 | efc_node_hold_frames(node); | ||
| 924 | break; | ||
| 925 | |||
| 926 | case EFC_EVT_EXIT: | ||
| 927 | efc_node_accept_frames(node); | ||
| 928 | break; | ||
| 929 | |||
| 930 | case EFC_EVT_NPORT_TOPOLOGY_NOTIFY: { | ||
| 931 | enum efc_nport_topology topology = | ||
| 932 | (enum efc_nport_topology)arg; | ||
| 933 | |||
| 934 | WARN_ON(node->nport->domain->attached); | ||
| 935 | |||
| 936 | WARN_ON(node->send_ls_acc != EFC_NODE_SEND_LS_ACC_PLOGI); | ||
| 937 | |||
| 938 | node_printf(node, "topology notification, topology=%d\n", | ||
| 939 | topology); | ||
| 940 | |||
| 941 | /* At the time the PLOGI was received, the topology was unknown, | ||
| 942 | * so we didn't know which node would perform the domain attach: | ||
| 943 | * 1. The node from which the PLOGI was sent (p2p) or | ||
| 944 | * 2. The node to which the FLOGI was sent (fabric). | ||
| 945 | */ | ||
| 946 | if (topology == EFC_NPORT_TOPO_P2P) { | ||
| 947 | /* if this is p2p, need to attach to the domain using | ||
| 948 | * the d_id from the PLOGI received | ||
| 949 | */ | ||
| 950 | efc_domain_attach(node->nport->domain, | ||
| 951 | node->ls_acc_did); | ||
| 952 | } | ||
| 953 | /* else, if this is fabric, the domain attach | ||
| 954 | * should be performed by the fabric node (node sending FLOGI); | ||
| 955 | * just wait for attach to complete | ||
| 956 | */ | ||
| 957 | |||
| 958 | efc_node_transition(node, __efc_d_wait_domain_attach, NULL); | ||
| 959 | break; | ||
| 960 | } | ||
| 961 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 962 | WARN_ON(!node->nport->domain->attached); | ||
| 963 | node_printf(node, "domain attach ok\n"); | ||
| 964 | /* sm: / efc_node_attach */ | ||
| 965 | rc = efc_node_attach(node); | ||
| 966 | efc_node_transition(node, __efc_d_wait_node_attach, NULL); | ||
| 967 | if (rc < 0) | ||
| 968 | efc_node_post_event(node, | ||
| 969 | EFC_EVT_NODE_ATTACH_FAIL, NULL); | ||
| 970 | |||
| 971 | break; | ||
| 972 | |||
| 973 | default: | ||
| 974 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 975 | } | ||
| 976 | } | ||
| 977 | |||
| 978 | void | ||
| 979 | __efc_d_wait_node_attach(struct efc_sm_ctx *ctx, | ||
| 980 | enum efc_sm_event evt, void *arg) | ||
| 981 | { | ||
| 982 | struct efc_node *node = ctx->app; | ||
| 983 | |||
| 984 | efc_node_evt_set(ctx, evt, __func__); | ||
| 985 | |||
| 986 | node_sm_trace(); | ||
| 987 | |||
| 988 | switch (evt) { | ||
| 989 | case EFC_EVT_ENTER: | ||
| 990 | efc_node_hold_frames(node); | ||
| 991 | break; | ||
| 992 | |||
| 993 | case EFC_EVT_EXIT: | ||
| 994 | efc_node_accept_frames(node); | ||
| 995 | break; | ||
| 996 | |||
| 997 | case EFC_EVT_NODE_ATTACH_OK: | ||
| 998 | node->attached = true; | ||
| 999 | switch (node->send_ls_acc) { | ||
| 1000 | case EFC_NODE_SEND_LS_ACC_PLOGI: { | ||
| 1001 | /* sm: send_plogi_acc is set / send PLOGI acc */ | ||
| 1002 | /* Normal case for T, or I+T */ | ||
| 1003 | efc_send_plogi_acc(node, node->ls_acc_oxid); | ||
| 1004 | efc_node_transition(node, __efc_d_wait_plogi_acc_cmpl, | ||
| 1005 | NULL); | ||
| 1006 | node->send_ls_acc = EFC_NODE_SEND_LS_ACC_NONE; | ||
| 1007 | node->ls_acc_io = NULL; | ||
| 1008 | break; | ||
| 1009 | } | ||
| 1010 | case EFC_NODE_SEND_LS_ACC_PRLI: { | ||
| 1011 | efc_d_send_prli_rsp(node, node->ls_acc_oxid); | ||
| 1012 | node->send_ls_acc = EFC_NODE_SEND_LS_ACC_NONE; | ||
| 1013 | node->ls_acc_io = NULL; | ||
| 1014 | break; | ||
| 1015 | } | ||
| 1016 | case EFC_NODE_SEND_LS_ACC_NONE: | ||
| 1017 | default: | ||
| 1018 | /* Normal case for I */ | ||
| 1019 | /* sm: send_plogi_acc is not set / send PLOGI acc */ | ||
| 1020 | efc_node_transition(node, | ||
| 1021 | __efc_d_port_logged_in, NULL); | ||
| 1022 | break; | ||
| 1023 | } | ||
| 1024 | break; | ||
| 1025 | |||
| 1026 | case EFC_EVT_NODE_ATTACH_FAIL: | ||
| 1027 | /* node attach failed, shutdown the node */ | ||
| 1028 | node->attached = false; | ||
| 1029 | node_printf(node, "node attach failed\n"); | ||
| 1030 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 1031 | efc_node_transition(node, __efc_d_initiate_shutdown, NULL); | ||
| 1032 | break; | ||
| 1033 | |||
| 1034 | /* Handle shutdown events */ | ||
| 1035 | case EFC_EVT_SHUTDOWN: | ||
| 1036 | node_printf(node, "%s received\n", efc_sm_event_name(evt)); | ||
| 1037 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 1038 | efc_node_transition(node, __efc_d_wait_attach_evt_shutdown, | ||
| 1039 | NULL); | ||
| 1040 | break; | ||
| 1041 | case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO: | ||
| 1042 | node_printf(node, "%s received\n", efc_sm_event_name(evt)); | ||
| 1043 | node->shutdown_reason = EFC_NODE_SHUTDOWN_EXPLICIT_LOGO; | ||
| 1044 | efc_node_transition(node, __efc_d_wait_attach_evt_shutdown, | ||
| 1045 | NULL); | ||
| 1046 | break; | ||
| 1047 | case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO: | ||
| 1048 | node_printf(node, "%s received\n", efc_sm_event_name(evt)); | ||
| 1049 | node->shutdown_reason = EFC_NODE_SHUTDOWN_IMPLICIT_LOGO; | ||
| 1050 | efc_node_transition(node, | ||
| 1051 | __efc_d_wait_attach_evt_shutdown, NULL); | ||
| 1052 | break; | ||
| 1053 | default: | ||
| 1054 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 1055 | } | ||
| 1056 | } | ||
| 1057 | |||
| 1058 | void | ||
| 1059 | __efc_d_wait_attach_evt_shutdown(struct efc_sm_ctx *ctx, | ||
| 1060 | enum efc_sm_event evt, void *arg) | ||
| 1061 | { | ||
| 1062 | struct efc_node *node = ctx->app; | ||
| 1063 | |||
| 1064 | efc_node_evt_set(ctx, evt, __func__); | ||
| 1065 | |||
| 1066 | node_sm_trace(); | ||
| 1067 | |||
| 1068 | switch (evt) { | ||
| 1069 | case EFC_EVT_ENTER: | ||
| 1070 | efc_node_hold_frames(node); | ||
| 1071 | break; | ||
| 1072 | |||
| 1073 | case EFC_EVT_EXIT: | ||
| 1074 | efc_node_accept_frames(node); | ||
| 1075 | break; | ||
| 1076 | |||
| 1077 | /* wait for any of these attach events and then shutdown */ | ||
| 1078 | case EFC_EVT_NODE_ATTACH_OK: | ||
| 1079 | node->attached = true; | ||
| 1080 | node_printf(node, "Attach evt=%s, proceed to shutdown\n", | ||
| 1081 | efc_sm_event_name(evt)); | ||
| 1082 | efc_node_transition(node, __efc_d_initiate_shutdown, NULL); | ||
| 1083 | break; | ||
| 1084 | |||
| 1085 | case EFC_EVT_NODE_ATTACH_FAIL: | ||
| 1086 | /* node attach failed, shutdown the node */ | ||
| 1087 | node->attached = false; | ||
| 1088 | node_printf(node, "Attach evt=%s, proceed to shutdown\n", | ||
| 1089 | efc_sm_event_name(evt)); | ||
| 1090 | efc_node_transition(node, __efc_d_initiate_shutdown, NULL); | ||
| 1091 | break; | ||
| 1092 | |||
| 1093 | /* ignore shutdown events as we're already in shutdown path */ | ||
| 1094 | case EFC_EVT_SHUTDOWN: | ||
| 1095 | /* have default shutdown event take precedence */ | ||
| 1096 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 1097 | fallthrough; | ||
| 1098 | |||
| 1099 | case EFC_EVT_SHUTDOWN_EXPLICIT_LOGO: | ||
| 1100 | case EFC_EVT_SHUTDOWN_IMPLICIT_LOGO: | ||
| 1101 | node_printf(node, "%s received\n", efc_sm_event_name(evt)); | ||
| 1102 | break; | ||
| 1103 | |||
| 1104 | default: | ||
| 1105 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 1106 | } | ||
| 1107 | } | ||
| 1108 | |||
| 1109 | void | ||
| 1110 | __efc_d_port_logged_in(struct efc_sm_ctx *ctx, | ||
| 1111 | enum efc_sm_event evt, void *arg) | ||
| 1112 | { | ||
| 1113 | struct efc_node_cb *cbdata = arg; | ||
| 1114 | struct efc_node *node = ctx->app; | ||
| 1115 | |||
| 1116 | efc_node_evt_set(ctx, evt, __func__); | ||
| 1117 | |||
| 1118 | node_sm_trace(); | ||
| 1119 | |||
| 1120 | switch (evt) { | ||
| 1121 | case EFC_EVT_ENTER: | ||
| 1122 | /* Normal case for I or I+T */ | ||
| 1123 | if (node->nport->enable_ini && | ||
| 1124 | !(node->rnode.fc_id != FC_FID_DOM_MGR)) { | ||
| 1125 | /* sm: if enable_ini / send PRLI */ | ||
| 1126 | efc_send_prli(node); | ||
| 1127 | /* can now expect ELS_REQ_OK/FAIL/RJT */ | ||
| 1128 | } | ||
| 1129 | break; | ||
| 1130 | |||
| 1131 | case EFC_EVT_FCP_CMD_RCVD: { | ||
| 1132 | break; | ||
| 1133 | } | ||
| 1134 | |||
| 1135 | case EFC_EVT_PRLI_RCVD: { | ||
| 1136 | /* Normal case for T or I+T */ | ||
| 1137 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1138 | struct { | ||
| 1139 | struct fc_els_prli prli; | ||
| 1140 | struct fc_els_spp sp; | ||
| 1141 | } *pp; | ||
| 1142 | |||
| 1143 | pp = cbdata->payload->dma.virt; | ||
| 1144 | if (pp->sp.spp_type != FC_TYPE_FCP) { | ||
| 1145 | /*Only FCP is supported*/ | ||
| 1146 | efc_send_ls_rjt(node, be16_to_cpu(hdr->fh_ox_id), | ||
| 1147 | ELS_RJT_UNAB, ELS_EXPL_UNSUPR, 0); | ||
| 1148 | break; | ||
| 1149 | } | ||
| 1150 | |||
| 1151 | efc_process_prli_payload(node, cbdata->payload->dma.virt); | ||
| 1152 | efc_d_send_prli_rsp(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1153 | break; | ||
| 1154 | } | ||
| 1155 | |||
| 1156 | case EFC_EVT_NODE_SESS_REG_OK: | ||
| 1157 | if (node->send_ls_acc == EFC_NODE_SEND_LS_ACC_PRLI) | ||
| 1158 | efc_send_prli_acc(node, node->ls_acc_oxid); | ||
| 1159 | |||
| 1160 | node->send_ls_acc = EFC_NODE_SEND_LS_ACC_NONE; | ||
| 1161 | efc_node_transition(node, __efc_d_device_ready, NULL); | ||
| 1162 | break; | ||
| 1163 | |||
| 1164 | case EFC_EVT_NODE_SESS_REG_FAIL: | ||
| 1165 | efc_send_ls_rjt(node, node->ls_acc_oxid, ELS_RJT_UNAB, | ||
| 1166 | ELS_EXPL_UNSUPR, 0); | ||
| 1167 | node->send_ls_acc = EFC_NODE_SEND_LS_ACC_NONE; | ||
| 1168 | break; | ||
| 1169 | |||
| 1170 | case EFC_EVT_SRRS_ELS_REQ_OK: { /* PRLI response */ | ||
| 1171 | /* Normal case for I or I+T */ | ||
| 1172 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PRLI, | ||
| 1173 | __efc_d_common, __func__)) | ||
| 1174 | return; | ||
| 1175 | |||
| 1176 | WARN_ON(!node->els_req_cnt); | ||
| 1177 | node->els_req_cnt--; | ||
| 1178 | /* sm: / process PRLI payload */ | ||
| 1179 | efc_process_prli_payload(node, cbdata->els_rsp.virt); | ||
| 1180 | efc_node_transition(node, __efc_d_device_ready, NULL); | ||
| 1181 | break; | ||
| 1182 | } | ||
| 1183 | |||
| 1184 | case EFC_EVT_SRRS_ELS_REQ_FAIL: { /* PRLI response failed */ | ||
| 1185 | /* I, I+T, assume some link failure, shutdown node */ | ||
| 1186 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PRLI, | ||
| 1187 | __efc_d_common, __func__)) | ||
| 1188 | return; | ||
| 1189 | |||
| 1190 | WARN_ON(!node->els_req_cnt); | ||
| 1191 | node->els_req_cnt--; | ||
| 1192 | efc_node_post_event(node, EFC_EVT_SHUTDOWN, NULL); | ||
| 1193 | break; | ||
| 1194 | } | ||
| 1195 | |||
| 1196 | case EFC_EVT_SRRS_ELS_REQ_RJT: { | ||
| 1197 | /* PRLI rejected by remote | ||
| 1198 | * Normal for I, I+T (connected to an I) | ||
| 1199 | * Node doesn't want to be a target, stay here and wait for a | ||
| 1200 | * PRLI from the remote node | ||
| 1201 | * if it really wants to connect to us as target | ||
| 1202 | */ | ||
| 1203 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PRLI, | ||
| 1204 | __efc_d_common, __func__)) | ||
| 1205 | return; | ||
| 1206 | |||
| 1207 | WARN_ON(!node->els_req_cnt); | ||
| 1208 | node->els_req_cnt--; | ||
| 1209 | break; | ||
| 1210 | } | ||
| 1211 | |||
| 1212 | case EFC_EVT_SRRS_ELS_CMPL_OK: { | ||
| 1213 | /* Normal T, I+T, target-server rejected the process login */ | ||
| 1214 | /* This would be received only in the case where we sent | ||
| 1215 | * LS_RJT for the PRLI, so | ||
| 1216 | * do nothing. (note: as T only we could shutdown the node) | ||
| 1217 | */ | ||
| 1218 | WARN_ON(!node->els_cmpl_cnt); | ||
| 1219 | node->els_cmpl_cnt--; | ||
| 1220 | break; | ||
| 1221 | } | ||
| 1222 | |||
| 1223 | case EFC_EVT_PLOGI_RCVD: { | ||
| 1224 | /*sm: / save sparams, set send_plogi_acc, | ||
| 1225 | *post implicit logout | ||
| 1226 | * Save plogi parameters | ||
| 1227 | */ | ||
| 1228 | efc_node_save_sparms(node, cbdata->payload->dma.virt); | ||
| 1229 | efc_send_ls_acc_after_attach(node, | ||
| 1230 | cbdata->header->dma.virt, | ||
| 1231 | EFC_NODE_SEND_LS_ACC_PLOGI); | ||
| 1232 | |||
| 1233 | /* Restart node attach with new service parameters, | ||
| 1234 | * and send ACC | ||
| 1235 | */ | ||
| 1236 | efc_node_post_event(node, EFC_EVT_SHUTDOWN_IMPLICIT_LOGO, | ||
| 1237 | NULL); | ||
| 1238 | break; | ||
| 1239 | } | ||
| 1240 | |||
| 1241 | case EFC_EVT_LOGO_RCVD: { | ||
| 1242 | /* I, T, I+T */ | ||
| 1243 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1244 | |||
| 1245 | node_printf(node, "%s received attached=%d\n", | ||
| 1246 | efc_sm_event_name(evt), | ||
| 1247 | node->attached); | ||
| 1248 | /* sm: / send LOGO acc */ | ||
| 1249 | efc_send_logo_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1250 | efc_node_transition(node, __efc_d_wait_logo_acc_cmpl, NULL); | ||
| 1251 | break; | ||
| 1252 | } | ||
| 1253 | |||
| 1254 | default: | ||
| 1255 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 1256 | } | ||
| 1257 | } | ||
| 1258 | |||
| 1259 | void | ||
| 1260 | __efc_d_wait_logo_acc_cmpl(struct efc_sm_ctx *ctx, | ||
| 1261 | enum efc_sm_event evt, void *arg) | ||
| 1262 | { | ||
| 1263 | struct efc_node *node = ctx->app; | ||
| 1264 | |||
| 1265 | efc_node_evt_set(ctx, evt, __func__); | ||
| 1266 | |||
| 1267 | node_sm_trace(); | ||
| 1268 | |||
| 1269 | switch (evt) { | ||
| 1270 | case EFC_EVT_ENTER: | ||
| 1271 | efc_node_hold_frames(node); | ||
| 1272 | break; | ||
| 1273 | |||
| 1274 | case EFC_EVT_EXIT: | ||
| 1275 | efc_node_accept_frames(node); | ||
| 1276 | break; | ||
| 1277 | |||
| 1278 | case EFC_EVT_SRRS_ELS_CMPL_OK: | ||
| 1279 | case EFC_EVT_SRRS_ELS_CMPL_FAIL: | ||
| 1280 | /* sm: / post explicit logout */ | ||
| 1281 | WARN_ON(!node->els_cmpl_cnt); | ||
| 1282 | node->els_cmpl_cnt--; | ||
| 1283 | efc_node_post_event(node, | ||
| 1284 | EFC_EVT_SHUTDOWN_EXPLICIT_LOGO, NULL); | ||
| 1285 | break; | ||
| 1286 | default: | ||
| 1287 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 1288 | } | ||
| 1289 | } | ||
| 1290 | |||
| 1291 | void | ||
| 1292 | __efc_d_device_ready(struct efc_sm_ctx *ctx, | ||
| 1293 | enum efc_sm_event evt, void *arg) | ||
| 1294 | { | ||
| 1295 | struct efc_node_cb *cbdata = arg; | ||
| 1296 | struct efc_node *node = ctx->app; | ||
| 1297 | struct efc *efc = node->efc; | ||
| 1298 | |||
| 1299 | efc_node_evt_set(ctx, evt, __func__); | ||
| 1300 | |||
| 1301 | if (evt != EFC_EVT_FCP_CMD_RCVD) | ||
| 1302 | node_sm_trace(); | ||
| 1303 | |||
| 1304 | switch (evt) { | ||
| 1305 | case EFC_EVT_ENTER: | ||
| 1306 | node->fcp_enabled = true; | ||
| 1307 | if (node->targ) { | ||
| 1308 | efc_log_info(efc, | ||
| 1309 | "[%s] found (target) WWPN %s WWNN %s\n", | ||
| 1310 | node->display_name, | ||
| 1311 | node->wwpn, node->wwnn); | ||
| 1312 | if (node->nport->enable_ini) | ||
| 1313 | efc->tt.scsi_new_node(efc, node); | ||
| 1314 | } | ||
| 1315 | break; | ||
| 1316 | |||
| 1317 | case EFC_EVT_EXIT: | ||
| 1318 | node->fcp_enabled = false; | ||
| 1319 | break; | ||
| 1320 | |||
| 1321 | case EFC_EVT_PLOGI_RCVD: { | ||
| 1322 | /* sm: / save sparams, set send_plogi_acc, post implicit | ||
| 1323 | * logout | ||
| 1324 | * Save plogi parameters | ||
| 1325 | */ | ||
| 1326 | efc_node_save_sparms(node, cbdata->payload->dma.virt); | ||
| 1327 | efc_send_ls_acc_after_attach(node, | ||
| 1328 | cbdata->header->dma.virt, | ||
| 1329 | EFC_NODE_SEND_LS_ACC_PLOGI); | ||
| 1330 | |||
| 1331 | /* | ||
| 1332 | * Restart node attach with new service parameters, | ||
| 1333 | * and send ACC | ||
| 1334 | */ | ||
| 1335 | efc_node_post_event(node, | ||
| 1336 | EFC_EVT_SHUTDOWN_IMPLICIT_LOGO, NULL); | ||
| 1337 | break; | ||
| 1338 | } | ||
| 1339 | |||
| 1340 | case EFC_EVT_PRLI_RCVD: { | ||
| 1341 | /* T, I+T: remote initiator is slow to get started */ | ||
| 1342 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1343 | struct { | ||
| 1344 | struct fc_els_prli prli; | ||
| 1345 | struct fc_els_spp sp; | ||
| 1346 | } *pp; | ||
| 1347 | |||
| 1348 | pp = cbdata->payload->dma.virt; | ||
| 1349 | if (pp->sp.spp_type != FC_TYPE_FCP) { | ||
| 1350 | /*Only FCP is supported*/ | ||
| 1351 | efc_send_ls_rjt(node, be16_to_cpu(hdr->fh_ox_id), | ||
| 1352 | ELS_RJT_UNAB, ELS_EXPL_UNSUPR, 0); | ||
| 1353 | break; | ||
| 1354 | } | ||
| 1355 | |||
| 1356 | efc_process_prli_payload(node, cbdata->payload->dma.virt); | ||
| 1357 | efc_send_prli_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1358 | break; | ||
| 1359 | } | ||
| 1360 | |||
| 1361 | case EFC_EVT_PRLO_RCVD: { | ||
| 1362 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1363 | /* sm: / send PRLO acc */ | ||
| 1364 | efc_send_prlo_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1365 | /* need implicit logout? */ | ||
| 1366 | break; | ||
| 1367 | } | ||
| 1368 | |||
| 1369 | case EFC_EVT_LOGO_RCVD: { | ||
| 1370 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1371 | |||
| 1372 | node_printf(node, "%s received attached=%d\n", | ||
| 1373 | efc_sm_event_name(evt), node->attached); | ||
| 1374 | /* sm: / send LOGO acc */ | ||
| 1375 | efc_send_logo_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1376 | efc_node_transition(node, __efc_d_wait_logo_acc_cmpl, NULL); | ||
| 1377 | break; | ||
| 1378 | } | ||
| 1379 | |||
| 1380 | case EFC_EVT_ADISC_RCVD: { | ||
| 1381 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1382 | /* sm: / send ADISC acc */ | ||
| 1383 | efc_send_adisc_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1384 | break; | ||
| 1385 | } | ||
| 1386 | |||
| 1387 | case EFC_EVT_ABTS_RCVD: | ||
| 1388 | /* sm: / process ABTS */ | ||
| 1389 | efc_log_err(efc, "Unexpected event:%s\n", | ||
| 1390 | efc_sm_event_name(evt)); | ||
| 1391 | break; | ||
| 1392 | |||
| 1393 | case EFC_EVT_NODE_ACTIVE_IO_LIST_EMPTY: | ||
| 1394 | break; | ||
| 1395 | |||
| 1396 | case EFC_EVT_NODE_REFOUND: | ||
| 1397 | break; | ||
| 1398 | |||
| 1399 | case EFC_EVT_NODE_MISSING: | ||
| 1400 | if (node->nport->enable_rscn) | ||
| 1401 | efc_node_transition(node, __efc_d_device_gone, NULL); | ||
| 1402 | |||
| 1403 | break; | ||
| 1404 | |||
| 1405 | case EFC_EVT_SRRS_ELS_CMPL_OK: | ||
| 1406 | /* T, or I+T, PRLI accept completed ok */ | ||
| 1407 | WARN_ON(!node->els_cmpl_cnt); | ||
| 1408 | node->els_cmpl_cnt--; | ||
| 1409 | break; | ||
| 1410 | |||
| 1411 | case EFC_EVT_SRRS_ELS_CMPL_FAIL: | ||
| 1412 | /* T, or I+T, PRLI accept failed to complete */ | ||
| 1413 | WARN_ON(!node->els_cmpl_cnt); | ||
| 1414 | node->els_cmpl_cnt--; | ||
| 1415 | node_printf(node, "Failed to send PRLI LS_ACC\n"); | ||
| 1416 | break; | ||
| 1417 | |||
| 1418 | default: | ||
| 1419 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 1420 | } | ||
| 1421 | } | ||
| 1422 | |||
| 1423 | void | ||
| 1424 | __efc_d_device_gone(struct efc_sm_ctx *ctx, | ||
| 1425 | enum efc_sm_event evt, void *arg) | ||
| 1426 | { | ||
| 1427 | struct efc_node_cb *cbdata = arg; | ||
| 1428 | struct efc_node *node = ctx->app; | ||
| 1429 | struct efc *efc = node->efc; | ||
| 1430 | |||
| 1431 | efc_node_evt_set(ctx, evt, __func__); | ||
| 1432 | |||
| 1433 | node_sm_trace(); | ||
| 1434 | |||
| 1435 | switch (evt) { | ||
| 1436 | case EFC_EVT_ENTER: { | ||
| 1437 | int rc = EFC_SCSI_CALL_COMPLETE; | ||
| 1438 | int rc_2 = EFC_SCSI_CALL_COMPLETE; | ||
| 1439 | static const char * const labels[] = { | ||
| 1440 | "none", "initiator", "target", "initiator+target" | ||
| 1441 | }; | ||
| 1442 | |||
| 1443 | efc_log_info(efc, "[%s] missing (%s) WWPN %s WWNN %s\n", | ||
| 1444 | node->display_name, | ||
| 1445 | labels[(node->targ << 1) | (node->init)], | ||
| 1446 | node->wwpn, node->wwnn); | ||
| 1447 | |||
| 1448 | switch (efc_node_get_enable(node)) { | ||
| 1449 | case EFC_NODE_ENABLE_T_TO_T: | ||
| 1450 | case EFC_NODE_ENABLE_I_TO_T: | ||
| 1451 | case EFC_NODE_ENABLE_IT_TO_T: | ||
| 1452 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 1453 | EFC_SCSI_TARGET_MISSING); | ||
| 1454 | break; | ||
| 1455 | |||
| 1456 | case EFC_NODE_ENABLE_T_TO_I: | ||
| 1457 | case EFC_NODE_ENABLE_I_TO_I: | ||
| 1458 | case EFC_NODE_ENABLE_IT_TO_I: | ||
| 1459 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 1460 | EFC_SCSI_INITIATOR_MISSING); | ||
| 1461 | break; | ||
| 1462 | |||
| 1463 | case EFC_NODE_ENABLE_T_TO_IT: | ||
| 1464 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 1465 | EFC_SCSI_INITIATOR_MISSING); | ||
| 1466 | break; | ||
| 1467 | |||
| 1468 | case EFC_NODE_ENABLE_I_TO_IT: | ||
| 1469 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 1470 | EFC_SCSI_TARGET_MISSING); | ||
| 1471 | break; | ||
| 1472 | |||
| 1473 | case EFC_NODE_ENABLE_IT_TO_IT: | ||
| 1474 | rc = efc->tt.scsi_del_node(efc, node, | ||
| 1475 | EFC_SCSI_INITIATOR_MISSING); | ||
| 1476 | rc_2 = efc->tt.scsi_del_node(efc, node, | ||
| 1477 | EFC_SCSI_TARGET_MISSING); | ||
| 1478 | break; | ||
| 1479 | |||
| 1480 | default: | ||
| 1481 | rc = EFC_SCSI_CALL_COMPLETE; | ||
| 1482 | break; | ||
| 1483 | } | ||
| 1484 | |||
| 1485 | if (rc == EFC_SCSI_CALL_COMPLETE && | ||
| 1486 | rc_2 == EFC_SCSI_CALL_COMPLETE) | ||
| 1487 | efc_node_post_event(node, EFC_EVT_SHUTDOWN, NULL); | ||
| 1488 | |||
| 1489 | break; | ||
| 1490 | } | ||
| 1491 | case EFC_EVT_NODE_REFOUND: | ||
| 1492 | /* two approaches, reauthenticate with PLOGI/PRLI, or ADISC */ | ||
| 1493 | |||
| 1494 | /* reauthenticate with PLOGI/PRLI */ | ||
| 1495 | /* efc_node_transition(node, __efc_d_discovered, NULL); */ | ||
| 1496 | |||
| 1497 | /* reauthenticate with ADISC */ | ||
| 1498 | /* sm: / send ADISC */ | ||
| 1499 | efc_send_adisc(node); | ||
| 1500 | efc_node_transition(node, __efc_d_wait_adisc_rsp, NULL); | ||
| 1501 | break; | ||
| 1502 | |||
| 1503 | case EFC_EVT_PLOGI_RCVD: { | ||
| 1504 | /* sm: / save sparams, set send_plogi_acc, post implicit | ||
| 1505 | * logout | ||
| 1506 | * Save plogi parameters | ||
| 1507 | */ | ||
| 1508 | efc_node_save_sparms(node, cbdata->payload->dma.virt); | ||
| 1509 | efc_send_ls_acc_after_attach(node, | ||
| 1510 | cbdata->header->dma.virt, | ||
| 1511 | EFC_NODE_SEND_LS_ACC_PLOGI); | ||
| 1512 | |||
| 1513 | /* | ||
| 1514 | * Restart node attach with new service parameters, and send | ||
| 1515 | * ACC | ||
| 1516 | */ | ||
| 1517 | efc_node_post_event(node, EFC_EVT_SHUTDOWN_IMPLICIT_LOGO, | ||
| 1518 | NULL); | ||
| 1519 | break; | ||
| 1520 | } | ||
| 1521 | |||
| 1522 | case EFC_EVT_FCP_CMD_RCVD: { | ||
| 1523 | /* most likely a stale frame (received prior to link down), | ||
| 1524 | * if attempt to send LOGO, will probably timeout and eat | ||
| 1525 | * up 20s; thus, drop FCP_CMND | ||
| 1526 | */ | ||
| 1527 | node_printf(node, "FCP_CMND received, drop\n"); | ||
| 1528 | break; | ||
| 1529 | } | ||
| 1530 | case EFC_EVT_LOGO_RCVD: { | ||
| 1531 | /* I, T, I+T */ | ||
| 1532 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1533 | |||
| 1534 | node_printf(node, "%s received attached=%d\n", | ||
| 1535 | efc_sm_event_name(evt), node->attached); | ||
| 1536 | /* sm: / send LOGO acc */ | ||
| 1537 | efc_send_logo_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1538 | efc_node_transition(node, __efc_d_wait_logo_acc_cmpl, NULL); | ||
| 1539 | break; | ||
| 1540 | } | ||
| 1541 | default: | ||
| 1542 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 1543 | } | ||
| 1544 | } | ||
| 1545 | |||
| 1546 | void | ||
| 1547 | __efc_d_wait_adisc_rsp(struct efc_sm_ctx *ctx, | ||
| 1548 | enum efc_sm_event evt, void *arg) | ||
| 1549 | { | ||
| 1550 | struct efc_node_cb *cbdata = arg; | ||
| 1551 | struct efc_node *node = ctx->app; | ||
| 1552 | |||
| 1553 | efc_node_evt_set(ctx, evt, __func__); | ||
| 1554 | |||
| 1555 | node_sm_trace(); | ||
| 1556 | |||
| 1557 | switch (evt) { | ||
| 1558 | case EFC_EVT_SRRS_ELS_REQ_OK: | ||
| 1559 | if (efc_node_check_els_req(ctx, evt, arg, ELS_ADISC, | ||
| 1560 | __efc_d_common, __func__)) | ||
| 1561 | return; | ||
| 1562 | |||
| 1563 | WARN_ON(!node->els_req_cnt); | ||
| 1564 | node->els_req_cnt--; | ||
| 1565 | efc_node_transition(node, __efc_d_device_ready, NULL); | ||
| 1566 | break; | ||
| 1567 | |||
| 1568 | case EFC_EVT_SRRS_ELS_REQ_RJT: | ||
| 1569 | /* received an LS_RJT, in this case, send shutdown | ||
| 1570 | * (explicit logo) event which will unregister the node, | ||
| 1571 | * and start over with PLOGI | ||
| 1572 | */ | ||
| 1573 | if (efc_node_check_els_req(ctx, evt, arg, ELS_ADISC, | ||
| 1574 | __efc_d_common, __func__)) | ||
| 1575 | return; | ||
| 1576 | |||
| 1577 | WARN_ON(!node->els_req_cnt); | ||
| 1578 | node->els_req_cnt--; | ||
| 1579 | /* sm: / post explicit logout */ | ||
| 1580 | efc_node_post_event(node, | ||
| 1581 | EFC_EVT_SHUTDOWN_EXPLICIT_LOGO, | ||
| 1582 | NULL); | ||
| 1583 | break; | ||
| 1584 | |||
| 1585 | case EFC_EVT_LOGO_RCVD: { | ||
| 1586 | /* In this case, we have the equivalent of an LS_RJT for | ||
| 1587 | * the ADISC, so we need to abort the ADISC, and re-login | ||
| 1588 | * with PLOGI | ||
| 1589 | */ | ||
| 1590 | /* sm: / request abort, send LOGO acc */ | ||
| 1591 | struct fc_frame_header *hdr = cbdata->header->dma.virt; | ||
| 1592 | |||
| 1593 | node_printf(node, "%s received attached=%d\n", | ||
| 1594 | efc_sm_event_name(evt), node->attached); | ||
| 1595 | |||
| 1596 | efc_send_logo_acc(node, be16_to_cpu(hdr->fh_ox_id)); | ||
| 1597 | efc_node_transition(node, __efc_d_wait_logo_acc_cmpl, NULL); | ||
| 1598 | break; | ||
| 1599 | } | ||
| 1600 | default: | ||
| 1601 | __efc_d_common(__func__, ctx, evt, arg); | ||
| 1602 | } | ||
| 1603 | } | ||
| @@ -0,0 +1,72 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * Node state machine functions for remote device node sm | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef __EFCT_DEVICE_H__ | ||
| 12 | #define __EFCT_DEVICE_H__ | ||
| 13 | void | ||
| 14 | efc_node_init_device(struct efc_node *node, bool send_plogi); | ||
| 15 | void | ||
| 16 | efc_process_prli_payload(struct efc_node *node, | ||
| 17 | void *prli); | ||
| 18 | void | ||
| 19 | efc_d_send_prli_rsp(struct efc_node *node, uint16_t ox_id); | ||
| 20 | void | ||
| 21 | efc_send_ls_acc_after_attach(struct efc_node *node, | ||
| 22 | struct fc_frame_header *hdr, | ||
| 23 | enum efc_node_send_ls_acc ls); | ||
| 24 | void | ||
| 25 | __efc_d_wait_loop(struct efc_sm_ctx *ctx, | ||
| 26 | enum efc_sm_event evt, void *arg); | ||
| 27 | void | ||
| 28 | __efc_d_wait_plogi_acc_cmpl(struct efc_sm_ctx *ctx, | ||
| 29 | enum efc_sm_event evt, void *arg); | ||
| 30 | void | ||
| 31 | __efc_d_init(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg); | ||
| 32 | void | ||
| 33 | __efc_d_wait_plogi_rsp(struct efc_sm_ctx *ctx, | ||
| 34 | enum efc_sm_event evt, void *arg); | ||
| 35 | void | ||
| 36 | __efc_d_wait_plogi_rsp_recvd_prli(struct efc_sm_ctx *ctx, | ||
| 37 | enum efc_sm_event evt, void *arg); | ||
| 38 | void | ||
| 39 | __efc_d_wait_domain_attach(struct efc_sm_ctx *ctx, | ||
| 40 | enum efc_sm_event evt, void *arg); | ||
| 41 | void | ||
| 42 | __efc_d_wait_topology_notify(struct efc_sm_ctx *ctx, | ||
| 43 | enum efc_sm_event evt, void *arg); | ||
| 44 | void | ||
| 45 | __efc_d_wait_node_attach(struct efc_sm_ctx *ctx, | ||
| 46 | enum efc_sm_event evt, void *arg); | ||
| 47 | void | ||
| 48 | __efc_d_wait_attach_evt_shutdown(struct efc_sm_ctx *ctx, | ||
| 49 | enum efc_sm_event evt, void *arg); | ||
| 50 | void | ||
| 51 | __efc_d_initiate_shutdown(struct efc_sm_ctx *ctx, | ||
| 52 | enum efc_sm_event evt, void *arg); | ||
| 53 | void | ||
| 54 | __efc_d_port_logged_in(struct efc_sm_ctx *ctx, | ||
| 55 | enum efc_sm_event evt, void *arg); | ||
| 56 | void | ||
| 57 | __efc_d_wait_logo_acc_cmpl(struct efc_sm_ctx *ctx, | ||
| 58 | enum efc_sm_event evt, void *arg); | ||
| 59 | void | ||
| 60 | __efc_d_device_ready(struct efc_sm_ctx *ctx, | ||
| 61 | enum efc_sm_event evt, void *arg); | ||
| 62 | void | ||
| 63 | __efc_d_device_gone(struct efc_sm_ctx *ctx, | ||
| 64 | enum efc_sm_event evt, void *arg); | ||
| 65 | void | ||
| 66 | __efc_d_wait_adisc_rsp(struct efc_sm_ctx *ctx, | ||
| 67 | enum efc_sm_event evt, void *arg); | ||
| 68 | void | ||
| 69 | __efc_d_wait_logo_rsp(struct efc_sm_ctx *ctx, | ||
| 70 | enum efc_sm_event evt, void *arg); | ||
| 71 | |||
| 72 | #endif /* __EFCT_DEVICE_H__ */ | ||
| @@ -0,0 +1,1088 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * domain_sm Domain State Machine: States | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include "efc.h" | ||
| 12 | |||
| 13 | int | ||
| 14 | efc_domain_cb(void *arg, int event, void *data) | ||
| 15 | { | ||
| 16 | struct efc *efc = arg; | ||
| 17 | struct efc_domain *domain = NULL; | ||
| 18 | int rc = 0; | ||
| 19 | unsigned long flags = 0; | ||
| 20 | |||
| 21 | if (event != EFC_HW_DOMAIN_FOUND) | ||
| 22 | domain = data; | ||
| 23 | |||
| 24 | /* Accept domain callback events from the user driver */ | ||
| 25 | spin_lock_irqsave(&efc->lock, flags); | ||
| 26 | switch (event) { | ||
| 27 | case EFC_HW_DOMAIN_FOUND: { | ||
| 28 | u64 fcf_wwn = 0; | ||
| 29 | struct efc_domain_record *drec = data; | ||
| 30 | |||
| 31 | /* extract the fcf_wwn */ | ||
| 32 | fcf_wwn = be64_to_cpu(*((__be64 *)drec->wwn)); | ||
| 33 | |||
| 34 | efc_log_debug(efc, "Domain found: wwn %016llX\n", fcf_wwn); | ||
| 35 | |||
| 36 | /* lookup domain, or allocate a new one */ | ||
| 37 | domain = efc->domain; | ||
| 38 | if (!domain) { | ||
| 39 | domain = efc_domain_alloc(efc, fcf_wwn); | ||
| 40 | if (!domain) { | ||
| 41 | efc_log_err(efc, "efc_domain_alloc() failed\n"); | ||
| 42 | rc = -1; | ||
| 43 | break; | ||
| 44 | } | ||
| 45 | efc_sm_transition(&domain->drvsm, __efc_domain_init, | ||
| 46 | NULL); | ||
| 47 | } | ||
| 48 | efc_domain_post_event(domain, EFC_EVT_DOMAIN_FOUND, drec); | ||
| 49 | break; | ||
| 50 | } | ||
| 51 | |||
| 52 | case EFC_HW_DOMAIN_LOST: | ||
| 53 | domain_trace(domain, "EFC_HW_DOMAIN_LOST:\n"); | ||
| 54 | efc->hold_frames = true; | ||
| 55 | efc_domain_post_event(domain, EFC_EVT_DOMAIN_LOST, NULL); | ||
| 56 | break; | ||
| 57 | |||
| 58 | case EFC_HW_DOMAIN_ALLOC_OK: | ||
| 59 | domain_trace(domain, "EFC_HW_DOMAIN_ALLOC_OK:\n"); | ||
| 60 | efc_domain_post_event(domain, EFC_EVT_DOMAIN_ALLOC_OK, NULL); | ||
| 61 | break; | ||
| 62 | |||
| 63 | case EFC_HW_DOMAIN_ALLOC_FAIL: | ||
| 64 | domain_trace(domain, "EFC_HW_DOMAIN_ALLOC_FAIL:\n"); | ||
| 65 | efc_domain_post_event(domain, EFC_EVT_DOMAIN_ALLOC_FAIL, | ||
| 66 | NULL); | ||
| 67 | break; | ||
| 68 | |||
| 69 | case EFC_HW_DOMAIN_ATTACH_OK: | ||
| 70 | domain_trace(domain, "EFC_HW_DOMAIN_ATTACH_OK:\n"); | ||
| 71 | efc_domain_post_event(domain, EFC_EVT_DOMAIN_ATTACH_OK, NULL); | ||
| 72 | break; | ||
| 73 | |||
| 74 | case EFC_HW_DOMAIN_ATTACH_FAIL: | ||
| 75 | domain_trace(domain, "EFC_HW_DOMAIN_ATTACH_FAIL:\n"); | ||
| 76 | efc_domain_post_event(domain, | ||
| 77 | EFC_EVT_DOMAIN_ATTACH_FAIL, NULL); | ||
| 78 | break; | ||
| 79 | |||
| 80 | case EFC_HW_DOMAIN_FREE_OK: | ||
| 81 | domain_trace(domain, "EFC_HW_DOMAIN_FREE_OK:\n"); | ||
| 82 | efc_domain_post_event(domain, EFC_EVT_DOMAIN_FREE_OK, NULL); | ||
| 83 | break; | ||
| 84 | |||
| 85 | case EFC_HW_DOMAIN_FREE_FAIL: | ||
| 86 | domain_trace(domain, "EFC_HW_DOMAIN_FREE_FAIL:\n"); | ||
| 87 | efc_domain_post_event(domain, EFC_EVT_DOMAIN_FREE_FAIL, NULL); | ||
| 88 | break; | ||
| 89 | |||
| 90 | default: | ||
| 91 | efc_log_warn(efc, "unsupported event %#x\n", event); | ||
| 92 | } | ||
| 93 | spin_unlock_irqrestore(&efc->lock, flags); | ||
| 94 | |||
| 95 | if (efc->domain && domain->req_accept_frames) { | ||
| 96 | domain->req_accept_frames = false; | ||
| 97 | efc->hold_frames = false; | ||
| 98 | } | ||
| 99 | |||
| 100 | return rc; | ||
| 101 | } | ||
| 102 | |||
| 103 | static void | ||
| 104 | _efc_domain_free(struct kref *arg) | ||
| 105 | { | ||
| 106 | struct efc_domain *domain = container_of(arg, struct efc_domain, ref); | ||
| 107 | struct efc *efc = domain->efc; | ||
| 108 | |||
| 109 | if (efc->domain_free_cb) | ||
| 110 | (*efc->domain_free_cb)(efc, efc->domain_free_cb_arg); | ||
| 111 | |||
| 112 | kfree(domain); | ||
| 113 | } | ||
| 114 | |||
| 115 | void | ||
| 116 | efc_domain_free(struct efc_domain *domain) | ||
| 117 | { | ||
| 118 | struct efc *efc; | ||
| 119 | |||
| 120 | efc = domain->efc; | ||
| 121 | |||
| 122 | /* Hold frames to clear the domain pointer from the xport lookup */ | ||
| 123 | efc->hold_frames = false; | ||
| 124 | |||
| 125 | efc_log_debug(efc, "Domain free: wwn %016llX\n", domain->fcf_wwn); | ||
| 126 | |||
| 127 | xa_destroy(&domain->lookup); | ||
| 128 | efc->domain = NULL; | ||
| 129 | kref_put(&domain->ref, domain->release); | ||
| 130 | } | ||
| 131 | |||
| 132 | struct efc_domain * | ||
| 133 | efc_domain_alloc(struct efc *efc, uint64_t fcf_wwn) | ||
| 134 | { | ||
| 135 | struct efc_domain *domain; | ||
| 136 | |||
| 137 | domain = kzalloc(sizeof(*domain), GFP_ATOMIC); | ||
| 138 | if (!domain) | ||
| 139 | return NULL; | ||
| 140 | |||
| 141 | domain->efc = efc; | ||
| 142 | domain->drvsm.app = domain; | ||
| 143 | |||
| 144 | /* initialize refcount */ | ||
| 145 | kref_init(&domain->ref); | ||
| 146 | domain->release = _efc_domain_free; | ||
| 147 | |||
| 148 | xa_init(&domain->lookup); | ||
| 149 | |||
| 150 | INIT_LIST_HEAD(&domain->nport_list); | ||
| 151 | efc->domain = domain; | ||
| 152 | domain->fcf_wwn = fcf_wwn; | ||
| 153 | efc_log_debug(efc, "Domain allocated: wwn %016llX\n", domain->fcf_wwn); | ||
| 154 | |||
| 155 | return domain; | ||
| 156 | } | ||
| 157 | |||
| 158 | void | ||
| 159 | efc_register_domain_free_cb(struct efc *efc, | ||
| 160 | void (*callback)(struct efc *efc, void *arg), | ||
| 161 | void *arg) | ||
| 162 | { | ||
| 163 | /* Register a callback to be called when the domain is freed */ | ||
| 164 | efc->domain_free_cb = callback; | ||
| 165 | efc->domain_free_cb_arg = arg; | ||
| 166 | if (!efc->domain && callback) | ||
| 167 | (*callback)(efc, arg); | ||
| 168 | } | ||
| 169 | |||
| 170 | static void | ||
| 171 | __efc_domain_common(const char *funcname, struct efc_sm_ctx *ctx, | ||
| 172 | enum efc_sm_event evt, void *arg) | ||
| 173 | { | ||
| 174 | struct efc_domain *domain = ctx->app; | ||
| 175 | |||
| 176 | switch (evt) { | ||
| 177 | case EFC_EVT_ENTER: | ||
| 178 | case EFC_EVT_REENTER: | ||
| 179 | case EFC_EVT_EXIT: | ||
| 180 | case EFC_EVT_ALL_CHILD_NODES_FREE: | ||
| 181 | /* | ||
| 182 | * this can arise if an FLOGI fails on the NPORT, | ||
| 183 | * and the NPORT is shutdown | ||
| 184 | */ | ||
| 185 | break; | ||
| 186 | default: | ||
| 187 | efc_log_warn(domain->efc, "%-20s %-20s not handled\n", | ||
| 188 | funcname, efc_sm_event_name(evt)); | ||
| 189 | } | ||
| 190 | } | ||
| 191 | |||
| 192 | static void | ||
| 193 | __efc_domain_common_shutdown(const char *funcname, struct efc_sm_ctx *ctx, | ||
| 194 | enum efc_sm_event evt, void *arg) | ||
| 195 | { | ||
| 196 | struct efc_domain *domain = ctx->app; | ||
| 197 | |||
| 198 | switch (evt) { | ||
| 199 | case EFC_EVT_ENTER: | ||
| 200 | case EFC_EVT_REENTER: | ||
| 201 | case EFC_EVT_EXIT: | ||
| 202 | break; | ||
| 203 | case EFC_EVT_DOMAIN_FOUND: | ||
| 204 | /* save drec, mark domain_found_pending */ | ||
| 205 | memcpy(&domain->pending_drec, arg, | ||
| 206 | sizeof(domain->pending_drec)); | ||
| 207 | domain->domain_found_pending = true; | ||
| 208 | break; | ||
| 209 | case EFC_EVT_DOMAIN_LOST: | ||
| 210 | /* unmark domain_found_pending */ | ||
| 211 | domain->domain_found_pending = false; | ||
| 212 | break; | ||
| 213 | |||
| 214 | default: | ||
| 215 | efc_log_warn(domain->efc, "%-20s %-20s not handled\n", | ||
| 216 | funcname, efc_sm_event_name(evt)); | ||
| 217 | } | ||
| 218 | } | ||
| 219 | |||
| 220 | #define std_domain_state_decl(...)\ | ||
| 221 | struct efc_domain *domain = NULL;\ | ||
| 222 | struct efc *efc = NULL;\ | ||
| 223 | \ | ||
| 224 | WARN_ON(!ctx || !ctx->app);\ | ||
| 225 | domain = ctx->app;\ | ||
| 226 | WARN_ON(!domain->efc);\ | ||
| 227 | efc = domain->efc | ||
| 228 | |||
| 229 | void | ||
| 230 | __efc_domain_init(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 231 | void *arg) | ||
| 232 | { | ||
| 233 | std_domain_state_decl(); | ||
| 234 | |||
| 235 | domain_sm_trace(domain); | ||
| 236 | |||
| 237 | switch (evt) { | ||
| 238 | case EFC_EVT_ENTER: | ||
| 239 | domain->attached = false; | ||
| 240 | break; | ||
| 241 | |||
| 242 | case EFC_EVT_DOMAIN_FOUND: { | ||
| 243 | u32 i; | ||
| 244 | struct efc_domain_record *drec = arg; | ||
| 245 | struct efc_nport *nport; | ||
| 246 | |||
| 247 | u64 my_wwnn = efc->req_wwnn; | ||
| 248 | u64 my_wwpn = efc->req_wwpn; | ||
| 249 | __be64 bewwpn; | ||
| 250 | |||
| 251 | if (my_wwpn == 0 || my_wwnn == 0) { | ||
| 252 | efc_log_debug(efc, "using default hardware WWN config\n"); | ||
| 253 | my_wwpn = efc->def_wwpn; | ||
| 254 | my_wwnn = efc->def_wwnn; | ||
| 255 | } | ||
| 256 | |||
| 257 | efc_log_debug(efc, "Create nport WWPN %016llX WWNN %016llX\n", | ||
| 258 | my_wwpn, my_wwnn); | ||
| 259 | |||
| 260 | /* Allocate a nport and transition to __efc_nport_allocated */ | ||
| 261 | nport = efc_nport_alloc(domain, my_wwpn, my_wwnn, U32_MAX, | ||
| 262 | efc->enable_ini, efc->enable_tgt); | ||
| 263 | |||
| 264 | if (!nport) { | ||
| 265 | efc_log_err(efc, "efc_nport_alloc() failed\n"); | ||
| 266 | break; | ||
| 267 | } | ||
| 268 | efc_sm_transition(&nport->sm, __efc_nport_allocated, NULL); | ||
| 269 | |||
| 270 | bewwpn = cpu_to_be64(nport->wwpn); | ||
| 271 | |||
| 272 | /* allocate struct efc_nport object for local port | ||
| 273 | * Note: drec->fc_id is ALPA from read_topology only if loop | ||
| 274 | */ | ||
| 275 | if (efc_cmd_nport_alloc(efc, nport, NULL, (uint8_t *)&bewwpn)) { | ||
| 276 | efc_log_err(efc, "Can't allocate port\n"); | ||
| 277 | efc_nport_free(nport); | ||
| 278 | break; | ||
| 279 | } | ||
| 280 | |||
| 281 | domain->is_loop = drec->is_loop; | ||
| 282 | |||
| 283 | /* | ||
| 284 | * If the loop position map includes ALPA == 0, | ||
| 285 | * then we are in a public loop (NL_PORT) | ||
| 286 | * Note that the first element of the loopmap[] | ||
| 287 | * contains the count of elements, and if | ||
| 288 | * ALPA == 0 is present, it will occupy the first | ||
| 289 | * location after the count. | ||
| 290 | */ | ||
| 291 | domain->is_nlport = drec->map.loop[1] == 0x00; | ||
| 292 | |||
| 293 | if (!domain->is_loop) { | ||
| 294 | /* Initiate HW domain alloc */ | ||
| 295 | if (efc_cmd_domain_alloc(efc, domain, drec->index)) { | ||
| 296 | efc_log_err(efc, | ||
| 297 | "Failed to initiate HW domain allocation\n"); | ||
| 298 | break; | ||
| 299 | } | ||
| 300 | efc_sm_transition(ctx, __efc_domain_wait_alloc, arg); | ||
| 301 | break; | ||
| 302 | } | ||
| 303 | |||
| 304 | efc_log_debug(efc, "%s fc_id=%#x speed=%d\n", | ||
| 305 | drec->is_loop ? | ||
| 306 | (domain->is_nlport ? | ||
| 307 | "public-loop" : "loop") : "other", | ||
| 308 | drec->fc_id, drec->speed); | ||
| 309 | |||
| 310 | nport->fc_id = drec->fc_id; | ||
| 311 | nport->topology = EFC_NPORT_TOPO_FC_AL; | ||
| 312 | snprintf(nport->display_name, sizeof(nport->display_name), | ||
| 313 | "s%06x", drec->fc_id); | ||
| 314 | |||
| 315 | if (efc->enable_ini) { | ||
| 316 | u32 count = drec->map.loop[0]; | ||
| 317 | |||
| 318 | efc_log_debug(efc, "%d position map entries\n", | ||
| 319 | count); | ||
| 320 | for (i = 1; i <= count; i++) { | ||
| 321 | if (drec->map.loop[i] != drec->fc_id) { | ||
| 322 | struct efc_node *node; | ||
| 323 | |||
| 324 | efc_log_debug(efc, "%#x -> %#x\n", | ||
| 325 | drec->fc_id, | ||
| 326 | drec->map.loop[i]); | ||
| 327 | node = efc_node_alloc(nport, | ||
| 328 | drec->map.loop[i], | ||
| 329 | false, true); | ||
| 330 | if (!node) { | ||
| 331 | efc_log_err(efc, | ||
| 332 | "efc_node_alloc() failed\n"); | ||
| 333 | break; | ||
| 334 | } | ||
| 335 | efc_node_transition(node, | ||
| 336 | __efc_d_wait_loop, | ||
| 337 | NULL); | ||
| 338 | } | ||
| 339 | } | ||
| 340 | } | ||
| 341 | |||
| 342 | /* Initiate HW domain alloc */ | ||
| 343 | if (efc_cmd_domain_alloc(efc, domain, drec->index)) { | ||
| 344 | efc_log_err(efc, | ||
| 345 | "Failed to initiate HW domain allocation\n"); | ||
| 346 | break; | ||
| 347 | } | ||
| 348 | efc_sm_transition(ctx, __efc_domain_wait_alloc, arg); | ||
| 349 | break; | ||
| 350 | } | ||
| 351 | default: | ||
| 352 | __efc_domain_common(__func__, ctx, evt, arg); | ||
| 353 | } | ||
| 354 | } | ||
| 355 | |||
| 356 | void | ||
| 357 | __efc_domain_wait_alloc(struct efc_sm_ctx *ctx, | ||
| 358 | enum efc_sm_event evt, void *arg) | ||
| 359 | { | ||
| 360 | std_domain_state_decl(); | ||
| 361 | |||
| 362 | domain_sm_trace(domain); | ||
| 363 | |||
| 364 | switch (evt) { | ||
| 365 | case EFC_EVT_DOMAIN_ALLOC_OK: { | ||
| 366 | struct fc_els_flogi *sp; | ||
| 367 | struct efc_nport *nport; | ||
| 368 | |||
| 369 | nport = domain->nport; | ||
| 370 | if (WARN_ON(!nport)) | ||
| 371 | return; | ||
| 372 | |||
| 373 | sp = (struct fc_els_flogi *)nport->service_params; | ||
| 374 | |||
| 375 | /* Save the domain service parameters */ | ||
| 376 | memcpy(domain->service_params + 4, domain->dma.virt, | ||
| 377 | sizeof(struct fc_els_flogi) - 4); | ||
| 378 | memcpy(nport->service_params + 4, domain->dma.virt, | ||
| 379 | sizeof(struct fc_els_flogi) - 4); | ||
| 380 | |||
| 381 | /* | ||
| 382 | * Update the nport's service parameters, | ||
| 383 | * user might have specified non-default names | ||
| 384 | */ | ||
| 385 | sp->fl_wwpn = cpu_to_be64(nport->wwpn); | ||
| 386 | sp->fl_wwnn = cpu_to_be64(nport->wwnn); | ||
| 387 | |||
| 388 | /* | ||
| 389 | * Take the loop topology path, | ||
| 390 | * unless we are an NL_PORT (public loop) | ||
| 391 | */ | ||
| 392 | if (domain->is_loop && !domain->is_nlport) { | ||
| 393 | /* | ||
| 394 | * For loop, we already have our FC ID | ||
| 395 | * and don't need fabric login. | ||
| 396 | * Transition to the allocated state and | ||
| 397 | * post an event to attach to | ||
| 398 | * the domain. Note that this breaks the | ||
| 399 | * normal action/transition | ||
| 400 | * pattern here to avoid a race with the | ||
| 401 | * domain attach callback. | ||
| 402 | */ | ||
| 403 | /* sm: is_loop / domain_attach */ | ||
| 404 | efc_sm_transition(ctx, __efc_domain_allocated, NULL); | ||
| 405 | __efc_domain_attach_internal(domain, nport->fc_id); | ||
| 406 | break; | ||
| 407 | } | ||
| 408 | { | ||
| 409 | struct efc_node *node; | ||
| 410 | |||
| 411 | /* alloc fabric node, send FLOGI */ | ||
| 412 | node = efc_node_find(nport, FC_FID_FLOGI); | ||
| 413 | if (node) { | ||
| 414 | efc_log_err(efc, | ||
| 415 | "Fabric Controller node already exists\n"); | ||
| 416 | break; | ||
| 417 | } | ||
| 418 | node = efc_node_alloc(nport, FC_FID_FLOGI, | ||
| 419 | false, false); | ||
| 420 | if (!node) { | ||
| 421 | efc_log_err(efc, | ||
| 422 | "Error: efc_node_alloc() failed\n"); | ||
| 423 | } else { | ||
| 424 | efc_node_transition(node, | ||
| 425 | __efc_fabric_init, NULL); | ||
| 426 | } | ||
| 427 | /* Accept frames */ | ||
| 428 | domain->req_accept_frames = true; | ||
| 429 | } | ||
| 430 | /* sm: / start fabric logins */ | ||
| 431 | efc_sm_transition(ctx, __efc_domain_allocated, NULL); | ||
| 432 | break; | ||
| 433 | } | ||
| 434 | |||
| 435 | case EFC_EVT_DOMAIN_ALLOC_FAIL: | ||
| 436 | efc_log_err(efc, "%s recv'd waiting for DOMAIN_ALLOC_OK;", | ||
| 437 | efc_sm_event_name(evt)); | ||
| 438 | efc_log_err(efc, "shutting down domain\n"); | ||
| 439 | domain->req_domain_free = true; | ||
| 440 | break; | ||
| 441 | |||
| 442 | case EFC_EVT_DOMAIN_FOUND: | ||
| 443 | /* Should not happen */ | ||
| 444 | break; | ||
| 445 | |||
| 446 | case EFC_EVT_DOMAIN_LOST: | ||
| 447 | efc_log_debug(efc, | ||
| 448 | "%s received while waiting for hw_domain_alloc()\n", | ||
| 449 | efc_sm_event_name(evt)); | ||
| 450 | efc_sm_transition(ctx, __efc_domain_wait_domain_lost, NULL); | ||
| 451 | break; | ||
| 452 | |||
| 453 | default: | ||
| 454 | __efc_domain_common(__func__, ctx, evt, arg); | ||
| 455 | } | ||
| 456 | } | ||
| 457 | |||
| 458 | void | ||
| 459 | __efc_domain_allocated(struct efc_sm_ctx *ctx, | ||
| 460 | enum efc_sm_event evt, void *arg) | ||
| 461 | { | ||
| 462 | std_domain_state_decl(); | ||
| 463 | |||
| 464 | domain_sm_trace(domain); | ||
| 465 | |||
| 466 | switch (evt) { | ||
| 467 | case EFC_EVT_DOMAIN_REQ_ATTACH: { | ||
| 468 | int rc = 0; | ||
| 469 | u32 fc_id; | ||
| 470 | |||
| 471 | if (WARN_ON(!arg)) | ||
| 472 | return; | ||
| 473 | |||
| 474 | fc_id = *((u32 *)arg); | ||
| 475 | efc_log_debug(efc, "Requesting hw domain attach fc_id x%x\n", | ||
| 476 | fc_id); | ||
| 477 | /* Update nport lookup */ | ||
| 478 | rc = xa_err(xa_store(&domain->lookup, fc_id, domain->nport, | ||
| 479 | GFP_ATOMIC)); | ||
| 480 | if (rc) { | ||
| 481 | efc_log_err(efc, "Sport lookup store failed: %d\n", rc); | ||
| 482 | return; | ||
| 483 | } | ||
| 484 | |||
| 485 | /* Update display name for the nport */ | ||
| 486 | efc_node_fcid_display(fc_id, domain->nport->display_name, | ||
| 487 | sizeof(domain->nport->display_name)); | ||
| 488 | |||
| 489 | /* Issue domain attach call */ | ||
| 490 | rc = efc_cmd_domain_attach(efc, domain, fc_id); | ||
| 491 | if (rc) { | ||
| 492 | efc_log_err(efc, "efc_hw_domain_attach failed: %d\n", | ||
| 493 | rc); | ||
| 494 | return; | ||
| 495 | } | ||
| 496 | /* sm: / domain_attach */ | ||
| 497 | efc_sm_transition(ctx, __efc_domain_wait_attach, NULL); | ||
| 498 | break; | ||
| 499 | } | ||
| 500 | |||
| 501 | case EFC_EVT_DOMAIN_FOUND: | ||
| 502 | /* Should not happen */ | ||
| 503 | efc_log_err(efc, "%s: evt: %d should not happen\n", | ||
| 504 | __func__, evt); | ||
| 505 | break; | ||
| 506 | |||
| 507 | case EFC_EVT_DOMAIN_LOST: { | ||
| 508 | efc_log_debug(efc, | ||
| 509 | "%s received while in EFC_EVT_DOMAIN_REQ_ATTACH\n", | ||
| 510 | efc_sm_event_name(evt)); | ||
| 511 | if (!list_empty(&domain->nport_list)) { | ||
| 512 | /* | ||
| 513 | * if there are nports, transition to | ||
| 514 | * wait state and send shutdown to each | ||
| 515 | * nport | ||
| 516 | */ | ||
| 517 | struct efc_nport *nport = NULL, *nport_next = NULL; | ||
| 518 | |||
| 519 | efc_sm_transition(ctx, __efc_domain_wait_nports_free, | ||
| 520 | NULL); | ||
| 521 | list_for_each_entry_safe(nport, nport_next, | ||
| 522 | &domain->nport_list, | ||
| 523 | list_entry) { | ||
| 524 | efc_sm_post_event(&nport->sm, | ||
| 525 | EFC_EVT_SHUTDOWN, NULL); | ||
| 526 | } | ||
| 527 | } else { | ||
| 528 | /* no nports exist, free domain */ | ||
| 529 | efc_sm_transition(ctx, __efc_domain_wait_shutdown, | ||
| 530 | NULL); | ||
| 531 | if (efc_cmd_domain_free(efc, domain)) | ||
| 532 | efc_log_err(efc, "hw_domain_free failed\n"); | ||
| 533 | } | ||
| 534 | |||
| 535 | break; | ||
| 536 | } | ||
| 537 | |||
| 538 | default: | ||
| 539 | __efc_domain_common(__func__, ctx, evt, arg); | ||
| 540 | } | ||
| 541 | } | ||
| 542 | |||
| 543 | void | ||
| 544 | __efc_domain_wait_attach(struct efc_sm_ctx *ctx, | ||
| 545 | enum efc_sm_event evt, void *arg) | ||
| 546 | { | ||
| 547 | std_domain_state_decl(); | ||
| 548 | |||
| 549 | domain_sm_trace(domain); | ||
| 550 | |||
| 551 | switch (evt) { | ||
| 552 | case EFC_EVT_DOMAIN_ATTACH_OK: { | ||
| 553 | struct efc_node *node = NULL; | ||
| 554 | struct efc_nport *nport, *next_nport; | ||
| 555 | unsigned long index; | ||
| 556 | |||
| 557 | /* | ||
| 558 | * Set domain notify pending state to avoid | ||
| 559 | * duplicate domain event post | ||
| 560 | */ | ||
| 561 | domain->domain_notify_pend = true; | ||
| 562 | |||
| 563 | /* Mark as attached */ | ||
| 564 | domain->attached = true; | ||
| 565 | |||
| 566 | /* Transition to ready */ | ||
| 567 | /* sm: / forward event to all nports and nodes */ | ||
| 568 | efc_sm_transition(ctx, __efc_domain_ready, NULL); | ||
| 569 | |||
| 570 | /* We have an FCFI, so we can accept frames */ | ||
| 571 | domain->req_accept_frames = true; | ||
| 572 | |||
| 573 | /* | ||
| 574 | * Notify all nodes that the domain attach request | ||
| 575 | * has completed | ||
| 576 | * Note: nport will have already received notification | ||
| 577 | * of nport attached as a result of the HW's port attach. | ||
| 578 | */ | ||
| 579 | list_for_each_entry_safe(nport, next_nport, | ||
| 580 | &domain->nport_list, list_entry) { | ||
| 581 | xa_for_each(&nport->lookup, index, node) { | ||
| 582 | efc_node_post_event(node, | ||
| 583 | EFC_EVT_DOMAIN_ATTACH_OK, | ||
| 584 | NULL); | ||
| 585 | } | ||
| 586 | } | ||
| 587 | domain->domain_notify_pend = false; | ||
| 588 | break; | ||
| 589 | } | ||
| 590 | |||
| 591 | case EFC_EVT_DOMAIN_ATTACH_FAIL: | ||
| 592 | efc_log_debug(efc, | ||
| 593 | "%s received while waiting for hw attach\n", | ||
| 594 | efc_sm_event_name(evt)); | ||
| 595 | break; | ||
| 596 | |||
| 597 | case EFC_EVT_DOMAIN_FOUND: | ||
| 598 | /* Should not happen */ | ||
| 599 | efc_log_err(efc, "%s: evt: %d should not happen\n", | ||
| 600 | __func__, evt); | ||
| 601 | break; | ||
| 602 | |||
| 603 | case EFC_EVT_DOMAIN_LOST: | ||
| 604 | /* | ||
| 605 | * Domain lost while waiting for an attach to complete, | ||
| 606 | * go to a state that waits for the domain attach to | ||
| 607 | * complete, then handle domain lost | ||
| 608 | */ | ||
| 609 | efc_sm_transition(ctx, __efc_domain_wait_domain_lost, NULL); | ||
| 610 | break; | ||
| 611 | |||
| 612 | case EFC_EVT_DOMAIN_REQ_ATTACH: | ||
| 613 | /* | ||
| 614 | * In P2P we can get an attach request from | ||
| 615 | * the other FLOGI path, so drop this one | ||
| 616 | */ | ||
| 617 | break; | ||
| 618 | |||
| 619 | default: | ||
| 620 | __efc_domain_common(__func__, ctx, evt, arg); | ||
| 621 | } | ||
| 622 | } | ||
| 623 | |||
| 624 | void | ||
| 625 | __efc_domain_ready(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg) | ||
| 626 | { | ||
| 627 | std_domain_state_decl(); | ||
| 628 | |||
| 629 | domain_sm_trace(domain); | ||
| 630 | |||
| 631 | switch (evt) { | ||
| 632 | case EFC_EVT_ENTER: { | ||
| 633 | /* start any pending vports */ | ||
| 634 | if (efc_vport_start(domain)) { | ||
| 635 | efc_log_debug(domain->efc, | ||
| 636 | "efc_vport_start didn't start vports\n"); | ||
| 637 | } | ||
| 638 | break; | ||
| 639 | } | ||
| 640 | case EFC_EVT_DOMAIN_LOST: { | ||
| 641 | if (!list_empty(&domain->nport_list)) { | ||
| 642 | /* | ||
| 643 | * if there are nports, transition to wait state | ||
| 644 | * and send shutdown to each nport | ||
| 645 | */ | ||
| 646 | struct efc_nport *nport = NULL, *nport_next = NULL; | ||
| 647 | |||
| 648 | efc_sm_transition(ctx, __efc_domain_wait_nports_free, | ||
| 649 | NULL); | ||
| 650 | list_for_each_entry_safe(nport, nport_next, | ||
| 651 | &domain->nport_list, | ||
| 652 | list_entry) { | ||
| 653 | efc_sm_post_event(&nport->sm, | ||
| 654 | EFC_EVT_SHUTDOWN, NULL); | ||
| 655 | } | ||
| 656 | } else { | ||
| 657 | /* no nports exist, free domain */ | ||
| 658 | efc_sm_transition(ctx, __efc_domain_wait_shutdown, | ||
| 659 | NULL); | ||
| 660 | if (efc_cmd_domain_free(efc, domain)) | ||
| 661 | efc_log_err(efc, "hw_domain_free failed\n"); | ||
| 662 | } | ||
| 663 | break; | ||
| 664 | } | ||
| 665 | |||
| 666 | case EFC_EVT_DOMAIN_FOUND: | ||
| 667 | /* Should not happen */ | ||
| 668 | efc_log_err(efc, "%s: evt: %d should not happen\n", | ||
| 669 | __func__, evt); | ||
| 670 | break; | ||
| 671 | |||
| 672 | case EFC_EVT_DOMAIN_REQ_ATTACH: { | ||
| 673 | /* can happen during p2p */ | ||
| 674 | u32 fc_id; | ||
| 675 | |||
| 676 | fc_id = *((u32 *)arg); | ||
| 677 | |||
| 678 | /* Assume that the domain is attached */ | ||
| 679 | WARN_ON(!domain->attached); | ||
| 680 | |||
| 681 | /* | ||
| 682 | * Verify that the requested FC_ID | ||
| 683 | * is the same as the one we're working with | ||
| 684 | */ | ||
| 685 | WARN_ON(domain->nport->fc_id != fc_id); | ||
| 686 | break; | ||
| 687 | } | ||
| 688 | |||
| 689 | default: | ||
| 690 | __efc_domain_common(__func__, ctx, evt, arg); | ||
| 691 | } | ||
| 692 | } | ||
| 693 | |||
| 694 | void | ||
| 695 | __efc_domain_wait_nports_free(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 696 | void *arg) | ||
| 697 | { | ||
| 698 | std_domain_state_decl(); | ||
| 699 | |||
| 700 | domain_sm_trace(domain); | ||
| 701 | |||
| 702 | /* Wait for nodes to free prior to the domain shutdown */ | ||
| 703 | switch (evt) { | ||
| 704 | case EFC_EVT_ALL_CHILD_NODES_FREE: { | ||
| 705 | int rc; | ||
| 706 | |||
| 707 | /* sm: / efc_hw_domain_free */ | ||
| 708 | efc_sm_transition(ctx, __efc_domain_wait_shutdown, NULL); | ||
| 709 | |||
| 710 | /* Request efc_hw_domain_free and wait for completion */ | ||
| 711 | rc = efc_cmd_domain_free(efc, domain); | ||
| 712 | if (rc) { | ||
| 713 | efc_log_err(efc, "efc_hw_domain_free() failed: %d\n", | ||
| 714 | rc); | ||
| 715 | } | ||
| 716 | break; | ||
| 717 | } | ||
| 718 | default: | ||
| 719 | __efc_domain_common_shutdown(__func__, ctx, evt, arg); | ||
| 720 | } | ||
| 721 | } | ||
| 722 | |||
| 723 | void | ||
| 724 | __efc_domain_wait_shutdown(struct efc_sm_ctx *ctx, | ||
| 725 | enum efc_sm_event evt, void *arg) | ||
| 726 | { | ||
| 727 | std_domain_state_decl(); | ||
| 728 | |||
| 729 | domain_sm_trace(domain); | ||
| 730 | |||
| 731 | switch (evt) { | ||
| 732 | case EFC_EVT_DOMAIN_FREE_OK: | ||
| 733 | /* sm: / domain_free */ | ||
| 734 | if (domain->domain_found_pending) { | ||
| 735 | /* | ||
| 736 | * save fcf_wwn and drec from this domain, | ||
| 737 | * free current domain and allocate | ||
| 738 | * a new one with the same fcf_wwn | ||
| 739 | * could use a SLI-4 "re-register VPI" | ||
| 740 | * operation here? | ||
| 741 | */ | ||
| 742 | u64 fcf_wwn = domain->fcf_wwn; | ||
| 743 | struct efc_domain_record drec = domain->pending_drec; | ||
| 744 | |||
| 745 | efc_log_debug(efc, "Reallocating domain\n"); | ||
| 746 | domain->req_domain_free = true; | ||
| 747 | domain = efc_domain_alloc(efc, fcf_wwn); | ||
| 748 | |||
| 749 | if (!domain) { | ||
| 750 | efc_log_err(efc, | ||
| 751 | "efc_domain_alloc() failed\n"); | ||
| 752 | return; | ||
| 753 | } | ||
| 754 | /* | ||
| 755 | * got a new domain; at this point, | ||
| 756 | * there are at least two domains | ||
| 757 | * once the req_domain_free flag is processed, | ||
| 758 | * the associated domain will be removed. | ||
| 759 | */ | ||
| 760 | efc_sm_transition(&domain->drvsm, __efc_domain_init, | ||
| 761 | NULL); | ||
| 762 | efc_sm_post_event(&domain->drvsm, | ||
| 763 | EFC_EVT_DOMAIN_FOUND, &drec); | ||
| 764 | } else { | ||
| 765 | domain->req_domain_free = true; | ||
| 766 | } | ||
| 767 | break; | ||
| 768 | default: | ||
| 769 | __efc_domain_common_shutdown(__func__, ctx, evt, arg); | ||
| 770 | } | ||
| 771 | } | ||
| 772 | |||
| 773 | void | ||
| 774 | __efc_domain_wait_domain_lost(struct efc_sm_ctx *ctx, | ||
| 775 | enum efc_sm_event evt, void *arg) | ||
| 776 | { | ||
| 777 | std_domain_state_decl(); | ||
| 778 | |||
| 779 | domain_sm_trace(domain); | ||
| 780 | |||
| 781 | /* | ||
| 782 | * Wait for the domain alloc/attach completion | ||
| 783 | * after receiving a domain lost. | ||
| 784 | */ | ||
| 785 | switch (evt) { | ||
| 786 | case EFC_EVT_DOMAIN_ALLOC_OK: | ||
| 787 | case EFC_EVT_DOMAIN_ATTACH_OK: { | ||
| 788 | if (!list_empty(&domain->nport_list)) { | ||
| 789 | /* | ||
| 790 | * if there are nports, transition to | ||
| 791 | * wait state and send shutdown to each nport | ||
| 792 | */ | ||
| 793 | struct efc_nport *nport = NULL, *nport_next = NULL; | ||
| 794 | |||
| 795 | efc_sm_transition(ctx, __efc_domain_wait_nports_free, | ||
| 796 | NULL); | ||
| 797 | list_for_each_entry_safe(nport, nport_next, | ||
| 798 | &domain->nport_list, | ||
| 799 | list_entry) { | ||
| 800 | efc_sm_post_event(&nport->sm, | ||
| 801 | EFC_EVT_SHUTDOWN, NULL); | ||
| 802 | } | ||
| 803 | } else { | ||
| 804 | /* no nports exist, free domain */ | ||
| 805 | efc_sm_transition(ctx, __efc_domain_wait_shutdown, | ||
| 806 | NULL); | ||
| 807 | if (efc_cmd_domain_free(efc, domain)) | ||
| 808 | efc_log_err(efc, "hw_domain_free() failed\n"); | ||
| 809 | } | ||
| 810 | break; | ||
| 811 | } | ||
| 812 | case EFC_EVT_DOMAIN_ALLOC_FAIL: | ||
| 813 | case EFC_EVT_DOMAIN_ATTACH_FAIL: | ||
| 814 | efc_log_err(efc, "[domain] %-20s: failed\n", | ||
| 815 | efc_sm_event_name(evt)); | ||
| 816 | break; | ||
| 817 | |||
| 818 | default: | ||
| 819 | __efc_domain_common_shutdown(__func__, ctx, evt, arg); | ||
| 820 | } | ||
| 821 | } | ||
| 822 | |||
| 823 | void | ||
| 824 | __efc_domain_attach_internal(struct efc_domain *domain, u32 s_id) | ||
| 825 | { | ||
| 826 | memcpy(domain->dma.virt, | ||
| 827 | ((uint8_t *)domain->flogi_service_params) + 4, | ||
| 828 | sizeof(struct fc_els_flogi) - 4); | ||
| 829 | (void)efc_sm_post_event(&domain->drvsm, EFC_EVT_DOMAIN_REQ_ATTACH, | ||
| 830 | &s_id); | ||
| 831 | } | ||
| 832 | |||
| 833 | void | ||
| 834 | efc_domain_attach(struct efc_domain *domain, u32 s_id) | ||
| 835 | { | ||
| 836 | __efc_domain_attach_internal(domain, s_id); | ||
| 837 | } | ||
| 838 | |||
| 839 | int | ||
| 840 | efc_domain_post_event(struct efc_domain *domain, | ||
| 841 | enum efc_sm_event event, void *arg) | ||
| 842 | { | ||
| 843 | int rc; | ||
| 844 | bool req_domain_free; | ||
| 845 | |||
| 846 | rc = efc_sm_post_event(&domain->drvsm, event, arg); | ||
| 847 | |||
| 848 | req_domain_free = domain->req_domain_free; | ||
| 849 | domain->req_domain_free = false; | ||
| 850 | |||
| 851 | if (req_domain_free) | ||
| 852 | efc_domain_free(domain); | ||
| 853 | |||
| 854 | return rc; | ||
| 855 | } | ||
| 856 | |||
| 857 | static void | ||
| 858 | efct_domain_process_pending(struct efc_domain *domain) | ||
| 859 | { | ||
| 860 | struct efc *efc = domain->efc; | ||
| 861 | struct efc_hw_sequence *seq = NULL; | ||
| 862 | u32 processed = 0; | ||
| 863 | unsigned long flags = 0; | ||
| 864 | |||
| 865 | for (;;) { | ||
| 866 | /* need to check for hold frames condition after each frame | ||
| 867 | * processed because any given frame could cause a transition | ||
| 868 | * to a state that holds frames | ||
| 869 | */ | ||
| 870 | if (efc->hold_frames) | ||
| 871 | break; | ||
| 872 | |||
| 873 | /* Get next frame/sequence */ | ||
| 874 | spin_lock_irqsave(&efc->pend_frames_lock, flags); | ||
| 875 | |||
| 876 | if (!list_empty(&efc->pend_frames)) { | ||
| 877 | seq = list_first_entry(&efc->pend_frames, | ||
| 878 | struct efc_hw_sequence, list_entry); | ||
| 879 | list_del(&seq->list_entry); | ||
| 880 | } | ||
| 881 | |||
| 882 | if (!seq) { | ||
| 883 | processed = efc->pend_frames_processed; | ||
| 884 | efc->pend_frames_processed = 0; | ||
| 885 | spin_unlock_irqrestore(&efc->pend_frames_lock, flags); | ||
| 886 | break; | ||
| 887 | } | ||
| 888 | efc->pend_frames_processed++; | ||
| 889 | |||
| 890 | spin_unlock_irqrestore(&efc->pend_frames_lock, flags); | ||
| 891 | |||
| 892 | /* now dispatch frame(s) to dispatch function */ | ||
| 893 | if (efc_domain_dispatch_frame(domain, seq)) | ||
| 894 | efc->tt.hw_seq_free(efc, seq); | ||
| 895 | |||
| 896 | seq = NULL; | ||
| 897 | } | ||
| 898 | |||
| 899 | if (processed != 0) | ||
| 900 | efc_log_debug(efc, "%u domain frames held and processed\n", | ||
| 901 | processed); | ||
| 902 | } | ||
| 903 | |||
| 904 | void | ||
| 905 | efc_dispatch_frame(struct efc *efc, struct efc_hw_sequence *seq) | ||
| 906 | { | ||
| 907 | struct efc_domain *domain = efc->domain; | ||
| 908 | |||
| 909 | /* | ||
| 910 | * If we are holding frames or the domain is not yet registered or | ||
| 911 | * there's already frames on the pending list, | ||
| 912 | * then add the new frame to pending list | ||
| 913 | */ | ||
| 914 | if (!domain || efc->hold_frames || !list_empty(&efc->pend_frames)) { | ||
| 915 | unsigned long flags = 0; | ||
| 916 | |||
| 917 | spin_lock_irqsave(&efc->pend_frames_lock, flags); | ||
| 918 | INIT_LIST_HEAD(&seq->list_entry); | ||
| 919 | list_add_tail(&seq->list_entry, &efc->pend_frames); | ||
| 920 | spin_unlock_irqrestore(&efc->pend_frames_lock, flags); | ||
| 921 | |||
| 922 | if (domain) { | ||
| 923 | /* immediately process pending frames */ | ||
| 924 | efct_domain_process_pending(domain); | ||
| 925 | } | ||
| 926 | } else { | ||
| 927 | /* | ||
| 928 | * We are not holding frames and pending list is empty, | ||
| 929 | * just process frame. A non-zero return means the frame | ||
| 930 | * was not handled - so cleanup | ||
| 931 | */ | ||
| 932 | if (efc_domain_dispatch_frame(domain, seq)) | ||
| 933 | efc->tt.hw_seq_free(efc, seq); | ||
| 934 | } | ||
| 935 | } | ||
| 936 | |||
| 937 | int | ||
| 938 | efc_domain_dispatch_frame(void *arg, struct efc_hw_sequence *seq) | ||
| 939 | { | ||
| 940 | struct efc_domain *domain = (struct efc_domain *)arg; | ||
| 941 | struct efc *efc = domain->efc; | ||
| 942 | struct fc_frame_header *hdr; | ||
| 943 | struct efc_node *node = NULL; | ||
| 944 | struct efc_nport *nport = NULL; | ||
| 945 | unsigned long flags = 0; | ||
| 946 | u32 s_id, d_id, rc = EFC_HW_SEQ_FREE; | ||
| 947 | |||
| 948 | if (!seq->header || !seq->header->dma.virt || !seq->payload->dma.virt) { | ||
| 949 | efc_log_err(efc, "Sequence header or payload is null\n"); | ||
| 950 | return rc; | ||
| 951 | } | ||
| 952 | |||
| 953 | hdr = seq->header->dma.virt; | ||
| 954 | |||
| 955 | /* extract the s_id and d_id */ | ||
| 956 | s_id = ntoh24(hdr->fh_s_id); | ||
| 957 | d_id = ntoh24(hdr->fh_d_id); | ||
| 958 | |||
| 959 | spin_lock_irqsave(&efc->lock, flags); | ||
| 960 | |||
| 961 | nport = efc_nport_find(domain, d_id); | ||
| 962 | if (!nport) { | ||
| 963 | if (hdr->fh_type == FC_TYPE_FCP) { | ||
| 964 | /* Drop frame */ | ||
| 965 | efc_log_warn(efc, "FCP frame with invalid d_id x%x\n", | ||
| 966 | d_id); | ||
| 967 | goto out; | ||
| 968 | } | ||
| 969 | |||
| 970 | /* p2p will use this case */ | ||
| 971 | nport = domain->nport; | ||
| 972 | if (!nport || !kref_get_unless_zero(&nport->ref)) { | ||
| 973 | efc_log_err(efc, "Physical nport is NULL\n"); | ||
| 974 | goto out; | ||
| 975 | } | ||
| 976 | } | ||
| 977 | |||
| 978 | /* Lookup the node given the remote s_id */ | ||
| 979 | node = efc_node_find(nport, s_id); | ||
| 980 | |||
| 981 | /* If not found, then create a new node */ | ||
| 982 | if (!node) { | ||
| 983 | /* | ||
| 984 | * If this is solicited data or control based on R_CTL and | ||
| 985 | * there is no node context, then we can drop the frame | ||
| 986 | */ | ||
| 987 | if ((hdr->fh_r_ctl == FC_RCTL_DD_SOL_DATA) || | ||
| 988 | (hdr->fh_r_ctl == FC_RCTL_DD_SOL_CTL)) { | ||
| 989 | efc_log_debug(efc, "sol data/ctrl frame without node\n"); | ||
| 990 | goto out_release; | ||
| 991 | } | ||
| 992 | |||
| 993 | node = efc_node_alloc(nport, s_id, false, false); | ||
| 994 | if (!node) { | ||
| 995 | efc_log_err(efc, "efc_node_alloc() failed\n"); | ||
| 996 | goto out_release; | ||
| 997 | } | ||
| 998 | /* don't send PLOGI on efc_d_init entry */ | ||
| 999 | efc_node_init_device(node, false); | ||
| 1000 | } | ||
| 1001 | |||
| 1002 | if (node->hold_frames || !list_empty(&node->pend_frames)) { | ||
| 1003 | /* add frame to node's pending list */ | ||
| 1004 | spin_lock(&node->pend_frames_lock); | ||
| 1005 | INIT_LIST_HEAD(&seq->list_entry); | ||
| 1006 | list_add_tail(&seq->list_entry, &node->pend_frames); | ||
| 1007 | spin_unlock(&node->pend_frames_lock); | ||
| 1008 | rc = EFC_HW_SEQ_HOLD; | ||
| 1009 | goto out_release; | ||
| 1010 | } | ||
| 1011 | |||
| 1012 | /* now dispatch frame to the node frame handler */ | ||
| 1013 | efc_node_dispatch_frame(node, seq); | ||
| 1014 | |||
| 1015 | out_release: | ||
| 1016 | kref_put(&nport->ref, nport->release); | ||
| 1017 | out: | ||
| 1018 | spin_unlock_irqrestore(&efc->lock, flags); | ||
| 1019 | return rc; | ||
| 1020 | } | ||
| 1021 | |||
| 1022 | void | ||
| 1023 | efc_node_dispatch_frame(void *arg, struct efc_hw_sequence *seq) | ||
| 1024 | { | ||
| 1025 | struct fc_frame_header *hdr = seq->header->dma.virt; | ||
| 1026 | u32 port_id; | ||
| 1027 | struct efc_node *node = (struct efc_node *)arg; | ||
| 1028 | struct efc *efc = node->efc; | ||
| 1029 | |||
| 1030 | port_id = ntoh24(hdr->fh_s_id); | ||
| 1031 | |||
| 1032 | if (WARN_ON(port_id != node->rnode.fc_id)) | ||
| 1033 | return; | ||
| 1034 | |||
| 1035 | if ((!(ntoh24(hdr->fh_f_ctl) & FC_FC_END_SEQ)) || | ||
| 1036 | !(ntoh24(hdr->fh_f_ctl) & FC_FC_SEQ_INIT)) { | ||
| 1037 | node_printf(node, | ||
| 1038 | "Drop frame hdr = %08x %08x %08x %08x %08x %08x\n", | ||
| 1039 | cpu_to_be32(((u32 *)hdr)[0]), | ||
| 1040 | cpu_to_be32(((u32 *)hdr)[1]), | ||
| 1041 | cpu_to_be32(((u32 *)hdr)[2]), | ||
| 1042 | cpu_to_be32(((u32 *)hdr)[3]), | ||
| 1043 | cpu_to_be32(((u32 *)hdr)[4]), | ||
| 1044 | cpu_to_be32(((u32 *)hdr)[5])); | ||
| 1045 | return; | ||
| 1046 | } | ||
| 1047 | |||
| 1048 | switch (hdr->fh_r_ctl) { | ||
| 1049 | case FC_RCTL_ELS_REQ: | ||
| 1050 | case FC_RCTL_ELS_REP: | ||
| 1051 | efc_node_recv_els_frame(node, seq); | ||
| 1052 | break; | ||
| 1053 | |||
| 1054 | case FC_RCTL_BA_ABTS: | ||
| 1055 | case FC_RCTL_BA_ACC: | ||
| 1056 | case FC_RCTL_BA_RJT: | ||
| 1057 | case FC_RCTL_BA_NOP: | ||
| 1058 | efc_log_err(efc, "Received ABTS:\n"); | ||
| 1059 | break; | ||
| 1060 | |||
| 1061 | case FC_RCTL_DD_UNSOL_CMD: | ||
| 1062 | case FC_RCTL_DD_UNSOL_CTL: | ||
| 1063 | switch (hdr->fh_type) { | ||
| 1064 | case FC_TYPE_FCP: | ||
| 1065 | if ((hdr->fh_r_ctl & 0xf) == FC_RCTL_DD_UNSOL_CMD) { | ||
| 1066 | if (!node->fcp_enabled) { | ||
| 1067 | efc_node_recv_fcp_cmd(node, seq); | ||
| 1068 | break; | ||
| 1069 | } | ||
| 1070 | efc_log_err(efc, "Recvd FCP CMD. Drop IO\n"); | ||
| 1071 | } else if ((hdr->fh_r_ctl & 0xf) == | ||
| 1072 | FC_RCTL_DD_SOL_DATA) { | ||
| 1073 | node_printf(node, | ||
| 1074 | "solicited data recvd. Drop IO\n"); | ||
| 1075 | } | ||
| 1076 | break; | ||
| 1077 | |||
| 1078 | case FC_TYPE_CT: | ||
| 1079 | efc_node_recv_ct_frame(node, seq); | ||
| 1080 | break; | ||
| 1081 | default: | ||
| 1082 | break; | ||
| 1083 | } | ||
| 1084 | break; | ||
| 1085 | default: | ||
| 1086 | efc_log_err(efc, "Unhandled frame rctl: %02x\n", hdr->fh_r_ctl); | ||
| 1087 | } | ||
| 1088 | } | ||
| @@ -0,0 +1,54 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * Declare driver's domain handler exported interface | ||
| 9 | */ | ||
| 10 | |||
| 11 | #ifndef __EFCT_DOMAIN_H__ | ||
| 12 | #define __EFCT_DOMAIN_H__ | ||
| 13 | |||
| 14 | struct efc_domain * | ||
| 15 | efc_domain_alloc(struct efc *efc, uint64_t fcf_wwn); | ||
| 16 | void | ||
| 17 | efc_domain_free(struct efc_domain *domain); | ||
| 18 | |||
| 19 | void | ||
| 20 | __efc_domain_init(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg); | ||
| 21 | void | ||
| 22 | __efc_domain_wait_alloc(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 23 | void *arg); | ||
| 24 | void | ||
| 25 | __efc_domain_allocated(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 26 | void *arg); | ||
| 27 | void | ||
| 28 | __efc_domain_wait_attach(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 29 | void *arg); | ||
| 30 | void | ||
| 31 | __efc_domain_ready(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg); | ||
| 32 | void | ||
| 33 | __efc_domain_wait_nports_free(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 34 | void *arg); | ||
| 35 | void | ||
| 36 | __efc_domain_wait_shutdown(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 37 | void *arg); | ||
| 38 | void | ||
| 39 | __efc_domain_wait_domain_lost(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 40 | void *arg); | ||
| 41 | void | ||
| 42 | efc_domain_attach(struct efc_domain *domain, u32 s_id); | ||
| 43 | int | ||
| 44 | efc_domain_post_event(struct efc_domain *domain, enum efc_sm_event event, | ||
| 45 | void *arg); | ||
| 46 | void | ||
| 47 | __efc_domain_attach_internal(struct efc_domain *domain, u32 s_id); | ||
| 48 | |||
| 49 | int | ||
| 50 | efc_domain_dispatch_frame(void *arg, struct efc_hw_sequence *seq); | ||
| 51 | void | ||
| 52 | efc_node_dispatch_frame(void *arg, struct efc_hw_sequence *seq); | ||
| 53 | |||
| 54 | #endif /* __EFCT_DOMAIN_H__ */ | ||
| @@ -0,0 +1,1098 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * Functions to build and send ELS/CT/BLS commands and responses. | ||
| 9 | */ | ||
| 10 | |||
| 11 | #include "efc.h" | ||
| 12 | #include "efc_els.h" | ||
| 13 | #include "../libefc_sli/sli4.h" | ||
| 14 | |||
| 15 | #define EFC_LOG_ENABLE_ELS_TRACE(efc) \ | ||
| 16 | (((efc) != NULL) ? (((efc)->logmask & (1U << 1)) != 0) : 0) | ||
| 17 | |||
| 18 | #define node_els_trace() \ | ||
| 19 | do { \ | ||
| 20 | if (EFC_LOG_ENABLE_ELS_TRACE(efc)) \ | ||
| 21 | efc_log_info(efc, "[%s] %-20s\n", \ | ||
| 22 | node->display_name, __func__); \ | ||
| 23 | } while (0) | ||
| 24 | |||
| 25 | #define els_io_printf(els, fmt, ...) \ | ||
| 26 | efc_log_err((struct efc *)els->node->efc,\ | ||
| 27 | "[%s] %-8s " fmt, \ | ||
| 28 | els->node->display_name,\ | ||
| 29 | els->display_name, ##__VA_ARGS__) | ||
| 30 | |||
| 31 | #define EFC_ELS_RSP_LEN 1024 | ||
| 32 | #define EFC_ELS_GID_PT_RSP_LEN 8096 | ||
| 33 | |||
| 34 | struct efc_els_io_req * | ||
| 35 | efc_els_io_alloc(struct efc_node *node, u32 reqlen) | ||
| 36 | { | ||
| 37 | return efc_els_io_alloc_size(node, reqlen, EFC_ELS_RSP_LEN); | ||
| 38 | } | ||
| 39 | |||
| 40 | struct efc_els_io_req * | ||
| 41 | efc_els_io_alloc_size(struct efc_node *node, u32 reqlen, u32 rsplen) | ||
| 42 | { | ||
| 43 | struct efc *efc; | ||
| 44 | struct efc_els_io_req *els; | ||
| 45 | unsigned long flags = 0; | ||
| 46 | |||
| 47 | efc = node->efc; | ||
| 48 | |||
| 49 | spin_lock_irqsave(&node->els_ios_lock, flags); | ||
| 50 | |||
| 51 | if (!node->els_io_enabled) { | ||
| 52 | efc_log_err(efc, "els io alloc disabled\n"); | ||
| 53 | spin_unlock_irqrestore(&node->els_ios_lock, flags); | ||
| 54 | return NULL; | ||
| 55 | } | ||
| 56 | |||
| 57 | els = mempool_alloc(efc->els_io_pool, GFP_ATOMIC); | ||
| 58 | if (!els) { | ||
| 59 | atomic_add_return(1, &efc->els_io_alloc_failed_count); | ||
| 60 | spin_unlock_irqrestore(&node->els_ios_lock, flags); | ||
| 61 | return NULL; | ||
| 62 | } | ||
| 63 | |||
| 64 | /* initialize refcount */ | ||
| 65 | kref_init(&els->ref); | ||
| 66 | els->release = _efc_els_io_free; | ||
| 67 | |||
| 68 | /* populate generic io fields */ | ||
| 69 | els->node = node; | ||
| 70 | |||
| 71 | /* now allocate DMA for request and response */ | ||
| 72 | els->io.req.size = reqlen; | ||
| 73 | els->io.req.virt = dma_alloc_coherent(&efc->pci->dev, els->io.req.size, | ||
| 74 | &els->io.req.phys, GFP_DMA); | ||
| 75 | if (!els->io.req.virt) { | ||
| 76 | mempool_free(els, efc->els_io_pool); | ||
| 77 | spin_unlock_irqrestore(&node->els_ios_lock, flags); | ||
| 78 | return NULL; | ||
| 79 | } | ||
| 80 | |||
| 81 | els->io.rsp.size = rsplen; | ||
| 82 | els->io.rsp.virt = dma_alloc_coherent(&efc->pci->dev, els->io.rsp.size, | ||
| 83 | &els->io.rsp.phys, GFP_DMA); | ||
| 84 | if (!els->io.rsp.virt) { | ||
| 85 | dma_free_coherent(&efc->pci->dev, els->io.req.size, | ||
| 86 | els->io.req.virt, els->io.req.phys); | ||
| 87 | mempool_free(els, efc->els_io_pool); | ||
| 88 | els = NULL; | ||
| 89 | } | ||
| 90 | |||
| 91 | if (els) { | ||
| 92 | /* initialize fields */ | ||
| 93 | els->els_retries_remaining = EFC_FC_ELS_DEFAULT_RETRIES; | ||
| 94 | |||
| 95 | /* add els structure to ELS IO list */ | ||
| 96 | INIT_LIST_HEAD(&els->list_entry); | ||
| 97 | list_add_tail(&els->list_entry, &node->els_ios_list); | ||
| 98 | } | ||
| 99 | |||
| 100 | spin_unlock_irqrestore(&node->els_ios_lock, flags); | ||
| 101 | return els; | ||
| 102 | } | ||
| 103 | |||
| 104 | void | ||
| 105 | efc_els_io_free(struct efc_els_io_req *els) | ||
| 106 | { | ||
| 107 | kref_put(&els->ref, els->release); | ||
| 108 | } | ||
| 109 | |||
| 110 | void | ||
| 111 | _efc_els_io_free(struct kref *arg) | ||
| 112 | { | ||
| 113 | struct efc_els_io_req *els = | ||
| 114 | container_of(arg, struct efc_els_io_req, ref); | ||
| 115 | struct efc *efc; | ||
| 116 | struct efc_node *node; | ||
| 117 | int send_empty_event = false; | ||
| 118 | unsigned long flags = 0; | ||
| 119 | |||
| 120 | node = els->node; | ||
| 121 | efc = node->efc; | ||
| 122 | |||
| 123 | spin_lock_irqsave(&node->els_ios_lock, flags); | ||
| 124 | |||
| 125 | list_del(&els->list_entry); | ||
| 126 | /* Send list empty event if the IO allocator | ||
| 127 | * is disabled, and the list is empty | ||
| 128 | * If node->els_io_enabled was not checked, | ||
| 129 | * the event would be posted continually | ||
| 130 | */ | ||
| 131 | send_empty_event = (!node->els_io_enabled && | ||
| 132 | list_empty(&node->els_ios_list)); | ||
| 133 | |||
| 134 | spin_unlock_irqrestore(&node->els_ios_lock, flags); | ||
| 135 | |||
| 136 | /* free ELS request and response buffers */ | ||
| 137 | dma_free_coherent(&efc->pci->dev, els->io.rsp.size, | ||
| 138 | els->io.rsp.virt, els->io.rsp.phys); | ||
| 139 | dma_free_coherent(&efc->pci->dev, els->io.req.size, | ||
| 140 | els->io.req.virt, els->io.req.phys); | ||
| 141 | |||
| 142 | mempool_free(els, efc->els_io_pool); | ||
| 143 | |||
| 144 | if (send_empty_event) | ||
| 145 | efc_scsi_io_list_empty(node->efc, node); | ||
| 146 | } | ||
| 147 | |||
| 148 | static void | ||
| 149 | efc_els_retry(struct efc_els_io_req *els); | ||
| 150 | |||
| 151 | static void | ||
| 152 | efc_els_delay_timer_cb(struct timer_list *t) | ||
| 153 | { | ||
| 154 | struct efc_els_io_req *els = from_timer(els, t, delay_timer); | ||
| 155 | |||
| 156 | /* Retry delay timer expired, retry the ELS request */ | ||
| 157 | efc_els_retry(els); | ||
| 158 | } | ||
| 159 | |||
| 160 | static int | ||
| 161 | efc_els_req_cb(void *arg, u32 length, int status, u32 ext_status) | ||
| 162 | { | ||
| 163 | struct efc_els_io_req *els; | ||
| 164 | struct efc_node *node; | ||
| 165 | struct efc *efc; | ||
| 166 | struct efc_node_cb cbdata; | ||
| 167 | u32 reason_code; | ||
| 168 | |||
| 169 | els = arg; | ||
| 170 | node = els->node; | ||
| 171 | efc = node->efc; | ||
| 172 | |||
| 173 | if (status) | ||
| 174 | els_io_printf(els, "status x%x ext x%x\n", status, ext_status); | ||
| 175 | |||
| 176 | /* set the response len element of els->rsp */ | ||
| 177 | els->io.rsp.len = length; | ||
| 178 | |||
| 179 | cbdata.status = status; | ||
| 180 | cbdata.ext_status = ext_status; | ||
| 181 | cbdata.header = NULL; | ||
| 182 | cbdata.els_rsp = els->io.rsp; | ||
| 183 | |||
| 184 | /* set the response len element of els->rsp */ | ||
| 185 | cbdata.rsp_len = length; | ||
| 186 | |||
| 187 | /* FW returns the number of bytes received on the link in | ||
| 188 | * the WCQE, not the amount placed in the buffer; use this info to | ||
| 189 | * check if there was an overrun. | ||
| 190 | */ | ||
| 191 | if (length > els->io.rsp.size) { | ||
| 192 | efc_log_warn(efc, | ||
| 193 | "ELS response returned len=%d > buflen=%zu\n", | ||
| 194 | length, els->io.rsp.size); | ||
| 195 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata); | ||
| 196 | return 0; | ||
| 197 | } | ||
| 198 | |||
| 199 | /* Post event to ELS IO object */ | ||
| 200 | switch (status) { | ||
| 201 | case SLI4_FC_WCQE_STATUS_SUCCESS: | ||
| 202 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_OK, &cbdata); | ||
| 203 | break; | ||
| 204 | |||
| 205 | case SLI4_FC_WCQE_STATUS_LS_RJT: | ||
| 206 | reason_code = (ext_status >> 16) & 0xff; | ||
| 207 | |||
| 208 | /* delay and retry if reason code is Logical Busy */ | ||
| 209 | switch (reason_code) { | ||
| 210 | case ELS_RJT_BUSY: | ||
| 211 | els->node->els_req_cnt--; | ||
| 212 | els_io_printf(els, | ||
| 213 | "LS_RJT Logical Busy, delay and retry\n"); | ||
| 214 | timer_setup(&els->delay_timer, | ||
| 215 | efc_els_delay_timer_cb, 0); | ||
| 216 | mod_timer(&els->delay_timer, | ||
| 217 | jiffies + msecs_to_jiffies(5000)); | ||
| 218 | break; | ||
| 219 | default: | ||
| 220 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_RJT, | ||
| 221 | &cbdata); | ||
| 222 | break; | ||
| 223 | } | ||
| 224 | break; | ||
| 225 | |||
| 226 | case SLI4_FC_WCQE_STATUS_LOCAL_REJECT: | ||
| 227 | switch (ext_status) { | ||
| 228 | case SLI4_FC_LOCAL_REJECT_SEQUENCE_TIMEOUT: | ||
| 229 | efc_els_retry(els); | ||
| 230 | break; | ||
| 231 | default: | ||
| 232 | efc_log_err(efc, "LOCAL_REJECT with ext status:%x\n", | ||
| 233 | ext_status); | ||
| 234 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, | ||
| 235 | &cbdata); | ||
| 236 | break; | ||
| 237 | } | ||
| 238 | break; | ||
| 239 | default: /* Other error */ | ||
| 240 | efc_log_warn(efc, "els req failed status x%x, ext_status x%x\n", | ||
| 241 | status, ext_status); | ||
| 242 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata); | ||
| 243 | break; | ||
| 244 | } | ||
| 245 | |||
| 246 | return 0; | ||
| 247 | } | ||
| 248 | |||
| 249 | void efc_disc_io_complete(struct efc_disc_io *io, u32 len, u32 status, | ||
| 250 | u32 ext_status) | ||
| 251 | { | ||
| 252 | struct efc_els_io_req *els = | ||
| 253 | container_of(io, struct efc_els_io_req, io); | ||
| 254 | |||
| 255 | WARN_ON_ONCE(!els->cb); | ||
| 256 | |||
| 257 | ((efc_hw_srrs_cb_t)els->cb) (els, len, status, ext_status); | ||
| 258 | } | ||
| 259 | |||
| 260 | static int efc_els_send_req(struct efc_node *node, struct efc_els_io_req *els, | ||
| 261 | enum efc_disc_io_type io_type) | ||
| 262 | { | ||
| 263 | int rc = 0; | ||
| 264 | struct efc *efc = node->efc; | ||
| 265 | struct efc_node_cb cbdata; | ||
| 266 | |||
| 267 | /* update ELS request counter */ | ||
| 268 | els->node->els_req_cnt++; | ||
| 269 | |||
| 270 | /* Prepare the IO request details */ | ||
| 271 | els->io.io_type = io_type; | ||
| 272 | els->io.xmit_len = els->io.req.size; | ||
| 273 | els->io.rsp_len = els->io.rsp.size; | ||
| 274 | els->io.rpi = node->rnode.indicator; | ||
| 275 | els->io.vpi = node->nport->indicator; | ||
| 276 | els->io.s_id = node->nport->fc_id; | ||
| 277 | els->io.d_id = node->rnode.fc_id; | ||
| 278 | |||
| 279 | if (node->rnode.attached) | ||
| 280 | els->io.rpi_registered = true; | ||
| 281 | |||
| 282 | els->cb = efc_els_req_cb; | ||
| 283 | |||
| 284 | rc = efc->tt.send_els(efc, &els->io); | ||
| 285 | if (!rc) | ||
| 286 | return rc; | ||
| 287 | |||
| 288 | cbdata.status = EFC_STATUS_INVALID; | ||
| 289 | cbdata.ext_status = EFC_STATUS_INVALID; | ||
| 290 | cbdata.els_rsp = els->io.rsp; | ||
| 291 | efc_log_err(efc, "efc_els_send failed: %d\n", rc); | ||
| 292 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata); | ||
| 293 | |||
| 294 | return rc; | ||
| 295 | } | ||
| 296 | |||
| 297 | static void | ||
| 298 | efc_els_retry(struct efc_els_io_req *els) | ||
| 299 | { | ||
| 300 | struct efc *efc; | ||
| 301 | struct efc_node_cb cbdata; | ||
| 302 | u32 rc; | ||
| 303 | |||
| 304 | efc = els->node->efc; | ||
| 305 | cbdata.status = EFC_STATUS_INVALID; | ||
| 306 | cbdata.ext_status = EFC_STATUS_INVALID; | ||
| 307 | cbdata.els_rsp = els->io.rsp; | ||
| 308 | |||
| 309 | if (els->els_retries_remaining) { | ||
| 310 | els->els_retries_remaining--; | ||
| 311 | rc = efc->tt.send_els(efc, &els->io); | ||
| 312 | } else { | ||
| 313 | rc = -EIO; | ||
| 314 | } | ||
| 315 | |||
| 316 | if (rc) { | ||
| 317 | efc_log_err(efc, "ELS retries exhausted\n"); | ||
| 318 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_REQ_FAIL, &cbdata); | ||
| 319 | } | ||
| 320 | } | ||
| 321 | |||
| 322 | static int | ||
| 323 | efc_els_acc_cb(void *arg, u32 length, int status, u32 ext_status) | ||
| 324 | { | ||
| 325 | struct efc_els_io_req *els; | ||
| 326 | struct efc_node *node; | ||
| 327 | struct efc *efc; | ||
| 328 | struct efc_node_cb cbdata; | ||
| 329 | |||
| 330 | els = arg; | ||
| 331 | node = els->node; | ||
| 332 | efc = node->efc; | ||
| 333 | |||
| 334 | cbdata.status = status; | ||
| 335 | cbdata.ext_status = ext_status; | ||
| 336 | cbdata.header = NULL; | ||
| 337 | cbdata.els_rsp = els->io.rsp; | ||
| 338 | |||
| 339 | /* Post node event */ | ||
| 340 | switch (status) { | ||
| 341 | case SLI4_FC_WCQE_STATUS_SUCCESS: | ||
| 342 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_OK, &cbdata); | ||
| 343 | break; | ||
| 344 | |||
| 345 | default: /* Other error */ | ||
| 346 | efc_log_warn(efc, "[%s] %-8s failed status x%x, ext x%x\n", | ||
| 347 | node->display_name, els->display_name, | ||
| 348 | status, ext_status); | ||
| 349 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata); | ||
| 350 | break; | ||
| 351 | } | ||
| 352 | |||
| 353 | return 0; | ||
| 354 | } | ||
| 355 | |||
| 356 | static int | ||
| 357 | efc_els_send_rsp(struct efc_els_io_req *els, u32 rsplen) | ||
| 358 | { | ||
| 359 | int rc = 0; | ||
| 360 | struct efc_node_cb cbdata; | ||
| 361 | struct efc_node *node = els->node; | ||
| 362 | struct efc *efc = node->efc; | ||
| 363 | |||
| 364 | /* increment ELS completion counter */ | ||
| 365 | node->els_cmpl_cnt++; | ||
| 366 | |||
| 367 | els->io.io_type = EFC_DISC_IO_ELS_RESP; | ||
| 368 | els->cb = efc_els_acc_cb; | ||
| 369 | |||
| 370 | /* Prepare the IO request details */ | ||
| 371 | els->io.xmit_len = rsplen; | ||
| 372 | els->io.rsp_len = els->io.rsp.size; | ||
| 373 | els->io.rpi = node->rnode.indicator; | ||
| 374 | els->io.vpi = node->nport->indicator; | ||
| 375 | if (node->nport->fc_id != U32_MAX) | ||
| 376 | els->io.s_id = node->nport->fc_id; | ||
| 377 | else | ||
| 378 | els->io.s_id = els->io.iparam.els.s_id; | ||
| 379 | els->io.d_id = node->rnode.fc_id; | ||
| 380 | |||
| 381 | if (node->attached) | ||
| 382 | els->io.rpi_registered = true; | ||
| 383 | |||
| 384 | rc = efc->tt.send_els(efc, &els->io); | ||
| 385 | if (!rc) | ||
| 386 | return rc; | ||
| 387 | |||
| 388 | cbdata.status = EFC_STATUS_INVALID; | ||
| 389 | cbdata.ext_status = EFC_STATUS_INVALID; | ||
| 390 | cbdata.els_rsp = els->io.rsp; | ||
| 391 | efc_els_io_cleanup(els, EFC_EVT_SRRS_ELS_CMPL_FAIL, &cbdata); | ||
| 392 | |||
| 393 | return rc; | ||
| 394 | } | ||
| 395 | |||
| 396 | int | ||
| 397 | efc_send_plogi(struct efc_node *node) | ||
| 398 | { | ||
| 399 | struct efc_els_io_req *els; | ||
| 400 | struct efc *efc = node->efc; | ||
| 401 | struct fc_els_flogi *plogi; | ||
| 402 | |||
| 403 | node_els_trace(); | ||
| 404 | |||
| 405 | els = efc_els_io_alloc(node, sizeof(*plogi)); | ||
| 406 | if (!els) { | ||
| 407 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 408 | return -EIO; | ||
| 409 | } | ||
| 410 | els->display_name = "plogi"; | ||
| 411 | |||
| 412 | /* Build PLOGI request */ | ||
| 413 | plogi = els->io.req.virt; | ||
| 414 | |||
| 415 | memcpy(plogi, node->nport->service_params, sizeof(*plogi)); | ||
| 416 | |||
| 417 | plogi->fl_cmd = ELS_PLOGI; | ||
| 418 | memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd)); | ||
| 419 | |||
| 420 | return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ); | ||
| 421 | } | ||
| 422 | |||
| 423 | int | ||
| 424 | efc_send_flogi(struct efc_node *node) | ||
| 425 | { | ||
| 426 | struct efc_els_io_req *els; | ||
| 427 | struct efc *efc; | ||
| 428 | struct fc_els_flogi *flogi; | ||
| 429 | |||
| 430 | efc = node->efc; | ||
| 431 | |||
| 432 | node_els_trace(); | ||
| 433 | |||
| 434 | els = efc_els_io_alloc(node, sizeof(*flogi)); | ||
| 435 | if (!els) { | ||
| 436 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 437 | return -EIO; | ||
| 438 | } | ||
| 439 | |||
| 440 | els->display_name = "flogi"; | ||
| 441 | |||
| 442 | /* Build FLOGI request */ | ||
| 443 | flogi = els->io.req.virt; | ||
| 444 | |||
| 445 | memcpy(flogi, node->nport->service_params, sizeof(*flogi)); | ||
| 446 | flogi->fl_cmd = ELS_FLOGI; | ||
| 447 | memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd)); | ||
| 448 | |||
| 449 | return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ); | ||
| 450 | } | ||
| 451 | |||
| 452 | int | ||
| 453 | efc_send_fdisc(struct efc_node *node) | ||
| 454 | { | ||
| 455 | struct efc_els_io_req *els; | ||
| 456 | struct efc *efc; | ||
| 457 | struct fc_els_flogi *fdisc; | ||
| 458 | |||
| 459 | efc = node->efc; | ||
| 460 | |||
| 461 | node_els_trace(); | ||
| 462 | |||
| 463 | els = efc_els_io_alloc(node, sizeof(*fdisc)); | ||
| 464 | if (!els) { | ||
| 465 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 466 | return -EIO; | ||
| 467 | } | ||
| 468 | |||
| 469 | els->display_name = "fdisc"; | ||
| 470 | |||
| 471 | /* Build FDISC request */ | ||
| 472 | fdisc = els->io.req.virt; | ||
| 473 | |||
| 474 | memcpy(fdisc, node->nport->service_params, sizeof(*fdisc)); | ||
| 475 | fdisc->fl_cmd = ELS_FDISC; | ||
| 476 | memset(fdisc->_fl_resvd, 0, sizeof(fdisc->_fl_resvd)); | ||
| 477 | |||
| 478 | return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ); | ||
| 479 | } | ||
| 480 | |||
| 481 | int | ||
| 482 | efc_send_prli(struct efc_node *node) | ||
| 483 | { | ||
| 484 | struct efc *efc = node->efc; | ||
| 485 | struct efc_els_io_req *els; | ||
| 486 | struct { | ||
| 487 | struct fc_els_prli prli; | ||
| 488 | struct fc_els_spp spp; | ||
| 489 | } *pp; | ||
| 490 | |||
| 491 | node_els_trace(); | ||
| 492 | |||
| 493 | els = efc_els_io_alloc(node, sizeof(*pp)); | ||
| 494 | if (!els) { | ||
| 495 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 496 | return -EIO; | ||
| 497 | } | ||
| 498 | |||
| 499 | els->display_name = "prli"; | ||
| 500 | |||
| 501 | /* Build PRLI request */ | ||
| 502 | pp = els->io.req.virt; | ||
| 503 | |||
| 504 | memset(pp, 0, sizeof(*pp)); | ||
| 505 | |||
| 506 | pp->prli.prli_cmd = ELS_PRLI; | ||
| 507 | pp->prli.prli_spp_len = 16; | ||
| 508 | pp->prli.prli_len = cpu_to_be16(sizeof(*pp)); | ||
| 509 | pp->spp.spp_type = FC_TYPE_FCP; | ||
| 510 | pp->spp.spp_type_ext = 0; | ||
| 511 | pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR; | ||
| 512 | pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS | | ||
| 513 | (node->nport->enable_ini ? | ||
| 514 | FCP_SPPF_INIT_FCN : 0) | | ||
| 515 | (node->nport->enable_tgt ? | ||
| 516 | FCP_SPPF_TARG_FCN : 0)); | ||
| 517 | |||
| 518 | return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ); | ||
| 519 | } | ||
| 520 | |||
| 521 | int | ||
| 522 | efc_send_logo(struct efc_node *node) | ||
| 523 | { | ||
| 524 | struct efc *efc = node->efc; | ||
| 525 | struct efc_els_io_req *els; | ||
| 526 | struct fc_els_logo *logo; | ||
| 527 | struct fc_els_flogi *sparams; | ||
| 528 | |||
| 529 | node_els_trace(); | ||
| 530 | |||
| 531 | sparams = (struct fc_els_flogi *)node->nport->service_params; | ||
| 532 | |||
| 533 | els = efc_els_io_alloc(node, sizeof(*logo)); | ||
| 534 | if (!els) { | ||
| 535 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 536 | return -EIO; | ||
| 537 | } | ||
| 538 | |||
| 539 | els->display_name = "logo"; | ||
| 540 | |||
| 541 | /* Build LOGO request */ | ||
| 542 | |||
| 543 | logo = els->io.req.virt; | ||
| 544 | |||
| 545 | memset(logo, 0, sizeof(*logo)); | ||
| 546 | logo->fl_cmd = ELS_LOGO; | ||
| 547 | hton24(logo->fl_n_port_id, node->rnode.nport->fc_id); | ||
| 548 | logo->fl_n_port_wwn = sparams->fl_wwpn; | ||
| 549 | |||
| 550 | return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ); | ||
| 551 | } | ||
| 552 | |||
| 553 | int | ||
| 554 | efc_send_adisc(struct efc_node *node) | ||
| 555 | { | ||
| 556 | struct efc *efc = node->efc; | ||
| 557 | struct efc_els_io_req *els; | ||
| 558 | struct fc_els_adisc *adisc; | ||
| 559 | struct fc_els_flogi *sparams; | ||
| 560 | struct efc_nport *nport = node->nport; | ||
| 561 | |||
| 562 | node_els_trace(); | ||
| 563 | |||
| 564 | sparams = (struct fc_els_flogi *)node->nport->service_params; | ||
| 565 | |||
| 566 | els = efc_els_io_alloc(node, sizeof(*adisc)); | ||
| 567 | if (!els) { | ||
| 568 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 569 | return -EIO; | ||
| 570 | } | ||
| 571 | |||
| 572 | els->display_name = "adisc"; | ||
| 573 | |||
| 574 | /* Build ADISC request */ | ||
| 575 | |||
| 576 | adisc = els->io.req.virt; | ||
| 577 | |||
| 578 | memset(adisc, 0, sizeof(*adisc)); | ||
| 579 | adisc->adisc_cmd = ELS_ADISC; | ||
| 580 | hton24(adisc->adisc_hard_addr, nport->fc_id); | ||
| 581 | adisc->adisc_wwpn = sparams->fl_wwpn; | ||
| 582 | adisc->adisc_wwnn = sparams->fl_wwnn; | ||
| 583 | hton24(adisc->adisc_port_id, node->rnode.nport->fc_id); | ||
| 584 | |||
| 585 | return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ); | ||
| 586 | } | ||
| 587 | |||
| 588 | int | ||
| 589 | efc_send_scr(struct efc_node *node) | ||
| 590 | { | ||
| 591 | struct efc_els_io_req *els; | ||
| 592 | struct efc *efc = node->efc; | ||
| 593 | struct fc_els_scr *req; | ||
| 594 | |||
| 595 | node_els_trace(); | ||
| 596 | |||
| 597 | els = efc_els_io_alloc(node, sizeof(*req)); | ||
| 598 | if (!els) { | ||
| 599 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 600 | return -EIO; | ||
| 601 | } | ||
| 602 | |||
| 603 | els->display_name = "scr"; | ||
| 604 | |||
| 605 | req = els->io.req.virt; | ||
| 606 | |||
| 607 | memset(req, 0, sizeof(*req)); | ||
| 608 | req->scr_cmd = ELS_SCR; | ||
| 609 | req->scr_reg_func = ELS_SCRF_FULL; | ||
| 610 | |||
| 611 | return efc_els_send_req(node, els, EFC_DISC_IO_ELS_REQ); | ||
| 612 | } | ||
| 613 | |||
| 614 | int | ||
| 615 | efc_send_ls_rjt(struct efc_node *node, u32 ox_id, u32 reason_code, | ||
| 616 | u32 reason_code_expl, u32 vendor_unique) | ||
| 617 | { | ||
| 618 | struct efc *efc = node->efc; | ||
| 619 | struct efc_els_io_req *els = NULL; | ||
| 620 | struct fc_els_ls_rjt *rjt; | ||
| 621 | |||
| 622 | els = efc_els_io_alloc(node, sizeof(*rjt)); | ||
| 623 | if (!els) { | ||
| 624 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 625 | return -EIO; | ||
| 626 | } | ||
| 627 | |||
| 628 | node_els_trace(); | ||
| 629 | |||
| 630 | els->display_name = "ls_rjt"; | ||
| 631 | |||
| 632 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 633 | els->io.iparam.els.ox_id = ox_id; | ||
| 634 | |||
| 635 | rjt = els->io.req.virt; | ||
| 636 | memset(rjt, 0, sizeof(*rjt)); | ||
| 637 | |||
| 638 | rjt->er_cmd = ELS_LS_RJT; | ||
| 639 | rjt->er_reason = reason_code; | ||
| 640 | rjt->er_explan = reason_code_expl; | ||
| 641 | |||
| 642 | return efc_els_send_rsp(els, sizeof(*rjt)); | ||
| 643 | } | ||
| 644 | |||
| 645 | int | ||
| 646 | efc_send_plogi_acc(struct efc_node *node, u32 ox_id) | ||
| 647 | { | ||
| 648 | struct efc *efc = node->efc; | ||
| 649 | struct efc_els_io_req *els = NULL; | ||
| 650 | struct fc_els_flogi *plogi; | ||
| 651 | struct fc_els_flogi *req = (struct fc_els_flogi *)node->service_params; | ||
| 652 | |||
| 653 | node_els_trace(); | ||
| 654 | |||
| 655 | els = efc_els_io_alloc(node, sizeof(*plogi)); | ||
| 656 | if (!els) { | ||
| 657 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 658 | return -EIO; | ||
| 659 | } | ||
| 660 | |||
| 661 | els->display_name = "plogi_acc"; | ||
| 662 | |||
| 663 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 664 | els->io.iparam.els.ox_id = ox_id; | ||
| 665 | |||
| 666 | plogi = els->io.req.virt; | ||
| 667 | |||
| 668 | /* copy our port's service parameters to payload */ | ||
| 669 | memcpy(plogi, node->nport->service_params, sizeof(*plogi)); | ||
| 670 | plogi->fl_cmd = ELS_LS_ACC; | ||
| 671 | memset(plogi->_fl_resvd, 0, sizeof(plogi->_fl_resvd)); | ||
| 672 | |||
| 673 | /* Set Application header support bit if requested */ | ||
| 674 | if (req->fl_csp.sp_features & cpu_to_be16(FC_SP_FT_BCAST)) | ||
| 675 | plogi->fl_csp.sp_features |= cpu_to_be16(FC_SP_FT_BCAST); | ||
| 676 | |||
| 677 | return efc_els_send_rsp(els, sizeof(*plogi)); | ||
| 678 | } | ||
| 679 | |||
| 680 | int | ||
| 681 | efc_send_flogi_p2p_acc(struct efc_node *node, u32 ox_id, u32 s_id) | ||
| 682 | { | ||
| 683 | struct efc *efc = node->efc; | ||
| 684 | struct efc_els_io_req *els = NULL; | ||
| 685 | struct fc_els_flogi *flogi; | ||
| 686 | |||
| 687 | node_els_trace(); | ||
| 688 | |||
| 689 | els = efc_els_io_alloc(node, sizeof(*flogi)); | ||
| 690 | if (!els) { | ||
| 691 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 692 | return -EIO; | ||
| 693 | } | ||
| 694 | |||
| 695 | els->display_name = "flogi_p2p_acc"; | ||
| 696 | |||
| 697 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 698 | els->io.iparam.els.ox_id = ox_id; | ||
| 699 | els->io.iparam.els.s_id = s_id; | ||
| 700 | |||
| 701 | flogi = els->io.req.virt; | ||
| 702 | |||
| 703 | /* copy our port's service parameters to payload */ | ||
| 704 | memcpy(flogi, node->nport->service_params, sizeof(*flogi)); | ||
| 705 | flogi->fl_cmd = ELS_LS_ACC; | ||
| 706 | memset(flogi->_fl_resvd, 0, sizeof(flogi->_fl_resvd)); | ||
| 707 | |||
| 708 | memset(flogi->fl_cssp, 0, sizeof(flogi->fl_cssp)); | ||
| 709 | |||
| 710 | return efc_els_send_rsp(els, sizeof(*flogi)); | ||
| 711 | } | ||
| 712 | |||
| 713 | int | ||
| 714 | efc_send_prli_acc(struct efc_node *node, u32 ox_id) | ||
| 715 | { | ||
| 716 | struct efc *efc = node->efc; | ||
| 717 | struct efc_els_io_req *els = NULL; | ||
| 718 | struct { | ||
| 719 | struct fc_els_prli prli; | ||
| 720 | struct fc_els_spp spp; | ||
| 721 | } *pp; | ||
| 722 | |||
| 723 | node_els_trace(); | ||
| 724 | |||
| 725 | els = efc_els_io_alloc(node, sizeof(*pp)); | ||
| 726 | if (!els) { | ||
| 727 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 728 | return -EIO; | ||
| 729 | } | ||
| 730 | |||
| 731 | els->display_name = "prli_acc"; | ||
| 732 | |||
| 733 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 734 | els->io.iparam.els.ox_id = ox_id; | ||
| 735 | |||
| 736 | pp = els->io.req.virt; | ||
| 737 | memset(pp, 0, sizeof(*pp)); | ||
| 738 | |||
| 739 | pp->prli.prli_cmd = ELS_LS_ACC; | ||
| 740 | pp->prli.prli_spp_len = 0x10; | ||
| 741 | pp->prli.prli_len = cpu_to_be16(sizeof(*pp)); | ||
| 742 | pp->spp.spp_type = FC_TYPE_FCP; | ||
| 743 | pp->spp.spp_type_ext = 0; | ||
| 744 | pp->spp.spp_flags = FC_SPP_EST_IMG_PAIR | FC_SPP_RESP_ACK; | ||
| 745 | |||
| 746 | pp->spp.spp_params = cpu_to_be32(FCP_SPPF_RD_XRDY_DIS | | ||
| 747 | (node->nport->enable_ini ? | ||
| 748 | FCP_SPPF_INIT_FCN : 0) | | ||
| 749 | (node->nport->enable_tgt ? | ||
| 750 | FCP_SPPF_TARG_FCN : 0)); | ||
| 751 | |||
| 752 | return efc_els_send_rsp(els, sizeof(*pp)); | ||
| 753 | } | ||
| 754 | |||
| 755 | int | ||
| 756 | efc_send_prlo_acc(struct efc_node *node, u32 ox_id) | ||
| 757 | { | ||
| 758 | struct efc *efc = node->efc; | ||
| 759 | struct efc_els_io_req *els = NULL; | ||
| 760 | struct { | ||
| 761 | struct fc_els_prlo prlo; | ||
| 762 | struct fc_els_spp spp; | ||
| 763 | } *pp; | ||
| 764 | |||
| 765 | node_els_trace(); | ||
| 766 | |||
| 767 | els = efc_els_io_alloc(node, sizeof(*pp)); | ||
| 768 | if (!els) { | ||
| 769 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 770 | return -EIO; | ||
| 771 | } | ||
| 772 | |||
| 773 | els->display_name = "prlo_acc"; | ||
| 774 | |||
| 775 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 776 | els->io.iparam.els.ox_id = ox_id; | ||
| 777 | |||
| 778 | pp = els->io.req.virt; | ||
| 779 | memset(pp, 0, sizeof(*pp)); | ||
| 780 | pp->prlo.prlo_cmd = ELS_LS_ACC; | ||
| 781 | pp->prlo.prlo_obs = 0x10; | ||
| 782 | pp->prlo.prlo_len = cpu_to_be16(sizeof(*pp)); | ||
| 783 | |||
| 784 | pp->spp.spp_type = FC_TYPE_FCP; | ||
| 785 | pp->spp.spp_type_ext = 0; | ||
| 786 | pp->spp.spp_flags = FC_SPP_RESP_ACK; | ||
| 787 | |||
| 788 | return efc_els_send_rsp(els, sizeof(*pp)); | ||
| 789 | } | ||
| 790 | |||
| 791 | int | ||
| 792 | efc_send_ls_acc(struct efc_node *node, u32 ox_id) | ||
| 793 | { | ||
| 794 | struct efc *efc = node->efc; | ||
| 795 | struct efc_els_io_req *els = NULL; | ||
| 796 | struct fc_els_ls_acc *acc; | ||
| 797 | |||
| 798 | node_els_trace(); | ||
| 799 | |||
| 800 | els = efc_els_io_alloc(node, sizeof(*acc)); | ||
| 801 | if (!els) { | ||
| 802 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 803 | return -EIO; | ||
| 804 | } | ||
| 805 | |||
| 806 | els->display_name = "ls_acc"; | ||
| 807 | |||
| 808 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 809 | els->io.iparam.els.ox_id = ox_id; | ||
| 810 | |||
| 811 | acc = els->io.req.virt; | ||
| 812 | memset(acc, 0, sizeof(*acc)); | ||
| 813 | |||
| 814 | acc->la_cmd = ELS_LS_ACC; | ||
| 815 | |||
| 816 | return efc_els_send_rsp(els, sizeof(*acc)); | ||
| 817 | } | ||
| 818 | |||
| 819 | int | ||
| 820 | efc_send_logo_acc(struct efc_node *node, u32 ox_id) | ||
| 821 | { | ||
| 822 | struct efc_els_io_req *els = NULL; | ||
| 823 | struct efc *efc = node->efc; | ||
| 824 | struct fc_els_ls_acc *logo; | ||
| 825 | |||
| 826 | node_els_trace(); | ||
| 827 | |||
| 828 | els = efc_els_io_alloc(node, sizeof(*logo)); | ||
| 829 | if (!els) { | ||
| 830 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 831 | return -EIO; | ||
| 832 | } | ||
| 833 | |||
| 834 | els->display_name = "logo_acc"; | ||
| 835 | |||
| 836 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 837 | els->io.iparam.els.ox_id = ox_id; | ||
| 838 | |||
| 839 | logo = els->io.req.virt; | ||
| 840 | memset(logo, 0, sizeof(*logo)); | ||
| 841 | |||
| 842 | logo->la_cmd = ELS_LS_ACC; | ||
| 843 | |||
| 844 | return efc_els_send_rsp(els, sizeof(*logo)); | ||
| 845 | } | ||
| 846 | |||
| 847 | int | ||
| 848 | efc_send_adisc_acc(struct efc_node *node, u32 ox_id) | ||
| 849 | { | ||
| 850 | struct efc *efc = node->efc; | ||
| 851 | struct efc_els_io_req *els = NULL; | ||
| 852 | struct fc_els_adisc *adisc; | ||
| 853 | struct fc_els_flogi *sparams; | ||
| 854 | |||
| 855 | node_els_trace(); | ||
| 856 | |||
| 857 | els = efc_els_io_alloc(node, sizeof(*adisc)); | ||
| 858 | if (!els) { | ||
| 859 | efc_log_err(efc, "els IO alloc failed\n"); | ||
| 860 | return -EIO; | ||
| 861 | } | ||
| 862 | |||
| 863 | els->display_name = "adisc_acc"; | ||
| 864 | |||
| 865 | /* Go ahead and send the ELS_ACC */ | ||
| 866 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 867 | els->io.iparam.els.ox_id = ox_id; | ||
| 868 | |||
| 869 | sparams = (struct fc_els_flogi *)node->nport->service_params; | ||
| 870 | adisc = els->io.req.virt; | ||
| 871 | memset(adisc, 0, sizeof(*adisc)); | ||
| 872 | adisc->adisc_cmd = ELS_LS_ACC; | ||
| 873 | adisc->adisc_wwpn = sparams->fl_wwpn; | ||
| 874 | adisc->adisc_wwnn = sparams->fl_wwnn; | ||
| 875 | hton24(adisc->adisc_port_id, node->rnode.nport->fc_id); | ||
| 876 | |||
| 877 | return efc_els_send_rsp(els, sizeof(*adisc)); | ||
| 878 | } | ||
| 879 | |||
| 880 | static inline void | ||
| 881 | fcct_build_req_header(struct fc_ct_hdr *hdr, u16 cmd, u16 max_size) | ||
| 882 | { | ||
| 883 | hdr->ct_rev = FC_CT_REV; | ||
| 884 | hdr->ct_fs_type = FC_FST_DIR; | ||
| 885 | hdr->ct_fs_subtype = FC_NS_SUBTYPE; | ||
| 886 | hdr->ct_options = 0; | ||
| 887 | hdr->ct_cmd = cpu_to_be16(cmd); | ||
| 888 | /* words */ | ||
| 889 | hdr->ct_mr_size = cpu_to_be16(max_size / (sizeof(u32))); | ||
| 890 | hdr->ct_reason = 0; | ||
| 891 | hdr->ct_explan = 0; | ||
| 892 | hdr->ct_vendor = 0; | ||
| 893 | } | ||
| 894 | |||
| 895 | int | ||
| 896 | efc_ns_send_rftid(struct efc_node *node) | ||
| 897 | { | ||
| 898 | struct efc *efc = node->efc; | ||
| 899 | struct efc_els_io_req *els; | ||
| 900 | struct { | ||
| 901 | struct fc_ct_hdr hdr; | ||
| 902 | struct fc_ns_rft_id rftid; | ||
| 903 | } *ct; | ||
| 904 | |||
| 905 | node_els_trace(); | ||
| 906 | |||
| 907 | els = efc_els_io_alloc(node, sizeof(*ct)); | ||
| 908 | if (!els) { | ||
| 909 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 910 | return -EIO; | ||
| 911 | } | ||
| 912 | |||
| 913 | els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ; | ||
| 914 | els->io.iparam.ct.type = FC_TYPE_CT; | ||
| 915 | els->io.iparam.ct.df_ctl = 0; | ||
| 916 | els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT; | ||
| 917 | |||
| 918 | els->display_name = "rftid"; | ||
| 919 | |||
| 920 | ct = els->io.req.virt; | ||
| 921 | memset(ct, 0, sizeof(*ct)); | ||
| 922 | fcct_build_req_header(&ct->hdr, FC_NS_RFT_ID, | ||
| 923 | sizeof(struct fc_ns_rft_id)); | ||
| 924 | |||
| 925 | hton24(ct->rftid.fr_fid.fp_fid, node->rnode.nport->fc_id); | ||
| 926 | ct->rftid.fr_fts.ff_type_map[FC_TYPE_FCP / FC_NS_BPW] = | ||
| 927 | cpu_to_be32(1 << (FC_TYPE_FCP % FC_NS_BPW)); | ||
| 928 | |||
| 929 | return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ); | ||
| 930 | } | ||
| 931 | |||
| 932 | int | ||
| 933 | efc_ns_send_rffid(struct efc_node *node) | ||
| 934 | { | ||
| 935 | struct efc *efc = node->efc; | ||
| 936 | struct efc_els_io_req *els; | ||
| 937 | struct { | ||
| 938 | struct fc_ct_hdr hdr; | ||
| 939 | struct fc_ns_rff_id rffid; | ||
| 940 | } *ct; | ||
| 941 | |||
| 942 | node_els_trace(); | ||
| 943 | |||
| 944 | els = efc_els_io_alloc(node, sizeof(*ct)); | ||
| 945 | if (!els) { | ||
| 946 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 947 | return -EIO; | ||
| 948 | } | ||
| 949 | |||
| 950 | els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ; | ||
| 951 | els->io.iparam.ct.type = FC_TYPE_CT; | ||
| 952 | els->io.iparam.ct.df_ctl = 0; | ||
| 953 | els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT; | ||
| 954 | |||
| 955 | els->display_name = "rffid"; | ||
| 956 | ct = els->io.req.virt; | ||
| 957 | |||
| 958 | memset(ct, 0, sizeof(*ct)); | ||
| 959 | fcct_build_req_header(&ct->hdr, FC_NS_RFF_ID, | ||
| 960 | sizeof(struct fc_ns_rff_id)); | ||
| 961 | |||
| 962 | hton24(ct->rffid.fr_fid.fp_fid, node->rnode.nport->fc_id); | ||
| 963 | if (node->nport->enable_ini) | ||
| 964 | ct->rffid.fr_feat |= FCP_FEAT_INIT; | ||
| 965 | if (node->nport->enable_tgt) | ||
| 966 | ct->rffid.fr_feat |= FCP_FEAT_TARG; | ||
| 967 | ct->rffid.fr_type = FC_TYPE_FCP; | ||
| 968 | |||
| 969 | return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ); | ||
| 970 | } | ||
| 971 | |||
| 972 | int | ||
| 973 | efc_ns_send_gidpt(struct efc_node *node) | ||
| 974 | { | ||
| 975 | struct efc_els_io_req *els = NULL; | ||
| 976 | struct efc *efc = node->efc; | ||
| 977 | struct { | ||
| 978 | struct fc_ct_hdr hdr; | ||
| 979 | struct fc_ns_gid_pt gidpt; | ||
| 980 | } *ct; | ||
| 981 | |||
| 982 | node_els_trace(); | ||
| 983 | |||
| 984 | els = efc_els_io_alloc_size(node, sizeof(*ct), EFC_ELS_GID_PT_RSP_LEN); | ||
| 985 | if (!els) { | ||
| 986 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 987 | return -EIO; | ||
| 988 | } | ||
| 989 | |||
| 990 | els->io.iparam.ct.r_ctl = FC_RCTL_ELS_REQ; | ||
| 991 | els->io.iparam.ct.type = FC_TYPE_CT; | ||
| 992 | els->io.iparam.ct.df_ctl = 0; | ||
| 993 | els->io.iparam.ct.timeout = EFC_FC_ELS_SEND_DEFAULT_TIMEOUT; | ||
| 994 | |||
| 995 | els->display_name = "gidpt"; | ||
| 996 | |||
| 997 | ct = els->io.req.virt; | ||
| 998 | |||
| 999 | memset(ct, 0, sizeof(*ct)); | ||
| 1000 | fcct_build_req_header(&ct->hdr, FC_NS_GID_PT, | ||
| 1001 | sizeof(struct fc_ns_gid_pt)); | ||
| 1002 | |||
| 1003 | ct->gidpt.fn_pt_type = FC_TYPE_FCP; | ||
| 1004 | |||
| 1005 | return efc_els_send_req(node, els, EFC_DISC_IO_CT_REQ); | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | void | ||
| 1009 | efc_els_io_cleanup(struct efc_els_io_req *els, int evt, void *arg) | ||
| 1010 | { | ||
| 1011 | /* don't want further events that could come; e.g. abort requests | ||
| 1012 | * from the node state machine; thus, disable state machine | ||
| 1013 | */ | ||
| 1014 | els->els_req_free = true; | ||
| 1015 | efc_node_post_els_resp(els->node, evt, arg); | ||
| 1016 | |||
| 1017 | efc_els_io_free(els); | ||
| 1018 | } | ||
| 1019 | |||
| 1020 | static int | ||
| 1021 | efc_ct_acc_cb(void *arg, u32 length, int status, u32 ext_status) | ||
| 1022 | { | ||
| 1023 | struct efc_els_io_req *els = arg; | ||
| 1024 | |||
| 1025 | efc_els_io_free(els); | ||
| 1026 | |||
| 1027 | return 0; | ||
| 1028 | } | ||
| 1029 | |||
| 1030 | int | ||
| 1031 | efc_send_ct_rsp(struct efc *efc, struct efc_node *node, u16 ox_id, | ||
| 1032 | struct fc_ct_hdr *ct_hdr, u32 cmd_rsp_code, | ||
| 1033 | u32 reason_code, u32 reason_code_explanation) | ||
| 1034 | { | ||
| 1035 | struct efc_els_io_req *els = NULL; | ||
| 1036 | struct fc_ct_hdr *rsp = NULL; | ||
| 1037 | |||
| 1038 | els = efc_els_io_alloc(node, 256); | ||
| 1039 | if (!els) { | ||
| 1040 | efc_log_err(efc, "IO alloc failed\n"); | ||
| 1041 | return -EIO; | ||
| 1042 | } | ||
| 1043 | |||
| 1044 | rsp = els->io.rsp.virt; | ||
| 1045 | |||
| 1046 | *rsp = *ct_hdr; | ||
| 1047 | |||
| 1048 | fcct_build_req_header(rsp, cmd_rsp_code, 0); | ||
| 1049 | rsp->ct_reason = reason_code; | ||
| 1050 | rsp->ct_explan = reason_code_explanation; | ||
| 1051 | |||
| 1052 | els->display_name = "ct_rsp"; | ||
| 1053 | els->cb = efc_ct_acc_cb; | ||
| 1054 | |||
| 1055 | /* Prepare the IO request details */ | ||
| 1056 | els->io.io_type = EFC_DISC_IO_CT_RESP; | ||
| 1057 | els->io.xmit_len = sizeof(*rsp); | ||
| 1058 | |||
| 1059 | els->io.rpi = node->rnode.indicator; | ||
| 1060 | els->io.d_id = node->rnode.fc_id; | ||
| 1061 | |||
| 1062 | memset(&els->io.iparam, 0, sizeof(els->io.iparam)); | ||
| 1063 | |||
| 1064 | els->io.iparam.ct.ox_id = ox_id; | ||
| 1065 | els->io.iparam.ct.r_ctl = 3; | ||
| 1066 | els->io.iparam.ct.type = FC_TYPE_CT; | ||
| 1067 | els->io.iparam.ct.df_ctl = 0; | ||
| 1068 | els->io.iparam.ct.timeout = 5; | ||
| 1069 | |||
| 1070 | if (efc->tt.send_els(efc, &els->io)) { | ||
| 1071 | efc_els_io_free(els); | ||
| 1072 | return -EIO; | ||
| 1073 | } | ||
| 1074 | return 0; | ||
| 1075 | } | ||
| 1076 | |||
| 1077 | int | ||
| 1078 | efc_send_bls_acc(struct efc_node *node, struct fc_frame_header *hdr) | ||
| 1079 | { | ||
| 1080 | struct sli_bls_params bls; | ||
| 1081 | struct fc_ba_acc *acc; | ||
| 1082 | struct efc *efc = node->efc; | ||
| 1083 | |||
| 1084 | memset(&bls, 0, sizeof(bls)); | ||
| 1085 | bls.ox_id = be16_to_cpu(hdr->fh_ox_id); | ||
| 1086 | bls.rx_id = be16_to_cpu(hdr->fh_rx_id); | ||
| 1087 | bls.s_id = ntoh24(hdr->fh_d_id); | ||
| 1088 | bls.d_id = node->rnode.fc_id; | ||
| 1089 | bls.rpi = node->rnode.indicator; | ||
| 1090 | bls.vpi = node->nport->indicator; | ||
| 1091 | |||
| 1092 | acc = (void *)bls.payload; | ||
| 1093 | acc->ba_ox_id = cpu_to_be16(bls.ox_id); | ||
| 1094 | acc->ba_rx_id = cpu_to_be16(bls.rx_id); | ||
| 1095 | acc->ba_high_seq_cnt = cpu_to_be16(U16_MAX); | ||
| 1096 | |||
| 1097 | return efc->tt.send_bls(efc, FC_RCTL_BA_ACC, &bls); | ||
| 1098 | } | ||
| @@ -0,0 +1,107 @@ | |||
| 1 | /* SPDX-License-Identifier: GPL-2.0 */ | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #ifndef __EFC_ELS_H__ | ||
| 8 | #define __EFC_ELS_H__ | ||
| 9 | |||
| 10 | #define EFC_STATUS_INVALID INT_MAX | ||
| 11 | #define EFC_ELS_IO_POOL_SZ 1024 | ||
| 12 | |||
| 13 | struct efc_els_io_req { | ||
| 14 | struct list_head list_entry; | ||
| 15 | struct kref ref; | ||
| 16 | void (*release)(struct kref *arg); | ||
| 17 | struct efc_node *node; | ||
| 18 | void *cb; | ||
| 19 | u32 els_retries_remaining; | ||
| 20 | bool els_req_free; | ||
| 21 | struct timer_list delay_timer; | ||
| 22 | |||
| 23 | const char *display_name; | ||
| 24 | |||
| 25 | struct efc_disc_io io; | ||
| 26 | }; | ||
| 27 | |||
| 28 | typedef int(*efc_hw_srrs_cb_t)(void *arg, u32 length, int status, | ||
| 29 | u32 ext_status); | ||
| 30 | |||
| 31 | void _efc_els_io_free(struct kref *arg); | ||
| 32 | struct efc_els_io_req * | ||
| 33 | efc_els_io_alloc(struct efc_node *node, u32 reqlen); | ||
| 34 | struct efc_els_io_req * | ||
| 35 | efc_els_io_alloc_size(struct efc_node *node, u32 reqlen, u32 rsplen); | ||
| 36 | void efc_els_io_free(struct efc_els_io_req *els); | ||
| 37 | |||
| 38 | /* ELS command send */ | ||
| 39 | typedef void (*els_cb_t)(struct efc_node *node, | ||
| 40 | struct efc_node_cb *cbdata, void *arg); | ||
| 41 | int | ||
| 42 | efc_send_plogi(struct efc_node *node); | ||
| 43 | int | ||
| 44 | efc_send_flogi(struct efc_node *node); | ||
| 45 | int | ||
| 46 | efc_send_fdisc(struct efc_node *node); | ||
| 47 | int | ||
| 48 | efc_send_prli(struct efc_node *node); | ||
| 49 | int | ||
| 50 | efc_send_prlo(struct efc_node *node); | ||
| 51 | int | ||
| 52 | efc_send_logo(struct efc_node *node); | ||
| 53 | int | ||
| 54 | efc_send_adisc(struct efc_node *node); | ||
| 55 | int | ||
| 56 | efc_send_pdisc(struct efc_node *node); | ||
| 57 | int | ||
| 58 | efc_send_scr(struct efc_node *node); | ||
| 59 | int | ||
| 60 | efc_ns_send_rftid(struct efc_node *node); | ||
| 61 | int | ||
| 62 | efc_ns_send_rffid(struct efc_node *node); | ||
| 63 | int | ||
| 64 | efc_ns_send_gidpt(struct efc_node *node); | ||
| 65 | void | ||
| 66 | efc_els_io_cleanup(struct efc_els_io_req *els, int evt, void *arg); | ||
| 67 | |||
| 68 | /* ELS acc send */ | ||
| 69 | int | ||
| 70 | efc_send_ls_acc(struct efc_node *node, u32 ox_id); | ||
| 71 | int | ||
| 72 | efc_send_ls_rjt(struct efc_node *node, u32 ox_id, u32 reason_cod, | ||
| 73 | u32 reason_code_expl, u32 vendor_unique); | ||
| 74 | int | ||
| 75 | efc_send_flogi_p2p_acc(struct efc_node *node, u32 ox_id, u32 s_id); | ||
| 76 | int | ||
| 77 | efc_send_flogi_acc(struct efc_node *node, u32 ox_id, u32 is_fport); | ||
| 78 | int | ||
| 79 | efc_send_plogi_acc(struct efc_node *node, u32 ox_id); | ||
| 80 | int | ||
| 81 | efc_send_prli_acc(struct efc_node *node, u32 ox_id); | ||
| 82 | int | ||
| 83 | efc_send_logo_acc(struct efc_node *node, u32 ox_id); | ||
| 84 | int | ||
| 85 | efc_send_prlo_acc(struct efc_node *node, u32 ox_id); | ||
| 86 | int | ||
| 87 | efc_send_adisc_acc(struct efc_node *node, u32 ox_id); | ||
| 88 | |||
| 89 | int | ||
| 90 | efc_bls_send_acc_hdr(struct efc *efc, struct efc_node *node, | ||
| 91 | struct fc_frame_header *hdr); | ||
| 92 | int | ||
| 93 | efc_bls_send_rjt_hdr(struct efc_els_io_req *io, struct fc_frame_header *hdr); | ||
| 94 | |||
| 95 | int | ||
| 96 | efc_els_io_list_empty(struct efc_node *node, struct list_head *list); | ||
| 97 | |||
| 98 | /* CT */ | ||
| 99 | int | ||
| 100 | efc_send_ct_rsp(struct efc *efc, struct efc_node *node, u16 ox_id, | ||
| 101 | struct fc_ct_hdr *ct_hdr, u32 cmd_rsp_code, u32 reason_code, | ||
| 102 | u32 reason_code_explanation); | ||
| 103 | |||
| 104 | int | ||
| 105 | efc_send_bls_acc(struct efc_node *node, struct fc_frame_header *hdr); | ||
| 106 | |||
| 107 | #endif /* __EFC_ELS_H__ */ | ||
| @@ -0,0 +1,1564 @@ | |||
| 1 | // SPDX-License-Identifier: GPL-2.0 | ||
| 2 | /* | ||
| 3 | * Copyright (C) 2021 Broadcom. All Rights Reserved. The term | ||
| 4 | * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. | ||
| 5 | */ | ||
| 6 | |||
| 7 | /* | ||
| 8 | * This file implements remote node state machines for: | ||
| 9 | * - Fabric logins. | ||
| 10 | * - Fabric controller events. | ||
| 11 | * - Name/directory services interaction. | ||
| 12 | * - Point-to-point logins. | ||
| 13 | */ | ||
| 14 | |||
| 15 | /* | ||
| 16 | * fabric_sm Node State Machine: Fabric States | ||
| 17 | * ns_sm Node State Machine: Name/Directory Services States | ||
| 18 | * p2p_sm Node State Machine: Point-to-Point Node States | ||
| 19 | */ | ||
| 20 | |||
| 21 | #include "efc.h" | ||
| 22 | |||
| 23 | static void | ||
| 24 | efc_fabric_initiate_shutdown(struct efc_node *node) | ||
| 25 | { | ||
| 26 | struct efc *efc = node->efc; | ||
| 27 | |||
| 28 | node->els_io_enabled = false; | ||
| 29 | |||
| 30 | if (node->attached) { | ||
| 31 | int rc; | ||
| 32 | |||
| 33 | /* issue hw node free; don't care if succeeds right away | ||
| 34 | * or sometime later, will check node->attached later in | ||
| 35 | * shutdown process | ||
| 36 | */ | ||
| 37 | rc = efc_cmd_node_detach(efc, &node->rnode); | ||
| 38 | if (rc < 0) { | ||
| 39 | node_printf(node, "Failed freeing HW node, rc=%d\n", | ||
| 40 | rc); | ||
| 41 | } | ||
| 42 | } | ||
| 43 | /* | ||
| 44 | * node has either been detached or is in the process of being detached, | ||
| 45 | * call common node's initiate cleanup function | ||
| 46 | */ | ||
| 47 | efc_node_initiate_cleanup(node); | ||
| 48 | } | ||
| 49 | |||
| 50 | static void | ||
| 51 | __efc_fabric_common(const char *funcname, struct efc_sm_ctx *ctx, | ||
| 52 | enum efc_sm_event evt, void *arg) | ||
| 53 | { | ||
| 54 | struct efc_node *node = NULL; | ||
| 55 | |||
| 56 | node = ctx->app; | ||
| 57 | |||
| 58 | switch (evt) { | ||
| 59 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 60 | break; | ||
| 61 | case EFC_EVT_SHUTDOWN: | ||
| 62 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 63 | efc_fabric_initiate_shutdown(node); | ||
| 64 | break; | ||
| 65 | |||
| 66 | default: | ||
| 67 | /* call default event handler common to all nodes */ | ||
| 68 | __efc_node_common(funcname, ctx, evt, arg); | ||
| 69 | } | ||
| 70 | } | ||
| 71 | |||
| 72 | void | ||
| 73 | __efc_fabric_init(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 74 | void *arg) | ||
| 75 | { | ||
| 76 | struct efc_node *node = ctx->app; | ||
| 77 | struct efc *efc = node->efc; | ||
| 78 | |||
| 79 | efc_node_evt_set(ctx, evt, __func__); | ||
| 80 | |||
| 81 | node_sm_trace(); | ||
| 82 | |||
| 83 | switch (evt) { | ||
| 84 | case EFC_EVT_REENTER: | ||
| 85 | efc_log_debug(efc, ">>> reenter !!\n"); | ||
| 86 | fallthrough; | ||
| 87 | |||
| 88 | case EFC_EVT_ENTER: | ||
| 89 | /* send FLOGI */ | ||
| 90 | efc_send_flogi(node); | ||
| 91 | efc_node_transition(node, __efc_fabric_flogi_wait_rsp, NULL); | ||
| 92 | break; | ||
| 93 | |||
| 94 | default: | ||
| 95 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 96 | } | ||
| 97 | } | ||
| 98 | |||
| 99 | void | ||
| 100 | efc_fabric_set_topology(struct efc_node *node, | ||
| 101 | enum efc_nport_topology topology) | ||
| 102 | { | ||
| 103 | node->nport->topology = topology; | ||
| 104 | } | ||
| 105 | |||
| 106 | void | ||
| 107 | efc_fabric_notify_topology(struct efc_node *node) | ||
| 108 | { | ||
| 109 | struct efc_node *tmp_node; | ||
| 110 | enum efc_nport_topology topology = node->nport->topology; | ||
| 111 | unsigned long index; | ||
| 112 | |||
| 113 | /* | ||
| 114 | * now loop through the nodes in the nport | ||
| 115 | * and send topology notification | ||
| 116 | */ | ||
| 117 | xa_for_each(&node->nport->lookup, index, tmp_node) { | ||
| 118 | if (tmp_node != node) { | ||
| 119 | efc_node_post_event(tmp_node, | ||
| 120 | EFC_EVT_NPORT_TOPOLOGY_NOTIFY, | ||
| 121 | (void *)topology); | ||
| 122 | } | ||
| 123 | } | ||
| 124 | } | ||
| 125 | |||
| 126 | static bool efc_rnode_is_nport(struct fc_els_flogi *rsp) | ||
| 127 | { | ||
| 128 | return !(ntohs(rsp->fl_csp.sp_features) & FC_SP_FT_FPORT); | ||
| 129 | } | ||
| 130 | |||
| 131 | void | ||
| 132 | __efc_fabric_flogi_wait_rsp(struct efc_sm_ctx *ctx, | ||
| 133 | enum efc_sm_event evt, void *arg) | ||
| 134 | { | ||
| 135 | struct efc_node_cb *cbdata = arg; | ||
| 136 | struct efc_node *node = ctx->app; | ||
| 137 | |||
| 138 | efc_node_evt_set(ctx, evt, __func__); | ||
| 139 | |||
| 140 | node_sm_trace(); | ||
| 141 | |||
| 142 | switch (evt) { | ||
| 143 | case EFC_EVT_SRRS_ELS_REQ_OK: { | ||
| 144 | if (efc_node_check_els_req(ctx, evt, arg, ELS_FLOGI, | ||
| 145 | __efc_fabric_common, __func__)) { | ||
| 146 | return; | ||
| 147 | } | ||
| 148 | WARN_ON(!node->els_req_cnt); | ||
| 149 | node->els_req_cnt--; | ||
| 150 | |||
| 151 | memcpy(node->nport->domain->flogi_service_params, | ||
| 152 | cbdata->els_rsp.virt, | ||
| 153 | sizeof(struct fc_els_flogi)); | ||
| 154 | |||
| 155 | /* Check to see if the fabric is an F_PORT or and N_PORT */ | ||
| 156 | if (!efc_rnode_is_nport(cbdata->els_rsp.virt)) { | ||
| 157 | /* sm: if not nport / efc_domain_attach */ | ||
| 158 | /* ext_status has the fc_id, attach domain */ | ||
| 159 | efc_fabric_set_topology(node, EFC_NPORT_TOPO_FABRIC); | ||
| 160 | efc_fabric_notify_topology(node); | ||
| 161 | WARN_ON(node->nport->domain->attached); | ||
| 162 | efc_domain_attach(node->nport->domain, | ||
| 163 | cbdata->ext_status); | ||
| 164 | efc_node_transition(node, | ||
| 165 | __efc_fabric_wait_domain_attach, | ||
| 166 | NULL); | ||
| 167 | break; | ||
| 168 | } | ||
| 169 | |||
| 170 | /* sm: if nport and p2p_winner / efc_domain_attach */ | ||
| 171 | efc_fabric_set_topology(node, EFC_NPORT_TOPO_P2P); | ||
| 172 | if (efc_p2p_setup(node->nport)) { | ||
| 173 | node_printf(node, | ||
| 174 | "p2p setup failed, shutting down node\n"); | ||
| 175 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 176 | efc_fabric_initiate_shutdown(node); | ||
| 177 | break; | ||
| 178 | } | ||
| 179 | |||
| 180 | if (node->nport->p2p_winner) { | ||
| 181 | efc_node_transition(node, | ||
| 182 | __efc_p2p_wait_domain_attach, | ||
| 183 | NULL); | ||
| 184 | if (node->nport->domain->attached && | ||
| 185 | !node->nport->domain->domain_notify_pend) { | ||
| 186 | /* | ||
| 187 | * already attached, | ||
| 188 | * just send ATTACH_OK | ||
| 189 | */ | ||
| 190 | node_printf(node, | ||
| 191 | "p2p winner, domain already attached\n"); | ||
| 192 | efc_node_post_event(node, | ||
| 193 | EFC_EVT_DOMAIN_ATTACH_OK, | ||
| 194 | NULL); | ||
| 195 | } | ||
| 196 | } else { | ||
| 197 | /* | ||
| 198 | * peer is p2p winner; | ||
| 199 | * PLOGI will be received on the | ||
| 200 | * remote SID=1 node; | ||
| 201 | * this node has served its purpose | ||
| 202 | */ | ||
| 203 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 204 | efc_fabric_initiate_shutdown(node); | ||
| 205 | } | ||
| 206 | |||
| 207 | break; | ||
| 208 | } | ||
| 209 | |||
| 210 | case EFC_EVT_ELS_REQ_ABORTED: | ||
| 211 | case EFC_EVT_SRRS_ELS_REQ_RJT: | ||
| 212 | case EFC_EVT_SRRS_ELS_REQ_FAIL: { | ||
| 213 | struct efc_nport *nport = node->nport; | ||
| 214 | /* | ||
| 215 | * with these errors, we have no recovery, | ||
| 216 | * so shutdown the nport, leave the link | ||
| 217 | * up and the domain ready | ||
| 218 | */ | ||
| 219 | if (efc_node_check_els_req(ctx, evt, arg, ELS_FLOGI, | ||
| 220 | __efc_fabric_common, __func__)) { | ||
| 221 | return; | ||
| 222 | } | ||
| 223 | node_printf(node, | ||
| 224 | "FLOGI failed evt=%s, shutting down nport [%s]\n", | ||
| 225 | efc_sm_event_name(evt), nport->display_name); | ||
| 226 | WARN_ON(!node->els_req_cnt); | ||
| 227 | node->els_req_cnt--; | ||
| 228 | efc_sm_post_event(&nport->sm, EFC_EVT_SHUTDOWN, NULL); | ||
| 229 | break; | ||
| 230 | } | ||
| 231 | |||
| 232 | default: | ||
| 233 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 234 | } | ||
| 235 | } | ||
| 236 | |||
| 237 | void | ||
| 238 | __efc_vport_fabric_init(struct efc_sm_ctx *ctx, | ||
| 239 | enum efc_sm_event evt, void *arg) | ||
| 240 | { | ||
| 241 | struct efc_node *node = ctx->app; | ||
| 242 | |||
| 243 | efc_node_evt_set(ctx, evt, __func__); | ||
| 244 | |||
| 245 | node_sm_trace(); | ||
| 246 | |||
| 247 | switch (evt) { | ||
| 248 | case EFC_EVT_ENTER: | ||
| 249 | /* sm: / send FDISC */ | ||
| 250 | efc_send_fdisc(node); | ||
| 251 | efc_node_transition(node, __efc_fabric_fdisc_wait_rsp, NULL); | ||
| 252 | break; | ||
| 253 | |||
| 254 | default: | ||
| 255 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 256 | } | ||
| 257 | } | ||
| 258 | |||
| 259 | void | ||
| 260 | __efc_fabric_fdisc_wait_rsp(struct efc_sm_ctx *ctx, | ||
| 261 | enum efc_sm_event evt, void *arg) | ||
| 262 | { | ||
| 263 | struct efc_node_cb *cbdata = arg; | ||
| 264 | struct efc_node *node = ctx->app; | ||
| 265 | |||
| 266 | efc_node_evt_set(ctx, evt, __func__); | ||
| 267 | |||
| 268 | node_sm_trace(); | ||
| 269 | |||
| 270 | switch (evt) { | ||
| 271 | case EFC_EVT_SRRS_ELS_REQ_OK: { | ||
| 272 | /* fc_id is in ext_status */ | ||
| 273 | if (efc_node_check_els_req(ctx, evt, arg, ELS_FDISC, | ||
| 274 | __efc_fabric_common, __func__)) { | ||
| 275 | return; | ||
| 276 | } | ||
| 277 | |||
| 278 | WARN_ON(!node->els_req_cnt); | ||
| 279 | node->els_req_cnt--; | ||
| 280 | /* sm: / efc_nport_attach */ | ||
| 281 | efc_nport_attach(node->nport, cbdata->ext_status); | ||
| 282 | efc_node_transition(node, __efc_fabric_wait_domain_attach, | ||
| 283 | NULL); | ||
| 284 | break; | ||
| 285 | } | ||
| 286 | |||
| 287 | case EFC_EVT_SRRS_ELS_REQ_RJT: | ||
| 288 | case EFC_EVT_SRRS_ELS_REQ_FAIL: { | ||
| 289 | if (efc_node_check_els_req(ctx, evt, arg, ELS_FDISC, | ||
| 290 | __efc_fabric_common, __func__)) { | ||
| 291 | return; | ||
| 292 | } | ||
| 293 | WARN_ON(!node->els_req_cnt); | ||
| 294 | node->els_req_cnt--; | ||
| 295 | efc_log_err(node->efc, "FDISC failed, shutting down nport\n"); | ||
| 296 | /* sm: / shutdown nport */ | ||
| 297 | efc_sm_post_event(&node->nport->sm, EFC_EVT_SHUTDOWN, NULL); | ||
| 298 | break; | ||
| 299 | } | ||
| 300 | |||
| 301 | default: | ||
| 302 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 303 | } | ||
| 304 | } | ||
| 305 | |||
| 306 | static int | ||
| 307 | efc_start_ns_node(struct efc_nport *nport) | ||
| 308 | { | ||
| 309 | struct efc_node *ns; | ||
| 310 | |||
| 311 | /* Instantiate a name services node */ | ||
| 312 | ns = efc_node_find(nport, FC_FID_DIR_SERV); | ||
| 313 | if (!ns) { | ||
| 314 | ns = efc_node_alloc(nport, FC_FID_DIR_SERV, false, false); | ||
| 315 | if (!ns) | ||
| 316 | return -EIO; | ||
| 317 | } | ||
| 318 | /* | ||
| 319 | * for found ns, should we be transitioning from here? | ||
| 320 | * breaks transition only | ||
| 321 | * 1. from within state machine or | ||
| 322 | * 2. if after alloc | ||
| 323 | */ | ||
| 324 | if (ns->efc->nodedb_mask & EFC_NODEDB_PAUSE_NAMESERVER) | ||
| 325 | efc_node_pause(ns, __efc_ns_init); | ||
| 326 | else | ||
| 327 | efc_node_transition(ns, __efc_ns_init, NULL); | ||
| 328 | return 0; | ||
| 329 | } | ||
| 330 | |||
| 331 | static int | ||
| 332 | efc_start_fabctl_node(struct efc_nport *nport) | ||
| 333 | { | ||
| 334 | struct efc_node *fabctl; | ||
| 335 | |||
| 336 | fabctl = efc_node_find(nport, FC_FID_FCTRL); | ||
| 337 | if (!fabctl) { | ||
| 338 | fabctl = efc_node_alloc(nport, FC_FID_FCTRL, | ||
| 339 | false, false); | ||
| 340 | if (!fabctl) | ||
| 341 | return -EIO; | ||
| 342 | } | ||
| 343 | /* | ||
| 344 | * for found ns, should we be transitioning from here? | ||
| 345 | * breaks transition only | ||
| 346 | * 1. from within state machine or | ||
| 347 | * 2. if after alloc | ||
| 348 | */ | ||
| 349 | efc_node_transition(fabctl, __efc_fabctl_init, NULL); | ||
| 350 | return 0; | ||
| 351 | } | ||
| 352 | |||
| 353 | void | ||
| 354 | __efc_fabric_wait_domain_attach(struct efc_sm_ctx *ctx, | ||
| 355 | enum efc_sm_event evt, void *arg) | ||
| 356 | { | ||
| 357 | struct efc_node *node = ctx->app; | ||
| 358 | |||
| 359 | efc_node_evt_set(ctx, evt, __func__); | ||
| 360 | |||
| 361 | node_sm_trace(); | ||
| 362 | |||
| 363 | switch (evt) { | ||
| 364 | case EFC_EVT_ENTER: | ||
| 365 | efc_node_hold_frames(node); | ||
| 366 | break; | ||
| 367 | |||
| 368 | case EFC_EVT_EXIT: | ||
| 369 | efc_node_accept_frames(node); | ||
| 370 | break; | ||
| 371 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 372 | case EFC_EVT_NPORT_ATTACH_OK: { | ||
| 373 | int rc; | ||
| 374 | |||
| 375 | rc = efc_start_ns_node(node->nport); | ||
| 376 | if (rc) | ||
| 377 | return; | ||
| 378 | |||
| 379 | /* sm: if enable_ini / start fabctl node */ | ||
| 380 | /* Instantiate the fabric controller (sends SCR) */ | ||
| 381 | if (node->nport->enable_rscn) { | ||
| 382 | rc = efc_start_fabctl_node(node->nport); | ||
| 383 | if (rc) | ||
| 384 | return; | ||
| 385 | } | ||
| 386 | efc_node_transition(node, __efc_fabric_idle, NULL); | ||
| 387 | break; | ||
| 388 | } | ||
| 389 | default: | ||
| 390 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 391 | } | ||
| 392 | } | ||
| 393 | |||
| 394 | void | ||
| 395 | __efc_fabric_idle(struct efc_sm_ctx *ctx, enum efc_sm_event evt, | ||
| 396 | void *arg) | ||
| 397 | { | ||
| 398 | struct efc_node *node = ctx->app; | ||
| 399 | |||
| 400 | efc_node_evt_set(ctx, evt, __func__); | ||
| 401 | |||
| 402 | node_sm_trace(); | ||
| 403 | |||
| 404 | switch (evt) { | ||
| 405 | case EFC_EVT_DOMAIN_ATTACH_OK: | ||
| 406 | break; | ||
| 407 | default: | ||
| 408 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 409 | } | ||
| 410 | } | ||
| 411 | |||
| 412 | void | ||
| 413 | __efc_ns_init(struct efc_sm_ctx *ctx, enum efc_sm_event evt, void *arg) | ||
| 414 | { | ||
| 415 | struct efc_node *node = ctx->app; | ||
| 416 | |||
| 417 | efc_node_evt_set(ctx, evt, __func__); | ||
| 418 | |||
| 419 | node_sm_trace(); | ||
| 420 | |||
| 421 | switch (evt) { | ||
| 422 | case EFC_EVT_ENTER: | ||
| 423 | /* sm: / send PLOGI */ | ||
| 424 | efc_send_plogi(node); | ||
| 425 | efc_node_transition(node, __efc_ns_plogi_wait_rsp, NULL); | ||
| 426 | break; | ||
| 427 | default: | ||
| 428 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 429 | } | ||
| 430 | } | ||
| 431 | |||
| 432 | void | ||
| 433 | __efc_ns_plogi_wait_rsp(struct efc_sm_ctx *ctx, | ||
| 434 | enum efc_sm_event evt, void *arg) | ||
| 435 | { | ||
| 436 | struct efc_node_cb *cbdata = arg; | ||
| 437 | struct efc_node *node = ctx->app; | ||
| 438 | |||
| 439 | efc_node_evt_set(ctx, evt, __func__); | ||
| 440 | |||
| 441 | node_sm_trace(); | ||
| 442 | |||
| 443 | switch (evt) { | ||
| 444 | case EFC_EVT_SRRS_ELS_REQ_OK: { | ||
| 445 | int rc; | ||
| 446 | |||
| 447 | /* Save service parameters */ | ||
| 448 | if (efc_node_check_els_req(ctx, evt, arg, ELS_PLOGI, | ||
| 449 | __efc_fabric_common, __func__)) { | ||
| 450 | return; | ||
| 451 | } | ||
| 452 | WARN_ON(!node->els_req_cnt); | ||
| 453 | node->els_req_cnt--; | ||
| 454 | /* sm: / save sparams, efc_node_attach */ | ||
| 455 | efc_node_save_sparms(node, cbdata->els_rsp.virt); | ||
| 456 | rc = efc_node_attach(node); | ||
| 457 | efc_node_transition(node, __efc_ns_wait_node_attach, NULL); | ||
| 458 | if (rc < 0) | ||
| 459 | efc_node_post_event(node, EFC_EVT_NODE_ATTACH_FAIL, | ||
| 460 | NULL); | ||
| 461 | break; | ||
| 462 | } | ||
| 463 | default: | ||
| 464 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 465 | } | ||
| 466 | } | ||
| 467 | |||
| 468 | void | ||
| 469 | __efc_ns_wait_node_attach(struct efc_sm_ctx *ctx, | ||
| 470 | enum efc_sm_event evt, void *arg) | ||
| 471 | { | ||
| 472 | struct efc_node *node = ctx->app; | ||
| 473 | |||
| 474 | efc_node_evt_set(ctx, evt, __func__); | ||
| 475 | |||
| 476 | node_sm_trace(); | ||
| 477 | |||
| 478 | switch (evt) { | ||
| 479 | case EFC_EVT_ENTER: | ||
| 480 | efc_node_hold_frames(node); | ||
| 481 | break; | ||
| 482 | |||
| 483 | case EFC_EVT_EXIT: | ||
| 484 | efc_node_accept_frames(node); | ||
| 485 | break; | ||
| 486 | |||
| 487 | case EFC_EVT_NODE_ATTACH_OK: | ||
| 488 | node->attached = true; | ||
| 489 | /* sm: / send RFTID */ | ||
| 490 | efc_ns_send_rftid(node); | ||
| 491 | efc_node_transition(node, __efc_ns_rftid_wait_rsp, NULL); | ||
| 492 | break; | ||
| 493 | |||
| 494 | case EFC_EVT_NODE_ATTACH_FAIL: | ||
| 495 | /* node attach failed, shutdown the node */ | ||
| 496 | node->attached = false; | ||
| 497 | node_printf(node, "Node attach failed\n"); | ||
| 498 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 499 | efc_fabric_initiate_shutdown(node); | ||
| 500 | break; | ||
| 501 | |||
| 502 | case EFC_EVT_SHUTDOWN: | ||
| 503 | node_printf(node, "Shutdown event received\n"); | ||
| 504 | node->shutdown_reason = EFC_NODE_SHUTDOWN_DEFAULT; | ||
| 505 | efc_node_transition(node, | ||
| 506 | __efc_fabric_wait_attach_evt_shutdown, | ||
| 507 | NULL); | ||
| 508 | break; | ||
| 509 | |||
| 510 | /* | ||
| 511 | * if receive RSCN just ignore, | ||
| 512 | * we haven't sent GID_PT yet (ACC sent by fabctl node) | ||
| 513 | */ | ||
| 514 | case EFC_EVT_RSCN_RCVD: | ||
| 515 | break; | ||
| 516 | |||
| 517 | default: | ||
| 518 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 519 | } | ||
| 520 | } | ||
| 521 | |||
| 522 | void | ||
| 523 | __efc_fabric_wait_attach_evt_shutdown(struct efc_sm_ctx *ctx, | ||
| 524 | enum efc_sm_event evt, void *arg) | ||
| 525 | { | ||
| 526 | struct efc_node *node = ctx->app; | ||
| 527 | |||
| 528 | efc_node_evt_set(ctx, evt, __func__); | ||
| 529 | |||
| 530 | node_sm_trace(); | ||
| 531 | |||
| 532 | switch (evt) { | ||
| 533 | case EFC_EVT_ENTER: | ||
| 534 | efc_node_hold_frames(node); | ||
| 535 | break; | ||
| 536 | |||
| 537 | case EFC_EVT_EXIT: | ||
| 538 | efc_node_accept_frames(node); | ||
| 539 | break; | ||
| 540 | |||
| 541 | /* wait for any of these attach events and then shutdown */ | ||
| 542 | case EFC_EVT_NODE_ATTACH_OK: | ||
| 543 | node->attached = true; | ||
| 544 | node_printf(node, "Attach evt=%s, proceed to shutdown\n", | ||
| 545 | efc_sm_event_name(evt)); | ||
| 546 | efc_fabric_initiate_shutdown(node); | ||
| 547 | break; | ||
| 548 | |||
| 549 | case EFC_EVT_NODE_ATTACH_FAIL: | ||
| 550 | node->attached = false; | ||
| 551 | node_printf(node, "Attach evt=%s, proceed to shutdown\n", | ||
| 552 | efc_sm_event_name(evt)); | ||
| 553 | efc_fabric_initiate_shutdown(node); | ||
| 554 | break; | ||
| 555 | |||
| 556 | /* ignore shutdown event as we're already in shutdown path */ | ||
| 557 | case EFC_EVT_SHUTDOWN: | ||
| 558 | node_printf(node, "Shutdown event received\n"); | ||
| 559 | break; | ||
| 560 | |||
| 561 | default: | ||
| 562 | __efc_fabric_common(__func__, ctx, evt, arg); | ||
| 563 | } | ||
| 564 | } | ||
| 565 | |||
| 566 | void | ||
| 567 | __efc_ns_rftid_wait_rsp(struct efc_sm_ctx *ctx, | ||
| 568 | enum efc_sm_event evt, void *arg) | ||
| 569 | { | ||
| 570 | struct efc_node *node = ctx->app; | ||
| 571 | |||
| 572 | efc_node_evt_set(ctx, evt, __func__); | ||
| 573 | |||
| 574 | node_sm_trace(); | ||
| 575 | |||
| 576 | switch (evt) { | ||
| 577 | case EFC_EVT_SRRS_ELS_REQ_OK: | ||
| 578 | if (efc_node_check_ns_req(ctx, evt, arg, FC_NS_RFT_ID, | ||
| 579 | __efc_fabric_common, __func__)) { | ||
| 580 | return; | ||
| 581 | } | ||
| 582 | WARN_ON(!node->els_req_cnt); | ||
| 583 | node->els_req_cnt--; | ||
| 584 | /* sm: / send RFFID */ | ||
| 585 | efc_ns_send_rffid(node); | ||
| 586 | efc_node_transition(node, __efc_ns_rffid_wait_rsp, NULL); | ||
| 587 | break; | ||
| 588 | |||
| 589 | /* | ||
| 590 | * if receive RSCN just ignore, | ||
| 591 | * we haven't sent GID_PT yet (ACC sent by fabctl node) | ||
| 592 | */ | ||
| 593 | case EFC_EVT_RSCN_RCVD: | ||
| 594 | break; | ||
970 more lines aren’t shown here.
This diff is large: its 117 lines aren’t shown here.
This diff is large: its 1103 lines aren’t shown here.
This diff is large: its 192 lines aren’t shown here.
This diff is large: its 778 lines aren’t shown here.
This diff is large: its 51 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 198 lines aren’t shown here.
This diff is large: its 82 lines aren’t shown here.
This diff is large: its 621 lines aren’t shown here.
This diff is large: its 5163 lines aren’t shown here.
This diff is large: its 4133 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 298 lines aren’t shown here.
This diff is large: its 89 lines aren’t shown here.
This diff is large: its 42 lines aren’t shown here.
This diff is large: its 41 lines aren’t shown here.
This diff is large: its 43 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 122 lines aren’t shown here.
This diff is large: its 17 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
This diff is large: its 309 lines aren’t shown here.
This diff is large: its 183 lines aren’t shown here.
This diff is large: its 572 lines aren’t shown here.
This diff is large: its 14 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 18 lines aren’t shown here.
This diff is large: its 187 lines aren’t shown here.
This diff is large: its 101 lines aren’t shown here.
This diff is large: its 23 lines aren’t shown here.
This diff is large: its 377 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
This diff is large: its 16 lines aren’t shown here.
This diff is large: its 876 lines aren’t shown here.
This diff is large: its 312 lines aren’t shown here.
This diff is large: its 173 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 165 lines aren’t shown here.
This diff is large: its 23 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 22 lines aren’t shown here.
This diff is large: its 588 lines aren’t shown here.
This diff is large: its 159 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 69 lines aren’t shown here.
This diff is large: its 37 lines aren’t shown here.
This diff is large: its 236 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 77 lines aren’t shown here.
This diff is large: its 31 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 5 lines aren’t shown here.
This diff is large: its 1881 lines aren’t shown here.
This diff is large: its 217 lines aren’t shown here.
This diff is large: its 160 lines aren’t shown here.
This diff is large: its 1005 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
This diff is large: its 464 lines aren’t shown here.
This diff is large: its 902 lines aren’t shown here.
This diff is large: its 61 lines aren’t shown here.
This diff is large: its 3959 lines aren’t shown here.
This diff is large: its 4046 lines aren’t shown here.
This diff is large: its 963 lines aren’t shown here.
This diff is large: its 43 lines aren’t shown here.
This diff is large: its 40 lines aren’t shown here.
This diff is large: its 340 lines aren’t shown here.
This diff is large: its 42 lines aren’t shown here.
This diff is large: its 34 lines aren’t shown here.
This diff is large: its 156 lines aren’t shown here.
This diff is large: its 23 lines aren’t shown here.
This diff is large: its 1162 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 66 lines aren’t shown here.
This diff is large: its 31 lines aren’t shown here.
This diff is large: its 57 lines aren’t shown here.
This diff is large: its 11 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 22 lines aren’t shown here.
This diff is large: its 13 lines aren’t shown here.
This diff is large: its 12 lines aren’t shown here.
This diff is large: its 37 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 515 lines aren’t shown here.
This diff is large: its 17 lines aren’t shown here.
This diff is large: its 221 lines aren’t shown here.
This diff is large: its 19 lines aren’t shown here.
This diff is large: its 31 lines aren’t shown here.
This diff is large: its 25 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 35 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 25 lines aren’t shown here.
This diff is large: its 338 lines aren’t shown here.
This diff is large: its 32 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 174 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
This diff is large: its 190 lines aren’t shown here.
This diff is large: its 24 lines aren’t shown here.
This diff is large: its 26 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 680 lines aren’t shown here.
This diff is large: its 21 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 183 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 39 lines aren’t shown here.
This diff is large: its 10 lines aren’t shown here.
This diff is large: its 12 lines aren’t shown here.
This diff is large: its 18 lines aren’t shown here.
This diff is large: its 13 lines aren’t shown here.
This diff is large: its 29 lines aren’t shown here.
This diff is large: its 31 lines aren’t shown here.
This diff is large: its 193 lines aren’t shown here.
This diff is large: its 28 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 26 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 60 lines aren’t shown here.
This diff is large: its 31 lines aren’t shown here.
This diff is large: its 18 lines aren’t shown here.
This diff is large: its 79 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 355 lines aren’t shown here.
This diff is large: its 27 lines aren’t shown here.
This diff is large: its 53 lines aren’t shown here.
This diff is large: its 1986 lines aren’t shown here.
This diff is large: its 178 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 19 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 64 lines aren’t shown here.
This diff is large: its 22 lines aren’t shown here.
This diff is large: its 38 lines aren’t shown here.
This diff is large: its 51 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 30 lines aren’t shown here.
This diff is large: its 16 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 27 lines aren’t shown here.
This diff is large: its 71 lines aren’t shown here.
This diff is large: its 12 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 36 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 44 lines aren’t shown here.
This diff is large: its 205 lines aren’t shown here.
This diff is large: its 45 lines aren’t shown here.
This diff is large: its 47 lines aren’t shown here.
This diff is large: its 14 lines aren’t shown here.
This diff is large: its 55 lines aren’t shown here.
This diff is large: its 82 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 94 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 27 lines aren’t shown here.
This diff is large: its 48 lines aren’t shown here.
This diff is large: its 20 lines aren’t shown here.
This diff is large: its 204 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 59 lines aren’t shown here.
This diff is large: its 9 lines aren’t shown here.
This diff is large: its 71 lines aren’t shown here.
This diff is large: its 75 lines aren’t shown here.
This diff is large: its 63 lines aren’t shown here.
This diff is large: its 50 lines aren’t shown here.
This diff is large: its 49 lines aren’t shown here.
This diff is large: its 8 lines aren’t shown here.
This diff is large: its 63 lines aren’t shown here.
This diff is large: its 27 lines aren’t shown here.
This diff is large: its 32 lines aren’t shown here.