Skip to content

Commit e3e7d3e

Browse files
Maggie ZhangJames Bottomley
authored andcommitted
[SCSI] bfa: scatter gather processing change
Modified scatter gather processing to use the kernel provided scsi_for_each_sg() macro. 1) Instead of allocating and setting up sgpg in bfa_ioim_sge_setup(), we only do allocation. As a result, we remove bfa_ioim_sgpg_setup() and rename bfa_ioim_sge_setup() to bfa_ioim_sgpg_alloc(). 2) bfa_ioim_send_ioreq() call scsi_for_each_sg() to handle both inline and sgpg setup. Signed-off-by: Maggie Zhang <xmzhang@brocade.com> Signed-off-by: Jing Huang <huangj@brocade.com> Signed-off-by: James Bottomley <James.Bottomley@suse.de>
1 parent b77ee1f commit e3e7d3e

1 file changed

Lines changed: 59 additions & 81 deletions

File tree

‎drivers/scsi/bfa/bfa_fcpim.c‎

Lines changed: 59 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ static void bfa_itnim_sm_deleting_qfull(struct bfa_itnim_s *itnim,
218218
* forward declaration for BFA IOIM functions
219219
*/
220220
static bfa_boolean_t bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim);
221-
static bfa_boolean_t bfa_ioim_sge_setup(struct bfa_ioim_s *ioim);
222-
static void bfa_ioim_sgpg_setup(struct bfa_ioim_s *ioim);
221+
static bfa_boolean_t bfa_ioim_sgpg_alloc(struct bfa_ioim_s *ioim);
223222
static bfa_boolean_t bfa_ioim_send_abort(struct bfa_ioim_s *ioim);
224223
static void bfa_ioim_notify_cleanup(struct bfa_ioim_s *ioim);
225224
static void __bfa_cb_ioim_good_comp(void *cbarg, bfa_boolean_t complete);
@@ -1621,7 +1620,7 @@ bfa_ioim_sm_uninit(struct bfa_ioim_s *ioim, enum bfa_ioim_event event)
16211620
}
16221621

