New upstream version 18.11-rc1
[deb_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 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, str)                               \
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                                           str, 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             rte_free(x);                             \
158             x = NULL;                                \
159             y = 0;                                   \
160         }                                            \
161     } while (0)
162
163 #define ECORE_IS_VALID_ETHER_ADDR(_mac) TRUE
164
165 #define ECORE_IS_MF_SD_MODE   IS_MF_SD_MODE
166 #define ECORE_IS_MF_SI_MODE   IS_MF_SI_MODE
167 #define ECORE_IS_MF_AFEX_MODE IS_MF_AFEX_MODE
168
169 #define ECORE_SET_CTX_VALIDATION bnx2x_set_ctx_validation
170
171 #define ECORE_UPDATE_COALESCE_SB_INDEX bnx2x_update_coalesce_sb_index
172
173 #define ECORE_ALIGN(x, a) ((((x) + (a) - 1) / (a)) * (a))
174
175 #define ECORE_REG_WR_DMAE_LEN REG_WR_DMAE_LEN
176
177 #define ECORE_PATH_ID     SC_PATH
178 #define ECORE_PORT_ID     SC_PORT
179 #define ECORE_FUNC_ID     SC_FUNC
180 #define ECORE_ABS_FUNC_ID SC_ABS_FUNC
181
182 #define CRCPOLY_LE 0xedb88320
183 uint32_t ecore_calc_crc32(uint32_t crc, uint8_t const *p,
184                           uint32_t len, uint32_t magic);
185
186 uint8_t ecore_calc_crc8(uint32_t data, uint8_t crc);
187
188
189 static inline uint32_t
190 ECORE_CRC32_LE(uint32_t seed, uint8_t *mac, uint32_t len)
191 {
192         return ecore_calc_crc32(seed, mac, len, CRCPOLY_LE);
193 }
194
195 #define ecore_sp_post(_sc, _a, _b, _c, _d) \
196     bnx2x_sp_post(_sc, _a, _b, U64_HI(_c), U64_LO(_c), _d)
197
198 #define ECORE_DBG_BREAK_IF(exp)     \
199     do {                            \
200         if (unlikely(exp)) {        \
201             rte_panic("ECORE");     \
202         }                           \
203     } while (0)
204
205 #define ECORE_BUG()                                   \
206     do {                                              \
207         rte_panic("BUG (%s:%d)", __FILE__, __LINE__); \
208     } while(0);
209
210 #define ECORE_BUG_ON(exp)                                    \
211     do {                                                     \
212         if (likely(exp)) {                                   \
213             rte_panic("BUG_ON (%s:%d)", __FILE__, __LINE__); \
214         }                                                    \
215     } while (0)
216
217
218 #define ECORE_MSG(sc, m, ...) \
219         PMD_DRV_LOG(DEBUG, sc, m, ##__VA_ARGS__)
220
221 typedef struct _ecore_list_entry_t
222 {
223     struct _ecore_list_entry_t *next, *prev;
224 } ecore_list_entry_t;
225
226 typedef struct ecore_list_t
227 {
228     ecore_list_entry_t *head, *tail;
229     unsigned long cnt;
230 } ecore_list_t;
231
232 /* initialize the list */
233 #define ECORE_LIST_INIT(_list) \
234     do {                       \
235         (_list)->head = NULL;  \
236         (_list)->tail = NULL;  \
237         (_list)->cnt  = 0;     \
238     } while (0)
239
240 /* return TRUE if the element is the last on the list */
241 #define ECORE_LIST_IS_LAST(_elem, _list) \
242     (_elem == (_list)->tail)
243
244 /* return TRUE if the list is empty */
245 #define ECORE_LIST_IS_EMPTY(_list) \
246     ((_list)->cnt == 0)
247
248 /* return the first element */
249 #define ECORE_LIST_FIRST_ENTRY(_list, cast, _link) \
250     (cast *)((_list)->head)
251
252 /* return the next element */
253 #define ECORE_LIST_NEXT(_elem, _link, cast) \
254     (cast *)((&((_elem)->_link))->next)
255
256 /* push an element on the head of the list */
257 #define ECORE_LIST_PUSH_HEAD(_elem, _list)              \
258     do {                                                \
259         (_elem)->prev = (ecore_list_entry_t *)0;        \
260         (_elem)->next = (_list)->head;                  \
261         if ((_list)->tail == (ecore_list_entry_t *)0) { \
262             (_list)->tail = (_elem);                    \
263         } else {                                        \
264             (_list)->head->prev = (_elem);              \
265         }                                               \
266         (_list)->head = (_elem);                        \
267         (_list)->cnt++;                                 \
268     } while (0)
269
270 /* push an element on the tail of the list */
271 #define ECORE_LIST_PUSH_TAIL(_elem, _list)       \
272     do {                                         \
273         (_elem)->next = (ecore_list_entry_t *)0; \
274         (_elem)->prev = (_list)->tail;           \
275         if ((_list)->tail) {                     \
276             (_list)->tail->next = (_elem);       \
277         } else {                                 \
278             (_list)->head = (_elem);             \
279         }                                        \
280         (_list)->tail = (_elem);                 \
281         (_list)->cnt++;                          \
282     } while (0)
283
284 /* push list1 on the head of list2 and return with list1 as empty */
285 #define ECORE_LIST_SPLICE_INIT(_list1, _list2)     \
286     do {                                           \
287         (_list1)->tail->next = (_list2)->head;     \
288         if ((_list2)->head) {                      \
289             (_list2)->head->prev = (_list1)->tail; \
290         } else {                                   \
291             (_list2)->tail = (_list1)->tail;       \
292         }                                          \
293         (_list2)->head = (_list1)->head;           \
294         (_list2)->cnt += (_list1)->cnt;            \
295         (_list1)->head = NULL;                     \
296         (_list1)->tail = NULL;                     \
297         (_list1)->cnt  = 0;                        \
298     } while (0)
299
300 /* remove an element from the list */
301 #define ECORE_LIST_REMOVE_ENTRY(_elem, _list)                      \
302     do {                                                           \
303         if ((_list)->head == (_elem)) {                            \
304             if ((_list)->head) {                                   \
305                 (_list)->head = (_list)->head->next;               \
306                 if ((_list)->head) {                               \
307                     (_list)->head->prev = (ecore_list_entry_t *)0; \
308                 } else {                                           \
309                     (_list)->tail = (ecore_list_entry_t *)0;       \
310                 }                                                  \
311                 (_list)->cnt--;                                    \
312             }                                                      \
313         } else if ((_list)->tail == (_elem)) {                     \
314             if ((_list)->tail) {                                   \
315                 (_list)->tail = (_list)->tail->prev;               \
316                 if ((_list)->tail) {                               \
317                     (_list)->tail->next = (ecore_list_entry_t *)0; \
318                 } else {                                           \
319                     (_list)->head = (ecore_list_entry_t *)0;       \
320                 }                                                  \
321                 (_list)->cnt--;                                    \
322             }                                                      \
323         } else {                                                   \
324             (_elem)->prev->next = (_elem)->next;                   \
325             (_elem)->next->prev = (_elem)->prev;                   \
326             (_list)->cnt--;                                        \
327         }                                                          \
328     } while (0)
329
330 /* walk the list */
331 #define ECORE_LIST_FOR_EACH_ENTRY(pos, _list, _link, cast) \
332     for (pos = ECORE_LIST_FIRST_ENTRY(_list, cast, _link); \
333          pos;                                              \
334          pos = ECORE_LIST_NEXT(pos, _link, cast))
335
336 /* walk the list (safely) */
337 #define ECORE_LIST_FOR_EACH_ENTRY_SAFE(pos, n, _list, _link, cast) \
338      for (pos = ECORE_LIST_FIRST_ENTRY(_list, cast, _lint),        \
339           n = (pos) ? ECORE_LIST_NEXT(pos, _link, cast) : NULL;    \
340           pos != NULL;                                             \
341           pos = (cast *)n,                                         \
342           n = (pos) ? ECORE_LIST_NEXT(pos, _link, cast) : NULL)
343
344
345 /* Manipulate a bit vector defined as an array of uint64_t */
346
347 /* Number of bits in one sge_mask array element */
348 #define BIT_VEC64_ELEM_SZ     64
349 #define BIT_VEC64_ELEM_SHIFT  6
350 #define BIT_VEC64_ELEM_MASK   ((uint64_t)BIT_VEC64_ELEM_SZ - 1)
351
352 #define __BIT_VEC64_SET_BIT(el, bit)            \
353     do {                                        \
354         el = ((el) | ((uint64_t)0x1 << (bit))); \
355     } while (0)
356
357 #define __BIT_VEC64_CLEAR_BIT(el, bit)             \
358     do {                                           \
359         el = ((el) & (~((uint64_t)0x1 << (bit)))); \
360     } while (0)
361
362 #define BIT_VEC64_SET_BIT(vec64, idx)                           \
363     __BIT_VEC64_SET_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
364                         (idx) & BIT_VEC64_ELEM_MASK)
365
366 #define BIT_VEC64_CLEAR_BIT(vec64, idx)                           \
367     __BIT_VEC64_CLEAR_BIT((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT], \
368                           (idx) & BIT_VEC64_ELEM_MASK)
369
370 #define BIT_VEC64_TEST_BIT(vec64, idx)          \
371     (((vec64)[(idx) >> BIT_VEC64_ELEM_SHIFT] >> \
372       ((idx) & BIT_VEC64_ELEM_MASK)) & 0x1)
373
374 /*
375  * Creates a bitmask of all ones in less significant bits.
376  * idx - index of the most significant bit in the created mask
377  */
378 #define BIT_VEC64_ONES_MASK(idx)                                 \
379     (((uint64_t)0x1 << (((idx) & BIT_VEC64_ELEM_MASK) + 1)) - 1)
380 #define BIT_VEC64_ELEM_ONE_MASK ((uint64_t)(~0))
381
382 /* fill in a MAC address the way the FW likes it */
383 static inline void
384 ecore_set_fw_mac_addr(uint16_t *fw_hi,
385                       uint16_t *fw_mid,
386                       uint16_t *fw_lo,
387                       uint8_t  *mac)
388 {
389     ((uint8_t *)fw_hi)[0]  = mac[1];
390     ((uint8_t *)fw_hi)[1]  = mac[0];
391     ((uint8_t *)fw_mid)[0] = mac[3];
392     ((uint8_t *)fw_mid)[1] = mac[2];
393     ((uint8_t *)fw_lo)[0]  = mac[5];
394     ((uint8_t *)fw_lo)[1]  = mac[4];
395 }
396
397
398 enum ecore_status_t {
399     ECORE_EXISTS  = -6,
400     ECORE_IO      = -5,
401     ECORE_TIMEOUT = -4,
402     ECORE_INVAL   = -3,
403     ECORE_BUSY    = -2,
404     ECORE_NOMEM   = -1,
405     ECORE_SUCCESS = 0,
406     /* PENDING is not an error and should be positive */
407     ECORE_PENDING = 1,
408 };
409
410 enum {
411     SWITCH_UPDATE,
412     AFEX_UPDATE,
413 };
414
415
416
417
418 struct bnx2x_softc;
419 struct eth_context;
420
421 /* Bits representing general command's configuration */
422 enum {
423         RAMROD_TX,
424         RAMROD_RX,
425         /* Wait until all pending commands complete */
426         RAMROD_COMP_WAIT,
427         /* Don't send a ramrod, only update a registry */
428         RAMROD_DRV_CLR_ONLY,
429         /* Configure HW according to the current object state */
430         RAMROD_RESTORE,
431          /* Execute the next command now */
432         RAMROD_EXEC,
433         /* Don't add a new command and continue execution of posponed
434          * commands. If not set a new command will be added to the
435          * pending commands list.
436          */
437         RAMROD_CONT,
438         /* If there is another pending ramrod, wait until it finishes and
439          * re-try to submit this one. This flag can be set only in sleepable
440          * context, and should not be set from the context that completes the
441          * ramrods as deadlock will occur.
442          */
443         RAMROD_RETRY,
444 };
445
446 typedef enum {
447         ECORE_OBJ_TYPE_RX,
448         ECORE_OBJ_TYPE_TX,
449         ECORE_OBJ_TYPE_RX_TX,
450 } ecore_obj_type;
451
452 /* Public slow path states */
453 enum {
454         ECORE_FILTER_MAC_PENDING,
455         ECORE_FILTER_VLAN_PENDING,
456         ECORE_FILTER_VLAN_MAC_PENDING,
457         ECORE_FILTER_RX_MODE_PENDING,
458         ECORE_FILTER_RX_MODE_SCHED,
459         ECORE_FILTER_ISCSI_ETH_START_SCHED,
460         ECORE_FILTER_ISCSI_ETH_STOP_SCHED,
461         ECORE_FILTER_FCOE_ETH_START_SCHED,
462         ECORE_FILTER_FCOE_ETH_STOP_SCHED,
463         ECORE_FILTER_MCAST_PENDING,
464         ECORE_FILTER_MCAST_SCHED,
465         ECORE_FILTER_RSS_CONF_PENDING,
466         ECORE_AFEX_FCOE_Q_UPDATE_PENDING,
467         ECORE_AFEX_PENDING_VIFSET_MCP_ACK
468 };
469
470 struct ecore_raw_obj {
471         uint8_t         func_id;
472
473         /* Queue params */
474         uint8_t         cl_id;
475         uint32_t                cid;
476
477         /* Ramrod data buffer params */
478         void            *rdata;
479         ecore_dma_addr_t        rdata_mapping;
480
481         /* Ramrod state params */
482         int             state;   /* "ramrod is pending" state bit */
483         unsigned long   *pstate; /* pointer to state buffer */
484
485         ecore_obj_type  obj_type;
486
487         int (*wait_comp)(struct bnx2x_softc *sc,
488                          struct ecore_raw_obj *o);
489
490         int (*check_pending)(struct ecore_raw_obj *o);
491         void (*clear_pending)(struct ecore_raw_obj *o);
492         void (*set_pending)(struct ecore_raw_obj *o);
493 };
494
495 /************************* VLAN-MAC commands related parameters ***************/
496 struct ecore_mac_ramrod_data {
497         uint8_t mac[ETH_ALEN];
498         uint8_t is_inner_mac;
499 };
500
501 struct ecore_vlan_ramrod_data {
502         uint16_t vlan;
503 };
504
505 struct ecore_vlan_mac_ramrod_data {
506         uint8_t mac[ETH_ALEN];
507         uint8_t is_inner_mac;
508         uint16_t vlan;
509 };
510
511 union ecore_classification_ramrod_data {
512         struct ecore_mac_ramrod_data mac;
513         struct ecore_vlan_ramrod_data vlan;
514         struct ecore_vlan_mac_ramrod_data vlan_mac;
515 };
516
517 /* VLAN_MAC commands */
518 enum ecore_vlan_mac_cmd {
519         ECORE_VLAN_MAC_ADD,
520         ECORE_VLAN_MAC_DEL,
521         ECORE_VLAN_MAC_MOVE,
522 };
523
524 struct ecore_vlan_mac_data {
525         /* Requested command: ECORE_VLAN_MAC_XX */
526         enum ecore_vlan_mac_cmd cmd;
527         /* used to contain the data related vlan_mac_flags bits from
528          * ramrod parameters.
529          */
530         unsigned long vlan_mac_flags;
531
532         /* Needed for MOVE command */
533         struct ecore_vlan_mac_obj *target_obj;
534
535         union ecore_classification_ramrod_data u;
536 };
537
538 /*************************** Exe Queue obj ************************************/
539 union ecore_exe_queue_cmd_data {
540         struct ecore_vlan_mac_data vlan_mac;
541
542         struct {
543         } mcast;
544 };
545
546 struct ecore_exeq_elem {
547         ecore_list_entry_t              link;
548
549         /* Length of this element in the exe_chunk. */
550         int                             cmd_len;
551
552         union ecore_exe_queue_cmd_data  cmd_data;
553 };
554
555 union ecore_qable_obj;
556
557 union ecore_exeq_comp_elem {
558         union event_ring_elem *elem;
559 };
560
561 struct ecore_exe_queue_obj;
562
563 typedef int (*exe_q_validate)(struct bnx2x_softc *sc,
564                               union ecore_qable_obj *o,
565                               struct ecore_exeq_elem *elem);
566
567 typedef int (*exe_q_remove)(struct bnx2x_softc *sc,
568                             union ecore_qable_obj *o,
569                             struct ecore_exeq_elem *elem);
570
571 /* Return positive if entry was optimized, 0 - if not, negative
572  * in case of an error.
573  */
574 typedef int (*exe_q_optimize)(struct bnx2x_softc *sc,
575                               union ecore_qable_obj *o,
576                               struct ecore_exeq_elem *elem);
577 typedef int (*exe_q_execute)(struct bnx2x_softc *sc,
578                              union ecore_qable_obj *o,
579                              ecore_list_t *exe_chunk,
580                              unsigned long *ramrod_flags);
581 typedef struct ecore_exeq_elem *
582                         (*exe_q_get)(struct ecore_exe_queue_obj *o,
583                                      struct ecore_exeq_elem *elem);
584
585 struct ecore_exe_queue_obj {
586         /* Commands pending for an execution. */
587         ecore_list_t    exe_queue;
588
589         /* Commands pending for an completion. */
590         ecore_list_t    pending_comp;
591
592         ECORE_MUTEX_SPIN                lock;
593
594         /* Maximum length of commands' list for one execution */
595         int                     exe_chunk_len;
596
597         union ecore_qable_obj   *owner;
598
599         /****** Virtual functions ******/
600         /**
601          * Called before commands execution for commands that are really
602          * going to be executed (after 'optimize').
603          *
604          * Must run under exe_queue->lock
605          */
606         exe_q_validate          validate;
607
608         /**
609          * Called before removing pending commands, cleaning allocated
610          * resources (e.g., credits from validate)
611          */
612          exe_q_remove           remove;
613
614         /**
615          * This will try to cancel the current pending commands list
616          * considering the new command.
617          *
618          * Returns the number of optimized commands or a negative error code
619          *
620          * Must run under exe_queue->lock
621          */
622         exe_q_optimize          optimize;
623
624         /**
625          * Run the next commands chunk (owner specific).
626          */
627         exe_q_execute           execute;
628
629         /**
630          * Return the exe_queue element containing the specific command
631          * if any. Otherwise return NULL.
632          */
633         exe_q_get               get;
634 };
635 /***************** Classification verbs: Set/Del MAC/VLAN/VLAN-MAC ************/
636 /*
637  * Element in the VLAN_MAC registry list having all current configured
638  * rules.
639  */
640 struct ecore_vlan_mac_registry_elem {
641         ecore_list_entry_t      link;
642
643         /* Used to store the cam offset used for the mac/vlan/vlan-mac.
644          * Relevant for 57711 only. VLANs and MACs share the
645          * same CAM for these chips.
646          */
647         int                     cam_offset;
648
649         /* Needed for DEL and RESTORE flows */
650         unsigned long           vlan_mac_flags;
651
652         union ecore_classification_ramrod_data u;
653 };
654
655 /* Bits representing VLAN_MAC commands specific flags */
656 enum {
657         ECORE_UC_LIST_MAC,
658         ECORE_ETH_MAC,
659         ECORE_ISCSI_ETH_MAC,
660         ECORE_NETQ_ETH_MAC,
661         ECORE_DONT_CONSUME_CAM_CREDIT,
662         ECORE_DONT_CONSUME_CAM_CREDIT_DEST,
663 };
664
665 struct ecore_vlan_mac_ramrod_params {
666         /* Object to run the command from */
667         struct ecore_vlan_mac_obj *vlan_mac_obj;
668
669         /* General command flags: COMP_WAIT, etc. */
670         unsigned long ramrod_flags;
671
672         /* Command specific configuration request */
673         struct ecore_vlan_mac_data user_req;
674 };
675
676 struct ecore_vlan_mac_obj {
677         struct ecore_raw_obj raw;
678
679         /* Bookkeeping list: will prevent the addition of already existing
680          * entries.
681          */
682         ecore_list_t            head;
683         /* Implement a simple reader/writer lock on the head list.
684          * all these fields should only be accessed under the exe_queue lock
685          */
686         uint8_t         head_reader; /* Num. of readers accessing head list */
687         int             head_exe_request; /* Pending execution request. */
688         unsigned long   saved_ramrod_flags; /* Ramrods of pending execution */
689
690         /* Execution queue interface instance */
691         struct ecore_exe_queue_obj      exe_queue;
692
693         /* MACs credit pool */
694         struct ecore_credit_pool_obj    *macs_pool;
695
696         /* VLANs credit pool */
697         struct ecore_credit_pool_obj    *vlans_pool;
698
699         /* RAMROD command to be used */
700         int                             ramrod_cmd;
701
702         /* copy first n elements onto preallocated buffer
703          *
704          * @param n number of elements to get
705          * @param buf buffer preallocated by caller into which elements
706          *            will be copied. Note elements are 4-byte aligned
707          *            so buffer size must be able to accommodate the
708          *            aligned elements.
709          *
710          * @return number of copied bytes
711          */
712
713         int (*get_n_elements)(struct bnx2x_softc *sc,
714                               struct ecore_vlan_mac_obj *o, int n, uint8_t *base,
715                               uint8_t stride, uint8_t size);
716
717         /**
718          * Checks if ADD-ramrod with the given params may be performed.
719          *
720          * @return zero if the element may be added
721          */
722
723         int (*check_add)(struct bnx2x_softc *sc,
724                          struct ecore_vlan_mac_obj *o,
725                          union ecore_classification_ramrod_data *data);
726
727         /**
728          * Checks if DEL-ramrod with the given params may be performed.
729          *
730          * @return TRUE if the element may be deleted
731          */
732         struct ecore_vlan_mac_registry_elem *
733                 (*check_del)(struct bnx2x_softc *sc,
734                              struct ecore_vlan_mac_obj *o,
735                              union ecore_classification_ramrod_data *data);
736
737         /**
738          * Checks if DEL-ramrod with the given params may be performed.
739          *
740          * @return TRUE if the element may be deleted
741          */
742         int (*check_move)(struct bnx2x_softc *sc,
743                            struct ecore_vlan_mac_obj *src_o,
744                            struct ecore_vlan_mac_obj *dst_o,
745                            union ecore_classification_ramrod_data *data);
746
747         /**
748          *  Update the relevant credit object(s) (consume/return
749          *  correspondingly).
750          */
751         int (*get_credit)(struct ecore_vlan_mac_obj *o);
752         int (*put_credit)(struct ecore_vlan_mac_obj *o);
753         int (*get_cam_offset)(struct ecore_vlan_mac_obj *o, int *offset);
754         int (*put_cam_offset)(struct ecore_vlan_mac_obj *o, int offset);
755
756         /**
757          * Configures one rule in the ramrod data buffer.
758          */
759         void (*set_one_rule)(struct bnx2x_softc *sc,
760                              struct ecore_vlan_mac_obj *o,
761                              struct ecore_exeq_elem *elem, int rule_idx,
762                              int cam_offset);
763
764         /**
765         *  Delete all configured elements having the given
766         *  vlan_mac_flags specification. Assumes no pending for
767         *  execution commands. Will schedule all all currently
768         *  configured MACs/VLANs/VLAN-MACs matching the vlan_mac_flags
769         *  specification for deletion and will use the given
770         *  ramrod_flags for the last DEL operation.
771          *
772          * @param sc
773          * @param o
774          * @param ramrod_flags RAMROD_XX flags
775          *
776          * @return 0 if the last operation has completed successfully
777          *         and there are no more elements left, positive value
778          *         if there are pending for completion commands,
779          *         negative value in case of failure.
780          */
781         int (*delete_all)(struct bnx2x_softc *sc,
782                           struct ecore_vlan_mac_obj *o,
783                           unsigned long *vlan_mac_flags,
784                           unsigned long *ramrod_flags);
785
786         /**
787          * Reconfigures the next MAC/VLAN/VLAN-MAC element from the previously
788          * configured elements list.
789          *
790          * @param sc
791          * @param p Command parameters (RAMROD_COMP_WAIT bit in
792          *          ramrod_flags is only taken into an account)
793          * @param ppos a pointer to the cookie that should be given back in the
794          *        next call to make function handle the next element. If
795          *        *ppos is set to NULL it will restart the iterator.
796          *        If returned *ppos == NULL this means that the last
797          *        element has been handled.
798          *
799          * @return int
800          */
801         int (*restore)(struct bnx2x_softc *sc,
802                        struct ecore_vlan_mac_ramrod_params *p,
803                        struct ecore_vlan_mac_registry_elem **ppos);
804
805         /**
806          * Should be called on a completion arrival.
807          *
808          * @param sc
809          * @param o
810          * @param cqe Completion element we are handling
811          * @param ramrod_flags if RAMROD_CONT is set the next bulk of
812          *                     pending commands will be executed.
813          *                     RAMROD_DRV_CLR_ONLY and RAMROD_RESTORE
814          *                     may also be set if needed.
815          *
816          * @return 0 if there are neither pending nor waiting for
817          *         completion commands. Positive value if there are
818          *         pending for execution or for completion commands.
819          *         Negative value in case of an error (including an
820          *         error in the cqe).
821          */
822         int (*complete)(struct bnx2x_softc *sc, struct ecore_vlan_mac_obj *o,
823                         union event_ring_elem *cqe,
824                         unsigned long *ramrod_flags);
825
826         /**
827          * Wait for completion of all commands. Don't schedule new ones,
828          * just wait. It assumes that the completion code will schedule
829          * for new commands.
830          */
831         int (*wait)(struct bnx2x_softc *sc, struct ecore_vlan_mac_obj *o);
832 };
833
834 enum {
835         ECORE_LLH_CAM_ISCSI_ETH_LINE = 0,
836         ECORE_LLH_CAM_ETH_LINE,
837         ECORE_LLH_CAM_MAX_PF_LINE = NIG_REG_LLH1_FUNC_MEM_SIZE / 2
838 };
839
840 /** RX_MODE verbs:DROP_ALL/ACCEPT_ALL/ACCEPT_ALL_MULTI/ACCEPT_ALL_VLAN/NORMAL */
841
842 /* RX_MODE ramrod special flags: set in rx_mode_flags field in
843  * a ecore_rx_mode_ramrod_params.
844  */
845 enum {
846         ECORE_RX_MODE_FCOE_ETH,
847         ECORE_RX_MODE_ISCSI_ETH,
848 };
849
850 enum {
851         ECORE_ACCEPT_UNICAST,
852         ECORE_ACCEPT_MULTICAST,
853         ECORE_ACCEPT_ALL_UNICAST,
854         ECORE_ACCEPT_ALL_MULTICAST,
855         ECORE_ACCEPT_BROADCAST,
856         ECORE_ACCEPT_UNMATCHED,
857         ECORE_ACCEPT_ANY_VLAN
858 };
859
860 struct ecore_rx_mode_ramrod_params {
861         struct ecore_rx_mode_obj *rx_mode_obj;
862         unsigned long *pstate;
863         int state;
864         uint8_t cl_id;
865         uint32_t cid;
866         uint8_t func_id;
867         unsigned long ramrod_flags;
868         unsigned long rx_mode_flags;
869
870         /* rdata is either a pointer to eth_filter_rules_ramrod_data(e2) or to
871          * a tstorm_eth_mac_filter_config (e1x).
872          */
873         void *rdata;
874         ecore_dma_addr_t rdata_mapping;
875
876         /* Rx mode settings */
877         unsigned long rx_accept_flags;
878
879         /* internal switching settings */
880         unsigned long tx_accept_flags;
881 };
882
883 struct ecore_rx_mode_obj {
884         int (*config_rx_mode)(struct bnx2x_softc *sc,
885                               struct ecore_rx_mode_ramrod_params *p);
886
887         int (*wait_comp)(struct bnx2x_softc *sc,
888                          struct ecore_rx_mode_ramrod_params *p);
889 };
890
891 /********************** Set multicast group ***********************************/
892
893 struct ecore_mcast_list_elem {
894         ecore_list_entry_t link;
895         uint8_t *mac;
896 };
897
898 union ecore_mcast_config_data {
899         uint8_t *mac;
900         uint8_t bin; /* used in a RESTORE flow */
901 };
902
903 struct ecore_mcast_ramrod_params {
904         struct ecore_mcast_obj *mcast_obj;
905
906         /* Relevant options are RAMROD_COMP_WAIT and RAMROD_DRV_CLR_ONLY */
907         unsigned long ramrod_flags;
908
909         ecore_list_t mcast_list; /* list of struct ecore_mcast_list_elem */
910         int mcast_list_len;
911 };
912
913 enum ecore_mcast_cmd {
914         ECORE_MCAST_CMD_ADD,
915         ECORE_MCAST_CMD_CONT,
916         ECORE_MCAST_CMD_DEL,
917         ECORE_MCAST_CMD_RESTORE,
918 };
919
920 struct ecore_mcast_obj {
921         struct ecore_raw_obj raw;
922
923         union {
924                 struct {
925                 #define ECORE_MCAST_BINS_NUM    256
926                 #define ECORE_MCAST_VEC_SZ      (ECORE_MCAST_BINS_NUM / 64)
927                         uint64_t vec[ECORE_MCAST_VEC_SZ];
928
929                         /** Number of BINs to clear. Should be updated
930                          *  immediately when a command arrives in order to
931                          *  properly create DEL commands.
932                          */
933                         int num_bins_set;
934                 } aprox_match;
935
936                 struct {
937                         ecore_list_t macs;
938                         int num_macs_set;
939                 } exact_match;
940         } registry;
941
942         /* Pending commands */
943         ecore_list_t pending_cmds_head;
944
945         /* A state that is set in raw.pstate, when there are pending commands */
946         int sched_state;
947
948         /* Maximal number of mcast MACs configured in one command */
949         int max_cmd_len;
950
951         /* Total number of currently pending MACs to configure: both
952          * in the pending commands list and in the current command.
953          */
954         int total_pending_num;
955
956         uint8_t engine_id;
957
958         /**
959          * @param cmd command to execute (ECORE_MCAST_CMD_X, see above)
960          */
961         int (*config_mcast)(struct bnx2x_softc *sc,
962                             struct ecore_mcast_ramrod_params *p,
963                             enum ecore_mcast_cmd cmd);
964
965         /**
966          * Fills the ramrod data during the RESTORE flow.
967          *
968          * @param sc
969          * @param o
970          * @param start_idx Registry index to start from
971          * @param rdata_idx Index in the ramrod data to start from
972          *
973          * @return -1 if we handled the whole registry or index of the last
974          *         handled registry element.
975          */
976         int (*hdl_restore)(struct bnx2x_softc *sc, struct ecore_mcast_obj *o,
977                            int start_bin, int *rdata_idx);
978
979         int (*enqueue_cmd)(struct bnx2x_softc *sc, struct ecore_mcast_obj *o,
980                            struct ecore_mcast_ramrod_params *p,
981                            enum ecore_mcast_cmd cmd);
982
983         void (*set_one_rule)(struct bnx2x_softc *sc,
984                              struct ecore_mcast_obj *o, int idx,
985                              union ecore_mcast_config_data *cfg_data,
986                              enum ecore_mcast_cmd cmd);
987
988         /** Checks if there are more mcast MACs to be set or a previous
989          *  command is still pending.
990          */
991         int (*check_pending)(struct ecore_mcast_obj *o);
992
993         /**
994          * Set/Clear/Check SCHEDULED state of the object
995          */
996         void (*set_sched)(struct ecore_mcast_obj *o);
997         void (*clear_sched)(struct ecore_mcast_obj *o);
998         int (*check_sched)(struct ecore_mcast_obj *o);
999
1000         /* Wait until all pending commands complete */
1001         int (*wait_comp)(struct bnx2x_softc *sc, struct ecore_mcast_obj *o);
1002
1003         /**
1004          * Handle the internal object counters needed for proper
1005          * commands handling. Checks that the provided parameters are
1006          * feasible.
1007          */
1008         int (*validate)(struct bnx2x_softc *sc,
1009                         struct ecore_mcast_ramrod_params *p,
1010                         enum ecore_mcast_cmd cmd);
1011
1012         /**
1013          * Restore the values of internal counters in case of a failure.
1014          */
1015         void (*revert)(struct bnx2x_softc *sc,
1016                        struct ecore_mcast_ramrod_params *p,
1017                        int old_num_bins);
1018
1019         int (*get_registry_size)(struct ecore_mcast_obj *o);
1020         void (*set_registry_size)(struct ecore_mcast_obj *o, int n);
1021 };
1022
1023 /*************************** Credit handling **********************************/
1024 struct ecore_credit_pool_obj {
1025
1026         /* Current amount of credit in the pool */
1027         ecore_atomic_t  credit;
1028
1029         /* Maximum allowed credit. put() will check against it. */
1030         int             pool_sz;
1031
1032         /* Allocate a pool table statically.
1033          *
1034          * Currently the maximum allowed size is MAX_MAC_CREDIT_E2(272)
1035          *
1036          * The set bit in the table will mean that the entry is available.
1037          */
1038 #define ECORE_POOL_VEC_SIZE     (MAX_MAC_CREDIT_E2 / 64)
1039         uint64_t                pool_mirror[ECORE_POOL_VEC_SIZE];
1040
1041         /* Base pool offset (initialized differently */
1042         int             base_pool_offset;
1043
1044         /**
1045          * Get the next free pool entry.
1046          *
1047          * @return TRUE if there was a free entry in the pool
1048          */
1049         int (*get_entry)(struct ecore_credit_pool_obj *o, int *entry);
1050
1051         /**
1052          * Return the entry back to the pool.
1053          *
1054          * @return TRUE if entry is legal and has been successfully
1055          *         returned to the pool.
1056          */
1057         int (*put_entry)(struct ecore_credit_pool_obj *o, int entry);
1058
1059         /**
1060          * Get the requested amount of credit from the pool.
1061          *
1062          * @param cnt Amount of requested credit
1063          * @return TRUE if the operation is successful
1064          */
1065         int (*get)(struct ecore_credit_pool_obj *o, int cnt);
1066
1067         /**
1068          * Returns the credit to the pool.
1069          *
1070          * @param cnt Amount of credit to return
1071          * @return TRUE if the operation is successful
1072          */
1073         int (*put)(struct ecore_credit_pool_obj *o, int cnt);
1074
1075         /**
1076          * Reads the current amount of credit.
1077          */
1078         int (*check)(struct ecore_credit_pool_obj *o);
1079 };
1080
1081 /*************************** RSS configuration ********************************/
1082 enum {
1083         /* RSS_MODE bits are mutually exclusive */
1084         ECORE_RSS_MODE_DISABLED,
1085         ECORE_RSS_MODE_REGULAR,
1086
1087         ECORE_RSS_SET_SRCH, /* Setup searcher, E1x specific flag */
1088
1089         ECORE_RSS_IPV4,
1090         ECORE_RSS_IPV4_TCP,
1091         ECORE_RSS_IPV4_UDP,
1092         ECORE_RSS_IPV6,
1093         ECORE_RSS_IPV6_TCP,
1094         ECORE_RSS_IPV6_UDP,
1095
1096         ECORE_RSS_TUNNELING,
1097 };
1098
1099 struct ecore_config_rss_params {
1100         struct ecore_rss_config_obj *rss_obj;
1101
1102         /* may have RAMROD_COMP_WAIT set only */
1103         unsigned long   ramrod_flags;
1104
1105         /* ECORE_RSS_X bits */
1106         unsigned long   rss_flags;
1107
1108         /* Number hash bits to take into an account */
1109         uint8_t         rss_result_mask;
1110
1111         /* Indirection table */
1112         uint8_t         ind_table[T_ETH_INDIRECTION_TABLE_SIZE];
1113
1114         /* RSS hash values */
1115         uint32_t                rss_key[10];
1116
1117         /* valid only if ECORE_RSS_UPDATE_TOE is set */
1118         uint16_t                toe_rss_bitmap;
1119
1120         /* valid if ECORE_RSS_TUNNELING is set */
1121         uint16_t                tunnel_value;
1122         uint16_t                tunnel_mask;
1123 };
1124
1125 struct ecore_rss_config_obj {
1126         struct ecore_raw_obj    raw;
1127
1128         /* RSS engine to use */
1129         uint8_t                 engine_id;
1130
1131         /* Last configured indirection table */
1132         uint8_t                 ind_table[T_ETH_INDIRECTION_TABLE_SIZE];
1133
1134         /* flags for enabling 4-tupple hash on UDP */
1135         uint8_t                 udp_rss_v4;
1136         uint8_t                 udp_rss_v6;
1137
1138         int (*config_rss)(struct bnx2x_softc *sc,
1139                           struct ecore_config_rss_params *p);
1140 };
1141
1142 /*********************** Queue state update ***********************************/
1143
1144 /* UPDATE command options */
1145 enum {
1146         ECORE_Q_UPDATE_IN_VLAN_REM,
1147         ECORE_Q_UPDATE_IN_VLAN_REM_CHNG,
1148         ECORE_Q_UPDATE_OUT_VLAN_REM,
1149         ECORE_Q_UPDATE_OUT_VLAN_REM_CHNG,
1150         ECORE_Q_UPDATE_ANTI_SPOOF,
1151         ECORE_Q_UPDATE_ANTI_SPOOF_CHNG,
1152         ECORE_Q_UPDATE_ACTIVATE,
1153         ECORE_Q_UPDATE_ACTIVATE_CHNG,
1154         ECORE_Q_UPDATE_DEF_VLAN_EN,
1155         ECORE_Q_UPDATE_DEF_VLAN_EN_CHNG,
1156         ECORE_Q_UPDATE_SILENT_VLAN_REM_CHNG,
1157         ECORE_Q_UPDATE_SILENT_VLAN_REM,
1158         ECORE_Q_UPDATE_TX_SWITCHING_CHNG,
1159         ECORE_Q_UPDATE_TX_SWITCHING,
1160 };
1161
1162 /* Allowed Queue states */
1163 enum ecore_q_state {
1164         ECORE_Q_STATE_RESET,
1165         ECORE_Q_STATE_INITIALIZED,
1166         ECORE_Q_STATE_ACTIVE,
1167         ECORE_Q_STATE_MULTI_COS,
1168         ECORE_Q_STATE_MCOS_TERMINATED,
1169         ECORE_Q_STATE_INACTIVE,
1170         ECORE_Q_STATE_STOPPED,
1171         ECORE_Q_STATE_TERMINATED,
1172         ECORE_Q_STATE_FLRED,
1173         ECORE_Q_STATE_MAX,
1174 };
1175
1176 /* Allowed Queue states */
1177 enum ecore_q_logical_state {
1178         ECORE_Q_LOGICAL_STATE_ACTIVE,
1179         ECORE_Q_LOGICAL_STATE_STOPPED,
1180 };
1181
1182 /* Allowed commands */
1183 enum ecore_queue_cmd {
1184         ECORE_Q_CMD_INIT,
1185         ECORE_Q_CMD_SETUP,
1186         ECORE_Q_CMD_SETUP_TX_ONLY,
1187         ECORE_Q_CMD_DEACTIVATE,
1188         ECORE_Q_CMD_ACTIVATE,
1189         ECORE_Q_CMD_UPDATE,
1190         ECORE_Q_CMD_UPDATE_TPA,
1191         ECORE_Q_CMD_HALT,
1192         ECORE_Q_CMD_CFC_DEL,
1193         ECORE_Q_CMD_TERMINATE,
1194         ECORE_Q_CMD_EMPTY,
1195         ECORE_Q_CMD_MAX,
1196 };
1197
1198 /* queue SETUP + INIT flags */
1199 enum {
1200         ECORE_Q_FLG_TPA,
1201         ECORE_Q_FLG_TPA_IPV6,
1202         ECORE_Q_FLG_TPA_GRO,
1203         ECORE_Q_FLG_STATS,
1204         ECORE_Q_FLG_ZERO_STATS,
1205         ECORE_Q_FLG_ACTIVE,
1206         ECORE_Q_FLG_OV,
1207         ECORE_Q_FLG_VLAN,
1208         ECORE_Q_FLG_COS,
1209         ECORE_Q_FLG_HC,
1210         ECORE_Q_FLG_HC_EN,
1211         ECORE_Q_FLG_DHC,
1212         ECORE_Q_FLG_OOO,
1213         ECORE_Q_FLG_FCOE,
1214         ECORE_Q_FLG_LEADING_RSS,
1215         ECORE_Q_FLG_MCAST,
1216         ECORE_Q_FLG_DEF_VLAN,
1217         ECORE_Q_FLG_TX_SWITCH,
1218         ECORE_Q_FLG_TX_SEC,
1219         ECORE_Q_FLG_ANTI_SPOOF,
1220         ECORE_Q_FLG_SILENT_VLAN_REM,
1221         ECORE_Q_FLG_FORCE_DEFAULT_PRI,
1222         ECORE_Q_FLG_REFUSE_OUTBAND_VLAN,
1223         ECORE_Q_FLG_PCSUM_ON_PKT,
1224         ECORE_Q_FLG_TUN_INC_INNER_IP_ID
1225 };
1226
1227 /* Queue type options: queue type may be a combination of below. */
1228 enum ecore_q_type {
1229         ECORE_Q_TYPE_FWD,
1230         ECORE_Q_TYPE_HAS_RX,
1231         ECORE_Q_TYPE_HAS_TX,
1232 };
1233
1234 #define ECORE_PRIMARY_CID_INDEX                 0
1235 #define ECORE_MULTI_TX_COS_E1X                  3 /* QM only */
1236 #define ECORE_MULTI_TX_COS_E2_E3A0              2
1237 #define ECORE_MULTI_TX_COS_E3B0                 3
1238 #define ECORE_MULTI_TX_COS                      3 /* Maximum possible */
1239 #define MAC_PAD (ECORE_ALIGN(ETH_ALEN, sizeof(uint32_t)) - ETH_ALEN)
1240
1241 struct ecore_queue_init_params {
1242         struct {
1243                 unsigned long   flags;
1244                 uint16_t                hc_rate;
1245                 uint8_t         fw_sb_id;
1246                 uint8_t         sb_cq_index;
1247         } tx;
1248
1249         struct {
1250                 unsigned long   flags;
1251                 uint16_t                hc_rate;
1252                 uint8_t         fw_sb_id;
1253                 uint8_t         sb_cq_index;
1254         } rx;
1255
1256         /* CID context in the host memory */
1257         struct eth_context *cxts[ECORE_MULTI_TX_COS];
1258
1259         /* maximum number of cos supported by hardware */
1260         uint8_t max_cos;
1261 };
1262
1263 struct ecore_queue_terminate_params {
1264         /* index within the tx_only cids of this queue object */
1265         uint8_t cid_index;
1266 };
1267
1268 struct ecore_queue_cfc_del_params {
1269         /* index within the tx_only cids of this queue object */
1270         uint8_t cid_index;
1271 };
1272
1273 struct ecore_queue_update_params {
1274         unsigned long   update_flags; /* ECORE_Q_UPDATE_XX bits */
1275         uint16_t                def_vlan;
1276         uint16_t                silent_removal_value;
1277         uint16_t                silent_removal_mask;
1278 /* index within the tx_only cids of this queue object */
1279         uint8_t         cid_index;
1280 };
1281
1282 struct rxq_pause_params {
1283         uint16_t                bd_th_lo;
1284         uint16_t                bd_th_hi;
1285         uint16_t                rcq_th_lo;
1286         uint16_t                rcq_th_hi;
1287         uint16_t                sge_th_lo; /* valid if ECORE_Q_FLG_TPA */
1288         uint16_t                sge_th_hi; /* valid if ECORE_Q_FLG_TPA */
1289         uint16_t                pri_map;
1290 };
1291
1292 /* general */
1293 struct ecore_general_setup_params {
1294         /* valid if ECORE_Q_FLG_STATS */
1295         uint8_t         stat_id;
1296
1297         uint8_t         spcl_id;
1298         uint16_t                mtu;
1299         uint8_t         cos;
1300 };
1301
1302 struct ecore_rxq_setup_params {
1303         /* dma */
1304         ecore_dma_addr_t        dscr_map;
1305         ecore_dma_addr_t        rcq_map;
1306         ecore_dma_addr_t        rcq_np_map;
1307
1308         uint16_t                drop_flags;
1309         uint16_t                buf_sz;
1310         uint8_t         fw_sb_id;
1311         uint8_t         cl_qzone_id;
1312
1313         /* valid if ECORE_Q_FLG_TPA */
1314         uint16_t                tpa_agg_sz;
1315         uint8_t         max_tpa_queues;
1316         uint8_t         rss_engine_id;
1317
1318         /* valid if ECORE_Q_FLG_MCAST */
1319         uint8_t         mcast_engine_id;
1320
1321         uint8_t         cache_line_log;
1322
1323         uint8_t         sb_cq_index;
1324
1325         /* valid if BXN2X_Q_FLG_SILENT_VLAN_REM */
1326         uint16_t silent_removal_value;
1327         uint16_t silent_removal_mask;
1328 };
1329
1330 struct ecore_txq_setup_params {
1331         /* dma */
1332         ecore_dma_addr_t        dscr_map;
1333
1334         uint8_t         fw_sb_id;
1335         uint8_t         sb_cq_index;
1336         uint8_t         cos;            /* valid if ECORE_Q_FLG_COS */
1337         uint16_t                traffic_type;
1338         /* equals to the leading rss client id, used for TX classification*/
1339         uint8_t         tss_leading_cl_id;
1340
1341         /* valid if ECORE_Q_FLG_DEF_VLAN */
1342         uint16_t                default_vlan;
1343 };
1344
1345 struct ecore_queue_setup_params {
1346         struct ecore_general_setup_params gen_params;
1347         struct ecore_txq_setup_params txq_params;
1348         struct ecore_rxq_setup_params rxq_params;
1349         struct rxq_pause_params pause_params;
1350         unsigned long flags;
1351 };
1352
1353 struct ecore_queue_setup_tx_only_params {
1354         struct ecore_general_setup_params       gen_params;
1355         struct ecore_txq_setup_params           txq_params;
1356         unsigned long                           flags;
1357         /* index within the tx_only cids of this queue object */
1358         uint8_t                                 cid_index;
1359 };
1360
1361 struct ecore_queue_state_params {
1362         struct ecore_queue_sp_obj *q_obj;
1363
1364         /* Current command */
1365         enum ecore_queue_cmd cmd;
1366
1367         /* may have RAMROD_COMP_WAIT set only */
1368         unsigned long ramrod_flags;
1369
1370         /* Params according to the current command */
1371         union {
1372                 struct ecore_queue_update_params        update;
1373                 struct ecore_queue_setup_params         setup;
1374                 struct ecore_queue_init_params          init;
1375                 struct ecore_queue_setup_tx_only_params tx_only;
1376                 struct ecore_queue_terminate_params     terminate;
1377                 struct ecore_queue_cfc_del_params       cfc_del;
1378         } params;
1379 };
1380
1381 struct ecore_viflist_params {
1382         uint8_t echo_res;
1383         uint8_t func_bit_map_res;
1384 };
1385
1386 struct ecore_queue_sp_obj {
1387         uint32_t                cids[ECORE_MULTI_TX_COS];
1388         uint8_t         cl_id;
1389         uint8_t         func_id;
1390
1391         /* number of traffic classes supported by queue.
1392          * The primary connection of the queue supports the first traffic
1393          * class. Any further traffic class is supported by a tx-only
1394          * connection.
1395          *
1396          * Therefore max_cos is also a number of valid entries in the cids
1397          * array.
1398          */
1399         uint8_t max_cos;
1400         uint8_t num_tx_only, next_tx_only;
1401
1402         enum ecore_q_state state, next_state;
1403
1404         /* bits from enum ecore_q_type */
1405         unsigned long   type;
1406
1407         /* ECORE_Q_CMD_XX bits. This object implements "one
1408          * pending" paradigm but for debug and tracing purposes it's
1409          * more convenient to have different bits for different
1410          * commands.
1411          */
1412         unsigned long   pending;
1413
1414         /* Buffer to use as a ramrod data and its mapping */
1415         void            *rdata;
1416         ecore_dma_addr_t        rdata_mapping;
1417
1418         /**
1419          * Performs one state change according to the given parameters.
1420          *
1421          * @return 0 in case of success and negative value otherwise.
1422          */
1423         int (*send_cmd)(struct bnx2x_softc *sc,
1424                         struct ecore_queue_state_params *params);
1425
1426         /**
1427          * Sets the pending bit according to the requested transition.
1428          */
1429         int (*set_pending)(struct ecore_queue_sp_obj *o,
1430                            struct ecore_queue_state_params *params);
1431
1432         /**
1433          * Checks that the requested state transition is legal.
1434          */
1435         int (*check_transition)(struct bnx2x_softc *sc,
1436                                 struct ecore_queue_sp_obj *o,
1437                                 struct ecore_queue_state_params *params);
1438
1439         /**
1440          * Completes the pending command.
1441          */
1442         int (*complete_cmd)(struct bnx2x_softc *sc,
1443                             struct ecore_queue_sp_obj *o,
1444                             enum ecore_queue_cmd);
1445
1446         int (*wait_comp)(struct bnx2x_softc *sc,
1447                          struct ecore_queue_sp_obj *o,
1448                          enum ecore_queue_cmd cmd);
1449 };
1450
1451 /********************** Function state update *********************************/
1452 /* Allowed Function states */
1453 enum ecore_func_state {
1454         ECORE_F_STATE_RESET,
1455         ECORE_F_STATE_INITIALIZED,
1456         ECORE_F_STATE_STARTED,
1457         ECORE_F_STATE_TX_STOPPED,
1458         ECORE_F_STATE_MAX,
1459 };
1460
1461 /* Allowed Function commands */
1462 enum ecore_func_cmd {
1463         ECORE_F_CMD_HW_INIT,
1464         ECORE_F_CMD_START,
1465         ECORE_F_CMD_STOP,
1466         ECORE_F_CMD_HW_RESET,
1467         ECORE_F_CMD_AFEX_UPDATE,
1468         ECORE_F_CMD_AFEX_VIFLISTS,
1469         ECORE_F_CMD_TX_STOP,
1470         ECORE_F_CMD_TX_START,
1471         ECORE_F_CMD_SWITCH_UPDATE,
1472         ECORE_F_CMD_MAX,
1473 };
1474
1475 struct ecore_func_hw_init_params {
1476         /* A load phase returned by MCP.
1477          *
1478          * May be:
1479          *              FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
1480          *              FW_MSG_CODE_DRV_LOAD_COMMON
1481          *              FW_MSG_CODE_DRV_LOAD_PORT
1482          *              FW_MSG_CODE_DRV_LOAD_FUNCTION
1483          */
1484         uint32_t load_phase;
1485 };
1486
1487 struct ecore_func_hw_reset_params {
1488         /* A load phase returned by MCP.
1489          *
1490          * May be:
1491          *              FW_MSG_CODE_DRV_LOAD_COMMON_CHIP
1492          *              FW_MSG_CODE_DRV_LOAD_COMMON
1493          *              FW_MSG_CODE_DRV_LOAD_PORT
1494          *              FW_MSG_CODE_DRV_LOAD_FUNCTION
1495          */
1496         uint32_t reset_phase;
1497 };
1498
1499 struct ecore_func_start_params {
1500         /* Multi Function mode:
1501          *      - Single Function
1502          *      - Switch Dependent
1503          *      - Switch Independent
1504          */
1505         uint16_t mf_mode;
1506
1507         /* Switch Dependent mode outer VLAN tag */
1508         uint16_t sd_vlan_tag;
1509
1510         /* Function cos mode */
1511         uint8_t network_cos_mode;
1512
1513         /* NVGRE classification enablement */
1514         uint8_t nvgre_clss_en;
1515
1516         /* NO_GRE_TUNNEL/NVGRE_TUNNEL/L2GRE_TUNNEL/IPGRE_TUNNEL */
1517         uint8_t gre_tunnel_mode;
1518
1519         /* GRE_OUTER_HEADERS_RSS/GRE_INNER_HEADERS_RSS/NVGRE_KEY_ENTROPY_RSS */
1520         uint8_t gre_tunnel_rss;
1521
1522 };
1523
1524 struct ecore_func_switch_update_params {
1525         uint8_t suspend;
1526 };
1527
1528 struct ecore_func_afex_update_params {
1529         uint16_t vif_id;
1530         uint16_t afex_default_vlan;
1531         uint8_t allowed_priorities;
1532 };
1533
1534 struct ecore_func_afex_viflists_params {
1535         uint16_t vif_list_index;
1536         uint8_t func_bit_map;
1537         uint8_t afex_vif_list_command;
1538         uint8_t func_to_clear;
1539 };
1540 struct ecore_func_tx_start_params {
1541         struct priority_cos traffic_type_to_priority_cos[MAX_TRAFFIC_TYPES];
1542         uint8_t dcb_enabled;
1543         uint8_t dcb_version;
1544         uint8_t dont_add_pri_0;
1545 };
1546
1547 struct ecore_func_state_params {
1548         struct ecore_func_sp_obj *f_obj;
1549
1550         /* Current command */
1551         enum ecore_func_cmd cmd;
1552
1553         /* may have RAMROD_COMP_WAIT set only */
1554         unsigned long   ramrod_flags;
1555
1556         /* Params according to the current command */
1557         union {
1558                 struct ecore_func_hw_init_params hw_init;
1559                 struct ecore_func_hw_reset_params hw_reset;
1560                 struct ecore_func_start_params start;
1561                 struct ecore_func_switch_update_params switch_update;
1562                 struct ecore_func_afex_update_params afex_update;
1563                 struct ecore_func_afex_viflists_params afex_viflists;
1564                 struct ecore_func_tx_start_params tx_start;
1565         } params;
1566 };
1567
1568 struct ecore_func_sp_drv_ops {
1569         /* Init tool + runtime initialization:
1570          *      - Common Chip
1571          *      - Common (per Path)
1572          *      - Port
1573          *      - Function phases
1574          */
1575         int (*init_hw_cmn_chip)(struct bnx2x_softc *sc);
1576         int (*init_hw_cmn)(struct bnx2x_softc *sc);
1577         int (*init_hw_port)(struct bnx2x_softc *sc);
1578         int (*init_hw_func)(struct bnx2x_softc *sc);
1579
1580         /* Reset Function HW: Common, Port, Function phases. */
1581         void (*reset_hw_cmn)(struct bnx2x_softc *sc);
1582         void (*reset_hw_port)(struct bnx2x_softc *sc);
1583         void (*reset_hw_func)(struct bnx2x_softc *sc);
1584
1585         /* Prepare/Release FW resources */
1586         int (*init_fw)(struct bnx2x_softc *sc);
1587         void (*release_fw)(struct bnx2x_softc *sc);
1588 };
1589
1590 struct ecore_func_sp_obj {
1591         enum ecore_func_state   state, next_state;
1592
1593         /* ECORE_FUNC_CMD_XX bits. This object implements "one
1594          * pending" paradigm but for debug and tracing purposes it's
1595          * more convenient to have different bits for different
1596          * commands.
1597          */
1598         unsigned long           pending;
1599
1600         /* Buffer to use as a ramrod data and its mapping */
1601         void                    *rdata;
1602         ecore_dma_addr_t                rdata_mapping;
1603
1604         /* Buffer to use as a afex ramrod data and its mapping.
1605          * This can't be same rdata as above because afex ramrod requests
1606          * can arrive to the object in parallel to other ramrod requests.
1607          */
1608         void                    *afex_rdata;
1609         ecore_dma_addr_t                afex_rdata_mapping;
1610
1611         /* this mutex validates that when pending flag is taken, the next
1612          * ramrod to be sent will be the one set the pending bit
1613          */
1614         ECORE_MUTEX             one_pending_mutex;
1615
1616         /* Driver interface */
1617         struct ecore_func_sp_drv_ops    *drv;
1618
1619         /**
1620          * Performs one state change according to the given parameters.
1621          *
1622          * @return 0 in case of success and negative value otherwise.
1623          */
1624         int (*send_cmd)(struct bnx2x_softc *sc,
1625                         struct ecore_func_state_params *params);
1626
1627         /**
1628          * Checks that the requested state transition is legal.
1629          */
1630         int (*check_transition)(struct bnx2x_softc *sc,
1631                                 struct ecore_func_sp_obj *o,
1632                                 struct ecore_func_state_params *params);
1633
1634         /**
1635          * Completes the pending command.
1636          */
1637         int (*complete_cmd)(struct bnx2x_softc *sc,
1638                             struct ecore_func_sp_obj *o,
1639                             enum ecore_func_cmd cmd);
1640
1641         int (*wait_comp)(struct bnx2x_softc *sc, struct ecore_func_sp_obj *o,
1642                          enum ecore_func_cmd cmd);
1643 };
1644
1645 /********************** Interfaces ********************************************/
1646 /* Queueable objects set */
1647 union ecore_qable_obj {
1648         struct ecore_vlan_mac_obj vlan_mac;
1649 };
1650 /************** Function state update *********/
1651 void ecore_init_func_obj(struct bnx2x_softc *sc,
1652                          struct ecore_func_sp_obj *obj,
1653                          void *rdata, ecore_dma_addr_t rdata_mapping,
1654                          void *afex_rdata, ecore_dma_addr_t afex_rdata_mapping,
1655                          struct ecore_func_sp_drv_ops *drv_iface);
1656
1657 int ecore_func_state_change(struct bnx2x_softc *sc,
1658                             struct ecore_func_state_params *params);
1659
1660 enum ecore_func_state ecore_func_get_state(struct bnx2x_softc *sc,
1661                                            struct ecore_func_sp_obj *o);
1662 /******************* Queue State **************/
1663 void ecore_init_queue_obj(struct bnx2x_softc *sc,
1664                           struct ecore_queue_sp_obj *obj, uint8_t cl_id, uint32_t *cids,
1665                           uint8_t cid_cnt, uint8_t func_id, void *rdata,
1666                           ecore_dma_addr_t rdata_mapping, unsigned long type);
1667
1668 int ecore_queue_state_change(struct bnx2x_softc *sc,
1669                              struct ecore_queue_state_params *params);
1670
1671 /********************* VLAN-MAC ****************/
1672 void ecore_init_mac_obj(struct bnx2x_softc *sc,
1673                         struct ecore_vlan_mac_obj *mac_obj,
1674                         uint8_t cl_id, uint32_t cid, uint8_t func_id, void *rdata,
1675                         ecore_dma_addr_t rdata_mapping, int state,
1676                         unsigned long *pstate, ecore_obj_type type,
1677                         struct ecore_credit_pool_obj *macs_pool);
1678
1679 void ecore_vlan_mac_h_read_unlock(struct bnx2x_softc *sc,
1680                                   struct ecore_vlan_mac_obj *o);
1681 int ecore_vlan_mac_h_write_lock(struct bnx2x_softc *sc,
1682                                 struct ecore_vlan_mac_obj *o);
1683 void ecore_vlan_mac_h_write_unlock(struct bnx2x_softc *sc,
1684                                           struct ecore_vlan_mac_obj *o);
1685 int ecore_config_vlan_mac(struct bnx2x_softc *sc,
1686                            struct ecore_vlan_mac_ramrod_params *p);
1687
1688 int ecore_vlan_mac_move(struct bnx2x_softc *sc,
1689                         struct ecore_vlan_mac_ramrod_params *p,
1690                         struct ecore_vlan_mac_obj *dest_o);
1691
1692 /********************* RX MODE ****************/
1693
1694 void ecore_init_rx_mode_obj(struct bnx2x_softc *sc,
1695                             struct ecore_rx_mode_obj *o);
1696
1697 /**
1698  * ecore_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
1699  *
1700  * @p: Command parameters
1701  *
1702  * Return: 0 - if operation was successful and there is no pending completions,
1703  *         positive number - if there are pending completions,
1704  *         negative - if there were errors
1705  */
1706 int ecore_config_rx_mode(struct bnx2x_softc *sc,
1707                          struct ecore_rx_mode_ramrod_params *p);
1708
1709 /****************** MULTICASTS ****************/
1710
1711 void ecore_init_mcast_obj(struct bnx2x_softc *sc,
1712                           struct ecore_mcast_obj *mcast_obj,
1713                           uint8_t mcast_cl_id, uint32_t mcast_cid, uint8_t func_id,
1714                           uint8_t engine_id, void *rdata, ecore_dma_addr_t rdata_mapping,
1715                           int state, unsigned long *pstate,
1716                           ecore_obj_type type);
1717
1718 /**
1719  * ecore_config_mcast - Configure multicast MACs list.
1720  *
1721  * @cmd: command to execute: BNX2X_MCAST_CMD_X
1722  *
1723  * May configure a new list
1724  * provided in p->mcast_list (ECORE_MCAST_CMD_ADD), clean up
1725  * (ECORE_MCAST_CMD_DEL) or restore (ECORE_MCAST_CMD_RESTORE) a current
1726  * configuration, continue to execute the pending commands
1727  * (ECORE_MCAST_CMD_CONT).
1728  *
1729  * If previous command is still pending or if number of MACs to
1730  * configure is more that maximum number of MACs in one command,
1731  * the current command will be enqueued to the tail of the
1732  * pending commands list.
1733  *
1734  * Return: 0 is operation was successful and there are no pending completions,
1735  *         negative if there were errors, positive if there are pending
1736  *         completions.
1737  */
1738 int ecore_config_mcast(struct bnx2x_softc *sc,
1739                        struct ecore_mcast_ramrod_params *p,
1740                        enum ecore_mcast_cmd cmd);
1741
1742 /****************** CREDIT POOL ****************/
1743 void ecore_init_mac_credit_pool(struct bnx2x_softc *sc,
1744                                 struct ecore_credit_pool_obj *p, uint8_t func_id,
1745                                 uint8_t func_num);
1746 void ecore_init_vlan_credit_pool(struct bnx2x_softc *sc,
1747                                  struct ecore_credit_pool_obj *p, uint8_t func_id,
1748                                  uint8_t func_num);
1749
1750 /****************** RSS CONFIGURATION ****************/
1751 void ecore_init_rss_config_obj(struct ecore_rss_config_obj *rss_obj,
1752                                uint8_t cl_id, uint32_t cid, uint8_t func_id, uint8_t engine_id,
1753                                void *rdata, ecore_dma_addr_t rdata_mapping,
1754                                int state, unsigned long *pstate,
1755                                ecore_obj_type type);
1756
1757 /**
1758  * ecore_config_rss - Updates RSS configuration according to provided parameters
1759  *
1760  * Return: 0 in case of success
1761  */
1762 int ecore_config_rss(struct bnx2x_softc *sc,
1763                      struct ecore_config_rss_params *p);
1764
1765
1766 #endif /* ECORE_SP_H */