dma.c (546121b65f47384e11ec1fa2e55449fc9f4846b2) dma.c (bd2bf302eef21aafa6da2cf829b87a9e33150658)
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Intel I/OAT DMA Linux driver
4 * Copyright(c) 2004 - 2015 Intel Corporation.
5 */
6
7/*
8 * This driver supports an Intel I/OAT DMA engine, which does asynchronous

--- 318 unchanged lines hidden (view full) ---

327 struct ioat_dma_descriptor *hw;
328 struct ioat_ring_ent *desc;
329 struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
330 int chunk;
331 dma_addr_t phys;
332 u8 *pos;
333 off_t offs;
334
1// SPDX-License-Identifier: GPL-2.0-only
2/*
3 * Intel I/OAT DMA Linux driver
4 * Copyright(c) 2004 - 2015 Intel Corporation.
5 */
6
7/*
8 * This driver supports an Intel I/OAT DMA engine, which does asynchronous

--- 318 unchanged lines hidden (view full) ---

327 struct ioat_dma_descriptor *hw;
328 struct ioat_ring_ent *desc;
329 struct ioatdma_chan *ioat_chan = to_ioat_chan(chan);
330 int chunk;
331 dma_addr_t phys;
332 u8 *pos;
333 off_t offs;
334
335 chunk = idx / IOAT_DESCS_PER_2M;
336 idx &= (IOAT_DESCS_PER_2M - 1);
335 chunk = idx / IOAT_DESCS_PER_CHUNK;
336 idx &= (IOAT_DESCS_PER_CHUNK - 1);
337 offs = idx * IOAT_DESC_SZ;
338 pos = (u8 *)ioat_chan->descs[chunk].virt + offs;
339 phys = ioat_chan->descs[chunk].hw + offs;
340 hw = (struct ioat_dma_descriptor *)pos;
341 memset(hw, 0, sizeof(*hw));
342
343 desc = kmem_cache_zalloc(ioat_cache, flags);
344 if (!desc)

--- 20 unchanged lines hidden (view full) ---

365 int total_descs = 1 << order;
366 int i, chunks;
367
368 /* allocate the array to hold the software ring */
369 ring = kcalloc(total_descs, sizeof(*ring), flags);
370 if (!ring)
371 return NULL;
372
337 offs = idx * IOAT_DESC_SZ;
338 pos = (u8 *)ioat_chan->descs[chunk].virt + offs;
339 phys = ioat_chan->descs[chunk].hw + offs;
340 hw = (struct ioat_dma_descriptor *)pos;
341 memset(hw, 0, sizeof(*hw));
342
343 desc = kmem_cache_zalloc(ioat_cache, flags);
344 if (!desc)

--- 20 unchanged lines hidden (view full) ---

365 int total_descs = 1 << order;
366 int i, chunks;
367
368 /* allocate the array to hold the software ring */
369 ring = kcalloc(total_descs, sizeof(*ring), flags);
370 if (!ring)
371 return NULL;
372
373 ioat_chan->desc_chunks = chunks = (total_descs * IOAT_DESC_SZ) / SZ_2M;
373 chunks = (total_descs * IOAT_DESC_SZ) / IOAT_CHUNK_SIZE;
374 ioat_chan->desc_chunks = chunks;
374
375 for (i = 0; i < chunks; i++) {
376 struct ioat_descs *descs = &ioat_chan->descs[i];
377
378 descs->virt = dma_alloc_coherent(to_dev(ioat_chan),
379 SZ_2M, &descs->hw, flags);
380 if (!descs->virt) {
381 int idx;
382
383 for (idx = 0; idx < i; idx++) {
384 descs = &ioat_chan->descs[idx];
375
376 for (i = 0; i < chunks; i++) {
377 struct ioat_descs *descs = &ioat_chan->descs[i];
378
379 descs->virt = dma_alloc_coherent(to_dev(ioat_chan),
380 SZ_2M, &descs->hw, flags);
381 if (!descs->virt) {
382 int idx;
383
384 for (idx = 0; idx < i; idx++) {
385 descs = &ioat_chan->descs[idx];
385 dma_free_coherent(to_dev(ioat_chan), SZ_2M,
386 descs->virt, descs->hw);
386 dma_free_coherent(to_dev(ioat_chan),
387 IOAT_CHUNK_SIZE,
388 descs->virt, descs->hw);
387 descs->virt = NULL;
388 descs->hw = 0;
389 }
390
391 ioat_chan->desc_chunks = 0;
392 kfree(ring);
393 return NULL;
394 }

--- 4 unchanged lines hidden (view full) ---

399 if (!ring[i]) {
400 int idx;
401
402 while (i--)
403 ioat_free_ring_ent(ring[i], c);
404
405 for (idx = 0; idx < ioat_chan->desc_chunks; idx++) {
406 dma_free_coherent(to_dev(ioat_chan),
389 descs->virt = NULL;
390 descs->hw = 0;
391 }
392
393 ioat_chan->desc_chunks = 0;
394 kfree(ring);
395 return NULL;
396 }

--- 4 unchanged lines hidden (view full) ---

401 if (!ring[i]) {
402 int idx;
403
404 while (i--)
405 ioat_free_ring_ent(ring[i], c);
406
407 for (idx = 0; idx < ioat_chan->desc_chunks; idx++) {
408 dma_free_coherent(to_dev(ioat_chan),
407 SZ_2M,
409 IOAT_CHUNK_SIZE,
408 ioat_chan->descs[idx].virt,
409 ioat_chan->descs[idx].hw);
410 ioat_chan->descs[idx].virt = NULL;
411 ioat_chan->descs[idx].hw = 0;
412 }
413
414 ioat_chan->desc_chunks = 0;
415 kfree(ring);

--- 622 unchanged lines hidden ---
410 ioat_chan->descs[idx].virt,
411 ioat_chan->descs[idx].hw);
412 ioat_chan->descs[idx].virt = NULL;
413 ioat_chan->descs[idx].hw = 0;
414 }
415
416 ioat_chan->desc_chunks = 0;
417 kfree(ring);

--- 622 unchanged lines hidden ---