Skip to content

Commit 26a4c99

Browse files
Christoph Hellwigmartinkpetersen
authored andcommitted
scsi: be2iscsi: switch to generic DMA API
Switch from the legacy PCI DMA API to the generic DMA API. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <jthumshirn@suse.de> Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
1 parent 48ecddb commit 26a4c99

File tree

4 files changed

+58
-64
lines changed

4 files changed

+58
-64
lines changed

drivers/scsi/be2iscsi/be_cmds.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ int beiscsi_process_mcc_compl(struct be_ctrl_info *ctrl,
520520
**/
521521
tag_mem = &ctrl->ptag_state[tag].tag_mem_state;
522522
if (tag_mem->size) {
523-
pci_free_consistent(ctrl->pdev, tag_mem->size,
523+
dma_free_coherent(&ctrl->pdev->dev, tag_mem->size,
524524
tag_mem->va, tag_mem->dma);
525525
tag_mem->size = 0;
526526
}
@@ -1269,12 +1269,12 @@ int beiscsi_check_supported_fw(struct be_ctrl_info *ctrl,
12691269
struct be_sge *sge = nonembedded_sgl(wrb);
12701270
int status = 0;
12711271

1272-
nonemb_cmd.va = pci_alloc_consistent(ctrl->pdev,
1272+
nonemb_cmd.va = dma_alloc_coherent(&ctrl->pdev->dev,
12731273
sizeof(struct be_mgmt_controller_attributes),
1274-
&nonemb_cmd.dma);
1274+
&nonemb_cmd.dma, GFP_KERNEL);
12751275
if (nonemb_cmd.va == NULL) {
12761276
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_INIT,
1277-
"BG_%d : pci_alloc_consistent failed in %s\n",
1277+
"BG_%d : dma_alloc_coherent failed in %s\n",
12781278
__func__);
12791279
return -ENOMEM;
12801280
}
@@ -1314,7 +1314,7 @@ int beiscsi_check_supported_fw(struct be_ctrl_info *ctrl,
13141314
"BG_%d : Failed in beiscsi_check_supported_fw\n");
13151315
mutex_unlock(&ctrl->mbox_lock);
13161316
if (nonemb_cmd.va)
1317-
pci_free_consistent(ctrl->pdev, nonemb_cmd.size,
1317+
dma_free_coherent(&ctrl->pdev->dev, nonemb_cmd.size,
13181318
nonemb_cmd.va, nonemb_cmd.dma);
13191319

13201320
return status;

drivers/scsi/be2iscsi/be_iscsi.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,9 +1071,9 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
10711071
else
10721072
req_memsize = sizeof(struct tcp_connect_and_offload_in_v1);
10731073

1074-
nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
1074+
nonemb_cmd.va = dma_alloc_coherent(&phba->ctrl.pdev->dev,
10751075
req_memsize,
1076-
&nonemb_cmd.dma);
1076+
&nonemb_cmd.dma, GFP_KERNEL);
10771077
if (nonemb_cmd.va == NULL) {
10781078

10791079
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
@@ -1091,7 +1091,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
10911091
"BS_%d : mgmt_open_connection Failed for cid=%d\n",
10921092
beiscsi_ep->ep_cid);
10931093

1094-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1094+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
10951095
nonemb_cmd.va, nonemb_cmd.dma);
10961096
beiscsi_free_ep(beiscsi_ep);
10971097
return -EAGAIN;
@@ -1104,8 +1104,9 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
11041104
"BS_%d : mgmt_open_connection Failed");
11051105

11061106
if (ret != -EBUSY)
1107-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1108-
nonemb_cmd.va, nonemb_cmd.dma);
1107+
dma_free_coherent(&phba->ctrl.pdev->dev,
1108+
nonemb_cmd.size, nonemb_cmd.va,
1109+
nonemb_cmd.dma);
11091110

11101111
beiscsi_free_ep(beiscsi_ep);
11111112
return ret;
@@ -1118,7 +1119,7 @@ static int beiscsi_open_conn(struct iscsi_endpoint *ep,
11181119
beiscsi_log(phba, KERN_INFO, BEISCSI_LOG_CONFIG,
11191120
"BS_%d : mgmt_open_connection Success\n");
11201121

1121-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1122+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
11221123
nonemb_cmd.va, nonemb_cmd.dma);
11231124
return 0;
11241125
}

drivers/scsi/be2iscsi/be_main.c

Lines changed: 31 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -511,18 +511,9 @@ static int beiscsi_enable_pci(struct pci_dev *pcidev)
511511
}
512512

