Skip to content

Commit 4ca7fe9

Browse files
Yihang Limartinkpetersen
authored andcommitted
scsi: hisi_sas: Use macro instead of magic number
The hisi_sas driver has a large number of magic numbers which makes for unfriendly code reading. Use macro definitions instead. Signed-off-by: Yihang Li <liyihang9@huawei.com> Link: https://lore.kernel.org/r/20250414080845.1220997-2-liyihang9@huawei.com Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 0af2f6b commit 4ca7fe9

File tree

3 files changed

+213
-115
lines changed

3 files changed

+213
-115
lines changed

drivers/scsi/hisi_sas/hisi_sas.h

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,13 @@
4646
#define HISI_SAS_IOST_ITCT_CACHE_DW_SZ 10
4747
#define HISI_SAS_FIFO_DATA_DW_SIZE 32
4848

49+
#define HISI_SAS_REG_MEM_SIZE 4
50+
#define HISI_SAS_MAX_CDB_LEN 16
51+
#define HISI_SAS_BLK_QUEUE_DEPTH 64
52+
53+
#define BYTE_TO_DW 4
54+
#define BYTE_TO_DDW 8
55+
4956
#define HISI_SAS_STATUS_BUF_SZ (sizeof(struct hisi_sas_status_buffer))
5057
#define HISI_SAS_COMMAND_TABLE_SZ (sizeof(union hisi_sas_command_table))
5158

@@ -92,6 +99,8 @@
9299

93100
#define HISI_SAS_WAIT_PHYUP_TIMEOUT (30 * HZ)
94101
#define HISI_SAS_CLEAR_ITCT_TIMEOUT (20 * HZ)
102+
#define HISI_SAS_DELAY_FOR_PHY_DISABLE 100
103+
#define NAME_BUF_SIZE 256
95104

96105
struct hisi_hba;
97106

@@ -167,6 +176,8 @@ struct hisi_sas_debugfs_fifo {
167176
u32 rd_data[HISI_SAS_FIFO_DATA_DW_SIZE];
168177
};
169178

