diff options
author | Krishna Gudipati <kgudipat@brocade.com> | 2011-06-24 23:24:29 -0400 |
---|---|---|
committer | James Bottomley <JBottomley@Parallels.com> | 2011-06-29 18:11:09 -0400 |
commit | 4507025d01149aea8705e43508d0ef11e7010cfd (patch) | |
tree | 937fefad76c8534bd42e0d1e46659db61ea57288 /drivers/scsi/bfa/bfa_svc.c | |
parent | 3fd459804ff8e002db2671900debd0fc6dc6c443 (diff) |
[SCSI] bfa: DMA memory allocation enhancement.
- Modified the design such that each BFA sub-module will provide
the amount of DMA and KVA memory needed by it and queues the
same request to the global dma and kva info queues.
- During the memory allocation we iterate over this queue to allocate
the dma and kva memory requested by sub-modules.
- The change is needed to avoid requesting the aggregate amount of memory
needed by all the BFA sub-modules as one contiguous chunk.
Signed-off-by: Krishna Gudipati <kgudipat@brocade.com>
Signed-off-by: James Bottomley <JBottomley@Parallels.com>
Diffstat (limited to 'drivers/scsi/bfa/bfa_svc.c')
-rw-r--r-- | drivers/scsi/bfa/bfa_svc.c | 372 |
1 files changed, 188 insertions, 184 deletions
diff --git a/drivers/scsi/bfa/bfa_svc.c b/drivers/scsi/bfa/bfa_svc.c index cfc0b09465ec..4dcf9b9a34d0 100644 --- a/drivers/scsi/bfa/bfa_svc.c +++ b/drivers/scsi/bfa/bfa_svc.c | |||
@@ -113,11 +113,10 @@ static void bfa_fcxp_queue(struct bfa_fcxp_s *fcxp, | |||
113 | /* | 113 | /* |
114 | * forward declarations for LPS functions | 114 | * forward declarations for LPS functions |
115 | */ | 115 | */ |
116 | static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, | 116 | static void bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, |
117 | u32 *dm_len); | 117 | struct bfa_meminfo_s *minfo, struct bfa_s *bfa); |
118 | static void bfa_lps_attach(struct bfa_s *bfa, void *bfad, | 118 | static void bfa_lps_attach(struct bfa_s *bfa, void *bfad, |
119 | struct bfa_iocfc_cfg_s *cfg, | 119 | struct bfa_iocfc_cfg_s *cfg, |
120 | struct bfa_meminfo_s *meminfo, | ||
121 | struct bfa_pcidev_s *pcidev); | 120 | struct bfa_pcidev_s *pcidev); |
122 | static void bfa_lps_detach(struct bfa_s *bfa); | 121 | static void bfa_lps_detach(struct bfa_s *bfa); |
123 | static void bfa_lps_start(struct bfa_s *bfa); | 122 | static void bfa_lps_start(struct bfa_s *bfa); |
@@ -431,47 +430,12 @@ bfa_plog_fchdr_and_pl(struct bfa_plog_s *plog, enum bfa_plog_mid mid, | |||
431 | */ | 430 | */ |
432 | 431 | ||
433 | static void | 432 | static void |
434 | claim_fcxp_req_rsp_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi) | 433 | claim_fcxps_mem(struct bfa_fcxp_mod_s *mod) |
435 | { | ||
436 | u8 *dm_kva = NULL; | ||
437 | u64 dm_pa; | ||
438 | u32 buf_pool_sz; | ||
439 | |||
440 | dm_kva = bfa_meminfo_dma_virt(mi); | ||
441 | dm_pa = bfa_meminfo_dma_phys(mi); | ||
442 | |||
443 | buf_pool_sz = mod->req_pld_sz * mod->num_fcxps; | ||
444 | |||
445 | /* | ||
446 | * Initialize the fcxp req payload list | ||
447 | */ | ||
448 | mod->req_pld_list_kva = dm_kva; | ||
449 | mod->req_pld_list_pa = dm_pa; | ||
450 | dm_kva += buf_pool_sz; | ||
451 | dm_pa += buf_pool_sz; | ||
452 | memset(mod->req_pld_list_kva, 0, buf_pool_sz); | ||
453 | |||
454 | /* | ||
455 | * Initialize the fcxp rsp payload list | ||
456 | */ | ||
457 | buf_pool_sz = mod->rsp_pld_sz * mod->num_fcxps; | ||
458 | mod->rsp_pld_list_kva = dm_kva; | ||
459 | mod->rsp_pld_list_pa = dm_pa; | ||
460 | dm_kva += buf_pool_sz; | ||
461 | dm_pa += buf_pool_sz; | ||
462 | memset(mod->rsp_pld_list_kva, 0, buf_pool_sz); | ||
463 | |||
464 | bfa_meminfo_dma_virt(mi) = dm_kva; | ||
465 | bfa_meminfo_dma_phys(mi) = dm_pa; | ||
466 | } | ||
467 | |||
468 | static void | ||
469 | claim_fcxps_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi) | ||
470 | { | 434 | { |
471 | u16 i; | 435 | u16 i; |
472 | struct bfa_fcxp_s *fcxp; | 436 | struct bfa_fcxp_s *fcxp; |
473 | 437 | ||
474 | fcxp = (struct bfa_fcxp_s *) bfa_meminfo_kva(mi); | 438 | fcxp = (struct bfa_fcxp_s *) bfa_mem_kva_curp(mod); |
475 | memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps); | 439 | memset(fcxp, 0, sizeof(struct bfa_fcxp_s) * mod->num_fcxps); |
476 | 440 | ||
477 | INIT_LIST_HEAD(&mod->fcxp_free_q); | 441 | INIT_LIST_HEAD(&mod->fcxp_free_q); |
@@ -491,40 +455,53 @@ claim_fcxps_mem(struct bfa_fcxp_mod_s *mod, struct bfa_meminfo_s *mi) | |||
491 | fcxp = fcxp + 1; | 455 | fcxp = fcxp + 1; |
492 | } | 456 | } |
493 | 457 | ||
494 | bfa_meminfo_kva(mi) = (void *)fcxp; | 458 | bfa_mem_kva_curp(mod) = (void *)fcxp; |
495 | } | 459 | } |
496 | 460 | ||
497 | static void | 461 | static void |
498 | bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, | 462 | bfa_fcxp_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
499 | u32 *dm_len) | 463 | struct bfa_s *bfa) |
500 | { | 464 | { |
501 | u16 num_fcxp_reqs = cfg->fwcfg.num_fcxp_reqs; | 465 | struct bfa_fcxp_mod_s *fcxp_mod = BFA_FCXP_MOD(bfa); |
466 | struct bfa_mem_kva_s *fcxp_kva = BFA_MEM_FCXP_KVA(bfa); | ||
467 | struct bfa_mem_dma_s *seg_ptr; | ||
468 | u16 nsegs, idx, per_seg_fcxp; | ||
469 | u16 num_fcxps = cfg->fwcfg.num_fcxp_reqs; | ||
470 | u32 per_fcxp_sz; | ||
502 | 471 | ||
503 | if (num_fcxp_reqs == 0) | 472 | if (num_fcxps == 0) |
504 | return; | 473 | return; |
505 | 474 | ||
506 | /* | ||
507 | * Account for req/rsp payload | ||
508 | */ | ||
509 | *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs; | ||
510 | if (cfg->drvcfg.min_cfg) | 475 | if (cfg->drvcfg.min_cfg) |
511 | *dm_len += BFA_FCXP_MAX_IBUF_SZ * num_fcxp_reqs; | 476 | per_fcxp_sz = 2 * BFA_FCXP_MAX_IBUF_SZ; |
512 | else | 477 | else |
513 | *dm_len += BFA_FCXP_MAX_LBUF_SZ * num_fcxp_reqs; | 478 | per_fcxp_sz = BFA_FCXP_MAX_IBUF_SZ + BFA_FCXP_MAX_LBUF_SZ; |
514 | 479 | ||
515 | /* | 480 | /* dma memory */ |
516 | * Account for fcxp structs | 481 | nsegs = BFI_MEM_DMA_NSEGS(num_fcxps, per_fcxp_sz); |
517 | */ | 482 | per_seg_fcxp = BFI_MEM_NREQS_SEG(per_fcxp_sz); |
518 | *ndm_len += sizeof(struct bfa_fcxp_s) * num_fcxp_reqs; | 483 | |
484 | bfa_mem_dma_seg_iter(fcxp_mod, seg_ptr, nsegs, idx) { | ||
485 | if (num_fcxps >= per_seg_fcxp) { | ||
486 | num_fcxps -= per_seg_fcxp; | ||
487 | bfa_mem_dma_setup(minfo, seg_ptr, | ||
488 | per_seg_fcxp * per_fcxp_sz); | ||
489 | } else | ||
490 | bfa_mem_dma_setup(minfo, seg_ptr, | ||
491 | num_fcxps * per_fcxp_sz); | ||
492 | } | ||
493 | |||
494 | /* kva memory */ | ||
495 | bfa_mem_kva_setup(minfo, fcxp_kva, | ||
496 | cfg->fwcfg.num_fcxp_reqs * sizeof(struct bfa_fcxp_s)); | ||
519 | } | 497 | } |
520 | 498 | ||
521 | static void | 499 | static void |
522 | bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | 500 | bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
523 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) | 501 | struct bfa_pcidev_s *pcidev) |
524 | { | 502 | { |
525 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); | 503 | struct bfa_fcxp_mod_s *mod = BFA_FCXP_MOD(bfa); |
526 | 504 | ||
527 | memset(mod, 0, sizeof(struct bfa_fcxp_mod_s)); | ||
528 | mod->bfa = bfa; | 505 | mod->bfa = bfa; |
529 | mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs; | 506 | mod->num_fcxps = cfg->fwcfg.num_fcxp_reqs; |
530 | 507 | ||
@@ -537,8 +514,7 @@ bfa_fcxp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | |||
537 | 514 | ||
538 | INIT_LIST_HEAD(&mod->wait_q); | 515 | INIT_LIST_HEAD(&mod->wait_q); |
539 | 516 | ||
540 | claim_fcxp_req_rsp_mem(mod, meminfo); | 517 | claim_fcxps_mem(mod); |
541 | claim_fcxps_mem(mod, meminfo); | ||
542 | } | 518 | } |
543 | 519 | ||
544 | static void | 520 | static void |
@@ -962,8 +938,8 @@ bfa_fcxp_get_reqbuf(struct bfa_fcxp_s *fcxp) | |||
962 | void *reqbuf; | 938 | void *reqbuf; |
963 | 939 | ||
964 | WARN_ON(fcxp->use_ireqbuf != 1); | 940 | WARN_ON(fcxp->use_ireqbuf != 1); |
965 | reqbuf = ((u8 *)mod->req_pld_list_kva) + | 941 | reqbuf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag, |
966 | fcxp->fcxp_tag * mod->req_pld_sz; | 942 | mod->req_pld_sz + mod->rsp_pld_sz); |
967 | return reqbuf; | 943 | return reqbuf; |
968 | } | 944 | } |
969 | 945 | ||
@@ -986,13 +962,15 @@ void * | |||
986 | bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp) | 962 | bfa_fcxp_get_rspbuf(struct bfa_fcxp_s *fcxp) |
987 | { | 963 | { |
988 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; | 964 | struct bfa_fcxp_mod_s *mod = fcxp->fcxp_mod; |
989 | void *rspbuf; | 965 | void *fcxp_buf; |
990 | 966 | ||
991 | WARN_ON(fcxp->use_irspbuf != 1); | 967 | WARN_ON(fcxp->use_irspbuf != 1); |
992 | 968 | ||
993 | rspbuf = ((u8 *)mod->rsp_pld_list_kva) + | 969 | fcxp_buf = bfa_mem_get_dmabuf_kva(mod, fcxp->fcxp_tag, |
994 | fcxp->fcxp_tag * mod->rsp_pld_sz; | 970 | mod->req_pld_sz + mod->rsp_pld_sz); |
995 | return rspbuf; | 971 | |
972 | /* fcxp_buf = req_buf + rsp_buf :- add req_buf_sz to get to rsp_buf */ | ||
973 | return ((u8 *) fcxp_buf) + mod->req_pld_sz; | ||
996 | } | 974 | } |
997 | 975 | ||
998 | /* | 976 | /* |
@@ -1473,13 +1451,17 @@ bfa_lps_sm_logowait(struct bfa_lps_s *lps, enum bfa_lps_event event) | |||
1473 | * return memory requirement | 1451 | * return memory requirement |
1474 | */ | 1452 | */ |
1475 | static void | 1453 | static void |
1476 | bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, | 1454 | bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
1477 | u32 *dm_len) | 1455 | struct bfa_s *bfa) |
1478 | { | 1456 | { |
1457 | struct bfa_mem_kva_s *lps_kva = BFA_MEM_LPS_KVA(bfa); | ||
1458 | |||
1479 | if (cfg->drvcfg.min_cfg) | 1459 | if (cfg->drvcfg.min_cfg) |
1480 | *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS; | 1460 | bfa_mem_kva_setup(minfo, lps_kva, |
1461 | sizeof(struct bfa_lps_s) * BFA_LPS_MIN_LPORTS); | ||
1481 | else | 1462 | else |
1482 | *ndm_len += sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS; | 1463 | bfa_mem_kva_setup(minfo, lps_kva, |
1464 | sizeof(struct bfa_lps_s) * BFA_LPS_MAX_LPORTS); | ||
1483 | } | 1465 | } |
1484 | 1466 | ||
1485 | /* | 1467 | /* |
@@ -1487,21 +1469,20 @@ bfa_lps_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, | |||
1487 | */ | 1469 | */ |
1488 | static void | 1470 | static void |
1489 | bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | 1471 | bfa_lps_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
1490 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) | 1472 | struct bfa_pcidev_s *pcidev) |
1491 | { | 1473 | { |
1492 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); | 1474 | struct bfa_lps_mod_s *mod = BFA_LPS_MOD(bfa); |
1493 | struct bfa_lps_s *lps; | 1475 | struct bfa_lps_s *lps; |
1494 | int i; | 1476 | int i; |
1495 | 1477 | ||
1496 | memset(mod, 0, sizeof(struct bfa_lps_mod_s)); | ||
1497 | mod->num_lps = BFA_LPS_MAX_LPORTS; | 1478 | mod->num_lps = BFA_LPS_MAX_LPORTS; |
1498 | if (cfg->drvcfg.min_cfg) | 1479 | if (cfg->drvcfg.min_cfg) |
1499 | mod->num_lps = BFA_LPS_MIN_LPORTS; | 1480 | mod->num_lps = BFA_LPS_MIN_LPORTS; |
1500 | else | 1481 | else |
1501 | mod->num_lps = BFA_LPS_MAX_LPORTS; | 1482 | mod->num_lps = BFA_LPS_MAX_LPORTS; |
1502 | mod->lps_arr = lps = (struct bfa_lps_s *) bfa_meminfo_kva(meminfo); | 1483 | mod->lps_arr = lps = (struct bfa_lps_s *) bfa_mem_kva_curp(mod); |
1503 | 1484 | ||
1504 | bfa_meminfo_kva(meminfo) += mod->num_lps * sizeof(struct bfa_lps_s); | 1485 | bfa_mem_kva_curp(mod) += mod->num_lps * sizeof(struct bfa_lps_s); |
1505 | 1486 | ||
1506 | INIT_LIST_HEAD(&mod->lps_free_q); | 1487 | INIT_LIST_HEAD(&mod->lps_free_q); |
1507 | INIT_LIST_HEAD(&mod->lps_active_q); | 1488 | INIT_LIST_HEAD(&mod->lps_active_q); |
@@ -2829,10 +2810,12 @@ bfa_fcport_queue_cb(struct bfa_fcport_ln_s *ln, enum bfa_port_linkstate event) | |||
2829 | BFA_CACHELINE_SZ)) | 2810 | BFA_CACHELINE_SZ)) |
2830 | 2811 | ||
2831 | static void | 2812 | static void |
2832 | bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, | 2813 | bfa_fcport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
2833 | u32 *dm_len) | 2814 | struct bfa_s *bfa) |
2834 | { | 2815 | { |
2835 | *dm_len += FCPORT_STATS_DMA_SZ; | 2816 | struct bfa_mem_dma_s *fcport_dma = BFA_MEM_FCPORT_DMA(bfa); |
2817 | |||
2818 | bfa_mem_dma_setup(minfo, fcport_dma, FCPORT_STATS_DMA_SZ); | ||
2836 | } | 2819 | } |
2837 | 2820 | ||
2838 | static void | 2821 | static void |
@@ -2844,23 +2827,14 @@ bfa_fcport_qresume(void *cbarg) | |||
2844 | } | 2827 | } |
2845 | 2828 | ||
2846 | static void | 2829 | static void |
2847 | bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo) | 2830 | bfa_fcport_mem_claim(struct bfa_fcport_s *fcport) |
2848 | { | 2831 | { |
2849 | u8 *dm_kva; | 2832 | struct bfa_mem_dma_s *fcport_dma = &fcport->fcport_dma; |
2850 | u64 dm_pa; | ||
2851 | 2833 | ||
2852 | dm_kva = bfa_meminfo_dma_virt(meminfo); | 2834 | fcport->stats_kva = bfa_mem_dma_virt(fcport_dma); |
2853 | dm_pa = bfa_meminfo_dma_phys(meminfo); | 2835 | fcport->stats_pa = bfa_mem_dma_phys(fcport_dma); |
2854 | 2836 | fcport->stats = (union bfa_fcport_stats_u *) | |
2855 | fcport->stats_kva = dm_kva; | 2837 | bfa_mem_dma_virt(fcport_dma); |
2856 | fcport->stats_pa = dm_pa; | ||
2857 | fcport->stats = (union bfa_fcport_stats_u *) dm_kva; | ||
2858 | |||
2859 | dm_kva += FCPORT_STATS_DMA_SZ; | ||
2860 | dm_pa += FCPORT_STATS_DMA_SZ; | ||
2861 | |||
2862 | bfa_meminfo_dma_virt(meminfo) = dm_kva; | ||
2863 | bfa_meminfo_dma_phys(meminfo) = dm_pa; | ||
2864 | } | 2838 | } |
2865 | 2839 | ||
2866 | /* | 2840 | /* |
@@ -2868,18 +2842,17 @@ bfa_fcport_mem_claim(struct bfa_fcport_s *fcport, struct bfa_meminfo_s *meminfo) | |||
2868 | */ | 2842 | */ |
2869 | static void | 2843 | static void |
2870 | bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | 2844 | bfa_fcport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
2871 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) | 2845 | struct bfa_pcidev_s *pcidev) |
2872 | { | 2846 | { |
2873 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); | 2847 | struct bfa_fcport_s *fcport = BFA_FCPORT_MOD(bfa); |
2874 | struct bfa_port_cfg_s *port_cfg = &fcport->cfg; | 2848 | struct bfa_port_cfg_s *port_cfg = &fcport->cfg; |
2875 | struct bfa_fcport_ln_s *ln = &fcport->ln; | 2849 | struct bfa_fcport_ln_s *ln = &fcport->ln; |
2876 | struct timeval tv; | 2850 | struct timeval tv; |
2877 | 2851 | ||
2878 | memset(fcport, 0, sizeof(struct bfa_fcport_s)); | ||
2879 | fcport->bfa = bfa; | 2852 | fcport->bfa = bfa; |
2880 | ln->fcport = fcport; | 2853 | ln->fcport = fcport; |
2881 | 2854 | ||
2882 | bfa_fcport_mem_claim(fcport, meminfo); | 2855 | bfa_fcport_mem_claim(fcport); |
2883 | 2856 | ||
2884 | bfa_sm_set_state(fcport, bfa_fcport_sm_uninit); | 2857 | bfa_sm_set_state(fcport, bfa_fcport_sm_uninit); |
2885 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn); | 2858 | bfa_sm_set_state(ln, bfa_fcport_ln_sm_dn); |
@@ -4417,18 +4390,22 @@ bfa_rport_qresume(void *cbarg) | |||
4417 | } | 4390 | } |
4418 | 4391 | ||
4419 | static void | 4392 | static void |
4420 | bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len, | 4393 | bfa_rport_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
4421 | u32 *dm_len) | 4394 | struct bfa_s *bfa) |
4422 | { | 4395 | { |
4396 | struct bfa_mem_kva_s *rport_kva = BFA_MEM_RPORT_KVA(bfa); | ||
4397 | |||
4423 | if (cfg->fwcfg.num_rports < BFA_RPORT_MIN) | 4398 | if (cfg->fwcfg.num_rports < BFA_RPORT_MIN) |
4424 | cfg->fwcfg.num_rports = BFA_RPORT_MIN; | 4399 | cfg->fwcfg.num_rports = BFA_RPORT_MIN; |
4425 | 4400 | ||
4426 | *km_len += cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s); | 4401 | /* kva memory */ |
4402 | bfa_mem_kva_setup(minfo, rport_kva, | ||
4403 | cfg->fwcfg.num_rports * sizeof(struct bfa_rport_s)); | ||
4427 | } | 4404 | } |
4428 | 4405 | ||
4429 | static void | 4406 | static void |
4430 | bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | 4407 | bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
4431 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) | 4408 | struct bfa_pcidev_s *pcidev) |
4432 | { | 4409 | { |
4433 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa); | 4410 | struct bfa_rport_mod_s *mod = BFA_RPORT_MOD(bfa); |
4434 | struct bfa_rport_s *rp; | 4411 | struct bfa_rport_s *rp; |
@@ -4438,7 +4415,7 @@ bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | |||
4438 | INIT_LIST_HEAD(&mod->rp_active_q); | 4415 | INIT_LIST_HEAD(&mod->rp_active_q); |
4439 | INIT_LIST_HEAD(&mod->rp_unused_q); | 4416 | INIT_LIST_HEAD(&mod->rp_unused_q); |
4440 | 4417 | ||
4441 | rp = (struct bfa_rport_s *) bfa_meminfo_kva(meminfo); | 4418 | rp = (struct bfa_rport_s *) bfa_mem_kva_curp(mod); |
4442 | mod->rps_list = rp; | 4419 | mod->rps_list = rp; |
4443 | mod->num_rports = cfg->fwcfg.num_rports; | 4420 | mod->num_rports = cfg->fwcfg.num_rports; |
4444 | 4421 | ||
@@ -4463,7 +4440,7 @@ bfa_rport_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | |||
4463 | /* | 4440 | /* |
4464 | * consume memory | 4441 | * consume memory |
4465 | */ | 4442 | */ |
4466 | bfa_meminfo_kva(meminfo) = (u8 *) rp; | 4443 | bfa_mem_kva_curp(mod) = (u8 *) rp; |
4467 | } | 4444 | } |
4468 | 4445 | ||
4469 | static void | 4446 | static void |
@@ -4723,26 +4700,51 @@ bfa_rport_speed(struct bfa_rport_s *rport, enum bfa_port_speed speed) | |||
4723 | * Compute and return memory needed by FCP(im) module. | 4700 | * Compute and return memory needed by FCP(im) module. |
4724 | */ | 4701 | */ |
4725 | static void | 4702 | static void |
4726 | bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *km_len, | 4703 | bfa_sgpg_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
4727 | u32 *dm_len) | 4704 | struct bfa_s *bfa) |
4728 | { | 4705 | { |
4706 | struct bfa_sgpg_mod_s *sgpg_mod = BFA_SGPG_MOD(bfa); | ||
4707 | struct bfa_mem_kva_s *sgpg_kva = BFA_MEM_SGPG_KVA(bfa); | ||
4708 | struct bfa_mem_dma_s *seg_ptr; | ||
4709 | u16 nsegs, idx, per_seg_sgpg, num_sgpg; | ||
4710 | u32 sgpg_sz = sizeof(struct bfi_sgpg_s); | ||
4711 | |||
4729 | if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN) | 4712 | if (cfg->drvcfg.num_sgpgs < BFA_SGPG_MIN) |
4730 | cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN; | 4713 | cfg->drvcfg.num_sgpgs = BFA_SGPG_MIN; |
4714 | else if (cfg->drvcfg.num_sgpgs > BFA_SGPG_MAX) | ||
4715 | cfg->drvcfg.num_sgpgs = BFA_SGPG_MAX; | ||
4731 | 4716 | ||
4732 | *km_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfa_sgpg_s); | 4717 | num_sgpg = cfg->drvcfg.num_sgpgs; |
4733 | *dm_len += (cfg->drvcfg.num_sgpgs + 1) * sizeof(struct bfi_sgpg_s); | 4718 | |
4734 | } | 4719 | nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz); |
4720 | per_seg_sgpg = BFI_MEM_NREQS_SEG(sgpg_sz); | ||
4721 | |||
4722 | bfa_mem_dma_seg_iter(sgpg_mod, seg_ptr, nsegs, idx) { | ||
4723 | if (num_sgpg >= per_seg_sgpg) { | ||
4724 | num_sgpg -= per_seg_sgpg; | ||
4725 | bfa_mem_dma_setup(minfo, seg_ptr, | ||
4726 | per_seg_sgpg * sgpg_sz); | ||
4727 | } else | ||
4728 | bfa_mem_dma_setup(minfo, seg_ptr, | ||
4729 | num_sgpg * sgpg_sz); | ||
4730 | } | ||
4735 | 4731 | ||
4732 | /* kva memory */ | ||
4733 | bfa_mem_kva_setup(minfo, sgpg_kva, | ||
4734 | cfg->drvcfg.num_sgpgs * sizeof(struct bfa_sgpg_s)); | ||
4735 | } | ||
4736 | 4736 | ||
4737 | static void | 4737 | static void |
4738 | bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | 4738 | bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
4739 | struct bfa_meminfo_s *minfo, struct bfa_pcidev_s *pcidev) | 4739 | struct bfa_pcidev_s *pcidev) |
4740 | { | 4740 | { |
4741 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); | 4741 | struct bfa_sgpg_mod_s *mod = BFA_SGPG_MOD(bfa); |
4742 | int i; | ||
4743 | struct bfa_sgpg_s *hsgpg; | 4742 | struct bfa_sgpg_s *hsgpg; |
4744 | struct bfi_sgpg_s *sgpg; | 4743 | struct bfi_sgpg_s *sgpg; |
4745 | u64 align_len; | 4744 | u64 align_len; |
4745 | struct bfa_mem_dma_s *seg_ptr; | ||
4746 | u32 sgpg_sz = sizeof(struct bfi_sgpg_s); | ||
4747 | u16 i, idx, nsegs, per_seg_sgpg, num_sgpg; | ||
4746 | 4748 | ||
4747 | union { | 4749 | union { |
4748 | u64 pa; | 4750 | u64 pa; |
@@ -4754,39 +4756,45 @@ bfa_sgpg_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | |||
4754 | 4756 | ||
4755 | bfa_trc(bfa, cfg->drvcfg.num_sgpgs); | 4757 | bfa_trc(bfa, cfg->drvcfg.num_sgpgs); |
4756 | 4758 | ||
4757 | mod->num_sgpgs = cfg->drvcfg.num_sgpgs; | 4759 | mod->free_sgpgs = mod->num_sgpgs = cfg->drvcfg.num_sgpgs; |
4758 | mod->sgpg_arr_pa = bfa_meminfo_dma_phys(minfo); | 4760 | |
4759 | align_len = (BFA_SGPG_ROUNDUP(mod->sgpg_arr_pa) - mod->sgpg_arr_pa); | 4761 | num_sgpg = cfg->drvcfg.num_sgpgs; |
4760 | mod->sgpg_arr_pa += align_len; | 4762 | nsegs = BFI_MEM_DMA_NSEGS(num_sgpg, sgpg_sz); |
4761 | mod->hsgpg_arr = (struct bfa_sgpg_s *) (bfa_meminfo_kva(minfo) + | 4763 | |
4762 | align_len); | 4764 | /* dma/kva mem claim */ |
4763 | mod->sgpg_arr = (struct bfi_sgpg_s *) (bfa_meminfo_dma_virt(minfo) + | 4765 | hsgpg = (struct bfa_sgpg_s *) bfa_mem_kva_curp(mod); |
4764 | align_len); | 4766 | |
4765 | 4767 | bfa_mem_dma_seg_iter(mod, seg_ptr, nsegs, idx) { | |
4766 | hsgpg = mod->hsgpg_arr; | 4768 | |
4767 | sgpg = mod->sgpg_arr; | 4769 | if (!bfa_mem_dma_virt(seg_ptr)) |
4768 | sgpg_pa.pa = mod->sgpg_arr_pa; | 4770 | break; |
4769 | mod->free_sgpgs = mod->num_sgpgs; | 4771 | |
4770 | 4772 | align_len = BFA_SGPG_ROUNDUP(bfa_mem_dma_phys(seg_ptr)) - | |
4771 | WARN_ON(sgpg_pa.pa & (sizeof(struct bfi_sgpg_s) - 1)); | 4773 | bfa_mem_dma_phys(seg_ptr); |
4772 | 4774 | ||
4773 | for (i = 0; i < mod->num_sgpgs; i++) { | 4775 | sgpg = (struct bfi_sgpg_s *) |
4774 | memset(hsgpg, 0, sizeof(*hsgpg)); | 4776 | (((u8 *) bfa_mem_dma_virt(seg_ptr)) + align_len); |
4775 | memset(sgpg, 0, sizeof(*sgpg)); | 4777 | sgpg_pa.pa = bfa_mem_dma_phys(seg_ptr) + align_len; |
4776 | 4778 | WARN_ON(sgpg_pa.pa & (sgpg_sz - 1)); | |
4777 | hsgpg->sgpg = sgpg; | 4779 | |
4778 | sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa); | 4780 | per_seg_sgpg = (seg_ptr->mem_len - (u32)align_len) / sgpg_sz; |
4779 | hsgpg->sgpg_pa = sgpg_pa_tmp.addr; | 4781 | |
4780 | list_add_tail(&hsgpg->qe, &mod->sgpg_q); | 4782 | for (i = 0; num_sgpg > 0 && i < per_seg_sgpg; i++, num_sgpg--) { |
4781 | 4783 | memset(hsgpg, 0, sizeof(*hsgpg)); | |
4782 | hsgpg++; | 4784 | memset(sgpg, 0, sizeof(*sgpg)); |
4783 | sgpg++; | 4785 | |
4784 | sgpg_pa.pa += sizeof(struct bfi_sgpg_s); | 4786 | hsgpg->sgpg = sgpg; |
4787 | sgpg_pa_tmp.pa = bfa_sgaddr_le(sgpg_pa.pa); | ||
4788 | hsgpg->sgpg_pa = sgpg_pa_tmp.addr; | ||
4789 | list_add_tail(&hsgpg->qe, &mod->sgpg_q); | ||
4790 | |||
4791 | sgpg++; | ||
4792 | hsgpg++; | ||
4793 | sgpg_pa.pa += sgpg_sz; | ||
4794 | } | ||
4785 | } | 4795 | } |
4786 | 4796 | ||
4787 | bfa_meminfo_kva(minfo) = (u8 *) hsgpg; | 4797 | bfa_mem_kva_curp(mod) = (u8 *) hsgpg; |
4788 | bfa_meminfo_dma_virt(minfo) = (u8 *) sgpg; | ||
4789 | bfa_meminfo_dma_phys(minfo) = sgpg_pa.pa; | ||
4790 | } | 4798 | } |
4791 | 4799 | ||
4792 | static void | 4800 | static void |
@@ -4928,29 +4936,13 @@ __bfa_cb_uf_recv(void *cbarg, bfa_boolean_t complete) | |||
4928 | } | 4936 | } |
4929 | 4937 | ||
4930 | static void | 4938 | static void |
4931 | claim_uf_pbs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | 4939 | claim_uf_post_msgs(struct bfa_uf_mod_s *ufm) |
4932 | { | ||
4933 | u32 uf_pb_tot_sz; | ||
4934 | |||
4935 | ufm->uf_pbs_kva = (struct bfa_uf_buf_s *) bfa_meminfo_dma_virt(mi); | ||
4936 | ufm->uf_pbs_pa = bfa_meminfo_dma_phys(mi); | ||
4937 | uf_pb_tot_sz = BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * ufm->num_ufs), | ||
4938 | BFA_DMA_ALIGN_SZ); | ||
4939 | |||
4940 | bfa_meminfo_dma_virt(mi) += uf_pb_tot_sz; | ||
4941 | bfa_meminfo_dma_phys(mi) += uf_pb_tot_sz; | ||
4942 | |||
4943 | memset((void *)ufm->uf_pbs_kva, 0, uf_pb_tot_sz); | ||
4944 | } | ||
4945 | |||
4946 | static void | ||
4947 | claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | ||
4948 | { | 4940 | { |
4949 | struct bfi_uf_buf_post_s *uf_bp_msg; | 4941 | struct bfi_uf_buf_post_s *uf_bp_msg; |
4950 | u16 i; | 4942 | u16 i; |
4951 | u16 buf_len; | 4943 | u16 buf_len; |
4952 | 4944 | ||
4953 | ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_meminfo_kva(mi); | 4945 | ufm->uf_buf_posts = (struct bfi_uf_buf_post_s *) bfa_mem_kva_curp(ufm); |
4954 | uf_bp_msg = ufm->uf_buf_posts; | 4946 | uf_bp_msg = ufm->uf_buf_posts; |
4955 | 4947 | ||
4956 | for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs; | 4948 | for (i = 0, uf_bp_msg = ufm->uf_buf_posts; i < ufm->num_ufs; |
@@ -4968,11 +4960,11 @@ claim_uf_post_msgs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | |||
4968 | /* | 4960 | /* |
4969 | * advance pointer beyond consumed memory | 4961 | * advance pointer beyond consumed memory |
4970 | */ | 4962 | */ |
4971 | bfa_meminfo_kva(mi) = (u8 *) uf_bp_msg; | 4963 | bfa_mem_kva_curp(ufm) = (u8 *) uf_bp_msg; |
4972 | } | 4964 | } |
4973 | 4965 | ||
4974 | static void | 4966 | static void |
4975 | claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | 4967 | claim_ufs(struct bfa_uf_mod_s *ufm) |
4976 | { | 4968 | { |
4977 | u16 i; | 4969 | u16 i; |
4978 | struct bfa_uf_s *uf; | 4970 | struct bfa_uf_s *uf; |
@@ -4980,7 +4972,7 @@ claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | |||
4980 | /* | 4972 | /* |
4981 | * Claim block of memory for UF list | 4973 | * Claim block of memory for UF list |
4982 | */ | 4974 | */ |
4983 | ufm->uf_list = (struct bfa_uf_s *) bfa_meminfo_kva(mi); | 4975 | ufm->uf_list = (struct bfa_uf_s *) bfa_mem_kva_curp(ufm); |
4984 | 4976 | ||
4985 | /* | 4977 | /* |
4986 | * Initialize UFs and queue it in UF free queue | 4978 | * Initialize UFs and queue it in UF free queue |
@@ -4989,8 +4981,8 @@ claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | |||
4989 | memset(uf, 0, sizeof(struct bfa_uf_s)); | 4981 | memset(uf, 0, sizeof(struct bfa_uf_s)); |
4990 | uf->bfa = ufm->bfa; | 4982 | uf->bfa = ufm->bfa; |
4991 | uf->uf_tag = i; | 4983 | uf->uf_tag = i; |
4992 | uf->pb_len = sizeof(struct bfa_uf_buf_s); | 4984 | uf->pb_len = BFA_PER_UF_DMA_SZ; |
4993 | uf->buf_kva = (void *)&ufm->uf_pbs_kva[i]; | 4985 | uf->buf_kva = bfa_mem_get_dmabuf_kva(ufm, i, BFA_PER_UF_DMA_SZ); |
4994 | uf->buf_pa = ufm_pbs_pa(ufm, i); | 4986 | uf->buf_pa = ufm_pbs_pa(ufm, i); |
4995 | list_add_tail(&uf->qe, &ufm->uf_free_q); | 4987 | list_add_tail(&uf->qe, &ufm->uf_free_q); |
4996 | } | 4988 | } |
@@ -4998,49 +4990,57 @@ claim_ufs(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | |||
4998 | /* | 4990 | /* |
4999 | * advance memory pointer | 4991 | * advance memory pointer |
5000 | */ | 4992 | */ |
5001 | bfa_meminfo_kva(mi) = (u8 *) uf; | 4993 | bfa_mem_kva_curp(ufm) = (u8 *) uf; |
5002 | } | 4994 | } |
5003 | 4995 | ||
5004 | static void | 4996 | static void |
5005 | uf_mem_claim(struct bfa_uf_mod_s *ufm, struct bfa_meminfo_s *mi) | 4997 | uf_mem_claim(struct bfa_uf_mod_s *ufm) |
5006 | { | 4998 | { |
5007 | claim_uf_pbs(ufm, mi); | 4999 | claim_ufs(ufm); |
5008 | claim_ufs(ufm, mi); | 5000 | claim_uf_post_msgs(ufm); |
5009 | claim_uf_post_msgs(ufm, mi); | ||
5010 | } | 5001 | } |
5011 | 5002 | ||
5012 | static void | 5003 | static void |
5013 | bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, u32 *ndm_len, u32 *dm_len) | 5004 | bfa_uf_meminfo(struct bfa_iocfc_cfg_s *cfg, struct bfa_meminfo_s *minfo, |
5005 | struct bfa_s *bfa) | ||
5014 | { | 5006 | { |
5015 | u32 num_ufs = cfg->fwcfg.num_uf_bufs; | 5007 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
5016 | 5008 | struct bfa_mem_kva_s *uf_kva = BFA_MEM_UF_KVA(bfa); | |
5017 | /* | 5009 | u32 num_ufs = cfg->fwcfg.num_uf_bufs; |
5018 | * dma-able memory for UF posted bufs | 5010 | struct bfa_mem_dma_s *seg_ptr; |
5019 | */ | 5011 | u16 nsegs, idx, per_seg_uf = 0; |
5020 | *dm_len += BFA_ROUNDUP((sizeof(struct bfa_uf_buf_s) * num_ufs), | 5012 | |
5021 | BFA_DMA_ALIGN_SZ); | 5013 | nsegs = BFI_MEM_DMA_NSEGS(num_ufs, BFA_PER_UF_DMA_SZ); |
5014 | per_seg_uf = BFI_MEM_NREQS_SEG(BFA_PER_UF_DMA_SZ); | ||
5015 | |||
5016 | bfa_mem_dma_seg_iter(ufm, seg_ptr, nsegs, idx) { | ||
5017 | if (num_ufs >= per_seg_uf) { | ||
5018 | num_ufs -= per_seg_uf; | ||
5019 | bfa_mem_dma_setup(minfo, seg_ptr, | ||
5020 | per_seg_uf * BFA_PER_UF_DMA_SZ); | ||
5021 | } else | ||
5022 | bfa_mem_dma_setup(minfo, seg_ptr, | ||
5023 | num_ufs * BFA_PER_UF_DMA_SZ); | ||
5024 | } | ||
5022 | 5025 | ||
5023 | /* | 5026 | /* kva memory */ |
5024 | * kernel Virtual memory for UFs and UF buf post msg copies | 5027 | bfa_mem_kva_setup(minfo, uf_kva, cfg->fwcfg.num_uf_bufs * |
5025 | */ | 5028 | (sizeof(struct bfa_uf_s) + sizeof(struct bfi_uf_buf_post_s))); |
5026 | *ndm_len += sizeof(struct bfa_uf_s) * num_ufs; | ||
5027 | *ndm_len += sizeof(struct bfi_uf_buf_post_s) * num_ufs; | ||
5028 | } | 5029 | } |
5029 | 5030 | ||
5030 | static void | 5031 | static void |
5031 | bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, | 5032 | bfa_uf_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg, |
5032 | struct bfa_meminfo_s *meminfo, struct bfa_pcidev_s *pcidev) | 5033 | struct bfa_pcidev_s *pcidev) |
5033 | { | 5034 | { |
5034 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); | 5035 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
5035 | 5036 | ||
5036 | memset(ufm, 0, sizeof(struct bfa_uf_mod_s)); | ||
5037 | ufm->bfa = bfa; | 5037 | ufm->bfa = bfa; |
5038 | ufm->num_ufs = cfg->fwcfg.num_uf_bufs; | 5038 | ufm->num_ufs = cfg->fwcfg.num_uf_bufs; |
5039 | INIT_LIST_HEAD(&ufm->uf_free_q); | 5039 | INIT_LIST_HEAD(&ufm->uf_free_q); |
5040 | INIT_LIST_HEAD(&ufm->uf_posted_q); | 5040 | INIT_LIST_HEAD(&ufm->uf_posted_q); |
5041 | INIT_LIST_HEAD(&ufm->uf_unused_q); | 5041 | INIT_LIST_HEAD(&ufm->uf_unused_q); |
5042 | 5042 | ||
5043 | uf_mem_claim(ufm, meminfo); | 5043 | uf_mem_claim(ufm); |
5044 | } | 5044 | } |
5045 | 5045 | ||
5046 | static void | 5046 | static void |
@@ -5098,11 +5098,15 @@ uf_recv(struct bfa_s *bfa, struct bfi_uf_frm_rcvd_s *m) | |||
5098 | { | 5098 | { |
5099 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); | 5099 | struct bfa_uf_mod_s *ufm = BFA_UF_MOD(bfa); |
5100 | u16 uf_tag = m->buf_tag; | 5100 | u16 uf_tag = m->buf_tag; |
5101 | struct bfa_uf_buf_s *uf_buf = &ufm->uf_pbs_kva[uf_tag]; | ||
5102 | struct bfa_uf_s *uf = &ufm->uf_list[uf_tag]; | 5101 | struct bfa_uf_s *uf = &ufm->uf_list[uf_tag]; |
5103 | u8 *buf = &uf_buf->d[0]; | 5102 | struct bfa_uf_buf_s *uf_buf; |
5103 | uint8_t *buf; | ||
5104 | struct fchs_s *fchs; | 5104 | struct fchs_s *fchs; |
5105 | 5105 | ||
5106 | uf_buf = (struct bfa_uf_buf_s *) | ||
5107 | bfa_mem_get_dmabuf_kva(ufm, uf_tag, uf->pb_len); | ||
5108 | buf = &uf_buf->d[0]; | ||
5109 | |||
5106 | m->frm_len = be16_to_cpu(m->frm_len); | 5110 | m->frm_len = be16_to_cpu(m->frm_len); |
5107 | m->xfr_len = be16_to_cpu(m->xfr_len); | 5111 | m->xfr_len = be16_to_cpu(m->xfr_len); |
5108 | 5112 | ||