Skip to content

Commit 3cf92f4

Browse files
mwilckmartinkpetersen
authored andcommitted
scsi: qla2xxx: cleanup trace buffer initialization
Avoid code duplication between qla2x00_alloc_offload_mem() and qla2x00_alloc_fw_dump() by moving the FCE and EFT buffer allocation and initialization to separate functions. Cleanly track failure and success by making sure that the ha->eft, ha->fce and respective eft_dma, fce_dma members are set if and only if the buffers are properly allocated and initialized. Avoid pointless buffer reallocation. Eliminate some goto statements. Make sure the fce_enabled flag is cleared when the FCE buffer is freed. Fixes: ad0a0b0 ("scsi: qla2xxx: Fix Firmware dump size for Extended login and Exchange Offload") Fixes: a28d9e4 ("scsi: qla2xxx: Add support for multiple fwdump templates/segments") Cc: Joe Carnuccio <joe.carnuccio@cavium.com> Cc: Quinn Tran <qutran@marvell.com> Cc: Himanshu Madhani <hmadhani@marvell.com> Cc: Bart Van Assche <bvanassche@acm.org> Signed-off-by: Martin Wilck <mwilck@suse.com> Tested-by: Himanshu Madhani <hmadhani@marvell.com> Reviewed-by: Himanshu Madhani <hmadhani@marvell.com> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent edbd564 commit 3cf92f4

File tree

2 files changed

+99
-116
lines changed

2 files changed

+99
-116
lines changed

drivers/scsi/qla2xxx/qla_init.c

Lines changed: 98 additions & 116 deletions
Original file line numberDiff line numberDiff line change
@@ -3032,103 +3032,113 @@ qla24xx_chip_diag(scsi_qla_host_t *vha)
30323032
}
30333033

30343034
static void
3035-
qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3035+
qla2x00_init_fce_trace(scsi_qla_host_t *vha)
30363036
{
30373037
int rval;
30383038
dma_addr_t tc_dma;
30393039
void *tc;
30403040
struct qla_hw_data *ha = vha->hw;
30413041

3042-
if (ha->eft) {
3042+
if (!IS_FWI2_CAPABLE(ha))
3043+
return;
3044+
3045+
if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3046+
!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3047+
return;
3048+
3049+
if (ha->fce) {
30433050
ql_dbg(ql_dbg_init, vha, 0x00bd,
3044-
"%s: Offload Mem is already allocated.\n",
3045-
__func__);
3051+
"%s: FCE Mem is already allocated.\n",
3052+
__func__);
30463053
return;
30473054
}
30483055

3049-
if (IS_FWI2_CAPABLE(ha)) {
3050-
/* Allocate memory for Fibre Channel Event Buffer. */
3051-
if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3052-
!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3053-
goto try_eft;
3056+
/* Allocate memory for Fibre Channel Event Buffer. */
3057+
tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3058+
GFP_KERNEL);
3059+
if (!tc) {
3060+
ql_log(ql_log_warn, vha, 0x00be,
3061+
"Unable to allocate (%d KB) for FCE.\n",
3062+
FCE_SIZE / 1024);
3063+
return;
3064+
}
30543065

3055-
if (ha->fce)
3056-
dma_free_coherent(&ha->pdev->dev,
3057-
FCE_SIZE, ha->fce, ha->fce_dma);
3066+
rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3067+
ha->fce_mb, &ha->fce_bufs);
3068+
if (rval) {
3069+
ql_log(ql_log_warn, vha, 0x00bf,
3070+
"Unable to initialize FCE (%d).\n", rval);
3071+
dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3072+
return;
3073+
}
30583074

