2 * Copyright(c) 2004 - 2009 Intel Corporation. All rights reserved.
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License as published by the Free
6 * Software Foundation; either version 2 of the License, or (at your option)
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
14 * The full GNU General Public License is included in this distribution in the
15 * file called COPYING.
20 #include <linux/dmaengine.h>
21 #include <linux/circ_buf.h>
26 extern int ioat_pending_level;
27 extern int ioat_ring_alloc_order;
30 * workaround for IOAT ver.3.0 null descriptor issue
31 * (channel returns error when size is 0)
33 #define NULL_DESC_BUFFER_SIZE 1
35 #define IOAT_MAX_ORDER 16
36 #define ioat_get_alloc_order() \
37 (min(ioat_ring_alloc_order, IOAT_MAX_ORDER))
38 #define ioat_get_max_alloc_order() \
39 (min(ioat_ring_max_alloc_order, IOAT_MAX_ORDER))
41 static inline u32 ioat2_ring_size(struct ioatdma_chan *ioat_chan)
43 return 1 << ioat_chan->alloc_order;
46 /* count of descriptors in flight with the engine */
47 static inline u16 ioat2_ring_active(struct ioatdma_chan *ioat_chan)
49 return CIRC_CNT(ioat_chan->head, ioat_chan->tail,
50 ioat2_ring_size(ioat_chan));
53 /* count of descriptors pending submission to hardware */
54 static inline u16 ioat2_ring_pending(struct ioatdma_chan *ioat_chan)
56 return CIRC_CNT(ioat_chan->head, ioat_chan->issued,
57 ioat2_ring_size(ioat_chan));
60 static inline u32 ioat2_ring_space(struct ioatdma_chan *ioat_chan)
62 return ioat2_ring_size(ioat_chan) - ioat2_ring_active(ioat_chan);
66 ioat2_xferlen_to_descs(struct ioatdma_chan *ioat_chan, size_t len)
68 u16 num_descs = len >> ioat_chan->xfercap_log;
70 num_descs += !!(len & ((1 << ioat_chan->xfercap_log) - 1));
75 * struct ioat_ring_ent - wrapper around hardware descriptor
76 * @hw: hardware DMA descriptor (for memcpy)
77 * @fill: hardware fill descriptor
78 * @xor: hardware xor descriptor
79 * @xor_ex: hardware xor extension descriptor
80 * @pq: hardware pq descriptor
81 * @pq_ex: hardware pq extension descriptor
82 * @pqu: hardware pq update descriptor
83 * @raw: hardware raw (un-typed) descriptor
84 * @txd: the generic software descriptor for all engines
85 * @len: total transaction length for unmap
86 * @result: asynchronous result of validate operations
87 * @id: identifier for debug
90 struct ioat_ring_ent {
92 struct ioat_dma_descriptor *hw;
93 struct ioat_xor_descriptor *xor;
94 struct ioat_xor_ext_descriptor *xor_ex;
95 struct ioat_pq_descriptor *pq;
96 struct ioat_pq_ext_descriptor *pq_ex;
97 struct ioat_pq_update_descriptor *pqu;
98 struct ioat_raw_descriptor *raw;
101 struct dma_async_tx_descriptor txd;
102 enum sum_check_flags *result;
106 struct ioat_sed_ent *sed;
109 static inline struct ioat_ring_ent *
110 ioat2_get_ring_ent(struct ioatdma_chan *ioat_chan, u16 idx)
112 return ioat_chan->ring[idx & (ioat2_ring_size(ioat_chan) - 1)];
116 ioat2_set_chainaddr(struct ioatdma_chan *ioat_chan, u64 addr)
118 writel(addr & 0x00000000FFFFFFFF,
119 ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW);
121 ioat_chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH);
124 int ioat2_dma_probe(struct ioatdma_device *dev, int dca);
125 int ioat3_dma_probe(struct ioatdma_device *dev, int dca);
126 struct dca_provider *ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase);
127 int ioat2_check_space_lock(struct ioatdma_chan *ioat_chan, int num_descs);
128 int ioat2_enumerate_channels(struct ioatdma_device *device);
129 struct dma_async_tx_descriptor *
130 ioat2_dma_prep_memcpy_lock(struct dma_chan *c, dma_addr_t dma_dest,
131 dma_addr_t dma_src, size_t len, unsigned long flags);
132 void ioat2_issue_pending(struct dma_chan *chan);
133 int ioat2_alloc_chan_resources(struct dma_chan *c);
134 void ioat2_free_chan_resources(struct dma_chan *c);
135 void __ioat2_restart_chan(struct ioatdma_chan *ioat_chan);
136 bool reshape_ring(struct ioatdma_chan *ioat, int order);
137 void __ioat2_issue_pending(struct ioatdma_chan *ioat_chan);
138 void ioat2_timer_event(unsigned long data);
139 int ioat2_quiesce(struct ioatdma_chan *ioat_chan, unsigned long tmo);
140 int ioat2_reset_sync(struct ioatdma_chan *ioat_chan, unsigned long tmo);
141 extern struct kobj_type ioat2_ktype;
142 extern struct kmem_cache *ioat2_cache;
143 #endif /* IOATDMA_V2_H */