1 /*
2 * Copyright (c) 2017-2018 Cavium, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29 #ifndef __ECORE_OOO_H__
30 #define __ECORE_OOO_H__
31
32 #include "ecore.h"
33
34 #define ECORE_MAX_NUM_ISLES 256
35 #define ECORE_MAX_NUM_OOO_HISTORY_ENTRIES 512
36
37 #define ECORE_OOO_LEFT_BUF 0
38 #define ECORE_OOO_RIGHT_BUF 1
39
40 struct ecore_ooo_buffer {
41 osal_list_entry_t list_entry;
42 void *rx_buffer_virt_addr;
43 dma_addr_t rx_buffer_phys_addr;
44 u32 rx_buffer_size;
45 u16 packet_length;
46 u16 parse_flags;
47 u16 vlan;
48 u8 placement_offset;
49 };
50
51 struct ecore_ooo_isle {
52 osal_list_entry_t list_entry;
53 osal_list_t buffers_list;
54 };
55
56 struct ecore_ooo_archipelago {
57 osal_list_t isles_list;
58 };
59
60 struct ecore_ooo_history {
61 struct ooo_opaque *p_cqes;
62 u32 head_idx;
63 u32 num_of_cqes;
64 };
65
66 struct ecore_ooo_info {
67 osal_list_t free_buffers_list;
68 osal_list_t ready_buffers_list;
69 osal_list_t free_isles_list;
70 struct ecore_ooo_archipelago *p_archipelagos_mem;
71 struct ecore_ooo_isle *p_isles_mem;
72 struct ecore_ooo_history ooo_history;
73 u32 cur_isles_number;
74 u32 max_isles_number;
75 u32 gen_isles_number;
76 u16 max_num_archipelagos;
77 u16 cid_base;
78 };
79
80 #if defined(CONFIG_ECORE_ISCSI) || defined(CONFIG_ECORE_IWARP)
81 enum _ecore_status_t ecore_ooo_alloc(struct ecore_hwfn *p_hwfn);
82
83 void ecore_ooo_setup(struct ecore_hwfn *p_hwfn);
84
85 void ecore_ooo_free(struct ecore_hwfn *p_hwfn);
86 #else
87 static inline enum _ecore_status_t
ecore_ooo_alloc(struct ecore_hwfn OSAL_UNUSED * p_hwfn)88 ecore_ooo_alloc(struct ecore_hwfn OSAL_UNUSED *p_hwfn)
89 {
90 return ECORE_INVAL;
91 }
92
93 static inline void
ecore_ooo_setup(struct ecore_hwfn OSAL_UNUSED * p_hwfn)94 ecore_ooo_setup(struct ecore_hwfn OSAL_UNUSED *p_hwfn) {}
95
96 static inline void
ecore_ooo_free(struct ecore_hwfn OSAL_UNUSED * p_hwfn)97 ecore_ooo_free(struct ecore_hwfn OSAL_UNUSED *p_hwfn) {}
98 #endif
99
100 void ecore_ooo_save_history_entry(struct ecore_ooo_info *p_ooo_info,
101 struct ooo_opaque *p_cqe);
102
103 void ecore_ooo_release_connection_isles(struct ecore_ooo_info *p_ooo_info,
104 u32 cid);
105
106 void ecore_ooo_release_all_isles(struct ecore_ooo_info *p_ooo_info);
107
108 void ecore_ooo_put_free_buffer(struct ecore_ooo_info *p_ooo_info,
109 struct ecore_ooo_buffer *p_buffer);
110
111 struct ecore_ooo_buffer *
112 ecore_ooo_get_free_buffer(struct ecore_ooo_info *p_ooo_info);
113
114 void ecore_ooo_put_ready_buffer(struct ecore_ooo_info *p_ooo_info,
115 struct ecore_ooo_buffer *p_buffer, u8 on_tail);
116
117 struct ecore_ooo_buffer *
118 ecore_ooo_get_ready_buffer(struct ecore_ooo_info *p_ooo_info);
119
120 void ecore_ooo_delete_isles(struct ecore_hwfn *p_hwfn,
121 struct ecore_ooo_info *p_ooo_info,
122 u32 cid,
123 u8 drop_isle,
124 u8 drop_size);
125
126 void ecore_ooo_add_new_isle(struct ecore_hwfn *p_hwfn,
127 struct ecore_ooo_info *p_ooo_info,
128 u32 cid,
129 u8 ooo_isle,
130 struct ecore_ooo_buffer *p_buffer);
131
132 void ecore_ooo_add_new_buffer(struct ecore_hwfn *p_hwfn,
133 struct ecore_ooo_info *p_ooo_info,
134 u32 cid,
135 u8 ooo_isle,
136 struct ecore_ooo_buffer *p_buffer,
137 u8 buffer_side);
138
139 void ecore_ooo_join_isles(struct ecore_hwfn *p_hwfn,
140 struct ecore_ooo_info *p_ooo_info,
141 u32 cid,
142 u8 left_isle);
143
144 void ecore_ooo_dump_rx_event(struct ecore_hwfn *p_hwfn,
145 struct ooo_opaque *iscsi_ooo,
146 struct ecore_ooo_buffer *p_buffer);
147
148 #endif /*__ECORE_OOO_H__*/
149