3059-
/* Allocate memory for Fibre Channel Event Buffer. */
3060-
tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3061-
GFP_KERNEL);
3062-
if (!tc) {
3063-
ql_log(ql_log_warn, vha, 0x00be,
3064-
"Unable to allocate (%d KB) for FCE.\n",
3065-
FCE_SIZE / 1024);
3066-
goto try_eft;
3067-
}
3068-
3069-
rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3070-
ha->fce_mb, &ha->fce_bufs);
3071-
if (rval) {
3072-
ql_log(ql_log_warn, vha, 0x00bf,
3073-
"Unable to initialize FCE (%d).\n", rval);
3074-
dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3075-
tc_dma);
3076-
ha->flags.fce_enabled = 0;
3077-
goto try_eft;
3078-
}
3079-
ql_dbg(ql_dbg_init, vha, 0x00c0,
3080-
"Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3081-
3082-
ha->flags.fce_enabled = 1;
3083-
ha->fce_dma = tc_dma;
3084-
ha->fce = tc;
3085-
3086-
try_eft:
3087-
if (ha->eft)
3088-
dma_free_coherent(&ha->pdev->dev,
3089-
EFT_SIZE, ha->eft, ha->eft_dma);
3075+
ql_dbg(ql_dbg_init, vha, 0x00c0,
3076+
"Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
30903077

3091-
/* Allocate memory for Extended Trace Buffer. */
3092-
tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3093-
GFP_KERNEL);
3094-
if (!tc) {
3095-
ql_log(ql_log_warn, vha, 0x00c1,
3096-
"Unable to allocate (%d KB) for EFT.\n",
3097-
EFT_SIZE / 1024);
3098-
goto eft_err;
3099-
}
3078+
ha->flags.fce_enabled = 1;
3079+
ha->fce_dma = tc_dma;
3080+
ha->fce = tc;
3081+
}
31003082

3101-
rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3102-
if (rval) {
3103-
ql_log(ql_log_warn, vha, 0x00c2,
3104-
"Unable to initialize EFT (%d).\n", rval);
3105-
dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3106-
tc_dma);
3107-
goto eft_err;
3108-
}
3109-
ql_dbg(ql_dbg_init, vha, 0x00c3,
3110-
"Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3083+
static void
3084+
qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3085+
{
3086+
int rval;
3087+
dma_addr_t tc_dma;
3088+
void *tc;
3089+
struct qla_hw_data *ha = vha->hw;
3090+
3091+
if (!IS_FWI2_CAPABLE(ha))
3092+
return;
31113093

3112-
ha->eft_dma = tc_dma;
3113-
ha->eft = tc;
3094+
if (ha->eft) {
3095+
ql_dbg(ql_dbg_init, vha, 0x00bd,
3096+
"%s: EFT Mem is already allocated.\n",
3097+
__func__);
3098+
return;
31143099
}
31153100

3116-
eft_err:
3117-
return;
3101+
/* Allocate memory for Extended Trace Buffer. */
3102+
tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3103+
GFP_KERNEL);
3104+
if (!tc) {
3105+
ql_log(ql_log_warn, vha, 0x00c1,
3106+
"Unable to allocate (%d KB) for EFT.\n",
3107+
EFT_SIZE / 1024);
3108+
return;
3109+
}
3110+
3111+
rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3112+
if (rval) {
3113+
ql_log(ql_log_warn, vha, 0x00c2,
3114+
"Unable to initialize EFT (%d).\n", rval);
3115+
dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3116+
return;
3117+
}
3118+
3119+
ql_dbg(ql_dbg_init, vha, 0x00c3,
3120+
"Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3121+
3122+
ha->eft_dma = tc_dma;
3123+
ha->eft = tc;
3124+
}
3125+
3126+
static void
3127+
qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3128+
{
3129+
qla2x00_init_fce_trace(vha);
3130+
qla2x00_init_eft_trace(vha);
31183131
}
31193132

31203133
void
31213134
qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
31223135
{
3123-
int rval;
31243136
uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
31253137
eft_size, fce_size, mq_size;
31263138
struct qla_hw_data *ha = vha->hw;
31273139
struct req_que *req = ha->req_q_map[0];
31283140
struct rsp_que *rsp = ha->rsp_q_map[0];
31293141
struct qla2xxx_fw_dump *fw_dump;
3130-
dma_addr_t tc_dma;
3131-
void *tc;
31323142

31333143
dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
31343144
req_q_size = rsp_q_size = 0;
@@ -3166,39 +3176,13 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
31663176
}
31673177
if (ha->tgt.atio_ring)
31683178
mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3169-
/* Allocate memory for Fibre Channel Event Buffer. */
3170-
if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3171-
!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3172-
goto try_eft;
31733179

3174-
fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3175-
try_eft:
3180+
qla2x00_init_fce_trace(vha);
3181+
if (ha->fce)
3182+
fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3183+
qla2x00_init_eft_trace(vha);
31763184
if (ha->eft)
3177-
dma_free_coherent(&ha->pdev->dev,
3178-
EFT_SIZE, ha->eft, ha->eft_dma);
3179-
3180-
/* Allocate memory for Extended Trace Buffer. */
3181-
tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3182-
GFP_KERNEL);
3183-
if (!tc) {
3184-
ql_log(ql_log_warn, vha, 0x00c1,
3185-
"Unable to allocate (%d KB) for EFT.\n",
3186-
EFT_SIZE / 1024);
3187-
goto allocate;
3188-
}
3189-
3190-
rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3191-
if (rval) {
3192-
ql_log(ql_log_warn, vha, 0x00c2,
3193-
"Unable to initialize EFT (%d).\n", rval);
3194-
dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3195-
tc_dma);
3196-
}
3197-
ql_dbg(ql_dbg_init, vha, 0x00c3,
3198-
"Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3199-
eft_size = EFT_SIZE;
3200-
ha->eft_dma = tc_dma;
3201-
ha->eft = tc;
3185+
eft_size = EFT_SIZE;
32023186
}
32033187