513513
pci_set_master(pcidev);
514-
ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(64));
514+
ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(64));
515515
if (ret) {
516-
ret = pci_set_dma_mask(pcidev, DMA_BIT_MASK(32));
517-
if (ret) {
518-
dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
519-
goto pci_region_release;
520-
} else {
521-
ret = pci_set_consistent_dma_mask(pcidev,
522-
DMA_BIT_MASK(32));
523-
}
524-
} else {
525-
ret = pci_set_consistent_dma_mask(pcidev, DMA_BIT_MASK(64));
516+
ret = dma_set_mask_and_coherent(&pcidev->dev, DMA_BIT_MASK(32));
526517
if (ret) {
527518
dev_err(&pcidev->dev, "Could not set PCI DMA Mask\n");
528519
goto pci_region_release;
@@ -550,9 +541,8 @@ static int be_ctrl_init(struct beiscsi_hba *phba, struct pci_dev *pdev)
550541
if (status)
551542
return status;
552543
mbox_mem_alloc->size = sizeof(struct be_mcc_mailbox) + 16;
553-
mbox_mem_alloc->va = pci_alloc_consistent(pdev,
554-
mbox_mem_alloc->size,
555-
&mbox_mem_alloc->dma);
544+
mbox_mem_alloc->va = dma_alloc_coherent(&pdev->dev,
545+
mbox_mem_alloc->size, &mbox_mem_alloc->dma, GFP_KERNEL);
556546
if (!mbox_mem_alloc->va) {
557547
beiscsi_unmap_pci_function(phba);
558548
return -ENOMEM;
@@ -2302,11 +2292,11 @@ static int hwi_write_buffer(struct iscsi_wrb *pwrb, struct iscsi_task *task)
23022292

23032293
/* Map addr only if there is data_count */
23042294
if (dsp_value) {
2305-
io_task->mtask_addr = pci_map_single(phba->pcidev,
2295+
io_task->mtask_addr = dma_map_single(&phba->pcidev->dev,
23062296
task->data,
23072297
task->data_count,
2308-
PCI_DMA_TODEVICE);
2309-
if (pci_dma_mapping_error(phba->pcidev,
2298+
DMA_TO_DEVICE);
2299+
if (dma_mapping_error(&phba->pcidev->dev,
23102300
io_task->mtask_addr))
23112301
return -ENOMEM;
23122302
io_task->mtask_data_count = task->data_count;
@@ -2517,10 +2507,9 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
25172507
BEISCSI_MAX_FRAGS_INIT);
25182508
curr_alloc_size = min(be_max_phys_size * 1024, alloc_size);
25192509
do {
2520-
mem_arr->virtual_address = pci_alloc_consistent(
2521-
phba->pcidev,
2522-
curr_alloc_size,
2523-
&bus_add);
2510+
mem_arr->virtual_address =
2511+
dma_alloc_coherent(&phba->pcidev->dev,
2512+
curr_alloc_size, &bus_add, GFP_KERNEL);
25242513
if (!mem_arr->virtual_address) {
25252514
if (curr_alloc_size <= BE_MIN_MEM_SIZE)
25262515
goto free_mem;
@@ -2558,7 +2547,7 @@ static int beiscsi_alloc_mem(struct beiscsi_hba *phba)
25582547
mem_descr->num_elements = j;
25592548
while ((i) || (j)) {
25602549
for (j = mem_descr->num_elements; j > 0; j--) {
2561-
pci_free_consistent(phba->pcidev,
2550+
dma_free_coherent(&phba->pcidev->dev,
25622551
mem_descr->mem_array[j - 1].size,
25632552
mem_descr->mem_array[j - 1].
25642553
virtual_address,
@@ -3029,9 +3018,9 @@ static int beiscsi_create_eqs(struct beiscsi_hba *phba,
30293018
eq = &phwi_context->be_eq[i].q;
30303019
mem = &eq->dma_mem;
30313020
phwi_context->be_eq[i].phba = phba;
3032-
eq_vaddress = pci_alloc_consistent(phba->pcidev,
3021+
eq_vaddress = dma_alloc_coherent(&phba->pcidev->dev,
30333022
num_eq_pages * PAGE_SIZE,
3034-
&paddr);
3023+
&paddr, GFP_KERNEL);
30353024
if (!eq_vaddress) {
30363025
ret = -ENOMEM;
30373026
goto create_eq_error;
@@ -3067,7 +3056,7 @@ static int beiscsi_create_eqs(struct beiscsi_hba *phba,
30673056
eq = &phwi_context->be_eq[i].q;
30683057
mem = &eq->dma_mem;
30693058
if (mem->va)
3070-
pci_free_consistent(phba->pcidev, num_eq_pages
3059+
dma_free_coherent(&phba->pcidev->dev, num_eq_pages
30713060
* PAGE_SIZE,
30723061
mem->va, mem->dma);
30733062
}
@@ -3095,9 +3084,9 @@ static int beiscsi_create_cqs(struct beiscsi_hba *phba,
30953084
pbe_eq->cq = cq;
30963085
pbe_eq->phba = phba;
30973086
mem = &cq->dma_mem;
3098-
cq_vaddress = pci_alloc_consistent(phba->pcidev,
3087+
cq_vaddress = dma_alloc_coherent(&phba->pcidev->dev,
30993088
num_cq_pages * PAGE_SIZE,
3100-
&paddr);
3089+
&paddr, GFP_KERNEL);
31013090
if (!cq_vaddress) {
31023091
ret = -ENOMEM;
31033092
goto create_cq_error;
@@ -3132,7 +3121,7 @@ static int beiscsi_create_cqs(struct beiscsi_hba *phba,
31323121
cq = &phwi_context->be_cq[i];
31333122
mem = &cq->dma_mem;
31343123
if (mem->va)
3135-
pci_free_consistent(phba->pcidev, num_cq_pages
3124+
dma_free_coherent(&phba->pcidev->dev, num_cq_pages
31363125
* PAGE_SIZE,
31373126
mem->va, mem->dma);
31383127
}
@@ -3324,7 +3313,7 @@ static void be_queue_free(struct beiscsi_hba *phba, struct be_queue_info *q)
33243313
{
33253314
struct be_dma_mem *mem = &q->dma_mem;
33263315
if (mem->va) {
3327-
pci_free_consistent(phba->pcidev, mem->size,
3316+
dma_free_coherent(&phba->pcidev->dev, mem->size,
33283317
mem->va, mem->dma);
33293318
mem->va = NULL;
33303319
}
@@ -3339,7 +3328,8 @@ static int be_queue_alloc(struct beiscsi_hba *phba, struct be_queue_info *q,
33393328
q->len = len;
33403329
q->entry_size = entry_size;
33413330
mem->size = len * entry_size;
3342-
mem->va = pci_zalloc_consistent(phba->pcidev, mem->size, &mem->dma);
3331+
mem->va = dma_zalloc_coherent(&phba->pcidev->dev, mem->size, &mem->dma,
3332+
GFP_KERNEL);
33433333
if (!mem->va)
33443334
return -ENOMEM;
33453335
return 0;
@@ -3477,7 +3467,7 @@ static void be_mcc_queues_destroy(struct beiscsi_hba *phba)
34773467
&ctrl->ptag_state[tag].tag_state)) {
34783468
ptag_mem = &ctrl->ptag_state[tag].tag_mem_state;
34793469
if (ptag_mem->size) {
3480-
pci_free_consistent(ctrl->pdev,
3470+
dma_free_coherent(&ctrl->pdev->dev,
34813471
ptag_mem->size,
34823472
ptag_mem->va,
34833473
ptag_mem->dma);
@@ -3878,7 +3868,7 @@ static void beiscsi_free_mem(struct beiscsi_hba *phba)
38783868
j = 0;
38793869
for (i = 0; i < SE_MEM_MAX; i++) {
38803870
for (j = mem_descr->num_elements; j > 0; j--) {
3881-
pci_free_consistent(phba->pcidev,
3871+
dma_free_coherent(&phba->pcidev->dev,
38823872
mem_descr->mem_array[j - 1].size,
38833873
mem_descr->mem_array[j - 1].virtual_address,
38843874
(unsigned long)mem_descr->mem_array[j - 1].
@@ -4253,10 +4243,10 @@ beiscsi_free_mgmt_task_handles(struct beiscsi_conn *beiscsi_conn,
42534243
}
42544244

42554245
if (io_task->mtask_addr) {
4256-
pci_unmap_single(phba->pcidev,
4246+
dma_unmap_single(&phba->pcidev->dev,
42574247
io_task->mtask_addr,
42584248
io_task->mtask_data_count,
4259-
PCI_DMA_TODEVICE);
4249+
DMA_TO_DEVICE);
42604250
io_task->mtask_addr = 0;
42614251
}
42624252
}
@@ -4850,9 +4840,9 @@ static int beiscsi_bsg_request(struct bsg_job *job)
48504840

48514841
switch (bsg_req->msgcode) {
48524842
case ISCSI_BSG_HST_VENDOR:
4853-
nonemb_cmd.va = pci_alloc_consistent(phba->ctrl.pdev,
4843+
nonemb_cmd.va = dma_alloc_coherent(&phba->ctrl.pdev->dev,
48544844
job->request_payload.payload_len,
4855-
&nonemb_cmd.dma);
4845+
&nonemb_cmd.dma, GFP_KERNEL);
48564846
if (nonemb_cmd.va == NULL) {
48574847
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
48584848
"BM_%d : Failed to allocate memory for "
@@ -4865,7 +4855,7 @@ static int beiscsi_bsg_request(struct bsg_job *job)
48654855
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
48664856
"BM_%d : MBX Tag Allocation Failed\n");
48674857

4868-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4858+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
48694859
nonemb_cmd.va, nonemb_cmd.dma);
48704860
return -EAGAIN;
48714861
}
@@ -4879,7 +4869,7 @@ static int beiscsi_bsg_request(struct bsg_job *job)
48794869
if (!test_bit(BEISCSI_HBA_ONLINE, &phba->state)) {
48804870
clear_bit(MCC_TAG_STATE_RUNNING,
48814871
&phba->ctrl.ptag_state[tag].tag_state);
4882-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4872+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
48834873
nonemb_cmd.va, nonemb_cmd.dma);
48844874
return -EIO;
48854875
}
@@ -4896,7 +4886,7 @@ static int beiscsi_bsg_request(struct bsg_job *job)
48964886
bsg_reply->result = status;
48974887
bsg_job_done(job, bsg_reply->result,
48984888
bsg_reply->reply_payload_rcv_len);
4899-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
4889+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
49004890
nonemb_cmd.va, nonemb_cmd.dma);
49014891
if (status || extd_status) {
49024892
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
@@ -5753,7 +5743,7 @@ static int beiscsi_dev_probe(struct pci_dev *pcidev,
57535743
beiscsi_cleanup_port(phba);
57545744
beiscsi_free_mem(phba);
57555745
free_port:
5756-
pci_free_consistent(phba->pcidev,
5746+
dma_free_coherent(&phba->pcidev->dev,
57575747
phba->ctrl.mbox_mem_alloced.size,
57585748
phba->ctrl.mbox_mem_alloced.va,
57595749
phba->ctrl.mbox_mem_alloced.dma);
@@ -5797,7 +5787,7 @@ static void beiscsi_remove(struct pci_dev *pcidev)
57975787

57985788
/* ctrl uninit */
57995789
beiscsi_unmap_pci_function(phba);
5800-
pci_free_consistent(phba->pcidev,
5790+
dma_free_coherent(&phba->pcidev->dev,
58015791
phba->ctrl.mbox_mem_alloced.size,
58025792
phba->ctrl.mbox_mem_alloced.va,
58035793
phba->ctrl.mbox_mem_alloced.dma);

drivers/scsi/be2iscsi/be_mgmt.c

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ static int beiscsi_exec_nemb_cmd(struct beiscsi_hba *phba,
284284
return rc;
285285

286286
free_cmd:
287-
pci_free_consistent(ctrl->pdev, nonemb_cmd->size,
287+
dma_free_coherent(&ctrl->pdev->dev, nonemb_cmd->size,
288288
nonemb_cmd->va, nonemb_cmd->dma);
289289
return rc;
290290
}
@@ -293,7 +293,8 @@ static int beiscsi_prep_nemb_cmd(struct beiscsi_hba *phba,
293293
struct be_dma_mem *cmd,
294294
u8 subsystem, u8 opcode, u32 size)
295295
{
296-
cmd->va = pci_zalloc_consistent(phba->ctrl.pdev, size, &cmd->dma);
296+
cmd->va = dma_zalloc_coherent(&phba->ctrl.pdev->dev, size, &cmd->dma,
297+
GFP_KERNEL);
297298
if (!cmd->va) {
298299
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_CONFIG,
299300
"BG_%d : Failed to allocate memory for if info\n");
@@ -315,7 +316,7 @@ static void __beiscsi_eq_delay_compl(struct beiscsi_hba *phba, unsigned int tag)
315316
__beiscsi_mcc_compl_status(phba, tag, NULL, NULL);
316317
tag_mem = &phba->ctrl.ptag_state[tag].tag_mem_state;
317318
if (tag_mem->size) {
318-
pci_free_consistent(phba->pcidev, tag_mem->size,
319+
dma_free_coherent(&phba->pcidev->dev, tag_mem->size,
319320
tag_mem->va, tag_mem->dma);
320321
tag_mem->size = 0;
321322
}
@@ -761,7 +762,7 @@ int beiscsi_if_get_info(struct beiscsi_hba *phba, int ip_type,
761762
"BG_%d : Memory Allocation Failure\n");
762763

763764
/* Free the DMA memory for the IOCTL issuing */
764-
pci_free_consistent(phba->ctrl.pdev,
765+
dma_free_coherent(&phba->ctrl.pdev->dev,
765766
nonemb_cmd.size,
766767
nonemb_cmd.va,
767768
nonemb_cmd.dma);
@@ -780,7 +781,7 @@ int beiscsi_if_get_info(struct beiscsi_hba *phba, int ip_type,
780781
ioctl_size += sizeof(struct be_cmd_req_hdr);
781782

782783
/* Free the previous allocated DMA memory */
783-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
784+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
784785
nonemb_cmd.va,
785786
nonemb_cmd.dma);
786787

@@ -869,7 +870,7 @@ static void beiscsi_boot_process_compl(struct beiscsi_hba *phba,
869870
status);
870871
boot_work = 0;
871872
}
872-
pci_free_consistent(phba->ctrl.pdev, bs->nonemb_cmd.size,
873+
dma_free_coherent(&phba->ctrl.pdev->dev, bs->nonemb_cmd.size,
873874
bs->nonemb_cmd.va, bs->nonemb_cmd.dma);
874875
bs->nonemb_cmd.va = NULL;
875876
break;
@@ -1012,9 +1013,10 @@ unsigned int beiscsi_boot_get_sinfo(struct beiscsi_hba *phba)
10121013

10131014
nonemb_cmd = &phba->boot_struct.nonemb_cmd;
10141015
nonemb_cmd->size = sizeof(struct be_cmd_get_session_resp);
1015-
nonemb_cmd->va = pci_alloc_consistent(phba->ctrl.pdev,
1016+
nonemb_cmd->va = dma_alloc_coherent(&phba->ctrl.pdev->dev,
10161017
nonemb_cmd->size,
1017-
&nonemb_cmd->dma);
1018+
&nonemb_cmd->dma,
1019+
GFP_KERNEL);
10181020
if (!nonemb_cmd->va) {
10191021
mutex_unlock(&ctrl->mbox_lock);
10201022
return 0;
@@ -1508,9 +1510,10 @@ int beiscsi_mgmt_invalidate_icds(struct beiscsi_hba *phba,
15081510
return -EINVAL;
15091511

15101512
nonemb_cmd.size = sizeof(union be_invldt_cmds_params);
1511-
nonemb_cmd.va = pci_zalloc_consistent(phba->ctrl.pdev,
1513+
nonemb_cmd.va = dma_zalloc_coherent(&phba->ctrl.pdev->dev,
15121514
nonemb_cmd.size,
1513-
&nonemb_cmd.dma);
1515+
&nonemb_cmd.dma,
1516+
GFP_KERNEL);
15141517
if (!nonemb_cmd.va) {
15151518
beiscsi_log(phba, KERN_ERR, BEISCSI_LOG_EH,
15161519
"BM_%d : invldt_cmds_params alloc failed\n");
@@ -1521,7 +1524,7 @@ int beiscsi_mgmt_invalidate_icds(struct beiscsi_hba *phba,
15211524
wrb = alloc_mcc_wrb(phba, &tag);
15221525
if (!wrb) {
15231526
mutex_unlock(&ctrl->mbox_lock);
1524-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1527+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
15251528
nonemb_cmd.va, nonemb_cmd.dma);
15261529
return -ENOMEM;
15271530
}
@@ -1548,7 +1551,7 @@ int beiscsi_mgmt_invalidate_icds(struct beiscsi_hba *phba,
15481551

15491552
rc = beiscsi_mccq_compl_wait(phba, tag, NULL, &nonemb_cmd);
15501553
if (rc != -EBUSY)
1551-
pci_free_consistent(phba->ctrl.pdev, nonemb_cmd.size,
1554+
dma_free_coherent(&phba->ctrl.pdev->dev, nonemb_cmd.size,
15521555
nonemb_cmd.va, nonemb_cmd.dma);
15531556
return rc;
15541557
}

0 commit comments

Comments
 (0)