net/memif: enable loopback
[dpdk.git] / drivers / net / bnx2x / ecore_sp.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright (c) 2007-2013 Broadcom Corporation.
3  *
4  * Eric Davis        <edavis@broadcom.com>
5  * David Christensen <davidch@broadcom.com>
6  * Gary Zambrano     <zambrano@broadcom.com>
7  *
8  * Copyright (c) 2013-2015 Brocade Communications Systems, Inc.
9  * Copyright (c) 2015-2018 Cavium Inc.
10  * All rights reserved.
11  * www.cavium.com
12  */
13
14 #ifndef ECORE_SP_H
15 #define ECORE_SP_H
16
17 #include <rte_byteorder.h>
18
19 #if RTE_BYTE_ORDER == RTE_LITTLE_ENDIAN
20 #ifndef __LITTLE_ENDIAN
21 #define __LITTLE_ENDIAN RTE_LITTLE_ENDIAN
22 #endif
23 #undef __BIG_ENDIAN
24 #elif RTE_BYTE_ORDER == RTE_BIG_ENDIAN
25 #ifndef __BIG_ENDIAN
26 #define __BIG_ENDIAN    RTE_BIG_ENDIAN
27 #endif
28 #undef __LITTLE_ENDIAN
29 #endif
30
31 #include "ecore_mfw_req.h"
32 #include "ecore_fw_defs.h"
33 #include "ecore_hsi.h"
34 #include "ecore_reg.h"
35
36 struct bnx2x_softc;
37 typedef rte_iova_t ecore_dma_addr_t; /* expected to be 64 bit wide */
38 typedef volatile int ecore_atomic_t;
39
40
41 #define ETH_ALEN RTE_ETHER_ADDR_LEN /* 6 */
42
43 #define ECORE_SWCID_SHIFT   17
44 #define ECORE_SWCID_MASK    ((0x1 << ECORE_SWCID_SHIFT) - 1)
45
46 #define ECORE_MC_HASH_SIZE 8
47 #define ECORE_MC_HASH_OFFSET(sc, i)                                          \
48     (BAR_TSTRORM_INTMEM +                                                    \
49      TSTORM_APPROXIMATE_MATCH_MULTICAST_FILTERING_OFFSET(FUNC_ID(sc)) + i*4)
50
51 #define ECORE_MAX_MULTICAST   64
52 #define ECORE_MAX_EMUL_MULTI  1
53
54 #define IRO sc->iro_array
55
56 typedef rte_spinlock_t ECORE_MUTEX;
57 #define ECORE_MUTEX_INIT(_mutex)           rte_spinlock_init(_mutex)
58 #define ECORE_MUTEX_LOCK(_mutex)           rte_spinlock_lock(_mutex)
59 #define ECORE_MUTEX_UNLOCK(_mutex)         rte_spinlock_unlock(_mutex)
60
61 typedef rte_spinlock_t ECORE_MUTEX_SPIN;
62 #define ECORE_SPIN_LOCK_INIT(_spin, _sc)   rte_spinlock_init(_spin)
63 #define ECORE_SPIN_LOCK_BH(_spin)          rte_spinlock_lock(_spin) /* bh = bottom-half */
64 #define ECORE_SPIN_UNLOCK_BH(_spin)        rte_spinlock_unlock(_spin) /* bh = bottom-half */
65
66 #define ECORE_SMP_MB_AFTER_CLEAR_BIT()     mb()
67 #define ECORE_SMP_MB_BEFORE_CLEAR_BIT()    mb()
68 #define ECORE_SMP_MB()                     mb()
69 #define ECORE_SMP_RMB()                    rmb()
70 #define ECORE_SMP_WMB()                    wmb()
71 #define ECORE_MMIOWB()                     wmb()
72
73 #define ECORE_SET_BIT_NA(bit, var)         (*var |= (1 << bit))
74 #define ECORE_CLEAR_BIT_NA(bit, var)       (*var &= ~(1 << bit))
75
76 #define ECORE_TEST_BIT(bit, var)           bnx2x_test_bit(bit, var)
77 #define ECORE_SET_BIT(bit, var)            bnx2x_set_bit(bit, var)
78 #define ECORE_CLEAR_BIT(bit, var)          bnx2x_clear_bit(bit, var)
79 #define ECORE_TEST_AND_CLEAR_BIT(bit, var) bnx2x_test_and_clear_bit(bit, var)
80
81 #define atomic_load_acq_int                (int)*
82 #define atomic_store_rel_int(a, v)         (*a = v)
83 #define atomic_cmpset_acq_int(a, o, n)     ((*a = (o & (n)) | (n)) ^ o)
84
85 #define atomic_load_acq_long               (long)*
86 #define atomic_store_rel_long(a, v)        (*a = v)
87 #define atomic_set_acq_long(a, v)          (*a |= v)
88 #define atomic_clear_acq_long(a, v)        (*a &= ~v)
89 #define atomic_cmpset_acq_long(a, o, n)    ((*a = (o & (n)) | (n)) ^ o)
90 #define atomic_subtract_acq_long(a, v)     (*a -= v)
91 #define atomic_add_acq_long(a, v)          (*a += v)
92
93 #define ECORE_ATOMIC_READ(a) atomic_load_acq_int((volatile int *)a)
94 #define ECORE_ATOMIC_SET(a, v) atomic_store_rel_int((volatile int *)a, v)
95 #define ECORE_ATOMIC_CMPXCHG(a, o, n) bnx2x_cmpxchg((volatile int *)a, o, n)
96
97 #define ECORE_RET_PENDING(pending_bit, pending) \
98     (ECORE_TEST_BIT(pending_bit, pending) ? ECORE_PENDING : ECORE_SUCCESS)
99
100 #define ECORE_SET_FLAG(value, mask, flag)      \
101     do {                                       \
102         (value) &= ~(mask);                    \
103         (value) |= ((flag) << (mask##_SHIFT)); \
104     } while (0)
105
106 #define ECORE_GET_FLAG(value, mask) \
107     (((value) &= (mask)) >> (mask##_SHIFT))
108
109 #define ECORE_MIGHT_SLEEP()
110
111 #define ECORE_FCOE_CID(sc) ((sc)->fp[FCOE_IDX(sc)].cl_id)
112
113 #define ECORE_MEMCMP(_a, _b, _s) memcmp(_a, _b, _s)
114 #define ECORE_MEMCPY(_a, _b, _s) rte_memcpy(_a, _b, _s)
115 #define ECORE_MEMSET(_a, _c, _s) memset(_a, _c, _s)
116
117 #define ECORE_CPU_TO_LE16(x) htole16(x)
118 #define ECORE_CPU_TO_LE32(x) htole32(x)
119
120 #define ECORE_WAIT(_s, _t) DELAY(1000)
121 #define ECORE_MSLEEP(_t)   DELAY((_t) * 1000)
122
123 #define ECORE_LIKELY(x)   likely(x)
124 #define ECORE_UNLIKELY(x) unlikely(x)
125
126 #define ECORE_ZALLOC(_size, _flags, _sc) \
127     rte_zmalloc("", _size, RTE_CACHE_LINE_SIZE)
128
129 #define ECORE_CALLOC(_len, _size, _flags, _sc) \
130     rte_calloc("", _len, _size, RTE_CACHE_LINE_SIZE)
131
132 #define ECORE_FREE(_s, _buf, _size) \
133     rte_free(_buf)
134
135 #define SC_ILT(sc)  ((sc)->ilt)
136 #define ILOG2(x)    bnx2x_ilog2(x)
137
138 #define ECORE_ILT_ZALLOC(x, y, size)                            \
139         do {                                                            \
140                 x = rte_malloc("", sizeof(struct bnx2x_dma), RTE_CACHE_LINE_SIZE); \
141                 if (x) {                                                \
142                         if (bnx2x_dma_alloc((struct bnx2x_softc *)sc,   \
143                                           size, (struct bnx2x_dma *)x,  \
144                                           "ILT", RTE_CACHE_LINE_SIZE) != 0) { \
145                                 rte_free(x);                            \
146                                 x = NULL;                               \
147                                 *(y) = 0;                               \
148                         } else {                                        \
149                                 *y = ((struct bnx2x_dma *)x)->paddr;    \
150                         }                                               \
151                 }                                                       \
152         } while (0)
153
154 #define ECORE_ILT_FREE(x, y, size)                                      \
155         do {                                                            \
156                 if (x) {                                                \
157                         bnx2x_dma_free((struct bnx2x_dma *)x);          \
158                         rte_free(x);                                    \
159                         x = NULL;                                       \
160                         y = 0;                                          \
161                 }                                                       \
162         } while (0)
163
164 #define ECORE_IS_VALID_ETHER_ADDR(_mac) true
165
166 #define ECORE_IS_MF_SD_MODE   IS_MF_SD_MODE
167 #define ECORE_IS_MF_SI_MODE   IS_MF_SI_MODE
168 #define ECORE_IS_MF_AFEX_MODE IS_MF_AFEX_MODE
169
170 #define ECORE_SET_CTX_VALIDATION bnx2x_set_ctx_validation
171
172 #define ECORE_UPDATE_COALESCE_SB_INDEX bnx2x_update_coalesce_sb_index
173
174 #define ECORE_ALIGN(x, a) ((((x) + (a) - 1) / (a)) * (a))
175
176 #define ECORE_REG_WR_DMAE_LEN REG_WR_DMAE_LEN
177
178 #define ECORE_PATH_ID     SC_PATH
179 #define ECORE_PORT_ID     SC_PORT
180 #define ECORE_FUNC_ID     SC_FUNC
181 #define ECORE_ABS_FUNC_ID SC_ABS_FUNC
182
183 #define CRCPOLY_LE 0xedb88320
184 uint32_t ecore_calc_crc32(uint32_t crc, uint8_t const *p,
185                           uint32_t len, uint32_t magic);
186
187 uint8_t ecore_calc_crc8(uint32_t data, uint8_t crc);
188
189
190 static inline uint32_t
191 ECORE_CRC32_LE(uint32_t seed, uint8_t *mac, uint32_t len)
192 {
193         return ecore_calc_crc32(seed, mac, len, CRCPOLY_LE);
194 }
195
196 #define ecore_sp_post(_sc, _a, _b, _c, _d) \
197     bnx2x_sp_post(_sc, _a, _b, U64_HI(_c), U64_LO(_c), _d)
198
199 #define ECORE_DBG_BREAK_IF(exp)     \
200     do {                            \
201         if (unlikely(exp)) {        \
202             rte_panic("ECORE");     \
203         }                           \
204     } while (0)
205
206 #define ECORE_BUG()                                   \
207     do {                                              \
208         rte_panic("BUG (%s:%d)", __FILE__, __LINE__); \
209     } while(0);
210
211 #define ECORE_BUG_ON(exp)                                    \
212     do {                                                     \
213         if (likely(exp)) {                                   \
214             rte_panic("BUG_ON (%s:%d)", __FILE__, __LINE__); \
215         }                                                    \
216     } while (0)
217
218
219 #define ECORE_MSG(sc, m, ...) \
220         PMD_DRV_LOG(DEBUG, sc, m, ##__VA_ARGS__)
221
222 typedef struct _ecore_list_entry_t
223 {
224     struct _ecore_list_entry_t *next, *prev;
225 } ecore_list_entry_t;
226
227 typedef struct ecore_list_t
228 {
229     ecore_list_entry_t *head, *tail;
230     unsigned long cnt;
231 } ecore_list_t;
232
233 /* initialize the list */
234 #define ECORE_LIST_INIT(_list) \
235     do {                       \
236         (_list)->head = NULL;  \
237         (_list)->tail = NULL;  \
238         (_list)->cnt  = 0;     \
239     } while (0)
240
241 /* return true if the element is the last on the list */
242 #define ECORE_LIST_IS_LAST(_elem, _list) \
243     (_elem == (_list)->tail)
244
245 /* return true if the list is empty */
246 #define ECORE_LIST_IS_EMPTY(_list) \
247     ((_list)->cnt == 0)
248
249 /* return the first element */
250 #define ECORE_LIST_FIRST_ENTRY(_list, cast, _link) \
251     (cast *)((_list)->head)
252
253 /* return the next element */
254 #define ECORE_LIST_NEXT(_elem, _link, cast) \
255     (cast *)((&((_elem)->_link))->next)
256
257 /* push an element on the head of the list */
258 #define ECORE_LIST_PUSH_HEAD(_elem, _list)              \
259     do {                                                \
260         (_elem)->prev = (ecore_list_entry_t *)0;        \
261         (_elem)->next = (_list)->head;                  \
262         if ((_list)->tail == (ecore_list_entry_t *)0) { \
263             (_list)->tail = (_elem);                    \
264         } else {                                        \
265             (_list)->head->prev = (_elem);              \
266         }                                               \
267         (_list)->head = (_elem);                        \
268         (_list)->cnt++;                                 \
269     } while (0)
270
271 /* push an element on the tail of the list */
272 #define ECORE_LIST_PUSH_TAIL(_elem, _list)       \
273     do {                                         \
274         (_elem)->next = (ecore_list_entry_t *)0; \
275         (_elem)->prev = (_list)->tail;           \
276         if ((_list)->tail) {                     \
277             (_list)->tail->next = (_elem);       \
278         } else {                                 \
279             (_list)->head = (_elem);             \
280         }                                        \
281         (_list)->tail = (_elem);                 \
282         (_list)->cnt++;                          \
283     } while (0)
284
285 /* push list1 on the head of list2 and return with list1 as empty */
286 #define ECORE_LIST_SPLICE_INIT(_list1, _list2)     \
287     do {                                           \
288         (_list1)->tail->next = (_list2)->head;     \
289         if ((_list2)->head) {                      \
290             (_list2)->head->prev = (_list1)->tail; \
291         } else {                                   \
292             (_list2)->tail = (_list1)->tail;       \
293         }                                          \
294         (_list2)->head = (_list1)->head;           \
295         (_list2)->cnt += (_list1)->cnt;            \
296         (_list1)->head = NULL;                     \
297         (_list1)->tail = NULL;                     \
298         (_list1)->cnt  = 0;                        \
299     } while (0)
300
301 /* remove an element from the list */
302 #define ECORE_LIST_REMOVE_ENTRY(_elem, _list)                      \
303     do {                                                           \
304         if ((_list)->head == (_elem)) {                            \
305             if ((_list)->head) {                                   \
306                 (_list)->head = (_list)->head->next;               \
307                 if ((_list)->head) {                               \
308                     (_list)->head->prev = (ecore_list_entry_t *)0; \
309                 } else {                                           \
310                     (_list)->tail = (ecore_list_entry_t *)0;       \
311                 }                                                  \
312                 (_list)->cnt--;                                    \
313             }                                                      \
314         } else if ((_list)->tail == (_elem)) {                     \
315             if ((_list)->tail) {                                   \
316                 (_list)->tail = (_list)->tail->prev;               \
317                 if ((_list)->tail) {                               \
318                     (_list)->tail->next = (ecore_list_entry_t *)0; \
319                 } else {                                           \
320                     (_list)->head = (ecore_list_entry_t *)0;       \
321                 }                                                  \
322                 (_list)->cnt--;                                    \
323             }                                                      \
324         } else {                                                   \
325             (_elem)->prev->next = (_elem)->next;                   \
326             (_elem)->next->prev = (_elem)->prev;                   \
327             (_list)->cnt--;                                        \
328         }                                                          \
329     } while (0)
330
331 /* walk the list */
332 #define ECORE_LIST_FOR_EACH_ENTRY(pos, _list, _link, cast) \
333     for (pos = ECORE_LIST_FIRST_ENTRY(_list, cast, _link); \
334          pos;                                              \
335          pos = ECORE_LIST_NEXT(pos, _link, cast))
336
337 /* walk the list (safely) */
338 #define ECORE_LIST_FOR_EACH_ENTRY_SAFE(pos, n, _list, _link, cast) \
339      for (pos = ECORE_LIST_FIRST_ENTRY(_list, cast, _lint),        \
340           n = (pos) ? ECORE_LIST_NEXT(pos, _link, cast) : NULL;    \
341           pos != NULL;                                             \
342           pos = (cast *)n,                                         \
343           n = (pos) ? ECORE_LIST_NEXT(pos, _link, cast) : NULL)
344
345
346 /* Manipulate a bit vector defined as an array of uint64_t */
347
348 /* Number of bits in one sge_mask array element */
349 #define BIT_VEC64_ELEM_SZ     64
350 #define BIT_VEC64_ELEM_SHIFT  6
351 #define BIT_VEC64_ELEM_MASK   ((uint64_t)BIT_VEC64_ELEM_SZ - 1)
352
353 #define __BIT_VEC64_SET_BIT(el, bit)            \
354     do {                                        \
355         el = ((el) | ((uint64_t)0x1 << (bit))); \
356     } while (0)
357
358 #define __BIT_VEC64_CLEAR_BIT(el, bit)             \
359     do {                                           \
360         el = ((el) & (~((uint64_t)0x1 << (bit)))); \
361     } while (0)
362
363 #define BIT_VEC64_SET_BIT(vec64, idx)                           \
364     __BIT_VEC64_SET_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
365                         (idx) & BIT_VEC64_ELEM_MASK)
366
367 #define BIT_VEC64_CLEAR_BIT(vec64, idx)                           \
368     __BIT_VEC64_CLEAR_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
369                           (idx) & BIT_VEC64_ELEM_MASK)
370
371 #define BIT_VEC64_TEST_BIT(vec64, idx)          \
372     (((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT] >> \
373       ((idx) & BIT_VEC64_ELEM_MASK)) & 0x1)
374
375 /*
376  * Creates a bitmask of all ones in less significant bits.
377  * idx - index of the most significant bit in the created mask
378  */
379 #define BIT_VEC64_ONES_MASK(idx)                                 \
380     (((uint64_t)0x1 << (((idx) & BIT_VEC64_ELEM_MASK) + 1)) - 1)
381 #define BIT_VEC64_ELEM_ONE_MASK ((uint64_t)(~0))
382
383 /* fill in a MAC address the way the FW likes it */
384 static inline void
385 ecore_set_fw_mac_addr(uint16_t *fw_hi,
386                       uint16_t *fw_mid,
387                       uint16_t *fw_lo,
388                       uint8_t  *mac)
389 {
390     ((uint8_t *)fw_hi)[0]  = mac[1];
391     ((uint8_t *)fw_hi)[1]  = mac[0];
392     ((uint8_t *)fw_mid)[0] = mac[3];
393     ((uint8_t *)fw_mid)[1] = mac[2];
394     ((uint8_t *)fw_lo)[0]  = mac[5];
395     ((uint8_t *)fw_lo)[1]  = mac[4];
396 }
397
398
399 enum ecore_status_t {
400     ECORE_EXISTS  = -6,
401     ECORE_IO      = -5,
402     ECORE_TIMEOUT = -4,
403     ECORE_INVAL   = -3,
404     ECORE_BUSY    = -2,
405     ECORE_NOMEM   = -1,
406     ECORE_SUCCESS = 0,
407     /* PENDING is not an error and should be positive */
408     ECORE_PENDING = 1,
409 };
410
411 enum {
412     SWITCH_UPDATE,
413     AFEX_UPDATE,
414 };
415
416 struct bnx2x_softc;
417 struct eth_context;
418
419 /* Bits representing general command's configuration */
420 enum {
421         RAMROD_TX,
422         RAMROD_RX,
423         /* Wait until all pending commands complete */
424         RAMROD_COMP_WAIT,
425         /* Don't send a ramrod, only update a registry */
426         RAMROD_DRV_CLR_ONLY,
427         /* Configure HW according to the current object state */
428         RAMROD_RESTORE,
429          /* Execute the next command now */
430         RAMROD_EXEC,
431         /* Don't add a new command and continue execution of posponed
432          * commands. If not set a new command will be added to the
433          * pending commands list.
434          */
435         RAMROD_CONT,
436         /* If there is another pending ramrod, wait until it finishes and
437          * re-try to submit this one. This flag can be set only in sleepable
438          * context, and should not be set from the context that completes the
439          * ramrods as deadlock will occur.
440          */
441         RAMROD_RETRY,
442 };
443
444 typedef enum {
445         ECORE_OBJ_TYPE_RX,
446         ECORE_OBJ_TYPE_TX,
447         ECORE_OBJ_TYPE_RX_TX,
448 } ecore_obj_type;
449
450 /* Public slow path states */
451 enum {
452         ECORE_FILTER_MAC_PENDING,
453         ECORE_FILTER_VLAN_PENDING,
454         ECORE_FILTER_VLAN_MAC_PENDING,
455         ECORE_FILTER_RX_MODE_PENDING,
456         ECORE_FILTER_RX_MODE_SCHED,
457         ECORE_FILTER_ISCSI_ETH_START_SCHED,
458         ECORE_FILTER_ISCSI_ETH_STOP_SCHED,
459         ECORE_FILTER_FCOE_ETH_START_SCHED,
460         ECORE_FILTER_FCOE_ETH_STOP_SCHED,
461 #ifdef ECORE_CHAR_DEV
462         ECORE_FILTER_BYPASS_RX_MODE_PENDING,
463         ECORE_FILTER_BYPASS_MAC_PENDING,
464         ECORE_FILTER_BYPASS_RSS_CONF_PENDING,
465 #endif
466         ECORE_FILTER_MCAST_PENDING,
467         ECORE_FILTER_MCAST_SCHED,
468         ECORE_FILTER_RSS_CONF_PENDING,
469         ECORE_AFEX_FCOE_Q_UPDATE_PENDING,
470         ECORE_AFEX_PENDING_VIFSET_MCP_ACK,
471         ECORE_FILTER_VXLAN_PENDING,
472         ECORE_FILTER_PVLAN_PENDING
473 };
474
475 struct ecore_raw_obj {
476         uint8_t         func_id;
477
478         /* Queue params */
479         uint8_t         cl_id;
480         uint32_t                cid;
481
482         /* Ramrod data buffer params */
483         void            *rdata;
484         ecore_dma_addr_t        rdata_mapping;
485
486         /* Ramrod state params */
487         int             state;   /* "ramrod is pending" state bit */
488         unsigned long   *pstate; /* pointer to state buffer */
489
490         ecore_obj_type  obj_type;
491
492         int (*wait_comp)(struct bnx2x_softc *sc,
493                          struct ecore_raw_obj *o);
494
495         bool (*check_pending)(struct ecore_raw_obj *o);
496         void (*clear_pending)(struct ecore_raw_obj *o);
497         void (*set_pending)(struct ecore_raw_obj *o);
498 };
499
500 /************************* VLAN-MAC commands related parameters ***************/
501 struct ecore_mac_ramrod_data {
502         uint8_t mac[ETH_ALEN];
503         uint8_t is_inner_mac;
504 };
505
506 struct ecore_vlan_ramrod_data {
507         uint16_t vlan;
508 };
509
510 struct ecore_vlan_mac_ramrod_data {
511         uint8_t mac[ETH_ALEN];
512         uint8_t is_inner_mac;
513         uint16_t vlan;
514 };
515
516 struct ecore_vxlan_fltr_ramrod_data {
517         uint8_t innermac[ETH_ALEN];
518         uint32_t vni;
519 };
520
521 union ecore_classification_ramrod_data {
522         struct ecore_mac_ramrod_data mac;
523         struct ecore_vlan_ramrod_data vlan;
524         struct ecore_vlan_mac_ramrod_data vlan_mac;
525         struct ecore_vxlan_fltr_ramrod_data vxlan_fltr;
526 };
527
528 /* VLAN_MAC commands */
529 enum ecore_vlan_mac_cmd {
530         ECORE_VLAN_MAC_ADD,
531         ECORE_VLAN_MAC_DEL,
532         ECORE_VLAN_MAC_MOVE,
533 };
534
535 struct ecore_vlan_mac_data {
536         /* Requested command: ECORE_VLAN_MAC_XX */
537         enum ecore_vlan_mac_cmd cmd;
538         /* used to contain the data related vlan_mac_flags bits from
539          * ramrod parameters.
540          */
541         unsigned long vlan_mac_flags;
542
543         /* Needed for MOVE command */
544         struct ecore_vlan_mac_obj *target_obj;
545
546         union ecore_classification_ramrod_data u;
547 };
548
549 /*************************** Exe Queue obj ************************************/
550 union ecore_exe_queue_cmd_data {
551         struct ecore_vlan_mac_data vlan_mac;
552
553         struct {
554                 /* TODO */
555         } mcast;
556 };
557
558 struct ecore_exeq_elem {
559         ecore_list_entry_t              link;
560
561         /* Length of this element in the exe_chunk. */
562         int                             cmd_len;
563
564         union ecore_exe_queue_cmd_data  cmd_data;
565 };
566
567 union ecore_qable_obj;
568
569 union ecore_exeq_comp_elem {
570         union event_ring_elem *elem;
571 };
572
573 struct ecore_exe_queue_obj;
574
575 typedef int (*exe_q_validate)(struct bnx2x_softc *sc,
576                               union ecore_qable_obj *o,
577                               struct ecore_exeq_elem *elem);
578
579 typedef int (*exe_q_remove)(struct bnx2x_softc *sc,
580                             union ecore_qable_obj *o,
581                             struct ecore_exeq_elem *elem);
582
583 /* Return positive if entry was optimized, 0 - if not, negative
584  * in case of an error.
585  */
586 typedef int (*exe_q_optimize)(struct bnx2x_softc *sc,
587                               union ecore_qable_obj *o,
588                               struct ecore_exeq_elem *elem);
589 typedef int (*exe_q_execute)(struct bnx2x_softc *sc,
590                              union ecore_qable_obj *o,
591                              ecore_list_t *exe_chunk,
592                              unsigned long *ramrod_flags);
593 typedef struct ecore_exeq_elem *
594                         (*exe_q_get)(struct ecore_exe_queue_obj *o,
595                                      struct ecore_exeq_elem *elem);
596
597 struct ecore_exe_queue_obj {
598         /* Commands pending for an execution. */
599         ecore_list_t    exe_queue;
600
601         /* Commands pending for an completion. */
602         ecore_list_t    pending_comp;
603
604         ECORE_MUTEX_SPIN                lock;
605
606         /* Maximum length of commands' list for one execution */
607         int                     exe_chunk_len;
608
609         union ecore_qable_obj   *owner;
610
611         /****** Virtual functions ******/
612         /**
613          * Called before commands execution for commands that are really
614          * going to be executed (after 'optimize').
615          *
616          * Must run under exe_queue->lock
617          */
618         exe_q_validate          validate;
619
620         /**
621          * Called before removing pending commands, cleaning allocated
622          * resources (e.g., credits from validate)
623          */
624          exe_q_remove           remove;
625
626         /**
627          * This will try to cancel the current pending commands list
628          * considering the new command.
629          *
630          * Returns the number of optimized commands or a negative error code
631          *
632          * Must run under exe_queue->lock
633          */
634         exe_q_optimize          optimize;
635
636         /**
637          * Run the next commands chunk (owner specific).
638          */
639         exe_q_execute           execute;
640
641         /**
642          * Return the exe_queue element containing the specific command
643          * if any. Otherwise return NULL.
644          */
645         exe_q_get               get;
646 };
647 /***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
648 /*
649  * Element in the VLAN_MAC registry list having all current configured
650  * rules.
651  */
652 struct ecore_vlan_mac_registry_elem {
653         ecore_list_entry_t      link;
654
655         /* Used to store the cam offset used for the mac/vlan/vlan-mac.
656          * Relevant for 57710 and 57711 only. VLANs and MACs share the
657          * same CAM for these chips.
658          */
659         int                     cam_offset;
660
661         /* Needed for DEL and RESTORE flows */
662         unsigned long           vlan_mac_flags;
663
664         union ecore_classification_ramrod_data u;
665 };
666
667 /* Bits representing VLAN_MAC commands specific flags */
668 enum {
669         ECORE_UC_LIST_MAC,
670         ECORE_ETH_MAC,
671         ECORE_ISCSI_ETH_MAC,
672         ECORE_NETQ_ETH_MAC,
673         ECORE_VLAN,
674         ECORE_DONT_CONSUME_CAM_CREDIT,
675         ECORE_DONT_CONSUME_CAM_CREDIT_DEST,
676 };
677 /* When looking for matching filters, some flags are not interesting */
678 #define ECORE_VLAN_MAC_CMP_MASK (1 << ECORE_UC_LIST_MAC | \
679                                  1 << ECORE_ETH_MAC | \
680                                  1 << ECORE_ISCSI_ETH_MAC | \
681                                  1 << ECORE_NETQ_ETH_MAC | \
682                                  1 << ECORE_VLAN)
683 #define ECORE_VLAN_MAC_CMP_FLAGS(flags) \
684         ((flags) & ECORE_VLAN_MAC_CMP_MASK)
685
686 struct ecore_vlan_mac_ramrod_params {
687         /* Object to run the command from */
688         struct ecore_vlan_mac_obj *vlan_mac_obj;
689
690         /* General command flags: COMP_WAIT, etc. */
691         unsigned long ramrod_flags;
692
693         /* Command specific configuration request */
694         struct ecore_vlan_mac_data user_req;
695 };
696
697 struct ecore_vlan_mac_obj {
698         struct ecore_raw_obj raw;
699
700         /* Bookkeeping list: will prevent the addition of already existing
701          * entries.
702          */
703         ecore_list_t            head;
704         /* Implement a simple reader/writer lock on the head list.
705          * all these fields should only be accessed under the exe_queue lock
706          */
707         uint8_t         head_reader; /* Num. of readers accessing head list */
708         bool            head_exe_request; /* Pending execution request. */
709         unsigned long   saved_ramrod_flags; /* Ramrods of pending execution */
710
711         /* Execution queue interface instance */
712         struct ecore_exe_queue_obj      exe_queue;
713
714         /* MACs credit pool */
715         struct ecore_credit_pool_obj    *macs_pool;
716
717         /* VLANs credit pool */
718         struct ecore_credit_pool_obj    *vlans_pool;
719
720         /* RAMROD command to be used */
721         int                             ramrod_cmd;
722
723         /* copy first n elements onto preallocated buffer
724          *
725          * @param n number of elements to get
726          * @param buf buffer preallocated by caller into which elements
727          *            will be copied. Note elements are 4-byte aligned
728          *            so buffer size must be able to accommodate the
729          *            aligned elements.
730          *
731          * @return number of copied bytes
732          */
733
734         int (*get_n_elements)(struct bnx2x_softc *sc,
735                               struct ecore_vlan_mac_obj *o, int n, uint8_t *base,
736                               uint8_t stride, uint8_t size);
737
738         /**
739          * Checks if ADD-ramrod with the given params may be performed.
740          *
741          * @return zero if the element may be added
742          */
743
744         int (*check_add)(struct bnx2x_softc *sc,
745                          struct ecore_vlan_mac_obj *o,
746                          union ecore_classification_ramrod_data *data);
747
748         /**
749          * Checks if DEL-ramrod with the given params may be performed.
750          *
751          * @return true if the element may be deleted
752          */
753         struct ecore_vlan_mac_registry_elem *
754                 (*check_del)(struct bnx2x_softc *sc,
755                              struct ecore_vlan_mac_obj *o,
756                              union ecore_classification_ramrod_data *data);
757
758         /**
759          * Checks if DEL-ramrod with the given params may be performed.
760          *
761          * @return true if the element may be deleted
762          */
763         bool (*check_move)(struct bnx2x_softc *sc,
764                            struct ecore_vlan_mac_obj *src_o,
765                            struct ecore_vlan_mac_obj *dst_o,
766                            union ecore_classification_ramrod_data *data);
767
768         /**
769          *  Update the relevant credit object(s) (consume/return
770          *  correspondingly).
771          */
772         bool (*get_credit)(struct ecore_vlan_mac_obj *o);
773         bool (*put_credit)(struct ecore_vlan_mac_obj *o);
774         bool (*get_cam_offset)(struct ecore_vlan_mac_obj *o, int *offset);
775         bool (*put_cam_offset)(struct ecore_vlan_mac_obj *o, int offset);
776
777         /**
778          * Configures one rule in the ramrod data buffer.
779          */
780         void (*set_one_rule)(struct bnx2x_softc *sc,
781                              struct ecore_vlan_mac_obj *o,
782                              struct ecore_exeq_elem *elem, int rule_idx,
783                              int cam_offset);
784
785         /**
786         *  Delete all configured elements having the given
787         *  vlan_mac_flags specification. Assumes no pending for
788         *  execution commands. Will schedule all all currently
789         *  configured MACs/VLANs/VLAN-MACs matching the vlan_mac_flags
790         *  specification for deletion and will use the given
791         *  ramrod_flags for the last DEL operation.
792          *
793          * @param sc
794          * @param o
795          * @param ramrod_flags RAMROD_XX flags
796          *
797          * @return 0 if the last operation has completed successfully
798          *         and there are no more elements left, positive value
799          *         if there are pending for completion commands,
800          *         negative value in case of failure.
801          */
802         int (*delete_all)(struct bnx2x_softc *sc,
803                           struct ecore_vlan_mac_obj *o,
804                           unsigned long *vlan_mac_flags,
805                           unsigned long *ramrod_flags);
806
807         /**
808          * Reconfigures the next MAC/VLAN/VLAN-MAC element from the previously
809          * configured elements list.
810          *
811          * @param sc
812          * @param p Command parameters (RAMROD_COMP_WAIT bit in
813          *          ramrod_flags is only taken into an account)
814          * @param ppos a pointer to the cookie that should be given back in the
815          *        next call to make function handle the next element. If
816          *        *ppos is set to NULL it will restart the iterator.
817          *        If returned *ppos == NULL this means that the last
818          *        element has been handled.
819          *
820          * @return int
821          */
822         int (*restore)(struct bnx2x_softc *sc,
823                        struct ecore_vlan_mac_ramrod_params *p,
824                        struct ecore_vlan_mac_registry_elem **ppos);
825
826         /**
827          * Should be called on a completion arrival.
828          *
829          * @param sc
830          * @param o
831          * @param cqe Completion element we are handling
832          * @param ramrod_flags if RAMROD_CONT is set the next bulk of
833          *                     pending commands will be executed.
834          *                     RAMROD_DRV_CLR_ONLY and RAMROD_RESTORE
835          *                     may also be set if needed.
836          *
837          * @return 0 if there are neither pending nor waiting for
838          *         completion commands. Positive value if there are
839          *         pending for execution or for completion commands.
840          *         Negative value in case of an error (including an
841          *         error in the cqe).
842          */
843         int (*complete)(struct bnx2x_softc *sc, struct ecore_vlan_mac_obj *o,
844                         union event_ring_elem *cqe,
845                         unsigned long *ramrod_flags);
846
847         /**
848          * Wait for completion of all commands. Don't schedule new ones,
849          * just wait. It assumes that the completion code will schedule
850          * for new commands.
851          */
852         int (*wait)(struct bnx2x_softc *sc, struct ecore_vlan_mac_obj *o);
853 };
854
855 enum {
856         ECORE_LLH_CAM_ISCSI_ETH_LINE = 0,
857         ECORE_LLH_CAM_ETH_LINE,
858         ECORE_LLH_CAM_MAX_PF_LINE = NIG_REG_LLH1_FUNC_MEM_SIZE / 2
859 };
860
861 void ecore_set_mac_in_nig(struct bnx2x_softc *sc,
862                           bool add, unsigned char *dev_addr, int index);
863
864 /** RX_MODE verbs:DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
865
866 /* RX_MODE ramrod special flags: set in rx_mode_flags field in
867  * a ecore_rx_mode_ramrod_params.
868  */
869 enum {
870         ECORE_RX_MODE_FCOE_ETH,
871         ECORE_RX_MODE_ISCSI_ETH,
872 };
873
874 enum {
875         ECORE_ACCEPT_UNICAST,
876         ECORE_ACCEPT_MULTICAST,
877         ECORE_ACCEPT_ALL_UNICAST,
878         ECORE_ACCEPT_ALL_MULTICAST,
879         ECORE_ACCEPT_BROADCAST,
880         ECORE_ACCEPT_UNMATCHED,
881         ECORE_ACCEPT_ANY_VLAN
882 };
883
884 struct ecore_rx_mode_ramrod_params {
885         struct ecore_rx_mode_obj *rx_mode_obj;
886         unsigned long *pstate;
887         int state;
888         uint8_t cl_id;
889         uint32_t cid;
890         uint8_t func_id;
891         unsigned long ramrod_flags;
892         unsigned long rx_mode_flags;
893
894         /* rdata is either a pointer to eth_filter_rules_ramrod_data(e2) or to
895          * a tstorm_eth_mac_filter_config (e1x).
896          */
897         void *rdata;
898         ecore_dma_addr_t rdata_mapping;
899
900         /* Rx mode settings */
901         unsigned long rx_accept_flags;
902
903         /* internal switching settings */
904         unsigned long tx_accept_flags;
905 };
906
907 struct ecore_rx_mode_obj {
908         int (*config_rx_mode)(struct bnx2x_softc *sc,
909                               struct ecore_rx_mode_ramrod_params *p);
910
911         int (*wait_comp)(struct bnx2x_softc *sc,
912                          struct ecore_rx_mode_ramrod_params *p);
913 };
914
915 /********************** Set multicast group ***********************************/
916
917 struct ecore_mcast_list_elem {
918         ecore_list_entry_t link;
919         uint8_t *mac;
920 };
921
922 union ecore_mcast_config_data {
923         uint8_t *mac;
924         uint8_t bin; /* used in a RESTORE/SET flows */
925 };
926
927 struct ecore_mcast_ramrod_params {
928         struct ecore_mcast_obj *mcast_obj;
929
930         /* Relevant options are RAMROD_COMP_WAIT and RAMROD_DRV_CLR_ONLY */
931         unsigned long ramrod_flags;
932
933         ecore_list_t mcast_list; /* list of struct ecore_mcast_list_elem */
934         /** TODO:
935          *      - rename it to macs_num.
936          *      - Add a new command type for handling pending commands
937          *        (remove "zero semantics").
938          *
939          *  Length of mcast_list. If zero and ADD_CONT command - post
940          *  pending commands.
941          */
942         int mcast_list_len;
943 };
944
945 enum ecore_mcast_cmd {
946         ECORE_MCAST_CMD_ADD,
947         ECORE_MCAST_CMD_CONT,
948         ECORE_MCAST_CMD_DEL,
949         ECORE_MCAST_CMD_RESTORE,
950
951         /* Following this, multicast configuration should equal to approx
952          * the set of MACs provided [i.e., remove all else].
953          * The two sub-commands are used internally to decide whether a given
954          * bin is to be added or removed
955          */
956         ECORE_MCAST_CMD_SET,
957         ECORE_MCAST_CMD_SET_ADD,
958         ECORE_MCAST_CMD_SET_DEL,
959 };
960
961 struct ecore_mcast_obj {
962         struct ecore_raw_obj raw;
963
964         union {
965                 struct {
966                 #define ECORE_MCAST_BINS_NUM    256
967                 #define ECORE_MCAST_VEC_SZ      (ECORE_MCAST_BINS_NUM / 64)
968                         uint64_t vec[ECORE_MCAST_VEC_SZ];
969
970                         /** Number of BINs to clear. Should be updated
971                          *  immediately when a command arrives in order to
972                          *  properly create DEL commands.
973                          */
974                         int num_bins_set;
975                 } aprox_match;
976
977                 struct {
978                         ecore_list_t macs;
979                         int num_macs_set;
980                 } exact_match;
981         } registry;
982
983         /* Pending commands */
984         ecore_list_t pending_cmds_head;
985
986         /* A state that is set in raw.pstate, when there are pending commands */
987         int sched_state;
988
989         /* Maximal number of mcast MACs configured in one command */
990         int max_cmd_len;
991
992         /* Total number of currently pending MACs to configure: both
993          * in the pending commands list and in the current command.
994          */
995         int total_pending_num;
996
997         uint8_t engine_id;
998
999         /**
1000          * @param cmd command to execute (ECORE_MCAST_CMD_X, see above)
1001          */
1002         int (*config_mcast)(struct bnx2x_softc *sc,
1003                             struct ecore_mcast_ramrod_params *p,
1004                             enum ecore_mcast_cmd cmd);
1005
1006         /**
1007          * Fills the ramrod data during the RESTORE flow.
1008          *
1009          * @param sc
1010          * @param o
1011          * @param start_idx Registry index to start from
1012          * @param rdata_idx Index in the ramrod data to start from
1013          *
1014          * @return -1 if we handled the whole registry or index of the last
1015          *         handled registry element.
1016          */
1017         int (*hdl_restore)(struct bnx2x_softc *sc, struct ecore_mcast_obj *o,
1018                            int start_bin, int *rdata_idx);
1019
1020         int (*enqueue_cmd)(struct bnx2x_softc *sc, struct ecore_mcast_obj *o,
1021                            struct ecore_mcast_ramrod_params *p,
1022                            enum ecore_mcast_cmd cmd);
1023
1024         void (*set_one_rule)(struct bnx2x_softc *sc,
1025                              struct ecore_mcast_obj *o, int idx,
1026                              union ecore_mcast_config_data *cfg_data,
1027                              enum ecore_mcast_cmd cmd);
1028
1029         /** Checks if there are more mcast MACs to be set or a previous
1030          *  command is still pending.
1031          */
1032         bool (*check_pending)(struct ecore_mcast_obj *o);
1033
1034         /**
1035          * Set/Clear/Check SCHEDULED state of the object
1036          */
1037         void (*set_sched)(struct ecore_mcast_obj *o);
1038         void (*clear_sched)(struct ecore_mcast_obj *o);
1039         bool (*check_sched)(struct ecore_mcast_obj *o);
1040
1041         /* Wait until all pending commands complete */
1042         int (*wait_comp)(struct bnx2x_softc *sc, struct ecore_mcast_obj *o);
1043
1044         /**
1045          * Handle the internal object counters needed for proper
1046          * commands handling. Checks that the provided parameters are
1047          * feasible.
1048          */
1049         int (*validate)(struct bnx2x_softc *sc,
1050                         struct ecore_mcast_ramrod_params *p,
1051                         enum ecore_mcast_cmd cmd);
1052
1053         /**
1054          * Restore the values of internal counters in case of a failure.
1055          */
1056         void (*revert)(struct bnx2x_softc *sc,
1057                        struct ecore_mcast_ramrod_params *p,
1058                        int old_num_bins,
1059                        enum ecore_mcast_cmd cmd);
1060
1061         int (*get_registry_size)(struct ecore_mcast_obj *o);
1062         void (*set_registry_size)(struct ecore_mcast_obj *o, int n);
1063 };
1064
1065 /*************************** Credit handling **********************************/
1066 struct ecore_credit_pool_obj {
1067
1068         /* Current amount of credit in the pool */
1069         ecore_atomic_t  credit;
1070
1071         /* Maximum allowed credit. put() will check against it. */
1072         int             pool_sz;
1073
1074         /* Allocate a pool table statically.
1075          *
1076          * Currently the maximum allowed size is MAX_MAC_CREDIT_E2(272)
1077          *
1078          * The set bit in the table will mean that the entry is available.
1079          */
1080 #define ECORE_POOL_VEC_SIZE     (MAX_MAC_CREDIT_E2 / 64)
1081         uint64_t                pool_mirror[ECORE_POOL_VEC_SIZE];
1082
1083         /* Base pool offset (initialized differently */
1084         int             base_pool_offset;
1085
1086         /**
1087          * Get the next free pool entry.
1088          *
1089          * @return true if there was a free entry in the pool
1090          */
1091         bool (*get_entry)(struct ecore_credit_pool_obj *o, int *entry);
1092
1093         /**
1094          * Return the entry back to the pool.
1095          *
1096          * @return true if entry is legal and has been successfully
1097          *         returned to the pool.
1098          */
1099         bool (*put_entry)(struct ecore_credit_pool_obj *o, int entry);
1100
1101         /**
1102          * Get the requested amount of credit from the pool.
1103          *
1104          * @param cnt Amount of requested credit
1105          * @return true if the operation is successful
1106          */
1107         bool (*get)(struct ecore_credit_pool_obj *o, int cnt);
1108
1109         /**
1110          * Returns the credit to the pool.
1111          *
1112          * @param cnt Amount of credit to return
1113          * @return true if the operation is successful
1114          */
1115         bool (*put)(struct ecore_credit_pool_obj *o, int cnt);
1116
1117         /**
1118          * Reads the current amount of credit.
1119          */
1120         int (*check)(struct ecore_credit_pool_obj *o);
1121 };
1122
1123 /*************************** RSS configuration ********************************/
1124 enum {
1125         /* RSS_MODE bits are mutually exclusive */
1126         ECORE_RSS_MODE_DISABLED,
1127         ECORE_RSS_MODE_REGULAR,
1128
1129         ECORE_RSS_SET_SRCH, /* Setup searcher, E1x specific flag */
1130
1131         ECORE_RSS_IPV4,
1132         ECORE_RSS_IPV4_TCP,
1133         ECORE_RSS_IPV4_UDP,
1134         ECORE_RSS_IPV6,
1135         ECORE_RSS_IPV6_TCP,
1136         ECORE_RSS_IPV6_UDP,
1137
1138         ECORE_RSS_IPV4_VXLAN,
1139         ECORE_RSS_IPV6_VXLAN,
1140         ECORE_RSS_TUNN_INNER_HDRS,
1141 };
1142
1143 struct ecore_config_rss_params {
1144         struct ecore_rss_config_obj *rss_obj;
1145
1146         /* may have RAMROD_COMP_WAIT set only */
1147         unsigned long   ramrod_flags;
1148
1149         /* ECORE_RSS_X bits */
1150         unsigned long   rss_flags;
1151
1152         /* Number hash bits to take into an account */
1153         uint8_t         rss_result_mask;
1154
1155         /* Indirection table */
1156         uint8_t         ind_table[T_ETH_INDIRECTION_TABLE_SIZE];
1157
1158         /* RSS hash values */
1159         uint32_t                rss_key[10];
1160
1161         /* valid only if ECORE_RSS_UPDATE_TOE is set */
1162         uint16_t                toe_rss_bitmap;
1163 };
1164
1165 struct ecore_rss_config_obj {
1166         struct ecore_raw_obj    raw;
1167
1168         /* RSS engine to use */
1169         uint8_t                 engine_id;
1170
1171         /* Last configured indirection table */
1172         uint8_t                 ind_table[T_ETH_INDIRECTION_TABLE_SIZE];
1173
1174         /* flags for enabling 4-tupple hash on UDP */
1175         uint8_t                 udp_rss_v4;
1176         uint8_t                 udp_rss_v6;
1177
1178         int (*config_rss)(struct bnx2x_softc *sc,
1179                           struct ecore_config_rss_params *p);
1180 };
1181
1182 /*********************** Queue state update ***********************************/
1183
1184 /* UPDATE command options */
1185 enum {
1186         ECORE_Q_UPDATE_IN_VLAN_REM,
1187         ECORE_Q_UPDATE_IN_VLAN_REM_CHNG,
1188         ECORE_Q_UPDATE_OUT_VLAN_REM,
1189         ECORE_Q_UPDATE_OUT_VLAN_REM_CHNG,
1190         ECORE_Q_UPDATE_ANTI_SPOOF,
1191         ECORE_Q_UPDATE_ANTI_SPOOF_CHNG,
1192         ECORE_Q_UPDATE_ACTIVATE,
1193         ECORE_Q_UPDATE_ACTIVATE_CHNG,
1194         ECORE_Q_UPDATE_DEF_VLAN_EN,
1195         ECORE_Q_UPDATE_DEF_VLAN_EN_CHNG,
1196         ECORE_Q_UPDATE_SILENT_VLAN_REM_CHNG,
1197         ECORE_Q_UPDATE_SILENT_VLAN_REM,
1198         ECORE_Q_UPDATE_TX_SWITCHING_CHNG,
1199         ECORE_Q_UPDATE_TX_SWITCHING,
1200         ECORE_Q_UPDATE_PTP_PKTS_CHNG,
1201         ECORE_Q_UPDATE_PTP_PKTS,
1202 };
1203
1204 /* Allowed Queue states */
1205 enum ecore_q_state {
1206         ECORE_Q_STATE_RESET,
1207         ECORE_Q_STATE_INITIALIZED,
1208         ECORE_Q_STATE_ACTIVE,
1209         ECORE_Q_STATE_MULTI_COS,
1210         ECORE_Q_STATE_MCOS_TERMINATED,
1211         ECORE_Q_STATE_INACTIVE,
1212         ECORE_Q_STATE_STOPPED,
1213         ECORE_Q_STATE_TERMINATED,
1214         ECORE_Q_STATE_FLRED,
1215         ECORE_Q_STATE_MAX,
1216 };
1217
1218 /* Allowed Queue states */
1219 enum ecore_q_logical_state {
1220         ECORE_Q_LOGICAL_STATE_ACTIVE,
1221         ECORE_Q_LOGICAL_STATE_STOPPED,
1222 };
1223
1224 /* Allowed commands */
1225 enum ecore_queue_cmd {
1226         ECORE_Q_CMD_INIT,
1227         ECORE_Q_CMD_SETUP,
1228         ECORE_Q_CMD_SETUP_TX_ONLY,
1229         ECORE_Q_CMD_DEACTIVATE,
1230         ECORE_Q_CMD_ACTIVATE,
1231         ECORE_Q_CMD_UPDATE,
1232         ECORE_Q_CMD_UPDATE_TPA,
1233         ECORE_Q_CMD_HALT,
1234         ECORE_Q_CMD_CFC_DEL,
1235         ECORE_Q_CMD_TERMINATE,
1236         ECORE_Q_CMD_EMPTY,
1237         ECORE_Q_CMD_MAX,
1238 };
1239
1240 /* queue SETUP + INIT flags */
1241 enum {
1242         ECORE_Q_FLG_TPA,
1243         ECORE_Q_FLG_TPA_IPV6,
1244         ECORE_Q_FLG_TPA_GRO,
1245         ECORE_Q_FLG_STATS,
1246         ECORE_Q_FLG_ZERO_STATS,
1247         ECORE_Q_FLG_ACTIVE,
1248         ECORE_Q_FLG_OV,
1249         ECORE_Q_FLG_VLAN,
1250         ECORE_Q_FLG_COS,
1251         ECORE_Q_FLG_HC,
1252         ECORE_Q_FLG_HC_EN,
1253         ECORE_Q_FLG_DHC,
1254         ECORE_Q_FLG_OOO,
1255         ECORE_Q_FLG_FCOE,
1256         ECORE_Q_FLG_LEADING_RSS,
1257         ECORE_Q_FLG_MCAST,
1258         ECORE_Q_FLG_DEF_VLAN,
1259         ECORE_Q_FLG_TX_SWITCH,
1260         ECORE_Q_FLG_TX_SEC,
1261         ECORE_Q_FLG_ANTI_SPOOF,
1262         ECORE_Q_FLG_SILENT_VLAN_REM,
1263         ECORE_Q_FLG_FORCE_DEFAULT_PRI,
1264         ECORE_Q_FLG_REFUSE_OUTBAND_VLAN,
1265         ECORE_Q_FLG_PCSUM_ON_PKT,
1266         ECORE_Q_FLG_TUN_INC_INNER_IP_ID,
1267         ECORE_Q_FLG_TPA_VLAN_DIS,
1268 };
1269
1270 /* Queue type options: queue type may be a combination of below. */
1271 enum ecore_q_type {
1272         ECORE_Q_TYPE_FWD,
1273         /** TODO: Consider moving both these flags into the init()
1274          *        ramrod params.
1275          */
1276         ECORE_Q_TYPE_HAS_RX,
1277         ECORE_Q_TYPE_HAS_TX,
1278 };
1279
1280 #define ECORE_PRIMARY_CID_INDEX                 0
1281 #define ECORE_MULTI_TX_COS_E1X                  3 /* QM only */
1282 #define ECORE_MULTI_TX_COS_E2_E3A0              2
1283 #define ECORE_MULTI_TX_COS_E3B0                 3
1284 #define ECORE_MULTI_TX_COS                      3 /* Maximum possible */
1285 #define MAC_PAD (ECORE_ALIGN(ETH_ALEN, sizeof(uint32_t)) - ETH_ALEN)
1286 /* DMAE channel to be used by FW for timesync workaroun. A driver that sends
1287  * timesync-related ramrods must not use this DMAE command ID.
1288  */
1289 #define FW_DMAE_CMD_ID 6
1290
1291 struct ecore_queue_init_params {
1292         struct {
1293                 unsigned long   flags;
1294                 uint16_t                hc_rate;
1295                 uint8_t         fw_sb_id;
1296                 uint8_t         sb_cq_index;
1297         } tx;
1298
1299         struct {
1300                 unsigned long   flags;
1301                 uint16_t                hc_rate;
1302                 uint8_t         fw_sb_id;
1303                 uint8_t         sb_cq_index;
1304         } rx;
1305
1306         /* CID context in the host memory */
1307         struct eth_context *cxts[ECORE_MULTI_TX_COS];
1308
1309         /* maximum number of cos supported by hardware */
1310         uint8_t max_cos;
1311 };
1312
1313 struct ecore_queue_terminate_params {
1314         /* index within the tx_only cids of this queue object */
1315         uint8_t cid_index;
1316 };
1317
1318 struct ecore_queue_cfc_del_params {
1319         /* index within the tx_only cids of this queue object */
1320         uint8_t cid_index;
1321 };
1322
1323 struct ecore_queue_update_params {
1324         unsigned long   update_flags; /* ECORE_Q_UPDATE_XX bits */
1325         uint16_t                def_vlan;
1326         uint16_t                silent_removal_value;
1327         uint16_t                silent_removal_mask;
1328 /* index within the tx_only cids of this queue object */
1329         uint8_t         cid_index;
1330 };
1331
1332 struct ecore_queue_update_tpa_params {
1333         ecore_dma_addr_t sge_map;
1334         uint8_t update_ipv4;
1335         uint8_t update_ipv6;
1336         uint8_t max_tpa_queues;
1337         uint8_t max_sges_pkt;
1338         uint8_t complete_on_both_clients;
1339         uint8_t dont_verify_thr;
1340         uint8_t tpa_mode;
1341         uint8_t _pad;
1342
1343         uint16_t sge_buff_sz;
1344         uint16_t max_agg_sz;
1345
1346         uint16_t sge_pause_thr_low;
1347         uint16_t sge_pause_thr_high;
1348
1349         uint8_t disable_tpa_over_vlan;
1350 };
1351
1352 struct rxq_pause_params {
1353         uint16_t                bd_th_lo;
1354         uint16_t                bd_th_hi;
1355         uint16_t                rcq_th_lo;
1356         uint16_t                rcq_th_hi;
1357         uint16_t                sge_th_lo; /* valid if ECORE_Q_FLG_TPA */
1358         uint16_t                sge_th_hi; /* valid if ECORE_Q_FLG_TPA */
1359         uint16_t                pri_map;
1360 };
1361
1362 /* general */
1363 struct ecore_general_setup_params {
1364         /* valid if ECORE_Q_FLG_STATS */
1365         uint8_t         stat_id;
1366
1367         uint8_t         spcl_id;
1368         uint16_t                mtu;
1369         uint8_t         cos;
1370
1371         uint8_t         fp_hsi;
1372 };
1373
1374 struct ecore_rxq_setup_params {
1375         /* dma */
1376         ecore_dma_addr_t        dscr_map;
1377         ecore_dma_addr_t        sge_map;
1378         ecore_dma_addr_t        rcq_map;
1379         ecore_dma_addr_t        rcq_np_map;
1380
1381         uint16_t                drop_flags;
1382         uint16_t                buf_sz;
1383         uint8_t         fw_sb_id;
1384         uint8_t         cl_qzone_id;
1385
1386         /* valid if ECORE_Q_FLG_TPA */
1387         uint16_t                tpa_agg_sz;
1388         uint16_t                sge_buf_sz;
1389         uint8_t         max_sges_pkt;
1390         uint8_t         max_tpa_queues;
1391         uint8_t         rss_engine_id;
1392
1393         /* valid if ECORE_Q_FLG_MCAST */
1394         uint8_t         mcast_engine_id;
1395
1396         uint8_t         cache_line_log;
1397
1398         uint8_t         sb_cq_index;
1399
1400         /* valid if ECORE_Q_FLG_SILENT_VLAN_REM */
1401         uint16_t silent_removal_value;
1402         uint16_t silent_removal_mask;
1403 };
1404
1405 struct ecore_txq_setup_params {
1406         /* dma */
1407         ecore_dma_addr_t        dscr_map;
1408
1409         uint8_t         fw_sb_id;
1410         uint8_t         sb_cq_index;
1411         uint8_t         cos;            /* valid if ECORE_Q_FLG_COS */
1412         uint16_t                traffic_type;
1413         /* equals to the leading rss client id, used for TX classification*/
1414         uint8_t         tss_leading_cl_id;
1415
1416         /* valid if ECORE_Q_FLG_DEF_VLAN */
1417         uint16_t                default_vlan;
1418 };
1419
1420 struct ecore_queue_setup_params {
1421         struct ecore_general_setup_params gen_params;
1422         struct ecore_txq_setup_params txq_params;
1423         struct ecore_rxq_setup_params rxq_params;
1424         struct rxq_pause_params pause_params;
1425         unsigned long flags;
1426 };
1427
1428 struct ecore_queue_setup_tx_only_params {
1429         struct ecore_general_setup_params       gen_params;
1430         struct ecore_txq_setup_params           txq_params;
1431         unsigned long                           flags;
1432         /* index within the tx_only cids of this queue object */
1433         uint8_t                                 cid_index;
1434 };
1435
1436 struct ecore_queue_state_params {
1437         struct ecore_queue_sp_obj *q_obj;
1438
1439         /* Current command */
1440         enum ecore_queue_cmd cmd;
1441
1442         /* may have RAMROD_COMP_WAIT set only */
1443         unsigned long ramrod_flags;
1444
1445         /* Params according to the current command */
1446         union {
1447                 struct ecore_queue_update_params        update;
1448                 struct ecore_queue_update_tpa_params    update_tpa;
1449                 struct ecore_queue_setup_params         setup;
1450                 struct ecore_queue_init_params          init;
1451                 struct ecore_queue_setup_tx_only_params tx_only;
1452                 struct ecore_queue_terminate_params     terminate;
1453                 struct ecore_queue_cfc_del_params       cfc_del;
1454         } params;
1455 };
1456
1457 struct ecore_viflist_params {
1458         uint8_t echo_res;
1459         uint8_t func_bit_map_res;
1460 };
1461
1462 struct ecore_queue_sp_obj {
1463         uint32_t                cids[ECORE_MULTI_TX_COS];
1464         uint8_t         cl_id;
1465         uint8_t         func_id;
1466
1467         /* number of traffic classes supported by queue.
1468          * The primary connection of the queue supports the first traffic
1469          * class. Any further traffic class is supported by a tx-only
1470          * connection.
1471          *
1472          * Therefore max_cos is also a number of valid entries in the cids
1473          * array.
1474          */
1475         uint8_t max_cos;
1476         uint8_t num_tx_only, next_tx_only;
1477
1478         enum ecore_q_state state, next_state;
1479
1480         /* bits from enum ecore_q_type */
1481         unsigned long   type;
1482
1483         /* ECORE_Q_CMD_XX bits. This object implements "one
1484          * pending" paradigm but for debug and tracing purposes it's
1485          * more convenient to have different bits for different
1486          * commands.
1487          */
1488         unsigned long   pending;
1489
1490         /* Buffer to use as a ramrod data and its mapping */
1491         void            *rdata;
1492         ecore_dma_addr_t        rdata_mapping;
1493
1494         /**
1495          * Performs one state change according to the given parameters.
1496          *
1497          * @return 0 in case of success and negative value otherwise.
1498          */
1499         int (*send_cmd)(struct bnx2x_softc *sc,
1500                         struct ecore_queue_state_params *params);
1501
1502         /**
1503          * Sets the pending bit according to the requested transition.
1504          */
1505         int (*set_pending)(struct ecore_queue_sp_obj *o,
1506                            struct ecore_queue_state_params *params);
1507
1508         /**
1509          * Checks that the requested state transition is legal.
1510          */
1511         int (*check_transition)(struct bnx2x_softc *sc,
1512                                 struct ecore_queue_sp_obj *o,
1513                                 struct ecore_queue_state_params *params);
1514
1515         /**
1516          * Completes the pending command.
1517          */
1518         int (*complete_cmd)(struct bnx2x_softc *sc,
1519                             struct ecore_queue_sp_obj *o,
1520                             enum ecore_queue_cmd);
1521
1522         int (*wait_comp)(struct bnx2x_softc *sc,
1523                          struct ecore_queue_sp_obj *o,
1524                          enum ecore_queue_cmd cmd);
1525 };
1526
1527 /********************** Function state update *********************************/
1528
1529 /* UPDATE command options */
1530 enum {
1531         ECORE_F_UPDATE_TX_SWITCH_SUSPEND_CHNG,
1532         ECORE_F_UPDATE_TX_SWITCH_SUSPEND,
1533         ECORE_F_UPDATE_SD_VLAN_TAG_CHNG,
1534         ECORE_F_UPDATE_SD_VLAN_ETH_TYPE_CHNG,
1535         ECORE_F_UPDATE_VLAN_FORCE_PRIO_CHNG,
1536         ECORE_F_UPDATE_VLAN_FORCE_PRIO_FLAG,
1537         ECORE_F_UPDATE_TUNNEL_CFG_CHNG,
1538         ECORE_F_UPDATE_TUNNEL_INNER_CLSS_L2GRE,
1539         ECORE_F_UPDATE_TUNNEL_INNER_CLSS_VXLAN,
1540         ECORE_F_UPDATE_TUNNEL_INNER_CLSS_L2GENEVE,
1541         ECORE_F_UPDATE_TUNNEL_INNER_RSS,
1542         ECORE_F_UPDATE_TUNNEL_INNER_CLSS_VXLAN_INNER_VNI,
1543         ECORE_F_UPDATE_VLAN_FILTERING_PVID_CHNG,
1544 };
1545
1546 /* Allowed Function states */
1547 enum ecore_func_state {
1548         ECORE_F_STATE_RESET,
1549         ECORE_F_STATE_INITIALIZED,
1550         ECORE_F_STATE_STARTED,
1551         ECORE_F_STATE_TX_STOPPED,
1552         ECORE_F_STATE_MAX,
1553 };
1554
1555 /* Allowed Function commands */
1556 enum ecore_func_cmd {
1557         ECORE_F_CMD_HW_INIT,
1558         ECORE_F_CMD_START,
1559         ECORE_F_CMD_STOP,
1560         ECORE_F_CMD_HW_RESET,
1561         ECORE_F_CMD_AFEX_UPDATE,
1562         ECORE_F_CMD_AFEX_VIFLISTS,
1563         ECORE_F_CMD_TX_STOP,
1564         ECORE_F_CMD_TX_START,
1565         ECORE_F_CMD_SWITCH_UPDATE,
1566         ECORE_F_CMD_SET_TIMESYNC,
1567         ECORE_F_CMD_MAX,
1568 };
1569
1570 struct ecore_func_hw_init_params {
1571         /* A load phase returned by MCP.
1572          *
1573          * May be:
1574          *              FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
1575          *              FW_MSG_CODE_DRV_LOAD_COMMON
1576          *              FW_MSG_CODE_DRV_LOAD_PORT
1577          *              FW_MSG_CODE_DRV_LOAD_FUNCTION
1578          */
1579         uint32_t load_phase;
1580 };
1581
1582 struct ecore_func_hw_reset_params {
1583         /* A load phase returned by MCP.
1584          *
1585          * May be:
1586          *              FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
1587          *              FW_MSG_CODE_DRV_LOAD_COMMON
1588          *              FW_MSG_CODE_DRV_LOAD_PORT
1589          *              FW_MSG_CODE_DRV_LOAD_FUNCTION
1590          */
1591         uint32_t reset_phase;
1592 };
1593
1594 struct ecore_func_start_params {
1595         /* Multi Function mode:
1596          *      - Single Function
1597          *      - Switch Dependent
1598          *      - Switch Independent
1599          */
1600         uint16_t mf_mode;
1601
1602         /* Switch Dependent mode outer VLAN tag */
1603         uint16_t sd_vlan_tag;
1604
1605         /* Function cos mode */
1606         uint8_t network_cos_mode;
1607
1608         /* DMAE command id to be used for FW DMAE transactions */
1609         uint8_t dmae_cmd_id;
1610
1611         /* UDP dest port for VXLAN */
1612         uint16_t vxlan_dst_port;
1613
1614         /* UDP dest port for Geneve */
1615         uint16_t geneve_dst_port;
1616
1617         /* Enable inner Rx classifications for L2GRE packets */
1618         uint8_t inner_clss_l2gre;
1619
1620         /* Enable inner Rx classifications for L2-Geneve packets */
1621         uint8_t inner_clss_l2geneve;
1622
1623         /* Enable inner Rx classification for vxlan packets */
1624         uint8_t inner_clss_vxlan;
1625
1626         /* Enable RSS according to inner header */
1627         uint8_t inner_rss;
1628
1629         /** Allows accepting of packets failing MF classification, possibly
1630          * only matching a given ethertype
1631          */
1632         uint8_t class_fail;
1633         uint16_t class_fail_ethtype;
1634
1635         /* Override priority of output packets */
1636         uint8_t sd_vlan_force_pri;
1637         uint8_t sd_vlan_force_pri_val;
1638
1639         /* Replace vlan's ethertype */
1640         uint16_t sd_vlan_eth_type;
1641
1642         /* Prevent inner vlans from being added by FW */
1643         uint8_t no_added_tags;
1644
1645         /* Inner-to-Outer vlan priority mapping */
1646         uint8_t c2s_pri[MAX_VLAN_PRIORITIES];
1647         uint8_t c2s_pri_default;
1648         uint8_t c2s_pri_valid;
1649
1650         /* TX Vlan filtering configuration */
1651         uint8_t tx_vlan_filtering_enable;
1652         uint8_t tx_vlan_filtering_use_pvid;
1653 };
1654
1655 struct ecore_func_switch_update_params {
1656         unsigned long changes; /* ECORE_F_UPDATE_XX bits */
1657         uint16_t vlan;
1658         uint16_t vlan_eth_type;
1659         uint8_t vlan_force_prio;
1660         uint16_t vxlan_dst_port;
1661         uint16_t geneve_dst_port;
1662 };
1663
1664 struct ecore_func_afex_update_params {
1665         uint16_t vif_id;
1666         uint16_t afex_default_vlan;
1667         uint8_t allowed_priorities;
1668 };
1669
1670 struct ecore_func_afex_viflists_params {
1671         uint16_t vif_list_index;
1672         uint8_t func_bit_map;
1673         uint8_t afex_vif_list_command;
1674         uint8_t func_to_clear;
1675 };
1676
1677 struct ecore_func_tx_start_params {
1678         struct priority_cos traffic_type_to_priority_cos[MAX_TRAFFIC_TYPES];
1679         uint8_t dcb_enabled;
1680         uint8_t dcb_version;
1681         uint8_t dont_add_pri_0_en;
1682         uint8_t dcb_outer_pri[MAX_TRAFFIC_TYPES];
1683 };
1684
1685 struct ecore_func_set_timesync_params {
1686         /* Reset, set or keep the current drift value */
1687         uint8_t drift_adjust_cmd;
1688         /* Dec, inc or keep the current offset */
1689         uint8_t offset_cmd;
1690         /* Drift value direction */
1691         uint8_t add_sub_drift_adjust_value;
1692         /* Drift, period and offset values to be used according to the commands
1693          * above.
1694          */
1695         uint8_t drift_adjust_value;
1696         uint32_t drift_adjust_period;
1697         uint64_t offset_delta;
1698 };
1699
1700 struct ecore_func_state_params {
1701         struct ecore_func_sp_obj *f_obj;
1702
1703         /* Current command */
1704         enum ecore_func_cmd cmd;
1705
1706         /* may have RAMROD_COMP_WAIT set only */
1707         unsigned long   ramrod_flags;
1708
1709         /* Params according to the current command */
1710         union {
1711                 struct ecore_func_hw_init_params hw_init;
1712                 struct ecore_func_hw_reset_params hw_reset;
1713                 struct ecore_func_start_params start;
1714                 struct ecore_func_switch_update_params switch_update;
1715                 struct ecore_func_afex_update_params afex_update;
1716                 struct ecore_func_afex_viflists_params afex_viflists;
1717                 struct ecore_func_tx_start_params tx_start;
1718                 struct ecore_func_set_timesync_params set_timesync;
1719         } params;
1720 };
1721
1722 struct ecore_func_sp_drv_ops {
1723         /* Init tool + runtime initialization:
1724          *      - Common Chip
1725          *      - Common (per Path)
1726          *      - Port
1727          *      - Function phases
1728          */
1729         int (*init_hw_cmn_chip)(struct bnx2x_softc *sc);
1730         int (*init_hw_cmn)(struct bnx2x_softc *sc);
1731         int (*init_hw_port)(struct bnx2x_softc *sc);
1732         int (*init_hw_func)(struct bnx2x_softc *sc);
1733
1734         /* Reset Function HW: Common, Port, Function phases. */
1735         void (*reset_hw_cmn)(struct bnx2x_softc *sc);
1736         void (*reset_hw_port)(struct bnx2x_softc *sc);
1737         void (*reset_hw_func)(struct bnx2x_softc *sc);
1738
1739         /* Init/Free GUNZIP resources */
1740         int (*gunzip_init)(struct bnx2x_softc *sc);
1741         void (*gunzip_end)(struct bnx2x_softc *sc);
1742
1743         /* Prepare/Release FW resources */
1744         int (*init_fw)(struct bnx2x_softc *sc);
1745         void (*release_fw)(struct bnx2x_softc *sc);
1746 };
1747
1748 struct ecore_func_sp_obj {
1749         enum ecore_func_state   state, next_state;
1750
1751         /* ECORE_FUNC_CMD_XX bits. This object implements "one
1752          * pending" paradigm but for debug and tracing purposes it's
1753          * more convenient to have different bits for different
1754          * commands.
1755          */
1756         unsigned long           pending;
1757
1758         /* Buffer to use as a ramrod data and its mapping */
1759         void                    *rdata;
1760         ecore_dma_addr_t                rdata_mapping;
1761
1762         /* Buffer to use as a afex ramrod data and its mapping.
1763          * This can't be same rdata as above because afex ramrod requests
1764          * can arrive to the object in parallel to other ramrod requests.
1765          */
1766         void                    *afex_rdata;
1767         ecore_dma_addr_t                afex_rdata_mapping;
1768
1769         /* this mutex validates that when pending flag is taken, the next
1770          * ramrod to be sent will be the one set the pending bit
1771          */
1772         ECORE_MUTEX             one_pending_mutex;
1773
1774         /* Driver interface */
1775         struct ecore_func_sp_drv_ops    *drv;
1776
1777         /**
1778          * Performs one state change according to the given parameters.
1779          *
1780          * @return 0 in case of success and negative value otherwise.
1781          */
1782         int (*send_cmd)(struct bnx2x_softc *sc,
1783                         struct ecore_func_state_params *params);
1784
1785         /**
1786          * Checks that the requested state transition is legal.
1787          */
1788         int (*check_transition)(struct bnx2x_softc *sc,
1789                                 struct ecore_func_sp_obj *o,
1790                                 struct ecore_func_state_params *params);
1791
1792         /**
1793          * Completes the pending command.
1794          */
1795         int (*complete_cmd)(struct bnx2x_softc *sc,
1796                             struct ecore_func_sp_obj *o,
1797                             enum ecore_func_cmd cmd);
1798
1799         int (*wait_comp)(struct bnx2x_softc *sc, struct ecore_func_sp_obj *o,
1800                          enum ecore_func_cmd cmd);
1801 };
1802
1803 /********************** Interfaces ********************************************/
1804 /* Queueable objects set */
1805 union ecore_qable_obj {
1806         struct ecore_vlan_mac_obj vlan_mac;
1807 };
1808 /************** Function state update *********/
1809 void ecore_init_func_obj(struct bnx2x_softc *sc,
1810                          struct ecore_func_sp_obj *obj,
1811                          void *rdata, ecore_dma_addr_t rdata_mapping,
1812                          void *afex_rdata, ecore_dma_addr_t afex_rdata_mapping,
1813                          struct ecore_func_sp_drv_ops *drv_iface);
1814
1815 int ecore_func_state_change(struct bnx2x_softc *sc,
1816                             struct ecore_func_state_params *params);
1817
1818 enum ecore_func_state ecore_func_get_state(struct bnx2x_softc *sc,
1819                                            struct ecore_func_sp_obj *o);
1820 /******************* Queue State **************/
1821 void ecore_init_queue_obj(struct bnx2x_softc *sc,
1822                           struct ecore_queue_sp_obj *obj, uint8_t cl_id, uint32_t *cids,
1823                           uint8_t cid_cnt, uint8_t func_id, void *rdata,
1824                           ecore_dma_addr_t rdata_mapping, unsigned long type);
1825
1826 int ecore_queue_state_change(struct bnx2x_softc *sc,
1827                              struct ecore_queue_state_params *params);
1828
1829 int ecore_get_q_logical_state(struct bnx2x_softc *sc,
1830                                struct ecore_queue_sp_obj *obj);
1831
1832 /********************* VLAN-MAC ****************/
1833 void ecore_init_mac_obj(struct bnx2x_softc *sc,
1834                         struct ecore_vlan_mac_obj *mac_obj,
1835                         uint8_t cl_id, uint32_t cid, uint8_t func_id, void *rdata,
1836                         ecore_dma_addr_t rdata_mapping, int state,
1837                         unsigned long *pstate, ecore_obj_type type,
1838                         struct ecore_credit_pool_obj *macs_pool);
1839
1840 void ecore_init_vlan_obj(struct bnx2x_softc *sc,
1841                          struct ecore_vlan_mac_obj *vlan_obj,
1842                          uint8_t cl_id, uint32_t cid, uint8_t func_id,
1843                          void *rdata,
1844                          ecore_dma_addr_t rdata_mapping, int state,
1845                          unsigned long *pstate, ecore_obj_type type,
1846                          struct ecore_credit_pool_obj *vlans_pool);
1847
1848 void ecore_init_vlan_mac_obj(struct bnx2x_softc *sc,
1849                              struct ecore_vlan_mac_obj *vlan_mac_obj,
1850                              uint8_t cl_id, uint32_t cid, uint8_t func_id,
1851                              void *rdata,
1852                              ecore_dma_addr_t rdata_mapping, int state,
1853                              unsigned long *pstate, ecore_obj_type type,
1854                              struct ecore_credit_pool_obj *macs_pool,
1855                              struct ecore_credit_pool_obj *vlans_pool);
1856
1857 void ecore_init_vxlan_fltr_obj(struct bnx2x_softc *sc,
1858                                struct ecore_vlan_mac_obj *vlan_mac_obj,
1859                                uint8_t cl_id, uint32_t cid, uint8_t func_id,
1860                                void *rdata,
1861                                ecore_dma_addr_t rdata_mapping, int state,
1862                                unsigned long *pstate, ecore_obj_type type,
1863                                struct ecore_credit_pool_obj *macs_pool,
1864                                struct ecore_credit_pool_obj *vlans_pool);
1865
1866 int ecore_vlan_mac_h_read_lock(struct bnx2x_softc *sc,
1867                                         struct ecore_vlan_mac_obj *o);
1868 void ecore_vlan_mac_h_read_unlock(struct bnx2x_softc *sc,
1869                                   struct ecore_vlan_mac_obj *o);
1870 int ecore_vlan_mac_h_write_lock(struct bnx2x_softc *sc,
1871                                 struct ecore_vlan_mac_obj *o);
1872 void ecore_vlan_mac_h_write_unlock(struct bnx2x_softc *sc,
1873                                           struct ecore_vlan_mac_obj *o);
1874 int ecore_config_vlan_mac(struct bnx2x_softc *sc,
1875                            struct ecore_vlan_mac_ramrod_params *p);
1876
1877 int ecore_vlan_mac_move(struct bnx2x_softc *sc,
1878                         struct ecore_vlan_mac_ramrod_params *p,
1879                         struct ecore_vlan_mac_obj *dest_o);
1880
1881 /********************* RX MODE ****************/
1882
1883 void ecore_init_rx_mode_obj(struct bnx2x_softc *sc,
1884                             struct ecore_rx_mode_obj *o);
1885
1886 /**
1887  * ecore_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
1888  *
1889  * @p: Command parameters
1890  *
1891  * Return: 0 - if operation was successful and there is no pending completions,
1892  *         positive number - if there are pending completions,
1893  *         negative - if there were errors
1894  */
1895 int ecore_config_rx_mode(struct bnx2x_softc *sc,
1896                          struct ecore_rx_mode_ramrod_params *p);
1897
1898 /****************** MULTICASTS ****************/
1899
1900 void ecore_init_mcast_obj(struct bnx2x_softc *sc,
1901                           struct ecore_mcast_obj *mcast_obj,
1902                           uint8_t mcast_cl_id, uint32_t mcast_cid, uint8_t func_id,
1903                           uint8_t engine_id, void *rdata, ecore_dma_addr_t rdata_mapping,
1904                           int state, unsigned long *pstate,
1905                           ecore_obj_type type);
1906
1907 /**
1908  * ecore_config_mcast - Configure multicast MACs list.
1909  *
1910  * @cmd: command to execute: ECORE_MCAST_CMD_X
1911  *
1912  * May configure a new list
1913  * provided in p->mcast_list (ECORE_MCAST_CMD_ADD), clean up
1914  * (ECORE_MCAST_CMD_DEL) or restore (ECORE_MCAST_CMD_RESTORE) a current
1915  * configuration, continue to execute the pending commands
1916  * (ECORE_MCAST_CMD_CONT).
1917  *
1918  * If previous command is still pending or if number of MACs to
1919  * configure is more that maximum number of MACs in one command,
1920  * the current command will be enqueued to the tail of the
1921  * pending commands list.
1922  *
1923  * Return: 0 is operation was successful and there are no pending completions,
1924  *         negative if there were errors, positive if there are pending
1925  *         completions.
1926  */
1927 int ecore_config_mcast(struct bnx2x_softc *sc,
1928                        struct ecore_mcast_ramrod_params *p,
1929                        enum ecore_mcast_cmd cmd);
1930
1931 /****************** CREDIT POOL ****************/
1932 void ecore_init_mac_credit_pool(struct bnx2x_softc *sc,
1933                                 struct ecore_credit_pool_obj *p, uint8_t func_id,
1934                                 uint8_t func_num);
1935 void ecore_init_vlan_credit_pool(struct bnx2x_softc *sc,
1936                                  struct ecore_credit_pool_obj *p, uint8_t func_id,
1937                                  uint8_t func_num);
1938 void ecore_init_credit_pool(struct ecore_credit_pool_obj *p,
1939                             int base, int credit);
1940
1941 /****************** RSS CONFIGURATION ****************/
1942 void ecore_init_rss_config_obj(struct bnx2x_softc *sc,
1943                                struct ecore_rss_config_obj *rss_obj,
1944                                uint8_t cl_id, uint32_t cid, uint8_t func_id, uint8_t engine_id,
1945                                void *rdata, ecore_dma_addr_t rdata_mapping,
1946                                int state, unsigned long *pstate,
1947                                ecore_obj_type type);
1948
1949 /**
1950  * ecore_config_rss - Updates RSS configuration according to provided parameters
1951  *
1952  * Return: 0 in case of success
1953  */
1954 int ecore_config_rss(struct bnx2x_softc *sc,
1955                      struct ecore_config_rss_params *p);
1956
1957 /**
1958  * ecore_get_rss_ind_table - Return the current ind_table configuration.
1959  *
1960  * @ind_table: buffer to fill with the current indirection
1961  *                  table content. Should be at least
1962  *                  T_ETH_INDIRECTION_TABLE_SIZE bytes long.
1963  */
1964 void ecore_get_rss_ind_table(struct ecore_rss_config_obj *rss_obj,
1965                              uint8_t *ind_table);
1966
1967 #define PF_MAC_CREDIT_E2(sc, func_num)                                  \
1968         ((MAX_MAC_CREDIT_E2 - GET_NUM_VFS_PER_PATH(sc) * VF_MAC_CREDIT_CNT) / \
1969          (func_num) + GET_NUM_VFS_PER_PF(sc) * VF_MAC_CREDIT_CNT)
1970
1971 #define PF_VLAN_CREDIT_E2(sc, func_num)                                  \
1972         ((MAX_MAC_CREDIT_E2 - GET_NUM_VFS_PER_PATH(sc) * VF_VLAN_CREDIT_CNT) / \
1973          (func_num) + GET_NUM_VFS_PER_PF(sc) * VF_VLAN_CREDIT_CNT)
1974
1975 #define ECORE_PF_VLAN_CREDIT_VLAN_FILTERING                             256
1976
1977 #endif /* ECORE_SP_H */