Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 1 | /* |
Vasanthy Kolluri | 29046f9 | 2010-06-24 10:52:26 +0000 | [diff] [blame] | 2 | * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved. |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 3 | * Copyright 2007 Nuova Systems, Inc. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you may redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; version 2 of the License. |
| 8 | * |
| 9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 10 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 11 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 12 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS |
| 13 | * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
| 14 | * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 15 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 16 | * SOFTWARE. |
| 17 | * |
| 18 | */ |
| 19 | |
| 20 | #ifndef _VNIC_WQ_H_ |
| 21 | #define _VNIC_WQ_H_ |
| 22 | |
| 23 | #include <linux/pci.h> |
| 24 | |
| 25 | #include "vnic_dev.h" |
| 26 | #include "vnic_cq.h" |
| 27 | |
| 28 | /* Work queue control */ |
| 29 | struct vnic_wq_ctrl { |
| 30 | u64 ring_base; /* 0x00 */ |
| 31 | u32 ring_size; /* 0x08 */ |
| 32 | u32 pad0; |
| 33 | u32 posted_index; /* 0x10 */ |
| 34 | u32 pad1; |
| 35 | u32 cq_index; /* 0x18 */ |
| 36 | u32 pad2; |
| 37 | u32 enable; /* 0x20 */ |
| 38 | u32 pad3; |
| 39 | u32 running; /* 0x28 */ |
| 40 | u32 pad4; |
| 41 | u32 fetch_index; /* 0x30 */ |
| 42 | u32 pad5; |
| 43 | u32 dca_value; /* 0x38 */ |
| 44 | u32 pad6; |
| 45 | u32 error_interrupt_enable; /* 0x40 */ |
| 46 | u32 pad7; |
| 47 | u32 error_interrupt_offset; /* 0x48 */ |
| 48 | u32 pad8; |
| 49 | u32 error_status; /* 0x50 */ |
| 50 | u32 pad9; |
| 51 | }; |
| 52 | |
| 53 | struct vnic_wq_buf { |
| 54 | struct vnic_wq_buf *next; |
| 55 | dma_addr_t dma_addr; |
| 56 | void *os_buf; |
| 57 | unsigned int len; |
| 58 | unsigned int index; |
| 59 | int sop; |
| 60 | void *desc; |
Neel Patel | 92e2b46 | 2013-08-16 15:47:39 -0700 | [diff] [blame] | 61 | uint64_t wr_id; /* Cookie */ |
| 62 | uint8_t cq_entry; /* Gets completion event from hw */ |
| 63 | uint8_t desc_skip_cnt; /* Num descs to occupy */ |
| 64 | uint8_t compressed_send; /* Both hdr and payload in one desc */ |
Govindarajulu Varadarajan | 5e32066 | 2014-12-24 15:59:36 +0530 | [diff] [blame] | 65 | struct vnic_wq_buf *prev; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 66 | }; |
| 67 | |
Vasanthy Kolluri | b5bab85 | 2010-06-24 10:51:51 +0000 | [diff] [blame] | 68 | /* Break the vnic_wq_buf allocations into blocks of 32/64 entries */ |
| 69 | #define VNIC_WQ_BUF_MIN_BLK_ENTRIES 32 |
| 70 | #define VNIC_WQ_BUF_DFLT_BLK_ENTRIES 64 |
| 71 | #define VNIC_WQ_BUF_BLK_ENTRIES(entries) \ |
| 72 | ((unsigned int)((entries < VNIC_WQ_BUF_DFLT_BLK_ENTRIES) ? \ |
| 73 | VNIC_WQ_BUF_MIN_BLK_ENTRIES : VNIC_WQ_BUF_DFLT_BLK_ENTRIES)) |
| 74 | #define VNIC_WQ_BUF_BLK_SZ(entries) \ |
| 75 | (VNIC_WQ_BUF_BLK_ENTRIES(entries) * sizeof(struct vnic_wq_buf)) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 76 | #define VNIC_WQ_BUF_BLKS_NEEDED(entries) \ |
Vasanthy Kolluri | b5bab85 | 2010-06-24 10:51:51 +0000 | [diff] [blame] | 77 | DIV_ROUND_UP(entries, VNIC_WQ_BUF_BLK_ENTRIES(entries)) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 78 | #define VNIC_WQ_BUF_BLKS_MAX VNIC_WQ_BUF_BLKS_NEEDED(4096) |
| 79 | |
| 80 | struct vnic_wq { |
| 81 | unsigned int index; |
| 82 | struct vnic_dev *vdev; |
| 83 | struct vnic_wq_ctrl __iomem *ctrl; /* memory-mapped */ |
| 84 | struct vnic_dev_ring ring; |
| 85 | struct vnic_wq_buf *bufs[VNIC_WQ_BUF_BLKS_MAX]; |
| 86 | struct vnic_wq_buf *to_use; |
| 87 | struct vnic_wq_buf *to_clean; |
| 88 | unsigned int pkts_outstanding; |
| 89 | }; |
| 90 | |
Govindarajulu Varadarajan | fda3f52 | 2015-08-16 01:44:53 +0530 | [diff] [blame^] | 91 | struct devcmd2_controller { |
| 92 | struct vnic_wq_ctrl __iomem *wq_ctrl; |
| 93 | struct vnic_devcmd2 *cmd_ring; |
| 94 | struct devcmd2_result *result; |
| 95 | u16 next_result; |
| 96 | u16 result_size; |
| 97 | int color; |
| 98 | struct vnic_dev_ring results_ring; |
| 99 | struct vnic_wq wq; |
| 100 | }; |
| 101 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 102 | static inline unsigned int vnic_wq_desc_avail(struct vnic_wq *wq) |
| 103 | { |
| 104 | /* how many does SW own? */ |
| 105 | return wq->ring.desc_avail; |
| 106 | } |
| 107 | |
| 108 | static inline unsigned int vnic_wq_desc_used(struct vnic_wq *wq) |
| 109 | { |
| 110 | /* how many does HW own? */ |
| 111 | return wq->ring.desc_count - wq->ring.desc_avail - 1; |
| 112 | } |
| 113 | |
| 114 | static inline void *vnic_wq_next_desc(struct vnic_wq *wq) |
| 115 | { |
| 116 | return wq->to_use->desc; |
| 117 | } |
| 118 | |
Govindarajulu Varadarajan | f8e34d2 | 2014-11-19 12:59:32 +0530 | [diff] [blame] | 119 | static inline void vnic_wq_doorbell(struct vnic_wq *wq) |
| 120 | { |
| 121 | /* Adding write memory barrier prevents compiler and/or CPU |
| 122 | * reordering, thus avoiding descriptor posting before |
| 123 | * descriptor is initialized. Otherwise, hardware can read |
| 124 | * stale descriptor fields. |
| 125 | */ |
| 126 | wmb(); |
| 127 | iowrite32(wq->to_use->index, &wq->ctrl->posted_index); |
| 128 | } |
| 129 | |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 130 | static inline void vnic_wq_post(struct vnic_wq *wq, |
| 131 | void *os_buf, dma_addr_t dma_addr, |
Neel Patel | 92e2b46 | 2013-08-16 15:47:39 -0700 | [diff] [blame] | 132 | unsigned int len, int sop, int eop, |
| 133 | uint8_t desc_skip_cnt, uint8_t cq_entry, |
| 134 | uint8_t compressed_send, uint64_t wrid) |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 135 | { |
| 136 | struct vnic_wq_buf *buf = wq->to_use; |
| 137 | |
| 138 | buf->sop = sop; |
Neel Patel | 92e2b46 | 2013-08-16 15:47:39 -0700 | [diff] [blame] | 139 | buf->cq_entry = cq_entry; |
| 140 | buf->compressed_send = compressed_send; |
| 141 | buf->desc_skip_cnt = desc_skip_cnt; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 142 | buf->os_buf = eop ? os_buf : NULL; |
| 143 | buf->dma_addr = dma_addr; |
| 144 | buf->len = len; |
Neel Patel | 92e2b46 | 2013-08-16 15:47:39 -0700 | [diff] [blame] | 145 | buf->wr_id = wrid; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 146 | |
| 147 | buf = buf->next; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 148 | wq->to_use = buf; |
| 149 | |
Neel Patel | 92e2b46 | 2013-08-16 15:47:39 -0700 | [diff] [blame] | 150 | wq->ring.desc_avail -= desc_skip_cnt; |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | static inline void vnic_wq_service(struct vnic_wq *wq, |
| 154 | struct cq_desc *cq_desc, u16 completed_index, |
| 155 | void (*buf_service)(struct vnic_wq *wq, |
| 156 | struct cq_desc *cq_desc, struct vnic_wq_buf *buf, void *opaque), |
| 157 | void *opaque) |
| 158 | { |
| 159 | struct vnic_wq_buf *buf; |
| 160 | |
| 161 | buf = wq->to_clean; |
| 162 | while (1) { |
| 163 | |
| 164 | (*buf_service)(wq, cq_desc, buf, opaque); |
| 165 | |
| 166 | wq->ring.desc_avail++; |
| 167 | |
| 168 | wq->to_clean = buf->next; |
| 169 | |
| 170 | if (buf->index == completed_index) |
| 171 | break; |
| 172 | |
| 173 | buf = wq->to_clean; |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void vnic_wq_free(struct vnic_wq *wq); |
| 178 | int vnic_wq_alloc(struct vnic_dev *vdev, struct vnic_wq *wq, unsigned int index, |
| 179 | unsigned int desc_count, unsigned int desc_size); |
Scott Feldman | 01f2e4e | 2008-09-15 09:17:11 -0700 | [diff] [blame] | 180 | void vnic_wq_init(struct vnic_wq *wq, unsigned int cq_index, |
| 181 | unsigned int error_interrupt_enable, |
| 182 | unsigned int error_interrupt_offset); |
| 183 | unsigned int vnic_wq_error_status(struct vnic_wq *wq); |
| 184 | void vnic_wq_enable(struct vnic_wq *wq); |
| 185 | int vnic_wq_disable(struct vnic_wq *wq); |
| 186 | void vnic_wq_clean(struct vnic_wq *wq, |
| 187 | void (*buf_clean)(struct vnic_wq *wq, struct vnic_wq_buf *buf)); |
| 188 | |
| 189 | #endif /* _VNIC_WQ_H_ */ |