32043188
if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
@@ -3220,24 +3204,22 @@ qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
32203204
j, fwdt->dump_size);
32213205
dump_size += fwdt->dump_size;
32223206
}
3223-
goto allocate;
3207+
} else {
3208+
req_q_size = req->length * sizeof(request_t);
3209+
rsp_q_size = rsp->length * sizeof(response_t);
3210+
dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3211+
dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3212+
+ eft_size;
3213+
ha->chain_offset = dump_size;
3214+
dump_size += mq_size + fce_size;
3215+
if (ha->exchoffld_buf)
3216+
dump_size += sizeof(struct qla2xxx_offld_chain) +
3217+
ha->exchoffld_size;
3218+
if (ha->exlogin_buf)
3219+
dump_size += sizeof(struct qla2xxx_offld_chain) +
3220+
ha->exlogin_size;
32243221
}
32253222

3226-
req_q_size = req->length * sizeof(request_t);
3227-
rsp_q_size = rsp->length * sizeof(response_t);
3228-
dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3229-
dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3230-
ha->chain_offset = dump_size;
3231-
dump_size += mq_size + fce_size;
3232-
3233-
if (ha->exchoffld_buf)
3234-
dump_size += sizeof(struct qla2xxx_offld_chain) +
3235-
ha->exchoffld_size;
3236-
if (ha->exlogin_buf)
3237-
dump_size += sizeof(struct qla2xxx_offld_chain) +
3238-
ha->exlogin_size;
3239-
3240-
allocate:
32413223
if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
32423224

32433225
ql_dbg(ql_dbg_init, vha, 0x00c5,

drivers/scsi/qla2xxx/qla_os.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4577,6 +4577,7 @@ qla2x00_free_fw_dump(struct qla_hw_data *ha)
45774577

45784578
ha->fce = NULL;
45794579
ha->fce_dma = 0;
4580+
ha->flags.fce_enabled = 0;
45804581
ha->eft = NULL;
45814582
ha->eft_dma = 0;
45824583
ha->fw_dumped = 0;

0 commit comments

Comments
 (0)