179+
#define FRAME_RCVD_BUF 32
180+
#define SAS_PHY_RESV_SIZE 2
170181
struct hisi_sas_phy {
171182
struct work_struct works[HISI_PHYES_NUM];
172183
struct hisi_hba *hisi_hba;
@@ -178,10 +189,10 @@ struct hisi_sas_phy {
178189
spinlock_t lock;
179190
u64 port_id; /* from hw */
180191
u64 frame_rcvd_size;
181-
u8 frame_rcvd[32];
192+
u8 frame_rcvd[FRAME_RCVD_BUF];
182193
u8 phy_attached;
183194
u8 in_reset;
184-
u8 reserved[2];
195+
u8 reserved[SAS_PHY_RESV_SIZE];
185196
u32 phy_type;
186197
u32 code_violation_err_count;
187198
enum sas_linkrate minimum_linkrate;
@@ -349,6 +360,7 @@ struct hisi_sas_hw {
349360
};
350361

351362
#define HISI_SAS_MAX_DEBUGFS_DUMP (50)
363+
#define HISI_SAS_DEFAULT_DEBUGFS_DUMP 1
352364

353365
struct hisi_sas_debugfs_cq {
354366
struct hisi_sas_cq *cq;
@@ -528,12 +540,13 @@ struct hisi_sas_cmd_hdr {
528540
__le64 dif_prd_table_addr;
529541
};
530542

543+
#define ITCT_RESV_DDW 12
531544
struct hisi_sas_itct {
532545
__le64 qw0;
533546
__le64 sas_addr;
534547
__le64 qw2;
535548
__le64 qw3;
536-
__le64 qw4_15[12];
549+
__le64 qw4_15[ITCT_RESV_DDW];
537550
};
538551

539552
struct hisi_sas_iost {
@@ -543,22 +556,26 @@ struct hisi_sas_iost {
543556
__le64 qw3;
544557
};
545558

559+
#define ERROR_RECORD_BUF_DW 4
546560
struct hisi_sas_err_record {
547-
u32 data[4];
561+
u32 data[ERROR_RECORD_BUF_DW];
548562
};
549563

564+
#define FIS_RESV_DW 3
550565
struct hisi_sas_initial_fis {
551566
struct hisi_sas_err_record err_record;
552567
struct dev_to_host_fis fis;
553-
u32 rsvd[3];
568+
u32 rsvd[FIS_RESV_DW];
554569
};
555570

571+
#define BREAKPOINT_DATA_SIZE 128
556572
struct hisi_sas_breakpoint {
557-
u8 data[128];
573+
u8 data[BREAKPOINT_DATA_SIZE];
558574
};
559575

576+
#define BREAKPOINT_TAG_NUM 32
560577
struct hisi_sas_sata_breakpoint {
561-
struct hisi_sas_breakpoint tag[32];
578+
struct hisi_sas_breakpoint tag[BREAKPOINT_TAG_NUM];
562579
};
563580

564581
struct hisi_sas_sge {
@@ -569,13 +586,15 @@ struct hisi_sas_sge {
569586
__le32 data_off;
570587
};
571588

589+
#define SMP_CMD_TABLE_SIZE 44
572590
struct hisi_sas_command_table_smp {
573-
u8 bytes[44];
591+
u8 bytes[SMP_CMD_TABLE_SIZE];
574592
};
575593

594+
#define DUMMY_BUF_SIZE 12
576595
struct hisi_sas_command_table_stp {
577596
struct host_to_dev_fis command_fis;
578-
u8 dummy[12];
597+
u8 dummy[DUMMY_BUF_SIZE];
579598
u8 atapi_cdb[ATAPI_CDB_LEN];
580599
};
581600

@@ -589,12 +608,13 @@ struct hisi_sas_sge_dif_page {
589608
struct hisi_sas_sge sge[HISI_SAS_SGE_DIF_PAGE_CNT];
590609
} __aligned(16);
591610

611+
#define PROT_BUF_SIZE 7
592612
struct hisi_sas_command_table_ssp {
593613
struct ssp_frame_hdr hdr;
594614
union {
595615
struct {
596616
struct ssp_command_iu task;
597-
u32 prot[7];
617+
u32 prot[PROT_BUF_SIZE];
598618
};
599619
struct ssp_tmf_iu ssp_task;
600620
struct xfer_rdy_iu xfer_rdy;
@@ -608,9 +628,10 @@ union hisi_sas_command_table {
608628
struct hisi_sas_command_table_stp stp;
609629
} __aligned(16);
610630

631+
#define IU_BUF_SIZE 1024
611632
struct hisi_sas_status_buffer {
612633
struct hisi_sas_err_record err;
613-
u8 iu[1024];
634+
u8 iu[IU_BUF_SIZE];
614635
} __aligned(16);
615636

616637
struct hisi_sas_slot_buf_table {

drivers/scsi/hisi_sas/hisi_sas_main.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,16 @@
77
#include "hisi_sas.h"
88
#define DRV_NAME "hisi_sas"
99

10+
#define LINK_RATE_BIT_MASK 2
11+
#define FIS_BUF_SIZE 20
12+
#define WAIT_CMD_COMPLETE_DELAY 100
13+
#define WAIT_CMD_COMPLETE_TMROUT 5000
14+
#define DELAY_FOR_LINK_READY 2000
15+
#define BLK_CNT_OPTIMIZE_MARK 64
16+
#define HZ_TO_MHZ 1000000
17+
#define DELAY_FOR_SOFTRESET_MAX 1000
18+
#define DELAY_FOR_SOFTRESET_MIN 900
19+
1020
#define DEV_IS_GONE(dev) \
1121
((!dev) || (dev->dev_type == SAS_PHY_UNUSED))
1222

@@ -151,7 +161,7 @@ u8 hisi_sas_get_prog_phy_linkrate_mask(enum sas_linkrate max)
151161

152162
max -= SAS_LINK_RATE_1_5_GBPS;
153163
for (i = 0; i <= max; i++)
154-
rate |= 1 << (i * 2);
164+
rate |= 1 << (i * LINK_RATE_BIT_MASK);
155165
return rate;
156166
}
157167
EXPORT_SYMBOL_GPL(hisi_sas_get_prog_phy_linkrate_mask);
@@ -900,7 +910,7 @@ int hisi_sas_sdev_configure(struct scsi_device *sdev, struct queue_limits *lim)
900910
if (ret)
901911
return ret;
902912
if (!dev_is_sata(dev))
903-
sas_change_queue_depth(sdev, 64);
913+
sas_change_queue_depth(sdev, HISI_SAS_BLK_QUEUE_DEPTH);
904914

905915
return 0;
906916
}
@@ -1242,7 +1252,7 @@ static int hisi_sas_phy_set_linkrate(struct hisi_hba *hisi_hba, int phy_no,
12421252
sas_phy->phy->minimum_linkrate = min;
12431253

12441254
hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1245-
msleep(100);
1255+
msleep(HISI_SAS_DELAY_FOR_PHY_DISABLE);
12461256
hisi_hba->hw->phy_set_linkrate(hisi_hba, phy_no, &_r);
12471257
hisi_sas_phy_enable(hisi_hba, phy_no, 1);
12481258

@@ -1272,7 +1282,7 @@ static int hisi_sas_control_phy(struct asd_sas_phy *sas_phy, enum phy_func func,
12721282

12731283
case PHY_FUNC_LINK_RESET:
12741284
hisi_sas_phy_enable(hisi_hba, phy_no, 0);
1275-
msleep(100);
1285+
msleep(HISI_SAS_DELAY_FOR_PHY_DISABLE);
12761286
hisi_sas_phy_enable(hisi_hba, phy_no, 1);
12771287
break;
12781288

@@ -1327,7 +1337,7 @@ static void hisi_sas_fill_ata_reset_cmd(struct ata_device *dev,
13271337

13281338
static int hisi_sas_softreset_ata_disk(struct domain_device *device)
13291339
{
1330-
u8 fis[20] = {0};
1340+
u8 fis[FIS_BUF_SIZE] = {0};
13311341
struct ata_port *ap = device->sata_dev.ap;
13321342
struct ata_link *link;
13331343
int rc = TMF_RESP_FUNC_FAILED;
@@ -1344,7 +1354,7 @@ static int hisi_sas_softreset_ata_disk(struct domain_device *device)
13441354
}
13451355

13461356
if (rc == TMF_RESP_FUNC_COMPLETE) {
1347-
usleep_range(900, 1000);
1357+
usleep_range(DELAY_FOR_SOFTRESET_MIN, DELAY_FOR_SOFTRESET_MAX);
13481358
ata_for_each_link(link, ap, EDGE) {
13491359
int pmp = sata_srst_pmp(link);
13501360

@@ -1474,7 +1484,7 @@ static void hisi_sas_send_ata_reset_each_phy(struct hisi_hba *hisi_hba,
14741484
struct device *dev = hisi_hba->dev;
14751485
int rc = TMF_RESP_FUNC_FAILED;
14761486
struct ata_link *link;
1477-
u8 fis[20] = {0};
1487+
u8 fis[FIS_BUF_SIZE] = {0};
14781488
int i;
14791489

14801490
for (i = 0; i < hisi_hba->n_phy; i++) {
@@ -1541,7 +1551,9 @@ void hisi_sas_controller_reset_prepare(struct hisi_hba *hisi_hba)
15411551
hisi_hba->phy_state = hisi_hba->hw->get_phys_state(hisi_hba);
15421552

15431553
scsi_block_requests(shost);
1544-
hisi_hba->hw->wait_cmds_complete_timeout(hisi_hba, 100, 5000);
1554+
hisi_hba->hw->wait_cmds_complete_timeout(hisi_hba,
1555+
WAIT_CMD_COMPLETE_DELAY,
1556+
WAIT_CMD_COMPLETE_TMROUT);
15451557

15461558
/*
15471559
* hisi_hba->timer is only used for v1/v2 hw, and check hw->sht
@@ -1842,7 +1854,7 @@ static int hisi_sas_debug_I_T_nexus_reset(struct domain_device *device)
18421854
rc = ata_wait_after_reset(link, jiffies + HISI_SAS_WAIT_PHYUP_TIMEOUT,
18431855
smp_ata_check_ready_type);
18441856
} else {
1845-
msleep(2000);
1857+
msleep(DELAY_FOR_LINK_READY);
18461858
}
18471859

18481860
return rc;
@@ -2276,12 +2288,14 @@ int hisi_sas_alloc(struct hisi_hba *hisi_hba)
22762288
goto err_out;
22772289

22782290
/* roundup to avoid overly large block size */
2279-
max_command_entries_ru = roundup(max_command_entries, 64);
2291+
max_command_entries_ru = roundup(max_command_entries,
2292+
BLK_CNT_OPTIMIZE_MARK);
22802293
if (hisi_hba->prot_mask & HISI_SAS_DIX_PROT_MASK)
22812294
sz_slot_buf_ru = sizeof(struct hisi_sas_slot_dif_buf_table);
22822295
else
22832296
sz_slot_buf_ru = sizeof(struct hisi_sas_slot_buf_table);
2284-
sz_slot_buf_ru = roundup(sz_slot_buf_ru, 64);
2297+
2298+
sz_slot_buf_ru = roundup(sz_slot_buf_ru, BLK_CNT_OPTIMIZE_MARK);
22852299
s = max(lcm(max_command_entries_ru, sz_slot_buf_ru), PAGE_SIZE);
22862300
blk_cnt = (max_command_entries_ru * sz_slot_buf_ru) / s;
22872301
slots_per_blk = s / sz_slot_buf_ru;
@@ -2446,7 +2460,8 @@ int hisi_sas_get_fw_info(struct hisi_hba *hisi_hba)
24462460
if (IS_ERR(refclk))
24472461
dev_dbg(dev, "no ref clk property\n");
24482462
else
2449-
hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) / 1000000;
2463+
hisi_hba->refclk_frequency_mhz = clk_get_rate(refclk) /
2464+
HZ_TO_MHZ;
24502465

24512466
if (device_property_read_u32(dev, "phy-count", &hisi_hba->n_phy)) {
24522467
dev_err(dev, "could not get property phy-count\n");
@@ -2568,7 +2583,7 @@ int hisi_sas_probe(struct platform_device *pdev,
25682583
shost->max_id = HISI_SAS_MAX_DEVICES;
25692584
shost->max_lun = ~0;
25702585
shost->max_channel = 1;
2571-
shost->max_cmd_len = 16;
2586+
shost->max_cmd_len = HISI_SAS_MAX_CDB_LEN;
25722587
if (hisi_hba->hw->slot_index_alloc) {
25732588
shost->can_queue = HISI_SAS_MAX_COMMANDS;
25742589
shost->cmd_per_lun = HISI_SAS_MAX_COMMANDS;

0 commit comments

Comments
 (0)