forked from ~ljy/RK356X_SDK_RELEASE

hc
2023-12-11 1f93a7dfd1f8d5ff7a5c53246c7534fe2332d6f4
kernel/drivers/scsi/qla2xxx/qla_bsg.c
....@@ -1,8 +1,7 @@
1
- /*
1
+// SPDX-License-Identifier: GPL-2.0-only
2
+/*
23 * QLogic Fibre Channel HBA Driver
34 * Copyright (c) 2003-2014 QLogic Corporation
4
- *
5
- * See LICENSE.qla2xxx for copyright and licensing details.
65 */
76 #include "qla_def.h"
87
....@@ -11,11 +10,17 @@
1110 #include <linux/delay.h>
1211 #include <linux/bsg-lib.h>
1312
14
-/* BSG support for ELS/CT pass through */
15
-void
16
-qla2x00_bsg_job_done(void *ptr, int res)
13
+static void qla2xxx_free_fcport_work(struct work_struct *work)
1714 {
18
- srb_t *sp = ptr;
15
+ struct fc_port *fcport = container_of(work, typeof(*fcport),
16
+ free_work);
17
+
18
+ qla2x00_free_fcport(fcport);
19
+}
20
+
21
+/* BSG support for ELS/CT pass through */
22
+void qla2x00_bsg_job_done(srb_t *sp, int res)
23
+{
1924 struct bsg_job *bsg_job = sp->u.bsg_job;
2025 struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2126
....@@ -26,10 +31,8 @@
2631 bsg_reply->reply_payload_rcv_len);
2732 }
2833
29
-void
30
-qla2x00_bsg_sp_free(void *ptr)
34
+void qla2x00_bsg_sp_free(srb_t *sp)
3135 {
32
- srb_t *sp = ptr;
3336 struct qla_hw_data *ha = sp->vha->hw;
3437 struct bsg_job *bsg_job = sp->u.bsg_job;
3538 struct fc_bsg_request *bsg_request = bsg_job->request;
....@@ -58,8 +61,11 @@
5861
5962 if (sp->type == SRB_CT_CMD ||
6063 sp->type == SRB_FXIOCB_BCMD ||
61
- sp->type == SRB_ELS_CMD_HST)
62
- kfree(sp->fcport);
64
+ sp->type == SRB_ELS_CMD_HST) {
65
+ INIT_WORK(&sp->fcport->free_work, qla2xxx_free_fcport_work);
66
+ queue_work(ha->wq, &sp->fcport->free_work);
67
+ }
68
+
6369 qla2x00_rel_sp(sp);
6470 }
6571
....@@ -85,8 +91,7 @@
8591 return 0;
8692 }
8793
88
- if (bcode[0] != 'H' || bcode[1] != 'Q' || bcode[2] != 'O' ||
89
- bcode[3] != 'S') {
94
+ if (memcmp(bcode, "HQOS", 4)) {
9095 /* Invalid FCP priority data header*/
9196 ql_dbg(ql_dbg_user, vha, 0x7052,
9297 "Invalid FCP Priority data header. bcode=0x%x.\n",
....@@ -218,8 +223,7 @@
218223
219224 /* validate fcp priority data */
220225
221
- if (!qla24xx_fcp_prio_cfg_valid(vha,
222
- (struct qla_fcp_prio_cfg *) ha->fcp_prio_cfg, 1)) {
226
+ if (!qla24xx_fcp_prio_cfg_valid(vha, ha->fcp_prio_cfg, 1)) {
223227 bsg_reply->result = (DID_ERROR << 16);
224228 ret = -EINVAL;
225229 /* If buffer was invalidatic int
....@@ -410,8 +414,8 @@
410414 goto done_free_fcport;
411415
412416 done_free_fcport:
413
- if (bsg_request->msgcode == FC_BSG_RPT_ELS)
414
- kfree(fcport);
417
+ if (bsg_request->msgcode != FC_BSG_RPT_ELS)
418
+ qla2x00_free_fcport(fcport);
415419 done:
416420 return rval;
417421 }
....@@ -485,7 +489,7 @@
485489 >> 24;
486490 switch (loop_id) {
487491 case 0xFC:
488
- loop_id = cpu_to_le16(NPH_SNS);
492
+ loop_id = NPH_SNS;
489493 break;
490494 case 0xFA:
491495 loop_id = vha->mgmt_svr_loop_id;
....@@ -551,7 +555,7 @@
551555 return rval;
552556
553557 done_free_fcport:
554
- kfree(fcport);
558
+ qla2x00_free_fcport(fcport);
555559 done_unmap_sg:
556560 dma_unmap_sg(&ha->pdev->dev, bsg_job->request_payload.sg_list,
557561 bsg_job->request_payload.sg_cnt, DMA_TO_DEVICE);
....@@ -686,7 +690,7 @@
686690 * dump and reset the chip.
687691 */
688692 if (ret) {
689
- ha->isp_ops->fw_dump(vha, 0);
693
+ qla2xxx_dump_fw(vha);
690694 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
691695 }
692696 rval = -EINVAL;
....@@ -723,7 +727,7 @@
723727 uint16_t response[MAILBOX_REGISTER_COUNT];
724728 uint16_t config[4], new_config[4];
725729 uint8_t *fw_sts_ptr;
726
- uint8_t *req_data = NULL;
730
+ void *req_data = NULL;
727731 dma_addr_t req_data_dma;
728732 uint32_t req_data_len;
729733 uint8_t *rsp_data = NULL;
....@@ -801,10 +805,11 @@
801805 bsg_request->rqst_data.h_vendor.vendor_cmd[2];
802806
803807 if (atomic_read(&vha->loop_state) == LOOP_READY &&
804
- (ha->current_topology == ISP_CFG_F ||
805
- (le32_to_cpu(*(uint32_t *)req_data) == ELS_OPCODE_BYTE &&
806
- req_data_len == MAX_ELS_FRAME_PAYLOAD)) &&
807
- elreq.options == EXTERNAL_LOOPBACK) {
808
+ ((ha->current_topology == ISP_CFG_F && (elreq.options & 7) >= 2) ||
809
+ ((IS_QLA81XX(ha) || IS_QLA8031(ha) || IS_QLA8044(ha)) &&
810
+ get_unaligned_le32(req_data) == ELS_OPCODE_BYTE &&
811
+ req_data_len == MAX_ELS_FRAME_PAYLOAD &&
812
+ elreq.options == EXTERNAL_LOOPBACK))) {
808813 type = "FC_BSG_HST_VENDOR_ECHO_DIAG";
809814 ql_dbg(ql_dbg_user, vha, 0x701e,
810815 "BSG request type: %s.\n", type);
....@@ -890,7 +895,7 @@
890895 * doesn't work take FCoE dump and then
891896 * reset the chip.
892897 */
893
- ha->isp_ops->fw_dump(vha, 0);
898
+ qla2xxx_dump_fw(vha);
894899 set_bit(ISP_ABORT_NEEDED,
895900 &vha->dpc_flags);
896901 }
....@@ -1049,7 +1054,7 @@
10491054 }
10501055
10511056 flag = bsg_request->rqst_data.h_vendor.vendor_cmd[1];
1052
- fw_ver = le32_to_cpu(*((uint32_t *)((uint32_t *)fw_buf + 2)));
1057
+ fw_ver = get_unaligned_le32((uint32_t *)fw_buf + 2);
10531058
10541059 mn->entry_type = VERIFY_CHIP_IOCB_TYPE;
10551060 mn->entry_count = 1;
....@@ -1062,9 +1067,8 @@
10621067 mn->fw_ver = cpu_to_le32(fw_ver);
10631068 mn->fw_size = cpu_to_le32(data_len);
10641069 mn->fw_seq_size = cpu_to_le32(data_len);
1065
- mn->dseg_address[0] = cpu_to_le32(LSD(fw_dma));
1066
- mn->dseg_address[1] = cpu_to_le32(MSD(fw_dma));
1067
- mn->dseg_length = cpu_to_le32(data_len);
1070
+ put_unaligned_le64(fw_dma, &mn->dsd.address);
1071
+ mn->dsd.length = cpu_to_le32(data_len);
10681072 mn->data_seg_cnt = cpu_to_le16(1);
10691073
10701074 rval = qla2x00_issue_iocb_timeout(vha, mn, mn_dma, 0, 120);
....@@ -1243,9 +1247,8 @@
12431247 if (ql84_mgmt->mgmt.cmd != QLA84_MGMT_CHNG_CONFIG) {
12441248 mn->total_byte_cnt = cpu_to_le32(ql84_mgmt->mgmt.len);
12451249 mn->dseg_count = cpu_to_le16(1);
1246
- mn->dseg_address[0] = cpu_to_le32(LSD(mgmt_dma));
1247
- mn->dseg_address[1] = cpu_to_le32(MSD(mgmt_dma));
1248
- mn->dseg_length = cpu_to_le32(ql84_mgmt->mgmt.len);
1250
+ put_unaligned_le64(mgmt_dma, &mn->dsd.address);
1251
+ mn->dsd.length = cpu_to_le32(ql84_mgmt->mgmt.len);
12491252 }
12501253
12511254 rval = qla2x00_issue_iocb(vha, mn, mn_dma, 0);
....@@ -1359,7 +1362,7 @@
13591362
13601363 if (rval) {
13611364 ql_log(ql_log_warn, vha, 0x704c,
1362
- "iIDMA cmd failed for %8phN -- "
1365
+ "iiDMA cmd failed for %8phN -- "
13631366 "%04x %x %04x %04x.\n", fcport->port_name,
13641367 rval, fcport->fp_speed, mb[0], mb[1]);
13651368 rval = (DID_ERROR << 16);
....@@ -1417,7 +1420,8 @@
14171420 start == (ha->flt_region_fw * 4))
14181421 valid = 1;
14191422 else if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha) ||
1420
- IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha))
1423
+ IS_CNA_CAPABLE(ha) || IS_QLA2031(ha) || IS_QLA27XX(ha) ||
1424
+ IS_QLA28XX(ha))
14211425 valid = 1;
14221426 if (!valid) {
14231427 ql_log(ql_log_warn, vha, 0x7058,
....@@ -1512,10 +1516,15 @@
15121516 bsg_job->request_payload.sg_cnt, ha->optrom_buffer,
15131517 ha->optrom_region_size);
15141518
1515
- ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
1519
+ rval = ha->isp_ops->write_optrom(vha, ha->optrom_buffer,
15161520 ha->optrom_region_start, ha->optrom_region_size);
15171521
1518
- bsg_reply->result = DID_OK;
1522
+ if (rval) {
1523
+ bsg_reply->result = -EINVAL;
1524
+ rval = -EINVAL;
1525
+ } else {
1526
+ bsg_reply->result = DID_OK;
1527
+ }
15191528 vfree(ha->optrom_buffer);
15201529 ha->optrom_buffer = NULL;
15211530 ha->optrom_state = QLA_SWAITING;
....@@ -1539,6 +1548,7 @@
15391548 uint32_t count;
15401549 dma_addr_t sfp_dma;
15411550 void *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1551
+
15421552 if (!sfp) {
15431553 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
15441554 EXT_STATUS_NO_MEMORY;
....@@ -1589,6 +1599,7 @@
15891599 struct qla_status_reg *sr = (void *)bsg;
15901600 dma_addr_t sfp_dma;
15911601 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1602
+
15921603 if (!sfp) {
15931604 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
15941605 EXT_STATUS_NO_MEMORY;
....@@ -1639,6 +1650,7 @@
16391650 struct qla_status_reg *sr = (void *)bsg;
16401651 dma_addr_t sfp_dma;
16411652 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1653
+
16421654 if (!sfp) {
16431655 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
16441656 EXT_STATUS_NO_MEMORY;
....@@ -1685,6 +1697,7 @@
16851697 struct qla_i2c_access *i2c = (void *)bsg;
16861698 dma_addr_t sfp_dma;
16871699 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1700
+
16881701 if (!sfp) {
16891702 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
16901703 EXT_STATUS_NO_MEMORY;
....@@ -1730,6 +1743,7 @@
17301743 struct qla_i2c_access *i2c = (void *)bsg;
17311744 dma_addr_t sfp_dma;
17321745 uint8_t *sfp = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL, &sfp_dma);
1746
+
17331747 if (!sfp) {
17341748 bsg_reply->reply_data.vendor_reply.vendor_rsp[0] =
17351749 EXT_STATUS_NO_MEMORY;
....@@ -1965,7 +1979,7 @@
19651979
19661980 /* Dump the vendor information */
19671981 ql_dump_buffer(ql_dbg_user + ql_dbg_verbose , vha, 0x70cf,
1968
- (uint8_t *)piocb_rqst, sizeof(struct qla_mt_iocb_rqst_fx00));
1982
+ piocb_rqst, sizeof(*piocb_rqst));
19691983
19701984 if (!vha->flags.online) {
19711985 ql_log(ql_log_warn, vha, 0x70d0,
....@@ -2027,7 +2041,7 @@
20272041
20282042 /* Initialize all required fields of fcport */
20292043 fcport->vha = vha;
2030
- fcport->loop_id = piocb_rqst->dataword;
2044
+ fcport->loop_id = le32_to_cpu(piocb_rqst->dataword);
20312045
20322046 sp->type = SRB_FXIOCB_BCMD;
20332047 sp->name = "bsg_fx_mgmt";
....@@ -2051,7 +2065,7 @@
20512065 return rval;
20522066
20532067 done_free_fcport:
2054
- kfree(fcport);
2068
+ qla2x00_free_fcport(fcport);
20552069
20562070 done_unmap_rsp_sg:
20572071 if (piocb_rqst->flags & SRB_FXDISC_RESP_DMA_VALID)
....@@ -2161,7 +2175,7 @@
21612175 struct qla_hw_data *ha = vha->hw;
21622176 struct qla_flash_update_caps cap;
21632177
2164
- if (!(IS_QLA27XX(ha)))
2178
+ if (!(IS_QLA27XX(ha)) && !IS_QLA28XX(ha))
21652179 return -EPERM;
21662180
21672181 memset(&cap, 0, sizeof(cap));
....@@ -2194,7 +2208,7 @@
21942208 uint64_t online_fw_attr = 0;
21952209 struct qla_flash_update_caps cap;
21962210
2197
- if (!(IS_QLA27XX(ha)))
2211
+ if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
21982212 return -EPERM;
21992213
22002214 memset(&cap, 0, sizeof(cap));
....@@ -2242,7 +2256,7 @@
22422256 uint8_t domain, area, al_pa, state;
22432257 int rval;
22442258
2245
- if (!(IS_QLA27XX(ha)))
2259
+ if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
22462260 return -EPERM;
22472261
22482262 memset(&bbcr, 0, sizeof(bbcr));
....@@ -2316,8 +2330,8 @@
23162330 if (!IS_FWI2_CAPABLE(ha))
23172331 return -EPERM;
23182332
2319
- stats = dma_zalloc_coherent(&ha->pdev->dev, sizeof(*stats),
2320
- &stats_dma, GFP_KERNEL);
2333
+ stats = dma_alloc_coherent(&ha->pdev->dev, sizeof(*stats), &stats_dma,
2334
+ GFP_KERNEL);
23212335 if (!stats) {
23222336 ql_log(ql_log_warn, vha, 0x70e2,
23232337 "Failed to allocate memory for stats.\n");
....@@ -2327,8 +2341,8 @@
23272341 rval = qla24xx_get_isp_stats(base_vha, stats, stats_dma, options);
23282342
23292343 if (rval == QLA_SUCCESS) {
2330
- ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e3,
2331
- (uint8_t *)stats, sizeof(*stats));
2344
+ ql_dump_buffer(ql_dbg_user + ql_dbg_verbose, vha, 0x70e5,
2345
+ stats, sizeof(*stats));
23322346 sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
23332347 bsg_job->reply_payload.sg_cnt, stats, sizeof(*stats));
23342348 }
....@@ -2357,7 +2371,8 @@
23572371 int rval;
23582372 struct qla_dport_diag *dd;
23592373
2360
- if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw))
2374
+ if (!IS_QLA83XX(vha->hw) && !IS_QLA27XX(vha->hw) &&
2375
+ !IS_QLA28XX(vha->hw))
23612376 return -EPERM;
23622377
23632378 dd = kmalloc(sizeof(*dd), GFP_KERNEL);
....@@ -2387,6 +2402,45 @@
23872402 bsg_reply->reply_payload_rcv_len);
23882403
23892404 kfree(dd);
2405
+
2406
+ return 0;
2407
+}
2408
+
2409
+static int
2410
+qla2x00_get_flash_image_status(struct bsg_job *bsg_job)
2411
+{
2412
+ scsi_qla_host_t *vha = shost_priv(fc_bsg_to_shost(bsg_job));
2413
+ struct fc_bsg_reply *bsg_reply = bsg_job->reply;
2414
+ struct qla_hw_data *ha = vha->hw;
2415
+ struct qla_active_regions regions = { };
2416
+ struct active_regions active_regions = { };
2417
+
2418
+ qla27xx_get_active_image(vha, &active_regions);
2419
+ regions.global_image = active_regions.global;
2420
+
2421
+ if (IS_QLA28XX(ha)) {
2422
+ qla28xx_get_aux_images(vha, &active_regions);
2423
+ regions.board_config = active_regions.aux.board_config;
2424
+ regions.vpd_nvram = active_regions.aux.vpd_nvram;
2425
+ regions.npiv_config_0_1 = active_regions.aux.npiv_config_0_1;
2426
+ regions.npiv_config_2_3 = active_regions.aux.npiv_config_2_3;
2427
+ }
2428
+
2429
+ ql_dbg(ql_dbg_user, vha, 0x70e1,
2430
+ "%s(%lu): FW=%u BCFG=%u VPDNVR=%u NPIV01=%u NPIV02=%u\n",
2431
+ __func__, vha->host_no, regions.global_image,
2432
+ regions.board_config, regions.vpd_nvram,
2433
+ regions.npiv_config_0_1, regions.npiv_config_2_3);
2434
+
2435
+ sg_copy_from_buffer(bsg_job->reply_payload.sg_list,
2436
+ bsg_job->reply_payload.sg_cnt, &regions, sizeof(regions));
2437
+
2438
+ bsg_reply->reply_data.vendor_reply.vendor_rsp[0] = EXT_STATUS_OK;
2439
+ bsg_reply->reply_payload_rcv_len = sizeof(regions);
2440
+ bsg_reply->result = DID_OK << 16;
2441
+ bsg_job->reply_len = sizeof(struct fc_bsg_reply);
2442
+ bsg_job_done(bsg_job, bsg_reply->result,
2443
+ bsg_reply->reply_payload_rcv_len);
23902444
23912445 return 0;
23922446 }
....@@ -2464,6 +2518,9 @@
24642518 case QL_VND_DPORT_DIAGNOSTICS:
24652519 return qla2x00_do_dport_diagnostics(bsg_job);
24662520
2521
+ case QL_VND_SS_GET_FLASH_IMAGE_STATUS:
2522
+ return qla2x00_get_flash_image_status(bsg_job);
2523
+
24672524 default:
24682525 return -ENOSYS;
24692526 }