| .. | .. |
|---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
|---|
| 1 | 2 | /* |
|---|
| 2 | 3 | * This file is part of the Emulex Linux Device Driver for Enterprise iSCSI |
|---|
| 3 | 4 | * Host Bus Adapters. Refer to the README file included with this package |
|---|
| .. | .. |
|---|
| 6 | 7 | * Copyright (c) 2018 Broadcom. All Rights Reserved. |
|---|
| 7 | 8 | * The term "Broadcom" refers to Broadcom Inc. and/or its subsidiaries. |
|---|
| 8 | 9 | * |
|---|
| 9 | | - * This program is free software; you can redistribute it and/or modify it |
|---|
| 10 | | - * under the terms of version 2 of the GNU General Public License as published |
|---|
| 11 | | - * by the Free Software Foundation. |
|---|
| 12 | | - * |
|---|
| 13 | 10 | * Contact Information: |
|---|
| 14 | 11 | * linux-drivers@broadcom.com |
|---|
| 15 | | - * |
|---|
| 16 | 12 | */ |
|---|
| 17 | 13 | |
|---|
| 18 | 14 | #include <scsi/libiscsi.h> |
|---|
| .. | .. |
|---|
| 31 | 27 | |
|---|
| 32 | 28 | /** |
|---|
| 33 | 29 | * beiscsi_session_create - creates a new iscsi session |
|---|
| 30 | + * @ep: pointer to iscsi ep |
|---|
| 34 | 31 | * @cmds_max: max commands supported |
|---|
| 35 | 32 | * @qdepth: max queue depth supported |
|---|
| 36 | 33 | * @initial_cmdsn: initial iscsi CMDSN |
|---|
| .. | .. |
|---|
| 168 | 165 | * @cls_session: pointer to iscsi cls session |
|---|
| 169 | 166 | * @cls_conn: pointer to iscsi cls conn |
|---|
| 170 | 167 | * @transport_fd: EP handle(64 bit) |
|---|
| 168 | + * @is_leading: indicate if this is the session leading connection (MCS) |
|---|
| 171 | 169 | * |
|---|
| 172 | 170 | * This function binds the TCP Conn with iSCSI Connection and Session. |
|---|
| 173 | 171 | */ |
|---|
| .. | .. |
|---|
| 184 | 182 | struct beiscsi_endpoint *beiscsi_ep; |
|---|
| 185 | 183 | struct iscsi_endpoint *ep; |
|---|
| 186 | 184 | uint16_t cri_index; |
|---|
| 185 | + int rc = 0; |
|---|
| 187 | 186 | |
|---|
| 188 | 187 | ep = iscsi_lookup_endpoint(transport_fd); |
|---|
| 189 | 188 | if (!ep) |
|---|
| .. | .. |
|---|
| 191 | 190 | |
|---|
| 192 | 191 | beiscsi_ep = ep->dd_data; |
|---|
| 193 | 192 | |
|---|
| 194 | | - if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) |
|---|
| 195 | | - return -EINVAL; |
|---|
| 193 | + if (iscsi_conn_bind(cls_session, cls_conn, is_leading)) { |
|---|
| 194 | + rc = -EINVAL; |
|---|
| 195 | + goto put_ep; |
|---|
| 196 | + } |
|---|
| 196 | 197 | |
|---|
| 197 | 198 | if (beiscsi_ep->phba != phba) { |
|---|
| 198 | 199 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
|---|
| 199 | 200 | "BS_%d : beiscsi_ep->hba=%p not equal to phba=%p\n", |
|---|
| 200 | 201 | beiscsi_ep->phba, phba); |
|---|
| 201 | | - |
|---|
| 202 | | - return -EEXIST; |
|---|
| 202 | + rc = -EEXIST; |
|---|
| 203 | + goto put_ep; |
|---|
| 203 | 204 | } |
|---|
| 204 | 205 | cri_index = BE_GET_CRI_FROM_CID(beiscsi_ep->ep_cid); |
|---|
| 205 | 206 | if (phba->conn_table[cri_index]) { |
|---|
| .. | .. |
|---|
| 211 | 212 | beiscsi_ep->ep_cid, |
|---|
| 212 | 213 | beiscsi_conn, |
|---|
| 213 | 214 | phba->conn_table[cri_index]); |
|---|
| 214 | | - return -EINVAL; |
|---|
| 215 | + rc = -EINVAL; |
|---|
| 216 | + goto put_ep; |
|---|
| 215 | 217 | } |
|---|
| 216 | 218 | } |
|---|
| 217 | 219 | |
|---|
| .. | .. |
|---|
| 228 | 230 | "BS_%d : cid %d phba->conn_table[%u]=%p\n", |
|---|
| 229 | 231 | beiscsi_ep->ep_cid, cri_index, beiscsi_conn); |
|---|
| 230 | 232 | phba->conn_table[cri_index] = beiscsi_conn; |
|---|
| 231 | | - return 0; |
|---|
| 233 | + |
|---|
| 234 | +put_ep: |
|---|
| 235 | + iscsi_put_endpoint(ep); |
|---|
| 236 | + return rc; |
|---|
| 232 | 237 | } |
|---|
| 233 | 238 | |
|---|
| 234 | 239 | static int beiscsi_iface_create_ipv4(struct beiscsi_hba *phba) |
|---|
| .. | .. |
|---|
| 445 | 450 | } |
|---|
| 446 | 451 | |
|---|
| 447 | 452 | nla_for_each_attr(attrib, data, dt_len, rm_len) { |
|---|
| 453 | + /* ignore nla_type as it is never used */ |
|---|
| 454 | + if (nla_len(attrib) < sizeof(*iface_param)) |
|---|
| 455 | + return -EINVAL; |
|---|
| 456 | + |
|---|
| 448 | 457 | iface_param = nla_data(attrib); |
|---|
| 449 | 458 | |
|---|
| 450 | 459 | if (iface_param->param_type != ISCSI_NET_PARAM) |
|---|
| .. | .. |
|---|
| 679 | 688 | case ISCSI_PARAM_MAX_XMIT_DLENGTH: |
|---|
| 680 | 689 | if (conn->max_xmit_dlength > 65536) |
|---|
| 681 | 690 | conn->max_xmit_dlength = 65536; |
|---|
| 691 | + fallthrough; |
|---|
| 682 | 692 | default: |
|---|
| 683 | 693 | return 0; |
|---|
| 684 | 694 | } |
|---|
| .. | .. |
|---|
| 771 | 781 | status = beiscsi_get_initiator_name(phba, buf, false); |
|---|
| 772 | 782 | if (status < 0) { |
|---|
| 773 | 783 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
|---|
| 774 | | - "BS_%d : Retreiving Initiator Name Failed\n"); |
|---|
| 784 | + "BS_%d : Retrieving Initiator Name Failed\n"); |
|---|
| 775 | 785 | status = 0; |
|---|
| 776 | 786 | } |
|---|
| 777 | 787 | } |
|---|
| .. | .. |
|---|
| 995 | 1005 | |
|---|
| 996 | 1006 | /** |
|---|
| 997 | 1007 | * beiscsi_free_ep - free endpoint |
|---|
| 998 | | - * @ep: pointer to iscsi endpoint structure |
|---|
| 1008 | + * @beiscsi_ep: pointer to device endpoint struct |
|---|
| 999 | 1009 | */ |
|---|
| 1000 | 1010 | static void beiscsi_free_ep(struct beiscsi_endpoint *beiscsi_ep) |
|---|
| 1001 | 1011 | { |
|---|
| .. | .. |
|---|
| 1030 | 1040 | |
|---|
| 1031 | 1041 | /** |
|---|
| 1032 | 1042 | * beiscsi_open_conn - Ask FW to open a TCP connection |
|---|
| 1033 | | - * @ep: endpoint to be used |
|---|
| 1043 | + * @ep: pointer to device endpoint struct |
|---|
| 1034 | 1044 | * @src_addr: The source IP address |
|---|
| 1035 | 1045 | * @dst_addr: The Destination IP address |
|---|
| 1046 | + * @non_blocking: blocking or non-blocking call |
|---|
| 1036 | 1047 | * |
|---|
| 1037 | 1048 | * Asks the FW to open a TCP connection |
|---|
| 1038 | 1049 | */ |
|---|
| .. | .. |
|---|
| 1071 | 1082 | else |
|---|
| 1072 | 1083 | req_memsize = sizeof(struct tcp_connect_and_offload_in_v1); |
|---|
| 1073 | 1084 | |
|---|
| 1074 | | - nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev, |
|---|
| 1085 | + nonemb_cmd.va = dma_alloc_coherent(&phba->ctrl.pdev->dev, |
|---|
| 1075 | 1086 | req_memsize, |
|---|
| 1076 | | - &nonemb_cmd.dma); |
|---|
| 1087 | + &nonemb_cmd.dma, GFP_KERNEL); |
|---|
| 1077 | 1088 | if (nonemb_cmd.va == NULL) { |
|---|
| 1078 | 1089 | |
|---|
| 1079 | 1090 | beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG, |
|---|
| .. | .. |
|---|
| 1091 | 1102 | "BS_%d : mgmt_open_connection Failed for cid=%d\n", |
|---|
| 1092 | 1103 | beiscsi_ep->ep_cid); |
|---|
| 1093 | 1104 | |
|---|
| 1094 | | - pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
|---|
| 1105 | + dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, |
|---|
| 1095 | 1106 | nonemb_cmd.va, nonemb_cmd.dma); |
|---|
| 1096 | 1107 | beiscsi_free_ep(beiscsi_ep); |
|---|
| 1097 | 1108 | return -EAGAIN; |
|---|
| .. | .. |
|---|
| 1104 | 1115 | "BS_%d : mgmt_open_connection Failed"); |
|---|
| 1105 | 1116 | |
|---|
| 1106 | 1117 | if (ret != -EBUSY) |
|---|
| 1107 | | - pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
|---|
| 1108 | | - nonemb_cmd.va, nonemb_cmd.dma); |
|---|
| 1118 | + dma_free_coherent(&phba->ctrl.pdev->dev, |
|---|
| 1119 | + nonemb_cmd.size, nonemb_cmd.va, |
|---|
| 1120 | + nonemb_cmd.dma); |
|---|
| 1109 | 1121 | |
|---|
| 1110 | 1122 | beiscsi_free_ep(beiscsi_ep); |
|---|
| 1111 | 1123 | return ret; |
|---|
| .. | .. |
|---|
| 1118 | 1130 | beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG, |
|---|
| 1119 | 1131 | "BS_%d : mgmt_open_connection Success\n"); |
|---|
| 1120 | 1132 | |
|---|
| 1121 | | - pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size, |
|---|
| 1133 | + dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size, |
|---|
| 1122 | 1134 | nonemb_cmd.va, nonemb_cmd.dma); |
|---|
| 1123 | 1135 | return 0; |
|---|
| 1124 | 1136 | } |
|---|
| 1125 | 1137 | |
|---|
| 1126 | 1138 | /** |
|---|
| 1127 | 1139 | * beiscsi_ep_connect - Ask chip to create TCP Conn |
|---|
| 1128 | | - * @scsi_host: Pointer to scsi_host structure |
|---|
| 1140 | + * @shost: Pointer to scsi_host structure |
|---|
| 1129 | 1141 | * @dst_addr: The IP address of Target |
|---|
| 1130 | 1142 | * @non_blocking: blocking or non-blocking call |
|---|
| 1131 | 1143 | * |
|---|
| .. | .. |
|---|
| 1230 | 1242 | |
|---|
| 1231 | 1243 | /** |
|---|
| 1232 | 1244 | * beiscsi_conn_close - Invalidate and upload connection |
|---|
| 1233 | | - * @ep: The iscsi endpoint |
|---|
| 1245 | + * @beiscsi_ep: pointer to device endpoint struct |
|---|
| 1234 | 1246 | * |
|---|
| 1235 | 1247 | * Returns 0 on success, -1 on failure. |
|---|
| 1236 | 1248 | */ |
|---|