16231622
if (ioim->nsges > BFI_SGE_INLINE) {
1624-
if (!bfa_ioim_sge_setup(ioim)) {
1623+
if (!bfa_ioim_sgpg_alloc(ioim)) {
16251624
bfa_sm_set_state(ioim, bfa_ioim_sm_sgalloc);
16261625
return;
16271626
}
@@ -2304,7 +2303,7 @@ bfa_ioim_sgpg_alloced(void *cbarg)
23042303

23052304
ioim->nsgpgs = BFA_SGPG_NPAGE(ioim->nsges);
23062305
list_splice_tail_init(&ioim->iosp->sgpg_wqe.sgpg_q, &ioim->sgpg_q);
2307-
bfa_ioim_sgpg_setup(ioim);
2306+
ioim->sgpg = bfa_q_first(&ioim->sgpg_q);
23082307
bfa_sm_send_event(ioim, BFA_IOIM_SM_SGALLOCED);
23092308
}
23102309

@@ -2317,12 +2316,14 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
23172316
struct bfa_itnim_s *itnim = ioim->itnim;
23182317
struct bfi_ioim_req_s *m;
23192318
static struct fcp_cmnd_s cmnd_z0 = { 0 };
2320-
struct bfi_sge_s *sge;
2319+
struct bfi_sge_s *sge, *sgpge;
23212320
u32 pgdlen = 0;
23222321
u32 fcp_dl;
23232322
u64 addr;
23242323
struct scatterlist *sg;
2324+
struct bfa_sgpg_s *sgpg;
23252325
struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio;
2326+
u32 i, sge_id, pgcumsz;
23262327

23272328
/*
23282329
* check for room in queue to send request now
@@ -2342,20 +2343,59 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
23422343
m->rport_hdl = ioim->itnim->rport->fw_handle;
23432344
m->io_timeout = bfa_cb_ioim_get_timeout(ioim->dio);
23442345

2345-
/*
2346-
* build inline IO SG element here
2347-
*/
23482346
sge = &m->sges[0];
2349-
if (ioim->nsges) {
2350-
sg = (struct scatterlist *)scsi_sglist(cmnd);
2351-
addr = bfa_os_sgaddr(sg_dma_address(sg));
2352-
sge->sga = *(union bfi_addr_u *) &addr;
2353-
pgdlen = sg_dma_len(sg);
2354-
sge->sg_len = pgdlen;
2355-
sge->flags = (ioim->nsges > BFI_SGE_INLINE) ?
2347+
sgpg = ioim->sgpg;
2348+
sge_id = 0;
2349+
sgpge = NULL;
2350+
pgcumsz = 0;
2351+
scsi_for_each_sg(cmnd, sg, ioim->nsges, i) {
2352+
if (i == 0) {
2353+
/* build inline IO SG element */
2354+
addr = bfa_os_sgaddr(sg_dma_address(sg));
2355+
sge->sga = *(union bfi_addr_u *) &addr;
2356+
pgdlen = sg_dma_len(sg);
2357+
sge->sg_len = pgdlen;
2358+
sge->flags = (ioim->nsges > BFI_SGE_INLINE) ?
23562359
BFI_SGE_DATA_CPL : BFI_SGE_DATA_LAST;
2357-
bfa_sge_to_be(sge);
2358-
sge++;
2360+
bfa_sge_to_be(sge);
2361+
sge++;
2362+
} else {
2363+
if (sge_id == 0)
2364+
sgpge = sgpg->sgpg->sges;
2365+
2366+
addr = bfa_os_sgaddr(sg_dma_address(sg));
2367+
sgpge->sga = *(union bfi_addr_u *) &addr;
2368+
sgpge->sg_len = sg_dma_len(sg);
2369+
pgcumsz += sgpge->sg_len;
2370+
2371+
/* set flags */
2372+
if (i < (ioim->nsges - 1) &&
2373+
sge_id < (BFI_SGPG_DATA_SGES - 1))
2374+
sgpge->flags = BFI_SGE_DATA;
2375+
else if (i < (ioim->nsges - 1))
2376+
sgpge->flags = BFI_SGE_DATA_CPL;
2377+
else
2378+
sgpge->flags = BFI_SGE_DATA_LAST;
2379+
2380+
bfa_sge_to_le(sgpge);
2381+
2382+
sgpge++;
2383+
if (i == (ioim->nsges - 1)) {
2384+
sgpge->flags = BFI_SGE_PGDLEN;
2385+
sgpge->sga.a32.addr_lo = 0;
2386+
sgpge->sga.a32.addr_hi = 0;
2387+
sgpge->sg_len = pgcumsz;
2388+
bfa_sge_to_le(sgpge);
2389+
} else if (++sge_id == BFI_SGPG_DATA_SGES) {
2390+
sgpg = (struct bfa_sgpg_s *) bfa_q_next(sgpg);
2391+
sgpge->flags = BFI_SGE_LINK;
2392+
sgpge->sga = sgpg->sgpg_pa;
2393+
sgpge->sg_len = pgcumsz;
2394+
bfa_sge_to_le(sgpge);
2395+
sge_id = 0;
2396+
pgcumsz = 0;
2397+
}
2398+
}
23592399
}
23602400

23612401
if (ioim->nsges > BFI_SGE_INLINE) {
@@ -2414,7 +2454,7 @@ bfa_ioim_send_ioreq(struct bfa_ioim_s *ioim)
24142454
* at queuing time.
24152455
*/
24162456
static bfa_boolean_t
2417-
bfa_ioim_sge_setup(struct bfa_ioim_s *ioim)
2457+
bfa_ioim_sgpg_alloc(struct bfa_ioim_s *ioim)
24182458
{
24192459
u16 nsgpgs;
24202460

@@ -2434,73 +2474,11 @@ bfa_ioim_sge_setup(struct bfa_ioim_s *ioim)
24342474
}
24352475

24362476
ioim->nsgpgs = nsgpgs;
2437-
bfa_ioim_sgpg_setup(ioim);
2477+
ioim->sgpg = bfa_q_first(&ioim->sgpg_q);
24382478

24392479
return BFA_TRUE;
24402480
}
24412481

2442-
static void
2443-
bfa_ioim_sgpg_setup(struct bfa_ioim_s *ioim)
2444-
{
2445-
int sgeid, nsges, i;
2446-
struct bfi_sge_s *sge;
2447-
struct bfa_sgpg_s *sgpg;
2448-
u32 pgcumsz;
2449-
u64 addr;
2450-
struct scatterlist *sg;
2451-
struct scsi_cmnd *cmnd = (struct scsi_cmnd *) ioim->dio;
2452-
2453-
sgeid = BFI_SGE_INLINE;
2454-
ioim->sgpg = sgpg = bfa_q_first(&ioim->sgpg_q);
2455-
2456-
sg = scsi_sglist(cmnd);
2457-
sg = sg_next(sg);
2458-
2459-
do {
2460-
sge = sgpg->sgpg->sges;
2461-
nsges = ioim->nsges - sgeid;
2462-
if (nsges > BFI_SGPG_DATA_SGES)
2463-
nsges = BFI_SGPG_DATA_SGES;
2464-
2465-
pgcumsz = 0;
2466-
for (i = 0; i < nsges; i++, sge++, sgeid++, sg = sg_next(sg)) {
2467-
addr = bfa_os_sgaddr(sg_dma_address(sg));
2468-
sge->sga = *(union bfi_addr_u *) &addr;
2469-
sge->sg_len = sg_dma_len(sg);
2470-
pgcumsz += sge->sg_len;
2471-
2472-
/*
2473-
* set flags
2474-
*/
2475-
if (i < (nsges - 1))
2476-
sge->flags = BFI_SGE_DATA;
2477-
else if (sgeid < (ioim->nsges - 1))
2478-
sge->flags = BFI_SGE_DATA_CPL;
2479-
else
2480-
sge->flags = BFI_SGE_DATA_LAST;
2481-
2482-
bfa_sge_to_le(sge);
2483-
}
2484-
2485-
sgpg = (struct bfa_sgpg_s *) bfa_q_next(sgpg);
2486-
2487-
/*
2488-
* set the link element of each page
2489-
*/
2490-
if (sgeid == ioim->nsges) {
2491-
sge->flags = BFI_SGE_PGDLEN;
2492-
sge->sga.a32.addr_lo = 0;
2493-
sge->sga.a32.addr_hi = 0;
2494-
} else {
2495-
sge->flags = BFI_SGE_LINK;
2496-
sge->sga = sgpg->sgpg_pa;
2497-
}
2498-
sge->sg_len = pgcumsz;
2499-
2500-
bfa_sge_to_le(sge);
2501-
} while (sgeid < ioim->nsges);
2502-
}
2503-
25042482
/*
25052483
* Send I/O abort request to firmware.
25062484
*/

0 commit comments

Comments
 (0)