forked from ~ljy/RK356X_SDK_RELEASE

hc
2024-05-13 9d77db3c730780c8ef5ccd4b66403ff5675cfe4e
kernel/drivers/scsi/qla4xxx/ql4_os.c
....@@ -1,8 +1,7 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * QLogic iSCSI HBA Driver
34 * Copyright (c) 2003-2013 QLogic Corporation
4
- *
5
- * See LICENSE.qla4xxx for copyright and licensing details.
65 */
76 #include <linux/moduleparam.h>
87 #include <linux/slab.h>
....@@ -188,6 +187,40 @@
188187 static struct qla4_8xxx_legacy_intr_set legacy_intr[] =
189188 QLA82XX_LEGACY_INTR_CONFIG;
190189
190
+static const uint32_t qla4_82xx_reg_tbl[] = {
191
+ QLA82XX_PEG_HALT_STATUS1,
192
+ QLA82XX_PEG_HALT_STATUS2,
193
+ QLA82XX_PEG_ALIVE_COUNTER,
194
+ QLA82XX_CRB_DRV_ACTIVE,
195
+ QLA82XX_CRB_DEV_STATE,
196
+ QLA82XX_CRB_DRV_STATE,
197
+ QLA82XX_CRB_DRV_SCRATCH,
198
+ QLA82XX_CRB_DEV_PART_INFO,
199
+ QLA82XX_CRB_DRV_IDC_VERSION,
200
+ QLA82XX_FW_VERSION_MAJOR,
201
+ QLA82XX_FW_VERSION_MINOR,
202
+ QLA82XX_FW_VERSION_SUB,
203
+ CRB_CMDPEG_STATE,
204
+ CRB_TEMP_STATE,
205
+};
206
+
207
+static const uint32_t qla4_83xx_reg_tbl[] = {
208
+ QLA83XX_PEG_HALT_STATUS1,
209
+ QLA83XX_PEG_HALT_STATUS2,
210
+ QLA83XX_PEG_ALIVE_COUNTER,
211
+ QLA83XX_CRB_DRV_ACTIVE,
212
+ QLA83XX_CRB_DEV_STATE,
213
+ QLA83XX_CRB_DRV_STATE,
214
+ QLA83XX_CRB_DRV_SCRATCH,
215
+ QLA83XX_CRB_DEV_PART_INFO1,
216
+ QLA83XX_CRB_IDC_VER_MAJOR,
217
+ QLA83XX_FW_VER_MAJOR,
218
+ QLA83XX_FW_VER_MINOR,
219
+ QLA83XX_FW_VER_SUB,
220
+ QLA83XX_CMDPEG_STATE,
221
+ QLA83XX_ASIC_TEMP,
222
+};
223
+
191224 static struct scsi_host_template qla4xxx_driver_template = {
192225 .module = THIS_MODULE,
193226 .name = DRIVER_NAME,
....@@ -205,7 +238,6 @@
205238
206239 .this_id = -1,
207240 .cmd_per_lun = 3,
208
- .use_clustering = ENABLE_CLUSTERING,
209241 .sg_tablesize = SG_ALL,
210242
211243 .max_sectors = 0xFFFF,
....@@ -227,6 +259,7 @@
227259 .start_conn = qla4xxx_conn_start,
228260 .create_conn = qla4xxx_conn_create,
229261 .bind_conn = qla4xxx_conn_bind,
262
+ .unbind_conn = iscsi_conn_unbind,
230263 .stop_conn = iscsi_conn_stop,
231264 .destroy_conn = qla4xxx_conn_destroy,
232265 .set_param = iscsi_set_param,
....@@ -940,6 +973,11 @@
940973 memset(&chap_rec, 0, sizeof(chap_rec));
941974
942975 nla_for_each_attr(attr, data, len, rem) {
976
+ if (nla_len(attr) < sizeof(*param_info)) {
977
+ rc = -EINVAL;
978
+ goto exit_set_chap;
979
+ }
980
+
943981 param_info = nla_data(attr);
944982
945983 switch (param_info->param) {
....@@ -967,7 +1005,7 @@
9671005 "%s: No such sysfs attribute\n", __func__);
9681006 rc = -ENOSYS;
9691007 goto exit_set_chap;
970
- };
1008
+ }
9711009 }
9721010
9731011 if (chap_rec.chap_type == CHAP_TYPE_IN)
....@@ -1846,12 +1884,10 @@
18461884 static enum blk_eh_timer_return qla4xxx_eh_cmd_timed_out(struct scsi_cmnd *sc)
18471885 {
18481886 struct iscsi_cls_session *session;
1849
- struct iscsi_session *sess;
18501887 unsigned long flags;
18511888 enum blk_eh_timer_return ret = BLK_EH_DONE;
18521889
18531890 session = starget_to_session(scsi_target(sc->device));
1854
- sess = session->dd_data;
18551891
18561892 spin_lock_irqsave(&session->lock, flags);
18571893 if (session->state == ISCSI_SESSION_FAILED)
....@@ -2705,9 +2741,9 @@
27052741 uint32_t rem = len;
27062742 struct nlattr *attr;
27072743
2708
- init_fw_cb = dma_zalloc_coherent(&ha->pdev->dev,
2709
- sizeof(struct addr_ctrl_blk),
2710
- &init_fw_cb_dma, GFP_KERNEL);
2744
+ init_fw_cb = dma_alloc_coherent(&ha->pdev->dev,
2745
+ sizeof(struct addr_ctrl_blk),
2746
+ &init_fw_cb_dma, GFP_KERNEL);
27112747 if (!init_fw_cb) {
27122748 ql4_printk(KERN_ERR, ha, "%s: Unable to alloc init_cb\n",
27132749 __func__);
....@@ -2724,6 +2760,11 @@
27242760 }
27252761
27262762 nla_for_each_attr(attr, data, len, rem) {
2763
+ if (nla_len(attr) < sizeof(*iface_param)) {
2764
+ rval = -EINVAL;
2765
+ goto exit_init_fw_cb;
2766
+ }
2767
+
27272768 iface_param = nla_data(attr);
27282769
27292770 if (iface_param->param_type == ISCSI_NET_PARAM) {
....@@ -2876,7 +2917,7 @@
28762917 chap_tbl.secret_len);
28772918 }
28782919 }
2879
- /* allow fall-through */
2920
+ fallthrough;
28802921 default:
28812922 return iscsi_session_get_param(cls_sess, param, buf);
28822923 }
....@@ -3060,7 +3101,6 @@
30603101 struct ddb_entry *ddb_entry;
30613102 uint16_t ddb_index;
30623103 struct iscsi_session *sess;
3063
- struct sockaddr *dst_addr;
30643104 int ret;
30653105
30663106 if (!ep) {
....@@ -3069,7 +3109,6 @@
30693109 }
30703110
30713111 qla_ep = ep->dd_data;
3072
- dst_addr = (struct sockaddr *)&qla_ep->dst_addr;
30733112 ha = to_qla_host(qla_ep->host);
30743113 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: host: %ld\n", __func__,
30753114 ha->host_no));
....@@ -3209,6 +3248,7 @@
32093248 conn = cls_conn->dd_data;
32103249 qla_conn = conn->dd_data;
32113250 qla_conn->qla_ep = ep->dd_data;
3251
+ iscsi_put_endpoint(ep);
32123252 return 0;
32133253 }
32143254
....@@ -3384,7 +3424,7 @@
33843424 if (task->data_count) {
33853425 task_data->data_dma = dma_map_single(&ha->pdev->dev, task->data,
33863426 task->data_count,
3387
- PCI_DMA_TODEVICE);
3427
+ DMA_TO_DEVICE);
33883428 }
33893429
33903430 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
....@@ -3439,7 +3479,7 @@
34393479
34403480 if (task->data_count) {
34413481 dma_unmap_single(&ha->pdev->dev, task_data->data_dma,
3442
- task->data_count, PCI_DMA_TODEVICE);
3482
+ task->data_count, DMA_TO_DEVICE);
34433483 }
34443484
34453485 DEBUG2(ql4_printk(KERN_INFO, ha, "%s: MaxRecvLen %u, iscsi hrd %d\n",
....@@ -4162,20 +4202,16 @@
41624202 ha->fw_dump_size = 0;
41634203
41644204 /* Free srb pool. */
4165
- if (ha->srb_mempool)
4166
- mempool_destroy(ha->srb_mempool);
4167
-
4205
+ mempool_destroy(ha->srb_mempool);
41684206 ha->srb_mempool = NULL;
41694207
4170
- if (ha->chap_dma_pool)
4171
- dma_pool_destroy(ha->chap_dma_pool);
4208
+ dma_pool_destroy(ha->chap_dma_pool);
41724209
41734210 if (ha->chap_list)
41744211 vfree(ha->chap_list);
41754212 ha->chap_list = NULL;
41764213
4177
- if (ha->fw_ddb_dma_pool)
4178
- dma_pool_destroy(ha->fw_ddb_dma_pool);
4214
+ dma_pool_destroy(ha->fw_ddb_dma_pool);
41794215
41804216 /* release io space registers */
41814217 if (is_qla8022(ha)) {
....@@ -4213,8 +4249,8 @@
42134249 sizeof(struct shadow_regs) +
42144250 MEM_ALIGN_VALUE +
42154251 (PAGE_SIZE - 1)) & ~(PAGE_SIZE - 1);
4216
- ha->queues = dma_zalloc_coherent(&ha->pdev->dev, ha->queues_len,
4217
- &ha->queues_dma, GFP_KERNEL);
4252
+ ha->queues = dma_alloc_coherent(&ha->pdev->dev, ha->queues_len,
4253
+ &ha->queues_dma, GFP_KERNEL);
42184254 if (ha->queues == NULL) {
42194255 ql4_printk(KERN_WARNING, ha,
42204256 "Memory Allocation failed - queues.\n");
....@@ -4520,7 +4556,7 @@
45204556
45214557 /**
45224558 * qla4xxx_timer - checks every second for work to do.
4523
- * @ha: Pointer to host adapter structure.
4559
+ * @t: Context to obtain pointer to host adapter structure.
45244560 **/
45254561 static void qla4xxx_timer(struct timer_list *t)
45264562 {
....@@ -5274,7 +5310,7 @@
52745310
52755311 /**
52765312 * qla4xxx_do_dpc - dpc routine
5277
- * @data: in our case pointer to adapter structure
5313
+ * @work: Context to obtain pointer to host adapter structure.
52785314 *
52795315 * This routine is a task that is schedule by the interrupt handler
52805316 * to perform the background processing for interrupts. We put it
....@@ -5497,7 +5533,7 @@
54975533 int qla4_8xxx_iospace_config(struct scsi_qla_host *ha)
54985534 {
54995535 int status = 0;
5500
- unsigned long mem_base, mem_len, db_base, db_len;
5536
+ unsigned long mem_base, mem_len;
55015537 struct pci_dev *pdev = ha->pdev;
55025538
55035539 status = pci_request_regions(pdev, DRIVER_NAME);
....@@ -5540,9 +5576,6 @@
55405576 ha->qla4_83xx_reg = (struct device_reg_83xx __iomem *)
55415577 ((uint8_t *)ha->nx_pcibase);
55425578 }
5543
-
5544
- db_base = pci_resource_start(pdev, 4); /* doorbell is on bar 4 */
5545
- db_len = pci_resource_len(pdev, 4);
55465579
55475580 return 0;
55485581 iospace_error_exit:
....@@ -6254,14 +6287,12 @@
62546287 static void qla4xxx_get_param_ddb(struct ddb_entry *ddb_entry,
62556288 struct ql4_tuple_ddb *tddb)
62566289 {
6257
- struct scsi_qla_host *ha;
62586290 struct iscsi_cls_session *cls_sess;
62596291 struct iscsi_cls_conn *cls_conn;
62606292 struct iscsi_session *sess;
62616293 struct iscsi_conn *conn;
62626294
62636295 DEBUG2(printk(KERN_INFO "Func: %s\n", __func__));
6264
- ha = ddb_entry->ha;
62656296 cls_sess = ddb_entry->sess;
62666297 sess = cls_sess->dd_data;
62676298 cls_conn = ddb_entry->conn;
....@@ -8098,6 +8129,11 @@
80988129
80998130 memset((void *)&chap_tbl, 0, sizeof(chap_tbl));
81008131 nla_for_each_attr(attr, data, len, rem) {
8132
+ if (nla_len(attr) < sizeof(*fnode_param)) {
8133
+ rc = -EINVAL;
8134
+ goto exit_set_param;
8135
+ }
8136
+
81018137 fnode_param = nla_data(attr);
81028138
81038139 switch (fnode_param->param) {
....@@ -8596,7 +8632,7 @@
85968632 /**
85978633 * qla4xxx_probe_adapter - callback function to probe HBA
85988634 * @pdev: pointer to pci_dev structure
8599
- * @pci_device_id: pointer to pci_device entry
8635
+ * @ent: pointer to pci_device entry
86008636 *
86018637 * This routine will probe for Qlogic 4xxx iSCSI host adapters.
86028638 * It returns zero if successful. It also initializes all data necessary for
....@@ -8982,7 +9018,7 @@
89829018 }
89839019 /**
89849020 * qla4xxx_remove_adapter - callback function to remove adapter.
8985
- * @pci_dev: PCI device pointer
9021
+ * @pdev: PCI device pointer
89869022 **/
89879023 static void qla4xxx_remove_adapter(struct pci_dev *pdev)
89889024 {
....@@ -9023,25 +9059,16 @@
90239059 /**
90249060 * qla4xxx_config_dma_addressing() - Configure OS DMA addressing method.
90259061 * @ha: HA context
9026
- *
9027
- * At exit, the @ha's flags.enable_64bit_addressing set to indicated
9028
- * supported addressing method.
90299062 */
90309063 static void qla4xxx_config_dma_addressing(struct scsi_qla_host *ha)
90319064 {
9032
- int retval;
9033
-
90349065 /* Update our PCI device dma_mask for full 64 bit mask */
9035
- if (pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(64)) == 0) {
9036
- if (pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
9037
- dev_dbg(&ha->pdev->dev,
9038
- "Failed to set 64 bit PCI consistent mask; "
9039
- "using 32 bit.\n");
9040
- retval = pci_set_consistent_dma_mask(ha->pdev,
9041
- DMA_BIT_MASK(32));
9042
- }
9043
- } else
9044
- retval = pci_set_dma_mask(ha->pdev, DMA_BIT_MASK(32));
9066
+ if (dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(64))) {
9067
+ dev_dbg(&ha->pdev->dev,
9068
+ "Failed to set 64 bit PCI consistent mask; "
9069
+ "using 32 bit.\n");
9070
+ dma_set_mask_and_coherent(&ha->pdev->dev, DMA_BIT_MASK(32));
9071
+ }
90459072 }
90469073
90479074 static int qla4xxx_slave_alloc(struct scsi_device *sdev)
....@@ -9158,8 +9185,8 @@
91589185 /**
91599186 * qla4xxx_eh_wait_for_commands - wait for active cmds to finish.
91609187 * @ha: pointer to HBA
9161
- * @t: target id
9162
- * @l: lun id
9188
+ * @stgt: pointer to SCSI target
9189
+ * @sdev: pointer to SCSI device
91639190 *
91649191 * This function waits for all outstanding commands to a lun to complete. It
91659192 * returns 0 if all pending commands are returned and 1 otherwise.
....@@ -9629,6 +9656,7 @@
96299656 * qla4xxx_pci_mmio_enabled() gets called if
96309657 * qla4xxx_pci_error_detected() returns PCI_ERS_RESULT_CAN_RECOVER
96319658 * and read/write to the device still works.
9659
+ * @pdev: PCI device pointer
96329660 **/
96339661 static pci_ers_result_t
96349662 qla4xxx_pci_mmio_enabled(struct pci_dev *pdev)
....@@ -9827,7 +9855,6 @@
98279855 __func__);
98289856 }
98299857
9830
- pci_cleanup_aer_uncorrect_error_status(pdev);
98319858 clear_bit(AF_EEH_BUSY, &ha->flags);
98329859 }
98339860