Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright(c) 2004 - 2009 Intel Corporation. All rights reserved. |
| 3 | * |
| 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) |
| 7 | * any later version. |
| 8 | * |
| 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 |
| 12 | * more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License along with |
| 15 | * this program; if not, write to the Free Software Foundation, Inc., 59 |
| 16 | * Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 17 | * |
| 18 | * The full GNU General Public License is included in this distribution in the |
| 19 | * file called COPYING. |
| 20 | */ |
| 21 | #ifndef IOATDMA_V2_H |
| 22 | #define IOATDMA_V2_H |
| 23 | |
| 24 | #include <linux/dmaengine.h> |
Dan Williams | abb12df | 2010-05-01 15:22:54 -0700 | [diff] [blame^] | 25 | #include <linux/circ_buf.h> |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 26 | #include "dma.h" |
| 27 | #include "hw.h" |
| 28 | |
| 29 | |
| 30 | extern int ioat_pending_level; |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 31 | extern int ioat_ring_alloc_order; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 32 | |
| 33 | /* |
| 34 | * workaround for IOAT ver.3.0 null descriptor issue |
| 35 | * (channel returns error when size is 0) |
| 36 | */ |
| 37 | #define NULL_DESC_BUFFER_SIZE 1 |
| 38 | |
| 39 | #define IOAT_MAX_ORDER 16 |
| 40 | #define ioat_get_alloc_order() \ |
| 41 | (min(ioat_ring_alloc_order, IOAT_MAX_ORDER)) |
Dan Williams | a309218 | 2009-09-08 12:02:01 -0700 | [diff] [blame] | 42 | #define ioat_get_max_alloc_order() \ |
| 43 | (min(ioat_ring_max_alloc_order, IOAT_MAX_ORDER)) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 44 | |
| 45 | /* struct ioat2_dma_chan - ioat v2 / v3 channel attributes |
| 46 | * @base: common ioat channel parameters |
| 47 | * @xfercap_log; log2 of channel max transfer length (for fast division) |
| 48 | * @head: allocated index |
| 49 | * @issued: hardware notification point |
| 50 | * @tail: cleanup index |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 51 | * @dmacount: identical to 'head' except for occasionally resetting to zero |
| 52 | * @alloc_order: log2 of the number of allocated descriptors |
| 53 | * @ring: software ring buffer implementation of hardware ring |
| 54 | * @ring_lock: protects ring attributes |
| 55 | */ |
| 56 | struct ioat2_dma_chan { |
| 57 | struct ioat_chan_common base; |
| 58 | size_t xfercap_log; |
| 59 | u16 head; |
| 60 | u16 issued; |
| 61 | u16 tail; |
| 62 | u16 dmacount; |
| 63 | u16 alloc_order; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 64 | struct ioat_ring_ent **ring; |
| 65 | spinlock_t ring_lock; |
| 66 | }; |
| 67 | |
| 68 | static inline struct ioat2_dma_chan *to_ioat2_chan(struct dma_chan *c) |
| 69 | { |
| 70 | struct ioat_chan_common *chan = to_chan_common(c); |
| 71 | |
| 72 | return container_of(chan, struct ioat2_dma_chan, base); |
| 73 | } |
| 74 | |
Dan Williams | abb12df | 2010-05-01 15:22:54 -0700 | [diff] [blame^] | 75 | static inline u16 ioat2_ring_size(struct ioat2_dma_chan *ioat) |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 76 | { |
Dan Williams | abb12df | 2010-05-01 15:22:54 -0700 | [diff] [blame^] | 77 | return 1 << ioat->alloc_order; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 78 | } |
| 79 | |
| 80 | /* count of descriptors in flight with the engine */ |
| 81 | static inline u16 ioat2_ring_active(struct ioat2_dma_chan *ioat) |
| 82 | { |
Dan Williams | abb12df | 2010-05-01 15:22:54 -0700 | [diff] [blame^] | 83 | return CIRC_CNT(ioat->head, ioat->tail, ioat2_ring_size(ioat)); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | /* count of descriptors pending submission to hardware */ |
| 87 | static inline u16 ioat2_ring_pending(struct ioat2_dma_chan *ioat) |
| 88 | { |
Dan Williams | abb12df | 2010-05-01 15:22:54 -0700 | [diff] [blame^] | 89 | return CIRC_CNT(ioat->head, ioat->issued, ioat2_ring_size(ioat)); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | static inline u16 ioat2_ring_space(struct ioat2_dma_chan *ioat) |
| 93 | { |
Dan Williams | abb12df | 2010-05-01 15:22:54 -0700 | [diff] [blame^] | 94 | return ioat2_ring_size(ioat) - ioat2_ring_active(ioat); |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | /* assumes caller already checked space */ |
| 98 | static inline u16 ioat2_desc_alloc(struct ioat2_dma_chan *ioat, u16 len) |
| 99 | { |
| 100 | ioat->head += len; |
| 101 | return ioat->head - len; |
| 102 | } |
| 103 | |
| 104 | static inline u16 ioat2_xferlen_to_descs(struct ioat2_dma_chan *ioat, size_t len) |
| 105 | { |
| 106 | u16 num_descs = len >> ioat->xfercap_log; |
| 107 | |
| 108 | num_descs += !!(len & ((1 << ioat->xfercap_log) - 1)); |
| 109 | return num_descs; |
| 110 | } |
| 111 | |
Dan Williams | 2aec048 | 2009-09-08 17:42:54 -0700 | [diff] [blame] | 112 | /** |
| 113 | * struct ioat_ring_ent - wrapper around hardware descriptor |
| 114 | * @hw: hardware DMA descriptor (for memcpy) |
| 115 | * @fill: hardware fill descriptor |
| 116 | * @xor: hardware xor descriptor |
| 117 | * @xor_ex: hardware xor extension descriptor |
| 118 | * @pq: hardware pq descriptor |
| 119 | * @pq_ex: hardware pq extension descriptor |
| 120 | * @pqu: hardware pq update descriptor |
| 121 | * @raw: hardware raw (un-typed) descriptor |
| 122 | * @txd: the generic software descriptor for all engines |
| 123 | * @len: total transaction length for unmap |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 124 | * @result: asynchronous result of validate operations |
Dan Williams | 2aec048 | 2009-09-08 17:42:54 -0700 | [diff] [blame] | 125 | * @id: identifier for debug |
| 126 | */ |
| 127 | |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 128 | struct ioat_ring_ent { |
Dan Williams | 2aec048 | 2009-09-08 17:42:54 -0700 | [diff] [blame] | 129 | union { |
| 130 | struct ioat_dma_descriptor *hw; |
| 131 | struct ioat_fill_descriptor *fill; |
| 132 | struct ioat_xor_descriptor *xor; |
| 133 | struct ioat_xor_ext_descriptor *xor_ex; |
| 134 | struct ioat_pq_descriptor *pq; |
| 135 | struct ioat_pq_ext_descriptor *pq_ex; |
| 136 | struct ioat_pq_update_descriptor *pqu; |
| 137 | struct ioat_raw_descriptor *raw; |
| 138 | }; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 139 | size_t len; |
Dan Williams | 162b96e | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 140 | struct dma_async_tx_descriptor txd; |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 141 | enum sum_check_flags *result; |
Dan Williams | 6df9183 | 2009-09-08 12:00:55 -0700 | [diff] [blame] | 142 | #ifdef DEBUG |
| 143 | int id; |
| 144 | #endif |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 145 | }; |
| 146 | |
| 147 | static inline struct ioat_ring_ent * |
| 148 | ioat2_get_ring_ent(struct ioat2_dma_chan *ioat, u16 idx) |
| 149 | { |
Dan Williams | abb12df | 2010-05-01 15:22:54 -0700 | [diff] [blame^] | 150 | return ioat->ring[idx & (ioat2_ring_size(ioat) - 1)]; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 151 | } |
| 152 | |
Dan Williams | 09c8a5b | 2009-09-08 12:01:49 -0700 | [diff] [blame] | 153 | static inline void ioat2_set_chainaddr(struct ioat2_dma_chan *ioat, u64 addr) |
| 154 | { |
| 155 | struct ioat_chan_common *chan = &ioat->base; |
| 156 | |
| 157 | writel(addr & 0x00000000FFFFFFFF, |
| 158 | chan->reg_base + IOAT2_CHAINADDR_OFFSET_LOW); |
| 159 | writel(addr >> 32, |
| 160 | chan->reg_base + IOAT2_CHAINADDR_OFFSET_HIGH); |
| 161 | } |
| 162 | |
Dan Williams | 345d852 | 2009-09-08 12:01:30 -0700 | [diff] [blame] | 163 | int __devinit ioat2_dma_probe(struct ioatdma_device *dev, int dca); |
| 164 | int __devinit ioat3_dma_probe(struct ioatdma_device *dev, int dca); |
| 165 | struct dca_provider * __devinit ioat2_dca_init(struct pci_dev *pdev, void __iomem *iobase); |
| 166 | struct dca_provider * __devinit ioat3_dca_init(struct pci_dev *pdev, void __iomem *iobase); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 167 | int ioat2_alloc_and_lock(u16 *idx, struct ioat2_dma_chan *ioat, int num_descs); |
| 168 | int ioat2_enumerate_channels(struct ioatdma_device *device); |
| 169 | struct dma_async_tx_descriptor * |
| 170 | ioat2_dma_prep_memcpy_lock(struct dma_chan *c, dma_addr_t dma_dest, |
| 171 | dma_addr_t dma_src, size_t len, unsigned long flags); |
| 172 | void ioat2_issue_pending(struct dma_chan *chan); |
| 173 | int ioat2_alloc_chan_resources(struct dma_chan *c); |
| 174 | void ioat2_free_chan_resources(struct dma_chan *c); |
Dan Williams | bf40a68 | 2009-09-08 17:42:55 -0700 | [diff] [blame] | 175 | void __ioat2_restart_chan(struct ioat2_dma_chan *ioat); |
| 176 | bool reshape_ring(struct ioat2_dma_chan *ioat, int order); |
Dan Williams | b094ad3 | 2009-09-08 17:42:57 -0700 | [diff] [blame] | 177 | void __ioat2_issue_pending(struct ioat2_dma_chan *ioat); |
Dan Williams | aa4d72a | 2010-03-03 21:21:13 -0700 | [diff] [blame] | 178 | void ioat2_cleanup_event(unsigned long data); |
Dan Williams | e323271 | 2009-09-08 17:43:02 -0700 | [diff] [blame] | 179 | void ioat2_timer_event(unsigned long data); |
Dan Williams | a6d52d7 | 2009-12-19 15:36:02 -0700 | [diff] [blame] | 180 | int ioat2_quiesce(struct ioat_chan_common *chan, unsigned long tmo); |
| 181 | int ioat2_reset_sync(struct ioat_chan_common *chan, unsigned long tmo); |
Dan Williams | 5669e31 | 2009-09-08 17:42:56 -0700 | [diff] [blame] | 182 | extern struct kobj_type ioat2_ktype; |
Dan Williams | 162b96e | 2009-09-08 17:53:04 -0700 | [diff] [blame] | 183 | extern struct kmem_cache *ioat2_cache; |
Dan Williams | 5cbafa6 | 2009-08-26 13:01:44 -0700 | [diff] [blame] | 184 | #endif /* IOATDMA_V2_H */ |