b0191093523ba9d212d4feb619e8fdd2ddbe7e9c
[deb_dpdk.git] / drivers / net / enic / base / enic_vnic_wq.h
1 /*
2  * Copyright 2008-2015 Cisco Systems, Inc.  All rights reserved.
3  * Copyright 2007 Nuova Systems, Inc.  All rights reserved.
4  *
5  * Copyright (c) 2015, Cisco Systems, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
25  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
26  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
28  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
30  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31  * POSSIBILITY OF SUCH DAMAGE.
32  *
33  */
34
35 #ifndef _ENIC_VNIC_WQ_H_
36 #define _ENIC_VNIC_WQ_H_
37
38 #include "vnic_dev.h"
39 #include "vnic_cq.h"
40
41 static inline void enic_vnic_post_wq_index(struct vnic_wq *wq)
42 {
43         struct vnic_wq_buf *buf = wq->to_use;
44
45         /* Adding write memory barrier prevents compiler and/or CPU
46          * reordering, thus avoiding descriptor posting before
47          * descriptor is initialized. Otherwise, hardware can read
48          * stale descriptor fields.
49         */
50         wmb();
51         iowrite32(buf->index, &wq->ctrl->posted_index);
52 }
53
54 static inline void enic_vnic_post_wq(struct vnic_wq *wq,
55                                      void *os_buf, dma_addr_t dma_addr,
56                                      unsigned int len, int sop,
57                                      uint8_t desc_skip_cnt, uint8_t cq_entry,
58                                      uint8_t compressed_send, uint64_t wrid)
59 {
60         struct vnic_wq_buf *buf = wq->to_use;
61
62         buf->sop = sop;
63         buf->cq_entry = cq_entry;
64         buf->compressed_send = compressed_send;
65         buf->desc_skip_cnt = desc_skip_cnt;
66         buf->os_buf = os_buf;
67         buf->dma_addr = dma_addr;
68         buf->len = len;
69         buf->wr_id = wrid;
70
71         buf = buf->next;
72         wq->ring.desc_avail -= desc_skip_cnt;
73         wq->to_use = buf;
74
75         if (cq_entry)
76                 enic_vnic_post_wq_index(wq);
77 }
78
79 #endif /* _ENIC_VNIC_WQ_H_ */